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 // For testing purposes. |
| 31 base::LazyInstance<blimp::DummyLayerDriver> g_dummy_layer_driver = |
| 32 LAZY_INSTANCE_INITIALIZER; |
| 33 |
| 34 } // namespace |
| 35 |
| 36 namespace blimp { |
| 37 |
| 38 BlimpCompositor::BlimpCompositor(float device_scale_factor) |
| 39 : device_scale_factor_(device_scale_factor) {} |
| 40 |
| 41 BlimpCompositor::~BlimpCompositor() { |
| 42 // Destroy |host_| first, as it has a reference to the |settings_| and runs |
| 43 // tasks on |compositor_thread_|. |
| 44 host_.reset(); |
| 45 settings_.reset(); |
| 46 if (compositor_thread_) |
| 47 compositor_thread_->Stop(); |
| 48 } |
| 49 |
| 50 void BlimpCompositor::SetVisible(bool visible) { |
| 51 if (visible && !host_) { |
| 52 if (!settings_) { |
| 53 settings_.reset(new cc::LayerTreeSettings); |
| 54 GenerateLayerTreeSettings(settings_.get(), |
| 55 *base::CommandLine::ForCurrentProcess()); |
| 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(cc::LayerTreeSettings* settings, |
| 142 const base::CommandLine& cmd) { |
| 143 PopulateCommonLayerTreeSettings(settings, cmd); |
| 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 |
| 165 return task_runner; |
| 166 } |
| 167 |
| 168 } // namespace blimp |
OLD | NEW |