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

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: android-build 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
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..b0b2d32f8b4fd78f4aea32b85d843dc85728f580 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"
@@ -2329,11 +2330,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 +2618,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 +2658,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 +2771,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 +2799,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 +2842,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 +2858,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 +4656,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 +4701,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 +5230,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 +5303,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 +6008,7 @@ class LayerTreeHostTestOneActivatePerPrepareTiles : public LayerTreeHostTest {
EndTestAfterDelayMs(100);
}
- void ScheduledActionPrepareTiles() override {
+ void WillPrepareTilesOnThread(LayerTreeHostImpl* impl) override {
++scheduled_prepare_tiles_count_;
}
@@ -6037,7 +6063,7 @@ class LayerTreeHostTestActivationCausesPrepareTiles : public LayerTreeHostTest {
EndTest();
}
- void ScheduledActionPrepareTiles() override {
+ void WillPrepareTilesOnThread(LayerTreeHostImpl* impl) override {
++scheduled_prepare_tiles_count_;
}

Powered by Google App Engine
This is Rietveld 408576698