0

cc: Introduce CompositorMode enum.

The compositor can currently be run in single threaded or threaded mode.
The LayerTreeHost needs to be aware of the mode it is running in for 2
reasons:
1) To safely cast Proxy to SingleThreadProxy to make calls which
are supported only in single threaded mode.
2) To make decisions which require excluding browser compositors which
run only in single threaded mode.

The LayerTreeHost checks if it has the impl task runner to know the
mode of operation. Using the enum will make the purpose of this check
explicit at the call sites and allow the addition of the remote mode to
the compositor which will be run in the renderer but will not have an
impl task runner since all impl thread operations will be run on the
client compositor.

BUG=550687
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel

Review URL: https://codereview.chromium.org/1464313007

Cr-Commit-Position: refs/heads/master@{#363708}
This commit is contained in:
khushalsagar
2015-12-07 18:19:01 -08:00
committed by Commit bot
parent f48e75b866
commit 19458bd9c4
10 changed files with 75 additions and 21 deletions

@ -471,6 +471,7 @@ component("cc") {
"trees/blocking_task_runner.h",
"trees/channel_impl.h",
"trees/channel_main.h",
"trees/compositor_mode.h",
"trees/damage_tracker.cc",
"trees/damage_tracker.h",
"trees/draw_property_utils.cc",

@ -533,6 +533,7 @@
'trees/blocking_task_runner.h',
'trees/channel_impl.h',
'trees/channel_main.h',
'trees/compositor_mode.h',
'trees/damage_tracker.cc',
'trees/damage_tracker.h',
'trees/draw_property_utils.cc',

@ -47,7 +47,7 @@ class MockLayerTreeHost : public LayerTreeHost {
public:
MockLayerTreeHost(LayerTreeHostSingleThreadClient* single_thread_client,
LayerTreeHost::InitParams* params)
: LayerTreeHost(params) {
: LayerTreeHost(params, CompositorMode::SingleThreaded) {
InitializeSingleThreaded(single_thread_client,
base::ThreadTaskRunnerHandle::Get(), nullptr);
}

@ -74,7 +74,7 @@ class MockLayerTreeHost : public LayerTreeHost {
private:
MockLayerTreeHost(FakeLayerTreeHostClient* client,
LayerTreeHost::InitParams* params)
: LayerTreeHost(params) {
: LayerTreeHost(params, CompositorMode::SingleThreaded) {
InitializeSingleThreaded(client, base::ThreadTaskRunnerHandle::Get(),
nullptr);
}

@ -10,7 +10,7 @@
namespace cc {
FakeLayerTreeHost::FakeLayerTreeHost(FakeLayerTreeHostClient* client,
LayerTreeHost::InitParams* params)
: LayerTreeHost(params),
: LayerTreeHost(params, CompositorMode::SingleThreaded),
client_(client),
host_impl_(*params->settings,
&task_runner_provider_,

@ -678,6 +678,7 @@ class LayerTreeHostForTesting : public LayerTreeHost {
public:
static scoped_ptr<LayerTreeHostForTesting> Create(
TestHooks* test_hooks,
CompositorMode mode,
LayerTreeHostClientForTesting* client,
SharedBitmapManager* shared_bitmap_manager,
gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
@ -693,11 +694,12 @@ class LayerTreeHostForTesting : public LayerTreeHost {
params.task_graph_runner = task_graph_runner;
params.settings = &settings;
scoped_ptr<LayerTreeHostForTesting> layer_tree_host(
new LayerTreeHostForTesting(test_hooks, &params));
new LayerTreeHostForTesting(test_hooks, &params, mode));
scoped_ptr<TaskRunnerProvider> task_runner_provider =
TaskRunnerProvider::Create(main_task_runner, impl_task_runner);
scoped_ptr<Proxy> proxy;
if (impl_task_runner.get()) {
if (mode == CompositorMode::Threaded) {
DCHECK(impl_task_runner.get());
proxy = ThreadProxyForTest::Create(
test_hooks, layer_tree_host.get(), task_runner_provider.get(),
std::move(external_begin_frame_source));
@ -735,8 +737,11 @@ class LayerTreeHostForTesting : public LayerTreeHost {
private:
LayerTreeHostForTesting(TestHooks* test_hooks,
LayerTreeHost::InitParams* params)
: LayerTreeHost(params), test_hooks_(test_hooks), test_started_(false) {}
LayerTreeHost::InitParams* params,
CompositorMode mode)
: LayerTreeHost(params, mode),
test_hooks_(test_hooks),
test_started_(false) {}
TestHooks* test_hooks_;
bool test_started_;
@ -915,8 +920,10 @@ void LayerTreeTest::DoBeginTest() {
}
DCHECK(!impl_thread_ || impl_thread_->task_runner().get());
CompositorMode mode =
impl_thread_ ? CompositorMode::Threaded : CompositorMode::SingleThreaded;
layer_tree_host_ = LayerTreeHostForTesting::Create(
this, client_.get(), shared_bitmap_manager_.get(),
this, mode, client_.get(), shared_bitmap_manager_.get(),
gpu_memory_buffer_manager_.get(), task_graph_runner_.get(), settings_,
base::ThreadTaskRunnerHandle::Get(),
impl_thread_ ? impl_thread_->task_runner() : NULL,

@ -0,0 +1,23 @@
// 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.
#ifndef CC_TREES_COMPOSITOR_MODE_H_
#define CC_TREES_COMPOSITOR_MODE_H_
namespace cc {
// The LayerTreeHost uses the CompositorMode to determine the current mode of
// operation, which is needed to:
// 1) Safely cast Proxy to SingleThreadProxy to allow operations only supported
// in SingleThreaded mode.
// 2) Make decisions restricted to either browser(SingleThreaded) or renderer
// compositors(Threaded).
enum CompositorMode {
SingleThreaded,
Threaded,
};
} // namespace cc
#endif // CC_TREES_COMPOSITOR_MODE_H_

@ -66,7 +66,8 @@ scoped_ptr<LayerTreeHost> LayerTreeHost::CreateThreaded(
DCHECK(params->main_task_runner.get());
DCHECK(impl_task_runner.get());
DCHECK(params->settings);
scoped_ptr<LayerTreeHost> layer_tree_host(new LayerTreeHost(params));
scoped_ptr<LayerTreeHost> layer_tree_host(
new LayerTreeHost(params, CompositorMode::Threaded));
layer_tree_host->InitializeThreaded(
params->main_task_runner, impl_task_runner,
std::move(params->external_begin_frame_source));
@ -77,16 +78,18 @@ scoped_ptr<LayerTreeHost> LayerTreeHost::CreateSingleThreaded(
LayerTreeHostSingleThreadClient* single_thread_client,
InitParams* params) {
DCHECK(params->settings);
scoped_ptr<LayerTreeHost> layer_tree_host(new LayerTreeHost(params));
scoped_ptr<LayerTreeHost> layer_tree_host(
new LayerTreeHost(params, CompositorMode::SingleThreaded));
layer_tree_host->InitializeSingleThreaded(
single_thread_client, params->main_task_runner,
std::move(params->external_begin_frame_source));
return layer_tree_host;
}
LayerTreeHost::LayerTreeHost(InitParams* params)
LayerTreeHost::LayerTreeHost(InitParams* params, CompositorMode mode)
: micro_benchmark_controller_(this),
next_ui_resource_id_(1),
compositor_mode_(mode),
needs_full_tree_sync_(true),
needs_meta_info_recomputation_(true),
client_(params->client),
@ -674,7 +677,7 @@ void LayerTreeHost::NotifyInputThrottledUntilCommit() {
}
void LayerTreeHost::LayoutAndUpdateLayers() {
DCHECK(!task_runner_provider_->HasImplThread());
DCHECK(IsSingleThreaded());
// This function is only valid when not using the scheduler.
DCHECK(!settings_.single_thread_proxy_scheduler);
SingleThreadProxy* proxy = static_cast<SingleThreadProxy*>(proxy_.get());
@ -692,7 +695,7 @@ void LayerTreeHost::LayoutAndUpdateLayers() {
}
void LayerTreeHost::Composite(base::TimeTicks frame_begin_time) {
DCHECK(!task_runner_provider_->HasImplThread());
DCHECK(IsSingleThreaded());
// This function is only valid when not using the scheduler.
DCHECK(!settings_.single_thread_proxy_scheduler);
SingleThreadProxy* proxy = static_cast<SingleThreadProxy*>(proxy_.get());
@ -732,9 +735,8 @@ static Layer* FindFirstScrollableLayer(Layer* layer) {
void LayerTreeHost::RecordGpuRasterizationHistogram() {
// Gpu rasterization is only supported for Renderer compositors.
// Checking for proxy_->HasImplThread() to exclude Browser compositors.
if (gpu_rasterization_histogram_recorded_ ||
!task_runner_provider_->HasImplThread())
// Checking for IsThreaded() to exclude Browser compositors.
if (gpu_rasterization_histogram_recorded_ || IsThreaded())
return;
// Record how widely gpu rasterization is enabled.
@ -896,7 +898,7 @@ void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints,
TopControlsState current,
bool animate) {
// Top controls are only used in threaded mode.
DCHECK(task_runner_provider_->HasImplThread());
DCHECK(IsThreaded());
proxy_->UpdateTopControlsState(constraints, current, animate);
}
@ -1247,4 +1249,16 @@ bool LayerTreeHost::HasActiveAnimation(const Layer* layer) const {
: false;
}
bool LayerTreeHost::IsSingleThreaded() const {
DCHECK(compositor_mode_ != CompositorMode::SingleThreaded ||
!task_runner_provider_->HasImplThread());
return compositor_mode_ == CompositorMode::SingleThreaded;
}
bool LayerTreeHost::IsThreaded() const {
DCHECK(compositor_mode_ != CompositorMode::Threaded ||
task_runner_provider_->HasImplThread());
return compositor_mode_ == CompositorMode::Threaded;
}
} // namespace cc

@ -33,6 +33,7 @@
#include "cc/resources/resource_format.h"
#include "cc/resources/scoped_ui_resource.h"
#include "cc/surfaces/surface_sequence.h"
#include "cc/trees/compositor_mode.h"
#include "cc/trees/layer_tree_host_client.h"
#include "cc/trees/layer_tree_host_common.h"
#include "cc/trees/layer_tree_settings.h"
@ -359,7 +360,7 @@ class CC_EXPORT LayerTreeHost : public MutatorHostClient {
bool HasActiveAnimation(const Layer* layer) const;
protected:
explicit LayerTreeHost(InitParams* params);
LayerTreeHost(InitParams* params, CompositorMode mode);
void InitializeThreaded(
scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
@ -397,6 +398,9 @@ class CC_EXPORT LayerTreeHost : public MutatorHostClient {
bool AnimateLayersRecursive(Layer* current, base::TimeTicks time);
bool IsSingleThreaded() const;
bool IsThreaded() const;
struct UIResourceClientData {
UIResourceClient* client;
gfx::Size size;
@ -417,6 +421,8 @@ class CC_EXPORT LayerTreeHost : public MutatorHostClient {
void SetPropertyTreesNeedRebuild();
const CompositorMode compositor_mode_;
bool needs_full_tree_sync_;
bool needs_meta_info_recomputation_;

@ -69,8 +69,9 @@ const ui::SystemUIResourceType kTestResourceType = ui::OVERSCROLL_GLOW;
class MockLayerTreeHost : public cc::LayerTreeHost {
public:
MockLayerTreeHost(cc::LayerTreeHost::InitParams* params)
: cc::LayerTreeHost(params) {}
MockLayerTreeHost(cc::LayerTreeHost::InitParams* params,
cc::CompositorMode mode)
: cc::LayerTreeHost(params, mode) {}
MOCK_METHOD1(CreateUIResource, cc::UIResourceId(cc::UIResourceClient*));
MOCK_METHOD1(DeleteUIResource, void(cc::UIResourceId));
@ -92,7 +93,8 @@ class ResourceManagerTest : public testing::Test {
params.client = &fake_client_;
params.settings = &settings;
params.task_graph_runner = &task_graph_runner_;
host_.reset(new MockLayerTreeHost(&params));
host_.reset(new MockLayerTreeHost(&params,
cc::CompositorMode::SingleThreaded));
resource_manager_.Init(host_.get());
}