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

Unified Diff: third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext.cpp

Issue 2660393002: Use gfx::ColorSpace instead of SkColorSpace in Blink (Closed)
Patch Set: Created 3 years, 11 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: third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext.cpp
diff --git a/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext.cpp b/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext.cpp
index bd781c8500381138b634443d9e3d8d3221d1efcd..2d138c24b64bd38fafd4457f5c14328ff5bdac3f 100644
--- a/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext.cpp
+++ b/third_party/WebKit/Source/core/html/canvas/CanvasRenderingContext.cpp
@@ -45,18 +45,30 @@ CanvasRenderingContext::CanvasRenderingContext(
: m_canvas(canvas),
m_offscreenCanvas(offscreenCanvas),
m_colorSpace(kLegacyCanvasColorSpace),
+ m_gfxColorSpace(gfx::ColorSpace::CreateSRGB()),
m_creationAttributes(attrs) {
if (RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled() &&
RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) {
- if (m_creationAttributes.colorSpace() == kSRGBCanvasColorSpaceName)
+ if (m_creationAttributes.colorSpace() == kSRGBCanvasColorSpaceName) {
m_colorSpace = kSRGBCanvasColorSpace;
- else if (m_creationAttributes.colorSpace() ==
- kLinearRGBCanvasColorSpaceName)
+ } else if (m_creationAttributes.colorSpace() ==
+ kLinearRGBCanvasColorSpaceName) {
m_colorSpace = kLinearRGBCanvasColorSpace;
- else if (m_creationAttributes.colorSpace() == kRec2020CanvasColorSpaceName)
+ m_gfxColorSpace = gfx::ColorSpace::CreateSCRGBLinear();
+ } else if (m_creationAttributes.colorSpace() ==
+ kRec2020CanvasColorSpaceName) {
m_colorSpace = kRec2020CanvasColorSpace;
- else if (m_creationAttributes.colorSpace() == kP3CanvasColorSpaceName)
+ m_gfxColorSpace = gfx::ColorSpace(
+ gfx::ColorSpace::PrimaryID::BT2020,
+ gfx::ColorSpace::TransferID::IEC61966_2_1,
+ gfx::ColorSpace::MatrixID::RGB, gfx::ColorSpace::RangeID::FULL);
+ } else if (m_creationAttributes.colorSpace() == kP3CanvasColorSpaceName) {
m_colorSpace = kP3CanvasColorSpace;
+ m_gfxColorSpace = gfx::ColorSpace(
Justin Novosad 2017/01/31 00:15:58 I am a bit concerned about having this duplication
ccameron 2017/01/31 05:34:26 Yeah, that was unnecessary optimization. Got rid o
+ gfx::ColorSpace::PrimaryID::SMPTEST432_1,
+ gfx::ColorSpace::TransferID::IEC61966_2_1,
+ gfx::ColorSpace::MatrixID::RGB, gfx::ColorSpace::RangeID::FULL);
+ }
}
// Make m_creationAttributes reflect the effective colorSpace rather than the
// requested one
@@ -80,59 +92,21 @@ WTF::String CanvasRenderingContext::colorSpaceAsString() const {
return "";
}
-sk_sp<SkColorSpace> CanvasRenderingContext::skColorSpace() const {
+sk_sp<SkColorSpace> CanvasRenderingContext::skSurfaceColorSpace() const {
if (!RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled() ||
!RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) {
return nullptr;
}
- switch (m_colorSpace) {
- case kLegacyCanvasColorSpace:
- // Legacy colorspace ensures color matching with CSS is preserved.
- // So if CSS is color corrected from sRGB to display space, then
- // canvas must do the same
- return SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
- case kSRGBCanvasColorSpace:
- return SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
- case kLinearRGBCanvasColorSpace:
- return SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named);
- case kRec2020CanvasColorSpace: {
- // TODO(zakerinasab): Replace this with proper constructor from Skia
- // when it is provided.
- // https://en.wikipedia.org/wiki/Rec._2020
- SkColorSpacePrimaries kPrimaries = {0.708, 0.292, 0.170, 0.797,
- 0.131, 0.046, 0.3127, 0.3290};
- SkMatrix44 kToXYZD50;
- if (!kPrimaries.toXYZD50(&kToXYZD50))
- return nullptr;
- return SkColorSpace::MakeRGB(
- SkColorSpace::RenderTargetGamma::kLinear_RenderTargetGamma,
- kToXYZD50);
- }
- case kP3CanvasColorSpace: {
- // TODO(zakerinasab): Replace this with proper constructor from Skia
- // when it is provided.
- // https://en.wikipedia.org/wiki/DCI-P3
- SkColorSpacePrimaries kPrimaries = {0.680, 0.320, 0.265, 0.690,
- 0.150, 0.060, 0.3127, 0.3290};
- SkMatrix44 kToXYZD50;
- if (!kPrimaries.toXYZD50(&kToXYZD50))
- return nullptr;
- return SkColorSpace::MakeRGB(
- SkColorSpace::RenderTargetGamma::kLinear_RenderTargetGamma,
- kToXYZD50);
- }
- };
- CHECK(false);
- return nullptr;
+ return m_gfxColorSpace.ToSkColorSpace();
}
ColorBehavior CanvasRenderingContext::colorBehaviorForMediaDrawnToCanvas()
const {
- sk_sp<SkColorSpace> colorSpace = skColorSpace();
- if (colorSpace) {
- return ColorBehavior::transformTo(std::move(colorSpace));
+ if (!RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled() ||
+ !RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) {
+ return ColorBehavior::transformToGlobalTarget();
}
- return ColorBehavior::transformToGlobalTarget();
+ return ColorBehavior::transformTo(m_gfxColorSpace);
}
SkColorType CanvasRenderingContext::colorType() const {

Powered by Google App Engine
This is Rietveld 408576698