Index: blimp/client/compositor/blimp_compositor.cc |
diff --git a/blimp/client/compositor/blimp_compositor.cc b/blimp/client/compositor/blimp_compositor.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a8f71e47a8e33791026467fbcebda1e2d902141d |
--- /dev/null |
+++ b/blimp/client/compositor/blimp_compositor.cc |
@@ -0,0 +1,154 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "blimp/client/compositor/blimp_compositor.h" |
+ |
+#include "base/bind_helpers.h" |
+#include "base/command_line.h" |
+#include "base/lazy_instance.h" |
+#include "base/single_thread_task_runner.h" |
+#include "base/thread_task_runner_handle.h" |
+#include "base/threading/thread.h" |
+#include "base/threading/thread_local.h" |
+#include "base/threading/thread_restrictions.h" |
+#include "blimp/client/compositor/blimp_context_provider.h" |
+#include "blimp/client/compositor/blimp_output_surface.h" |
+#include "blimp/client/compositor/blimp_task_graph_runner.h" |
+#include "blimp/client/compositor/test/dummy_layer_driver.h" |
+#include "blimp/common/compositor/blimp_layer_tree_settings.h" |
+#include "cc/layers/layer.h" |
+#include "cc/output/output_surface.h" |
+#include "cc/trees/layer_tree_host.h" |
+#include "ui/gl/gl_surface.h" |
+ |
+namespace { |
+ |
+base::LazyInstance<blimp::BlimpTaskGraphRunner> g_task_graph_runner = |
+ LAZY_INSTANCE_INITIALIZER; |
+ |
+} // namespace |
+ |
+// Testing Code: |
+namespace { |
+base::LazyInstance<blimp::DummyLayerDriver> g_dummy_layer_driver = |
+ LAZY_INSTANCE_INITIALIZER; |
+} |
+ |
+namespace blimp { |
+ |
+BlimpCompositor::BlimpCompositor(float device_scale_factor) |
+ : device_scale_factor_(device_scale_factor), weak_factory_(this) {} |
+ |
+BlimpCompositor::~BlimpCompositor() { |
+ // Make sure things get freed in the right order. |
+ host_.reset(); |
+ settings_.reset(); |
+ if (compositor_thread_) |
+ compositor_thread_->Stop(); |
+} |
+ |
+void BlimpCompositor::SetVisible(bool visible) { |
+ if (visible && !host_) { |
+ if (!settings_) { |
+ settings_.reset(new cc::LayerTreeSettings); |
+ GenerateLayerTreeSettings(settings_.get(), |
+ *base::CommandLine::ForCurrentProcess()); |
+ } |
+ // Create the LayerTreeHost |
+ cc::LayerTreeHost::InitParams params; |
+ params.client = this; |
+ params.shared_bitmap_manager = nullptr; |
+ params.gpu_memory_buffer_manager = nullptr; |
+ params.task_graph_runner = g_task_graph_runner.Pointer(); |
+ params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); |
+ params.settings = settings_.get(); |
+ // TODO(dtrainor): Swap this out with the remote client proxy when |
+ // implemented. |
+ host_ = |
+ cc::LayerTreeHost::CreateThreaded(GetCompositorTaskRunner(), ¶ms); |
+ |
+ host_->SetVisible(true); |
+ host_->SetLayerTreeHostClientReady(); |
+ host_->SetViewportSize(viewport_size_); |
+ host_->SetDeviceScaleFactor(device_scale_factor_); |
+ |
+ // Build the root Layer |
+ scoped_refptr<cc::Layer> root(cc::Layer::Create(cc::LayerSettings())); |
+ host_->SetRootLayer(root); |
+ |
+ // For testing, set the dummy Layer. |
+ g_dummy_layer_driver.Pointer()->SetParentLayer(root); |
+ |
+ } else if (!visible && host_) { |
+ // Destroy the LayerTreeHost |
+ host_.reset(); |
+ } |
+} |
+ |
+void BlimpCompositor::SetSize(const gfx::Size& size) { |
+ viewport_size_ = size; |
+ if (host_) |
+ host_->SetViewportSize(viewport_size_); |
+} |
+ |
+void BlimpCompositor::Layout() {} |
+ |
+void BlimpCompositor::RequestNewOutputSurface() { |
+ gfx::AcceleratedWidget widget = GetWindow(); |
+ DCHECK(widget); |
+ |
+ scoped_refptr<BlimpContextProvider> context_provider = |
+ BlimpContextProvider::Create(widget); |
+ |
+ scoped_ptr<cc::OutputSurface> output_surface( |
+ new BlimpOutputSurface(context_provider)); |
+ |
+ host_->SetOutputSurface(output_surface.Pass()); |
+} |
+ |
+void BlimpCompositor::DidInitializeOutputSurface() {} |
+ |
+void BlimpCompositor::DidFailToInitializeOutputSurface() {} |
+ |
+void BlimpCompositor::DidCommit() {} |
+ |
+void BlimpCompositor::DidCompleteSwapBuffers() {} |
+ |
+void BlimpCompositor::ScheduleComposite() {} |
+ |
+void BlimpCompositor::ScheduleAnimation() {} |
+ |
+void BlimpCompositor::DidPostSwapBuffers() {} |
+ |
+void BlimpCompositor::DidAbortSwapBuffers() {} |
+ |
+void BlimpCompositor::GenerateLayerTreeSettings(cc::LayerTreeSettings* settings, |
+ const base::CommandLine& cmd) { |
+ PopulateCommonLayerTreeSettings(settings, cmd); |
+} |
+ |
+scoped_refptr<base::SingleThreadTaskRunner> |
+BlimpCompositor::GetCompositorTaskRunner() { |
+ if (!compositor_thread_) { |
+ base::Thread::Options thread_options; |
+#if defined(OS_ANDROID) |
+ thread_options.priority = base::ThreadPriority::DISPLAY; |
+#endif |
+ compositor_thread_.reset(new base::Thread("Compositor")); |
+ compositor_thread_->StartWithOptions(thread_options); |
+ |
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner = |
+ compositor_thread_->task_runner(); |
+ task_runner->PostTask( |
+ FROM_HERE, |
+ base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed), |
+ false)); |
+ |
+ return task_runner; |
+ } else { |
+ return compositor_thread_->task_runner(); |
+ } |
+} |
+ |
+} // namespace blimp |