summaryrefslogtreecommitdiffstats
path: root/cc/trees/layer_tree_host_unittest_context.cc
diff options
context:
space:
mode:
Diffstat (limited to 'cc/trees/layer_tree_host_unittest_context.cc')
-rw-r--r--cc/trees/layer_tree_host_unittest_context.cc225
1 files changed, 181 insertions, 44 deletions
diff --git a/cc/trees/layer_tree_host_unittest_context.cc b/cc/trees/layer_tree_host_unittest_context.cc
index 20f5114..1658dea 100644
--- a/cc/trees/layer_tree_host_unittest_context.cc
+++ b/cc/trees/layer_tree_host_unittest_context.cc
@@ -5,6 +5,7 @@
#include "cc/trees/layer_tree_host.h"
#include "base/basictypes.h"
+#include "cc/base/thread_impl.h"
#include "cc/layers/content_layer.h"
#include "cc/layers/heads_up_display_layer.h"
#include "cc/layers/io_surface_layer.h"
@@ -20,6 +21,7 @@
#include "cc/test/fake_context_provider.h"
#include "cc/test/fake_delegated_renderer_layer.h"
#include "cc/test/fake_delegated_renderer_layer_impl.h"
+#include "cc/test/fake_layer_tree_host_client.h"
#include "cc/test/fake_output_surface.h"
#include "cc/test/fake_scrollbar_layer.h"
#include "cc/test/fake_scrollbar_theme_painter.h"
@@ -58,10 +60,11 @@ class LayerTreeHostContextTest : public LayerTreeTest {
times_to_lose_on_recreate_(0),
times_to_fail_create_offscreen_(0),
times_to_fail_recreate_offscreen_(0),
- times_to_expect_recreate_retried_(0),
- times_recreate_retried_(0),
+ times_to_expect_create_failed_(0),
+ times_create_failed_(0),
times_offscreen_created_(0),
- committed_at_least_once_(false) {
+ committed_at_least_once_(false),
+ context_should_support_io_surface_(false) {
media::InitializeMediaLibraryForTesting();
}
@@ -78,24 +81,29 @@ class LayerTreeHostContextTest : public LayerTreeTest {
virtual scoped_ptr<OutputSurface> CreateOutputSurface() OVERRIDE {
if (times_to_fail_create_) {
--times_to_fail_create_;
- ExpectRecreateToRetry();
+ ExpectCreateToFail();
return scoped_ptr<OutputSurface>();
}
scoped_ptr<TestWebGraphicsContext3D> context3d = CreateContext3d();
context3d_ = context3d.get();
+ if (context_should_support_io_surface_) {
+ context3d_->set_have_extension_io_surface(true);
+ context3d_->set_have_extension_egl_image(true);
+ }
+
if (times_to_fail_initialize_) {
--times_to_fail_initialize_;
// Make the context get lost during reinitialization.
// The number of times MakeCurrent succeeds is not important, and
// can be changed if needed to make this pass with future changes.
context3d_->set_times_make_current_succeeds(2);
- ExpectRecreateToRetry();
+ ExpectCreateToFail();
} else if (times_to_lose_on_create_) {
--times_to_lose_on_create_;
LoseContext();
- ExpectRecreateToRetry();
+ ExpectCreateToFail();
}
return FakeOutputSurface::Create3d(
@@ -110,7 +118,7 @@ class LayerTreeHostContextTest : public LayerTreeTest {
if (times_to_fail_create_offscreen_) {
--times_to_fail_create_offscreen_;
- ExpectRecreateToRetry();
+ ExpectCreateToFail();
return scoped_ptr<TestWebGraphicsContext3D>();
}
@@ -153,10 +161,8 @@ class LayerTreeHostContextTest : public LayerTreeTest {
virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
LayerTreeHostImpl::FrameData* frame,
- bool result)
- OVERRIDE {
- bool expect_success = !frame->has_no_damage;
- EXPECT_EQ(expect_success, result);
+ bool result) OVERRIDE {
+ EXPECT_TRUE(result);
if (!times_to_lose_during_draw_)
return result;
@@ -193,18 +199,17 @@ class LayerTreeHostContextTest : public LayerTreeTest {
times_to_fail_recreate_offscreen_ = 0;
}
- virtual void WillRetryRecreateOutputSurface() OVERRIDE {
- ++times_recreate_retried_;
+ virtual void DidFailToInitializeOutputSurface() OVERRIDE {
+ ++times_create_failed_;
}
virtual void TearDown() OVERRIDE {
LayerTreeTest::TearDown();
- EXPECT_EQ(times_to_expect_recreate_retried_, times_recreate_retried_);
+ EXPECT_EQ(times_to_expect_create_failed_, times_create_failed_);
}
- void ExpectRecreateToRetry() {
- if (committed_at_least_once_)
- ++times_to_expect_recreate_retried_;
+ void ExpectCreateToFail() {
+ ++times_to_expect_create_failed_;
}
protected:
@@ -219,10 +224,11 @@ class LayerTreeHostContextTest : public LayerTreeTest {
int times_to_lose_on_recreate_;
int times_to_fail_create_offscreen_;
int times_to_fail_recreate_offscreen_;
- int times_to_expect_recreate_retried_;
- int times_recreate_retried_;
+ int times_to_expect_create_failed_;
+ int times_create_failed_;
int times_offscreen_created_;
bool committed_at_least_once_;
+ bool context_should_support_io_surface_;
scoped_refptr<FakeContextProvider> offscreen_contexts_main_thread_;
scoped_refptr<FakeContextProvider> offscreen_contexts_compositor_thread_;
@@ -235,7 +241,8 @@ class LayerTreeHostContextTestLostContextSucceeds
: LayerTreeHostContextTest(),
test_case_(0),
num_losses_(0),
- recovered_context_(true) {}
+ recovered_context_(true),
+ first_initialized_(false) {}
virtual void BeginTest() OVERRIDE {
PostSetNeedsCommitToMainThread();
@@ -243,7 +250,12 @@ class LayerTreeHostContextTestLostContextSucceeds
virtual void DidRecreateOutputSurface(bool succeeded) OVERRIDE {
EXPECT_TRUE(succeeded);
- ++num_losses_;
+
+ if (first_initialized_)
+ ++num_losses_;
+ else
+ first_initialized_ = true;
+
recovered_context_ = true;
}
@@ -381,6 +393,7 @@ class LayerTreeHostContextTestLostContextSucceeds
size_t test_case_;
int num_losses_;
bool recovered_context_;
+ bool first_initialized_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLostContextSucceeds);
@@ -524,6 +537,9 @@ class LayerTreeHostContextTestOffscreenContextFails
cc::ContextProvider* contexts =
host_impl->resource_provider()->offscreen_context_provider();
EXPECT_FALSE(contexts);
+
+ // This did not lead to create failure.
+ times_to_expect_create_failed_ = 0;
EndTest();
}
@@ -542,7 +558,8 @@ class LayerTreeHostContextTestLostContextFails
public:
LayerTreeHostContextTestLostContextFails()
: LayerTreeHostContextTest(),
- num_commits_(0) {
+ num_commits_(0),
+ first_initialized_(false) {
times_to_lose_during_commit_ = 1;
}
@@ -551,8 +568,12 @@ class LayerTreeHostContextTestLostContextFails
}
virtual void DidRecreateOutputSurface(bool succeeded) OVERRIDE {
- EXPECT_FALSE(succeeded);
- EndTest();
+ if (first_initialized_) {
+ EXPECT_FALSE(succeeded);
+ EndTest();
+ } else {
+ first_initialized_ = true;
+ }
}
virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
@@ -577,6 +598,7 @@ class LayerTreeHostContextTestLostContextFails
private:
int num_commits_;
+ bool first_initialized_;
};
TEST_F(LayerTreeHostContextTestLostContextFails,
@@ -632,18 +654,26 @@ class LayerTreeHostContextTestFinishAllRenderingAfterLoss
public:
virtual void BeginTest() OVERRIDE {
// Lose the context until the compositor gives up on it.
+ first_initialized_ = false;
times_to_lose_during_commit_ = 1;
times_to_fail_reinitialize_ = 10;
PostSetNeedsCommitToMainThread();
}
virtual void DidRecreateOutputSurface(bool succeeded) OVERRIDE {
- EXPECT_FALSE(succeeded);
- layer_tree_host()->FinishAllRendering();
- EndTest();
+ if (first_initialized_) {
+ EXPECT_FALSE(succeeded);
+ layer_tree_host()->FinishAllRendering();
+ EndTest();
+ } else {
+ first_initialized_ = true;
+ }
}
virtual void AfterTest() OVERRIDE {}
+
+ private:
+ bool first_initialized_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(
@@ -890,9 +920,6 @@ class LayerTreeHostContextTestDontUseLostResources
: public LayerTreeHostContextTest {
public:
virtual void SetupTree() OVERRIDE {
- context3d_->set_have_extension_io_surface(true);
- context3d_->set_have_extension_egl_image(true);
-
scoped_refptr<Layer> root_ = Layer::Create();
root_->SetBounds(gfx::Size(10, 10));
root_->SetAnchorPoint(gfx::PointF());
@@ -982,6 +1009,7 @@ class LayerTreeHostContextTestDontUseLostResources
}
virtual void BeginTest() OVERRIDE {
+ context_should_support_io_surface_ = true;
PostSetNeedsCommitToMainThread();
}
@@ -1101,13 +1129,13 @@ class LayerTreeHostContextTestDontUseLostResources
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestDontUseLostResources);
-class LayerTreeHostContextTestFailsImmediately
+class LayerTreeHostContextTestLosesFirstOutputSurface
: public LayerTreeHostContextTest {
public:
- LayerTreeHostContextTestFailsImmediately()
- : LayerTreeHostContextTest() {}
-
- virtual ~LayerTreeHostContextTestFailsImmediately() {}
+ LayerTreeHostContextTestLosesFirstOutputSurface() {
+ // Always fail. This needs to be set before LayerTreeHost is created.
+ times_to_lose_on_create_ = 1000;
+ }
virtual void BeginTest() OVERRIDE {
PostSetNeedsCommitToMainThread();
@@ -1115,22 +1143,98 @@ class LayerTreeHostContextTestFailsImmediately
virtual void AfterTest() OVERRIDE {}
- virtual scoped_ptr<TestWebGraphicsContext3D> CreateContext3d() OVERRIDE {
- scoped_ptr<TestWebGraphicsContext3D> context =
- LayerTreeHostContextTest::CreateContext3d();
- context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
- GL_INNOCENT_CONTEXT_RESET_ARB);
- return context.Pass();
- }
-
virtual void DidRecreateOutputSurface(bool succeeded) OVERRIDE {
EXPECT_FALSE(succeeded);
+
// If we make it this far without crashing, we pass!
EndTest();
}
+
+ virtual void DidCommitAndDrawFrame() OVERRIDE {
+ EXPECT_TRUE(false);
+ }
};
-SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestFailsImmediately);
+SINGLE_AND_MULTI_THREAD_TEST_F(
+ LayerTreeHostContextTestLosesFirstOutputSurface);
+
+class LayerTreeHostContextTestRetriesFirstInitializationAndSucceeds
+ : public LayerTreeHostContextTest {
+ public:
+ virtual void AfterTest() OVERRIDE {}
+
+ virtual void BeginTest() OVERRIDE {
+ times_to_fail_initialize_ = 2;
+ PostSetNeedsCommitToMainThread();
+ }
+
+ virtual void DidCommitAndDrawFrame() OVERRIDE {
+ EndTest();
+ }
+};
+
+SINGLE_AND_MULTI_THREAD_TEST_F(
+ LayerTreeHostContextTestRetriesFirstInitializationAndSucceeds);
+
+class LayerTreeHostContextTestRetryWorksWithForcedInit
+ : public LayerTreeHostContextTestRetriesFirstInitializationAndSucceeds {
+ public:
+ virtual void DidFailToInitializeOutputSurface() OVERRIDE {
+ LayerTreeHostContextTestRetriesFirstInitializationAndSucceeds
+ ::DidFailToInitializeOutputSurface();
+
+ if (times_create_failed_ == 1) {
+ // CompositeAndReadback force recreates the output surface, which should
+ // fail.
+ char pixels[4];
+ EXPECT_FALSE(layer_tree_host()->CompositeAndReadback(
+ &pixels, gfx::Rect(1, 1)));
+ }
+ }
+};
+
+SINGLE_AND_MULTI_THREAD_TEST_F(
+ LayerTreeHostContextTestRetryWorksWithForcedInit);
+
+class LayerTreeHostContextTestCompositeAndReadbackBeforeOutputSurfaceInit
+ : public LayerTreeHostContextTest {
+ public:
+ virtual void BeginTest() OVERRIDE {
+ // This must be called immediately after creating LTH, before the first
+ // OutputSurface is initialized.
+ ASSERT_TRUE(layer_tree_host()->output_surface_lost());
+
+ times_output_surface_created_ = 0;
+
+ char pixels[4];
+ EXPECT_TRUE(layer_tree_host()->CompositeAndReadback(
+ &pixels, gfx::Rect(1, 1)));
+ EXPECT_EQ(1, times_output_surface_created_);
+
+ PostSetNeedsCommitToMainThread();
+ }
+
+ virtual void DidRecreateOutputSurface(bool succeeded) OVERRIDE {
+ EXPECT_TRUE(succeeded);
+ ++times_output_surface_created_;
+ }
+
+ virtual void DidCommitAndDrawFrame() OVERRIDE {
+ EndTest();
+ }
+
+ virtual void AfterTest() OVERRIDE {
+ // Should not try to create output surface again after successfully
+ // created by CompositeAndReadback.
+ EXPECT_EQ(1, times_output_surface_created_);
+ }
+
+ private:
+ int times_output_surface_created_;
+};
+
+SINGLE_AND_MULTI_THREAD_TEST_F(
+ LayerTreeHostContextTestCompositeAndReadbackBeforeOutputSurfaceInit);
class ImplSidePaintingLayerTreeHostContextTest
: public LayerTreeHostContextTest {
@@ -1261,5 +1365,38 @@ class LayerTreeHostContextTestFailsToCreateSurface
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestFailsToCreateSurface);
+// Not reusing LayerTreeTest because it expects creating LTH to always succeed.
+class LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface
+ : public testing::Test,
+ public FakeLayerTreeHostClient {
+ public:
+ LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface()
+ : FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D) {}
+
+ // FakeLayerTreeHostClient
+ virtual scoped_ptr<OutputSurface> CreateOutputSurface() {
+ return scoped_ptr<OutputSurface>();
+ }
+
+ void RunTest(bool threaded) {
+ scoped_ptr<base::Thread> impl_thread;
+ scoped_ptr<cc::Thread> impl_ccthread(NULL);
+ if (threaded) {
+ impl_thread.reset(new base::Thread("LayerTreeTest"));
+ impl_ccthread = cc::ThreadImpl::CreateForDifferentThread(
+ impl_thread->message_loop_proxy());
+ ASSERT_TRUE(impl_ccthread);
+ }
+
+ LayerTreeSettings settings;
+ scoped_ptr<LayerTreeHost> layer_tree_host =
+ LayerTreeHost::Create(this, settings, impl_ccthread.Pass());
+ EXPECT_FALSE(layer_tree_host);
+ }
+};
+
+SINGLE_AND_MULTI_THREAD_TEST_F(
+ LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface);
+
} // namespace
} // namespace cc