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