aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/image/SkImage_Raster.cpp
diff options
context:
space:
mode:
authorGravatar Matt Sarett <msarett@google.com>2017-06-08 09:37:01 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-06-08 19:07:54 +0000
commitdc792701012a99d3b7499952df1e55031fa4b795 (patch)
tree06b40f93c7c3274d792d2790b9f319b54e47413c /src/image/SkImage_Raster.cpp
parent81c83a7db4e524b19d33bf7c8a9b537b9d606c93 (diff)
Draw time color xform API for Android
Will do a lazy color xform to the dst color space at GPU upload time. I've included the capability to control the gen id of the output image. This will allow us to reuse images in the Ganesh cache. This should only be temporary. When Android is able to cache the actual SkImage object, we won't need to expose this anymore. Bug: b/62347704 Change-Id: I93b950ef680f6bbdd7eb6a2ec6f50195dbb78311 Reviewed-on: https://skia-review.googlesource.com/16440 Reviewed-by: Mike Reed <reed@google.com> Reviewed-by: Yuqian Li <liyuqian@google.com> Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Matt Sarett <msarett@google.com>
Diffstat (limited to 'src/image/SkImage_Raster.cpp')
-rw-r--r--src/image/SkImage_Raster.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp
index 5b55c44685..ce0957901b 100644
--- a/src/image/SkImage_Raster.cpp
+++ b/src/image/SkImage_Raster.cpp
@@ -10,6 +10,7 @@
#include "SkBitmapProcShader.h"
#include "SkCanvas.h"
#include "SkColorSpaceXform_Base.h"
+#include "SkColorSpaceXformImageGenerator.h"
#include "SkColorSpaceXformPriv.h"
#include "SkColorTable.h"
#include "SkData.h"
@@ -321,6 +322,28 @@ sk_sp<SkImage> SkMakeImageFromRasterBitmap(const SkBitmap& bm, SkCopyPixelsMode
return SkMakeImageFromRasterBitmapPriv(bm, cpm);
}
+sk_sp<SkImage> SkMakeImageInColorSpace(const SkBitmap& bm, sk_sp<SkColorSpace> dstCS, uint32_t id) {
+ if (!SkImageInfoIsValidAllowNumericalCS(bm.info()) || !bm.getPixels() ||
+ bm.rowBytes() < bm.info().minRowBytes() || !dstCS) {
+ return nullptr;
+ }
+
+ sk_sp<SkColorSpace> srcCS = bm.info().refColorSpace();
+ if (!srcCS) {
+ // Treat nullptr as sRGB.
+ srcCS = SkColorSpace::MakeSRGB();
+ }
+
+ // For the Android use case, this is very likely to be true.
+ if (SkColorSpace::Equals(srcCS.get(), dstCS.get())) {
+ SkASSERT(0 == id || bm.getGenerationID() == id);
+ return SkMakeImageFromRasterBitmapPriv(bm, kNever_SkCopyPixelsMode);
+ }
+
+ return SkImage::MakeFromGenerator(SkColorSpaceXformImageGenerator::Make(
+ bm, dstCS, kNever_SkCopyPixelsMode, id));
+}
+
const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* image) {
return ((const SkImage_Raster*)image)->getPixelRef();
}