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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "cc/surfaces/surface.h" | |
12 #include "cc/surfaces/surface_manager.h" | 11 #include "cc/surfaces/surface_manager.h" |
| 12 #include "content/browser/compositor/frame_sink_manager_host.h" |
13 #include "content/browser/compositor/surface_utils.h" | 13 #include "content/browser/compositor/surface_utils.h" |
14 #include "content/browser/renderer_host/offscreen_canvas_compositor_frame_sink_m
anager.h" | 14 #include "content/browser/renderer_host/offscreen_canvas_compositor_frame_sink_m
anager.h" |
15 #include "content/public/browser/browser_thread.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 cc::mojom::FrameSinkManagerClientPtr client) | 21 cc::mojom::FrameSinkManagerClientPtr client) |
23 : client_(std::move(client)), | 22 : client_(std::move(client)), |
24 frame_sink_id_(frame_sink_id), | 23 frame_sink_id_(frame_sink_id), |
25 parent_frame_sink_id_(parent_frame_sink_id) { | 24 parent_frame_sink_id_(parent_frame_sink_id) { |
26 OffscreenCanvasCompositorFrameSinkManager::GetInstance() | 25 OffscreenCanvasCompositorFrameSinkManager::GetInstance() |
27 ->RegisterOffscreenCanvasSurfaceInstance(frame_sink_id_, this); | 26 ->RegisterOffscreenCanvasSurfaceInstance(frame_sink_id_, this); |
28 } | 27 } |
29 | 28 |
30 OffscreenCanvasSurfaceImpl::~OffscreenCanvasSurfaceImpl() { | 29 OffscreenCanvasSurfaceImpl::~OffscreenCanvasSurfaceImpl() { |
31 if (frame_sink_id_.is_valid()) { | 30 if (has_created_compositor_frame_sink_) { |
32 OffscreenCanvasCompositorFrameSinkManager::GetInstance() | 31 GetFrameSinkManagerHost()->UnregisterFrameSinkHierarchy( |
33 ->UnregisterOffscreenCanvasSurfaceInstance(frame_sink_id_); | 32 parent_frame_sink_id_, frame_sink_id_); |
34 } | 33 } |
| 34 OffscreenCanvasCompositorFrameSinkManager::GetInstance() |
| 35 ->UnregisterOffscreenCanvasSurfaceInstance(frame_sink_id_); |
35 } | 36 } |
36 | 37 |
37 // static | 38 // static |
38 void OffscreenCanvasSurfaceImpl::Create( | 39 void OffscreenCanvasSurfaceImpl::Create( |
39 const cc::FrameSinkId& parent_frame_sink_id, | 40 const cc::FrameSinkId& parent_frame_sink_id, |
40 const cc::FrameSinkId& frame_sink_id, | 41 const cc::FrameSinkId& frame_sink_id, |
41 cc::mojom::FrameSinkManagerClientPtr client, | 42 cc::mojom::FrameSinkManagerClientPtr client, |
42 blink::mojom::OffscreenCanvasSurfaceRequest request) { | 43 blink::mojom::OffscreenCanvasSurfaceRequest request) { |
43 std::unique_ptr<OffscreenCanvasSurfaceImpl> impl = | 44 std::unique_ptr<OffscreenCanvasSurfaceImpl> impl = |
44 base::MakeUnique<OffscreenCanvasSurfaceImpl>( | 45 base::MakeUnique<OffscreenCanvasSurfaceImpl>( |
45 parent_frame_sink_id, frame_sink_id, std::move(client)); | 46 parent_frame_sink_id, frame_sink_id, std::move(client)); |
46 OffscreenCanvasSurfaceImpl* surface_service = impl.get(); | 47 OffscreenCanvasSurfaceImpl* surface_service = impl.get(); |
47 surface_service->binding_ = | 48 surface_service->binding_ = |
48 mojo::MakeStrongBinding(std::move(impl), std::move(request)); | 49 mojo::MakeStrongBinding(std::move(impl), std::move(request)); |
49 } | 50 } |
50 | 51 |
| 52 void OffscreenCanvasSurfaceImpl::CreateCompositorFrameSink( |
| 53 cc::mojom::MojoCompositorFrameSinkClientPtr client, |
| 54 cc::mojom::MojoCompositorFrameSinkRequest request) { |
| 55 if (has_created_compositor_frame_sink_) { |
| 56 DLOG(ERROR) << "CreateCompositorFrameSink() called more than once."; |
| 57 return; |
| 58 } |
| 59 |
| 60 GetFrameSinkManagerHost()->CreateCompositorFrameSink( |
| 61 frame_sink_id_, std::move(request), |
| 62 mojo::MakeRequest(&compositor_frame_sink_private_), std::move(client)); |
| 63 |
| 64 GetFrameSinkManagerHost()->RegisterFrameSinkHierarchy(parent_frame_sink_id_, |
| 65 frame_sink_id_); |
| 66 has_created_compositor_frame_sink_ = true; |
| 67 } |
| 68 |
51 void OffscreenCanvasSurfaceImpl::OnSurfaceCreated( | 69 void OffscreenCanvasSurfaceImpl::OnSurfaceCreated( |
52 const cc::SurfaceInfo& surface_info) { | 70 const cc::SurfaceInfo& surface_info) { |
53 DCHECK_EQ(surface_info.id().frame_sink_id(), frame_sink_id_); | 71 DCHECK_EQ(surface_info.id().frame_sink_id(), frame_sink_id_); |
54 if (!current_local_surface_id_.is_valid() || | 72 if (!current_local_surface_id_.is_valid() || |
55 surface_info.id().local_surface_id() != current_local_surface_id_) { | 73 surface_info.id().local_surface_id() != current_local_surface_id_) { |
56 current_local_surface_id_ = surface_info.id().local_surface_id(); | 74 current_local_surface_id_ = surface_info.id().local_surface_id(); |
57 if (client_) | 75 if (client_) |
58 client_->OnSurfaceCreated(surface_info); | 76 client_->OnSurfaceCreated(surface_info); |
59 } | 77 } |
60 } | 78 } |
61 | 79 |
62 void OffscreenCanvasSurfaceImpl::Require(const cc::SurfaceId& surface_id, | 80 void OffscreenCanvasSurfaceImpl::Require(const cc::SurfaceId& surface_id, |
63 const cc::SurfaceSequence& sequence) { | 81 const cc::SurfaceSequence& sequence) { |
64 GetSurfaceManager()->RequireSequence(surface_id, sequence); | 82 GetSurfaceManager()->RequireSequence(surface_id, sequence); |
65 } | 83 } |
66 | 84 |
67 void OffscreenCanvasSurfaceImpl::Satisfy(const cc::SurfaceSequence& sequence) { | 85 void OffscreenCanvasSurfaceImpl::Satisfy(const cc::SurfaceSequence& sequence) { |
68 GetSurfaceManager()->SatisfySequence(sequence); | 86 GetSurfaceManager()->SatisfySequence(sequence); |
69 } | 87 } |
70 | 88 |
71 } // namespace content | 89 } // namespace content |
OLD | NEW |