diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-11-04 20:57:36 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-11-04 20:57:36 +0000 |
commit | 84e922bfb3e7a03f6e35beb2f1e4f2657e7cd3e9 (patch) | |
tree | e57c3c2c12fd8da316c8ee01f0eae00b346f6130 | |
parent | d48c16b2ff83a78f71870ce86002a545a4513b3c (diff) |
Revert "speed up A8 by creating a new entry-point in SkDraw that blits the path's coverage directly into an A8 target, regardless of the previous pixel values."
This reverts commit d615e839b71f75df895de6850b774a9e1c28ad2a.
Revert "must initialize SkDraw.fClip"
This reverts commit 108e46d29b5f57927fc8b8c403bb52019d8cb16d.
BUG=
Review URL: https://codereview.chromium.org/57883006
git-svn-id: http://skia.googlecode.com/svn/trunk@12122 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | bench/CoverageBench.cpp | 71 | ||||
-rw-r--r-- | gyp/bench.gypi | 1 | ||||
-rw-r--r-- | include/core/SkDraw.h | 24 | ||||
-rw-r--r-- | include/core/SkRect.h | 11 | ||||
-rw-r--r-- | src/core/SkBlitter.cpp | 14 | ||||
-rw-r--r-- | src/core/SkBlitter.h | 3 | ||||
-rw-r--r-- | src/core/SkBlitter_A8.cpp | 53 | ||||
-rw-r--r-- | src/core/SkCoreBlitters.h | 11 | ||||
-rw-r--r-- | src/core/SkDraw.cpp | 9 | ||||
-rw-r--r-- | src/gpu/GrSWMaskHelper.cpp | 25 | ||||
-rw-r--r-- | src/gpu/GrSWMaskHelper.h | 3 |
11 files changed, 25 insertions, 200 deletions
diff --git a/bench/CoverageBench.cpp b/bench/CoverageBench.cpp deleted file mode 100644 index de09733cf8..0000000000 --- a/bench/CoverageBench.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2013 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "SkBenchmark.h" -#include "SkBitmap.h" -#include "SkCanvas.h" -#include "SkColorPriv.h" -#include "SkDraw.h" -#include "SkMatrix.h" -#include "SkPath.h" -#include "SkRasterClip.h" - -class DrawPathBench : public SkBenchmark { - SkPaint fPaint; - SkString fName; - SkPath fPath; - SkRasterClip fRC; - SkBitmap fBitmap; - SkMatrix fIdentity; - SkDraw fDraw; - bool fDrawCoverage; -public: - DrawPathBench(bool drawCoverage) : fDrawCoverage(drawCoverage) { - fPaint.setAntiAlias(true); - fName.printf("draw_coverage_%s", drawCoverage ? "true" : "false"); - - fPath.moveTo(0, 0); - fPath.quadTo(500, 0, 500, 500); - fPath.quadTo(250, 0, 0, 500); - - fBitmap.setConfig(SkBitmap::kA8_Config, 500, 500); - fBitmap.allocPixels(); - - fIdentity.setIdentity(); - fRC.setRect(fPath.getBounds().round()); - - fDraw.fBitmap = &fBitmap; - fDraw.fMatrix = &fIdentity; - fDraw.fClip = &fRC.bwRgn(); - fDraw.fRC = &fRC; - } - -protected: - virtual const char* onGetName() SK_OVERRIDE { - return fName.c_str(); - } - - virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { - if (fDrawCoverage) { - for (int i = 0; i < this->getLoops(); ++i) { - fDraw.drawPathCoverage(fPath, fPaint); - } - } else { - for (int i = 0; i < this->getLoops(); ++i) { - fDraw.drawPath(fPath, fPaint); - } - } - } - -private: - typedef SkBenchmark INHERITED; -}; - -/////////////////////////////////////////////////////////////////////////////// - -DEF_BENCH( return new DrawPathBench(false) ) -DEF_BENCH( return new DrawPathBench(true) ) diff --git a/gyp/bench.gypi b/gyp/bench.gypi index 7659c768a2..32902b4134 100644 --- a/gyp/bench.gypi +++ b/gyp/bench.gypi @@ -18,7 +18,6 @@ '../bench/ChromeBench.cpp', '../bench/CmapBench.cpp', '../bench/ColorFilterBench.cpp', - '../bench/CoverageBench.cpp', '../bench/DashBench.cpp', '../bench/DecodeBench.cpp', '../bench/DeferredCanvasBench.cpp', diff --git a/include/core/SkDraw.h b/include/core/SkDraw.h index 9183094679..772e11e00d 100644 --- a/include/core/SkDraw.h +++ b/include/core/SkDraw.h @@ -43,15 +43,8 @@ public: * affect the geometry/rasterization, then the pre matrix can just be * pre-concated with the current matrix. */ - void drawPath(const SkPath& path, const SkPaint& paint, - const SkMatrix* prePathMatrix, bool pathIsMutable) const { - this->drawPath(path, paint, prePathMatrix, pathIsMutable, false); - } - - void drawPath(const SkPath& path, const SkPaint& paint) const { - this->drawPath(path, paint, NULL, false, false); - } - + void drawPath(const SkPath& srcPath, const SkPaint&, + const SkMatrix* prePathMatrix, bool pathIsMutable) const; void drawBitmap(const SkBitmap&, const SkMatrix&, const SkPaint&) const; void drawSprite(const SkBitmap&, int x, int y, const SkPaint&) const; void drawText(const char text[], size_t byteLength, SkScalar x, @@ -72,14 +65,8 @@ public: const uint16_t indices[], int ptCount, const SkPaint& paint) const; - /** - * Overwrite the target with the path's coverage (i.e. its mask). - * Will overwrite the entire device, so it need not be zero'd first. - * - * Only device A8 is supported right now. - */ - void drawPathCoverage(const SkPath& src, const SkPaint& paint) const { - this->drawPath(src, paint, NULL, false, true); + void drawPath(const SkPath& src, const SkPaint& paint) const { + this->drawPath(src, paint, NULL, false); } /** Helper function that creates a mask from a path and an optional maskfilter. @@ -120,9 +107,6 @@ private: void drawDevMask(const SkMask& mask, const SkPaint&) const; void drawBitmapAsMask(const SkBitmap&, const SkPaint&) const; - void drawPath(const SkPath&, const SkPaint&, const SkMatrix* preMatrix, - bool pathIsMutable, bool drawCoverage) const; - /** * Return the current clip bounds, in local coordinates, with slop to account * for antialiasing or hairlines (i.e. device-bounds outset by 1, and then diff --git a/include/core/SkRect.h b/include/core/SkRect.h index 8bfa57a8f9..98acb1cda3 100644 --- a/include/core/SkRect.h +++ b/include/core/SkRect.h @@ -730,7 +730,7 @@ struct SK_API SkRect { /** * Set the dst rectangle by rounding this rectangle's coordinates to their - * nearest integer values using SkScalarRoundToInt. + * nearest integer values using SkScalarRound. */ void round(SkIRect* dst) const { SkASSERT(dst); @@ -772,15 +772,6 @@ struct SK_API SkRect { SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom)); } - /** - * Return a new SkIRect which is contains the rounded coordinates of this - * rect using SkScalarRoundToInt. - */ - SkIRect round() const { - SkIRect ir; - this->round(&ir); - return ir; - } /** * Swap top/bottom or left/right if there are flipped (i.e. if width() diff --git a/src/core/SkBlitter.cpp b/src/core/SkBlitter.cpp index f46db357d4..f4e1a37c80 100644 --- a/src/core/SkBlitter.cpp +++ b/src/core/SkBlitter.cpp @@ -850,16 +850,14 @@ static XferInterp interpret_xfermode(const SkPaint& paint, SkXfermode* xfer, SkBlitter* SkBlitter::Choose(const SkBitmap& device, const SkMatrix& matrix, const SkPaint& origPaint, - void* storage, size_t storageSize, - bool drawCoverage) { + void* storage, size_t storageSize) { SkASSERT(storageSize == 0 || storage != NULL); SkBlitter* blitter = NULL; // which check, in case we're being called by a client with a dummy device // (e.g. they have a bounder that always aborts the draw) - if (SkBitmap::kNo_Config == device.config() || - (drawCoverage && (SkBitmap::kA8_Config != device.config()))) { + if (SkBitmap::kNo_Config == device.config()) { SK_PLACEMENT_NEW(blitter, SkNullBlitter, storage, storageSize); return blitter; } @@ -942,7 +940,6 @@ SkBlitter* SkBlitter::Choose(const SkBitmap& device, return blitter; } - switch (device.config()) { case SkBitmap::kA1_Config: SK_PLACEMENT_NEW_ARGS(blitter, SkA1_Blitter, @@ -950,12 +947,7 @@ SkBlitter* SkBlitter::Choose(const SkBitmap& device, break; case SkBitmap::kA8_Config: - if (drawCoverage) { - SkASSERT(NULL == shader); - SkASSERT(NULL == paint->getXfermode()); - SK_PLACEMENT_NEW_ARGS(blitter, SkA8_Coverage_Blitter, - storage, storageSize, (device, *paint)); - } else if (shader) { + if (shader) { SK_PLACEMENT_NEW_ARGS(blitter, SkA8_Shader_Blitter, storage, storageSize, (device, *paint)); } else { diff --git a/src/core/SkBlitter.h b/src/core/SkBlitter.h index b659fe4735..0a075f89ad 100644 --- a/src/core/SkBlitter.h +++ b/src/core/SkBlitter.h @@ -76,8 +76,7 @@ public: static SkBlitter* Choose(const SkBitmap& device, const SkMatrix& matrix, const SkPaint& paint, - void* storage, size_t storageSize, - bool drawCoverage = false); + void* storage, size_t storageSize); static SkBlitter* ChooseSprite(const SkBitmap& device, const SkPaint&, diff --git a/src/core/SkBlitter_A8.cpp b/src/core/SkBlitter_A8.cpp index c524d0af06..7fca29ecf5 100644 --- a/src/core/SkBlitter_A8.cpp +++ b/src/core/SkBlitter_A8.cpp @@ -347,56 +347,3 @@ void SkA8_Shader_Blitter::blitMask(const SkMask& mask, const SkIRect& clip) { alpha += mask.fRowBytes; } } - -/////////////////////////////////////////////////////////////////////////////// - -SkA8_Coverage_Blitter::SkA8_Coverage_Blitter(const SkBitmap& device, - const SkPaint& paint) : SkRasterBlitter(device) { - SkASSERT(NULL == paint.getShader()); - SkASSERT(NULL == paint.getXfermode()); - SkASSERT(NULL == paint.getColorFilter()); -} - -void SkA8_Coverage_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[], - const int16_t runs[]) { - SkASSERT(0 == x); - - uint8_t* device = fDevice.getAddr8(x, y); - SkDEBUGCODE(int totalCount = 0;) - - for (;;) { - int count = runs[0]; - SkASSERT(count >= 0); - if (count == 0) { - return; - } - memset(device, antialias[0], count); - runs += count; - antialias += count; - device += count; - - SkDEBUGCODE(totalCount += count;) - } - SkASSERT(fDevice.width() == totalCount); -} - -void SkA8_Coverage_Blitter::blitH(int x, int y, int width) { - sk_throw(); -} - -void SkA8_Coverage_Blitter::blitV(int x, int y, int height, SkAlpha alpha) { - sk_throw(); -} - -void SkA8_Coverage_Blitter::blitRect(int x, int y, int width, int height) { - sk_throw(); -} - -void SkA8_Coverage_Blitter::blitMask(const SkMask&, const SkIRect&) { - sk_throw(); -} - -const SkBitmap* SkA8_Coverage_Blitter::justAnOpaqueColor(uint32_t*) { - sk_throw(); - return NULL; -} diff --git a/src/core/SkCoreBlitters.h b/src/core/SkCoreBlitters.h index 673b874545..9455509c48 100644 --- a/src/core/SkCoreBlitters.h +++ b/src/core/SkCoreBlitters.h @@ -40,17 +40,6 @@ private: /////////////////////////////////////////////////////////////////////////////// -class SkA8_Coverage_Blitter : public SkRasterBlitter { -public: - SkA8_Coverage_Blitter(const SkBitmap& device, const SkPaint& paint); - virtual void blitH(int x, int y, int width) SK_OVERRIDE; - virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) SK_OVERRIDE; - virtual void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE; - virtual void blitRect(int x, int y, int width, int height) SK_OVERRIDE; - virtual void blitMask(const SkMask&, const SkIRect&) SK_OVERRIDE; - virtual const SkBitmap* justAnOpaqueColor(uint32_t*) SK_OVERRIDE; -}; - class SkA8_Blitter : public SkRasterBlitter { public: SkA8_Blitter(const SkBitmap& device, const SkPaint& paint); diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp index af4f1ca047..df73f7ae37 100644 --- a/src/core/SkDraw.cpp +++ b/src/core/SkDraw.cpp @@ -59,9 +59,9 @@ public: fBlitter = NULL; } SkAutoBlitterChoose(const SkBitmap& device, const SkMatrix& matrix, - const SkPaint& paint, bool drawCoverage = false) { + const SkPaint& paint) { fBlitter = SkBlitter::Choose(device, matrix, paint, - fStorage, sizeof(fStorage), drawCoverage); + fStorage, sizeof(fStorage)); } ~SkAutoBlitterChoose(); @@ -1023,8 +1023,7 @@ bool SkDrawTreatAsHairline(const SkPaint& paint, const SkMatrix& matrix, } void SkDraw::drawPath(const SkPath& origSrcPath, const SkPaint& origPaint, - const SkMatrix* prePathMatrix, bool pathIsMutable, - bool drawCoverage) const { + const SkMatrix* prePathMatrix, bool pathIsMutable) const { SkDEBUGCODE(this->validate();) // nothing to draw @@ -1113,7 +1112,7 @@ void SkDraw::drawPath(const SkPath& origSrcPath, const SkPaint& origPaint, // transform the path into device space pathPtr->transform(*matrix, devPathPtr); - SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, *paint, drawCoverage); + SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, *paint); if (paint->getMaskFilter()) { SkPaint::Style style = doFill ? SkPaint::kFill_Style : diff --git a/src/gpu/GrSWMaskHelper.cpp b/src/gpu/GrSWMaskHelper.cpp index 54fde0f989..5fb944bac4 100644 --- a/src/gpu/GrSWMaskHelper.cpp +++ b/src/gpu/GrSWMaskHelper.cpp @@ -73,21 +73,20 @@ void GrSWMaskHelper::draw(const SkPath& path, const SkStrokeRec& stroke, SkRegio paint.setStrokeWidth(stroke.getWidth()); } } + + SkXfermode* mode = SkXfermode::Create(op_to_mode(op)); + + paint.setXfermode(mode); paint.setAntiAlias(antiAlias); + paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha)); - if (SkRegion::kReplace_Op == op && 0xFF == alpha) { - SkASSERT(0xFF == paint.getAlpha()); - fDraw.drawPathCoverage(path, paint); - } else { - paint.setXfermodeMode(op_to_mode(op)); - paint.setColor(SkColorSetARGB(alpha, alpha, alpha, alpha)); - fDraw.drawPath(path, paint); - } + fDraw.drawPath(path, paint); + + SkSafeUnref(mode); } bool GrSWMaskHelper::init(const SkIRect& resultBounds, - const SkMatrix* matrix, - bool zeroPixels) { + const SkMatrix* matrix) { if (NULL != matrix) { fMatrix = *matrix; } else { @@ -104,9 +103,7 @@ bool GrSWMaskHelper::init(const SkIRect& resultBounds, if (!fBM.allocPixels()) { return false; } - if (zeroPixels) { - sk_bzero(fBM.getPixels(), fBM.getSafeSize()); - } + sk_bzero(fBM.getPixels(), fBM.getSafeSize()); sk_bzero(&fDraw, sizeof(fDraw)); fRasterClip.setRect(bounds); @@ -166,7 +163,7 @@ GrTexture* GrSWMaskHelper::DrawPathMaskToTexture(GrContext* context, GrSWMaskHelper helper(context); - if (!helper.init(resultBounds, matrix, false)) { + if (!helper.init(resultBounds, matrix)) { return NULL; } diff --git a/src/gpu/GrSWMaskHelper.h b/src/gpu/GrSWMaskHelper.h index 097f62c048..b274e84c66 100644 --- a/src/gpu/GrSWMaskHelper.h +++ b/src/gpu/GrSWMaskHelper.h @@ -48,8 +48,7 @@ public: // may be accumulated in the helper during creation, "resultBounds" // allows the caller to specify the region of interest - to limit the // amount of work. - bool init(const SkIRect& resultBounds, const SkMatrix* matrix, - bool zeroPixels = true); + bool init(const SkIRect& resultBounds, const SkMatrix* matrix); // Draw a single rect into the accumulation bitmap using the specified op void draw(const SkRect& rect, SkRegion::Op op, |