Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1539)

Unified Diff: cc/trees/layer_tree_host_unittest.cc

Issue 2158973002: cc: Clean up LayerTreeTest and TestHooks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: proxy-impls: test Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/trees/layer_tree_host_impl_unittest.cc ('k') | cc/trees/layer_tree_host_unittest_animation.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/trees/layer_tree_host_unittest.cc
diff --git a/cc/trees/layer_tree_host_unittest.cc b/cc/trees/layer_tree_host_unittest.cc
index 711366c095ef51691e74f5b4efbb2e7b85670df6..1e3ac1b62b6925ea4bc467147d527db5a135619d 100644
--- a/cc/trees/layer_tree_host_unittest.cc
+++ b/cc/trees/layer_tree_host_unittest.cc
@@ -50,6 +50,7 @@
#include "cc/test/test_shared_bitmap_manager.h"
#include "cc/test/test_web_graphics_context_3d.h"
#include "cc/trees/effect_node.h"
+#include "cc/trees/layer_tree_host_common.h"
#include "cc/trees/layer_tree_host_impl.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/single_thread_proxy.h"
@@ -147,6 +148,7 @@ class LayerTreeHostTestFrameOrdering : public LayerTreeHostTest {
enum ImplOrder : int {
IMPL_START = 1,
+ IMPL_READY_TO_COMMIT,
IMPL_COMMIT,
IMPL_COMMIT_COMPLETE,
IMPL_ACTIVATE,
@@ -177,6 +179,10 @@ class LayerTreeHostTestFrameOrdering : public LayerTreeHostTest {
EXPECT_TRUE(CheckStep(MAIN_DID_BEGIN_FRAME, &main_));
}
+ void ReadyToCommitOnThread(LayerTreeHostImpl* impl) override {
+ EXPECT_TRUE(CheckStep(IMPL_READY_TO_COMMIT, &impl_));
+ }
+
void BeginCommitOnThread(LayerTreeHostImpl* impl) override {
EXPECT_TRUE(CheckStep(IMPL_COMMIT, &impl_));
}
@@ -2329,11 +2335,11 @@ class LayerTreeHostTestDeferCommits : public LayerTreeHostTest {
}
}
- void ScheduledActionSendBeginMainFrame() override {
+ void WillBeginMainFrame() override {
num_send_begin_main_frame_++;
switch (num_send_begin_main_frame_) {
case 1:
- PostSetDeferCommitsToMainThread(true);
+ layer_tree_host()->SetDeferCommits(true);
break;
case 2:
EndTest();
@@ -2617,6 +2623,38 @@ class LayerTreeHostTestAbortedCommitDoesntStall : public LayerTreeHostTest {
int commit_complete_count_;
};
+class OnDrawOutputSurface : public OutputSurface {
+ public:
+ explicit OnDrawOutputSurface(base::Closure invalidate_callback)
+ : OutputSurface(TestContextProvider::Create(),
+ TestContextProvider::CreateWorker(),
+ nullptr),
+ invalidate_callback_(std::move(invalidate_callback)) {
+ capabilities_.delegated_rendering = true;
+ }
+
+ // OutputSurface implementation.
+ void SwapBuffers(CompositorFrame frame) override { did_swap_ = true; }
+ uint32_t GetFramebufferCopyTextureFormat() override { return 0; }
+ void Invalidate() override { invalidate_callback_.Run(); }
+
+ void OnDraw(bool resourceless_software_draw) {
+ gfx::Transform identity;
+ gfx::Rect empty_rect;
+ // SwapBuffers happens inside of OnDraw.
+ client_->OnDraw(identity, empty_rect, empty_rect,
+ resourceless_software_draw);
+ if (did_swap_) {
+ did_swap_ = false;
+ client_->DidSwapBuffersComplete();
+ }
+ }
+
+ private:
+ bool did_swap_ = false;
+ base::Closure invalidate_callback_;
+};
+
class LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor
: public LayerTreeHostTestAbortedCommitDoesntStall {
protected:
@@ -2625,28 +2663,28 @@ class LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor
settings->using_synchronous_renderer_compositor = true;
}
- void ScheduledActionInvalidateOutputSurface() override {
- // Do not call ImplThreadTaskRunner after the test ended because of the
- // possibility of use-after-free due to a race.
- if (TestEnded())
- return;
- ImplThreadTaskRunner()->PostTask(
- FROM_HERE,
- base::Bind(
- &LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor::
- CallOnDraw,
- base::Unretained(this)));
+ std::unique_ptr<OutputSurface> CreateOutputSurface() override {
+ auto output_surface = base::MakeUnique<OnDrawOutputSurface>(base::Bind(
+ &LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor::
+ CallOnDraw,
+ base::Unretained(this)));
+ output_surface_ = output_surface.get();
+ return std::move(output_surface);
}
void CallOnDraw() {
- // Synchronous compositor does not draw unless told to do so by the output
- // surface.
- gfx::Transform identity;
- gfx::Rect empty_rect;
- bool resourceless_software_draw = false;
- fake_output_surface()->client()->OnDraw(identity, empty_rect, empty_rect,
- resourceless_software_draw);
+ if (!TestEnded()) {
+ // Synchronous compositor does not draw unless told to do so by the output
+ // surface. But it needs to be done on a new stack frame.
+ bool resourceless_software_draw = false;
+ ImplThreadTaskRunner()->PostTask(
+ FROM_HERE, base::Bind(&OnDrawOutputSurface::OnDraw,
+ base::Unretained(output_surface_),
+ resourceless_software_draw));
+ }
}
+
+ OnDrawOutputSurface* output_surface_ = nullptr;
};
MULTI_THREAD_TEST_F(
@@ -2738,7 +2776,7 @@ class LayerTreeHostTestNumFramesPending : public LayerTreeHostTest {
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNumFramesPending);
class LayerTreeHostTestResourcelessSoftwareDraw : public LayerTreeHostTest {
- public:
+ protected:
void InitializeSettings(LayerTreeSettings* settings) override {
settings->using_synchronous_renderer_compositor = true;
}
@@ -2766,36 +2804,27 @@ class LayerTreeHostTestResourcelessSoftwareDraw : public LayerTreeHostTest {
}
std::unique_ptr<OutputSurface> CreateOutputSurface() override {
- auto output_surface = delegating_renderer()
- ? FakeOutputSurface::CreateDelegatingSoftware(
- base::WrapUnique(new SoftwareOutputDevice))
- : FakeOutputSurface::CreateSoftware(
- base::WrapUnique(new SoftwareOutputDevice));
- software_output_surface_ = output_surface.get();
+ auto output_surface = base::MakeUnique<OnDrawOutputSurface>(
+ base::Bind(&LayerTreeHostTestResourcelessSoftwareDraw::CallOnDraw,
+ base::Unretained(this)));
+ output_surface_ = output_surface.get();
return std::move(output_surface);
}
void BeginTest() override {
PostSetNeedsCommitToMainThread();
- swap_count_ = 0;
- }
-
- void ScheduledActionInvalidateOutputSurface() override {
- if (TestEnded())
- return;
-
- ImplThreadTaskRunner()->PostTask(
- FROM_HERE,
- base::Bind(&LayerTreeHostTestResourcelessSoftwareDraw::CallOnDraw,
- base::Unretained(this)));
}
void CallOnDraw() {
- gfx::Transform identity;
- gfx::Rect empty_rect;
- bool resourceless_software_draw = true;
- software_output_surface_->client()->OnDraw(identity, empty_rect, empty_rect,
- resourceless_software_draw);
+ if (!TestEnded()) {
+ // Synchronous compositor does not draw unless told to do so by the output
+ // surface. But it needs to be done on a new stack frame.
+ bool resourceless_software_draw = true;
+ ImplThreadTaskRunner()->PostTask(
+ FROM_HERE, base::Bind(&OnDrawOutputSurface::OnDraw,
+ base::Unretained(output_surface_),
+ resourceless_software_draw));
+ }
}
DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
@@ -2818,8 +2847,8 @@ class LayerTreeHostTestResourcelessSoftwareDraw : public LayerTreeHostTest {
}
void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
- swap_count_++;
- switch (swap_count_) {
+ draw_count_++;
+ switch (draw_count_) {
case 1:
host_impl->SetNeedsRedraw();
break;
@@ -2834,12 +2863,12 @@ class LayerTreeHostTestResourcelessSoftwareDraw : public LayerTreeHostTest {
void AfterTest() override {}
private:
- FakeOutputSurface* software_output_surface_ = nullptr;
+ OnDrawOutputSurface* output_surface_ = nullptr;
FakeContentLayerClient client_;
scoped_refptr<Layer> root_layer_;
scoped_refptr<Layer> parent_layer_;
scoped_refptr<Layer> child_layer_;
- int swap_count_;
+ int draw_count_ = 0;
};
// Resourceless is not used for SingleThreadProxy, so it is unimplemented.
@@ -4632,7 +4661,8 @@ class LayerTreeHostTestBreakSwapPromiseForVisibility
layer_tree_host()->QueueSwapPromise(std::move(swap_promise));
}
- void ScheduledActionWillSendBeginMainFrame() override {
+ void WillBeginImplFrameOnThread(LayerTreeHostImpl* impl,
+ const BeginFrameArgs& args) override {
MainThreadTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&LayerTreeHostTestBreakSwapPromiseForVisibility
@@ -4676,7 +4706,8 @@ class LayerTreeHostTestBreakSwapPromiseForContext : public LayerTreeHostTest {
layer_tree_host()->QueueSwapPromise(std::move(swap_promise));
}
- void ScheduledActionWillSendBeginMainFrame() override {
+ void WillBeginImplFrameOnThread(LayerTreeHostImpl* impl,
+ const BeginFrameArgs& args) override {
if (output_surface_lost_triggered_)
return;
output_surface_lost_triggered_ = true;
@@ -5204,7 +5235,7 @@ class LayerTreeHostTestWillBeginImplFrameHasDidFinishImplFrame
PostSetNeedsCommitToMainThread();
}
- void SendBeginMainFrameNotExpectedSoon() override { EndTest(); }
+ void BeginMainFrameNotExpectedSoon() override { EndTest(); }
void AfterTest() override {
EXPECT_GT(will_begin_impl_frame_count_, 0);
@@ -5277,7 +5308,7 @@ class LayerTreeHostTestBeginMainFrameTimeIsAlsoImplTime
EXPECT_PRED_FORMAT2(AssertFrameTimeContained, impl_frame_args_, args);
}
- void SendBeginMainFrameNotExpectedSoon() override { EndTest(); }
+ void BeginMainFrameNotExpectedSoon() override { EndTest(); }
void AfterTest() override {
EXPECT_GT(impl_frame_args_.size(), 0U);
@@ -5982,7 +6013,7 @@ class LayerTreeHostTestOneActivatePerPrepareTiles : public LayerTreeHostTest {
EndTestAfterDelayMs(100);
}
- void ScheduledActionPrepareTiles() override {
+ void WillPrepareTilesOnThread(LayerTreeHostImpl* impl) override {
++scheduled_prepare_tiles_count_;
}
@@ -6037,7 +6068,7 @@ class LayerTreeHostTestActivationCausesPrepareTiles : public LayerTreeHostTest {
EndTest();
}
- void ScheduledActionPrepareTiles() override {
+ void WillPrepareTilesOnThread(LayerTreeHostImpl* impl) override {
++scheduled_prepare_tiles_count_;
}
@@ -6692,71 +6723,6 @@ class LayerTreeTestPageScaleFlags : public LayerTreeTest {
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeTestPageScaleFlags);
-class LayerTreeHostScrollingAndScalingUpdatesLayers : public LayerTreeHostTest {
- public:
- LayerTreeHostScrollingAndScalingUpdatesLayers()
- : requested_update_layers_(false), commit_count_(0) {}
-
- void SetupTree() override {
- LayerTreeHostTest::SetupTree();
- Layer* root_layer = layer_tree_host()->root_layer();
- scoped_refptr<Layer> scroll_layer = Layer::Create();
- CreateVirtualViewportLayers(root_layer, scroll_layer, root_layer->bounds(),
- root_layer->bounds(), layer_tree_host());
- }
-
- void BeginTest() override {
- LayerTreeHostCommon::ScrollUpdateInfo scroll;
- scroll.layer_id = layer_tree_host()->root_layer()->id();
- scroll.scroll_delta = gfx::Vector2d(0, 33);
- scroll_info_.scrolls.push_back(scroll);
-
- scale_info_.page_scale_delta = 2.71f;
-
- PostSetNeedsCommitToMainThread();
- }
-
- void BeginMainFrame(const BeginFrameArgs& args) override {
- switch (commit_count_) {
- case 0:
- requested_update_layers_ = false;
- layer_tree_host()->ApplyScrollAndScale(&no_op_info_);
- EXPECT_FALSE(requested_update_layers_);
- break;
- case 1:
- requested_update_layers_ = false;
- layer_tree_host()->ApplyScrollAndScale(&scale_info_);
- EXPECT_TRUE(requested_update_layers_);
- break;
- case 2:
- requested_update_layers_ = false;
- layer_tree_host()->ApplyScrollAndScale(&scroll_info_);
- EXPECT_TRUE(requested_update_layers_);
- EndTest();
- break;
- default:
- NOTREACHED();
- }
- }
-
- void DidSetNeedsUpdateLayers() override { requested_update_layers_ = true; }
-
- void DidCommit() override {
- if (++commit_count_ < 3)
- PostSetNeedsCommitToMainThread();
- }
-
- void AfterTest() override {}
-
- ScrollAndScaleSet scroll_info_;
- ScrollAndScaleSet scale_info_;
- ScrollAndScaleSet no_op_info_;
- bool requested_update_layers_;
- int commit_count_;
-};
-
-MULTI_THREAD_TEST_F(LayerTreeHostScrollingAndScalingUpdatesLayers);
-
class LayerTreeHostTestDestroyWhileInitializingOutputSurface
: public LayerTreeHostTest {
protected:
« no previous file with comments | « cc/trees/layer_tree_host_impl_unittest.cc ('k') | cc/trees/layer_tree_host_unittest_animation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698