diff options
author | Herb Derby <herb@google.com> | 2017-02-13 20:04:00 +0000 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-02-13 20:04:16 +0000 |
commit | 07f665efb918f68e406b76a78d0b76d5c714f16c (patch) | |
tree | d58a5d4849f779e9504aa69dda0414777770eafb /src/core | |
parent | d2d6d726fa3e401da73befa649266bc5589da7e5 (diff) |
Revert "Always make SkImageShaders in heap."
This reverts commit ff590a12441002d281254ec6a86070ac0a19263f.
Reason for revert: This breaks the android roll because they are using
a private call. Updating android tests to use new api.
Original change's description:
> Always make SkImageShaders in heap.
>
> I made a couple of measurments, and it looks like any differences is
> well below the noise threshold.
>
> Just for the record run1: .9991 of baseline and run2 .9988 of baseline.
> I was using top25 .skps as workload.
>
> TBR=mtklein@google.com
>
> Change-Id: If4fa06e5d5df72fb67dbb4bbb99c926f05765897
> Reviewed-on: https://skia-review.googlesource.com/8341
> Reviewed-by: Herb Derby <herb@google.com>
> Commit-Queue: Herb Derby <herb@google.com>
>
TBR=mtklein@chromium.org,mtklein@google.com,herb@google.com,reviews@skia.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
Change-Id: Ibdaafc796702e250933b62e5f4abb5e2ce8d40c0
Reviewed-on: https://skia-review.googlesource.com/8393
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: Herb Derby <herb@google.com>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkBitmapDevice.cpp | 6 | ||||
-rw-r--r-- | src/core/SkDraw.cpp | 19 | ||||
-rw-r--r-- | src/core/SkImagePriv.h | 6 | ||||
-rw-r--r-- | src/core/SkShader.cpp | 2 |
4 files changed, 26 insertions, 7 deletions
diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp index 45ec2b70ae..2b5c37fa2e 100644 --- a/src/core/SkBitmapDevice.cpp +++ b/src/core/SkBitmapDevice.cpp @@ -334,13 +334,15 @@ void SkBitmapDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, // Since the shader need only live for our stack-frame, pass in a custom allocator. This // can save malloc calls, and signals to SkMakeBitmapShader to not try to copy the bitmap // if its mutable, since that precaution is not needed (give the short lifetime of the shader). - + SkTBlitterAllocator allocator; // construct a shader, so we can call drawRect with the dst auto s = SkMakeBitmapShader(*bitmapPtr, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, - &matrix, kNever_SkCopyPixelsMode); + &matrix, kNever_SkCopyPixelsMode, &allocator); if (!s) { return; } + // we deliberately add a ref, since the allocator wants to be the last owner + s.get()->ref(); SkPaint paintWithShader(paint); paintWithShader.setStyle(SkPaint::kFill_Style); diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp index 4d1c5a4998..4308000457 100644 --- a/src/core/SkDraw.cpp +++ b/src/core/SkDraw.cpp @@ -85,10 +85,23 @@ public: SkAutoBitmapShaderInstall(const SkBitmap& src, const SkPaint& paint, const SkMatrix* localMatrix = nullptr) : fPaint(paint) /* makes a copy of the paint */ { - + // TODO(herb): Move this over to SkArenaAlloc when arena alloc has a + // facility to return sk_sps. fPaint.setShader(SkMakeBitmapShader(src, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, localMatrix, - kNever_SkCopyPixelsMode)); + kNever_SkCopyPixelsMode, + &fAllocator)); + // we deliberately left the shader with an owner-count of 2 + fPaint.getShader()->ref(); + SkASSERT(2 == fPaint.getShader()->getRefCnt()); + } + + ~SkAutoBitmapShaderInstall() { + // since fAllocator will destroy shader, we insist that owners == 2 + SkASSERT(2 == fPaint.getShader()->getRefCnt()); + + fPaint.setShader(nullptr); // unref the shader by 1 + } // return the new paint that has the shader applied @@ -97,6 +110,8 @@ public: private: // copy of caller's paint (which we then modify) SkPaint fPaint; + // Stores the shader. + SkTBlitterAllocator fAllocator; }; #define SkAutoBitmapShaderInstall(...) SK_REQUIRE_LOCAL_VAR(SkAutoBitmapShaderInstall) diff --git a/src/core/SkImagePriv.h b/src/core/SkImagePriv.h index d6e58d3c11..601108665d 100644 --- a/src/core/SkImagePriv.h +++ b/src/core/SkImagePriv.h @@ -30,7 +30,8 @@ typedef SkSmallAllocator<3, kSkBlitterContextSize> SkTBlitterAllocator; // If alloc is non-nullptr, it will be used to allocate the returned SkShader, and MUST outlive // the SkShader. sk_sp<SkShader> SkMakeBitmapShader(const SkBitmap& src, SkShader::TileMode, SkShader::TileMode, - const SkMatrix* localMatrix, SkCopyPixelsMode); + const SkMatrix* localMatrix, SkCopyPixelsMode, + SkTBlitterAllocator* alloc); /** * Examines the bitmap to decide if it can share the existing pixelRef, or @@ -50,7 +51,8 @@ sk_sp<SkShader> SkMakeBitmapShader(const SkBitmap& src, SkShader::TileMode, SkSh * SkImageInfo, or the bitmap's pixels cannot be accessed, this will return * nullptr. */ -extern sk_sp<SkImage> SkMakeImageFromRasterBitmap(const SkBitmap&, SkCopyPixelsMode); +extern sk_sp<SkImage> SkMakeImageFromRasterBitmap(const SkBitmap&, SkCopyPixelsMode, + SkTBlitterAllocator* = nullptr); // Given an image created from SkNewImageFromBitmap, return its pixelref. This // may be called to see if the surface and the image share the same pixelref, diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp index cfdd8b946e..81aae116d5 100644 --- a/src/core/SkShader.cpp +++ b/src/core/SkShader.cpp @@ -232,7 +232,7 @@ sk_sp<SkShader> SkShader::MakeBitmapShader(const SkBitmap& src, TileMode tmx, Ti if (localMatrix && !localMatrix->invert(nullptr)) { return nullptr; } - return SkMakeBitmapShader(src, tmx, tmy, localMatrix, kIfMutable_SkCopyPixelsMode); + return SkMakeBitmapShader(src, tmx, tmy, localMatrix, kIfMutable_SkCopyPixelsMode, nullptr); } sk_sp<SkShader> SkShader::MakePictureShader(sk_sp<SkPicture> src, TileMode tmx, TileMode tmy, |