| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "services/ui/surfaces/display_compositor.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "base/command_line.h" | |
| 10 #include "base/memory/ptr_util.h" | |
| 11 #include "base/threading/thread_task_runner_handle.h" | |
| 12 #include "cc/base/switches.h" | |
| 13 #include "cc/output/in_process_context_provider.h" | |
| 14 #include "cc/output/texture_mailbox_deleter.h" | |
| 15 #include "cc/surfaces/display.h" | |
| 16 #include "cc/surfaces/display_scheduler.h" | |
| 17 #include "cc/surfaces/surface.h" | |
| 18 #include "components/display_compositor/gpu_compositor_frame_sink.h" | |
| 19 #include "components/display_compositor/gpu_root_compositor_frame_sink.h" | |
| 20 #include "gpu/command_buffer/client/shared_memory_limits.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 | |
| 30 namespace ui { | |
| 31 | |
| 32 DisplayCompositor::DisplayCompositor( | |
| 33 scoped_refptr<gpu::InProcessCommandBuffer::Service> gpu_service, | |
| 34 std::unique_ptr<gpu::GpuMemoryBufferManager> gpu_memory_buffer_manager, | |
| 35 gpu::ImageFactory* image_factory, | |
| 36 cc::mojom::DisplayCompositorRequest request, | |
| 37 cc::mojom::DisplayCompositorClientPtr client) | |
| 38 : manager_(cc::SurfaceManager::LifetimeType::REFERENCES), | |
| 39 gpu_service_(std::move(gpu_service)), | |
| 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)), | |
| 44 binding_(this, std::move(request)) { | |
| 45 manager_.AddObserver(this); | |
| 46 } | |
| 47 | |
| 48 DisplayCompositor::~DisplayCompositor() { | |
| 49 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 50 manager_.RemoveObserver(this); | |
| 51 } | |
| 52 | |
| 53 void DisplayCompositor::CreateRootCompositorFrameSink( | |
| 54 const cc::FrameSinkId& frame_sink_id, | |
| 55 gpu::SurfaceHandle surface_handle, | |
| 56 cc::mojom::MojoCompositorFrameSinkAssociatedRequest request, | |
| 57 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, | |
| 58 cc::mojom::MojoCompositorFrameSinkClientPtr client, | |
| 59 cc::mojom::DisplayPrivateAssociatedRequest display_private_request) { | |
| 60 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 61 DCHECK_NE(surface_handle, gpu::kNullSurfaceHandle); | |
| 62 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id)); | |
| 63 | |
| 64 std::unique_ptr<cc::SyntheticBeginFrameSource> begin_frame_source( | |
| 65 new cc::DelayBasedBeginFrameSource( | |
| 66 base::MakeUnique<cc::DelayBasedTimeSource>(task_runner_.get()))); | |
| 67 std::unique_ptr<cc::Display> display = | |
| 68 CreateDisplay(frame_sink_id, surface_handle, begin_frame_source.get()); | |
| 69 | |
| 70 // Lazily inject a SurfaceDependencyTracker into SurfaceManager if surface | |
| 71 // synchronization is enabled. | |
| 72 if (!manager_.dependency_tracker() && | |
| 73 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 74 cc::switches::kEnableSurfaceSynchronization)) { | |
| 75 std::unique_ptr<cc::SurfaceDependencyTracker> dependency_tracker( | |
| 76 new cc::SurfaceDependencyTracker(&manager_, begin_frame_source.get())); | |
| 77 manager_.SetDependencyTracker(std::move(dependency_tracker)); | |
| 78 } | |
| 79 | |
| 80 compositor_frame_sinks_[frame_sink_id] = | |
| 81 base::MakeUnique<display_compositor::GpuRootCompositorFrameSink>( | |
| 82 this, &manager_, frame_sink_id, std::move(display), | |
| 83 std::move(begin_frame_source), std::move(request), | |
| 84 std::move(private_request), std::move(client), | |
| 85 std::move(display_private_request)); | |
| 86 } | |
| 87 | |
| 88 void DisplayCompositor::CreateCompositorFrameSink( | |
| 89 const cc::FrameSinkId& frame_sink_id, | |
| 90 cc::mojom::MojoCompositorFrameSinkRequest request, | |
| 91 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, | |
| 92 cc::mojom::MojoCompositorFrameSinkClientPtr client) { | |
| 93 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 94 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id)); | |
| 95 | |
| 96 compositor_frame_sinks_[frame_sink_id] = | |
| 97 base::MakeUnique<display_compositor::GpuCompositorFrameSink>( | |
| 98 this, &manager_, frame_sink_id, std::move(request), | |
| 99 std::move(private_request), std::move(client)); | |
| 100 } | |
| 101 | |
| 102 void DisplayCompositor::RegisterFrameSinkHierarchy( | |
| 103 const cc::FrameSinkId& parent_frame_sink_id, | |
| 104 const cc::FrameSinkId& child_frame_sink_id) { | |
| 105 manager_.RegisterFrameSinkHierarchy(parent_frame_sink_id, | |
| 106 child_frame_sink_id); | |
| 107 } | |
| 108 | |
| 109 void DisplayCompositor::UnregisterFrameSinkHierarchy( | |
| 110 const cc::FrameSinkId& parent_frame_sink_id, | |
| 111 const cc::FrameSinkId& child_frame_sink_id) { | |
| 112 manager_.UnregisterFrameSinkHierarchy(parent_frame_sink_id, | |
| 113 child_frame_sink_id); | |
| 114 } | |
| 115 | |
| 116 void DisplayCompositor::DropTemporaryReference( | |
| 117 const cc::SurfaceId& surface_id) { | |
| 118 manager_.DropTemporaryReference(surface_id); | |
| 119 } | |
| 120 | |
| 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) { | |
| 169 compositor_frame_sinks_.erase(sink_id); | |
| 170 } | |
| 171 | |
| 172 void DisplayCompositor::OnSurfaceCreated(const cc::SurfaceInfo& surface_info) { | |
| 173 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 174 DCHECK_GT(surface_info.device_scale_factor(), 0.0f); | |
| 175 | |
| 176 // TODO(kylechar): |client_| will try to find an owner for the temporary | |
| 177 // reference to the new surface. With surface synchronization this might not | |
| 178 // be necessary, because a surface reference might already exist and no | |
| 179 // temporary reference was created. It could be useful to let |client_| know | |
| 180 // if it should find an owner. | |
| 181 if (client_) | |
| 182 client_->OnSurfaceCreated(surface_info); | |
| 183 } | |
| 184 | |
| 185 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id, | |
| 186 bool* changed) {} | |
| 187 | |
| 188 void DisplayCompositor::OnClientConnectionLost( | |
| 189 const cc::FrameSinkId& frame_sink_id, | |
| 190 bool destroy_compositor_frame_sink) { | |
| 191 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 192 if (destroy_compositor_frame_sink) | |
| 193 DestroyCompositorFrameSink(frame_sink_id); | |
| 194 // TODO(fsamuel): Tell the display compositor host that the client connection | |
| 195 // has been lost so that it can drop its private connection and allow a new | |
| 196 // client instance to create a new CompositorFrameSink. | |
| 197 } | |
| 198 | |
| 199 void DisplayCompositor::OnPrivateConnectionLost( | |
| 200 const cc::FrameSinkId& frame_sink_id, | |
| 201 bool destroy_compositor_frame_sink) { | |
| 202 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 203 if (destroy_compositor_frame_sink) | |
| 204 DestroyCompositorFrameSink(frame_sink_id); | |
| 205 } | |
| 206 | |
| 207 } // namespace ui | |
| OLD | NEW |