Chromium Code Reviews| 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 "content/browser/renderer_host/offscreen_canvas_compositor_frame_sink.h " | 5 #include "content/browser/renderer_host/offscreen_canvas_compositor_frame_sink.h " |
| 6 | 6 |
| 7 #include "cc/surfaces/surface.h" | 7 #include "cc/surfaces/surface.h" |
| 8 #include "cc/surfaces/surface_manager.h" | 8 #include "cc/surfaces/surface_manager.h" |
| 9 #include "content/browser/compositor/surface_utils.h" | 9 #include "content/browser/compositor/surface_utils.h" |
| 10 #include "content/browser/renderer_host/offscreen_canvas_surface_impl.h" | |
| 11 #include "content/browser/renderer_host/offscreen_canvas_surface_manager.h" | |
| 10 #include "mojo/public/cpp/bindings/strong_binding.h" | 12 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 11 | 13 |
| 12 namespace content { | 14 namespace content { |
| 13 | 15 |
| 14 OffscreenCanvasCompositorFrameSink::OffscreenCanvasCompositorFrameSink( | 16 OffscreenCanvasCompositorFrameSink::OffscreenCanvasCompositorFrameSink( |
| 15 const cc::SurfaceId& surface_id, | 17 const cc::SurfaceId& surface_id, |
| 16 cc::mojom::MojoCompositorFrameSinkClientPtr client) | 18 cc::mojom::MojoCompositorFrameSinkClientPtr client) |
| 17 : surface_id_(surface_id), client_(std::move(client)) { | 19 : surface_id_(surface_id), client_(std::move(client)) { |
| 18 cc::SurfaceManager* manager = GetSurfaceManager(); | 20 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 19 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>( | 21 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>( |
| 20 surface_id_.frame_sink_id(), manager, this); | 22 surface_id_.frame_sink_id(), manager, this); |
| 21 manager->RegisterFrameSinkId(surface_id_.frame_sink_id()); | 23 manager->RegisterFrameSinkId(surface_id_.frame_sink_id()); |
| 22 surface_factory_->Create(surface_id_.local_frame_id()); | |
| 23 } | 24 } |
| 24 | 25 |
| 25 OffscreenCanvasCompositorFrameSink::~OffscreenCanvasCompositorFrameSink() { | 26 OffscreenCanvasCompositorFrameSink::~OffscreenCanvasCompositorFrameSink() { |
| 26 cc::SurfaceManager* manager = GetSurfaceManager(); | 27 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 27 if (!manager) { | 28 if (!manager) { |
| 28 // Inform SurfaceFactory that SurfaceManager's no longer alive to | 29 // Inform SurfaceFactory that SurfaceManager's no longer alive to |
| 29 // avoid its destruction error. | 30 // avoid its destruction error. |
| 30 surface_factory_->DidDestroySurfaceManager(); | 31 surface_factory_->DidDestroySurfaceManager(); |
| 31 } else { | 32 } else { |
| 32 manager->InvalidateFrameSinkId(surface_id_.frame_sink_id()); | 33 manager->InvalidateFrameSinkId(surface_id_.frame_sink_id()); |
| 33 } | 34 } |
| 34 surface_factory_->Destroy(surface_id_.local_frame_id()); | 35 surface_factory_->Destroy(surface_id_.local_frame_id()); |
| 35 } | 36 } |
| 36 | 37 |
| 37 // static | 38 // static |
| 38 void OffscreenCanvasCompositorFrameSink::Create( | 39 void OffscreenCanvasCompositorFrameSink::Create( |
| 39 const cc::SurfaceId& surface_id, | 40 const cc::SurfaceId& surface_id, |
| 40 cc::mojom::MojoCompositorFrameSinkClientPtr client, | 41 cc::mojom::MojoCompositorFrameSinkClientPtr client, |
| 41 cc::mojom::MojoCompositorFrameSinkRequest request) { | 42 cc::mojom::MojoCompositorFrameSinkRequest request) { |
| 42 mojo::MakeStrongBinding(base::MakeUnique<OffscreenCanvasCompositorFrameSink>( | 43 mojo::MakeStrongBinding(base::MakeUnique<OffscreenCanvasCompositorFrameSink>( |
| 43 surface_id, std::move(client)), | 44 surface_id, std::move(client)), |
| 44 std::move(request)); | 45 std::move(request)); |
| 45 } | 46 } |
| 46 | 47 |
| 47 void OffscreenCanvasCompositorFrameSink::SubmitCompositorFrame( | 48 void OffscreenCanvasCompositorFrameSink::SubmitCompositorFrame( |
| 48 cc::CompositorFrame frame) { | 49 cc::CompositorFrame frame) { |
| 50 cc::RenderPass* root_pass = frame.render_pass_list.back().get(); | |
| 51 gfx::Size surface_size = root_pass->output_rect.size(); | |
| 52 | |
| 53 if (!GetSurfaceManager()->GetSurfaceForId(surface_id_)) { | |
|
Fady Samuel
2016/11/22 16:04:09
I hate to be overly nitpicky but this flow doesn't
| |
| 54 // If this is the first commit, surface_id_ is not used to create a new | |
| 55 // Surface yet. | |
| 56 surface_factory_->Create(surface_id_.local_frame_id()); | |
| 57 current_surface_size_ = surface_size; | |
| 58 } else if (surface_size != current_surface_size_) { | |
| 59 // If this is not the first commit, we check whether there is a resize | |
| 60 // since the previous commit. | |
| 61 OffscreenCanvasSurfaceImpl* surface_impl = | |
| 62 OffscreenCanvasSurfaceManager::GetInstance()->GetSurfaceInstance( | |
| 63 surface_id_.frame_sink_id()); | |
| 64 if (!surface_impl) { | |
| 65 // We may end up here when the HTMLCanvasElement- | |
| 66 // OffscreenCanvasSurfaceImpl connection is torn down and the | |
| 67 // OffscreenCanvas-CompositorFrameSink connection is still working. In | |
| 68 // this case, we ignore the commit() because it is meaningless to | |
| 69 // process a compositor frame when there is no placeholder canvas for | |
| 70 // this OffscreenCanvas. | |
| 71 LOG(ERROR) << "OffscreenCanvas is submitting frame when its place holder" | |
| 72 << " canvas's browser service-end does no longer exist."; | |
| 73 return; | |
| 74 } | |
| 75 | |
| 76 cc::LocalFrameId new_local_frame_id = surface_impl->GenerateLocalFrameId(); | |
| 77 surface_factory_->Destroy(surface_id_.local_frame_id()); | |
| 78 surface_id_ = | |
| 79 cc::SurfaceId(surface_id_.frame_sink_id(), new_local_frame_id); | |
| 80 surface_factory_->Create(surface_id_.local_frame_id()); | |
| 81 current_surface_size_ = surface_size; | |
| 82 surface_impl->OnSurfaceSizeChanged(surface_id_, current_surface_size_); | |
| 83 } | |
| 84 | |
| 49 ++ack_pending_count_; | 85 ++ack_pending_count_; |
| 50 surface_factory_->SubmitCompositorFrame( | 86 surface_factory_->SubmitCompositorFrame( |
| 51 surface_id_.local_frame_id(), std::move(frame), | 87 surface_id_.local_frame_id(), std::move(frame), |
| 52 base::Bind( | 88 base::Bind( |
| 53 &OffscreenCanvasCompositorFrameSink::DidReceiveCompositorFrameAck, | 89 &OffscreenCanvasCompositorFrameSink::DidReceiveCompositorFrameAck, |
| 54 base::Unretained(this))); | 90 base::Unretained(this))); |
| 55 } | 91 } |
| 56 | 92 |
| 57 void OffscreenCanvasCompositorFrameSink::SetNeedsBeginFrame( | 93 void OffscreenCanvasCompositorFrameSink::SetNeedsBeginFrame( |
| 58 bool needs_begin_frame) { | 94 bool needs_begin_frame) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 86 client_->DidReceiveCompositorFrameAck(); | 122 client_->DidReceiveCompositorFrameAck(); |
| 87 DCHECK_GT(ack_pending_count_, 0); | 123 DCHECK_GT(ack_pending_count_, 0); |
| 88 if (!surface_returned_resources_.empty()) { | 124 if (!surface_returned_resources_.empty()) { |
| 89 client_->ReclaimResources(surface_returned_resources_); | 125 client_->ReclaimResources(surface_returned_resources_); |
| 90 surface_returned_resources_.clear(); | 126 surface_returned_resources_.clear(); |
| 91 } | 127 } |
| 92 ack_pending_count_--; | 128 ack_pending_count_--; |
| 93 } | 129 } |
| 94 | 130 |
| 95 } // namespace content | 131 } // namespace content |
| OLD | NEW |