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 const char* const kLinearRGBCanvasColorSpaceName = "linear-rgb"; | 34 const char* const kLinearRGBCanvasColorSpaceName = "linear-rgb"; |
34 const char* const kSRGBCanvasColorSpaceName = "srgb"; | 35 const char* const kSRGBCanvasColorSpaceName = "srgb"; |
35 const char* const kLegacyCanvasColorSpaceName = "legacy-srgb"; | 36 const char* const kLegacyCanvasColorSpaceName = "legacy-srgb"; |
36 | 37 |
37 namespace blink { | 38 namespace blink { |
38 | 39 |
39 CanvasRenderingContext::CanvasRenderingContext( | 40 CanvasRenderingContext::CanvasRenderingContext( |
40 HTMLCanvasElement* canvas, | 41 HTMLCanvasElement* canvas, |
41 OffscreenCanvas* offscreenCanvas, | 42 OffscreenCanvas* offscreenCanvas, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 SkColorType CanvasRenderingContext::colorType() const { | 102 SkColorType CanvasRenderingContext::colorType() const { |
102 switch (m_colorSpace) { | 103 switch (m_colorSpace) { |
103 case kLinearRGBCanvasColorSpace: | 104 case kLinearRGBCanvasColorSpace: |
104 return kRGBA_F16_SkColorType; | 105 return kRGBA_F16_SkColorType; |
105 default: | 106 default: |
106 return kN32_SkColorType; | 107 return kN32_SkColorType; |
107 } | 108 } |
108 } | 109 } |
109 | 110 |
110 void CanvasRenderingContext::dispose() { | 111 void CanvasRenderingContext::dispose() { |
112 if (m_finalizeFrameScheduled) { | |
113 Platform::current()->currentThread()->removeTaskObserver(this); | |
114 } | |
115 | |
111 // HTMLCanvasElement and CanvasRenderingContext have a circular reference. | 116 // HTMLCanvasElement and CanvasRenderingContext have a circular reference. |
112 // When the pair is no longer reachable, their destruction order is non- | 117 // When the pair is no longer reachable, their destruction order is non- |
113 // deterministic, so the first of the two to be destroyed needs to notify | 118 // deterministic, so the first of the two to be destroyed needs to notify |
114 // the other in order to break the circular reference. This is to avoid | 119 // the other in order to break the circular reference. This is to avoid |
115 // an error when CanvasRenderingContext2D::didProcessTask() is invoked | 120 // an error when CanvasRenderingContext2D::didProcessTask() is invoked |
xlai (Olivia)
2017/01/27 22:23:25
Update the comment.
Justin Novosad
2017/02/07 21:52:29
Done.
| |
116 // after the HTMLCanvasElement is destroyed. | 121 // after the HTMLCanvasElement is destroyed. |
117 if (canvas()) { | 122 if (canvas()) { |
118 canvas()->detachContext(); | 123 canvas()->detachContext(); |
119 m_canvas = nullptr; | 124 m_canvas = nullptr; |
120 } | 125 } |
121 if (offscreenCanvas()) { | 126 if (offscreenCanvas()) { |
122 offscreenCanvas()->detachContext(); | 127 offscreenCanvas()->detachContext(); |
123 m_offscreenCanvas = nullptr; | 128 m_offscreenCanvas = nullptr; |
124 } | 129 } |
125 } | 130 } |
126 | 131 |
132 void CanvasRenderingContext::didDraw(const SkIRect& dirtyRect) { | |
133 canvas()->didDraw(SkRect::Make(dirtyRect)); | |
134 if (!m_finalizeFrameScheduled) { | |
135 m_finalizeFrameScheduled = true; | |
136 Platform::current()->currentThread()->addTaskObserver(this); | |
137 } | |
138 } | |
139 | |
140 void CanvasRenderingContext::didProcessTask() { | |
141 Platform::current()->currentThread()->removeTaskObserver(this); | |
142 m_finalizeFrameScheduled = false; | |
143 | |
144 if (!canvas()) | |
145 return; | |
146 | |
147 canvas()->finalizeFrame(); | |
xlai (Olivia)
2017/01/27 22:23:25
Can you add a comment here explaining why you call
Justin Novosad
2017/02/07 21:52:29
Done.
| |
148 } | |
149 | |
127 CanvasRenderingContext::ContextType CanvasRenderingContext::contextTypeFromId( | 150 CanvasRenderingContext::ContextType CanvasRenderingContext::contextTypeFromId( |
128 const String& id) { | 151 const String& id) { |
129 if (id == "2d") | 152 if (id == "2d") |
130 return Context2d; | 153 return Context2d; |
131 if (id == "experimental-webgl") | 154 if (id == "experimental-webgl") |
132 return ContextExperimentalWebgl; | 155 return ContextExperimentalWebgl; |
133 if (id == "webgl") | 156 if (id == "webgl") |
134 return ContextWebgl; | 157 return ContextWebgl; |
135 if (id == "webgl2") | 158 if (id == "webgl2") |
136 return ContextWebgl2; | 159 return ContextWebgl2; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 } | 200 } |
178 return taintOrigin; | 201 return taintOrigin; |
179 } | 202 } |
180 | 203 |
181 DEFINE_TRACE(CanvasRenderingContext) { | 204 DEFINE_TRACE(CanvasRenderingContext) { |
182 visitor->trace(m_canvas); | 205 visitor->trace(m_canvas); |
183 visitor->trace(m_offscreenCanvas); | 206 visitor->trace(m_offscreenCanvas); |
184 } | 207 } |
185 | 208 |
186 } // namespace blink | 209 } // namespace blink |
OLD | NEW |