| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 case kLinearRGBCanvasColorSpace: | 141 case kLinearRGBCanvasColorSpace: |
| 141 case kRec2020CanvasColorSpace: | 142 case kRec2020CanvasColorSpace: |
| 142 case kP3CanvasColorSpace: | 143 case kP3CanvasColorSpace: |
| 143 return kRGBA_F16_SkColorType; | 144 return kRGBA_F16_SkColorType; |
| 144 default: | 145 default: |
| 145 return kN32_SkColorType; | 146 return kN32_SkColorType; |
| 146 } | 147 } |
| 147 } | 148 } |
| 148 | 149 |
| 149 void CanvasRenderingContext::dispose() { | 150 void CanvasRenderingContext::dispose() { |
| 151 if (m_finalizeFrameScheduled) { |
| 152 Platform::current()->currentThread()->removeTaskObserver(this); |
| 153 } |
| 154 |
| 150 // HTMLCanvasElement and CanvasRenderingContext have a circular reference. | 155 // HTMLCanvasElement and CanvasRenderingContext have a circular reference. |
| 151 // When the pair is no longer reachable, their destruction order is non- | 156 // When the pair is no longer reachable, their destruction order is non- |
| 152 // deterministic, so the first of the two to be destroyed needs to notify | 157 // deterministic, so the first of the two to be destroyed needs to notify |
| 153 // the other in order to break the circular reference. This is to avoid | 158 // the other in order to break the circular reference. This is to avoid |
| 154 // an error when CanvasRenderingContext2D::didProcessTask() is invoked | 159 // an error when CanvasRenderingContext::didProcessTask() is invoked |
| 155 // after the HTMLCanvasElement is destroyed. | 160 // after the HTMLCanvasElement is destroyed. |
| 156 if (canvas()) { | 161 if (canvas()) { |
| 157 canvas()->detachContext(); | 162 canvas()->detachContext(); |
| 158 m_canvas = nullptr; | 163 m_canvas = nullptr; |
| 159 } | 164 } |
| 160 if (offscreenCanvas()) { | 165 if (offscreenCanvas()) { |
| 161 offscreenCanvas()->detachContext(); | 166 offscreenCanvas()->detachContext(); |
| 162 m_offscreenCanvas = nullptr; | 167 m_offscreenCanvas = nullptr; |
| 163 } | 168 } |
| 164 } | 169 } |
| 165 | 170 |
| 171 void CanvasRenderingContext::didDraw(const SkIRect& dirtyRect) { |
| 172 canvas()->didDraw(SkRect::Make(dirtyRect)); |
| 173 if (!m_finalizeFrameScheduled) { |
| 174 m_finalizeFrameScheduled = true; |
| 175 Platform::current()->currentThread()->addTaskObserver(this); |
| 176 } |
| 177 } |
| 178 |
| 179 void CanvasRenderingContext::didProcessTask() { |
| 180 Platform::current()->currentThread()->removeTaskObserver(this); |
| 181 m_finalizeFrameScheduled = false; |
| 182 |
| 183 if (!canvas()) |
| 184 return; |
| 185 |
| 186 // The end of a script task that drew content to the canvas is the point |
| 187 // at which the current frame may be considered complete. |
| 188 canvas()->finalizeFrame(); |
| 189 } |
| 190 |
| 166 CanvasRenderingContext::ContextType CanvasRenderingContext::contextTypeFromId( | 191 CanvasRenderingContext::ContextType CanvasRenderingContext::contextTypeFromId( |
| 167 const String& id) { | 192 const String& id) { |
| 168 if (id == "2d") | 193 if (id == "2d") |
| 169 return Context2d; | 194 return Context2d; |
| 170 if (id == "experimental-webgl") | 195 if (id == "experimental-webgl") |
| 171 return ContextExperimentalWebgl; | 196 return ContextExperimentalWebgl; |
| 172 if (id == "webgl") | 197 if (id == "webgl") |
| 173 return ContextWebgl; | 198 return ContextWebgl; |
| 174 if (id == "webgl2") | 199 if (id == "webgl2") |
| 175 return ContextWebgl2; | 200 return ContextWebgl2; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 } | 241 } |
| 217 return taintOrigin; | 242 return taintOrigin; |
| 218 } | 243 } |
| 219 | 244 |
| 220 DEFINE_TRACE(CanvasRenderingContext) { | 245 DEFINE_TRACE(CanvasRenderingContext) { |
| 221 visitor->trace(m_canvas); | 246 visitor->trace(m_canvas); |
| 222 visitor->trace(m_offscreenCanvas); | 247 visitor->trace(m_offscreenCanvas); |
| 223 } | 248 } |
| 224 | 249 |
| 225 } // namespace blink | 250 } // namespace blink |
| OLD | NEW |