| 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 751e7d782265976081f0af1552bb980789b2f0e1..a2405a12cefeef330c930488a1f0386cc28a5d96 100644
|
| --- a/cc/layer_tree_host_unittest_context.cc
|
| +++ b/cc/layer_tree_host_unittest_context.cc
|
| @@ -33,6 +33,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 +54,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_lose_on_create_offscreen_(0),
|
| + times_to_fail_recreate_offscreen_(0),
|
| + times_to_lose_on_recreate_offscreen_(0),
|
| + times_to_expect_recreate_retried_(0),
|
| + times_recreate_retried_(0) {
|
| media::InitializeMediaLibraryForTesting();
|
| }
|
|
|
| @@ -70,6 +77,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,33 +90,94 @@ 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;
|
| + WebKit::WebGraphicsContext3D* CreateOffscreenContext3d() {
|
| + DCHECK(!offscreen_context3d_);
|
| + DCHECK(!offscreen_gr_context_);
|
|
|
| - --times_to_lose_during_draw_;
|
| - if (context3d_)
|
| - context3d_->set_times_make_current_succeeds(0);
|
| - return result;
|
| + if (times_to_fail_create_offscreen_) {
|
| + --times_to_fail_create_offscreen_;
|
| + ExpectRecreateToRetry();
|
| + return NULL;
|
| }
|
|
|
| + WebKit::WebGraphicsContext3D::Attributes attrs;
|
| + offscreen_context3d_ =
|
| + FakeWebGraphicsContext3D::Create(attrs)
|
| + .PassAs<WebKit::WebGraphicsContext3D>();
|
| + DCHECK(offscreen_context3d_);
|
| +
|
| + if (times_to_lose_on_create_offscreen_) {
|
| + --times_to_lose_on_create_offscreen_;
|
| + offscreen_context3d_->loseContextCHROMIUM(
|
| + GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB);
|
| + offscreen_context3d_.reset();
|
| + ExpectRecreateToRetry();
|
| + }
|
| +
|
| + return offscreen_context3d_.get();
|
| + }
|
| +
|
| + virtual WebKit::WebGraphicsContext3D*
|
| + createOrGetOffscreenContext3dForMainThread() OVERRIDE {
|
| + DCHECK(!implThread());
|
| +
|
| + if (!offscreen_context3d_)
|
| + CreateOffscreenContext3d();
|
| + return offscreen_context3d_.get();
|
| + }
|
| +
|
| + virtual WebKit::WebGraphicsContext3D*
|
| + createOrGetOffscreenContext3dForCompositorThread() OVERRIDE {
|
| + DCHECK(implThread());
|
| +
|
| + if (!offscreen_context3d_)
|
| + CreateOffscreenContext3d();
|
| + return offscreen_context3d_.get();
|
| + }
|
| +
|
| + virtual GrContext*
|
| + createOrGetOffscreenGrContextForMainThread() OVERRIDE {
|
| + DCHECK(!implThread());
|
| + // TODO(danakj): Make a FakeGrContext.
|
| + return NULL;
|
| + }
|
| +
|
| + virtual GrContext*
|
| + createOrGetOffscreenGrContextForCompositorThread() OVERRIDE {
|
| + DCHECK(implThread());
|
| + // TODO(danakj): Make a FakeGrContext.
|
| + return NULL;
|
| + }
|
| +
|
| + 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_)
|
| - return;
|
| - --times_to_lose_during_commit_;
|
| - LoseContext();
|
| + if (times_to_lose_during_commit_) {
|
| + --times_to_lose_during_commit_;
|
| + LoseContext();
|
| + }
|
|
|
| times_to_fail_create_ = times_to_fail_recreate_;
|
| times_to_fail_recreate_ = 0;
|
| @@ -116,6 +185,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;
|
| + times_to_lose_on_create_offscreen_ = times_to_lose_on_recreate_offscreen_;
|
| + times_to_lose_on_recreate_offscreen_ = 0;
|
| + }
|
| +
|
| + virtual void willRetryRecreateOutputSurface() OVERRIDE {
|
| + ++times_recreate_retried_;
|
| + }
|
| +
|
| + virtual void afterTest() OVERRIDE {
|
| + EXPECT_EQ(times_to_expect_recreate_retried_, times_recreate_retried_);
|
| + }
|
| +
|
| + void ExpectRecreateToRetry() {
|
| + ++times_to_expect_recreate_retried_;
|
| }
|
|
|
| protected:
|
| @@ -128,6 +213,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_lose_on_create_offscreen_;
|
| + int times_to_fail_recreate_offscreen_;
|
| + int times_to_lose_on_recreate_offscreen_;
|
| + int times_to_expect_recreate_retried_;
|
| + int times_recreate_retried_;
|
| +
|
| + scoped_ptr<WebKit::WebGraphicsContext3D> offscreen_context3d_;
|
| + skia::RefPtr<GrContext> offscreen_gr_context_;
|
| };
|
|
|
| class LayerTreeHostContextTestLostContextSucceeds :
|
| @@ -151,8 +245,9 @@ class LayerTreeHostContextTestLostContextSucceeds :
|
| }
|
|
|
| virtual void afterTest() OVERRIDE {
|
| - EXPECT_EQ(8, test_case_);
|
| - EXPECT_EQ(6 + 10 + 10, num_losses_);
|
| + LayerTreeHostContextTest::afterTest();
|
| + EXPECT_EQ(12, test_case_);
|
| + EXPECT_EQ(10 + 10 + 10, num_losses_);
|
| }
|
|
|
| virtual void didCommitAndDrawFrame() OVERRIDE {
|
| @@ -185,36 +280,80 @@ 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_on_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;
|
| + 0, // times_to_lose_on_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_on_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;
|
| + 0, // times_to_lose_on_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_on_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;
|
| + 0, // times_to_lose_on_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_on_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;
|
| + 0, // times_to_lose_on_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_on_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;
|
| + 3, // times_to_lose_on_recreate_offscreen;
|
| },
|
| // Losing the context and recreating it any number of times should
|
| // succeed.
|
| @@ -223,12 +362,16 @@ 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_on_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;
|
| + 0, // times_to_lose_on_recreate_offscreen;
|
| },
|
| };
|
|
|
| @@ -242,6 +385,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;
|
| + times_to_lose_on_recreate_offscreen_ = kTests[test_case_].times_to_lose_on_recreate_offscreen;
|
| ++test_case_;
|
| return true;
|
| }
|
| @@ -252,6 +397,8 @@ class LayerTreeHostContextTestLostContextSucceeds :
|
| int times_to_fail_reinitialize;
|
| int times_to_fail_recreate;
|
| int times_to_lose_on_recreate;
|
| + int times_to_fail_recreate_offscreen;
|
| + int times_to_lose_on_recreate_offscreen;
|
| };
|
|
|
| private:
|
| @@ -281,9 +428,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 +457,11 @@ class LayerTreeHostContextTestLostContextSucceedsWithContent :
|
| // FakeWebGraphicsContext3D ensures that this resource is created with
|
| // the active context.
|
| EXPECT_TRUE(content_impl->HaveResourceForTileAt(0, 0));
|
| +
|
| + if (use_surface_)
|
| + EXPECT_TRUE(host_impl->resourceProvider()->offscreenGraphicsContext3d());
|
| + else
|
| + EXPECT_FALSE(host_impl->resourceProvider()->offscreenGraphicsContext3d());
|
| }
|
|
|
| protected:
|
| @@ -376,8 +531,6 @@ class LayerTreeHostContextTestLostContextFails :
|
| EXPECT_FALSE(host_impl->resourceProvider());
|
| }
|
|
|
| - virtual void afterTest() OVERRIDE {}
|
| -
|
| private:
|
| int num_commits_;
|
| };
|
| @@ -439,8 +592,6 @@ class LayerTreeHostContextTestFinishAllRenderingAfterLoss :
|
| m_layerTreeHost->finishAllRendering();
|
| endTest();
|
| }
|
| -
|
| - virtual void afterTest() OVERRIDE {}
|
| };
|
|
|
| SINGLE_AND_MULTI_THREAD_TEST_F(
|
| @@ -506,8 +657,6 @@ class LayerTreeHostContextTestLostContextAndEvictTextures :
|
| endTest();
|
| }
|
|
|
| - virtual void afterTest() OVERRIDE {}
|
| -
|
| protected:
|
| bool lose_after_evict_;
|
| FakeContentLayerClient client_;
|
| @@ -587,6 +736,7 @@ class LayerTreeHostContextTestLostContextWhileUpdatingResources :
|
| }
|
|
|
| virtual void afterTest() {
|
| + LayerTreeHostContextTest::afterTest();
|
| EXPECT_EQ(0, times_to_lose_on_end_query_);
|
| }
|
|
|
| @@ -669,8 +819,6 @@ class LayerTreeHostContextTestLayersNotified :
|
| }
|
| }
|
|
|
| - virtual void afterTest() OVERRIDE {}
|
| -
|
| private:
|
| int num_commits_;
|
|
|
| @@ -870,8 +1018,6 @@ class LayerTreeHostContextTestDontUseLostResources :
|
| endTest();
|
| }
|
|
|
| - virtual void afterTest() OVERRIDE {}
|
| -
|
| private:
|
| FakeContentLayerClient client_;
|
|
|
| @@ -912,9 +1058,6 @@ class LayerTreeHostContextTestFailsImmediately :
|
| postSetNeedsCommitToMainThread();
|
| }
|
|
|
| - virtual void afterTest() OVERRIDE {
|
| - }
|
| -
|
| virtual scoped_ptr<FakeWebGraphicsContext3D> CreateContext3d() OVERRIDE {
|
| scoped_ptr<FakeWebGraphicsContext3D> context =
|
| LayerTreeHostContextTest::CreateContext3d();
|
| @@ -964,8 +1107,6 @@ class LayerTreeHostContextTestImplSidePainting :
|
| postSetNeedsCommitToMainThread();
|
| }
|
|
|
| - virtual void afterTest() OVERRIDE {}
|
| -
|
| virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE {
|
| EXPECT_TRUE(succeeded);
|
| endTest();
|
| @@ -991,9 +1132,6 @@ class ScrollbarLayerLostContext : public LayerTreeHostContextTest {
|
| postSetNeedsCommitToMainThread();
|
| }
|
|
|
| - virtual void afterTest() OVERRIDE {
|
| - }
|
| -
|
| virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE {
|
| ++commits_;
|
| size_t upload_count = scrollbar_layer_->last_update_full_upload_size() +
|
|
|