| 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 |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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/CanvasContextCreationAttributes.h" |
| 28 #include "core/html/canvas/CanvasImageSource.h" | 29 #include "core/html/canvas/CanvasImageSource.h" |
| 29 #include "platform/RuntimeEnabledFeatures.h" | 30 #include "platform/RuntimeEnabledFeatures.h" |
| 30 #include "platform/weborigin/SecurityOrigin.h" | 31 #include "platform/weborigin/SecurityOrigin.h" |
| 31 | 32 |
| 33 const char * const kLinearRGBCanvasColorSpaceName = "linear-rgb"; |
| 34 const char * const kSRGBCanvasColorSpaceName = "srgb"; |
| 35 const char * const kLegacyCanvasColorSpaceName = "legacy-srgb"; |
| 36 |
| 32 namespace blink { | 37 namespace blink { |
| 33 | 38 |
| 34 CanvasRenderingContext::CanvasRenderingContext(HTMLCanvasElement* canvas, Offscr
eenCanvas* offscreenCanvas) | 39 CanvasRenderingContext::CanvasRenderingContext(HTMLCanvasElement* canvas, Offscr
eenCanvas* offscreenCanvas, const CanvasContextCreationAttributes& attrs) |
| 35 : m_canvas(canvas) | 40 : m_canvas(canvas) |
| 36 , m_offscreenCanvas(offscreenCanvas) | 41 , m_offscreenCanvas(offscreenCanvas) |
| 42 , m_colorSpace(kLegacyCanvasColorSpace) |
| 43 , m_creationAttributes(attrs) |
| 37 { | 44 { |
| 45 if (RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled()) { |
| 46 if (m_creationAttributes.colorSpace() == kSRGBCanvasColorSpaceName) |
| 47 m_colorSpace = kSRGBCanvasColorSpace; |
| 48 else if (m_creationAttributes.colorSpace() == kLinearRGBCanvasColorSpace
Name) |
| 49 m_colorSpace = kLinearRGBCanvasColorSpace; |
| 50 } |
| 51 // Make m_creationAttributes reflect the effective colorSpace rather than th
e requested one |
| 52 m_creationAttributes.setColorSpace(colorSpaceAsString()); |
| 53 } |
| 54 |
| 55 WTF::String CanvasRenderingContext::colorSpaceAsString() const |
| 56 { |
| 57 switch (m_colorSpace) { |
| 58 case kSRGBCanvasColorSpace: |
| 59 return kSRGBCanvasColorSpaceName; |
| 60 case kLinearRGBCanvasColorSpace: |
| 61 return kLinearRGBCanvasColorSpaceName; |
| 62 case kLegacyCanvasColorSpace: |
| 63 return kLegacyCanvasColorSpaceName; |
| 64 }; |
| 65 CHECK(false); |
| 66 return ""; |
| 67 } |
| 68 |
| 69 sk_sp<SkColorSpace> CanvasRenderingContext::skColorSpace() const |
| 70 { |
| 71 switch (m_colorSpace) { |
| 72 case kSRGBCanvasColorSpace: |
| 73 return SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); |
| 74 case kLinearRGBCanvasColorSpace: |
| 75 { |
| 76 // Creating a temp srgb colorspace just to get the matrix. |
| 77 // There should be a better way |
| 78 sk_sp<SkColorSpace> tmp = SkColorSpace::NewNamed(SkColorSpace::kSRGB
_Named); |
| 79 return SkColorSpace::NewRGB(SkColorSpace::kLinear_GammaNamed, tmp->x
yz()); |
| 80 } |
| 81 case kLegacyCanvasColorSpace: |
| 82 // TODO(crbug.com/637381): To uncomment the following block of code we n
eed |
| 83 // it to not cause a bunch of test failures. |
| 84 /* |
| 85 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) { |
| 86 // Legacy colorspace ensures color matching with CSS is preserved. |
| 87 // So if CSS is color corrected from sRGB to display space, then |
| 88 // canvas must do the same |
| 89 return SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); |
| 90 } |
| 91 */ |
| 92 return nullptr; |
| 93 }; |
| 94 CHECK(false); |
| 95 return nullptr; |
| 38 } | 96 } |
| 39 | 97 |
| 40 void CanvasRenderingContext::dispose() | 98 void CanvasRenderingContext::dispose() |
| 41 { | 99 { |
| 42 // HTMLCanvasElement and CanvasRenderingContext have a circular reference. | 100 // HTMLCanvasElement and CanvasRenderingContext have a circular reference. |
| 43 // When the pair is no longer reachable, their destruction order is non- | 101 // 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 | 102 // 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 | 103 // the other in order to break the circular reference. This is to avoid |
| 46 // an error when CanvasRenderingContext2D::didProcessTask() is invoked | 104 // an error when CanvasRenderingContext2D::didProcessTask() is invoked |
| 47 // after the HTMLCanvasElement is destroyed. | 105 // after the HTMLCanvasElement is destroyed. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 return taintOrigin; | 156 return taintOrigin; |
| 99 } | 157 } |
| 100 | 158 |
| 101 DEFINE_TRACE(CanvasRenderingContext) | 159 DEFINE_TRACE(CanvasRenderingContext) |
| 102 { | 160 { |
| 103 visitor->trace(m_canvas); | 161 visitor->trace(m_canvas); |
| 104 visitor->trace(m_offscreenCanvas); | 162 visitor->trace(m_offscreenCanvas); |
| 105 } | 163 } |
| 106 | 164 |
| 107 } // namespace blink | 165 } // namespace blink |
| OLD | NEW |