| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 return kLinearRGBCanvasColorSpaceName; | 73 return kLinearRGBCanvasColorSpaceName; |
| 74 case kRec2020CanvasColorSpace: | 74 case kRec2020CanvasColorSpace: |
| 75 return kRec2020CanvasColorSpaceName; | 75 return kRec2020CanvasColorSpaceName; |
| 76 case kP3CanvasColorSpace: | 76 case kP3CanvasColorSpace: |
| 77 return kP3CanvasColorSpaceName; | 77 return kP3CanvasColorSpaceName; |
| 78 }; | 78 }; |
| 79 CHECK(false); | 79 CHECK(false); |
| 80 return ""; | 80 return ""; |
| 81 } | 81 } |
| 82 | 82 |
| 83 sk_sp<SkColorSpace> CanvasRenderingContext::skColorSpace() const { | 83 gfx::ColorSpace CanvasRenderingContext::gfxColorSpace() const { |
| 84 if (!RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled() || | |
| 85 !RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) { | |
| 86 return nullptr; | |
| 87 } | |
| 88 switch (m_colorSpace) { | 84 switch (m_colorSpace) { |
| 89 case kLegacyCanvasColorSpace: | 85 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: | 86 case kSRGBCanvasColorSpace: |
| 95 return SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); | 87 return gfx::ColorSpace::CreateSRGB(); |
| 96 case kLinearRGBCanvasColorSpace: | 88 case kLinearRGBCanvasColorSpace: |
| 97 return SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named); | 89 return gfx::ColorSpace::CreateSCRGBLinear(); |
| 98 case kRec2020CanvasColorSpace: { | 90 case kRec2020CanvasColorSpace: |
| 99 // TODO(zakerinasab): Replace this with proper constructor from Skia | 91 return gfx::ColorSpace(gfx::ColorSpace::PrimaryID::BT2020, |
| 100 // when it is provided. | 92 gfx::ColorSpace::TransferID::IEC61966_2_1); |
| 101 // https://en.wikipedia.org/wiki/Rec._2020 | 93 case kP3CanvasColorSpace: |
| 102 SkColorSpacePrimaries kPrimaries = {0.708, 0.292, 0.170, 0.797, | 94 return gfx::ColorSpace(gfx::ColorSpace::PrimaryID::SMPTEST432_1, |
| 103 0.131, 0.046, 0.3127, 0.3290}; | 95 gfx::ColorSpace::TransferID::IEC61966_2_1); |
| 104 SkMatrix44 kToXYZD50; | 96 } |
| 105 if (!kPrimaries.toXYZD50(&kToXYZD50)) | 97 NOTREACHED(); |
| 106 return nullptr; | 98 return gfx::ColorSpace(); |
| 107 return SkColorSpace::MakeRGB( | 99 } |
| 108 SkColorSpace::RenderTargetGamma::kLinear_RenderTargetGamma, | 100 |
| 109 kToXYZD50); | 101 sk_sp<SkColorSpace> CanvasRenderingContext::skSurfaceColorSpace() const { |
| 110 } | 102 if (skSurfacesUseColorSpace()) |
| 111 case kP3CanvasColorSpace: { | 103 return gfxColorSpace().ToSkColorSpace(); |
| 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; | 104 return nullptr; |
| 127 } | 105 } |
| 128 | 106 |
| 107 bool CanvasRenderingContext::skSurfacesUseColorSpace() const { |
| 108 return m_colorSpace != kLegacyCanvasColorSpace; |
| 109 } |
| 110 |
| 129 ColorBehavior CanvasRenderingContext::colorBehaviorForMediaDrawnToCanvas() | 111 ColorBehavior CanvasRenderingContext::colorBehaviorForMediaDrawnToCanvas() |
| 130 const { | 112 const { |
| 131 sk_sp<SkColorSpace> colorSpace = skColorSpace(); | 113 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) |
| 132 if (colorSpace) { | 114 return ColorBehavior::transformTo(gfxColorSpace()); |
| 133 return ColorBehavior::transformTo(std::move(colorSpace)); | |
| 134 } | |
| 135 return ColorBehavior::transformToGlobalTarget(); | 115 return ColorBehavior::transformToGlobalTarget(); |
| 136 } | 116 } |
| 137 | 117 |
| 138 SkColorType CanvasRenderingContext::colorType() const { | 118 SkColorType CanvasRenderingContext::colorType() const { |
| 139 switch (m_colorSpace) { | 119 switch (m_colorSpace) { |
| 140 case kLinearRGBCanvasColorSpace: | 120 case kLinearRGBCanvasColorSpace: |
| 141 case kRec2020CanvasColorSpace: | 121 case kRec2020CanvasColorSpace: |
| 142 case kP3CanvasColorSpace: | 122 case kP3CanvasColorSpace: |
| 143 return kRGBA_F16_SkColorType; | 123 return kRGBA_F16_SkColorType; |
| 144 default: | 124 default: |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 } | 196 } |
| 217 return taintOrigin; | 197 return taintOrigin; |
| 218 } | 198 } |
| 219 | 199 |
| 220 DEFINE_TRACE(CanvasRenderingContext) { | 200 DEFINE_TRACE(CanvasRenderingContext) { |
| 221 visitor->trace(m_canvas); | 201 visitor->trace(m_canvas); |
| 222 visitor->trace(m_offscreenCanvas); | 202 visitor->trace(m_offscreenCanvas); |
| 223 } | 203 } |
| 224 | 204 |
| 225 } // namespace blink | 205 } // namespace blink |
| OLD | NEW |