Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Side by Side Diff: blimp/client/app/compositor/browser_compositor.cc

Issue 2266863003: blimp: Move BlimpCompositor to use delegated rendering. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "blimp/client/app/compositor/browser_compositor.h"
6
7 #include "base/lazy_instance.h"
8 #include "base/threading/thread_task_runner_handle.h"
9 #include "blimp/client/feature/compositor/blimp_context_provider.h"
10 #include "blimp/client/feature/compositor/blimp_gpu_memory_buffer_manager.h"
11 #include "cc/animation/animation_host.h"
12 #include "cc/layers/layer.h"
13 #include "cc/output/compositor_frame.h"
14 #include "cc/output/texture_mailbox_deleter.h"
15 #include "cc/raster/single_thread_task_graph_runner.h"
16 #include "cc/surfaces/display.h"
17 #include "cc/surfaces/surface_display_output_surface.h"
18 #include "cc/surfaces/surface_id_allocator.h"
19 #include "cc/surfaces/surface_manager.h"
20 #include "cc/trees/layer_tree_host.h"
21 #include "gpu/command_buffer/client/context_support.h"
22
23 namespace blimp {
24 namespace client {
25
26 namespace {
27
28 class SimpleTaskGraphRunner : public cc::SingleThreadTaskGraphRunner {
29 public:
30 SimpleTaskGraphRunner() {
31 Start("BlimpBrowserCompositorWorker",
32 base::SimpleThread::Options(base::ThreadPriority::BACKGROUND));
33 }
34
35 ~SimpleTaskGraphRunner() override { Shutdown(); }
36 };
37
38 class DisplayOutputSurface : public cc::OutputSurface {
39 public:
40 explicit DisplayOutputSurface(
41 scoped_refptr<cc::ContextProvider> context_provider)
42 : cc::OutputSurface(std::move(context_provider), nullptr, nullptr) {}
43
44 ~DisplayOutputSurface() override {}
45
46 // cc::OutputSurface implementation
47 void SwapBuffers(cc::CompositorFrame frame) override {
48 // See cc::OutputSurface::SwapBuffers() comment for details.
49 context_provider_->ContextSupport()->Swap();
50 cc::OutputSurface::PostSwapBuffersComplete();
51 }
52
53 uint32_t GetFramebufferCopyTextureFormat() override {
54 auto* gl = static_cast<BlimpContextProvider*>(context_provider());
55 return gl->GetCopyTextureInternalFormat();
56 }
57
58 private:
59 DISALLOW_COPY_AND_ASSIGN(DisplayOutputSurface);
60 };
61
62 base::LazyInstance<SimpleTaskGraphRunner> g_task_graph_runner =
63 LAZY_INSTANCE_INITIALIZER;
64
65 base::LazyInstance<cc::SurfaceManager> g_surface_manager =
66 LAZY_INSTANCE_INITIALIZER;
67
68 base::LazyInstance<BlimpGpuMemoryBufferManager> g_gpu_memory_buffer_manager =
69 LAZY_INSTANCE_INITIALIZER;
70
71 uint32_t g_surface_id = 0;
72
73 } // namespace
74
75 // static
76 cc::SurfaceManager* BrowserCompositor::GetSurfaceManager() {
77 return g_surface_manager.Pointer();
78 }
79
80 // static
81 BlimpGpuMemoryBufferManager* BrowserCompositor::GetGpuMemoryBufferManager() {
82 return g_gpu_memory_buffer_manager.Pointer();
83 }
84
85 // static
86 uint32_t BrowserCompositor::AllocateSurfaceClientId() {
87 return ++g_surface_id;
88 }
89
90 BrowserCompositor::BrowserCompositor()
91 : surface_id_allocator_(base::MakeUnique<cc::SurfaceIdAllocator>(
92 BrowserCompositor::AllocateSurfaceClientId())),
93 widget_(gfx::kNullAcceleratedWidget),
94 output_surface_request_pending_(false),
95 root_layer_(cc::Layer::Create()) {
96 BrowserCompositor::GetSurfaceManager()->RegisterSurfaceClientId(
97 surface_id_allocator_->client_id());
98
99 cc::LayerTreeHost::InitParams params;
100 params.client = this;
101 params.gpu_memory_buffer_manager =
102 BrowserCompositor::GetGpuMemoryBufferManager();
103 params.task_graph_runner = g_task_graph_runner.Pointer();
104 cc::LayerTreeSettings settings;
105 params.settings = &settings;
106 params.main_task_runner = base::ThreadTaskRunnerHandle::Get();
107 params.animation_host = cc::AnimationHost::CreateMainInstance();
108 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, &params);
109
110 root_layer_->SetBackgroundColor(SK_ColorWHITE);
111 host_->GetLayerTree()->SetRootLayer(root_layer_);
112 host_->set_surface_client_id(surface_id_allocator_->client_id());
113 }
114
115 BrowserCompositor::~BrowserCompositor() {
116 root_layer_->RemoveAllChildren();
David Trainor- moved to gerrit 2016/08/22 23:58:10 Is all of this teardown needed?
Khushal 2016/08/23 02:53:11 Actually no. We have the SetSurface cleanup in Cla
117 host_->GetLayerTree()->SetRootLayer(nullptr);
118 root_layer_ = nullptr;
119 SetAcceleratedWidget(gfx::kNullAcceleratedWidget);
120 }
121
122 void BrowserCompositor::SetContentLayer(
123 scoped_refptr<cc::Layer> content_layer) {
124 root_layer_->RemoveAllChildren();
125 root_layer_->AddChild(content_layer);
126 }
127
128 void BrowserCompositor::SetSize(const gfx::Size& size_in_px) {
129 viewport_size_in_px_ = size_in_px;
130 // Update the host.
David Trainor- moved to gerrit 2016/08/22 23:58:10 newline before this
Khushal 2016/08/23 02:53:11 Done.
131 host_->GetLayerTree()->SetViewportSize(viewport_size_in_px_);
132 root_layer_->SetBounds(viewport_size_in_px_);
133
134 // Update the display.
135 if (display_) {
136 display_->Resize(viewport_size_in_px_);
137 }
138 }
139
140 void BrowserCompositor::SetAcceleratedWidget(gfx::AcceleratedWidget widget) {
141 // Kill all references to the old widget.
142 if (widget_ != gfx::kNullAcceleratedWidget) {
143 // We are always visible if we have a widget.
144 DCHECK(host_->visible());
145 host_->SetVisible(false);
146 if (!host_->output_surface_lost()) {
147 host_->ReleaseOutputSurface();
148 }
149 display_.reset();
150 }
151
152 widget_ = gfx::kNullAcceleratedWidget;
153
154 if (widget != gfx::kNullAcceleratedWidget) {
155 widget_ = widget;
156 host_->SetVisible(true);
157 if (output_surface_request_pending_)
158 HandlePendingOutputSurfaceRequest();
159 }
160 }
161
162 void BrowserCompositor::RequestNewOutputSurface() {
163 DCHECK(!output_surface_request_pending_)
164 << "We already have a pending request?";
165 output_surface_request_pending_ = true;
166 HandlePendingOutputSurfaceRequest();
167 }
168
169 void BrowserCompositor::DidInitializeOutputSurface() {
170 output_surface_request_pending_ = false;
171 }
172
173 void BrowserCompositor::DidFailToInitializeOutputSurface() {
174 NOTREACHED() << "Can't fail to initialize the OutputSurface here";
175 }
176
177 void BrowserCompositor::DidCompleteSwapBuffers() {
178 if (!did_complete_swap_buffers_.is_null()) {
179 did_complete_swap_buffers_.Run();
180 }
181 }
182
183 void BrowserCompositor::HandlePendingOutputSurfaceRequest() {
184 DCHECK(output_surface_request_pending_);
185
186 // Can't handle the request right now since we don't have a widget.
187 if (!host_->visible())
188 return;
189
190 DCHECK_NE(gfx::kNullAcceleratedWidget, widget_);
191
192 scoped_refptr<cc::ContextProvider> context_provider =
193 BlimpContextProvider::Create(
194 widget_, BrowserCompositor::GetGpuMemoryBufferManager());
195
196 std::unique_ptr<cc::OutputSurface> display_output_surface =
197 base::MakeUnique<DisplayOutputSurface>(context_provider);
198
199 auto* task_runner = base::ThreadTaskRunnerHandle::Get().get();
200 std::unique_ptr<cc::SyntheticBeginFrameSource> begin_frame_source(
201 new cc::DelayBasedBeginFrameSource(
202 base::MakeUnique<cc::DelayBasedTimeSource>(task_runner)));
203 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler(
204 begin_frame_source.get(), task_runner,
205 display_output_surface->capabilities().max_frames_pending));
206
207 display_ = base::MakeUnique<cc::Display>(
208 nullptr /*shared_bitmap_manager*/,
209 BrowserCompositor::GetGpuMemoryBufferManager(),
210 host_->settings().renderer_settings, std::move(begin_frame_source),
211 std::move(display_output_surface), std::move(scheduler),
212 base::MakeUnique<cc::TextureMailboxDeleter>(task_runner));
213 display_->SetVisible(true);
214 display_->Resize(viewport_size_in_px_);
215
216 // The Browser compositor and display share the same context provider.
217 std::unique_ptr<cc::OutputSurface> delegated_output_surface =
218 base::MakeUnique<cc::SurfaceDisplayOutputSurface>(
219 BrowserCompositor::GetSurfaceManager(), surface_id_allocator_.get(),
220 display_.get(), context_provider, nullptr);
221
222 host_->SetOutputSurface(std::move(delegated_output_surface));
223 }
224
225 } // namespace client
226 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698