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_surface_impl.h" | 5 #include "content/browser/renderer_host/offscreen_canvas_surface_impl.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind_helpers.h" | |
| 11 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 12 #include "cc/surfaces/surface_manager.h" | 11 #include "cc/surfaces/surface_manager.h" |
| 13 #include "content/browser/compositor/frame_sink_manager_host.h" | 12 #include "content/browser/compositor/frame_sink_manager_host.h" |
| 14 #include "content/browser/compositor/surface_utils.h" | 13 #include "content/browser/compositor/surface_utils.h" |
| 15 #include "content/browser/renderer_host/offscreen_canvas_compositor_frame_sink_m anager.h" | 14 #include "content/browser/renderer_host/offscreen_canvas_provider_impl.h" |
| 16 | 15 |
| 17 namespace content { | 16 namespace content { |
| 18 | 17 |
| 19 OffscreenCanvasSurfaceImpl::OffscreenCanvasSurfaceImpl( | 18 OffscreenCanvasSurfaceImpl::OffscreenCanvasSurfaceImpl( |
| 20 const cc::FrameSinkId& parent_frame_sink_id, | 19 const cc::FrameSinkId& parent_frame_sink_id, |
| 21 const cc::FrameSinkId& frame_sink_id, | 20 const cc::FrameSinkId& frame_sink_id, |
| 22 blink::mojom::OffscreenCanvasSurfaceClientPtr client) | 21 OffscreenCanvasProviderImpl* provider, |
| 22 blink::mojom::OffscreenCanvasSurfaceClientPtr client, | |
| 23 blink::mojom::OffscreenCanvasSurfaceRequest request) | |
| 23 : client_(std::move(client)), | 24 : client_(std::move(client)), |
| 25 binding_(this, std::move(request)), | |
| 26 provider_(provider), | |
| 24 frame_sink_id_(frame_sink_id), | 27 frame_sink_id_(frame_sink_id), |
| 25 parent_frame_sink_id_(parent_frame_sink_id) { | 28 parent_frame_sink_id_(parent_frame_sink_id) { |
| 26 OffscreenCanvasCompositorFrameSinkManager::GetInstance() | 29 binding_.set_connection_error_handler( |
| 27 ->RegisterOffscreenCanvasSurfaceInstance(frame_sink_id_, this); | 30 base::Bind(&OffscreenCanvasSurfaceImpl::OnSurfaceConnectionClosed, |
| 31 base::Unretained(this))); | |
| 32 GetFrameSinkManagerHost()->AddObserver(this); | |
| 28 } | 33 } |
| 29 | 34 |
| 30 OffscreenCanvasSurfaceImpl::~OffscreenCanvasSurfaceImpl() { | 35 OffscreenCanvasSurfaceImpl::~OffscreenCanvasSurfaceImpl() { |
| 31 if (has_created_compositor_frame_sink_) { | 36 if (has_created_compositor_frame_sink_) { |
| 32 GetFrameSinkManagerHost()->UnregisterFrameSinkHierarchy( | 37 GetFrameSinkManagerHost()->UnregisterFrameSinkHierarchy( |
| 33 parent_frame_sink_id_, frame_sink_id_); | 38 parent_frame_sink_id_, frame_sink_id_); |
| 34 } | 39 } |
| 35 OffscreenCanvasCompositorFrameSinkManager::GetInstance() | 40 GetFrameSinkManagerHost()->RemoveObserver(this); |
| 36 ->UnregisterOffscreenCanvasSurfaceInstance(frame_sink_id_); | |
| 37 } | |
| 38 | |
| 39 // static | |
| 40 void OffscreenCanvasSurfaceImpl::Create( | |
| 41 const cc::FrameSinkId& parent_frame_sink_id, | |
| 42 const cc::FrameSinkId& frame_sink_id, | |
| 43 blink::mojom::OffscreenCanvasSurfaceClientPtr client, | |
| 44 blink::mojom::OffscreenCanvasSurfaceRequest request) { | |
| 45 std::unique_ptr<OffscreenCanvasSurfaceImpl> impl = | |
| 46 base::MakeUnique<OffscreenCanvasSurfaceImpl>( | |
| 47 parent_frame_sink_id, frame_sink_id, std::move(client)); | |
| 48 OffscreenCanvasSurfaceImpl* surface_service = impl.get(); | |
| 49 surface_service->binding_ = | |
| 50 mojo::MakeStrongBinding(std::move(impl), std::move(request)); | |
| 51 } | 41 } |
| 52 | 42 |
| 53 void OffscreenCanvasSurfaceImpl::CreateCompositorFrameSink( | 43 void OffscreenCanvasSurfaceImpl::CreateCompositorFrameSink( |
| 54 cc::mojom::MojoCompositorFrameSinkClientPtr client, | 44 cc::mojom::MojoCompositorFrameSinkClientPtr client, |
| 55 cc::mojom::MojoCompositorFrameSinkRequest request) { | 45 cc::mojom::MojoCompositorFrameSinkRequest request) { |
| 56 if (has_created_compositor_frame_sink_) { | 46 if (has_created_compositor_frame_sink_) { |
| 57 DLOG(ERROR) << "CreateCompositorFrameSink() called more than once."; | 47 DLOG(ERROR) << "CreateCompositorFrameSink() called more than once."; |
| 58 return; | 48 return; |
| 59 } | 49 } |
| 60 | 50 |
| 61 GetFrameSinkManagerHost()->CreateCompositorFrameSink( | 51 GetFrameSinkManagerHost()->CreateCompositorFrameSink( |
| 62 frame_sink_id_, std::move(request), | 52 frame_sink_id_, std::move(request), |
| 63 mojo::MakeRequest(&compositor_frame_sink_private_), std::move(client)); | 53 mojo::MakeRequest(&compositor_frame_sink_private_), std::move(client)); |
| 64 | 54 |
| 65 GetFrameSinkManagerHost()->RegisterFrameSinkHierarchy(parent_frame_sink_id_, | 55 GetFrameSinkManagerHost()->RegisterFrameSinkHierarchy(parent_frame_sink_id_, |
| 66 frame_sink_id_); | 56 frame_sink_id_); |
| 67 has_created_compositor_frame_sink_ = true; | 57 has_created_compositor_frame_sink_ = true; |
| 68 } | 58 } |
| 69 | 59 |
| 70 void OffscreenCanvasSurfaceImpl::OnSurfaceCreated( | 60 void OffscreenCanvasSurfaceImpl::OnSurfaceCreated( |
| 71 const cc::SurfaceInfo& surface_info) { | 61 const cc::SurfaceInfo& surface_info) { |
| 72 DCHECK_EQ(surface_info.id().frame_sink_id(), frame_sink_id_); | 62 if (surface_info.id().frame_sink_id() != frame_sink_id_) |
| 73 if (!current_local_surface_id_.is_valid() || | 63 return; |
| 74 surface_info.id().local_surface_id() != current_local_surface_id_) { | 64 |
| 75 current_local_surface_id_ = surface_info.id().local_surface_id(); | 65 if (surface_info.id().local_surface_id() != local_surface_id_) { |
|
Fady Samuel
2017/04/28 04:58:00
When would this ever be the case? What's the point
kylechar
2017/05/01 19:07:48
Hmmm, in the future when MojoFrameSinkManager is i
| |
| 66 local_surface_id_ = surface_info.id().local_surface_id(); | |
| 76 if (client_) | 67 if (client_) |
| 77 client_->OnSurfaceCreated(surface_info); | 68 client_->OnSurfaceCreated(surface_info); |
| 78 } | 69 } |
| 79 } | 70 } |
| 80 | 71 |
| 81 void OffscreenCanvasSurfaceImpl::Require(const cc::SurfaceId& surface_id, | 72 void OffscreenCanvasSurfaceImpl::Require(const cc::SurfaceId& surface_id, |
| 82 const cc::SurfaceSequence& sequence) { | 73 const cc::SurfaceSequence& sequence) { |
| 83 GetSurfaceManager()->RequireSequence(surface_id, sequence); | 74 GetSurfaceManager()->RequireSequence(surface_id, sequence); |
| 84 } | 75 } |
| 85 | 76 |
| 86 void OffscreenCanvasSurfaceImpl::Satisfy(const cc::SurfaceSequence& sequence) { | 77 void OffscreenCanvasSurfaceImpl::Satisfy(const cc::SurfaceSequence& sequence) { |
| 87 GetSurfaceManager()->SatisfySequence(sequence); | 78 GetSurfaceManager()->SatisfySequence(sequence); |
| 88 } | 79 } |
| 89 | 80 |
| 81 void OffscreenCanvasSurfaceImpl::OnSurfaceConnectionClosed() { | |
| 82 provider_->DestroyOffscreenCanvasSurface(frame_sink_id_); | |
|
Fady Samuel
2017/04/28 04:58:00
DestroyOffscreenCanvasSurface should take the fram
kylechar
2017/05/01 19:07:48
Good catch.
| |
| 83 } | |
| 84 | |
| 90 } // namespace content | 85 } // namespace content |
| OLD | NEW |