OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.h" | 5 #include "modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.h" |
6 | 6 |
7 #include "bindings/modules/v8/OffscreenCanvasRenderingContext2DOrWebGLRenderingC
ontextOrWebGL2RenderingContext.h" | 7 #include "bindings/modules/v8/OffscreenCanvasRenderingContext2DOrWebGLRenderingC
ontextOrWebGL2RenderingContext.h" |
| 8 #include "core/dom/ExecutionContext.h" |
8 #include "core/frame/ImageBitmap.h" | 9 #include "core/frame/ImageBitmap.h" |
9 #include "core/frame/Settings.h" | 10 #include "core/frame/Settings.h" |
10 #include "core/workers/WorkerGlobalScope.h" | 11 #include "core/workers/WorkerGlobalScope.h" |
11 #include "core/workers/WorkerSettings.h" | 12 #include "core/workers/WorkerSettings.h" |
12 #include "platform/graphics/ImageBuffer.h" | 13 #include "platform/graphics/ImageBuffer.h" |
13 #include "platform/graphics/StaticBitmapImage.h" | 14 #include "platform/graphics/StaticBitmapImage.h" |
14 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 15 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
15 #include "platform/graphics/gpu/AcceleratedImageBufferSurface.h" | 16 #include "platform/graphics/gpu/AcceleratedImageBufferSurface.h" |
16 #include "platform/graphics/paint/PaintCanvas.h" | 17 #include "platform/graphics/paint/PaintCanvas.h" |
17 #include "platform/wtf/Assertions.h" | 18 #include "platform/wtf/Assertions.h" |
18 #include "platform/wtf/CurrentTime.h" | 19 #include "platform/wtf/CurrentTime.h" |
19 | 20 |
20 namespace blink { | 21 namespace blink { |
21 | 22 |
22 OffscreenCanvasRenderingContext2D::~OffscreenCanvasRenderingContext2D() {} | 23 OffscreenCanvasRenderingContext2D::~OffscreenCanvasRenderingContext2D() {} |
23 | 24 |
24 OffscreenCanvasRenderingContext2D::OffscreenCanvasRenderingContext2D( | 25 OffscreenCanvasRenderingContext2D::OffscreenCanvasRenderingContext2D( |
25 ScriptState* script_state, | 26 ScriptState* script_state, |
26 OffscreenCanvas* canvas, | 27 OffscreenCanvas* canvas, |
27 const CanvasContextCreationAttributes& attrs) | 28 const CanvasContextCreationAttributes& attrs) |
28 : CanvasRenderingContext(nullptr, canvas, attrs) { | 29 : CanvasRenderingContext(nullptr, canvas, attrs) { |
29 ExecutionContext* execution_context = script_state->GetExecutionContext(); | 30 ExecutionContext* execution_context = ExecutionContext::From(script_state); |
30 if (execution_context->IsDocument()) { | 31 if (execution_context->IsDocument()) { |
31 if (ToDocument(execution_context) | 32 if (ToDocument(execution_context) |
32 ->GetSettings() | 33 ->GetSettings() |
33 ->GetDisableReadingFromCanvas()) | 34 ->GetDisableReadingFromCanvas()) |
34 canvas->SetDisableReadingFromCanvasTrue(); | 35 canvas->SetDisableReadingFromCanvasTrue(); |
35 return; | 36 return; |
36 } | 37 } |
37 | 38 |
38 WorkerSettings* worker_settings = | 39 WorkerSettings* worker_settings = |
39 ToWorkerGlobalScope(execution_context)->GetWorkerSettings(); | 40 ToWorkerGlobalScope(execution_context)->GetWorkerSettings(); |
40 if (worker_settings && worker_settings->DisableReadingFromCanvas()) | 41 if (worker_settings && worker_settings->DisableReadingFromCanvas()) |
41 canvas->SetDisableReadingFromCanvasTrue(); | 42 canvas->SetDisableReadingFromCanvasTrue(); |
42 } | 43 } |
43 | 44 |
44 DEFINE_TRACE(OffscreenCanvasRenderingContext2D) { | 45 DEFINE_TRACE(OffscreenCanvasRenderingContext2D) { |
45 CanvasRenderingContext::Trace(visitor); | 46 CanvasRenderingContext::Trace(visitor); |
46 BaseRenderingContext2D::Trace(visitor); | 47 BaseRenderingContext2D::Trace(visitor); |
47 } | 48 } |
48 | 49 |
49 ScriptPromise OffscreenCanvasRenderingContext2D::commit( | 50 ScriptPromise OffscreenCanvasRenderingContext2D::commit( |
50 ScriptState* script_state, | 51 ScriptState* script_state, |
51 ExceptionState& exception_state) { | 52 ExceptionState& exception_state) { |
52 UseCounter::Feature feature = UseCounter::kOffscreenCanvasCommit2D; | 53 UseCounter::Feature feature = UseCounter::kOffscreenCanvasCommit2D; |
53 UseCounter::Count(script_state->GetExecutionContext(), feature); | 54 UseCounter::Count(ExecutionContext::From(script_state), feature); |
54 if (!offscreenCanvas()->HasPlaceholderCanvas()) { | 55 if (!offscreenCanvas()->HasPlaceholderCanvas()) { |
55 // If an OffscreenCanvas has no associated canvas Id, it indicates that | 56 // If an OffscreenCanvas has no associated canvas Id, it indicates that |
56 // it is not an OffscreenCanvas created by transfering control from html | 57 // it is not an OffscreenCanvas created by transfering control from html |
57 // canvas. | 58 // canvas. |
58 exception_state.ThrowDOMException( | 59 exception_state.ThrowDOMException( |
59 kInvalidStateError, | 60 kInvalidStateError, |
60 "Commit() was called on a context whose " | 61 "Commit() was called on a context whose " |
61 "OffscreenCanvas is not associated with a " | 62 "OffscreenCanvas is not associated with a " |
62 "canvas element."); | 63 "canvas element."); |
63 return exception_state.Reject(script_state); | 64 return exception_state.Reject(script_state); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 RefPtr<StaticBitmapImage> image = | 151 RefPtr<StaticBitmapImage> image = |
151 StaticBitmapImage::Create(std::move(sk_image)); | 152 StaticBitmapImage::Create(std::move(sk_image)); |
152 image->SetOriginClean(this->OriginClean()); | 153 image->SetOriginClean(this->OriginClean()); |
153 return image; | 154 return image; |
154 } | 155 } |
155 | 156 |
156 ImageBitmap* OffscreenCanvasRenderingContext2D::TransferToImageBitmap( | 157 ImageBitmap* OffscreenCanvasRenderingContext2D::TransferToImageBitmap( |
157 ScriptState* script_state) { | 158 ScriptState* script_state) { |
158 UseCounter::Feature feature = | 159 UseCounter::Feature feature = |
159 UseCounter::kOffscreenCanvasTransferToImageBitmap2D; | 160 UseCounter::kOffscreenCanvasTransferToImageBitmap2D; |
160 UseCounter::Count(script_state->GetExecutionContext(), feature); | 161 UseCounter::Count(ExecutionContext::From(script_state), feature); |
161 RefPtr<StaticBitmapImage> image = TransferToStaticBitmapImage(); | 162 RefPtr<StaticBitmapImage> image = TransferToStaticBitmapImage(); |
162 if (!image) | 163 if (!image) |
163 return nullptr; | 164 return nullptr; |
164 image_buffer_.reset(); // "Transfer" means no retained buffer | 165 image_buffer_.reset(); // "Transfer" means no retained buffer |
165 needs_matrix_clip_restore_ = true; | 166 needs_matrix_clip_restore_ = true; |
166 return ImageBitmap::Create(std::move(image)); | 167 return ImageBitmap::Create(std::move(image)); |
167 } | 168 } |
168 | 169 |
169 PassRefPtr<Image> OffscreenCanvasRenderingContext2D::GetImage( | 170 PassRefPtr<Image> OffscreenCanvasRenderingContext2D::GetImage( |
170 AccelerationHint hint, | 171 AccelerationHint hint, |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 } | 253 } |
253 | 254 |
254 bool OffscreenCanvasRenderingContext2D::IsPaintable() const { | 255 bool OffscreenCanvasRenderingContext2D::IsPaintable() const { |
255 return this->GetImageBuffer(); | 256 return this->GetImageBuffer(); |
256 } | 257 } |
257 | 258 |
258 bool OffscreenCanvasRenderingContext2D::IsAccelerated() const { | 259 bool OffscreenCanvasRenderingContext2D::IsAccelerated() const { |
259 return image_buffer_ && image_buffer_->IsAccelerated(); | 260 return image_buffer_ && image_buffer_->IsAccelerated(); |
260 } | 261 } |
261 } | 262 } |
OLD | NEW |