aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2016-08-05 14:50:19 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-08-05 14:50:19 -0700
commit4c1abdcd21d65bb34a6b4aea969ef4485e117e67 (patch)
tree5c40789cd3815eea5a29769750ec03c6d17d75cf
parent462d0148a5c9433a1f9c26d947a07ca7f70cf09d (diff)
use tmp allocator for images in temp shaders
-rw-r--r--src/core/SkBitmapProcShader.h17
-rw-r--r--src/core/SkImagePriv.h29
-rw-r--r--src/image/SkImageShader.cpp2
-rw-r--r--src/image/SkImage_Raster.cpp11
4 files changed, 33 insertions, 26 deletions
diff --git a/src/core/SkBitmapProcShader.h b/src/core/SkBitmapProcShader.h
index edb9864270..4b7447e52e 100644
--- a/src/core/SkBitmapProcShader.h
+++ b/src/core/SkBitmapProcShader.h
@@ -9,9 +9,7 @@
#include "SkImagePriv.h"
#include "SkShader.h"
-#include "SkSmallAllocator.h"
-struct SkBitmapProcState;
class SkBitmapProvider;
class SkBitmapProcLegacyShader : public SkShader {
@@ -25,19 +23,4 @@ private:
typedef SkShader INHERITED;
};
-enum {kSkBlitterContextSize = 3332};
-
-// Commonly used allocator. It currently is only used to allocate up to 3 objects. The total
-// bytes requested is calculated using one of our large shaders, its context size plus the size of
-// an Sk3DBlitter in SkDraw.cpp
-// Note that some contexts may contain other contexts (e.g. for compose shaders), but we've not
-// yet found a situation where the size below isn't big enough.
-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,
- SkTBlitterAllocator* alloc);
-
#endif
diff --git a/src/core/SkImagePriv.h b/src/core/SkImagePriv.h
index ed40996acd..3077f34367 100644
--- a/src/core/SkImagePriv.h
+++ b/src/core/SkImagePriv.h
@@ -9,19 +9,35 @@
#define SkImagePriv_DEFINED
#include "SkImage.h"
+#include "SkSmallAllocator.h"
#include "SkSurface.h"
-// Call this if you explicitly want to use/share this pixelRef in the image
-extern sk_sp<SkImage> SkMakeImageFromPixelRef(const SkImageInfo&, SkPixelRef*,
- const SkIPoint& pixelRefOrigin,
- size_t rowBytes);
-
enum SkCopyPixelsMode {
kIfMutable_SkCopyPixelsMode, //!< only copy src pixels if they are marked mutable
kAlways_SkCopyPixelsMode, //!< always copy src pixels (even if they are marked immutable)
kNever_SkCopyPixelsMode, //!< never copy src pixels (even if they are marked mutable)
};
+enum {kSkBlitterContextSize = 3332};
+
+// Commonly used allocator. It currently is only used to allocate up to 3 objects. The total
+// bytes requested is calculated using one of our large shaders, its context size plus the size of
+// an Sk3DBlitter in SkDraw.cpp
+// Note that some contexts may contain other contexts (e.g. for compose shaders), but we've not
+// yet found a situation where the size below isn't big enough.
+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,
+ SkTBlitterAllocator* alloc);
+
+// Call this if you explicitly want to use/share this pixelRef in the image
+extern sk_sp<SkImage> SkMakeImageFromPixelRef(const SkImageInfo&, SkPixelRef*,
+ const SkIPoint& pixelRefOrigin,
+ size_t rowBytes);
+
/**
* Examines the bitmap to decide if it can share the existing pixelRef, or
* if it needs to make a deep-copy of the pixels.
@@ -40,7 +56,8 @@ enum SkCopyPixelsMode {
* 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/image/SkImageShader.cpp b/src/image/SkImageShader.cpp
index 5fbb0a9b9f..d9af95d913 100644
--- a/src/image/SkImageShader.cpp
+++ b/src/image/SkImageShader.cpp
@@ -241,7 +241,7 @@ sk_sp<SkShader> SkMakeBitmapShader(const SkBitmap& src, SkShader::TileMode tmx,
// or modify this assert.
SkASSERT(!allocator || (kNever_SkCopyPixelsMode == cpm));
- return SkImageShader::Make(SkMakeImageFromRasterBitmap(src, cpm).get(),
+ return SkImageShader::Make(SkMakeImageFromRasterBitmap(src, cpm, allocator).get(),
tmx, tmy, localMatrix, allocator);
}
diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp
index 645a3db64b..67d521e345 100644
--- a/src/image/SkImage_Raster.cpp
+++ b/src/image/SkImage_Raster.cpp
@@ -7,6 +7,7 @@
#include "SkImage_Base.h"
#include "SkBitmap.h"
+#include "SkBitmapProcShader.h"
#include "SkCanvas.h"
#include "SkColorTable.h"
#include "SkData.h"
@@ -254,7 +255,8 @@ sk_sp<SkImage> SkMakeImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr,
return sk_make_sp<SkImage_Raster>(info, pr, pixelRefOrigin, rowBytes);
}
-sk_sp<SkImage> SkMakeImageFromRasterBitmap(const SkBitmap& bm, SkCopyPixelsMode cpm) {
+sk_sp<SkImage> SkMakeImageFromRasterBitmap(const SkBitmap& bm, SkCopyPixelsMode cpm,
+ SkTBlitterAllocator* allocator) {
bool hasColorTable = false;
if (kIndex_8_SkColorType == bm.colorType()) {
SkAutoLockPixels autoLockPixels(bm);
@@ -274,7 +276,12 @@ sk_sp<SkImage> SkMakeImageFromRasterBitmap(const SkBitmap& bm, SkCopyPixelsMode
image = SkImage::MakeRasterCopy(pmap);
}
} else {
- image = sk_make_sp<SkImage_Raster>(bm, kNever_SkCopyPixelsMode == cpm);
+ if (allocator) {
+ image.reset(allocator->createT<SkImage_Raster>(bm, kNever_SkCopyPixelsMode == cpm));
+ image.get()->ref(); // account for the allocator being an owner
+ } else {
+ image = sk_make_sp<SkImage_Raster>(bm, kNever_SkCopyPixelsMode == cpm);
+ }
}
return image;
}