OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "core/offscreencanvas/OffscreenCanvas.h" | 5 #include "core/offscreencanvas/OffscreenCanvas.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include "core/dom/ExceptionCode.h" | 8 #include "core/dom/ExceptionCode.h" |
9 #include "core/dom/ExecutionContext.h" | 9 #include "core/dom/ExecutionContext.h" |
10 #include "core/fileapi/Blob.h" | 10 #include "core/fileapi/Blob.h" |
11 #include "core/frame/ImageBitmap.h" | 11 #include "core/frame/ImageBitmap.h" |
12 #include "core/html/ImageData.h" | 12 #include "core/html/ImageData.h" |
13 #include "core/html/canvas/CanvasAsyncBlobCreator.h" | 13 #include "core/html/canvas/CanvasAsyncBlobCreator.h" |
14 #include "core/html/canvas/CanvasContextCreationAttributes.h" | 14 #include "core/html/canvas/CanvasContextCreationAttributes.h" |
15 #include "core/html/canvas/CanvasRenderingContext.h" | 15 #include "core/html/canvas/CanvasRenderingContext.h" |
16 #include "core/html/canvas/CanvasRenderingContextFactory.h" | 16 #include "core/html/canvas/CanvasRenderingContextFactory.h" |
17 #include "platform/graphics/Image.h" | 17 #include "platform/graphics/Image.h" |
18 #include "platform/graphics/ImageBuffer.h" | 18 #include "platform/graphics/ImageBuffer.h" |
19 #include "platform/graphics/OffscreenCanvasFrameDispatcherImpl.h" | 19 #include "platform/graphics/OffscreenCanvasFrameDispatcherImpl.h" |
20 #include "platform/graphics/StaticBitmapImage.h" | 20 #include "platform/graphics/StaticBitmapImage.h" |
21 #include "platform/image-encoders/ImageEncoderUtils.h" | 21 #include "platform/image-encoders/ImageEncoderUtils.h" |
| 22 #include "platform/instrumentation/tracing/TraceEvent.h" |
22 #include "platform/wtf/MathExtras.h" | 23 #include "platform/wtf/MathExtras.h" |
23 #include "public/platform/Platform.h" | 24 #include "public/platform/Platform.h" |
24 #include "third_party/skia/include/core/SkSurface.h" | 25 #include "third_party/skia/include/core/SkSurface.h" |
25 | 26 |
26 namespace blink { | 27 namespace blink { |
27 | 28 |
28 OffscreenCanvas::OffscreenCanvas(const IntSize& size) : size_(size) {} | 29 OffscreenCanvas::OffscreenCanvas(const IntSize& size) : size_(size) {} |
29 | 30 |
30 OffscreenCanvas* OffscreenCanvas::Create(unsigned width, unsigned height) { | 31 OffscreenCanvas* OffscreenCanvas::Create(unsigned width, unsigned height) { |
31 return new OffscreenCanvas( | 32 return new OffscreenCanvas( |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 this, client_id_, sink_id_, placeholder_canvas_id_, size_.Width(), | 234 this, client_id_, sink_id_, placeholder_canvas_id_, size_.Width(), |
234 size_.Height())); | 235 size_.Height())); |
235 } | 236 } |
236 return frame_dispatcher_.get(); | 237 return frame_dispatcher_.get(); |
237 } | 238 } |
238 | 239 |
239 ScriptPromise OffscreenCanvas::Commit(RefPtr<StaticBitmapImage> image, | 240 ScriptPromise OffscreenCanvas::Commit(RefPtr<StaticBitmapImage> image, |
240 bool is_web_gl_software_rendering, | 241 bool is_web_gl_software_rendering, |
241 ScriptState* script_state, | 242 ScriptState* script_state, |
242 ExceptionState& exception_state) { | 243 ExceptionState& exception_state) { |
| 244 TRACE_EVENT0("blink", "OffscreenCanvas::Commit"); |
| 245 |
243 if (!HasPlaceholderCanvas()) { | 246 if (!HasPlaceholderCanvas()) { |
244 exception_state.ThrowDOMException( | 247 exception_state.ThrowDOMException( |
245 kInvalidStateError, | 248 kInvalidStateError, |
246 "Commit() was called on a context whose " | 249 "Commit() was called on a context whose " |
247 "OffscreenCanvas is not associated with a " | 250 "OffscreenCanvas is not associated with a " |
248 "canvas element."); | 251 "canvas element."); |
249 return exception_state.Reject(script_state); | 252 return exception_state.Reject(script_state); |
250 } | 253 } |
251 | 254 |
252 GetOrCreateFrameDispatcher()->SetNeedsBeginFrame(true); | 255 GetOrCreateFrameDispatcher()->SetNeedsBeginFrame(true); |
(...skipping 26 matching lines...) Expand all Loading... |
279 if (current_frame_) { | 282 if (current_frame_) { |
280 // TODO(eseckler): OffscreenCanvas shouldn't dispatch CompositorFrames | 283 // TODO(eseckler): OffscreenCanvas shouldn't dispatch CompositorFrames |
281 // without a prior BeginFrame. | 284 // without a prior BeginFrame. |
282 DoCommit(std::move(current_frame_), | 285 DoCommit(std::move(current_frame_), |
283 current_frame_is_web_gl_software_rendering_); | 286 current_frame_is_web_gl_software_rendering_); |
284 } | 287 } |
285 } | 288 } |
286 | 289 |
287 void OffscreenCanvas::DoCommit(RefPtr<StaticBitmapImage> image, | 290 void OffscreenCanvas::DoCommit(RefPtr<StaticBitmapImage> image, |
288 bool is_web_gl_software_rendering) { | 291 bool is_web_gl_software_rendering) { |
| 292 TRACE_EVENT0("blink", "OffscreenCanvas::DoCommit"); |
289 double commit_start_time = WTF::MonotonicallyIncreasingTime(); | 293 double commit_start_time = WTF::MonotonicallyIncreasingTime(); |
290 GetOrCreateFrameDispatcher()->DispatchFrame( | 294 GetOrCreateFrameDispatcher()->DispatchFrame( |
291 std::move(image), commit_start_time, is_web_gl_software_rendering); | 295 std::move(image), commit_start_time, is_web_gl_software_rendering); |
292 } | 296 } |
293 | 297 |
294 void OffscreenCanvas::BeginFrame() { | 298 void OffscreenCanvas::BeginFrame() { |
| 299 TRACE_EVENT0("blink", "OffscreenCanvas::BeginFrame"); |
295 if (current_frame_) { | 300 if (current_frame_) { |
296 // TODO(eseckler): beginFrame() shouldn't be used as confirmation of | 301 // TODO(eseckler): beginFrame() shouldn't be used as confirmation of |
297 // CompositorFrame activation. | 302 // CompositorFrame activation. |
298 // If we have an overdraw backlog, push the frame from the backlog | 303 // If we have an overdraw backlog, push the frame from the backlog |
299 // first and save the promise resolution for later. | 304 // first and save the promise resolution for later. |
300 // Then we need to wait for one more frame time to resolve the existing | 305 // Then we need to wait for one more frame time to resolve the existing |
301 // promise. | 306 // promise. |
302 DoCommit(std::move(current_frame_), | 307 DoCommit(std::move(current_frame_), |
303 current_frame_is_web_gl_software_rendering_); | 308 current_frame_is_web_gl_software_rendering_); |
304 } else if (commit_promise_resolver_) { | 309 } else if (commit_promise_resolver_) { |
305 commit_promise_resolver_->Resolve(); | 310 commit_promise_resolver_->Resolve(); |
306 commit_promise_resolver_.Clear(); | 311 commit_promise_resolver_.Clear(); |
| 312 |
307 // We need to tell parent frame to stop sending signals on begin frame to | 313 // We need to tell parent frame to stop sending signals on begin frame to |
308 // avoid overhead once we resolve the promise. | 314 // avoid overhead once we resolve the promise. |
309 GetOrCreateFrameDispatcher()->SetNeedsBeginFrame(false); | 315 GetOrCreateFrameDispatcher()->SetNeedsBeginFrame(false); |
310 } | 316 } |
311 } | 317 } |
312 | 318 |
313 ScriptPromise OffscreenCanvas::convertToBlob(ScriptState* script_state, | 319 ScriptPromise OffscreenCanvas::convertToBlob(ScriptState* script_state, |
314 const ImageEncodeOptions& options, | 320 const ImageEncodeOptions& options, |
315 ExceptionState& exception_state) { | 321 ExceptionState& exception_state) { |
316 if (this->IsNeutered()) { | 322 if (this->IsNeutered()) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 } | 368 } |
363 | 369 |
364 DEFINE_TRACE(OffscreenCanvas) { | 370 DEFINE_TRACE(OffscreenCanvas) { |
365 visitor->Trace(context_); | 371 visitor->Trace(context_); |
366 visitor->Trace(execution_context_); | 372 visitor->Trace(execution_context_); |
367 visitor->Trace(commit_promise_resolver_); | 373 visitor->Trace(commit_promise_resolver_); |
368 EventTargetWithInlineData::Trace(visitor); | 374 EventTargetWithInlineData::Trace(visitor); |
369 } | 375 } |
370 | 376 |
371 } // namespace blink | 377 } // namespace blink |
OLD | NEW |