Commit 91841308 authored by vmpstr's avatar vmpstr Committed by Commit bot

cc: Re-enable GPU rasterization after content veto.

This patch periodically re-enables GPU rasterization after it is
disabled due to a content veto.

R=enne
CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_blink_rel

Review-Url: https://codereview.chromium.org/2108033004
Cr-Commit-Position: refs/heads/master@{#405295}
parent 547610b2
......@@ -448,7 +448,7 @@ TEST(PictureLayerTest, SuitableForGpuRasterization) {
EXPECT_TRUE(layer->IsSuitableForGpuRasterization());
// Veto gpu rasterization.
recording_source->SetUnsuitableForGpuRasterization();
recording_source->SetForceUnsuitableForGpuRasterization(true);
EXPECT_FALSE(recording_source->IsSuitableForGpuRasterization());
EXPECT_FALSE(layer->IsSuitableForGpuRasterization());
}
......
......@@ -119,8 +119,8 @@ class FakeRecordingSource : public RecordingSource {
client_.set_bounds(size_);
}
void SetUnsuitableForGpuRasterization() {
force_unsuitable_for_gpu_rasterization_ = true;
void SetForceUnsuitableForGpuRasterization(bool flag) {
force_unsuitable_for_gpu_rasterization_ = flag;
}
void SetPlaybackAllowedEvent(base::WaitableEvent* event) {
......
......@@ -1050,10 +1050,21 @@ bool LayerTreeHost::DoUpdateLayers(Layer* root_layer) {
base::AutoReset<bool> painting(&in_paint_layer_contents_, true);
bool did_paint_content = false;
bool content_is_suitable_for_gpu = true;
for (const auto& layer : update_layer_list) {
did_paint_content |= layer->Update();
content_is_suitable_for_gpu_rasterization_ &=
layer->IsSuitableForGpuRasterization();
content_is_suitable_for_gpu &= layer->IsSuitableForGpuRasterization();
}
if (content_is_suitable_for_gpu) {
++num_consecutive_frames_suitable_for_gpu_;
if (num_consecutive_frames_suitable_for_gpu_ >=
kNumFramesToConsiderBeforeGpuRasterization) {
content_is_suitable_for_gpu_rasterization_ = true;
}
} else {
num_consecutive_frames_suitable_for_gpu_ = 0;
content_is_suitable_for_gpu_rasterization_ = false;
}
return did_paint_content;
}
......
......@@ -474,6 +474,10 @@ class CC_EXPORT LayerTreeHost : public MutatorHostClient {
private:
friend class LayerTreeHostSerializationTest;
// This is the number of consecutive frames in which we want the content to be
// suitable for GPU rasterization before re-enabling it.
enum { kNumFramesToConsiderBeforeGpuRasterization = 60 };
void InitializeProxy(
std::unique_ptr<Proxy> proxy,
std::unique_ptr<BeginFrameSource> external_begin_frame_source);
......@@ -600,6 +604,7 @@ class CC_EXPORT LayerTreeHost : public MutatorHostClient {
uint32_t surface_client_id_;
uint32_t next_surface_sequence_;
uint32_t num_consecutive_frames_suitable_for_gpu_ = 0;
DISALLOW_COPY_AND_ASSIGN(LayerTreeHost);
};
......
......@@ -4968,7 +4968,7 @@ class LayerTreeHostTestGpuRasterizationEnabled : public LayerTreeHostTest {
EXPECT_TRUE(layer_tree_host()->has_gpu_rasterization_trigger());
// Content-based veto is relevant as well.
recording_source_->SetUnsuitableForGpuRasterization();
recording_source_->SetForceUnsuitableForGpuRasterization(true);
// Veto will take effect when layers are updated.
// The results will be verified after commit is completed below.
......@@ -5005,6 +5005,90 @@ class LayerTreeHostTestGpuRasterizationEnabled : public LayerTreeHostTest {
MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterizationEnabled);
class LayerTreeHostTestGpuRasterizationReenabled : public LayerTreeHostTest {
protected:
void InitializeSettings(LayerTreeSettings* settings) override {
EXPECT_FALSE(settings->gpu_rasterization_enabled);
settings->gpu_rasterization_enabled = true;
settings->wait_for_beginframe_interval = false;
settings->renderer_settings.disable_display_vsync = true;
}
void SetupTree() override {
LayerTreeHostTest::SetupTree();
std::unique_ptr<FakeRecordingSource> recording_source(
new FakeRecordingSource);
recording_source_ = recording_source.get();
scoped_refptr<FakePictureLayer> layer =
FakePictureLayer::CreateWithRecordingSource(
&layer_client_, std::move(recording_source));
layer_ = layer.get();
layer->SetBounds(gfx::Size(10, 10));
layer->SetIsDrawable(true);
layer_tree_host()->root_layer()->AddChild(layer);
layer_client_.set_bounds(layer_->bounds());
}
void BeginTest() override {
// Verify default value.
EXPECT_FALSE(layer_tree_host()->has_gpu_rasterization_trigger());
// Gpu rasterization trigger is relevant.
layer_tree_host()->SetHasGpuRasterizationTrigger(true);
EXPECT_TRUE(layer_tree_host()->has_gpu_rasterization_trigger());
// Content-based veto is relevant as well.
recording_source_->SetForceUnsuitableForGpuRasterization(true);
// Veto will take effect when layers are updated.
// The results will be verified after commit is completed below.
// Since we are manually marking the source as unsuitable,
// make sure that the layer gets a chance to update.
layer_->SetNeedsDisplay();
PostSetNeedsCommitToMainThread();
}
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
SCOPED_TRACE(base::StringPrintf("commit %d", num_commits_));
if (expected_gpu_enabled_) {
EXPECT_TRUE(host_impl->use_gpu_rasterization());
} else {
EXPECT_FALSE(host_impl->use_gpu_rasterization());
}
++num_commits_;
switch (num_commits_) {
case 1:
recording_source_->SetForceUnsuitableForGpuRasterization(false);
break;
case 30:
recording_source_->SetForceUnsuitableForGpuRasterization(true);
break;
case 31:
recording_source_->SetForceUnsuitableForGpuRasterization(false);
break;
case 90:
expected_gpu_enabled_ = true;
break;
}
PostSetNeedsCommitToMainThread();
if (num_commits_ > 100)
EndTest();
}
void AfterTest() override {}
FakeContentLayerClient layer_client_;
FakePictureLayer* layer_;
FakeRecordingSource* recording_source_;
int num_commits_ = 0;
bool expected_gpu_enabled_ = false;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterizationReenabled);
class LayerTreeHostTestGpuRasterizationForced : public LayerTreeHostTest {
protected:
void InitializeSettings(LayerTreeSettings* settings) override {
......@@ -5039,7 +5123,7 @@ class LayerTreeHostTestGpuRasterizationForced : public LayerTreeHostTest {
EXPECT_TRUE(layer_tree_host()->has_gpu_rasterization_trigger());
// Content-based veto is irrelevant as well.
recording_source_->SetUnsuitableForGpuRasterization();
recording_source_->SetForceUnsuitableForGpuRasterization(true);
// Veto will take effect when layers are updated.
// The results will be verified after commit is completed below.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment