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..0747c1f0c29e00e8ee77fed6e2e38ec1a534e193 100644 |
--- a/cc/layer_tree_host_unittest_context.cc |
+++ b/cc/layer_tree_host_unittest_context.cc |
@@ -8,6 +8,7 @@ |
#include "cc/content_layer.h" |
#include "cc/delegated_renderer_layer.h" |
#include "cc/delegated_renderer_layer_impl.h" |
+#include "cc/grcontext_provider.h" |
#include "cc/heads_up_display_layer.h" |
#include "cc/io_surface_layer.h" |
#include "cc/layer_impl.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,12 @@ 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) { |
media::InitializeMediaLibraryForTesting(); |
} |
@@ -68,8 +75,11 @@ class LayerTreeHostContextTest : public ThreadedTest { |
} |
virtual scoped_ptr<OutputSurface> createOutputSurface() OVERRIDE { |
+ offscreen_context3d_main_thread_.reset(); |
+ |
if (times_to_fail_create_) { |
--times_to_fail_create_; |
+ ExpectRecreateToRetry(); |
return scoped_ptr<OutputSurface>(); |
} |
@@ -82,27 +92,84 @@ 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 (times_to_fail_create_offscreen_) { |
+ --times_to_fail_create_offscreen_; |
+ ExpectRecreateToRetry(); |
+ return scoped_ptr<TestWebGraphicsContext3D>(); |
+ } |
+ |
+ WebKit::WebGraphicsContext3D::Attributes attrs; |
+ scoped_ptr<TestWebGraphicsContext3D> offscreen_context3d = |
+ TestWebGraphicsContext3D::Create(attrs).Pass(); |
+ DCHECK(offscreen_context3d); |
- --times_to_lose_during_draw_; |
- if (context3d_) |
- context3d_->set_times_make_current_succeeds(0); |
+ ++times_offscreen_created_; |
+ return offscreen_context3d.Pass(); |
+ } |
+ |
+ // LayerTreeHostClient implementation. |
+ virtual WebKit::WebGraphicsContext3D* OffscreenContext3dForMainThread() |
+ OVERRIDE { |
+ DCHECK(!implThread()); |
+ |
+ if (!offscreen_context3d_main_thread_ && context3d_) |
+ offscreen_context3d_main_thread_ = CreateOffscreenContext3d().Pass(); |
+ return offscreen_context3d_main_thread_.get(); |
+ } |
+ |
+ // LayerTreeHostClient implementation. |
+ virtual WebKit::WebGraphicsContext3D* OffscreenContext3dForCompositorThread() |
+ OVERRIDE { |
+ DCHECK(implThread()); |
+ |
+ if (!offscreen_context3d_impl_thread_ && context3d_) |
+ offscreen_context3d_impl_thread_ = CreateOffscreenContext3d().Pass(); |
+ return offscreen_context3d_impl_thread_.get(); |
+ } |
+ |
+ // LayerTreeHostClient implementation. |
+ virtual GrContext* OffscreenGrContextForMainThread() OVERRIDE { |
+ DCHECK(!implThread()); |
+ // TODO(danakj): Make a FakeGrContext. |
+ return NULL; |
+ } |
+ |
+ // LayerTreeHostClient implementation. |
+ virtual GrContext* OffscreenGrContextForCompositorThread() OVERRIDE { |
+ DCHECK(implThread()); |
+ // TODO(danakj): Make a FakeGrContext. |
+ return NULL; |
+ } |
+ |
+ virtual void DestroyOffscreenContext3dForCompositorThread() OVERRIDE { |
+ // TODO(danakj): Delete the FakeGrContext. |
+ offscreen_context3d_impl_thread_.reset(); |
+ } |
+ |
+ 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_; |
+ if (context3d_) |
+ context3d_->set_times_make_current_succeeds(0); |
+ return result; |
+ } |
virtual void commitCompleteOnThread(LayerTreeHostImpl *host_impl) OVERRIDE { |
if (!times_to_lose_during_commit_) |
@@ -116,6 +183,21 @@ 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() { |
+ ++times_to_expect_recreate_retried_; |
} |
protected: |
@@ -128,6 +210,14 @@ 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_; |
+ |
+ scoped_ptr<TestWebGraphicsContext3D> offscreen_context3d_main_thread_; |
+ scoped_ptr<TestWebGraphicsContext3D> offscreen_context3d_impl_thread_; |
}; |
class LayerTreeHostContextTestLostContextSucceeds : |
@@ -151,8 +241,8 @@ class LayerTreeHostContextTestLostContextSucceeds : |
} |
virtual void afterTest() OVERRIDE { |
- EXPECT_EQ(8, test_case_); |
- EXPECT_EQ(6 + 10 + 10, num_losses_); |
+ EXPECT_EQ(12, test_case_); |
+ EXPECT_EQ(10 + 10 + 10, num_losses_); |
} |
virtual void didCommitAndDrawFrame() OVERRIDE { |
@@ -185,36 +275,70 @@ 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; |
+ }, |
+ { 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 |
+ 0, // times_to_fail_recreate_offscreen; |
}, |
// Losing the context and recreating it any number of times should |
// succeed. |
@@ -223,12 +347,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 +368,7 @@ 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,6 +379,7 @@ 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: |
@@ -281,9 +409,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 +438,25 @@ class LayerTreeHostContextTestLostContextSucceedsWithContent : |
// TestWebGraphicsContext3D ensures that this resource is created with |
// the active context. |
EXPECT_TRUE(content_impl->HaveResourceForTileAt(0, 0)); |
+ |
+ GrContextProvider* contexts = |
+ host_impl->resourceProvider()->offscreenContextProvider(); |
+ if (use_surface_) { |
+ EXPECT_TRUE(contexts->context3d()); |
+ // TODO(danakj): Make a fake GrContext. |
+ //EXPECT_TRUE(contexts->gr_context()); |
+ } else { |
+ EXPECT_FALSE(contexts->context3d()); |
+ EXPECT_FALSE(contexts->gr_context()); |
+ } |
+ } |
+ |
+ virtual void afterTest() OVERRIDE { |
+ LayerTreeHostContextTestLostContextSucceeds::afterTest(); |
+ if (use_surface_) |
+ EXPECT_EQ(14 + 10 + 10, times_offscreen_created_); |
+ else |
+ EXPECT_EQ(0, times_offscreen_created_); |
} |
protected: |