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

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: Cleaned it up, addressed nyquist@ 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 {
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.
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
59 cc::LayerTreeHost::InitParams params;
60 params.client = this;
61 params.shared_bitmap_manager = nullptr;
62 params.gpu_memory_buffer_manager = nullptr;
63 params.task_graph_runner = g_task_graph_runner.Pointer();
64 params.main_task_runner = base::ThreadTaskRunnerHandle::Get();
65 params.settings = settings_.get();
66 host_ =
67 cc::LayerTreeHost::CreateThreaded(GetCompositorTaskRunner(), &params);
68
69 host_->SetVisible(true);
70 host_->SetLayerTreeHostClientReady();
71 host_->SetViewportSize(viewport_size_);
72 host_->SetDeviceScaleFactor(device_scale_factor_);
73
74 // Build the root Layer
75 scoped_refptr<cc::Layer> root(cc::Layer::Create(cc::LayerSettings()));
76 host_->SetRootLayer(root);
77
78 // For testing, set the dummy Layer.
79 g_dummy_layer_driver.Pointer()->SetParentLayer(root);
80
81 } else if (!visible && host_) {
82 // Destroy the LayerTreeHost
83 host_.reset();
84 }
85 }
86
87 void BlimpCompositor::SetSize(const gfx::Size& size) {
88 viewport_size_ = size;
89 if (host_)
90 host_->SetViewportSize(viewport_size_);
91 }
92
93 void BlimpCompositor::Layout() {}
94
95 void BlimpCompositor::RequestNewOutputSurface() {
96 gfx::AcceleratedWidget widget = GetWindow();
97 DCHECK(widget);
98
99 scoped_refptr<BlimpContextProvider> context_provider =
100 BlimpContextProvider::Create(widget);
101
102 scoped_ptr<cc::OutputSurface> output_surface(
103 new BlimpOutputSurface(context_provider));
104
105 host_->SetOutputSurface(output_surface.Pass());
106 }
107
108 void BlimpCompositor::DidInitializeOutputSurface() {}
109
110 void BlimpCompositor::DidFailToInitializeOutputSurface() {}
111
112 void BlimpCompositor::DidCommit() {}
113
114 void BlimpCompositor::DidCompleteSwapBuffers() {}
115
116 void BlimpCompositor::ScheduleComposite() {}
117
118 void BlimpCompositor::ScheduleAnimation() {}
119
120 void BlimpCompositor::DidPostSwapBuffers() {}
121
122 void BlimpCompositor::DidAbortSwapBuffers() {}
123
124 void BlimpCompositor::GenerateLayerTreeSettings(cc::LayerTreeSettings& settings,
125 const base::CommandLine& cmd) {
126 PopulateCommonLayerTreeSettings(settings, cmd);
127 }
128
129 scoped_refptr<base::SingleThreadTaskRunner>
130 BlimpCompositor::GetCompositorTaskRunner() {
131 if (!compositor_thread_) {
132 base::Thread::Options thread_options;
133 #if defined(OS_ANDROID)
134 thread_options.priority = base::ThreadPriority::DISPLAY;
135 #endif
136 compositor_thread_.reset(new base::Thread("Compositor"));
137 compositor_thread_->StartWithOptions(thread_options);
138
139 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
140 compositor_thread_->task_runner();
141 task_runner->PostTask(
142 FROM_HERE,
143 base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed),
144 false));
145
146 return task_runner;
147 } else {
148 return compositor_thread_->task_runner();
149 }
150 }
151
152 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698