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