Index: cc/layer_tree_host_unittest_context.cc |
diff --git a/cc/layer_tree_host_unittest_context.cc b/cc/layer_tree_host_unittest_context.cc |
index 41ebbfd91af832210713d9005afd40b9c5e125b1..0147ca9074bd7b396bc57f3c8d7de6dc700205b3 100644 |
--- a/cc/layer_tree_host_unittest_context.cc |
+++ b/cc/layer_tree_host_unittest_context.cc |
@@ -19,6 +19,7 @@ |
#include "cc/test/fake_content_layer.h" |
#include "cc/test/fake_content_layer_client.h" |
#include "cc/test/fake_content_layer_impl.h" |
+#include "cc/test/fake_context_provider.h" |
#include "cc/test/fake_output_surface.h" |
#include "cc/test/fake_scrollbar_layer.h" |
#include "cc/test/fake_scrollbar_theme_painter.h" |
@@ -33,6 +34,7 @@ |
#include "cc/video_layer_impl.h" |
#include "gpu/GLES2/gl2extchromium.h" |
#include "media/base/media.h" |
+#include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperations.h" |
using media::VideoFrame; |
using WebKit::WebGraphicsContext3D; |
@@ -53,7 +55,13 @@ class LayerTreeHostContextTest : public ThreadedTest { |
times_to_lose_during_draw_(0), |
times_to_fail_recreate_(0), |
times_to_fail_reinitialize_(0), |
- times_to_lose_on_recreate_(0) { |
+ 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_offscreen_created_(0), |
+ committed_at_least_once_(false) { |
media::InitializeMediaLibraryForTesting(); |
} |
@@ -70,6 +78,7 @@ class LayerTreeHostContextTest : public ThreadedTest { |
virtual scoped_ptr<OutputSurface> createOutputSurface() OVERRIDE { |
if (times_to_fail_create_) { |
--times_to_fail_create_; |
+ ExpectRecreateToRetry(); |
return scoped_ptr<OutputSurface>(); |
} |
@@ -82,29 +91,88 @@ class LayerTreeHostContextTest : public ThreadedTest { |
// 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(); |
} else if (times_to_lose_on_create_) { |
--times_to_lose_on_create_; |
LoseContext(); |
+ ExpectRecreateToRetry(); |
} |
return FakeOutputSurface::Create3d( |
context3d.PassAs<WebGraphicsContext3D>()).PassAs<OutputSurface>(); |
} |
- virtual bool prepareToDrawOnThread( |
- LayerTreeHostImpl*, LayerTreeHostImpl::FrameData&, bool result) |
- OVERRIDE { |
- EXPECT_TRUE(result); |
- if (!times_to_lose_during_draw_) |
- return result; |
+ scoped_ptr<TestWebGraphicsContext3D> CreateOffscreenContext3d() { |
+ if (!context3d_) |
+ return scoped_ptr<TestWebGraphicsContext3D>(); |
- --times_to_lose_during_draw_; |
- if (context3d_) |
- context3d_->set_times_make_current_succeeds(0); |
- return result; |
+ ++times_offscreen_created_; |
+ |
+ if (times_to_fail_create_offscreen_) { |
+ --times_to_fail_create_offscreen_; |
+ ExpectRecreateToRetry(); |
+ return scoped_ptr<TestWebGraphicsContext3D>(); |
+ } |
+ |
+ scoped_ptr<TestWebGraphicsContext3D> offscreen_context3d = |
+ TestWebGraphicsContext3D::Create().Pass(); |
+ DCHECK(offscreen_context3d); |
+ context3d_->add_share_group_context(offscreen_context3d.get()); |
+ |
+ return offscreen_context3d.Pass(); |
+ } |
+ |
+ virtual scoped_refptr<cc::ContextProvider> |
+ OffscreenContextProviderForMainThread() OVERRIDE { |
+ DCHECK(!implThread()); |
+ |
+ if (!offscreen_contexts_main_thread_ || |
+ offscreen_contexts_main_thread_->DestroyedOnMainThread()) { |
+ offscreen_contexts_main_thread_ = new FakeContextProvider( |
+ base::Bind(&LayerTreeHostContextTest::CreateOffscreenContext3d, |
+ base::Unretained(this))); |
+ } |
+ return offscreen_contexts_main_thread_; |
+ } |
+ |
+ virtual scoped_refptr<cc::ContextProvider> |
+ OffscreenContextProviderForCompositorThread() OVERRIDE { |
+ DCHECK(implThread()); |
+ |
+ if (!offscreen_contexts_compositor_thread_ || |
+ offscreen_contexts_compositor_thread_->DestroyedOnMainThread()) { |
+ offscreen_contexts_compositor_thread_ = new FakeContextProvider( |
+ base::Bind(&LayerTreeHostContextTest::CreateOffscreenContext3d, |
+ base::Unretained(this))); |
} |
+ return offscreen_contexts_compositor_thread_; |
+ } |
+ |
+ virtual bool prepareToDrawOnThread( |
+ LayerTreeHostImpl*, LayerTreeHostImpl::FrameData&, bool result) |
+ OVERRIDE { |
+ EXPECT_TRUE(result); |
+ if (!times_to_lose_during_draw_) |
+ return result; |
+ |
+ --times_to_lose_during_draw_; |
+ context3d_->set_times_make_current_succeeds(0); |
+ |
+ times_to_fail_create_ = times_to_fail_recreate_; |
+ times_to_fail_recreate_ = 0; |
+ times_to_fail_initialize_ = times_to_fail_reinitialize_; |
+ times_to_fail_reinitialize_ = 0; |
+ times_to_lose_on_create_ = times_to_lose_on_recreate_; |
+ times_to_lose_on_recreate_ = 0; |
+ times_to_fail_create_offscreen_ = times_to_fail_recreate_offscreen_; |
+ times_to_fail_recreate_offscreen_ = 0; |
+ |
+ return result; |
+ } |
virtual void commitCompleteOnThread(LayerTreeHostImpl *host_impl) OVERRIDE { |
+ committed_at_least_once_ = true; |
+ |
if (!times_to_lose_during_commit_) |
return; |
--times_to_lose_during_commit_; |
@@ -116,6 +184,22 @@ class LayerTreeHostContextTest : public ThreadedTest { |
times_to_fail_reinitialize_ = 0; |
times_to_lose_on_create_ = times_to_lose_on_recreate_; |
times_to_lose_on_recreate_ = 0; |
+ times_to_fail_create_offscreen_ = times_to_fail_recreate_offscreen_; |
+ times_to_fail_recreate_offscreen_ = 0; |
+ } |
+ |
+ virtual void willRetryRecreateOutputSurface() OVERRIDE { |
+ ++times_recreate_retried_; |
+ } |
+ |
+ virtual void TearDown() OVERRIDE { |
+ ThreadedTest::TearDown(); |
+ EXPECT_EQ(times_to_expect_recreate_retried_, times_recreate_retried_); |
+ } |
+ |
+ void ExpectRecreateToRetry() { |
+ if (committed_at_least_once_) |
+ ++times_to_expect_recreate_retried_; |
} |
protected: |
@@ -128,6 +212,15 @@ class LayerTreeHostContextTest : public ThreadedTest { |
int times_to_fail_reinitialize_; |
int times_to_fail_recreate_; |
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_offscreen_created_; |
+ bool committed_at_least_once_; |
+ |
+ scoped_refptr<FakeContextProvider> offscreen_contexts_main_thread_; |
+ scoped_refptr<FakeContextProvider> offscreen_contexts_compositor_thread_; |
}; |
class LayerTreeHostContextTestLostContextSucceeds : |
@@ -151,8 +244,8 @@ class LayerTreeHostContextTestLostContextSucceeds : |
} |
virtual void afterTest() OVERRIDE { |
- EXPECT_EQ(8, test_case_); |
- EXPECT_EQ(6 + 10 + 10, num_losses_); |
+ EXPECT_EQ(10, test_case_); |
+ EXPECT_EQ(8 + 10 + 10, num_losses_); |
} |
virtual void didCommitAndDrawFrame() OVERRIDE { |
@@ -185,36 +278,56 @@ class LayerTreeHostContextTestLostContextSucceeds : |
3, // times_to_fail_reinitialize |
0, // times_to_fail_recreate |
0, // times_to_lose_on_recreate |
+ 0, // times_to_fail_recreate_offscreen |
}, |
{ 0, // times_to_lose_during_commit |
1, // times_to_lose_during_draw |
3, // times_to_fail_reinitialize |
0, // times_to_fail_recreate |
0, // times_to_lose_on_recreate |
+ 0, // times_to_fail_recreate_offscreen |
}, |
{ 1, // times_to_lose_during_commit |
0, // times_to_lose_during_draw |
0, // times_to_fail_reinitialize |
3, // times_to_fail_recreate |
0, // times_to_lose_on_recreate |
+ 0, // times_to_fail_recreate_offscreen |
}, |
{ 0, // times_to_lose_during_commit |
1, // times_to_lose_during_draw |
0, // times_to_fail_reinitialize |
3, // times_to_fail_recreate |
0, // times_to_lose_on_recreate |
+ 0, // times_to_fail_recreate_offscreen |
}, |
{ 1, // times_to_lose_during_commit |
0, // times_to_lose_during_draw |
0, // times_to_fail_reinitialize |
0, // times_to_fail_recreate |
3, // times_to_lose_on_recreate |
+ 0, // times_to_fail_recreate_offscreen |
}, |
{ 0, // times_to_lose_during_commit |
1, // times_to_lose_during_draw |
0, // times_to_fail_reinitialize |
0, // times_to_fail_recreate |
3, // times_to_lose_on_recreate |
+ 0, // times_to_fail_recreate_offscreen |
+ }, |
+ { 1, // times_to_lose_during_commit |
+ 0, // times_to_lose_during_draw |
+ 0, // times_to_fail_reinitialize |
+ 0, // times_to_fail_recreate |
+ 0, // times_to_lose_on_recreate |
+ 3, // times_to_fail_recreate_offscreen |
+ }, |
+ { 0, // times_to_lose_during_commit |
+ 1, // times_to_lose_during_draw |
+ 0, // times_to_fail_reinitialize |
+ 0, // times_to_fail_recreate |
+ 0, // times_to_lose_on_recreate |
+ 3, // times_to_fail_recreate_offscreen |
}, |
// Losing the context and recreating it any number of times should |
// succeed. |
@@ -223,12 +336,14 @@ class LayerTreeHostContextTestLostContextSucceeds : |
0, // times_to_fail_reinitialize |
0, // times_to_fail_recreate |
0, // times_to_lose_on_recreate |
+ 0, // times_to_fail_recreate_offscreen |
}, |
{ 0, // times_to_lose_during_commit |
10, // times_to_lose_during_draw |
0, // times_to_fail_reinitialize |
0, // times_to_fail_recreate |
0, // times_to_lose_on_recreate |
+ 0, // times_to_fail_recreate_offscreen |
}, |
}; |
@@ -242,6 +357,8 @@ class LayerTreeHostContextTestLostContextSucceeds : |
times_to_fail_reinitialize_ = kTests[test_case_].times_to_fail_reinitialize; |
times_to_fail_recreate_ = kTests[test_case_].times_to_fail_recreate; |
times_to_lose_on_recreate_ = kTests[test_case_].times_to_lose_on_recreate; |
+ times_to_fail_recreate_offscreen_ = |
+ kTests[test_case_].times_to_fail_recreate_offscreen; |
++test_case_; |
return true; |
} |
@@ -252,9 +369,10 @@ class LayerTreeHostContextTestLostContextSucceeds : |
int times_to_fail_reinitialize; |
int times_to_fail_recreate; |
int times_to_lose_on_recreate; |
+ int times_to_fail_recreate_offscreen; |
}; |
- private: |
+ protected: |
size_t test_case_; |
int num_losses_; |
bool recovered_context_; |
@@ -281,9 +399,12 @@ class LayerTreeHostContextTestLostContextSucceedsWithContent : |
content_->setAnchorPoint(gfx::PointF()); |
content_->setIsDrawable(true); |
if (use_surface_) { |
- // TODO(danakj): Give the surface a filter to test more code when we can |
- // do so without crashing in the shared context creation. |
content_->setForceRenderSurface(true); |
+ // Filters require us to create an offscreen context. |
+ WebKit::WebFilterOperations filters; |
+ filters.append(WebKit::WebFilterOperation::createGrayscaleFilter(0.5f)); |
+ content_->setFilters(filters); |
+ content_->setBackgroundFilters(filters); |
} |
root_->addChild(content_); |
@@ -307,6 +428,31 @@ class LayerTreeHostContextTestLostContextSucceedsWithContent : |
// TestWebGraphicsContext3D ensures that this resource is created with |
// the active context. |
EXPECT_TRUE(content_impl->HaveResourceForTileAt(0, 0)); |
+ |
+ cc::ContextProvider* contexts = |
+ host_impl->resourceProvider()->offscreenContextProvider(); |
+ if (use_surface_) { |
+ EXPECT_TRUE(contexts->Context3d()); |
+ // TODO(danakj): Make a fake GrContext. |
+ //EXPECT_TRUE(contexts->GrContext()); |
+ } else { |
+ EXPECT_FALSE(contexts); |
+ } |
+ } |
+ |
+ virtual void afterTest() OVERRIDE { |
+ LayerTreeHostContextTestLostContextSucceeds::afterTest(); |
+ if (use_surface_) { |
+ // 1 create to start with + |
+ // 6 from test cases that fail on initializing the renderer (after the |
+ // offscreen context is created) + |
+ // 6 from test cases that lose the offscreen context directly + |
+ // All the test cases that recreate both contexts only once |
+ // per time it is lost. |
+ EXPECT_EQ(6 + 6 + 1 + num_losses_, times_offscreen_created_); |
+ } else { |
+ EXPECT_EQ(0, times_offscreen_created_); |
+ } |
} |
protected: |
@@ -340,6 +486,54 @@ TEST_F(LayerTreeHostContextTestLostContextSucceedsWithContent, |
runTest(true); |
} |
+class LayerTreeHostContextTestOffscreenContextFails |
+ : public LayerTreeHostContextTest { |
+ public: |
+ virtual void setupTree() OVERRIDE { |
+ root_ = Layer::create(); |
+ root_->setBounds(gfx::Size(10, 10)); |
+ root_->setAnchorPoint(gfx::PointF()); |
+ root_->setIsDrawable(true); |
+ |
+ content_ = FakeContentLayer::Create(&client_); |
+ content_->setBounds(gfx::Size(10, 10)); |
+ content_->setAnchorPoint(gfx::PointF()); |
+ content_->setIsDrawable(true); |
+ content_->setForceRenderSurface(true); |
+ // Filters require us to create an offscreen context. |
+ WebKit::WebFilterOperations filters; |
+ filters.append(WebKit::WebFilterOperation::createGrayscaleFilter(0.5f)); |
+ content_->setFilters(filters); |
+ content_->setBackgroundFilters(filters); |
+ |
+ root_->addChild(content_); |
+ |
+ m_layerTreeHost->setRootLayer(root_); |
+ LayerTreeHostContextTest::setupTree(); |
+ } |
+ |
+ virtual void beginTest() OVERRIDE { |
+ times_to_fail_create_offscreen_ = 1; |
+ postSetNeedsCommitToMainThread(); |
+ } |
+ |
+ virtual void drawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
+ cc::ContextProvider* contexts = |
+ host_impl->resourceProvider()->offscreenContextProvider(); |
+ EXPECT_FALSE(contexts); |
+ endTest(); |
+ } |
+ |
+ virtual void afterTest() OVERRIDE {} |
+ |
+ protected: |
+ FakeContentLayerClient client_; |
+ scoped_refptr<Layer> root_; |
+ scoped_refptr<ContentLayer> content_; |
+}; |
+ |
+SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestOffscreenContextFails) |
+ |
class LayerTreeHostContextTestLostContextFails : |
public LayerTreeHostContextTest { |
public: |
@@ -493,6 +687,7 @@ class LayerTreeHostContextTestLostContextAndEvictTextures : |
} |
virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
+ LayerTreeHostContextTest::commitCompleteOnThread(impl); |
if (num_commits_ > 1) |
return; |
++num_commits_; |
@@ -579,6 +774,7 @@ class LayerTreeHostContextTestLostContextWhileUpdatingResources : |
} |
virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
+ LayerTreeHostContextTest::commitCompleteOnThread(impl); |
endTest(); |
} |
@@ -625,6 +821,8 @@ class LayerTreeHostContextTestLayersNotified : |
} |
virtual void commitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
+ LayerTreeHostContextTest::commitCompleteOnThread(host_impl); |
+ |
FakeContentLayerImpl* root = static_cast<FakeContentLayerImpl*>( |
host_impl->rootLayer()); |
FakeContentLayerImpl* child = static_cast<FakeContentLayerImpl*>( |
@@ -787,6 +985,8 @@ class LayerTreeHostContextTestDontUseLostResources : |
} |
virtual void commitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
+ LayerTreeHostContextTest::commitCompleteOnThread(host_impl); |
+ |
ResourceProvider* resource_provider = host_impl->resourceProvider(); |
if (host_impl->activeTree()->source_frame_number() == 0) { |
@@ -995,6 +1195,8 @@ class ScrollbarLayerLostContext : public LayerTreeHostContextTest { |
} |
virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
+ LayerTreeHostContextTest::commitCompleteOnThread(impl); |
+ |
++commits_; |
size_t upload_count = scrollbar_layer_->last_update_full_upload_size() + |
scrollbar_layer_->last_update_partial_upload_size(); |