| OLD | NEW |
| 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" | 10 #include "cc/output/texture_mailbox_deleter.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 gpu::SurfaceHandle surface_handle, | 97 gpu::SurfaceHandle surface_handle, |
| 98 cc::mojom::MojoCompositorFrameSinkRequest request, | 98 cc::mojom::MojoCompositorFrameSinkRequest request, |
| 99 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, | 99 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, |
| 100 cc::mojom::MojoCompositorFrameSinkClientPtr client) { | 100 cc::mojom::MojoCompositorFrameSinkClientPtr client) { |
| 101 DCHECK(thread_checker_.CalledOnValidThread()); | 101 DCHECK(thread_checker_.CalledOnValidThread()); |
| 102 // We cannot create more than one CompositorFrameSink with a given | 102 // We cannot create more than one CompositorFrameSink with a given |
| 103 // |frame_sink_id|. | 103 // |frame_sink_id|. |
| 104 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id)); | 104 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id)); |
| 105 | 105 |
| 106 std::unique_ptr<cc::Display> display; | 106 std::unique_ptr<cc::Display> display; |
| 107 if (surface_handle != gpu::kNullSurfaceHandle) | 107 std::unique_ptr<cc::SyntheticBeginFrameSource> begin_frame_source; |
| 108 display = CreateDisplay(frame_sink_id, surface_handle); | 108 if (surface_handle != gpu::kNullSurfaceHandle) { |
| 109 begin_frame_source.reset(new cc::DelayBasedBeginFrameSource( |
| 110 base::MakeUnique<cc::DelayBasedTimeSource>(task_runner_.get()))); |
| 111 display = |
| 112 CreateDisplay(frame_sink_id, surface_handle, begin_frame_source.get()); |
| 113 } |
| 109 | 114 |
| 110 compositor_frame_sinks_[frame_sink_id] = | 115 compositor_frame_sinks_[frame_sink_id] = |
| 111 base::MakeUnique<GpuCompositorFrameSink>( | 116 base::MakeUnique<GpuCompositorFrameSink>( |
| 112 this, frame_sink_id, std::move(display), std::move(request), | 117 this, frame_sink_id, std::move(display), |
| 118 std::move(begin_frame_source), std::move(request), |
| 113 std::move(private_request), std::move(client)); | 119 std::move(private_request), std::move(client)); |
| 114 } | 120 } |
| 115 | 121 |
| 116 void DisplayCompositor::AddSurfaceReference(const cc::SurfaceReference& ref) { | 122 void DisplayCompositor::AddSurfaceReference(const cc::SurfaceReference& ref) { |
| 117 const cc::SurfaceId& parent_id = ref.parent_id(); | 123 const cc::SurfaceId& parent_id = ref.parent_id(); |
| 118 const cc::SurfaceId& child_id = ref.child_id(); | 124 const cc::SurfaceId& child_id = ref.child_id(); |
| 119 | 125 |
| 120 auto vector_iter = temp_references_.find(child_id.frame_sink_id()); | 126 auto vector_iter = temp_references_.find(child_id.frame_sink_id()); |
| 121 | 127 |
| 122 // If there are no temporary references for the FrameSinkId then we can just | 128 // If there are no temporary references for the FrameSinkId then we can just |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 refs.erase(refs.begin(), ++temp_ref_iter); | 171 refs.erase(refs.begin(), ++temp_ref_iter); |
| 166 } | 172 } |
| 167 | 173 |
| 168 void DisplayCompositor::RemoveSurfaceReference( | 174 void DisplayCompositor::RemoveSurfaceReference( |
| 169 const cc::SurfaceReference& ref) { | 175 const cc::SurfaceReference& ref) { |
| 170 reference_manager_->RemoveSurfaceReference(ref.parent_id(), ref.child_id()); | 176 reference_manager_->RemoveSurfaceReference(ref.parent_id(), ref.child_id()); |
| 171 } | 177 } |
| 172 | 178 |
| 173 std::unique_ptr<cc::Display> DisplayCompositor::CreateDisplay( | 179 std::unique_ptr<cc::Display> DisplayCompositor::CreateDisplay( |
| 174 const cc::FrameSinkId& frame_sink_id, | 180 const cc::FrameSinkId& frame_sink_id, |
| 175 gpu::SurfaceHandle surface_handle) { | 181 gpu::SurfaceHandle surface_handle, |
| 182 cc::SyntheticBeginFrameSource* begin_frame_source) { |
| 176 scoped_refptr<cc::InProcessContextProvider> context_provider = | 183 scoped_refptr<cc::InProcessContextProvider> context_provider = |
| 177 new cc::InProcessContextProvider( | 184 new cc::InProcessContextProvider( |
| 178 gpu_service_, surface_handle, gpu_memory_buffer_manager_.get(), | 185 gpu_service_, surface_handle, gpu_memory_buffer_manager_.get(), |
| 179 image_factory_, gpu::SharedMemoryLimits(), | 186 image_factory_, gpu::SharedMemoryLimits(), |
| 180 nullptr /* shared_context */); | 187 nullptr /* shared_context */); |
| 181 | 188 |
| 182 // TODO(rjkroege): If there is something better to do than CHECK, add it. | 189 // TODO(rjkroege): If there is something better to do than CHECK, add it. |
| 183 CHECK(context_provider->BindToCurrentThread()); | 190 CHECK(context_provider->BindToCurrentThread()); |
| 184 | 191 |
| 185 std::unique_ptr<cc::SyntheticBeginFrameSource> synthetic_begin_frame_source( | |
| 186 new cc::DelayBasedBeginFrameSource( | |
| 187 base::MakeUnique<cc::DelayBasedTimeSource>(task_runner_.get()))); | |
| 188 | |
| 189 std::unique_ptr<cc::OutputSurface> display_output_surface; | 192 std::unique_ptr<cc::OutputSurface> display_output_surface; |
| 190 if (context_provider->ContextCapabilities().surfaceless) { | 193 if (context_provider->ContextCapabilities().surfaceless) { |
| 191 #if defined(USE_OZONE) | 194 #if defined(USE_OZONE) |
| 192 display_output_surface = base::MakeUnique<DisplayOutputSurfaceOzone>( | 195 display_output_surface = base::MakeUnique<DisplayOutputSurfaceOzone>( |
| 193 std::move(context_provider), surface_handle, | 196 std::move(context_provider), surface_handle, |
| 194 synthetic_begin_frame_source.get(), gpu_memory_buffer_manager_.get(), | 197 begin_frame_source, gpu_memory_buffer_manager_.get(), |
| 195 GL_TEXTURE_2D, GL_RGB); | 198 GL_TEXTURE_2D, GL_RGB); |
| 196 #else | 199 #else |
| 197 NOTREACHED(); | 200 NOTREACHED(); |
| 198 #endif | 201 #endif |
| 199 } else { | 202 } else { |
| 200 display_output_surface = base::MakeUnique<DisplayOutputSurface>( | 203 display_output_surface = base::MakeUnique<DisplayOutputSurface>( |
| 201 std::move(context_provider), synthetic_begin_frame_source.get()); | 204 std::move(context_provider), begin_frame_source); |
| 202 } | 205 } |
| 203 | 206 |
| 204 int max_frames_pending = | 207 int max_frames_pending = |
| 205 display_output_surface->capabilities().max_frames_pending; | 208 display_output_surface->capabilities().max_frames_pending; |
| 206 DCHECK_GT(max_frames_pending, 0); | 209 DCHECK_GT(max_frames_pending, 0); |
| 207 | 210 |
| 208 std::unique_ptr<cc::DisplayScheduler> scheduler( | 211 std::unique_ptr<cc::DisplayScheduler> scheduler( |
| 209 new cc::DisplayScheduler(synthetic_begin_frame_source.get(), | 212 new cc::DisplayScheduler(task_runner_.get(), max_frames_pending)); |
| 210 task_runner_.get(), max_frames_pending)); | |
| 211 | 213 |
| 212 return base::MakeUnique<cc::Display>( | 214 return base::MakeUnique<cc::Display>( |
| 213 nullptr /* bitmap_manager */, gpu_memory_buffer_manager_.get(), | 215 nullptr /* bitmap_manager */, gpu_memory_buffer_manager_.get(), |
| 214 cc::RendererSettings(), frame_sink_id, | 216 cc::RendererSettings(), frame_sink_id, begin_frame_source, |
| 215 std::move(synthetic_begin_frame_source), | |
| 216 std::move(display_output_surface), std::move(scheduler), | 217 std::move(display_output_surface), std::move(scheduler), |
| 217 base::MakeUnique<cc::TextureMailboxDeleter>(task_runner_.get())); | 218 base::MakeUnique<cc::TextureMailboxDeleter>(task_runner_.get())); |
| 218 } | 219 } |
| 219 | 220 |
| 220 const cc::SurfaceId& DisplayCompositor::GetRootSurfaceId() const { | 221 const cc::SurfaceId& DisplayCompositor::GetRootSurfaceId() const { |
| 221 return reference_manager_->GetRootSurfaceId(); | 222 return reference_manager_->GetRootSurfaceId(); |
| 222 } | 223 } |
| 223 | 224 |
| 224 void DisplayCompositor::OnSurfaceCreated(const cc::SurfaceId& surface_id, | 225 void DisplayCompositor::OnSurfaceCreated(const cc::SurfaceId& surface_id, |
| 225 const gfx::Size& frame_size, | 226 const gfx::Size& frame_size, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 236 surface_id.local_frame_id()); | 237 surface_id.local_frame_id()); |
| 237 | 238 |
| 238 if (client_) | 239 if (client_) |
| 239 client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor); | 240 client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor); |
| 240 } | 241 } |
| 241 | 242 |
| 242 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id, | 243 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id, |
| 243 bool* changed) {} | 244 bool* changed) {} |
| 244 | 245 |
| 245 } // namespace ui | 246 } // namespace ui |
| OLD | NEW |