| 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/gpu_compositor_frame_sink.h" | 5 #include "services/ui/surfaces/gpu_compositor_frame_sink.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| 11 #include "cc/output/compositor_frame.h" | 11 #include "cc/output/compositor_frame.h" |
| 12 #include "cc/output/output_surface.h" | 12 #include "cc/output/output_surface.h" |
| 13 #include "cc/output/texture_mailbox_deleter.h" | |
| 14 #include "cc/quads/shared_quad_state.h" | 13 #include "cc/quads/shared_quad_state.h" |
| 15 #include "cc/quads/surface_draw_quad.h" | 14 #include "cc/quads/surface_draw_quad.h" |
| 16 #include "cc/scheduler/begin_frame_source.h" | 15 #include "cc/scheduler/begin_frame_source.h" |
| 17 #include "cc/surfaces/display_scheduler.h" | 16 #include "cc/surfaces/display.h" |
| 18 #include "services/ui/surfaces/display_compositor.h" | 17 #include "services/ui/surfaces/display_compositor.h" |
| 19 #include "services/ui/surfaces/display_output_surface.h" | |
| 20 | |
| 21 #if defined(USE_OZONE) | |
| 22 #include "gpu/command_buffer/client/gles2_interface.h" | |
| 23 #include "services/ui/surfaces/display_output_surface_ozone.h" | |
| 24 #endif | |
| 25 | 18 |
| 26 namespace ui { | 19 namespace ui { |
| 27 | 20 |
| 28 GpuCompositorFrameSink::GpuCompositorFrameSink( | 21 GpuCompositorFrameSink::GpuCompositorFrameSink( |
| 29 DisplayCompositor* display_compositor, | 22 DisplayCompositor* display_compositor, |
| 30 const cc::FrameSinkId& frame_sink_id, | 23 const cc::FrameSinkId& frame_sink_id, |
| 31 gpu::SurfaceHandle surface_handle, | 24 std::unique_ptr<cc::Display> display, |
| 32 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | |
| 33 scoped_refptr<cc::InProcessContextProvider> context_provider, | |
| 34 cc::mojom::MojoCompositorFrameSinkRequest request, | 25 cc::mojom::MojoCompositorFrameSinkRequest request, |
| 35 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, | 26 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, |
| 36 cc::mojom::MojoCompositorFrameSinkClientPtr client) | 27 cc::mojom::MojoCompositorFrameSinkClientPtr client) |
| 37 : frame_sink_id_(frame_sink_id), | 28 : frame_sink_id_(frame_sink_id), |
| 38 task_runner_(base::ThreadTaskRunnerHandle::Get()), | |
| 39 display_compositor_(display_compositor), | 29 display_compositor_(display_compositor), |
| 30 display_(std::move(display)), |
| 40 surface_factory_(frame_sink_id_, display_compositor_->manager(), this), | 31 surface_factory_(frame_sink_id_, display_compositor_->manager(), this), |
| 41 client_(std::move(client)), | 32 client_(std::move(client)), |
| 42 binding_(this, std::move(request)), | 33 binding_(this, std::move(request)), |
| 43 private_binding_(this, std::move(private_request)), | 34 private_binding_(this, std::move(private_request)), |
| 44 weak_factory_(this) { | 35 weak_factory_(this) { |
| 45 display_compositor_->manager()->RegisterFrameSinkId(frame_sink_id_); | 36 display_compositor_->manager()->RegisterFrameSinkId(frame_sink_id_); |
| 46 display_compositor_->manager()->RegisterSurfaceFactoryClient(frame_sink_id_, | 37 display_compositor_->manager()->RegisterSurfaceFactoryClient(frame_sink_id_, |
| 47 this); | 38 this); |
| 48 | 39 |
| 49 if (surface_handle != gpu::kNullSurfaceHandle) { | 40 if (display_) { |
| 50 InitDisplay(surface_handle, gpu_memory_buffer_manager, | 41 display_->Initialize(this, display_compositor_->manager()); |
| 51 std::move(context_provider)); | 42 display_->SetVisible(true); |
| 52 } | 43 } |
| 53 | 44 |
| 54 binding_.set_connection_error_handler(base::Bind( | 45 binding_.set_connection_error_handler(base::Bind( |
| 55 &GpuCompositorFrameSink::OnClientConnectionLost, base::Unretained(this))); | 46 &GpuCompositorFrameSink::OnClientConnectionLost, base::Unretained(this))); |
| 56 | 47 |
| 57 private_binding_.set_connection_error_handler( | 48 private_binding_.set_connection_error_handler( |
| 58 base::Bind(&GpuCompositorFrameSink::OnPrivateConnectionLost, | 49 base::Bind(&GpuCompositorFrameSink::OnPrivateConnectionLost, |
| 59 base::Unretained(this))); | 50 base::Unretained(this))); |
| 60 } | 51 } |
| 61 | 52 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 child_frame_sink_id); | 107 child_frame_sink_id); |
| 117 } | 108 } |
| 118 | 109 |
| 119 void GpuCompositorFrameSink::RemoveChildFrameSink( | 110 void GpuCompositorFrameSink::RemoveChildFrameSink( |
| 120 const cc::FrameSinkId& child_frame_sink_id) { | 111 const cc::FrameSinkId& child_frame_sink_id) { |
| 121 cc::SurfaceManager* surface_manager = display_compositor_->manager(); | 112 cc::SurfaceManager* surface_manager = display_compositor_->manager(); |
| 122 surface_manager->UnregisterFrameSinkHierarchy(frame_sink_id_, | 113 surface_manager->UnregisterFrameSinkHierarchy(frame_sink_id_, |
| 123 child_frame_sink_id); | 114 child_frame_sink_id); |
| 124 } | 115 } |
| 125 | 116 |
| 126 void GpuCompositorFrameSink::InitDisplay( | |
| 127 gpu::SurfaceHandle surface_handle, | |
| 128 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | |
| 129 scoped_refptr<cc::InProcessContextProvider> context_provider) { | |
| 130 // TODO(rjkroege): If there is something better to do than CHECK, add it. | |
| 131 CHECK(context_provider->BindToCurrentThread()); | |
| 132 | |
| 133 std::unique_ptr<cc::SyntheticBeginFrameSource> synthetic_begin_frame_source( | |
| 134 new cc::DelayBasedBeginFrameSource( | |
| 135 base::MakeUnique<cc::DelayBasedTimeSource>(task_runner_.get()))); | |
| 136 | |
| 137 std::unique_ptr<cc::OutputSurface> display_output_surface; | |
| 138 if (context_provider->ContextCapabilities().surfaceless) { | |
| 139 #if defined(USE_OZONE) | |
| 140 display_output_surface = base::MakeUnique<DisplayOutputSurfaceOzone>( | |
| 141 std::move(context_provider), surface_handle, | |
| 142 synthetic_begin_frame_source.get(), gpu_memory_buffer_manager, | |
| 143 GL_TEXTURE_2D, GL_RGB); | |
| 144 #else | |
| 145 NOTREACHED(); | |
| 146 #endif | |
| 147 } else { | |
| 148 display_output_surface = base::MakeUnique<DisplayOutputSurface>( | |
| 149 std::move(context_provider), synthetic_begin_frame_source.get()); | |
| 150 } | |
| 151 | |
| 152 int max_frames_pending = | |
| 153 display_output_surface->capabilities().max_frames_pending; | |
| 154 DCHECK_GT(max_frames_pending, 0); | |
| 155 | |
| 156 std::unique_ptr<cc::DisplayScheduler> scheduler( | |
| 157 new cc::DisplayScheduler(synthetic_begin_frame_source.get(), | |
| 158 task_runner_.get(), max_frames_pending)); | |
| 159 | |
| 160 display_.reset(new cc::Display( | |
| 161 nullptr /* bitmap_manager */, gpu_memory_buffer_manager, | |
| 162 cc::RendererSettings(), frame_sink_id_, | |
| 163 std::move(synthetic_begin_frame_source), | |
| 164 std::move(display_output_surface), std::move(scheduler), | |
| 165 base::MakeUnique<cc::TextureMailboxDeleter>(task_runner_.get()))); | |
| 166 display_->Initialize(this, display_compositor_->manager()); | |
| 167 display_->SetVisible(true); | |
| 168 } | |
| 169 | |
| 170 void GpuCompositorFrameSink::DisplayOutputSurfaceLost() {} | 117 void GpuCompositorFrameSink::DisplayOutputSurfaceLost() {} |
| 171 | 118 |
| 172 void GpuCompositorFrameSink::DisplayWillDrawAndSwap( | 119 void GpuCompositorFrameSink::DisplayWillDrawAndSwap( |
| 173 bool will_draw_and_swap, | 120 bool will_draw_and_swap, |
| 174 const cc::RenderPassList& render_passes) {} | 121 const cc::RenderPassList& render_passes) {} |
| 175 | 122 |
| 176 void GpuCompositorFrameSink::DisplayDidDrawAndSwap() {} | 123 void GpuCompositorFrameSink::DisplayDidDrawAndSwap() {} |
| 177 | 124 |
| 178 void GpuCompositorFrameSink::ReturnResources( | 125 void GpuCompositorFrameSink::ReturnResources( |
| 179 const cc::ReturnedResourceArray& resources) { | 126 const cc::ReturnedResourceArray& resources) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 } | 183 } |
| 237 | 184 |
| 238 void GpuCompositorFrameSink::OnPrivateConnectionLost() { | 185 void GpuCompositorFrameSink::OnPrivateConnectionLost() { |
| 239 private_connection_lost_ = true; | 186 private_connection_lost_ = true; |
| 240 // Request destruction of |this| only if both connections are lost. | 187 // Request destruction of |this| only if both connections are lost. |
| 241 display_compositor_->OnCompositorFrameSinkPrivateConnectionLost( | 188 display_compositor_->OnCompositorFrameSinkPrivateConnectionLost( |
| 242 frame_sink_id_, client_connection_lost_); | 189 frame_sink_id_, client_connection_lost_); |
| 243 } | 190 } |
| 244 | 191 |
| 245 } // namespace ui | 192 } // namespace ui |
| OLD | NEW |