Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 | 38 |
| 39 namespace blink { | 39 namespace blink { |
| 40 | 40 |
| 41 CanvasRenderingContext::CanvasRenderingContext( | 41 CanvasRenderingContext::CanvasRenderingContext( |
| 42 HTMLCanvasElement* canvas, | 42 HTMLCanvasElement* canvas, |
| 43 OffscreenCanvas* offscreenCanvas, | 43 OffscreenCanvas* offscreenCanvas, |
| 44 const CanvasContextCreationAttributes& attrs) | 44 const CanvasContextCreationAttributes& attrs) |
| 45 : m_canvas(canvas), | 45 : m_canvas(canvas), |
| 46 m_offscreenCanvas(offscreenCanvas), | 46 m_offscreenCanvas(offscreenCanvas), |
| 47 m_colorSpace(kLegacyCanvasColorSpace), | 47 m_colorSpace(kLegacyCanvasColorSpace), |
| 48 m_gfxColorSpace(gfx::ColorSpace::CreateSRGB()), | |
| 48 m_creationAttributes(attrs) { | 49 m_creationAttributes(attrs) { |
| 49 if (RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled() && | 50 if (RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled() && |
| 50 RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) { | 51 RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) { |
| 51 if (m_creationAttributes.colorSpace() == kSRGBCanvasColorSpaceName) | 52 if (m_creationAttributes.colorSpace() == kSRGBCanvasColorSpaceName) { |
| 52 m_colorSpace = kSRGBCanvasColorSpace; | 53 m_colorSpace = kSRGBCanvasColorSpace; |
| 53 else if (m_creationAttributes.colorSpace() == | 54 } else if (m_creationAttributes.colorSpace() == |
| 54 kLinearRGBCanvasColorSpaceName) | 55 kLinearRGBCanvasColorSpaceName) { |
| 55 m_colorSpace = kLinearRGBCanvasColorSpace; | 56 m_colorSpace = kLinearRGBCanvasColorSpace; |
| 56 else if (m_creationAttributes.colorSpace() == kRec2020CanvasColorSpaceName) | 57 m_gfxColorSpace = gfx::ColorSpace::CreateSCRGBLinear(); |
| 58 } else if (m_creationAttributes.colorSpace() == | |
| 59 kRec2020CanvasColorSpaceName) { | |
| 57 m_colorSpace = kRec2020CanvasColorSpace; | 60 m_colorSpace = kRec2020CanvasColorSpace; |
| 58 else if (m_creationAttributes.colorSpace() == kP3CanvasColorSpaceName) | 61 m_gfxColorSpace = gfx::ColorSpace( |
| 62 gfx::ColorSpace::PrimaryID::BT2020, | |
| 63 gfx::ColorSpace::TransferID::IEC61966_2_1, | |
| 64 gfx::ColorSpace::MatrixID::RGB, gfx::ColorSpace::RangeID::FULL); | |
| 65 } else if (m_creationAttributes.colorSpace() == kP3CanvasColorSpaceName) { | |
| 59 m_colorSpace = kP3CanvasColorSpace; | 66 m_colorSpace = kP3CanvasColorSpace; |
| 67 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
| |
| 68 gfx::ColorSpace::PrimaryID::SMPTEST432_1, | |
| 69 gfx::ColorSpace::TransferID::IEC61966_2_1, | |
| 70 gfx::ColorSpace::MatrixID::RGB, gfx::ColorSpace::RangeID::FULL); | |
| 71 } | |
| 60 } | 72 } |
| 61 // Make m_creationAttributes reflect the effective colorSpace rather than the | 73 // Make m_creationAttributes reflect the effective colorSpace rather than the |
| 62 // requested one | 74 // requested one |
| 63 m_creationAttributes.setColorSpace(colorSpaceAsString()); | 75 m_creationAttributes.setColorSpace(colorSpaceAsString()); |
| 64 } | 76 } |
| 65 | 77 |
| 66 WTF::String CanvasRenderingContext::colorSpaceAsString() const { | 78 WTF::String CanvasRenderingContext::colorSpaceAsString() const { |
| 67 switch (m_colorSpace) { | 79 switch (m_colorSpace) { |
| 68 case kLegacyCanvasColorSpace: | 80 case kLegacyCanvasColorSpace: |
| 69 return kLegacyCanvasColorSpaceName; | 81 return kLegacyCanvasColorSpaceName; |
| 70 case kSRGBCanvasColorSpace: | 82 case kSRGBCanvasColorSpace: |
| 71 return kSRGBCanvasColorSpaceName; | 83 return kSRGBCanvasColorSpaceName; |
| 72 case kLinearRGBCanvasColorSpace: | 84 case kLinearRGBCanvasColorSpace: |
| 73 return kLinearRGBCanvasColorSpaceName; | 85 return kLinearRGBCanvasColorSpaceName; |
| 74 case kRec2020CanvasColorSpace: | 86 case kRec2020CanvasColorSpace: |
| 75 return kRec2020CanvasColorSpaceName; | 87 return kRec2020CanvasColorSpaceName; |
| 76 case kP3CanvasColorSpace: | 88 case kP3CanvasColorSpace: |
| 77 return kP3CanvasColorSpaceName; | 89 return kP3CanvasColorSpaceName; |
| 78 }; | 90 }; |
| 79 CHECK(false); | 91 CHECK(false); |
| 80 return ""; | 92 return ""; |
| 81 } | 93 } |
| 82 | 94 |
| 83 sk_sp<SkColorSpace> CanvasRenderingContext::skColorSpace() const { | 95 sk_sp<SkColorSpace> CanvasRenderingContext::skSurfaceColorSpace() const { |
| 84 if (!RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled() || | 96 if (!RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled() || |
| 85 !RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) { | 97 !RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) { |
| 86 return nullptr; | 98 return nullptr; |
| 87 } | 99 } |
| 88 switch (m_colorSpace) { | 100 return m_gfxColorSpace.ToSkColorSpace(); |
| 89 case kLegacyCanvasColorSpace: | |
| 90 // Legacy colorspace ensures color matching with CSS is preserved. | |
| 91 // So if CSS is color corrected from sRGB to display space, then | |
| 92 // canvas must do the same | |
| 93 return SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); | |
| 94 case kSRGBCanvasColorSpace: | |
| 95 return SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); | |
| 96 case kLinearRGBCanvasColorSpace: | |
| 97 return SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named); | |
| 98 case kRec2020CanvasColorSpace: { | |
| 99 // TODO(zakerinasab): Replace this with proper constructor from Skia | |
| 100 // when it is provided. | |
| 101 // https://en.wikipedia.org/wiki/Rec._2020 | |
| 102 SkColorSpacePrimaries kPrimaries = {0.708, 0.292, 0.170, 0.797, | |
| 103 0.131, 0.046, 0.3127, 0.3290}; | |
| 104 SkMatrix44 kToXYZD50; | |
| 105 if (!kPrimaries.toXYZD50(&kToXYZD50)) | |
| 106 return nullptr; | |
| 107 return SkColorSpace::MakeRGB( | |
| 108 SkColorSpace::RenderTargetGamma::kLinear_RenderTargetGamma, | |
| 109 kToXYZD50); | |
| 110 } | |
| 111 case kP3CanvasColorSpace: { | |
| 112 // TODO(zakerinasab): Replace this with proper constructor from Skia | |
| 113 // when it is provided. | |
| 114 // https://en.wikipedia.org/wiki/DCI-P3 | |
| 115 SkColorSpacePrimaries kPrimaries = {0.680, 0.320, 0.265, 0.690, | |
| 116 0.150, 0.060, 0.3127, 0.3290}; | |
| 117 SkMatrix44 kToXYZD50; | |
| 118 if (!kPrimaries.toXYZD50(&kToXYZD50)) | |
| 119 return nullptr; | |
| 120 return SkColorSpace::MakeRGB( | |
| 121 SkColorSpace::RenderTargetGamma::kLinear_RenderTargetGamma, | |
| 122 kToXYZD50); | |
| 123 } | |
| 124 }; | |
| 125 CHECK(false); | |
| 126 return nullptr; | |
| 127 } | 101 } |
| 128 | 102 |
| 129 ColorBehavior CanvasRenderingContext::colorBehaviorForMediaDrawnToCanvas() | 103 ColorBehavior CanvasRenderingContext::colorBehaviorForMediaDrawnToCanvas() |
| 130 const { | 104 const { |
| 131 sk_sp<SkColorSpace> colorSpace = skColorSpace(); | 105 if (!RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled() || |
| 132 if (colorSpace) { | 106 !RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) { |
| 133 return ColorBehavior::transformTo(std::move(colorSpace)); | 107 return ColorBehavior::transformToGlobalTarget(); |
| 134 } | 108 } |
| 135 return ColorBehavior::transformToGlobalTarget(); | 109 return ColorBehavior::transformTo(m_gfxColorSpace); |
| 136 } | 110 } |
| 137 | 111 |
| 138 SkColorType CanvasRenderingContext::colorType() const { | 112 SkColorType CanvasRenderingContext::colorType() const { |
| 139 switch (m_colorSpace) { | 113 switch (m_colorSpace) { |
| 140 case kLinearRGBCanvasColorSpace: | 114 case kLinearRGBCanvasColorSpace: |
| 141 case kRec2020CanvasColorSpace: | 115 case kRec2020CanvasColorSpace: |
| 142 case kP3CanvasColorSpace: | 116 case kP3CanvasColorSpace: |
| 143 return kRGBA_F16_SkColorType; | 117 return kRGBA_F16_SkColorType; |
| 144 default: | 118 default: |
| 145 return kN32_SkColorType; | 119 return kN32_SkColorType; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 } | 190 } |
| 217 return taintOrigin; | 191 return taintOrigin; |
| 218 } | 192 } |
| 219 | 193 |
| 220 DEFINE_TRACE(CanvasRenderingContext) { | 194 DEFINE_TRACE(CanvasRenderingContext) { |
| 221 visitor->trace(m_canvas); | 195 visitor->trace(m_canvas); |
| 222 visitor->trace(m_offscreenCanvas); | 196 visitor->trace(m_offscreenCanvas); |
| 223 } | 197 } |
| 224 | 198 |
| 225 } // namespace blink | 199 } // namespace blink |
| OLD | NEW |