OLD | NEW |
---|---|
(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 // TODO(dtrainor): Replace this when Layer content comes from the server (see | |
31 // crbug.com/527200 for details). | |
32 base::LazyInstance<blimp::DummyLayerDriver> g_dummy_layer_driver = | |
33 LAZY_INSTANCE_INITIALIZER; | |
34 | |
35 } // namespace | |
36 | |
37 namespace blimp { | |
38 | |
39 BlimpCompositor::BlimpCompositor(float dp_to_px) | |
40 : device_scale_factor_(dp_to_px) {} | |
Wez
2015/09/03 19:56:08
Rename the member as well?
| |
41 | |
42 BlimpCompositor::~BlimpCompositor() { | |
43 // Destroy |host_| first, as it has a reference to the |settings_| and runs | |
44 // tasks on |compositor_thread_|. | |
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_.get()); | |
56 } | |
57 | |
58 // Create the LayerTreeHost | |
59 cc::LayerTreeHost::InitParams params; | |
60 params.client = this; | |
61 params.task_graph_runner = g_task_graph_runner.Pointer(); | |
62 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); | |
63 params.settings = settings_.get(); | |
64 | |
65 // TODO(dtrainor): Swap this out with the remote client proxy when | |
66 // implemented. | |
67 host_ = | |
68 cc::LayerTreeHost::CreateThreaded(GetCompositorTaskRunner(), ¶ms); | |
69 | |
70 host_->SetVisible(true); | |
71 host_->SetLayerTreeHostClientReady(); | |
72 host_->SetViewportSize(viewport_size_); | |
73 host_->SetDeviceScaleFactor(device_scale_factor_); | |
74 | |
75 // Build the root Layer. | |
76 scoped_refptr<cc::Layer> root(cc::Layer::Create(cc::LayerSettings())); | |
77 host_->SetRootLayer(root); | |
78 | |
79 // For testing, set the dummy Layer. | |
80 g_dummy_layer_driver.Pointer()->SetParentLayer(root); | |
81 | |
82 } else if (!visible && host_) { | |
83 // Release the LayerTreeHost to free all resources when the compositor is no | |
84 // longer visible. This will destroy the underlying compositor components. | |
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::WillBeginMainFrame() {} | |
96 | |
97 void BlimpCompositor::DidBeginMainFrame() {} | |
98 | |
99 void BlimpCompositor::BeginMainFrame(const cc::BeginFrameArgs& args) {} | |
100 | |
101 void BlimpCompositor::BeginMainFrameNotExpectedSoon() {} | |
102 | |
103 void BlimpCompositor::Layout() {} | |
104 | |
105 void BlimpCompositor::ApplyViewportDeltas( | |
106 const gfx::Vector2dF& inner_delta, | |
107 const gfx::Vector2dF& outer_delta, | |
108 const gfx::Vector2dF& elastic_overscroll_delta, | |
109 float page_scale, | |
110 float top_controls_delta) {} | |
111 | |
112 void BlimpCompositor::RequestNewOutputSurface() { | |
113 gfx::AcceleratedWidget widget = GetWindow(); | |
114 DCHECK(widget); | |
115 | |
116 scoped_refptr<BlimpContextProvider> context_provider = | |
117 BlimpContextProvider::Create(widget); | |
118 | |
119 host_->SetOutputSurface( | |
120 make_scoped_ptr(new BlimpOutputSurface(context_provider))); | |
121 } | |
122 | |
123 void BlimpCompositor::DidInitializeOutputSurface() {} | |
124 | |
125 void BlimpCompositor::DidFailToInitializeOutputSurface() {} | |
126 | |
127 void BlimpCompositor::WillCommit() {} | |
128 | |
129 void BlimpCompositor::DidCommit() {} | |
130 | |
131 void BlimpCompositor::DidCommitAndDrawFrame() {} | |
132 | |
133 void BlimpCompositor::DidCompleteSwapBuffers() {} | |
134 | |
135 void BlimpCompositor::DidCompletePageScaleAnimation() {} | |
136 | |
137 void BlimpCompositor::RecordFrameTimingEvents( | |
138 scoped_ptr<cc::FrameTimingTracker::CompositeTimingSet> composite_events, | |
139 scoped_ptr<cc::FrameTimingTracker::MainFrameTimingSet> main_frame_events) {} | |
140 | |
141 void BlimpCompositor::GenerateLayerTreeSettings( | |
142 cc::LayerTreeSettings* settings) { | |
143 PopulateCommonLayerTreeSettings(settings); | |
144 } | |
145 | |
146 scoped_refptr<base::SingleThreadTaskRunner> | |
147 BlimpCompositor::GetCompositorTaskRunner() { | |
148 if (compositor_thread_) | |
149 return compositor_thread_->task_runner(); | |
150 | |
151 base::Thread::Options thread_options; | |
152 #if defined(OS_ANDROID) | |
153 thread_options.priority = base::ThreadPriority::DISPLAY; | |
154 #endif | |
155 compositor_thread_.reset(new base::Thread("Compositor")); | |
156 compositor_thread_->StartWithOptions(thread_options); | |
157 | |
158 scoped_refptr<base::SingleThreadTaskRunner> task_runner = | |
159 compositor_thread_->task_runner(); | |
160 task_runner->PostTask( | |
161 FROM_HERE, | |
162 base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed), | |
163 false)); | |
164 // TODO(dtrainor): Determine whether or not we can disallow waiting. | |
165 | |
166 return task_runner; | |
167 } | |
168 | |
169 } // namespace blimp | |
OLD | NEW |