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

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

Issue 2778863002: Introduce DisplayProvider for DisplayCompositor. (Closed)
Patch Set: Delete extra task runner ref. Created 3 years, 8 months 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/surfaces/display_provider.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 <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/threading/thread_task_runner_handle.h"
12 #include "cc/base/switches.h" 11 #include "cc/base/switches.h"
13 #include "cc/output/in_process_context_provider.h" 12 #include "cc/scheduler/begin_frame_source.h"
14 #include "cc/output/texture_mailbox_deleter.h"
15 #include "cc/surfaces/display.h" 13 #include "cc/surfaces/display.h"
16 #include "cc/surfaces/display_scheduler.h" 14 #include "cc/surfaces/surface_dependency_tracker.h"
17 #include "cc/surfaces/surface.h"
18 #include "components/display_compositor/gpu_compositor_frame_sink.h" 15 #include "components/display_compositor/gpu_compositor_frame_sink.h"
19 #include "components/display_compositor/gpu_root_compositor_frame_sink.h" 16 #include "components/display_compositor/gpu_root_compositor_frame_sink.h"
20 #include "gpu/command_buffer/client/shared_memory_limits.h" 17 #include "services/ui/surfaces/display_provider.h"
21 #include "gpu/ipc/gpu_in_process_thread_service.h"
22 #include "mojo/public/cpp/bindings/strong_binding.h"
23 #include "services/ui/surfaces/display_output_surface.h"
24
25 #if defined(USE_OZONE)
26 #include "gpu/command_buffer/client/gles2_interface.h"
27 #include "services/ui/surfaces/display_output_surface_ozone.h"
28 #endif
29 18
30 namespace ui { 19 namespace ui {
31 20
32 DisplayCompositor::DisplayCompositor( 21 DisplayCompositor::DisplayCompositor(
33 scoped_refptr<gpu::InProcessCommandBuffer::Service> gpu_service, 22 DisplayProvider* display_provider,
34 std::unique_ptr<gpu::GpuMemoryBufferManager> gpu_memory_buffer_manager,
35 gpu::ImageFactory* image_factory,
36 cc::mojom::DisplayCompositorRequest request, 23 cc::mojom::DisplayCompositorRequest request,
37 cc::mojom::DisplayCompositorClientPtr client) 24 cc::mojom::DisplayCompositorClientPtr client)
38 : manager_(cc::SurfaceManager::LifetimeType::REFERENCES), 25 : manager_(cc::SurfaceManager::LifetimeType::REFERENCES),
39 gpu_service_(std::move(gpu_service)), 26 display_provider_(display_provider),
40 gpu_memory_buffer_manager_(std::move(gpu_memory_buffer_manager)),
41 image_factory_(image_factory),
42 task_runner_(base::ThreadTaskRunnerHandle::Get()),
43 client_(std::move(client)), 27 client_(std::move(client)),
44 binding_(this, std::move(request)) { 28 binding_(this, std::move(request)) {
45 manager_.AddObserver(this); 29 manager_.AddObserver(this);
46 } 30 }
47 31
48 DisplayCompositor::~DisplayCompositor() { 32 DisplayCompositor::~DisplayCompositor() {
49 DCHECK(thread_checker_.CalledOnValidThread()); 33 DCHECK(thread_checker_.CalledOnValidThread());
50 manager_.RemoveObserver(this); 34 manager_.RemoveObserver(this);
51 } 35 }
52 36
53 void DisplayCompositor::CreateRootCompositorFrameSink( 37 void DisplayCompositor::CreateRootCompositorFrameSink(
54 const cc::FrameSinkId& frame_sink_id, 38 const cc::FrameSinkId& frame_sink_id,
55 gpu::SurfaceHandle surface_handle, 39 gpu::SurfaceHandle surface_handle,
56 cc::mojom::MojoCompositorFrameSinkAssociatedRequest request, 40 cc::mojom::MojoCompositorFrameSinkAssociatedRequest request,
57 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, 41 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request,
58 cc::mojom::MojoCompositorFrameSinkClientPtr client, 42 cc::mojom::MojoCompositorFrameSinkClientPtr client,
59 cc::mojom::DisplayPrivateAssociatedRequest display_private_request) { 43 cc::mojom::DisplayPrivateAssociatedRequest display_private_request) {
60 DCHECK(thread_checker_.CalledOnValidThread()); 44 DCHECK(thread_checker_.CalledOnValidThread());
61 DCHECK_NE(surface_handle, gpu::kNullSurfaceHandle); 45 DCHECK_NE(surface_handle, gpu::kNullSurfaceHandle);
62 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id)); 46 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id));
47 DCHECK(display_provider_);
63 48
64 std::unique_ptr<cc::SyntheticBeginFrameSource> begin_frame_source( 49 std::unique_ptr<cc::BeginFrameSource> begin_frame_source;
65 new cc::DelayBasedBeginFrameSource( 50 std::unique_ptr<cc::Display> display = display_provider_->CreateDisplay(
66 base::MakeUnique<cc::DelayBasedTimeSource>(task_runner_.get()))); 51 frame_sink_id, surface_handle, &begin_frame_source);
67 std::unique_ptr<cc::Display> display =
68 CreateDisplay(frame_sink_id, surface_handle, begin_frame_source.get());
69 52
70 // Lazily inject a SurfaceDependencyTracker into SurfaceManager if surface 53 // Lazily inject a SurfaceDependencyTracker into SurfaceManager if surface
71 // synchronization is enabled. 54 // synchronization is enabled.
72 if (!manager_.dependency_tracker() && 55 if (!manager_.dependency_tracker() &&
73 base::CommandLine::ForCurrentProcess()->HasSwitch( 56 base::CommandLine::ForCurrentProcess()->HasSwitch(
74 cc::switches::kEnableSurfaceSynchronization)) { 57 cc::switches::kEnableSurfaceSynchronization)) {
75 std::unique_ptr<cc::SurfaceDependencyTracker> dependency_tracker( 58 std::unique_ptr<cc::SurfaceDependencyTracker> dependency_tracker(
76 new cc::SurfaceDependencyTracker(&manager_, begin_frame_source.get())); 59 new cc::SurfaceDependencyTracker(&manager_, begin_frame_source.get()));
77 manager_.SetDependencyTracker(std::move(dependency_tracker)); 60 manager_.SetDependencyTracker(std::move(dependency_tracker));
78 } 61 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 const cc::FrameSinkId& child_frame_sink_id) { 94 const cc::FrameSinkId& child_frame_sink_id) {
112 manager_.UnregisterFrameSinkHierarchy(parent_frame_sink_id, 95 manager_.UnregisterFrameSinkHierarchy(parent_frame_sink_id,
113 child_frame_sink_id); 96 child_frame_sink_id);
114 } 97 }
115 98
116 void DisplayCompositor::DropTemporaryReference( 99 void DisplayCompositor::DropTemporaryReference(
117 const cc::SurfaceId& surface_id) { 100 const cc::SurfaceId& surface_id) {
118 manager_.DropTemporaryReference(surface_id); 101 manager_.DropTemporaryReference(surface_id);
119 } 102 }
120 103
121 std::unique_ptr<cc::Display> DisplayCompositor::CreateDisplay(
122 const cc::FrameSinkId& frame_sink_id,
123 gpu::SurfaceHandle surface_handle,
124 cc::SyntheticBeginFrameSource* begin_frame_source) {
125 scoped_refptr<cc::InProcessContextProvider> context_provider =
126 new cc::InProcessContextProvider(
127 gpu_service_, surface_handle, gpu_memory_buffer_manager_.get(),
128 image_factory_, gpu::SharedMemoryLimits(),
129 nullptr /* shared_context */);
130
131 // TODO(rjkroege): If there is something better to do than CHECK, add it.
132 CHECK(context_provider->BindToCurrentThread());
133
134 std::unique_ptr<cc::OutputSurface> display_output_surface;
135 if (context_provider->ContextCapabilities().surfaceless) {
136 #if defined(USE_OZONE)
137 display_output_surface = base::MakeUnique<DisplayOutputSurfaceOzone>(
138 std::move(context_provider), surface_handle,
139 begin_frame_source, gpu_memory_buffer_manager_.get(),
140 GL_TEXTURE_2D, GL_RGB);
141 #else
142 NOTREACHED();
143 #endif
144 } else {
145 display_output_surface = base::MakeUnique<DisplayOutputSurface>(
146 std::move(context_provider), begin_frame_source);
147 }
148
149 int max_frames_pending =
150 display_output_surface->capabilities().max_frames_pending;
151 DCHECK_GT(max_frames_pending, 0);
152
153 std::unique_ptr<cc::DisplayScheduler> scheduler(
154 new cc::DisplayScheduler(task_runner_.get(), max_frames_pending));
155
156 cc::RendererSettings settings;
157 settings.show_overdraw_feedback =
158 base::CommandLine::ForCurrentProcess()->HasSwitch(
159 cc::switches::kShowOverdrawFeedback);
160
161 return base::MakeUnique<cc::Display>(
162 nullptr /* bitmap_manager */, gpu_memory_buffer_manager_.get(), settings,
163 frame_sink_id, begin_frame_source, std::move(display_output_surface),
164 std::move(scheduler),
165 base::MakeUnique<cc::TextureMailboxDeleter>(task_runner_.get()));
166 }
167
168 void DisplayCompositor::DestroyCompositorFrameSink(cc::FrameSinkId sink_id) { 104 void DisplayCompositor::DestroyCompositorFrameSink(cc::FrameSinkId sink_id) {
169 compositor_frame_sinks_.erase(sink_id); 105 compositor_frame_sinks_.erase(sink_id);
170 } 106 }
171 107
172 void DisplayCompositor::OnSurfaceCreated(const cc::SurfaceInfo& surface_info) { 108 void DisplayCompositor::OnSurfaceCreated(const cc::SurfaceInfo& surface_info) {
173 DCHECK(thread_checker_.CalledOnValidThread()); 109 DCHECK(thread_checker_.CalledOnValidThread());
174 DCHECK_GT(surface_info.device_scale_factor(), 0.0f); 110 DCHECK_GT(surface_info.device_scale_factor(), 0.0f);
175 111
176 // TODO(kylechar): |client_| will try to find an owner for the temporary 112 // TODO(kylechar): |client_| will try to find an owner for the temporary
177 // reference to the new surface. With surface synchronization this might not 113 // reference to the new surface. With surface synchronization this might not
(...skipping 20 matching lines...) Expand all
198 134
199 void DisplayCompositor::OnPrivateConnectionLost( 135 void DisplayCompositor::OnPrivateConnectionLost(
200 const cc::FrameSinkId& frame_sink_id, 136 const cc::FrameSinkId& frame_sink_id,
201 bool destroy_compositor_frame_sink) { 137 bool destroy_compositor_frame_sink) {
202 DCHECK(thread_checker_.CalledOnValidThread()); 138 DCHECK(thread_checker_.CalledOnValidThread());
203 if (destroy_compositor_frame_sink) 139 if (destroy_compositor_frame_sink)
204 DestroyCompositorFrameSink(frame_sink_id); 140 DestroyCompositorFrameSink(frame_sink_id);
205 } 141 }
206 142
207 } // namespace ui 143 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/surfaces/display_compositor.h ('k') | services/ui/surfaces/display_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698