Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Unified Diff: src/core/SkSpecialImage.cpp

Issue 2163343002: Adding color space to SkSpecialImage (Closed) Base URL: https://skia.googlesource.com/skia.git@colorspace-on-image
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/core/SkSpecialImage.cpp
diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp
index 23334991885d17c85a512e0dab931cf3c0ae994f..d19b8306d6714b79c90f3731de72438454f8f3d9 100644
--- a/src/core/SkSpecialImage.cpp
+++ b/src/core/SkSpecialImage.cpp
@@ -39,6 +39,8 @@ public:
virtual GrTexture* onPeekTexture() const { return nullptr; }
+ virtual SkColorSpace* onGetColorSpace() const = 0;
+
#if SK_SUPPORT_GPU
virtual sk_sp<GrTexture> onAsTextureRef(GrContext* context) const = 0;
#endif
@@ -101,7 +103,8 @@ sk_sp<SkSpecialImage> SkSpecialImage::makeTextureImage(GrContext* context) {
return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(resultTex->width(), resultTex->height()),
this->uniqueID(),
- resultTex, &this->props(), at);
+ resultTex, sk_ref_sp(this->getColorSpace()), &this->props(),
+ at);
#else
return nullptr;
#endif
@@ -134,6 +137,10 @@ GrContext* SkSpecialImage::getContext() const {
return nullptr;
}
+SkColorSpace* SkSpecialImage::getColorSpace() const {
+ return as_SIB(this)->onGetColorSpace();
+}
+
#if SK_SUPPORT_GPU
sk_sp<GrTexture> SkSpecialImage::asTextureRef(GrContext* context) const {
return as_SIB(this)->onAsTextureRef(context);
@@ -169,6 +176,7 @@ sk_sp<SkSpecialImage> SkSpecialImage::internal_fromBM(const SkBitmap& src,
return SkSpecialImage::MakeFromGpu(src.bounds(),
src.getGenerationID(),
sk_ref_sp(src.getTexture()),
+ sk_ref_sp(src.colorSpace()),
props);
}
#endif
@@ -229,6 +237,10 @@ public:
return as_IB(fImage)->getROPixels(bm);
}
+ SkColorSpace* onGetColorSpace() const override {
+ return as_IB(fImage)->onImageInfo().colorSpace();
+ }
+
GrTexture* onPeekTexture() const override { return as_IB(fImage)->peekTexture(); }
#if SK_SUPPORT_GPU
@@ -244,7 +256,8 @@ public:
if (GrTexture* texture = as_IB(fImage.get())->peekTexture()) {
const SkImageInfo info = GrMakeInfoFromTexture(texture,
fImage->width(), fImage->height(),
- fImage->isOpaque());
+ fImage->isOpaque(),
+ sk_ref_sp(this->onGetColorSpace()));
if (!result->setInfo(info)) {
return false;
}
@@ -363,6 +376,10 @@ public:
return true;
}
+ SkColorSpace* onGetColorSpace() const override {
+ return fBitmap.colorSpace();
+ }
+
#if SK_SUPPORT_GPU
sk_sp<GrTexture> onAsTextureRef(GrContext* context) const override {
if (context) {
@@ -444,10 +461,11 @@ class SkSpecialImage_Gpu : public SkSpecialImage_Base {
public:
SkSpecialImage_Gpu(const SkIRect& subset,
uint32_t uniqueID, sk_sp<GrTexture> tex, SkAlphaType at,
- const SkSurfaceProps* props)
+ sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* props)
: INHERITED(subset, uniqueID, props)
, fTexture(std::move(tex))
, fAlphaType(at)
+ , fColorSpace(std::move(colorSpace))
, fAddedRasterVersionToCache(false) {
}
@@ -467,10 +485,9 @@ public:
SkRect dst = SkRect::MakeXYWH(x, y,
this->subset().width(), this->subset().height());
- // TODO: Supply correct color space after we're storing it here
auto img = sk_sp<SkImage>(new SkImage_Gpu(fTexture->width(), fTexture->height(),
this->uniqueID(), fAlphaType, fTexture.get(),
- nullptr, SkBudgeted::kNo));
+ fColorSpace, SkBudgeted::kNo));
canvas->drawImageRect(img, this->subset(),
dst, paint, SkCanvas::kStrict_SrcRectConstraint);
@@ -490,7 +507,8 @@ public:
SkImageInfo info = SkImageInfo::MakeN32(this->width(), this->height(),
this->isOpaque() ? kOpaque_SkAlphaType
- : kPremul_SkAlphaType);
+ : kPremul_SkAlphaType,
+ fColorSpace);
if (!dst->tryAllocPixels(info)) {
return false;
@@ -507,10 +525,14 @@ public:
return true;
}
+ SkColorSpace* onGetColorSpace() const override {
+ return fColorSpace.get();
+ }
+
bool getBitmapDeprecated(SkBitmap* result) const override {
const SkImageInfo info = GrMakeInfoFromTexture(fTexture.get(),
this->width(), this->height(),
- this->isOpaque());
+ this->isOpaque(), fColorSpace);
if (!result->setInfo(info)) {
return false;
}
@@ -538,6 +560,7 @@ public:
return SkSpecialImage::MakeFromGpu(subset,
this->uniqueID(),
fTexture,
+ fColorSpace,
&this->props(),
fAlphaType);
}
@@ -547,10 +570,10 @@ public:
fTexture->width() == subset.width() &&
fTexture->height() == subset.height()) {
// The existing GrTexture is already tight so reuse it in the SkImage
- // TODO: Supply correct color space after we're storing it here
return sk_make_sp<SkImage_Gpu>(fTexture->width(), fTexture->height(),
kNeedNewImageUniqueID,
- fAlphaType, fTexture.get(), nullptr, SkBudgeted::kYes);
+ fAlphaType, fTexture.get(), fColorSpace,
+ SkBudgeted::kYes);
}
GrContext* ctx = fTexture->getContext();
@@ -563,9 +586,8 @@ public:
return nullptr;
}
ctx->copySurface(subTx.get(), fTexture.get(), subset, SkIPoint::Make(0, 0));
- // TODO: Supply correct color space after we're storing it here
return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID,
- fAlphaType, subTx.get(), nullptr, SkBudgeted::kYes);
+ fAlphaType, subTx.get(), fColorSpace, SkBudgeted::kYes);
}
sk_sp<SkSurface> onMakeTightSurface(const SkImageInfo& info) const override {
@@ -575,6 +597,7 @@ public:
private:
sk_sp<GrTexture> fTexture;
const SkAlphaType fAlphaType;
+ sk_sp<SkColorSpace> fColorSpace;
mutable SkAtomic<bool> fAddedRasterVersionToCache;
typedef SkSpecialImage_Base INHERITED;
@@ -583,10 +606,12 @@ private:
sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(const SkIRect& subset,
uint32_t uniqueID,
sk_sp<GrTexture> tex,
+ sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* props,
SkAlphaType at) {
SkASSERT(rect_fits(subset, tex->width(), tex->height()));
- return sk_make_sp<SkSpecialImage_Gpu>(subset, uniqueID, std::move(tex), at, props);
+ return sk_make_sp<SkSpecialImage_Gpu>(subset, uniqueID, std::move(tex), at,
+ std::move(colorSpace), props);
}
#endif

Powered by Google App Engine
This is Rietveld 408576698