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 "platform/graphics/OffscreenCanvasFrameDispatcherImpl.h" | 5 #include "platform/graphics/OffscreenCanvasFrameDispatcherImpl.h" |
6 | 6 |
7 #include "cc/output/compositor_frame.h" | 7 #include "cc/output/compositor_frame.h" |
8 #include "cc/quads/texture_draw_quad.h" | 8 #include "cc/quads/texture_draw_quad.h" |
9 #include "gpu/command_buffer/client/gles2_interface.h" | 9 #include "gpu/command_buffer/client/gles2_interface.h" |
10 #include "platform/CrossThreadFunctional.h" | 10 #include "platform/CrossThreadFunctional.h" |
11 #include "platform/Histogram.h" | 11 #include "platform/Histogram.h" |
12 #include "platform/WebTaskRunner.h" | 12 #include "platform/WebTaskRunner.h" |
13 #include "platform/graphics/OffscreenCanvasPlaceholder.h" | 13 #include "platform/graphics/OffscreenCanvasPlaceholder.h" |
14 #include "platform/graphics/gpu/SharedGpuContext.h" | 14 #include "platform/graphics/gpu/SharedGpuContext.h" |
15 #include "platform/wtf/typed_arrays/ArrayBuffer.h" | 15 #include "platform/wtf/typed_arrays/ArrayBuffer.h" |
16 #include "platform/wtf/typed_arrays/Uint8Array.h" | 16 #include "platform/wtf/typed_arrays/Uint8Array.h" |
17 #include "public/platform/InterfaceProvider.h" | 17 #include "public/platform/InterfaceProvider.h" |
18 #include "public/platform/Platform.h" | 18 #include "public/platform/Platform.h" |
19 #include "public/platform/WebGraphicsContext3DProvider.h" | 19 #include "public/platform/WebGraphicsContext3DProvider.h" |
20 #include "public/platform/modules/offscreencanvas/offscreen_canvas_surface.mojom
-blink.h" | 20 #include "public/platform/modules/offscreencanvas/offscreen_canvas_surface.mojom
-blink.h" |
21 #include "third_party/khronos/GLES2/gl2.h" | 21 #include "third_party/khronos/GLES2/gl2.h" |
22 #include "third_party/khronos/GLES2/gl2ext.h" | 22 #include "third_party/khronos/GLES2/gl2ext.h" |
23 #include "third_party/skia/include/core/SkColor.h" | 23 #include "third_party/skia/include/core/SkColor.h" |
24 #include "third_party/skia/include/core/SkImage.h" | 24 #include "third_party/skia/include/core/SkImage.h" |
25 #include "ui/gfx/geometry/rect.h" | 25 #include "ui/gfx/geometry/rect.h" |
26 #include "ui/gfx/transform.h" | 26 #include "ui/gfx/transform.h" |
27 | 27 |
28 namespace blink { | 28 namespace blink { |
29 | 29 |
| 30 enum { |
| 31 kMaxPendingCompositorFrames = 2, |
| 32 }; |
| 33 |
30 OffscreenCanvasFrameDispatcherImpl::OffscreenCanvasFrameDispatcherImpl( | 34 OffscreenCanvasFrameDispatcherImpl::OffscreenCanvasFrameDispatcherImpl( |
31 OffscreenCanvasFrameDispatcherClient* client, | 35 OffscreenCanvasFrameDispatcherClient* client, |
32 uint32_t client_id, | 36 uint32_t client_id, |
33 uint32_t sink_id, | 37 uint32_t sink_id, |
34 int canvas_id, | 38 int canvas_id, |
35 int width, | 39 int width, |
36 int height) | 40 int height) |
37 : OffscreenCanvasFrameDispatcher(client), | 41 : OffscreenCanvasFrameDispatcher(client), |
38 frame_sink_id_(cc::FrameSinkId(client_id, sink_id)), | 42 frame_sink_id_(cc::FrameSinkId(client_id, sink_id)), |
39 width_(width), | 43 width_(width), |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 break; | 396 break; |
393 case kOffscreenCanvasCommitTypeCount: | 397 case kOffscreenCanvasCommitTypeCount: |
394 NOTREACHED(); | 398 NOTREACHED(); |
395 } | 399 } |
396 | 400 |
397 if (change_size_for_next_commit_) { | 401 if (change_size_for_next_commit_) { |
398 current_local_surface_id_ = local_surface_id_allocator_.GenerateId(); | 402 current_local_surface_id_ = local_surface_id_allocator_.GenerateId(); |
399 change_size_for_next_commit_ = false; | 403 change_size_for_next_commit_ = false; |
400 } | 404 } |
401 | 405 |
402 compositor_has_pending_frame_ = true; | 406 pending_compositor_frames_++; |
403 sink_->SubmitCompositorFrame(current_local_surface_id_, std::move(frame)); | 407 sink_->SubmitCompositorFrame(current_local_surface_id_, std::move(frame)); |
404 } | 408 } |
405 | 409 |
406 void OffscreenCanvasFrameDispatcherImpl::DidReceiveCompositorFrameAck( | 410 void OffscreenCanvasFrameDispatcherImpl::DidReceiveCompositorFrameAck( |
407 const cc::ReturnedResourceArray& resources) { | 411 const cc::ReturnedResourceArray& resources) { |
408 ReclaimResources(resources); | 412 ReclaimResources(resources); |
409 compositor_has_pending_frame_ = false; | 413 pending_compositor_frames_--; |
| 414 DCHECK_GE(pending_compositor_frames_, 0); |
410 } | 415 } |
411 | 416 |
412 void OffscreenCanvasFrameDispatcherImpl::SetNeedsBeginFrame( | 417 void OffscreenCanvasFrameDispatcherImpl::SetNeedsBeginFrame( |
413 bool needs_begin_frame) { | 418 bool needs_begin_frame) { |
414 if (sink_ && needs_begin_frame != needs_begin_frame_) { | 419 if (sink_ && needs_begin_frame != needs_begin_frame_) { |
415 needs_begin_frame_ = needs_begin_frame; | 420 needs_begin_frame_ = needs_begin_frame; |
416 sink_->SetNeedsBeginFrame(needs_begin_frame); | 421 sink_->SetNeedsBeginFrame(needs_begin_frame); |
417 } | 422 } |
418 } | 423 } |
419 | 424 |
420 void OffscreenCanvasFrameDispatcherImpl::OnBeginFrame( | 425 void OffscreenCanvasFrameDispatcherImpl::OnBeginFrame( |
421 const cc::BeginFrameArgs& begin_frame_args) { | 426 const cc::BeginFrameArgs& begin_frame_args) { |
422 DCHECK(Client()); | 427 DCHECK(Client()); |
423 | 428 |
424 // TODO(eseckler): Set correct |latest_confirmed_sequence_number|. | 429 // TODO(eseckler): Set correct |latest_confirmed_sequence_number|. |
425 current_begin_frame_ack_ = cc::BeginFrameAck( | 430 current_begin_frame_ack_ = cc::BeginFrameAck( |
426 begin_frame_args.source_id, begin_frame_args.sequence_number, | 431 begin_frame_args.source_id, begin_frame_args.sequence_number, |
427 begin_frame_args.sequence_number, false); | 432 begin_frame_args.sequence_number, false); |
428 | 433 |
429 if (compositor_has_pending_frame_ || | 434 if (pending_compositor_frames_ >= kMaxPendingCompositorFrames || |
430 (begin_frame_args.type == cc::BeginFrameArgs::MISSED && | 435 (begin_frame_args.type == cc::BeginFrameArgs::MISSED && |
431 base::TimeTicks::Now() > begin_frame_args.deadline)) { | 436 base::TimeTicks::Now() > begin_frame_args.deadline)) { |
432 sink_->BeginFrameDidNotSwap(current_begin_frame_ack_); | 437 sink_->BeginFrameDidNotSwap(current_begin_frame_ack_); |
433 return; | 438 return; |
434 } | 439 } |
435 | 440 |
436 Client()->BeginFrame(); | 441 Client()->BeginFrame(); |
437 // TODO(eseckler): Tell |m_sink| if we did not draw during the BeginFrame. | 442 // TODO(eseckler): Tell |m_sink| if we did not draw during the BeginFrame. |
438 current_begin_frame_ack_.sequence_number = | 443 current_begin_frame_ack_.sequence_number = |
439 cc::BeginFrameArgs::kInvalidFrameNumber; | 444 cc::BeginFrameArgs::kInvalidFrameNumber; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 | 492 |
488 void OffscreenCanvasFrameDispatcherImpl::Reshape(int width, int height) { | 493 void OffscreenCanvasFrameDispatcherImpl::Reshape(int width, int height) { |
489 if (width_ != width || height_ != height) { | 494 if (width_ != width || height_ != height) { |
490 width_ = width; | 495 width_ = width; |
491 height_ = height; | 496 height_ = height; |
492 change_size_for_next_commit_ = true; | 497 change_size_for_next_commit_ = true; |
493 } | 498 } |
494 } | 499 } |
495 | 500 |
496 } // namespace blink | 501 } // namespace blink |
OLD | NEW |