SkPixmap::setColorSpace
Landed for reed@ with bug fix:
Use default copy constructor for SkDraw
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2057563002
patch from issue 2057563002 at patchset 1 (http://crrev.com/2057563002#ps1)
Review-Url: https://codereview.chromium.org/2052943002
diff --git a/include/core/SkDraw.h b/include/core/SkDraw.h
index 892aec9..d7068fd 100644
--- a/include/core/SkDraw.h
+++ b/include/core/SkDraw.h
@@ -30,7 +30,6 @@
class SkDraw {
public:
SkDraw();
- SkDraw(const SkDraw& src);
void drawPaint(const SkPaint&) const;
void drawPoints(SkCanvas::PointMode, size_t count, const SkPoint[],
diff --git a/include/core/SkImageInfo.h b/include/core/SkImageInfo.h
index 2d89fbf..2be04ff 100644
--- a/include/core/SkImageInfo.h
+++ b/include/core/SkImageInfo.h
@@ -285,6 +285,10 @@
return SkImageInfo(fWidth, fHeight, newColorType, fAlphaType, fProfileType, fColorSpace);
}
+ SkImageInfo makeColorSpace(sk_sp<SkColorSpace> cs) const {
+ return SkImageInfo::Make(fWidth, fHeight, fColorType, fAlphaType, std::move(cs));
+ }
+
int bytesPerPixel() const { return SkColorTypeBytesPerPixel(fColorType); }
int shiftPerPixel() const { return SkColorTypeShiftPerPixel(fColorType); }
diff --git a/include/core/SkPixmap.h b/include/core/SkPixmap.h
index c3c27be..699ddb4 100644
--- a/include/core/SkPixmap.h
+++ b/include/core/SkPixmap.h
@@ -44,6 +44,9 @@
this->reset(info, NULL, 0, NULL);
}
+ // overrides the colorspace in the SkImageInfo of the pixmap
+ void setColorSpace(sk_sp<SkColorSpace>);
+
/**
* If supported, set this pixmap to point to the pixels in the specified mask and return true.
* On failure, return false and set this pixmap to empty.
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp
index f838cc1..24fc906 100644
--- a/src/core/SkDraw.cpp
+++ b/src/core/SkDraw.cpp
@@ -114,10 +114,6 @@
sk_bzero(this, sizeof(*this));
}
-SkDraw::SkDraw(const SkDraw& src) {
- memcpy(this, &src, sizeof(*this));
-}
-
bool SkDraw::computeConservativeLocalClipBounds(SkRect* localBounds) const {
if (fRC->isEmpty()) {
return false;
diff --git a/src/core/SkImageInfo.cpp b/src/core/SkImageInfo.cpp
index 7a2558e..88f1ed6 100644
--- a/src/core/SkImageInfo.cpp
+++ b/src/core/SkImageInfo.cpp
@@ -32,7 +32,13 @@
SkImageInfo SkImageInfo::Make(int width, int height, SkColorType ct, SkAlphaType at,
sk_sp<SkColorSpace> cs) {
- return SkImageInfo(width, height, ct, at, SkDefaultColorProfile(), std::move(cs));
+ SkColorProfileType pt = SkDefaultColorProfile();
+ // try to keep the enum and the colorspace in sync.
+ // TODO: eliminate the enum entirely, now that we have colorspace objects
+ if (cs && (SkColorSpace::kLinear_GammaNamed != cs->gammaNamed())) {
+ pt = kSRGB_SkColorProfileType;
+ }
+ return SkImageInfo(width, height, ct, at, pt, std::move(cs));
}
SkImageInfo SkImageInfo::MakeS32(int width, int height, SkAlphaType at) {
diff --git a/src/core/SkPixmap.cpp b/src/core/SkPixmap.cpp
index bd551ed..887fdb4 100644
--- a/src/core/SkPixmap.cpp
+++ b/src/core/SkPixmap.cpp
@@ -52,6 +52,10 @@
return false;
}
+void SkPixmap::setColorSpace(sk_sp<SkColorSpace> cs) {
+ fInfo = fInfo.makeColorSpace(std::move(cs));
+}
+
bool SkPixmap::extractSubset(SkPixmap* result, const SkIRect& subset) const {
SkIRect srcRect, r;
srcRect.set(0, 0, this->width(), this->height());