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 11 matching lines...) Expand all Loading... | |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "core/html/canvas/CanvasRenderingContext.h" | 26 #include "core/html/canvas/CanvasRenderingContext.h" |
| 27 | 27 |
| 28 #include "core/html/canvas/CanvasImageSource.h" | 28 #include "core/html/canvas/CanvasImageSource.h" |
| 29 #include "platform/RuntimeEnabledFeatures.h" | 29 #include "platform/RuntimeEnabledFeatures.h" |
| 30 #include "platform/weborigin/SecurityOrigin.h" | 30 #include "platform/weborigin/SecurityOrigin.h" |
| 31 | 31 |
| 32 const char * const kLinearRGBCanvasColorSpaceName = "linear-rgb"; | |
| 33 const char * const kSRGBCanvasColorSpaceName = "srgb"; | |
| 34 const char * const kLegacyCanvasColorSpaceName = "legacy-srgb"; | |
| 35 | |
| 32 namespace blink { | 36 namespace blink { |
| 33 | 37 |
| 34 CanvasRenderingContext::CanvasRenderingContext(HTMLCanvasElement* canvas, Offscr eenCanvas* offscreenCanvas) | 38 CanvasRenderingContext::CanvasRenderingContext(HTMLCanvasElement* canvas, Offscr eenCanvas* offscreenCanvas, const String& colorSpace) |
| 35 : m_canvas(canvas) | 39 : m_canvas(canvas) |
| 36 , m_offscreenCanvas(offscreenCanvas) | 40 , m_offscreenCanvas(offscreenCanvas) |
| 41 , m_colorSpace(kLegacyCanvasColorSpace) | |
| 37 { | 42 { |
| 43 if (RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled()) { | |
| 44 if (colorSpace == kSRGBCanvasColorSpaceName) | |
| 45 m_colorSpace = kSRGBCanvasColorSpace; | |
| 46 else if (colorSpace == kLinearRGBCanvasColorSpaceName) | |
| 47 m_colorSpace = kLinearRGBCanvasColorSpace; | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 WTF::String CanvasRenderingContext::colorSpaceAsString() const | |
| 52 { | |
| 53 switch (m_colorSpace) { | |
| 54 case kSRGBCanvasColorSpace: | |
| 55 return kSRGBCanvasColorSpaceName; | |
| 56 case kLinearRGBCanvasColorSpace: | |
| 57 return kLinearRGBCanvasColorSpaceName; | |
| 58 case kLegacyCanvasColorSpace: | |
| 59 return kLegacyCanvasColorSpaceName; | |
| 60 }; | |
| 61 CHECK(0); | |
|
Stephen White
2016/08/11 20:41:27
Nit: CHECK(false) seems to be more common than CHE
Justin Novosad
2016/08/12 17:40:18
Done.
| |
| 62 return ""; | |
| 63 } | |
| 64 | |
| 65 sk_sp<SkColorSpace> CanvasRenderingContext::skColorSpace() const | |
| 66 { | |
| 67 switch (m_colorSpace) { | |
| 68 case kSRGBCanvasColorSpace: | |
| 69 return SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); | |
| 70 case kLinearRGBCanvasColorSpace: | |
| 71 { | |
| 72 // Creating a temp srgb colorspace just to get the matrix. | |
| 73 // There should be a better way | |
| 74 sk_sp<SkColorSpace> tmp = SkColorSpace::NewNamed(SkColorSpace::kSRGB _Named); | |
| 75 return SkColorSpace::NewRGB(SkColorSpace::kLinear_GammaNamed, tmp->x yz()); | |
| 76 } | |
| 77 case kLegacyCanvasColorSpace: | |
| 78 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) { | |
| 79 // Legacy colorspace ensures color matching with CSS is preserved. | |
| 80 // So if CSS is color corrected from sRGB to display space, then | |
| 81 // canvas must do the same | |
| 82 return SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); | |
| 83 } | |
| 84 return nullptr; | |
| 85 }; | |
| 86 CHECK(0); | |
|
Stephen White
2016/08/11 20:41:27
Ibid.
Justin Novosad
2016/08/12 17:40:18
Done.
| |
| 87 return nullptr; | |
| 38 } | 88 } |
| 39 | 89 |
| 40 void CanvasRenderingContext::dispose() | 90 void CanvasRenderingContext::dispose() |
| 41 { | 91 { |
| 42 // HTMLCanvasElement and CanvasRenderingContext have a circular reference. | 92 // HTMLCanvasElement and CanvasRenderingContext have a circular reference. |
| 43 // When the pair is no longer reachable, their destruction order is non- | 93 // When the pair is no longer reachable, their destruction order is non- |
| 44 // deterministic, so the first of the two to be destroyed needs to notify | 94 // deterministic, so the first of the two to be destroyed needs to notify |
| 45 // the other in order to break the circular reference. This is to avoid | 95 // the other in order to break the circular reference. This is to avoid |
| 46 // an error when CanvasRenderingContext2D::didProcessTask() is invoked | 96 // an error when CanvasRenderingContext2D::didProcessTask() is invoked |
| 47 // after the HTMLCanvasElement is destroyed. | 97 // after the HTMLCanvasElement is destroyed. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 return taintOrigin; | 148 return taintOrigin; |
| 99 } | 149 } |
| 100 | 150 |
| 101 DEFINE_TRACE(CanvasRenderingContext) | 151 DEFINE_TRACE(CanvasRenderingContext) |
| 102 { | 152 { |
| 103 visitor->trace(m_canvas); | 153 visitor->trace(m_canvas); |
| 104 visitor->trace(m_offscreenCanvas); | 154 visitor->trace(m_offscreenCanvas); |
| 105 } | 155 } |
| 106 | 156 |
| 107 } // namespace blink | 157 } // namespace blink |
| OLD | NEW |