| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "services/ui/surfaces/display_compositor_frame_sink.h" |
| 6 |
| 7 #include "cc/output/copy_output_request.h" |
| 8 #include "cc/output/output_surface.h" |
| 9 #include "cc/output/renderer_settings.h" |
| 10 #include "cc/output/texture_mailbox_deleter.h" |
| 11 #include "cc/scheduler/begin_frame_source.h" |
| 12 #include "cc/scheduler/delay_based_time_source.h" |
| 13 #include "cc/surfaces/display.h" |
| 14 #include "cc/surfaces/display_scheduler.h" |
| 15 #include "cc/surfaces/frame_sink_id.h" |
| 16 #include "gpu/ipc/client/gpu_channel_host.h" |
| 17 #include "services/ui/surfaces/direct_output_surface.h" |
| 18 #include "services/ui/surfaces/surfaces_context_provider.h" |
| 19 |
| 20 #if defined(USE_OZONE) |
| 21 #include "gpu/command_buffer/client/gles2_interface.h" |
| 22 #include "services/ui/surfaces/direct_output_surface_ozone.h" |
| 23 #endif |
| 24 |
| 25 namespace ui { |
| 26 |
| 27 DisplayCompositorFrameSink::DisplayCompositorFrameSink( |
| 28 const cc::FrameSinkId& frame_sink_id, |
| 29 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 30 gfx::AcceleratedWidget widget, |
| 31 scoped_refptr<gpu::GpuChannelHost> gpu_channel, |
| 32 const scoped_refptr<DisplayCompositor>& display_compositor) |
| 33 : frame_sink_id_(frame_sink_id), |
| 34 task_runner_(task_runner), |
| 35 display_compositor_(display_compositor), |
| 36 factory_(frame_sink_id_, display_compositor->manager(), this) { |
| 37 display_compositor_->manager()->RegisterFrameSinkId(frame_sink_id_); |
| 38 display_compositor_->manager()->RegisterSurfaceFactoryClient(frame_sink_id_, |
| 39 this); |
| 40 |
| 41 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager = |
| 42 gpu_channel->gpu_memory_buffer_manager(); |
| 43 scoped_refptr<SurfacesContextProvider> surfaces_context_provider( |
| 44 new SurfacesContextProvider(widget, std::move(gpu_channel))); |
| 45 // TODO(rjkroege): If there is something better to do than CHECK, add it. |
| 46 CHECK(surfaces_context_provider->BindToCurrentThread()); |
| 47 |
| 48 std::unique_ptr<cc::SyntheticBeginFrameSource> synthetic_begin_frame_source( |
| 49 new cc::DelayBasedBeginFrameSource( |
| 50 base::MakeUnique<cc::DelayBasedTimeSource>(task_runner_.get()))); |
| 51 |
| 52 std::unique_ptr<cc::OutputSurface> display_output_surface; |
| 53 if (surfaces_context_provider->ContextCapabilities().surfaceless) { |
| 54 #if defined(USE_OZONE) |
| 55 display_output_surface = base::MakeUnique<DirectOutputSurfaceOzone>( |
| 56 surfaces_context_provider, widget, synthetic_begin_frame_source.get(), |
| 57 gpu_memory_buffer_manager, GL_TEXTURE_2D, GL_RGB); |
| 58 #else |
| 59 NOTREACHED(); |
| 60 #endif |
| 61 } else { |
| 62 display_output_surface = base::MakeUnique<DirectOutputSurface>( |
| 63 surfaces_context_provider, synthetic_begin_frame_source.get()); |
| 64 } |
| 65 |
| 66 int max_frames_pending = |
| 67 display_output_surface->capabilities().max_frames_pending; |
| 68 DCHECK_GT(max_frames_pending, 0); |
| 69 |
| 70 std::unique_ptr<cc::DisplayScheduler> scheduler( |
| 71 new cc::DisplayScheduler(synthetic_begin_frame_source.get(), |
| 72 task_runner_.get(), max_frames_pending)); |
| 73 |
| 74 display_.reset(new cc::Display( |
| 75 nullptr /* bitmap_manager */, gpu_memory_buffer_manager, |
| 76 cc::RendererSettings(), std::move(synthetic_begin_frame_source), |
| 77 std::move(display_output_surface), std::move(scheduler), |
| 78 base::MakeUnique<cc::TextureMailboxDeleter>(task_runner_.get()))); |
| 79 display_->Initialize(this, display_compositor_->manager(), frame_sink_id_); |
| 80 display_->SetVisible(true); |
| 81 } |
| 82 |
| 83 DisplayCompositorFrameSink::~DisplayCompositorFrameSink() { |
| 84 display_compositor_->manager()->UnregisterSurfaceFactoryClient( |
| 85 frame_sink_id_); |
| 86 display_compositor_->manager()->InvalidateFrameSinkId(frame_sink_id_); |
| 87 } |
| 88 |
| 89 void DisplayCompositorFrameSink::SubmitCompositorFrame( |
| 90 cc::CompositorFrame frame, |
| 91 const base::Callback<void()>& callback) { |
| 92 gfx::Size frame_size = |
| 93 frame.delegated_frame_data->render_pass_list.back()->output_rect.size(); |
| 94 if (frame_size.IsEmpty() || frame_size != display_size_) { |
| 95 if (!local_frame_id_.is_null()) |
| 96 factory_.Destroy(local_frame_id_); |
| 97 local_frame_id_ = allocator_.GenerateId(); |
| 98 factory_.Create(local_frame_id_); |
| 99 display_size_ = frame_size; |
| 100 display_->Resize(display_size_); |
| 101 } |
| 102 display_->SetSurfaceId(cc::SurfaceId(frame_sink_id_, local_frame_id_), |
| 103 frame.metadata.device_scale_factor); |
| 104 factory_.SubmitCompositorFrame(local_frame_id_, std::move(frame), callback); |
| 105 } |
| 106 |
| 107 void DisplayCompositorFrameSink::ReturnResources( |
| 108 const cc::ReturnedResourceArray& resources) { |
| 109 // TODO(fsamuel): Implement this. |
| 110 } |
| 111 |
| 112 void DisplayCompositorFrameSink::SetBeginFrameSource( |
| 113 cc::BeginFrameSource* begin_frame_source) { |
| 114 // TODO(fsamuel): Implement this. |
| 115 } |
| 116 |
| 117 void DisplayCompositorFrameSink::DisplayOutputSurfaceLost() { |
| 118 // TODO(fsamuel): This looks like it would crash if a frame was in flight and |
| 119 // will be submitted. |
| 120 display_.reset(); |
| 121 } |
| 122 |
| 123 void DisplayCompositorFrameSink::DisplayWillDrawAndSwap( |
| 124 bool will_draw_and_swap, |
| 125 const cc::RenderPassList& render_passes) { |
| 126 // This notification is not relevant to our client outside of tests. |
| 127 } |
| 128 |
| 129 void DisplayCompositorFrameSink::DisplayDidDrawAndSwap() { |
| 130 // This notification is not relevant to our client outside of tests. We |
| 131 // unblock the client from the DrawCallback when the surface is going to |
| 132 // be drawn. |
| 133 } |
| 134 |
| 135 } // namespace ui |
| OLD | NEW |