| 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/CanvasContextCreationAttributes.h" | 28 #include "core/html/canvas/CanvasContextCreationAttributes.h" |
| 29 #include "core/html/canvas/CanvasImageSource.h" | 29 #include "core/html/canvas/CanvasImageSource.h" |
| 30 #include "platform/RuntimeEnabledFeatures.h" | 30 #include "platform/RuntimeEnabledFeatures.h" |
| 31 #include "platform/weborigin/SecurityOrigin.h" | 31 #include "platform/weborigin/SecurityOrigin.h" |
| 32 #include "public/platform/Platform.h" |
| 32 | 33 |
| 33 constexpr const char* kLegacyCanvasColorSpaceName = "legacy-srgb"; | 34 constexpr const char* kLegacyCanvasColorSpaceName = "legacy-srgb"; |
| 34 constexpr const char* kSRGBCanvasColorSpaceName = "srgb"; | 35 constexpr const char* kSRGBCanvasColorSpaceName = "srgb"; |
| 35 constexpr const char* kLinearRGBCanvasColorSpaceName = "linear-rgb"; | 36 constexpr const char* kLinearRGBCanvasColorSpaceName = "linear-rgb"; |
| 36 constexpr const char* kRec2020CanvasColorSpaceName = "rec-2020"; | 37 constexpr const char* kRec2020CanvasColorSpaceName = "rec-2020"; |
| 37 constexpr const char* kP3CanvasColorSpaceName = "p3"; | 38 constexpr const char* kP3CanvasColorSpaceName = "p3"; |
| 38 | 39 |
| 39 namespace blink { | 40 namespace blink { |
| 40 | 41 |
| 41 CanvasRenderingContext::CanvasRenderingContext( | 42 CanvasRenderingContext::CanvasRenderingContext( |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 case kLinearRGBCanvasColorSpace: | 121 case kLinearRGBCanvasColorSpace: |
| 121 case kRec2020CanvasColorSpace: | 122 case kRec2020CanvasColorSpace: |
| 122 case kP3CanvasColorSpace: | 123 case kP3CanvasColorSpace: |
| 123 return kRGBA_F16_SkColorType; | 124 return kRGBA_F16_SkColorType; |
| 124 default: | 125 default: |
| 125 return kN32_SkColorType; | 126 return kN32_SkColorType; |
| 126 } | 127 } |
| 127 } | 128 } |
| 128 | 129 |
| 129 void CanvasRenderingContext::dispose() { | 130 void CanvasRenderingContext::dispose() { |
| 131 if (m_finalizeFrameScheduled) { |
| 132 Platform::current()->currentThread()->removeTaskObserver(this); |
| 133 } |
| 134 |
| 130 // HTMLCanvasElement and CanvasRenderingContext have a circular reference. | 135 // HTMLCanvasElement and CanvasRenderingContext have a circular reference. |
| 131 // When the pair is no longer reachable, their destruction order is non- | 136 // When the pair is no longer reachable, their destruction order is non- |
| 132 // deterministic, so the first of the two to be destroyed needs to notify | 137 // deterministic, so the first of the two to be destroyed needs to notify |
| 133 // the other in order to break the circular reference. This is to avoid | 138 // the other in order to break the circular reference. This is to avoid |
| 134 // an error when CanvasRenderingContext2D::didProcessTask() is invoked | 139 // an error when CanvasRenderingContext::didProcessTask() is invoked |
| 135 // after the HTMLCanvasElement is destroyed. | 140 // after the HTMLCanvasElement is destroyed. |
| 136 if (canvas()) { | 141 if (canvas()) { |
| 137 canvas()->detachContext(); | 142 canvas()->detachContext(); |
| 138 m_canvas = nullptr; | 143 m_canvas = nullptr; |
| 139 } | 144 } |
| 140 if (offscreenCanvas()) { | 145 if (offscreenCanvas()) { |
| 141 offscreenCanvas()->detachContext(); | 146 offscreenCanvas()->detachContext(); |
| 142 m_offscreenCanvas = nullptr; | 147 m_offscreenCanvas = nullptr; |
| 143 } | 148 } |
| 144 } | 149 } |
| 145 | 150 |
| 151 void CanvasRenderingContext::didDraw(const SkIRect& dirtyRect) { |
| 152 canvas()->didDraw(SkRect::Make(dirtyRect)); |
| 153 if (!m_finalizeFrameScheduled) { |
| 154 m_finalizeFrameScheduled = true; |
| 155 Platform::current()->currentThread()->addTaskObserver(this); |
| 156 } |
| 157 } |
| 158 |
| 159 void CanvasRenderingContext::didProcessTask() { |
| 160 Platform::current()->currentThread()->removeTaskObserver(this); |
| 161 m_finalizeFrameScheduled = false; |
| 162 |
| 163 if (!canvas()) |
| 164 return; |
| 165 |
| 166 // The end of a script task that drew content to the canvas is the point |
| 167 // at which the current frame may be considered complete. |
| 168 canvas()->finalizeFrame(); |
| 169 } |
| 170 |
| 146 CanvasRenderingContext::ContextType CanvasRenderingContext::contextTypeFromId( | 171 CanvasRenderingContext::ContextType CanvasRenderingContext::contextTypeFromId( |
| 147 const String& id) { | 172 const String& id) { |
| 148 if (id == "2d") | 173 if (id == "2d") |
| 149 return Context2d; | 174 return Context2d; |
| 150 if (id == "experimental-webgl") | 175 if (id == "experimental-webgl") |
| 151 return ContextExperimentalWebgl; | 176 return ContextExperimentalWebgl; |
| 152 if (id == "webgl") | 177 if (id == "webgl") |
| 153 return ContextWebgl; | 178 return ContextWebgl; |
| 154 if (id == "webgl2") | 179 if (id == "webgl2") |
| 155 return ContextWebgl2; | 180 return ContextWebgl2; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 221 } |
| 197 return taintOrigin; | 222 return taintOrigin; |
| 198 } | 223 } |
| 199 | 224 |
| 200 DEFINE_TRACE(CanvasRenderingContext) { | 225 DEFINE_TRACE(CanvasRenderingContext) { |
| 201 visitor->trace(m_canvas); | 226 visitor->trace(m_canvas); |
| 202 visitor->trace(m_offscreenCanvas); | 227 visitor->trace(m_offscreenCanvas); |
| 203 } | 228 } |
| 204 | 229 |
| 205 } // namespace blink | 230 } // namespace blink |
| OLD | NEW |