OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "cc/surfaces/direct_compositor_frame_sink.h" | 5 #include "cc/surfaces/direct_compositor_frame_sink.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "cc/output/compositor_frame.h" | 8 #include "cc/output/compositor_frame.h" |
9 #include "cc/output/compositor_frame_sink_client.h" | 9 #include "cc/output/compositor_frame_sink_client.h" |
10 #include "cc/surfaces/display.h" | 10 #include "cc/surfaces/display.h" |
| 11 #include "cc/surfaces/frame_sink_id.h" |
11 #include "cc/surfaces/surface.h" | 12 #include "cc/surfaces/surface.h" |
12 #include "cc/surfaces/surface_id_allocator.h" | 13 #include "cc/surfaces/surface_id_allocator.h" |
13 #include "cc/surfaces/surface_manager.h" | 14 #include "cc/surfaces/surface_manager.h" |
14 | 15 |
15 namespace cc { | 16 namespace cc { |
16 | 17 |
17 DirectCompositorFrameSink::DirectCompositorFrameSink( | 18 DirectCompositorFrameSink::DirectCompositorFrameSink( |
| 19 const FrameSinkId& frame_sink_id, |
18 SurfaceManager* surface_manager, | 20 SurfaceManager* surface_manager, |
19 SurfaceIdAllocator* surface_id_allocator, | |
20 Display* display, | 21 Display* display, |
21 scoped_refptr<ContextProvider> context_provider, | 22 scoped_refptr<ContextProvider> context_provider, |
22 scoped_refptr<ContextProvider> worker_context_provider) | 23 scoped_refptr<ContextProvider> worker_context_provider) |
23 : CompositorFrameSink(std::move(context_provider), | 24 : CompositorFrameSink(std::move(context_provider), |
24 std::move(worker_context_provider)), | 25 std::move(worker_context_provider)), |
| 26 frame_sink_id_(frame_sink_id), |
25 surface_manager_(surface_manager), | 27 surface_manager_(surface_manager), |
26 surface_id_allocator_(surface_id_allocator), | 28 surface_id_allocator_(frame_sink_id), |
27 display_(display), | 29 display_(display), |
28 factory_(surface_manager, this) { | 30 factory_(frame_sink_id, surface_manager, this) { |
29 DCHECK(thread_checker_.CalledOnValidThread()); | 31 DCHECK(thread_checker_.CalledOnValidThread()); |
30 capabilities_.can_force_reclaim_resources = true; | 32 capabilities_.can_force_reclaim_resources = true; |
31 // Display and DirectCompositorFrameSink share a GL context, so sync | 33 // Display and DirectCompositorFrameSink share a GL context, so sync |
32 // points aren't needed when passing resources between them. | 34 // points aren't needed when passing resources between them. |
33 capabilities_.delegated_sync_points_required = false; | 35 capabilities_.delegated_sync_points_required = false; |
34 factory_.set_needs_sync_points(false); | 36 factory_.set_needs_sync_points(false); |
35 } | 37 } |
36 | 38 |
37 DirectCompositorFrameSink::DirectCompositorFrameSink( | 39 DirectCompositorFrameSink::DirectCompositorFrameSink( |
| 40 const FrameSinkId& frame_sink_id, |
38 SurfaceManager* surface_manager, | 41 SurfaceManager* surface_manager, |
39 SurfaceIdAllocator* surface_id_allocator, | |
40 Display* display, | 42 Display* display, |
41 scoped_refptr<VulkanContextProvider> vulkan_context_provider) | 43 scoped_refptr<VulkanContextProvider> vulkan_context_provider) |
42 : CompositorFrameSink(std::move(vulkan_context_provider)), | 44 : CompositorFrameSink(std::move(vulkan_context_provider)), |
| 45 frame_sink_id_(frame_sink_id), |
43 surface_manager_(surface_manager), | 46 surface_manager_(surface_manager), |
44 surface_id_allocator_(surface_id_allocator), | 47 surface_id_allocator_(frame_sink_id_), |
45 display_(display), | 48 display_(display), |
46 factory_(surface_manager, this) { | 49 factory_(frame_sink_id_, surface_manager, this) { |
47 DCHECK(thread_checker_.CalledOnValidThread()); | 50 DCHECK(thread_checker_.CalledOnValidThread()); |
48 capabilities_.can_force_reclaim_resources = true; | 51 capabilities_.can_force_reclaim_resources = true; |
49 } | 52 } |
50 | 53 |
51 DirectCompositorFrameSink::~DirectCompositorFrameSink() { | 54 DirectCompositorFrameSink::~DirectCompositorFrameSink() { |
52 DCHECK(thread_checker_.CalledOnValidThread()); | 55 DCHECK(thread_checker_.CalledOnValidThread()); |
53 if (HasClient()) | 56 if (HasClient()) |
54 DetachFromClient(); | 57 DetachFromClient(); |
55 } | 58 } |
56 | 59 |
57 bool DirectCompositorFrameSink::BindToClient( | 60 bool DirectCompositorFrameSink::BindToClient( |
58 CompositorFrameSinkClient* client) { | 61 CompositorFrameSinkClient* client) { |
59 DCHECK(thread_checker_.CalledOnValidThread()); | 62 DCHECK(thread_checker_.CalledOnValidThread()); |
60 | 63 |
61 surface_manager_->RegisterSurfaceFactoryClient( | 64 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); |
62 surface_id_allocator_->frame_sink_id(), this); | |
63 | 65 |
64 if (!CompositorFrameSink::BindToClient(client)) | 66 if (!CompositorFrameSink::BindToClient(client)) |
65 return false; | 67 return false; |
66 | 68 |
67 // We want the Display's output surface to hear about lost context, and since | 69 // We want the Display's output surface to hear about lost context, and since |
68 // this shares a context with it, we should not be listening for lost context | 70 // this shares a context with it, we should not be listening for lost context |
69 // callbacks on the context here. | 71 // callbacks on the context here. |
70 if (context_provider()) | 72 if (context_provider()) |
71 context_provider()->SetLostContextCallback(base::Closure()); | 73 context_provider()->SetLostContextCallback(base::Closure()); |
72 | 74 |
73 // Avoid initializing GL context here, as this should be sharing the | 75 // Avoid initializing GL context here, as this should be sharing the |
74 // Display's context. | 76 // Display's context. |
75 display_->Initialize(this, surface_manager_, | 77 display_->Initialize(this, surface_manager_, frame_sink_id_); |
76 surface_id_allocator_->frame_sink_id()); | |
77 return true; | 78 return true; |
78 } | 79 } |
79 | 80 |
80 void DirectCompositorFrameSink::DetachFromClient() { | 81 void DirectCompositorFrameSink::DetachFromClient() { |
81 DCHECK(HasClient()); | 82 DCHECK(HasClient()); |
82 | 83 |
83 // Unregister the SurfaceFactoryClient here instead of the dtor so that only | 84 // Unregister the SurfaceFactoryClient here instead of the dtor so that only |
84 // one client is alive for this namespace at any given time. | 85 // one client is alive for this namespace at any given time. |
85 surface_manager_->UnregisterSurfaceFactoryClient( | 86 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); |
86 surface_id_allocator_->frame_sink_id()); | |
87 if (!delegated_surface_id_.is_null()) | 87 if (!delegated_surface_id_.is_null()) |
88 factory_.Destroy(delegated_surface_id_); | 88 factory_.Destroy(delegated_surface_id_); |
89 | 89 |
90 CompositorFrameSink::DetachFromClient(); | 90 CompositorFrameSink::DetachFromClient(); |
91 } | 91 } |
92 | 92 |
93 void DirectCompositorFrameSink::SwapBuffers(CompositorFrame frame) { | 93 void DirectCompositorFrameSink::SwapBuffers(CompositorFrame frame) { |
94 gfx::Size frame_size = | 94 gfx::Size frame_size = |
95 frame.delegated_frame_data->render_pass_list.back()->output_rect.size(); | 95 frame.delegated_frame_data->render_pass_list.back()->output_rect.size(); |
96 if (frame_size.IsEmpty() || frame_size != last_swap_frame_size_) { | 96 if (frame_size.IsEmpty() || frame_size != last_swap_frame_size_) { |
97 if (!delegated_surface_id_.is_null()) { | 97 if (!delegated_surface_id_.is_null()) { |
98 factory_.Destroy(delegated_surface_id_); | 98 factory_.Destroy(delegated_surface_id_); |
99 } | 99 } |
100 delegated_surface_id_ = surface_id_allocator_->GenerateId(); | 100 delegated_surface_id_ = surface_id_allocator_.GenerateId(); |
101 factory_.Create(delegated_surface_id_); | 101 factory_.Create(delegated_surface_id_); |
102 last_swap_frame_size_ = frame_size; | 102 last_swap_frame_size_ = frame_size; |
103 } | 103 } |
104 display_->SetSurfaceId(delegated_surface_id_, | 104 display_->SetSurfaceId(delegated_surface_id_, |
105 frame.metadata.device_scale_factor); | 105 frame.metadata.device_scale_factor); |
106 | 106 |
107 factory_.SubmitCompositorFrame( | 107 factory_.SubmitCompositorFrame( |
108 delegated_surface_id_, std::move(frame), | 108 delegated_surface_id_, std::move(frame), |
109 base::Bind(&DirectCompositorFrameSink::DidDrawCallback, | 109 base::Bind(&DirectCompositorFrameSink::DidDrawCallback, |
110 base::Unretained(this))); | 110 base::Unretained(this))); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 // This notification is not relevant to our client outside of tests. We | 144 // This notification is not relevant to our client outside of tests. We |
145 // unblock the client from DidDrawCallback() when the surface is going to | 145 // unblock the client from DidDrawCallback() when the surface is going to |
146 // be drawn. | 146 // be drawn. |
147 } | 147 } |
148 | 148 |
149 void DirectCompositorFrameSink::DidDrawCallback() { | 149 void DirectCompositorFrameSink::DidDrawCallback() { |
150 CompositorFrameSink::PostSwapBuffersComplete(); | 150 CompositorFrameSink::PostSwapBuffersComplete(); |
151 } | 151 } |
152 | 152 |
153 } // namespace cc | 153 } // namespace cc |
OLD | NEW |