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