diff options
author | 2017-02-14 11:13:26 -0500 | |
---|---|---|
committer | 2017-02-14 17:02:33 +0000 | |
commit | 4bf560a056d7ba5b3051ebc87e687d4997928ff6 (patch) | |
tree | 711c29457e828f9072af7a25991e004acc0d14f9 /src/core | |
parent | c6b7146eef808dc7b60a1d5f49eb98f947c0bfe3 (diff) |
Simplify code for making paints with shaders.
Since SkAutoBitmapShaderInstall was simplified to create shaders on the
heap, it is no longer needed. Simplify to a single routine.
TBR=mtklein@google.com
Change-Id: Ib18be559b03e234a05105d0892c1457cafce28b7
Reviewed-on: https://skia-review.googlesource.com/8391
Reviewed-by: Herb Derby <herb@google.com>
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Herb Derby <herb@google.com>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkDraw.cpp | 45 |
1 files changed, 13 insertions, 32 deletions
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp index 4d1c5a4998..eb5af7ab06 100644 --- a/src/core/SkDraw.cpp +++ b/src/core/SkDraw.cpp @@ -75,30 +75,14 @@ private: }; #define SkAutoBlitterChoose(...) SK_REQUIRE_LOCAL_VAR(SkAutoBlitterChoose) -/** - * Since we are providing the storage for the shader (to avoid the perf cost - * of calling new) we insist that in our destructor we can account for all - * owners of the shader. - */ -class SkAutoBitmapShaderInstall : SkNoncopyable { -public: - SkAutoBitmapShaderInstall(const SkBitmap& src, const SkPaint& paint, - const SkMatrix* localMatrix = nullptr) - : fPaint(paint) /* makes a copy of the paint */ { - - fPaint.setShader(SkMakeBitmapShader(src, SkShader::kClamp_TileMode, - SkShader::kClamp_TileMode, localMatrix, - kNever_SkCopyPixelsMode)); - } - - // return the new paint that has the shader applied - const SkPaint& paintWithShader() const { return fPaint; } - -private: - // copy of caller's paint (which we then modify) - SkPaint fPaint; -}; -#define SkAutoBitmapShaderInstall(...) SK_REQUIRE_LOCAL_VAR(SkAutoBitmapShaderInstall) +static SkPaint make_paint_with_image( + const SkPaint& origPaint, const SkBitmap& bitmap, SkMatrix* matrix = nullptr) { + SkPaint paint(origPaint); + paint.setShader(SkMakeBitmapShader(bitmap, SkShader::kClamp_TileMode, + SkShader::kClamp_TileMode, matrix, + kNever_SkCopyPixelsMode)); + return paint; +} /////////////////////////////////////////////////////////////////////////////// @@ -1249,11 +1233,11 @@ void SkDraw::drawBitmapAsMask(const SkBitmap& bitmap, const SkPaint& paint) cons SkPaint tmpPaint; tmpPaint.setFlags(paint.getFlags()); tmpPaint.setFilterQuality(paint.getFilterQuality()); - SkAutoBitmapShaderInstall install(bitmap, tmpPaint); + SkPaint paintWithShader = make_paint_with_image(tmpPaint, bitmap); SkRect rr; rr.set(0, 0, SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height())); - c.drawRect(rr, install.paintWithShader()); + c.drawRect(rr, paintWithShader); } this->drawDevMask(mask, paint); } @@ -1335,8 +1319,7 @@ void SkDraw::drawBitmap(const SkBitmap& bitmap, const SkMatrix& prematrix, if (bitmap.colorType() == kAlpha_8_SkColorType && !paint->getColorFilter()) { draw.drawBitmapAsMask(bitmap, *paint); } else { - SkAutoBitmapShaderInstall install(bitmap, *paint); - const SkPaint& paintWithShader = install.paintWithShader(); + SkPaint paintWithShader = make_paint_with_image(*paint, bitmap); const SkRect srcBounds = SkRect::MakeIWH(bitmap.width(), bitmap.height()); if (dstBounds) { this->drawRect(srcBounds, paintWithShader, &prematrix, dstBounds); @@ -1390,15 +1373,13 @@ void SkDraw::drawSprite(const SkBitmap& bitmap, int x, int y, const SkPaint& ori // create shader with offset matrix.setTranslate(r.fLeft, r.fTop); - SkAutoBitmapShaderInstall install(bitmap, paint, &matrix); - const SkPaint& shaderPaint = install.paintWithShader(); - + SkPaint paintWithShader = make_paint_with_image(paint, bitmap, &matrix); SkDraw draw(*this); matrix.reset(); draw.fMatrix = &matrix; // call ourself with a rect // is this OK if paint has a rasterizer? - draw.drawRect(r, shaderPaint); + draw.drawRect(r, paintWithShader); } /////////////////////////////////////////////////////////////////////////////// |