Skip to content

Commit

Permalink
cc: Add SwapPromiseManager and SurfaceSequenceGenerator.
Browse files Browse the repository at this point in the history
Move SwapPromise tracking to SwapPromiseManager and SurfaceSequnce
creation to SurfaceSequenceGenerator.

BUG=625283
CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_precise_blink_rel

Review-Url: https://codereview.chromium.org/2323423002
Cr-Commit-Position: refs/heads/master@{#418666}
  • Loading branch information
khushalsagar authored and Commit bot committed Sep 14, 2016
1 parent eaa283b commit 8297ae9
Show file tree
Hide file tree
Showing 28 changed files with 385 additions and 166 deletions.
6 changes: 6 additions & 0 deletions cc/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,10 @@ component("cc") {
"trees/scroll_node.h",
"trees/single_thread_proxy.cc",
"trees/single_thread_proxy.h",
"trees/surface_sequence_generator.cc",
"trees/surface_sequence_generator.h",
"trees/swap_promise_manager.cc",
"trees/swap_promise_manager.h",
"trees/swap_promise_monitor.cc",
"trees/swap_promise_monitor.h",
"trees/task_runner_provider.cc",
Expand Down Expand Up @@ -938,6 +942,8 @@ test("cc_unittests") {
"trees/occlusion_unittest.cc",
"trees/property_tree_unittest.cc",
"trees/proxy_common_unittest.cc",
"trees/surface_sequence_generator_unittest.cc",
"trees/swap_promise_manager_unittest.cc",
"trees/tree_synchronizer_unittest.cc",

# Surfaces test files.
Expand Down
2 changes: 0 additions & 2 deletions cc/layers/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,6 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> {
// of |proto| is only read if |needs_push_properties_| is set.
void FromLayerPropertiesProto(const proto::LayerProperties& proto);

// TODO(xingliu): Layer will hold LayerTree instead of LayerTreeHost.
// http://crbug.com/628683
LayerTreeHost* layer_tree_host() { return layer_tree_host_; }
const LayerTreeHost* layer_tree_host() const { return layer_tree_host_; }
LayerTree* GetLayerTree() const;
Expand Down
6 changes: 3 additions & 3 deletions cc/layers/painted_scrollbar_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void PaintedScrollbarLayer::UpdateThumbAndTrackGeometry() {

void PaintedScrollbarLayer::UpdateInternalContentScale() {
float scale = GetLayerTree()->device_scale_factor();
if (GetLayerTree()
if (layer_tree_host()
->GetSettings()
.layer_transforms_should_scale_layer_contents) {
gfx::Transform transform;
Expand Down Expand Up @@ -229,7 +229,7 @@ bool PaintedScrollbarLayer::Update() {

if (!track_resource_ || scrollbar_->NeedsPaintPart(TRACK)) {
track_resource_ = ScopedUIResource::Create(
GetLayerTree()->GetUIResourceManager(),
layer_tree_host()->GetUIResourceManager(),
RasterizeScrollbarPart(track_layer_rect, scaled_track_rect, TRACK));
}

Expand All @@ -241,7 +241,7 @@ bool PaintedScrollbarLayer::Update() {
scaled_thumb_rect.size() !=
thumb_resource_->GetBitmap(0, false).GetSize()) {
thumb_resource_ = ScopedUIResource::Create(
GetLayerTree()->GetUIResourceManager(),
layer_tree_host()->GetUIResourceManager(),
RasterizeScrollbarPart(thumb_layer_rect, scaled_thumb_rect, THUMB));
}
thumb_opacity_ = scrollbar_->ThumbOpacity();
Expand Down
9 changes: 7 additions & 2 deletions cc/layers/surface_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "cc/layers/surface_layer_impl.h"
#include "cc/output/swap_promise.h"
#include "cc/trees/layer_tree_host.h"
#include "cc/trees/surface_sequence_generator.h"
#include "cc/trees/swap_promise_manager.h"

namespace cc {

Expand Down Expand Up @@ -104,7 +106,9 @@ void SurfaceLayer::PushPropertiesTo(LayerImpl* layer) {
void SurfaceLayer::CreateNewDestroySequence() {
DCHECK(destroy_sequence_.is_null());
if (layer_tree_host()) {
destroy_sequence_ = layer_tree_host()->CreateSurfaceSequence();
destroy_sequence_ = layer_tree_host()
->GetSurfaceSequenceGenerator()
->CreateSurfaceSequence();
require_callback_.Run(surface_id_, destroy_sequence_);
}
}
Expand All @@ -115,7 +119,8 @@ void SurfaceLayer::SatisfyDestroySequence() {
DCHECK(!destroy_sequence_.is_null());
std::unique_ptr<SatisfySwapPromise> satisfy(
new SatisfySwapPromise(destroy_sequence_, satisfy_callback_));
layer_tree_host()->QueueSwapPromise(std::move(satisfy));
layer_tree_host()->GetSwapPromiseManager()->QueueSwapPromise(
std::move(satisfy));
destroy_sequence_ = SurfaceSequence();
}

Expand Down
6 changes: 3 additions & 3 deletions cc/layers/surface_layer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ TEST_F(SurfaceLayerTest, MultipleFramesOneSurface) {
base::Bind(&RequireCallback, &required_id, &required_seq)));
layer->SetSurfaceId(SurfaceId(kArbitraryClientId, 1, 0), 1.f,
gfx::Size(1, 1));
layer_tree_host_->SetSurfaceClientId(1);
layer_tree_host_->GetSurfaceSequenceGenerator()->set_surface_client_id(1);
layer_tree_->SetRootLayer(layer);

std::unique_ptr<FakeLayerTreeHost> layer_tree_host2 =
Expand All @@ -84,7 +84,7 @@ TEST_F(SurfaceLayerTest, MultipleFramesOneSurface) {
base::Bind(&RequireCallback, &required_id, &required_seq)));
layer2->SetSurfaceId(SurfaceId(kArbitraryClientId, 1, 0), 1.f,
gfx::Size(1, 1));
layer_tree_host2->SetSurfaceClientId(2);
layer_tree_host2->GetSurfaceSequenceGenerator()->set_surface_client_id(2);
layer_tree_host2->SetRootLayer(layer2);

// Layers haven't been removed, so no sequence should be satisfied.
Expand Down Expand Up @@ -126,7 +126,7 @@ class SurfaceLayerSwapPromise : public LayerTreeTest {
: commit_count_(0), sequence_was_satisfied_(false) {}

void BeginTest() override {
layer_tree_host()->SetSurfaceClientId(1);
layer_tree_host()->GetSurfaceSequenceGenerator()->set_surface_client_id(1);
layer_ = SurfaceLayer::Create(
base::Bind(&SatisfyCallback, &satisfied_sequence_),
base::Bind(&RequireCallback, &required_id_, &required_set_));
Expand Down
4 changes: 2 additions & 2 deletions cc/layers/ui_resource_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void UIResourceLayer::SetBitmap(const SkBitmap& skbitmap) {
bitmap_ = skbitmap;
if (GetLayerTree() && !bitmap_.empty()) {
ui_resource_holder_ = ScopedUIResourceHolder::Create(
GetLayerTree()->GetUIResourceManager(), bitmap_);
layer_tree_host()->GetUIResourceManager(), bitmap_);
} else {
ui_resource_holder_ = nullptr;
}
Expand Down Expand Up @@ -164,7 +164,7 @@ void UIResourceLayer::PushPropertiesTo(LayerImpl* layer) {
DCHECK(GetLayerTree());

gfx::Size image_size =
GetLayerTree()->GetUIResourceManager()->GetUIResourceSize(
layer_tree_host()->GetUIResourceManager()->GetUIResourceSize(
ui_resource_holder_->id());
layer_impl->SetUIResourceId(ui_resource_holder_->id());
layer_impl->SetImageBounds(image_size);
Expand Down
8 changes: 4 additions & 4 deletions cc/trees/latency_info_swap_promise_monitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

#include "base/threading/platform_thread.h"
#include "cc/output/latency_info_swap_promise.h"
#include "cc/trees/layer_tree_host.h"
#include "cc/trees/layer_tree_host_impl.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/swap_promise_manager.h"

namespace {

Expand Down Expand Up @@ -42,9 +42,9 @@ namespace cc {

LatencyInfoSwapPromiseMonitor::LatencyInfoSwapPromiseMonitor(
ui::LatencyInfo* latency,
LayerTreeHostInterface* layer_tree_host,
SwapPromiseManager* swap_promise_manager,
LayerTreeHostImpl* layer_tree_host_impl)
: SwapPromiseMonitor(layer_tree_host, layer_tree_host_impl),
: SwapPromiseMonitor(swap_promise_manager, layer_tree_host_impl),
latency_(latency) {}

LatencyInfoSwapPromiseMonitor::~LatencyInfoSwapPromiseMonitor() {
Expand All @@ -54,7 +54,7 @@ void LatencyInfoSwapPromiseMonitor::OnSetNeedsCommitOnMain() {
if (AddRenderingScheduledComponent(latency_, true /* on_main */)) {
std::unique_ptr<SwapPromise> swap_promise(
new LatencyInfoSwapPromise(*latency_));
layer_tree_host_->QueueSwapPromise(std::move(swap_promise));
swap_promise_manager_->QueueSwapPromise(std::move(swap_promise));
}
}

Expand Down
2 changes: 1 addition & 1 deletion cc/trees/latency_info_swap_promise_monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace cc {
class CC_EXPORT LatencyInfoSwapPromiseMonitor : public SwapPromiseMonitor {
public:
LatencyInfoSwapPromiseMonitor(ui::LatencyInfo* latency,
LayerTreeHostInterface* layer_tree_host,
SwapPromiseManager* swap_promise_manager,
LayerTreeHostImpl* layer_tree_host_impl);
~LatencyInfoSwapPromiseMonitor() override;

Expand Down
8 changes: 0 additions & 8 deletions cc/trees/layer_tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -720,12 +720,4 @@ void LayerTree::SetNeedsDisplayOnAllLayers() {
layer->SetNeedsDisplay();
}

UIResourceManager* LayerTree::GetUIResourceManager() const {
return layer_tree_host_->GetUIResourceManager();
}

const LayerTreeSettings& LayerTree::GetSettings() const {
return layer_tree_host_->GetSettings();
}

} // namespace cc
5 changes: 2 additions & 3 deletions cc/trees/layer_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class LayerTreeImpl;
class LayerTreeSettings;
struct PendingPageScaleAnimation;
class UIResourceManager;
class SwapPromiseManager;
class SurfaceSequenceGenerator;

class CC_EXPORT LayerTree : public MutatorHostClient {
public:
Expand Down Expand Up @@ -122,9 +124,6 @@ class CC_EXPORT LayerTree : public MutatorHostClient {

void SetNeedsDisplayOnAllLayers();

UIResourceManager* GetUIResourceManager() const;
const LayerTreeSettings& GetSettings() const;

// Methods which should only be used internally in cc ------------------
void RegisterLayer(Layer* layer);
void UnregisterLayer(Layer* layer);
Expand Down
93 changes: 26 additions & 67 deletions cc/trees/layer_tree_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#include "cc/trees/proxy_main.h"
#include "cc/trees/remote_channel_impl.h"
#include "cc/trees/single_thread_proxy.h"
#include "cc/trees/swap_promise_manager.h"
#include "cc/trees/tree_synchronizer.h"
#include "ui/gfx/geometry/size_conversions.h"
#include "ui/gfx/geometry/vector2d_conversions.h"
Expand Down Expand Up @@ -227,9 +228,7 @@ LayerTreeHost::LayerTreeHost(InitParams* params,
shared_bitmap_manager_(params->shared_bitmap_manager),
gpu_memory_buffer_manager_(params->gpu_memory_buffer_manager),
task_graph_runner_(params->task_graph_runner),
image_serialization_processor_(params->image_serialization_processor),
surface_client_id_(0u),
next_surface_sequence_(1u) {
image_serialization_processor_(params->image_serialization_processor) {
DCHECK(task_graph_runner_);
DCHECK(layer_tree_);

Expand Down Expand Up @@ -350,10 +349,6 @@ LayerTreeHost::~LayerTreeHost() {
// Clear any references into the LayerTreeHost.
layer_tree_.reset();

DCHECK(swap_promise_monitor_.empty());

BreakSwapPromises(SwapPromise::COMMIT_FAILS);

if (proxy_) {
DCHECK(task_runner_provider_->IsMainThread());
proxy_->Stop();
Expand Down Expand Up @@ -387,10 +382,27 @@ TaskRunnerProvider* LayerTreeHost::GetTaskRunnerProvider() const {
return task_runner_provider_.get();
}

SwapPromiseManager* LayerTreeHost::GetSwapPromiseManager() {
return &swap_promise_manager_;
}

const LayerTreeSettings& LayerTreeHost::GetSettings() const {
return settings_;
}

void LayerTreeHost::SetSurfaceClientId(uint32_t client_id) {
surface_sequence_generator_.set_surface_client_id(client_id);
}

void LayerTreeHost::QueueSwapPromise(
std::unique_ptr<SwapPromise> swap_promise) {
swap_promise_manager_.QueueSwapPromise(std::move(swap_promise));
}

SurfaceSequenceGenerator* LayerTreeHost::GetSurfaceSequenceGenerator() {
return &surface_sequence_generator_;
}

void LayerTreeHost::WillBeginMainFrame() {
devtools_instrumentation::WillBeginMainThreadFrame(GetId(),
SourceFrameNumber());
Expand Down Expand Up @@ -453,8 +465,7 @@ void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) {

layer_tree_->PushPropertiesTo(sync_tree);

sync_tree->PassSwapPromises(std::move(swap_promise_list_));
swap_promise_list_.clear();
sync_tree->PassSwapPromises(swap_promise_manager_.TakeSwapPromises());

host_impl->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_);
host_impl->SetContentIsSuitableForGpuRasterization(
Expand Down Expand Up @@ -499,7 +510,7 @@ void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) {
}

void LayerTreeHost::WillCommit() {
OnCommitForSwapPromises();
swap_promise_manager_.WillCommit();
client_->WillCommit();
}

Expand Down Expand Up @@ -590,18 +601,18 @@ void LayerTreeHost::SetDeferCommits(bool defer_commits) {
DISABLE_CFI_PERF
void LayerTreeHost::SetNeedsAnimate() {
proxy_->SetNeedsAnimate();
NotifySwapPromiseMonitorsOfSetNeedsCommit();
swap_promise_manager_.NotifySwapPromiseMonitorsOfSetNeedsCommit();
}

DISABLE_CFI_PERF
void LayerTreeHost::SetNeedsUpdateLayers() {
proxy_->SetNeedsUpdateLayers();
NotifySwapPromiseMonitorsOfSetNeedsCommit();
swap_promise_manager_.NotifySwapPromiseMonitorsOfSetNeedsCommit();
}

void LayerTreeHost::SetNeedsCommit() {
proxy_->SetNeedsCommit();
NotifySwapPromiseMonitorsOfSetNeedsCommit();
swap_promise_manager_.NotifySwapPromiseMonitorsOfSetNeedsCommit();
}

void LayerTreeHost::SetNeedsRedraw() {
Expand Down Expand Up @@ -876,7 +887,7 @@ void LayerTreeHost::ApplyScrollAndScale(ScrollAndScaleSet* info) {
TRACE_ID_DONT_MANGLE(swap_promise->TraceId()),
TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT,
"step", "Main thread scroll update");
QueueSwapPromise(std::move(swap_promise));
swap_promise_manager_.QueueSwapPromise(std::move(swap_promise));
}

if (layer_tree_->root_layer()) {
Expand Down Expand Up @@ -933,51 +944,6 @@ bool LayerTreeHost::SendMessageToMicroBenchmark(
return micro_benchmark_controller_.SendMessage(id, std::move(value));
}

void LayerTreeHost::InsertSwapPromiseMonitor(SwapPromiseMonitor* monitor) {
swap_promise_monitor_.insert(monitor);
}

void LayerTreeHost::RemoveSwapPromiseMonitor(SwapPromiseMonitor* monitor) {
swap_promise_monitor_.erase(monitor);
}

void LayerTreeHost::NotifySwapPromiseMonitorsOfSetNeedsCommit() {
std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin();
for (; it != swap_promise_monitor_.end(); it++)
(*it)->OnSetNeedsCommitOnMain();
}

void LayerTreeHost::QueueSwapPromise(
std::unique_ptr<SwapPromise> swap_promise) {
DCHECK(swap_promise);
swap_promise_list_.push_back(std::move(swap_promise));
}

void LayerTreeHost::BreakSwapPromises(SwapPromise::DidNotSwapReason reason) {
for (const auto& swap_promise : swap_promise_list_)
swap_promise->DidNotSwap(reason);
swap_promise_list_.clear();
}

std::vector<std::unique_ptr<SwapPromise>> LayerTreeHost::TakeSwapPromises() {
std::vector<std::unique_ptr<SwapPromise>> to_return;
to_return.swap(swap_promise_list_);
return to_return;
}

void LayerTreeHost::OnCommitForSwapPromises() {
for (const auto& swap_promise : swap_promise_list_)
swap_promise->OnCommit();
}

void LayerTreeHost::SetSurfaceClientId(uint32_t client_id) {
surface_client_id_ = client_id;
}

SurfaceSequence LayerTreeHost::CreateSurfaceSequence() {
return SurfaceSequence(surface_client_id_, next_surface_sequence_++);
}

void LayerTreeHost::SetLayerTreeMutator(
std::unique_ptr<LayerTreeMutator> mutator) {
proxy_->SetMutator(std::move(mutator));
Expand Down Expand Up @@ -1031,8 +997,7 @@ void LayerTreeHost::ToProtobufForCommit(
// LayerTreeHost.
// TODO(nyquist): Figure out how to support animations. See crbug.com/570376.
TRACE_EVENT0("cc.remote", "LayerTreeHost::ToProtobufForCommit");
swap_promises->swap(swap_promise_list_);
DCHECK(swap_promise_list_.empty());
*swap_promises = swap_promise_manager_.TakeSwapPromises();

proto->set_source_frame_number(source_frame_number_);

Expand All @@ -1056,9 +1021,6 @@ void LayerTreeHost::ToProtobufForCommit(
proto->set_id(id_);
proto->set_next_commit_forces_redraw(next_commit_forces_redraw_);

proto->set_surface_client_id(surface_client_id_);
proto->set_next_surface_sequence(next_surface_sequence_);

TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(
"cc.remote", "LayerTreeHostProto", source_frame_number_,
ComputeLayerTreeHostProtoSizeSplitAsValue(proto));
Expand Down Expand Up @@ -1089,9 +1051,6 @@ void LayerTreeHost::FromProtobufForCommit(const proto::LayerTreeHost& proto) {
proto.content_is_suitable_for_gpu_rasterization();
id_ = proto.id();
next_commit_forces_redraw_ = proto.next_commit_forces_redraw();

surface_client_id_ = proto.surface_client_id();
next_surface_sequence_ = proto.next_surface_sequence();
}

} // namespace cc
Loading

0 comments on commit 8297ae9

Please sign in to comment.