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

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

Issue 2543123004: Mus: Move creation of cc::Display to DisplayCompositor (Closed)
Patch Set: More cleanup 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
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 <utility> 7 #include <utility>
8 8
9 #include "cc/output/in_process_context_provider.h" 9 #include "cc/output/in_process_context_provider.h"
10 #include "cc/output/texture_mailbox_deleter.h"
11 #include "cc/surfaces/display.h"
12 #include "cc/surfaces/display_scheduler.h"
10 #include "cc/surfaces/surface.h" 13 #include "cc/surfaces/surface.h"
11 #include "gpu/command_buffer/client/shared_memory_limits.h" 14 #include "gpu/command_buffer/client/shared_memory_limits.h"
12 #include "gpu/ipc/gpu_in_process_thread_service.h" 15 #include "gpu/ipc/gpu_in_process_thread_service.h"
13 #include "mojo/public/cpp/bindings/strong_binding.h" 16 #include "mojo/public/cpp/bindings/strong_binding.h"
17 #include "services/ui/surfaces/display_output_surface.h"
14 #include "services/ui/surfaces/gpu_compositor_frame_sink.h" 18 #include "services/ui/surfaces/gpu_compositor_frame_sink.h"
15 19
20 #if defined(USE_OZONE)
21 #include "gpu/command_buffer/client/gles2_interface.h"
22 #include "services/ui/surfaces/display_output_surface_ozone.h"
23 #endif
24
16 namespace ui { 25 namespace ui {
17 26
18 DisplayCompositor::DisplayCompositor( 27 DisplayCompositor::DisplayCompositor(
19 scoped_refptr<gpu::InProcessCommandBuffer::Service> gpu_service, 28 scoped_refptr<gpu::InProcessCommandBuffer::Service> gpu_service,
20 std::unique_ptr<gpu::GpuMemoryBufferManager> gpu_memory_buffer_manager, 29 std::unique_ptr<gpu::GpuMemoryBufferManager> gpu_memory_buffer_manager,
21 gpu::ImageFactory* image_factory, 30 gpu::ImageFactory* image_factory,
22 cc::mojom::DisplayCompositorRequest request, 31 cc::mojom::DisplayCompositorRequest request,
23 cc::mojom::DisplayCompositorClientPtr client) 32 cc::mojom::DisplayCompositorClientPtr client)
24 : manager_(cc::SurfaceManager::LifetimeType::REFERENCES), 33 : manager_(cc::SurfaceManager::LifetimeType::REFERENCES),
34 reference_manager_(&manager_),
25 gpu_service_(std::move(gpu_service)), 35 gpu_service_(std::move(gpu_service)),
26 gpu_memory_buffer_manager_(std::move(gpu_memory_buffer_manager)), 36 gpu_memory_buffer_manager_(std::move(gpu_memory_buffer_manager)),
27 image_factory_(image_factory), 37 image_factory_(image_factory),
38 task_runner_(base::ThreadTaskRunnerHandle::Get()),
28 client_(std::move(client)), 39 client_(std::move(client)),
29 reference_manager_(&manager_),
30 binding_(this, std::move(request)) { 40 binding_(this, std::move(request)) {
31 manager_.AddObserver(this); 41 manager_.AddObserver(this);
32 } 42 }
33 43
34 void DisplayCompositor::CreateCompositorFrameSink( 44 void DisplayCompositor::CreateCompositorFrameSink(
35 const cc::FrameSinkId& frame_sink_id, 45 const cc::FrameSinkId& frame_sink_id,
36 gpu::SurfaceHandle surface_handle, 46 gpu::SurfaceHandle surface_handle,
37 cc::mojom::MojoCompositorFrameSinkRequest request, 47 cc::mojom::MojoCompositorFrameSinkRequest request,
38 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, 48 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request,
39 cc::mojom::MojoCompositorFrameSinkClientPtr client) { 49 cc::mojom::MojoCompositorFrameSinkClientPtr client) {
40 DCHECK(thread_checker_.CalledOnValidThread()); 50 DCHECK(thread_checker_.CalledOnValidThread());
41 // We cannot create more than one CompositorFrameSink with a given 51 // We cannot create more than one CompositorFrameSink with a given
42 // |frame_sink_id|. 52 // |frame_sink_id|.
43 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id)); 53 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id));
44 scoped_refptr<cc::InProcessContextProvider> context_provider; 54
45 if (surface_handle != gpu::kNullSurfaceHandle) { 55 std::unique_ptr<cc::Display> display;
46 context_provider = new cc::InProcessContextProvider( 56 if (surface_handle != gpu::kNullSurfaceHandle)
47 gpu_service_, surface_handle, gpu_memory_buffer_manager_.get(), 57 display = CreateDisplay(frame_sink_id, surface_handle);
48 image_factory_, gpu::SharedMemoryLimits(), 58
49 nullptr /* shared_context */);
50 }
51 compositor_frame_sinks_[frame_sink_id] = 59 compositor_frame_sinks_[frame_sink_id] =
52 base::MakeUnique<GpuCompositorFrameSink>( 60 base::MakeUnique<GpuCompositorFrameSink>(
53 this, frame_sink_id, surface_handle, gpu_memory_buffer_manager_.get(), 61 this, frame_sink_id, std::move(display), std::move(request),
54 std::move(context_provider), std::move(request),
55 std::move(private_request), std::move(client)); 62 std::move(private_request), std::move(client));
56 } 63 }
57 64
58 void DisplayCompositor::AddRootSurfaceReference(const cc::SurfaceId& child_id) { 65 void DisplayCompositor::AddRootSurfaceReference(const cc::SurfaceId& child_id) {
59 DCHECK(thread_checker_.CalledOnValidThread()); 66 DCHECK(thread_checker_.CalledOnValidThread());
60 AddSurfaceReference(GetRootSurfaceId(), child_id); 67 AddSurfaceReference(GetRootSurfaceId(), child_id);
61 } 68 }
62 69
63 void DisplayCompositor::AddSurfaceReference(const cc::SurfaceId& parent_id, 70 void DisplayCompositor::AddSurfaceReference(const cc::SurfaceId& parent_id,
64 const cc::SurfaceId& child_id) { 71 const cc::SurfaceId& child_id) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 } 157 }
151 158
152 void DisplayCompositor::OnCompositorFrameSinkPrivateConnectionLost( 159 void DisplayCompositor::OnCompositorFrameSinkPrivateConnectionLost(
153 const cc::FrameSinkId& frame_sink_id, 160 const cc::FrameSinkId& frame_sink_id,
154 bool destroy_compositor_frame_sink) { 161 bool destroy_compositor_frame_sink) {
155 DCHECK(thread_checker_.CalledOnValidThread()); 162 DCHECK(thread_checker_.CalledOnValidThread());
156 if (destroy_compositor_frame_sink) 163 if (destroy_compositor_frame_sink)
157 compositor_frame_sinks_.erase(frame_sink_id); 164 compositor_frame_sinks_.erase(frame_sink_id);
158 } 165 }
159 166
167 std::unique_ptr<cc::Display> DisplayCompositor::CreateDisplay(
168 const cc::FrameSinkId& frame_sink_id,
169 gpu::SurfaceHandle surface_handle) {
170 scoped_refptr<cc::InProcessContextProvider> context_provider =
171 new cc::InProcessContextProvider(
172 gpu_service_, surface_handle, gpu_memory_buffer_manager_.get(),
173 image_factory_, gpu::SharedMemoryLimits(),
174 nullptr /* shared_context */);
175
176 // TODO(rjkroege): If there is something better to do than CHECK, add it.
177 CHECK(context_provider->BindToCurrentThread());
178
179 std::unique_ptr<cc::SyntheticBeginFrameSource> synthetic_begin_frame_source(
180 new cc::DelayBasedBeginFrameSource(
181 base::MakeUnique<cc::DelayBasedTimeSource>(task_runner_.get())));
182
183 std::unique_ptr<cc::OutputSurface> display_output_surface;
184 if (context_provider->ContextCapabilities().surfaceless) {
185 #if defined(USE_OZONE)
186 display_output_surface = base::MakeUnique<DisplayOutputSurfaceOzone>(
187 std::move(context_provider), surface_handle,
188 synthetic_begin_frame_source.get(), gpu_memory_buffer_manager_.get(),
189 GL_TEXTURE_2D, GL_RGB);
190 #else
191 NOTREACHED();
192 #endif
193 } else {
194 display_output_surface = base::MakeUnique<DisplayOutputSurface>(
195 std::move(context_provider), synthetic_begin_frame_source.get());
196 }
197
198 int max_frames_pending =
199 display_output_surface->capabilities().max_frames_pending;
200 DCHECK_GT(max_frames_pending, 0);
201
202 std::unique_ptr<cc::DisplayScheduler> scheduler(
203 new cc::DisplayScheduler(synthetic_begin_frame_source.get(),
204 task_runner_.get(), max_frames_pending));
205
206 return base::MakeUnique<cc::Display>(
207 nullptr /* bitmap_manager */, gpu_memory_buffer_manager_.get(),
208 cc::RendererSettings(), frame_sink_id,
209 std::move(synthetic_begin_frame_source),
210 std::move(display_output_surface), std::move(scheduler),
211 base::MakeUnique<cc::TextureMailboxDeleter>(task_runner_.get()));
212 }
213
160 const cc::SurfaceId& DisplayCompositor::GetRootSurfaceId() const { 214 const cc::SurfaceId& DisplayCompositor::GetRootSurfaceId() const {
161 return reference_manager_->GetRootSurfaceId(); 215 return reference_manager_->GetRootSurfaceId();
162 } 216 }
163 217
164 void DisplayCompositor::OnSurfaceCreated(const cc::SurfaceId& surface_id, 218 void DisplayCompositor::OnSurfaceCreated(const cc::SurfaceId& surface_id,
165 const gfx::Size& frame_size, 219 const gfx::Size& frame_size,
166 float device_scale_factor) { 220 float device_scale_factor) {
167 DCHECK(thread_checker_.CalledOnValidThread()); 221 DCHECK(thread_checker_.CalledOnValidThread());
168 // We can get into a situation where multiple CompositorFrames arrive for a 222 // We can get into a situation where multiple CompositorFrames arrive for a
169 // CompositorFrameSink before the DisplayCompositorClient can add any 223 // CompositorFrameSink before the DisplayCompositorClient can add any
170 // references for the frame. When the second frame with a new size arrives, 224 // references for the frame. When the second frame with a new size arrives,
171 // the first will be destroyed and then if there are no references it will be 225 // the first will be destroyed and then if there are no references it will be
172 // deleted during surface GC. A temporary reference, removed when a real 226 // deleted during surface GC. A temporary reference, removed when a real
173 // reference is received, is added to prevent this from happening. 227 // reference is received, is added to prevent this from happening.
174 reference_manager_->AddSurfaceReference(GetRootSurfaceId(), surface_id); 228 reference_manager_->AddSurfaceReference(GetRootSurfaceId(), surface_id);
175 temp_references_[surface_id.frame_sink_id()].push_back( 229 temp_references_[surface_id.frame_sink_id()].push_back(
176 surface_id.local_frame_id()); 230 surface_id.local_frame_id());
177 231
178 if (client_) 232 if (client_)
179 client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor); 233 client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor);
180 } 234 }
181 235
182 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id, 236 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id,
183 bool* changed) {} 237 bool* changed) {}
184 238
185 } // namespace ui 239 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/surfaces/display_compositor.h ('k') | services/ui/surfaces/gpu_compositor_frame_sink.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698