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_registered_frame_sink_hierarchy_) { |
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 DCHECK(!compositor_frame_sink_private_.is_bound()); | |
piman
2017/04/12 18:08:43
What makes this DCHECK valid? Can't the (untrusted
kylechar
2017/04/12 18:48:35
It wouldn't be valid to call this twice, but I don
| |
56 | |
57 GetFrameSinkManagerHost()->CreateCompositorFrameSink( | |
58 frame_sink_id_, std::move(request), | |
59 mojo::MakeRequest(&compositor_frame_sink_private_), std::move(client)); | |
60 | |
61 GetFrameSinkManagerHost()->RegisterFrameSinkHierarchy(parent_frame_sink_id_, | |
62 frame_sink_id_); | |
63 has_registered_frame_sink_hierarchy_ = true; | |
64 } | |
65 | |
51 void OffscreenCanvasSurfaceImpl::OnSurfaceCreated( | 66 void OffscreenCanvasSurfaceImpl::OnSurfaceCreated( |
52 const cc::SurfaceInfo& surface_info) { | 67 const cc::SurfaceInfo& surface_info) { |
53 DCHECK_EQ(surface_info.id().frame_sink_id(), frame_sink_id_); | 68 DCHECK_EQ(surface_info.id().frame_sink_id(), frame_sink_id_); |
54 if (!current_local_surface_id_.is_valid() || | 69 if (!current_local_surface_id_.is_valid() || |
55 surface_info.id().local_surface_id() != current_local_surface_id_) { | 70 surface_info.id().local_surface_id() != current_local_surface_id_) { |
56 current_local_surface_id_ = surface_info.id().local_surface_id(); | 71 current_local_surface_id_ = surface_info.id().local_surface_id(); |
57 if (client_) | 72 if (client_) |
58 client_->OnSurfaceCreated(surface_info); | 73 client_->OnSurfaceCreated(surface_info); |
59 } | 74 } |
60 } | 75 } |
61 | 76 |
62 void OffscreenCanvasSurfaceImpl::Require(const cc::SurfaceId& surface_id, | 77 void OffscreenCanvasSurfaceImpl::Require(const cc::SurfaceId& surface_id, |
63 const cc::SurfaceSequence& sequence) { | 78 const cc::SurfaceSequence& sequence) { |
64 GetSurfaceManager()->RequireSequence(surface_id, sequence); | 79 GetSurfaceManager()->RequireSequence(surface_id, sequence); |
65 } | 80 } |
66 | 81 |
67 void OffscreenCanvasSurfaceImpl::Satisfy(const cc::SurfaceSequence& sequence) { | 82 void OffscreenCanvasSurfaceImpl::Satisfy(const cc::SurfaceSequence& sequence) { |
68 GetSurfaceManager()->SatisfySequence(sequence); | 83 GetSurfaceManager()->SatisfySequence(sequence); |
69 } | 84 } |
70 | 85 |
71 } // namespace content | 86 } // namespace content |
OLD | NEW |