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

Side by Side Diff: blimp/client/compositor/blimp_compositor.cc

Issue 1295243003: Initial commit of the blimp/ folder and target (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Some cleanup nits. Created 5 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 2015 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/compositor/blimp_compositor.h"
6
7 #include "base/bind_helpers.h"
8 #include "base/command_line.h"
9 #include "base/lazy_instance.h"
10 #include "base/single_thread_task_runner.h"
11 #include "base/thread_task_runner_handle.h"
12 #include "base/threading/thread.h"
13 #include "base/threading/thread_local.h"
14 #include "base/threading/thread_restrictions.h"
15 #include "blimp/client/compositor/blimp_context_provider.h"
16 #include "blimp/client/compositor/blimp_output_surface.h"
17 #include "blimp/client/compositor/blimp_task_graph_runner.h"
18 #include "blimp/client/compositor/test/dummy_layer_driver.h"
19 #include "blimp/common/compositor/blimp_layer_tree_settings.h"
20 #include "cc/layers/layer.h"
21 #include "cc/output/output_surface.h"
22 #include "cc/trees/layer_tree_host.h"
23 #include "ui/gl/gl_surface.h"
24
25 namespace {
26
27 base::LazyInstance<blimp::BlimpTaskGraphRunner> g_task_graph_runner =
28 LAZY_INSTANCE_INITIALIZER;
29
30 } // namespace
31
32 // Testing Code:
33 namespace {
Wez 2015/08/27 02:01:51 Why does this need a separate anonymous namespace?
David Trainor- moved to gerrit 2015/08/28 01:23:46 I wanted it separate so I could delete this chunk
Wez 2015/09/03 00:49:27 OK, suggest commenting like: TODO(dtrainor): Repl
David Trainor- moved to gerrit 2015/09/03 06:33:21 Done.
34 base::LazyInstance<blimp::DummyLayerDriver> g_dummy_layer_driver =
35 LAZY_INSTANCE_INITIALIZER;
36 }
37
38 namespace blimp {
39
40 BlimpCompositor::BlimpCompositor(float device_scale_factor)
41 : device_scale_factor_(device_scale_factor), weak_factory_(this) {}
42
43 BlimpCompositor::~BlimpCompositor() {
44 // Make sure things get freed in the right order.
Wez 2015/08/27 02:01:51 nit: This comment explains why we're doing it expl
David Trainor- moved to gerrit 2015/08/28 01:23:46 Done.
Wez 2015/09/03 00:49:27 Acknowledged.
45 host_.reset();
46 settings_.reset();
47 if (compositor_thread_)
48 compositor_thread_->Stop();
49 }
50
51 void BlimpCompositor::SetVisible(bool visible) {
52 if (visible && !host_) {
53 if (!settings_) {
54 settings_.reset(new cc::LayerTreeSettings);
55 GenerateLayerTreeSettings(*settings_,
56 *base::CommandLine::ForCurrentProcess());
57 }
58 // Create the LayerTreeHost
Wez 2015/08/27 02:01:51 nit: Blank line before block comment?
David Trainor- moved to gerrit 2015/08/28 01:23:46 Done.
59 cc::LayerTreeHost::InitParams params;
60 params.client = this;
61 params.shared_bitmap_manager = nullptr;
62 params.gpu_memory_buffer_manager = nullptr;
Wez 2015/08/27 02:01:51 nit: These two = nullptrs are redundant.
David Trainor- moved to gerrit 2015/08/28 01:23:46 Done.
63 params.task_graph_runner = g_task_graph_runner.Pointer();
64 params.main_task_runner = base::ThreadTaskRunnerHandle::Get();
65 params.settings = settings_.get();
66 // TODO(dtrainor): Swap this out with the remote client proxy when
67 // implemented.
68 host_ =
69 cc::LayerTreeHost::CreateThreaded(GetCompositorTaskRunner(), &params);
70
71 host_->SetVisible(true);
72 host_->SetLayerTreeHostClientReady();
73 host_->SetViewportSize(viewport_size_);
74 host_->SetDeviceScaleFactor(device_scale_factor_);
75
76 // Build the root Layer
Wez 2015/08/27 02:01:51 nit: Punctuation - missing .
David Trainor- moved to gerrit 2015/08/28 01:23:46 Done.
77 scoped_refptr<cc::Layer> root(cc::Layer::Create(cc::LayerSettings()));
78 host_->SetRootLayer(root);
79
80 // For testing, set the dummy Layer.
81 g_dummy_layer_driver.Pointer()->SetParentLayer(root);
82
83 } else if (!visible && host_) {
84 // Destroy the LayerTreeHost
Wez 2015/08/27 02:01:51 nit: Punctuation Also, this comment seems redunda
David Trainor- moved to gerrit 2015/08/28 01:23:46 Done.
85 host_.reset();
86 }
87 }
88
89 void BlimpCompositor::SetSize(const gfx::Size& size) {
90 viewport_size_ = size;
91 if (host_)
92 host_->SetViewportSize(viewport_size_);
93 }
94
95 void BlimpCompositor::Layout() {}
96
97 void BlimpCompositor::RequestNewOutputSurface() {
98 gfx::AcceleratedWidget widget = GetWindow();
99 DCHECK(widget);
100
101 scoped_refptr<BlimpContextProvider> context_provider =
102 BlimpContextProvider::Create(widget);
103
104 scoped_ptr<cc::OutputSurface> output_surface(
105 new BlimpOutputSurface(context_provider));
106
107 host_->SetOutputSurface(output_surface.Pass());
Wez 2015/08/27 02:01:51 nit: Do you need the output_surface temporary?
David Trainor- moved to gerrit 2015/08/28 01:23:46 Done.
108 }
109
110 void BlimpCompositor::DidInitializeOutputSurface() {}
111
112 void BlimpCompositor::DidFailToInitializeOutputSurface() {}
113
114 void BlimpCompositor::DidCommit() {}
115
116 void BlimpCompositor::DidCompleteSwapBuffers() {}
117
118 void BlimpCompositor::ScheduleComposite() {}
119
120 void BlimpCompositor::ScheduleAnimation() {}
121
122 void BlimpCompositor::DidPostSwapBuffers() {}
123
124 void BlimpCompositor::DidAbortSwapBuffers() {}
125
126 void BlimpCompositor::GenerateLayerTreeSettings(cc::LayerTreeSettings& settings,
127 const base::CommandLine& cmd) {
128 PopulateCommonLayerTreeSettings(settings, cmd);
129 }
130
131 scoped_refptr<base::SingleThreadTaskRunner>
132 BlimpCompositor::GetCompositorTaskRunner() {
133 if (!compositor_thread_) {
Wez 2015/08/27 02:01:51 nit: Suggest restructing this as an early-return i
David Trainor- moved to gerrit 2015/08/28 01:23:46 Done.
134 base::Thread::Options thread_options;
135 #if defined(OS_ANDROID)
136 thread_options.priority = base::ThreadPriority::DISPLAY;
137 #endif
138 compositor_thread_.reset(new base::Thread("Compositor"));
139 compositor_thread_->StartWithOptions(thread_options);
140
141 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
142 compositor_thread_->task_runner();
143 task_runner->PostTask(
144 FROM_HERE,
145 base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed),
146 false));
Wez 2015/08/27 02:01:51 What's all this about? Surely you can just create
David Trainor- moved to gerrit 2015/08/28 01:23:46 I pulled this piece from render_thread_impl.cc. L
Wez 2015/09/03 00:49:27 Ha! We have a poster about avoiding negatives in c
David Trainor- moved to gerrit 2015/09/03 06:33:21 Yes! I want a poster like that. I had to ask Tom
147
148 return task_runner;
149 } else {
150 return compositor_thread_->task_runner();
151 }
152 }
153
154 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698