Chromium Code Reviews| 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..edb32bcaa7a254f4198177fac563aff591bf7c36 |
| --- /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 { |
|
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.
|
| +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. |
|
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.
|
| + 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_, |
| + *base::CommandLine::ForCurrentProcess()); |
| + } |
| + // 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.
|
| + cc::LayerTreeHost::InitParams params; |
| + params.client = this; |
| + params.shared_bitmap_manager = nullptr; |
| + 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.
|
| + 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 |
|
Wez
2015/08/27 02:01:51
nit: Punctuation - missing .
David Trainor- moved to gerrit
2015/08/28 01:23:46
Done.
|
| + 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 |
|
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.
|
| + 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()); |
|
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.
|
| +} |
| + |
| +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_) { |
|
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.
|
| + 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)); |
|
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
|
| + |
| + return task_runner; |
| + } else { |
| + return compositor_thread_->task_runner(); |
| + } |
| +} |
| + |
| +} // namespace blimp |