Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Side by Side Diff: services/ui/surfaces/display_compositor.cc

Issue 2539893002: Mus: Implement GpuMain mojo interface (Closed)
Patch Set: Addressed Sadrul's comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/ui/surfaces/display_compositor.h ('k') | services/ui/ws/gpu_service_proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "services/ui/surfaces/display_compositor.h" 5 #include "services/ui/surfaces/display_compositor.h"
6 6
7 #include "cc/output/in_process_context_provider.h" 7 #include "cc/output/in_process_context_provider.h"
8 #include "cc/surfaces/surface.h" 8 #include "cc/surfaces/surface.h"
9 #include "gpu/command_buffer/client/shared_memory_limits.h" 9 #include "gpu/command_buffer/client/shared_memory_limits.h"
10 #include "gpu/ipc/gpu_in_process_thread_service.h" 10 #include "gpu/ipc/gpu_in_process_thread_service.h"
11 #include "mojo/public/cpp/bindings/strong_binding.h" 11 #include "mojo/public/cpp/bindings/strong_binding.h"
12 #include "services/ui/common/mus_gpu_memory_buffer_manager.h" 12 #include "services/ui/common/mus_gpu_memory_buffer_manager.h"
13 #include "services/ui/surfaces/gpu_compositor_frame_sink.h" 13 #include "services/ui/surfaces/gpu_compositor_frame_sink.h"
14 14
15 namespace ui { 15 namespace ui {
16 16
17 DisplayCompositor::DisplayCompositor( 17 DisplayCompositor::DisplayCompositor(
18 scoped_refptr<gpu::InProcessCommandBuffer::Service> gpu_service, 18 scoped_refptr<gpu::InProcessCommandBuffer::Service> gpu_service,
19 std::unique_ptr<MusGpuMemoryBufferManager> gpu_memory_buffer_manager, 19 std::unique_ptr<gpu::GpuMemoryBufferManager> gpu_memory_buffer_manager,
20 gpu::ImageFactory* image_factory, 20 gpu::ImageFactory* image_factory,
21 cc::mojom::DisplayCompositorRequest request, 21 cc::mojom::DisplayCompositorRequest request,
22 cc::mojom::DisplayCompositorClientPtr client) 22 cc::mojom::DisplayCompositorClientPtr client)
23 : gpu_service_(std::move(gpu_service)), 23 : gpu_service_(std::move(gpu_service)),
24 gpu_memory_buffer_manager_(std::move(gpu_memory_buffer_manager)), 24 gpu_memory_buffer_manager_(std::move(gpu_memory_buffer_manager)),
25 image_factory_(image_factory), 25 image_factory_(image_factory),
26 client_(std::move(client)), 26 client_(std::move(client)),
27 binding_(this, std::move(request)) { 27 binding_(this, std::move(request)) {
28 manager_.AddObserver(this); 28 manager_.AddObserver(this);
29 } 29 }
30 30
31 void DisplayCompositor::CreateCompositorFrameSink( 31 void DisplayCompositor::CreateCompositorFrameSink(
32 const cc::FrameSinkId& frame_sink_id, 32 const cc::FrameSinkId& frame_sink_id,
33 gpu::SurfaceHandle surface_handle, 33 gpu::SurfaceHandle surface_handle,
34 cc::mojom::MojoCompositorFrameSinkRequest request, 34 cc::mojom::MojoCompositorFrameSinkRequest request,
35 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, 35 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request,
36 cc::mojom::MojoCompositorFrameSinkClientPtr client) { 36 cc::mojom::MojoCompositorFrameSinkClientPtr client) {
37 DCHECK(thread_checker_.CalledOnValidThread());
37 // We cannot create more than one CompositorFrameSink with a given 38 // We cannot create more than one CompositorFrameSink with a given
38 // |frame_sink_id|. 39 // |frame_sink_id|.
39 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id)); 40 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id));
40 scoped_refptr<cc::InProcessContextProvider> context_provider; 41 scoped_refptr<cc::InProcessContextProvider> context_provider;
41 if (surface_handle != gpu::kNullSurfaceHandle) { 42 if (surface_handle != gpu::kNullSurfaceHandle) {
42 context_provider = new cc::InProcessContextProvider( 43 context_provider = new cc::InProcessContextProvider(
43 gpu_service_, surface_handle, gpu_memory_buffer_manager_.get(), 44 gpu_service_, surface_handle, gpu_memory_buffer_manager_.get(),
44 image_factory_, gpu::SharedMemoryLimits(), 45 image_factory_, gpu::SharedMemoryLimits(),
45 nullptr /* shared_context */); 46 nullptr /* shared_context */);
46 } 47 }
47 compositor_frame_sinks_[frame_sink_id] = 48 compositor_frame_sinks_[frame_sink_id] =
48 base::MakeUnique<GpuCompositorFrameSink>( 49 base::MakeUnique<GpuCompositorFrameSink>(
49 this, frame_sink_id, surface_handle, gpu_memory_buffer_manager_.get(), 50 this, frame_sink_id, surface_handle, gpu_memory_buffer_manager_.get(),
50 std::move(context_provider), std::move(request), 51 std::move(context_provider), std::move(request),
51 std::move(private_request), std::move(client)); 52 std::move(private_request), std::move(client));
52 } 53 }
53 54
54 void DisplayCompositor::AddRootSurfaceReference(const cc::SurfaceId& child_id) { 55 void DisplayCompositor::AddRootSurfaceReference(const cc::SurfaceId& child_id) {
56 DCHECK(thread_checker_.CalledOnValidThread());
55 AddSurfaceReference(manager_.GetRootSurfaceId(), child_id); 57 AddSurfaceReference(manager_.GetRootSurfaceId(), child_id);
56 } 58 }
57 59
58 void DisplayCompositor::AddSurfaceReference(const cc::SurfaceId& parent_id, 60 void DisplayCompositor::AddSurfaceReference(const cc::SurfaceId& parent_id,
59 const cc::SurfaceId& child_id) { 61 const cc::SurfaceId& child_id) {
62 DCHECK(thread_checker_.CalledOnValidThread());
60 auto vector_iter = temp_references_.find(child_id.frame_sink_id()); 63 auto vector_iter = temp_references_.find(child_id.frame_sink_id());
61 64
62 // If there are no temporary references for the FrameSinkId then we can just 65 // If there are no temporary references for the FrameSinkId then we can just
63 // add reference and return. 66 // add reference and return.
64 if (vector_iter == temp_references_.end()) { 67 if (vector_iter == temp_references_.end()) {
65 manager_.AddSurfaceReference(parent_id, child_id); 68 manager_.AddSurfaceReference(parent_id, child_id);
66 return; 69 return;
67 } 70 }
68 71
69 // Get the vector<LocalFrameId> for the appropriate FrameSinkId and look for 72 // Get the vector<LocalFrameId> for the appropriate FrameSinkId and look for
(...skipping 30 matching lines...) Expand all
100 // element in |refs| then we are removing all temporary references for the 103 // element in |refs| then we are removing all temporary references for the
101 // FrameSinkId and can remove the map entry entirely. 104 // FrameSinkId and can remove the map entry entirely.
102 if (++temp_ref_iter == refs.end()) 105 if (++temp_ref_iter == refs.end())
103 temp_references_.erase(child_id.frame_sink_id()); 106 temp_references_.erase(child_id.frame_sink_id());
104 else 107 else
105 refs.erase(refs.begin(), ++temp_ref_iter); 108 refs.erase(refs.begin(), ++temp_ref_iter);
106 } 109 }
107 110
108 void DisplayCompositor::RemoveRootSurfaceReference( 111 void DisplayCompositor::RemoveRootSurfaceReference(
109 const cc::SurfaceId& child_id) { 112 const cc::SurfaceId& child_id) {
113 DCHECK(thread_checker_.CalledOnValidThread());
110 RemoveSurfaceReference(manager_.GetRootSurfaceId(), child_id); 114 RemoveSurfaceReference(manager_.GetRootSurfaceId(), child_id);
111 } 115 }
112 116
113 void DisplayCompositor::RemoveSurfaceReference(const cc::SurfaceId& parent_id, 117 void DisplayCompositor::RemoveSurfaceReference(const cc::SurfaceId& parent_id,
114 const cc::SurfaceId& child_id) { 118 const cc::SurfaceId& child_id) {
119 DCHECK(thread_checker_.CalledOnValidThread());
115 // TODO(kylechar): Each remove reference can trigger GC, it would be better if 120 // TODO(kylechar): Each remove reference can trigger GC, it would be better if
116 // we GC only once if removing multiple references. 121 // we GC only once if removing multiple references.
117 manager_.RemoveSurfaceReference(parent_id, child_id); 122 manager_.RemoveSurfaceReference(parent_id, child_id);
118 } 123 }
119 124
120 DisplayCompositor::~DisplayCompositor() { 125 DisplayCompositor::~DisplayCompositor() {
126 DCHECK(thread_checker_.CalledOnValidThread());
121 // Remove all temporary references on shutdown. 127 // Remove all temporary references on shutdown.
122 for (auto& map_entry : temp_references_) { 128 for (auto& map_entry : temp_references_) {
123 const cc::FrameSinkId& frame_sink_id = map_entry.first; 129 const cc::FrameSinkId& frame_sink_id = map_entry.first;
124 for (auto& local_frame_id : map_entry.second) { 130 for (auto& local_frame_id : map_entry.second) {
125 manager_.RemoveSurfaceReference( 131 manager_.RemoveSurfaceReference(
126 manager_.GetRootSurfaceId(), 132 manager_.GetRootSurfaceId(),
127 cc::SurfaceId(frame_sink_id, local_frame_id)); 133 cc::SurfaceId(frame_sink_id, local_frame_id));
128 } 134 }
129 } 135 }
130 manager_.RemoveObserver(this); 136 manager_.RemoveObserver(this);
131 } 137 }
132 138
133 void DisplayCompositor::OnCompositorFrameSinkClientConnectionLost( 139 void DisplayCompositor::OnCompositorFrameSinkClientConnectionLost(
134 const cc::FrameSinkId& frame_sink_id, 140 const cc::FrameSinkId& frame_sink_id,
135 bool destroy_compositor_frame_sink) { 141 bool destroy_compositor_frame_sink) {
142 DCHECK(thread_checker_.CalledOnValidThread());
136 if (destroy_compositor_frame_sink) 143 if (destroy_compositor_frame_sink)
137 compositor_frame_sinks_.erase(frame_sink_id); 144 compositor_frame_sinks_.erase(frame_sink_id);
138 // TODO(fsamuel): Tell the display compositor host that the client connection 145 // TODO(fsamuel): Tell the display compositor host that the client connection
139 // has been lost so that it can drop its private connection and allow a new 146 // has been lost so that it can drop its private connection and allow a new
140 // client instance to create a new CompositorFrameSink. 147 // client instance to create a new CompositorFrameSink.
141 } 148 }
142 149
143 void DisplayCompositor::OnCompositorFrameSinkPrivateConnectionLost( 150 void DisplayCompositor::OnCompositorFrameSinkPrivateConnectionLost(
144 const cc::FrameSinkId& frame_sink_id, 151 const cc::FrameSinkId& frame_sink_id,
145 bool destroy_compositor_frame_sink) { 152 bool destroy_compositor_frame_sink) {
153 DCHECK(thread_checker_.CalledOnValidThread());
146 if (destroy_compositor_frame_sink) 154 if (destroy_compositor_frame_sink)
147 compositor_frame_sinks_.erase(frame_sink_id); 155 compositor_frame_sinks_.erase(frame_sink_id);
148 } 156 }
149 157
150 void DisplayCompositor::OnSurfaceCreated(const cc::SurfaceId& surface_id, 158 void DisplayCompositor::OnSurfaceCreated(const cc::SurfaceId& surface_id,
151 const gfx::Size& frame_size, 159 const gfx::Size& frame_size,
152 float device_scale_factor) { 160 float device_scale_factor) {
161 DCHECK(thread_checker_.CalledOnValidThread());
153 // We can get into a situation where multiple CompositorFrames arrive for a 162 // We can get into a situation where multiple CompositorFrames arrive for a
154 // CompositorFrameSink before the DisplayCompositorClient can add any 163 // CompositorFrameSink before the DisplayCompositorClient can add any
155 // references for the frame. When the second frame with a new size arrives, 164 // references for the frame. When the second frame with a new size arrives,
156 // the first will be destroyed and then if there are no references it will be 165 // the first will be destroyed and then if there are no references it will be
157 // deleted during surface GC. A temporary reference, removed when a real 166 // deleted during surface GC. A temporary reference, removed when a real
158 // reference is received, is added to prevent this from happening. 167 // reference is received, is added to prevent this from happening.
159 manager_.AddSurfaceReference(manager_.GetRootSurfaceId(), surface_id); 168 manager_.AddSurfaceReference(manager_.GetRootSurfaceId(), surface_id);
160 temp_references_[surface_id.frame_sink_id()].push_back( 169 temp_references_[surface_id.frame_sink_id()].push_back(
161 surface_id.local_frame_id()); 170 surface_id.local_frame_id());
162 171
163 if (client_) 172 if (client_)
164 client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor); 173 client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor);
165 } 174 }
166 175
167 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id, 176 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id,
168 bool* changed) {} 177 bool* changed) {}
169 178
170 } // namespace ui 179 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/surfaces/display_compositor.h ('k') | services/ui/ws/gpu_service_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698