| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/compositor_frame_sink.h" |
| 6 | 6 |
| 7 #include "cc/output/copy_output_request.h" | 7 #include "cc/output/copy_output_request.h" |
| 8 #include "cc/output/output_surface.h" | 8 #include "cc/output/output_surface.h" |
| 9 #include "cc/output/renderer_settings.h" | 9 #include "cc/output/renderer_settings.h" |
| 10 #include "cc/output/texture_mailbox_deleter.h" | 10 #include "cc/output/texture_mailbox_deleter.h" |
| 11 #include "cc/scheduler/begin_frame_source.h" | 11 #include "cc/scheduler/begin_frame_source.h" |
| 12 #include "cc/scheduler/delay_based_time_source.h" | 12 #include "cc/scheduler/delay_based_time_source.h" |
| 13 #include "cc/surfaces/display.h" | 13 #include "cc/surfaces/display.h" |
| 14 #include "cc/surfaces/display_scheduler.h" | 14 #include "cc/surfaces/display_scheduler.h" |
| 15 #include "gpu/ipc/client/gpu_channel_host.h" | 15 #include "gpu/ipc/client/gpu_channel_host.h" |
| 16 #include "services/ui/surfaces/direct_output_surface.h" | 16 #include "services/ui/surfaces/direct_output_surface.h" |
| 17 #include "services/ui/surfaces/surfaces_context_provider.h" | 17 #include "services/ui/surfaces/surfaces_context_provider.h" |
| 18 | 18 |
| 19 #if defined(USE_OZONE) | 19 #if defined(USE_OZONE) |
| 20 #include "gpu/command_buffer/client/gles2_interface.h" | 20 #include "gpu/command_buffer/client/gles2_interface.h" |
| 21 #include "services/ui/surfaces/direct_output_surface_ozone.h" | 21 #include "services/ui/surfaces/direct_output_surface_ozone.h" |
| 22 #endif | 22 #endif |
| 23 | 23 |
| 24 namespace ui { | 24 namespace ui { |
| 25 namespace surfaces { |
| 25 | 26 |
| 26 DisplayCompositor::DisplayCompositor( | 27 CompositorFrameSink::CompositorFrameSink( |
| 27 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 28 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 28 gfx::AcceleratedWidget widget, | 29 gfx::AcceleratedWidget widget, |
| 29 scoped_refptr<gpu::GpuChannelHost> gpu_channel, | 30 scoped_refptr<gpu::GpuChannelHost> gpu_channel, |
| 30 const scoped_refptr<SurfacesState>& surfaces_state) | 31 const scoped_refptr<DisplayCompositor>& display_compositor) |
| 31 : task_runner_(task_runner), | 32 : task_runner_(task_runner), |
| 32 surfaces_state_(surfaces_state), | 33 display_compositor_(display_compositor), |
| 33 factory_(surfaces_state->manager(), this), | 34 factory_(display_compositor->manager(), this), |
| 34 allocator_(surfaces_state->next_client_id()) { | 35 // TODO(fsamuel): Use the WindowId as the FrameSinkId |
| 35 surfaces_state_->manager()->RegisterSurfaceClientId(allocator_.client_id()); | 36 allocator_(cc::FrameSinkId(display_compositor->next_client_id(), 0)) { |
| 36 surfaces_state_->manager()->RegisterSurfaceFactoryClient( | 37 display_compositor_->manager()->RegisterFrameSinkId( |
| 37 allocator_.client_id(), this); | 38 allocator_.frame_sink_id()); |
| 39 display_compositor_->manager()->RegisterSurfaceFactoryClient( |
| 40 allocator_.frame_sink_id(), this); |
| 38 | 41 |
| 39 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager = | 42 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager = |
| 40 gpu_channel->gpu_memory_buffer_manager(); | 43 gpu_channel->gpu_memory_buffer_manager(); |
| 41 scoped_refptr<SurfacesContextProvider> surfaces_context_provider( | 44 scoped_refptr<SurfacesContextProvider> surfaces_context_provider( |
| 42 new SurfacesContextProvider(widget, std::move(gpu_channel))); | 45 new SurfacesContextProvider(widget, std::move(gpu_channel))); |
| 43 // TODO(rjkroege): If there is something better to do than CHECK, add it. | 46 // TODO(rjkroege): If there is something better to do than CHECK, add it. |
| 44 CHECK(surfaces_context_provider->BindToCurrentThread()); | 47 CHECK(surfaces_context_provider->BindToCurrentThread()); |
| 45 | 48 |
| 46 std::unique_ptr<cc::SyntheticBeginFrameSource> synthetic_begin_frame_source( | 49 std::unique_ptr<cc::SyntheticBeginFrameSource> synthetic_begin_frame_source( |
| 47 new cc::DelayBasedBeginFrameSource( | 50 new cc::DelayBasedBeginFrameSource( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 67 | 70 |
| 68 std::unique_ptr<cc::DisplayScheduler> scheduler( | 71 std::unique_ptr<cc::DisplayScheduler> scheduler( |
| 69 new cc::DisplayScheduler(synthetic_begin_frame_source.get(), | 72 new cc::DisplayScheduler(synthetic_begin_frame_source.get(), |
| 70 task_runner_.get(), max_frames_pending)); | 73 task_runner_.get(), max_frames_pending)); |
| 71 | 74 |
| 72 display_.reset(new cc::Display( | 75 display_.reset(new cc::Display( |
| 73 nullptr /* bitmap_manager */, gpu_memory_buffer_manager, | 76 nullptr /* bitmap_manager */, gpu_memory_buffer_manager, |
| 74 cc::RendererSettings(), std::move(synthetic_begin_frame_source), | 77 cc::RendererSettings(), std::move(synthetic_begin_frame_source), |
| 75 std::move(display_output_surface), std::move(scheduler), | 78 std::move(display_output_surface), std::move(scheduler), |
| 76 base::MakeUnique<cc::TextureMailboxDeleter>(task_runner_.get()))); | 79 base::MakeUnique<cc::TextureMailboxDeleter>(task_runner_.get()))); |
| 77 display_->Initialize(this, surfaces_state_->manager(), | 80 display_->Initialize(this, display_compositor_->manager(), |
| 78 allocator_.client_id()); | 81 allocator_.frame_sink_id()); |
| 79 display_->SetVisible(true); | 82 display_->SetVisible(true); |
| 80 } | 83 } |
| 81 | 84 |
| 82 DisplayCompositor::~DisplayCompositor() { | 85 CompositorFrameSink::~CompositorFrameSink() { |
| 83 surfaces_state_->manager()->UnregisterSurfaceFactoryClient( | 86 display_compositor_->manager()->UnregisterSurfaceFactoryClient( |
| 84 allocator_.client_id()); | 87 allocator_.frame_sink_id()); |
| 85 surfaces_state_->manager()->InvalidateSurfaceClientId(allocator_.client_id()); | 88 display_compositor_->manager()->InvalidateFrameSinkId( |
| 89 allocator_.frame_sink_id()); |
| 86 } | 90 } |
| 87 | 91 |
| 88 void DisplayCompositor::SubmitCompositorFrame( | 92 void CompositorFrameSink::SubmitCompositorFrame( |
| 89 cc::CompositorFrame frame, | 93 cc::CompositorFrame frame, |
| 90 const base::Callback<void()>& callback) { | 94 const base::Callback<void()>& callback) { |
| 91 gfx::Size frame_size = | 95 gfx::Size frame_size = |
| 92 frame.delegated_frame_data->render_pass_list.back()->output_rect.size(); | 96 frame.delegated_frame_data->render_pass_list.back()->output_rect.size(); |
| 93 if (frame_size.IsEmpty() || frame_size != display_size_) { | 97 if (frame_size.IsEmpty() || frame_size != display_size_) { |
| 94 if (!surface_id_.is_null()) | 98 if (!surface_id_.is_null()) |
| 95 factory_.Destroy(surface_id_); | 99 factory_.Destroy(surface_id_); |
| 96 surface_id_ = allocator_.GenerateId(); | 100 surface_id_ = allocator_.GenerateId(); |
| 97 factory_.Create(surface_id_); | 101 factory_.Create(surface_id_); |
| 98 display_size_ = frame_size; | 102 display_size_ = frame_size; |
| 99 display_->Resize(display_size_); | 103 display_->Resize(display_size_); |
| 100 } | 104 } |
| 101 display_->SetSurfaceId(surface_id_, frame.metadata.device_scale_factor); | 105 display_->SetSurfaceId(surface_id_, frame.metadata.device_scale_factor); |
| 102 factory_.SubmitCompositorFrame(surface_id_, std::move(frame), callback); | 106 factory_.SubmitCompositorFrame(surface_id_, std::move(frame), callback); |
| 103 } | 107 } |
| 104 | 108 |
| 105 void DisplayCompositor::RequestCopyOfOutput( | 109 void CompositorFrameSink::RequestCopyOfOutput( |
| 106 std::unique_ptr<cc::CopyOutputRequest> output_request) { | 110 std::unique_ptr<cc::CopyOutputRequest> output_request) { |
| 107 factory_.RequestCopyOfSurface(surface_id_, std::move(output_request)); | 111 factory_.RequestCopyOfSurface(surface_id_, std::move(output_request)); |
| 108 } | 112 } |
| 109 | 113 |
| 110 void DisplayCompositor::ReturnResources( | 114 void CompositorFrameSink::ReturnResources( |
| 111 const cc::ReturnedResourceArray& resources) { | 115 const cc::ReturnedResourceArray& resources) { |
| 112 // TODO(fsamuel): Implement this. | 116 // TODO(fsamuel): Implement this. |
| 113 } | 117 } |
| 114 | 118 |
| 115 void DisplayCompositor::SetBeginFrameSource( | 119 void CompositorFrameSink::SetBeginFrameSource( |
| 116 cc::BeginFrameSource* begin_frame_source) { | 120 cc::BeginFrameSource* begin_frame_source) { |
| 117 // TODO(fsamuel): Implement this. | 121 // TODO(fsamuel): Implement this. |
| 118 } | 122 } |
| 119 | 123 |
| 120 void DisplayCompositor::DisplayOutputSurfaceLost() { | 124 void CompositorFrameSink::DisplayOutputSurfaceLost() { |
| 121 // TODO(fsamuel): This looks like it would crash if a frame was in flight and | 125 // TODO(fsamuel): This looks like it would crash if a frame was in flight and |
| 122 // will be submitted. | 126 // will be submitted. |
| 123 display_.reset(); | 127 display_.reset(); |
| 124 } | 128 } |
| 125 | 129 |
| 126 void DisplayCompositor::DisplayWillDrawAndSwap( | 130 void CompositorFrameSink::DisplayWillDrawAndSwap( |
| 127 bool will_draw_and_swap, | 131 bool will_draw_and_swap, |
| 128 const cc::RenderPassList& render_passes) { | 132 const cc::RenderPassList& render_passes) { |
| 129 // This notification is not relevant to our client outside of tests. | 133 // This notification is not relevant to our client outside of tests. |
| 130 } | 134 } |
| 131 | 135 |
| 132 void DisplayCompositor::DisplayDidDrawAndSwap() { | 136 void CompositorFrameSink::DisplayDidDrawAndSwap() { |
| 133 // This notification is not relevant to our client outside of tests. We | 137 // This notification is not relevant to our client outside of tests. We |
| 134 // unblock the client from the DrawCallback when the surface is going to | 138 // unblock the client from the DrawCallback when the surface is going to |
| 135 // be drawn. | 139 // be drawn. |
| 136 } | 140 } |
| 137 | 141 |
| 142 } // namespace surfaces |
| 138 } // namespace ui | 143 } // namespace ui |
| OLD | NEW |