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/surface.h" | 11 #include "cc/surfaces/surface.h" |
12 #include "cc/surfaces/surface_id_allocator.h" | 12 #include "cc/surfaces/surface_id_allocator.h" |
13 #include "cc/surfaces/surface_manager.h" | 13 #include "cc/surfaces/surface_manager.h" |
14 | 14 |
15 namespace cc { | 15 namespace cc { |
16 | 16 |
17 DirectCompositorFrameSink::DirectCompositorFrameSink( | 17 DirectCompositorFrameSink::DirectCompositorFrameSink( |
18 SurfaceManager* surface_manager, | 18 SurfaceManager* surface_manager, |
19 SurfaceIdAllocator* surface_id_allocator, | 19 SurfaceIdAllocator* surface_id_allocator, |
20 Display* display, | 20 Display* display, |
21 scoped_refptr<ContextProvider> context_provider, | 21 scoped_refptr<ContextProvider> context_provider, |
22 scoped_refptr<ContextProvider> worker_context_provider) | 22 scoped_refptr<ContextProvider> worker_context_provider) |
23 : CompositorFrameSink(std::move(context_provider), | 23 : CompositorFrameSink(std::move(context_provider), |
24 std::move(worker_context_provider), | 24 std::move(worker_context_provider)), |
25 nullptr), | |
26 surface_manager_(surface_manager), | 25 surface_manager_(surface_manager), |
27 surface_id_allocator_(surface_id_allocator), | 26 surface_id_allocator_(surface_id_allocator), |
28 display_(display), | 27 display_(display), |
29 factory_(surface_manager, this) { | 28 factory_(surface_manager, this) { |
30 DCHECK(thread_checker_.CalledOnValidThread()); | 29 DCHECK(thread_checker_.CalledOnValidThread()); |
31 capabilities_.delegated_rendering = true; | |
32 capabilities_.adjust_deadline_for_parent = true; | |
33 capabilities_.can_force_reclaim_resources = true; | 30 capabilities_.can_force_reclaim_resources = true; |
34 | |
35 // Display and DirectCompositorFrameSink share a GL context, so sync | 31 // Display and DirectCompositorFrameSink share a GL context, so sync |
36 // points aren't needed when passing resources between them. | 32 // points aren't needed when passing resources between them. |
37 capabilities_.delegated_sync_points_required = false; | 33 capabilities_.delegated_sync_points_required = false; |
38 factory_.set_needs_sync_points(false); | 34 factory_.set_needs_sync_points(false); |
39 } | 35 } |
40 | 36 |
41 DirectCompositorFrameSink::DirectCompositorFrameSink( | 37 DirectCompositorFrameSink::DirectCompositorFrameSink( |
42 SurfaceManager* surface_manager, | 38 SurfaceManager* surface_manager, |
43 SurfaceIdAllocator* surface_id_allocator, | 39 SurfaceIdAllocator* surface_id_allocator, |
44 Display* display, | 40 Display* display, |
45 scoped_refptr<VulkanContextProvider> vulkan_context_provider) | 41 scoped_refptr<VulkanContextProvider> vulkan_context_provider) |
46 : CompositorFrameSink(std::move(vulkan_context_provider)), | 42 : CompositorFrameSink(std::move(vulkan_context_provider)), |
47 surface_manager_(surface_manager), | 43 surface_manager_(surface_manager), |
48 surface_id_allocator_(surface_id_allocator), | 44 surface_id_allocator_(surface_id_allocator), |
49 display_(display), | 45 display_(display), |
50 factory_(surface_manager, this) { | 46 factory_(surface_manager, this) { |
51 DCHECK(thread_checker_.CalledOnValidThread()); | 47 DCHECK(thread_checker_.CalledOnValidThread()); |
52 capabilities_.delegated_rendering = true; | |
53 capabilities_.adjust_deadline_for_parent = true; | |
54 capabilities_.can_force_reclaim_resources = true; | 48 capabilities_.can_force_reclaim_resources = true; |
55 } | 49 } |
56 | 50 |
57 DirectCompositorFrameSink::~DirectCompositorFrameSink() { | 51 DirectCompositorFrameSink::~DirectCompositorFrameSink() { |
58 DCHECK(thread_checker_.CalledOnValidThread()); | 52 DCHECK(thread_checker_.CalledOnValidThread()); |
59 if (HasClient()) | 53 if (HasClient()) |
60 DetachFromClient(); | 54 DetachFromClient(); |
61 } | 55 } |
62 | 56 |
63 void DirectCompositorFrameSink::SwapBuffers(CompositorFrame frame) { | |
64 gfx::Size frame_size = | |
65 frame.delegated_frame_data->render_pass_list.back()->output_rect.size(); | |
66 if (frame_size.IsEmpty() || frame_size != last_swap_frame_size_) { | |
67 if (!delegated_surface_id_.is_null()) { | |
68 factory_.Destroy(delegated_surface_id_); | |
69 } | |
70 delegated_surface_id_ = surface_id_allocator_->GenerateId(); | |
71 factory_.Create(delegated_surface_id_); | |
72 last_swap_frame_size_ = frame_size; | |
73 } | |
74 display_->SetSurfaceId(delegated_surface_id_, | |
75 frame.metadata.device_scale_factor); | |
76 | |
77 factory_.SubmitCompositorFrame( | |
78 delegated_surface_id_, std::move(frame), | |
79 base::Bind(&DirectCompositorFrameSink::DidDrawCallback, | |
80 base::Unretained(this))); | |
81 } | |
82 | |
83 bool DirectCompositorFrameSink::BindToClient( | 57 bool DirectCompositorFrameSink::BindToClient( |
84 CompositorFrameSinkClient* client) { | 58 CompositorFrameSinkClient* client) { |
85 DCHECK(thread_checker_.CalledOnValidThread()); | 59 DCHECK(thread_checker_.CalledOnValidThread()); |
86 | 60 |
87 surface_manager_->RegisterSurfaceFactoryClient( | 61 surface_manager_->RegisterSurfaceFactoryClient( |
88 surface_id_allocator_->client_id(), this); | 62 surface_id_allocator_->client_id(), this); |
89 | 63 |
90 if (!CompositorFrameSink::BindToClient(client)) | 64 if (!CompositorFrameSink::BindToClient(client)) |
91 return false; | 65 return false; |
92 | 66 |
93 // We want the Display's output surface to hear about lost context, and since | 67 // We want the Display's output surface to hear about lost context, and since |
94 // this shares a context with it, we should not be listening for lost context | 68 // this shares a context with it, we should not be listening for lost context |
95 // callbacks on the context here. | 69 // callbacks on the context here. |
96 if (context_provider()) | 70 if (context_provider()) |
97 context_provider()->SetLostContextCallback(base::Closure()); | 71 context_provider()->SetLostContextCallback(base::Closure()); |
98 | 72 |
99 // Avoid initializing GL context here, as this should be sharing the | 73 // Avoid initializing GL context here, as this should be sharing the |
100 // Display's context. | 74 // Display's context. |
101 display_->Initialize(this, surface_manager_, | 75 display_->Initialize(this, surface_manager_, |
102 surface_id_allocator_->client_id()); | 76 surface_id_allocator_->client_id()); |
103 return true; | 77 return true; |
104 } | 78 } |
105 | 79 |
106 void DirectCompositorFrameSink::ForceReclaimResources() { | |
107 if (!delegated_surface_id_.is_null()) { | |
108 factory_.SubmitCompositorFrame(delegated_surface_id_, CompositorFrame(), | |
109 SurfaceFactory::DrawCallback()); | |
110 } | |
111 } | |
112 | |
113 void DirectCompositorFrameSink::DetachFromClient() { | 80 void DirectCompositorFrameSink::DetachFromClient() { |
114 DCHECK(HasClient()); | 81 DCHECK(HasClient()); |
115 // Unregister the SurfaceFactoryClient here instead of the dtor so that only | 82 // Unregister the SurfaceFactoryClient here instead of the dtor so that only |
116 // one client is alive for this namespace at any given time. | 83 // one client is alive for this namespace at any given time. |
117 surface_manager_->UnregisterSurfaceFactoryClient( | 84 surface_manager_->UnregisterSurfaceFactoryClient( |
118 surface_id_allocator_->client_id()); | 85 surface_id_allocator_->client_id()); |
119 if (!delegated_surface_id_.is_null()) | 86 if (!delegated_surface_id_.is_null()) |
120 factory_.Destroy(delegated_surface_id_); | 87 factory_.Destroy(delegated_surface_id_); |
121 | 88 |
122 CompositorFrameSink::DetachFromClient(); | 89 CompositorFrameSink::DetachFromClient(); |
123 } | 90 } |
124 | 91 |
125 void DirectCompositorFrameSink::BindFramebuffer() { | 92 void DirectCompositorFrameSink::SwapBuffers(CompositorFrame frame) { |
126 // This is a CompositorFrameSink, no framebuffer/direct drawing support. | 93 gfx::Size frame_size = |
127 NOTREACHED(); | 94 frame.delegated_frame_data->render_pass_list.back()->output_rect.size(); |
| 95 if (frame_size.IsEmpty() || frame_size != last_swap_frame_size_) { |
| 96 if (!delegated_surface_id_.is_null()) { |
| 97 factory_.Destroy(delegated_surface_id_); |
| 98 } |
| 99 delegated_surface_id_ = surface_id_allocator_->GenerateId(); |
| 100 factory_.Create(delegated_surface_id_); |
| 101 last_swap_frame_size_ = frame_size; |
| 102 } |
| 103 display_->SetSurfaceId(delegated_surface_id_, |
| 104 frame.metadata.device_scale_factor); |
| 105 |
| 106 factory_.SubmitCompositorFrame( |
| 107 delegated_surface_id_, std::move(frame), |
| 108 base::Bind(&DirectCompositorFrameSink::DidDrawCallback, |
| 109 base::Unretained(this))); |
128 } | 110 } |
129 | 111 |
130 uint32_t DirectCompositorFrameSink::GetFramebufferCopyTextureFormat() { | 112 void DirectCompositorFrameSink::ForceReclaimResources() { |
131 // This is a CompositorFrameSink, no framebuffer/direct drawing support. | 113 if (!delegated_surface_id_.is_null()) { |
132 NOTREACHED(); | 114 factory_.SubmitCompositorFrame(delegated_surface_id_, CompositorFrame(), |
133 return 0; | 115 SurfaceFactory::DrawCallback()); |
| 116 } |
134 } | 117 } |
135 | 118 |
136 void DirectCompositorFrameSink::ReturnResources( | 119 void DirectCompositorFrameSink::ReturnResources( |
137 const ReturnedResourceArray& resources) { | 120 const ReturnedResourceArray& resources) { |
138 if (client_) | 121 if (client_) |
139 client_->ReclaimResources(resources); | 122 client_->ReclaimResources(resources); |
140 } | 123 } |
141 | 124 |
142 void DirectCompositorFrameSink::SetBeginFrameSource( | 125 void DirectCompositorFrameSink::SetBeginFrameSource( |
143 BeginFrameSource* begin_frame_source) { | 126 BeginFrameSource* begin_frame_source) { |
(...skipping 18 matching lines...) Expand all Loading... |
162 // be drawn. | 145 // be drawn. |
163 } | 146 } |
164 | 147 |
165 void DirectCompositorFrameSink::DidDrawCallback() { | 148 void DirectCompositorFrameSink::DidDrawCallback() { |
166 // TODO(danakj): Why the lost check? | 149 // TODO(danakj): Why the lost check? |
167 if (!is_lost_) | 150 if (!is_lost_) |
168 client_->DidSwapBuffersComplete(); | 151 client_->DidSwapBuffersComplete(); |
169 } | 152 } |
170 | 153 |
171 } // namespace cc | 154 } // namespace cc |
OLD | NEW |