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

Unified Diff: cc/layer_tree_host_unittest_context.cc

Issue 12212007: cc: Route offscreen context creation for compositor to the browser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename to GaneshContextProvider Created 7 years, 10 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/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 7b84656039d59e0530eb2f1b638b9d568fa077bb..ca3bb1fe2b0e8b589b1fc0e32ac10fec137fe976 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/ganesh_context_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,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 +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,28 +91,90 @@ 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_);
- --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();
+ }
+
+ // LayerTreeHostClient implementation.
+ virtual WebKit::WebGraphicsContext3D* OffscreenContext3dForMainThread()
+ OVERRIDE {
+ DCHECK(!implThread());
+
+ if (!offscreen_context3d_)
+ CreateOffscreenContext3d();
+ return offscreen_context3d_.get();
+ }
+
+ // LayerTreeHostClient implementation.
+ virtual WebKit::WebGraphicsContext3D* OffscreenContext3dForCompositorThread()
+ OVERRIDE {
+ DCHECK(implThread());
+
+ if (!offscreen_context3d_)
+ CreateOffscreenContext3d();
+ return offscreen_context3d_.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 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;
@@ -116,6 +187,23 @@ 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 TearDown() OVERRIDE {
+ ThreadedTest::TearDown();
+ EXPECT_EQ(times_to_expect_recreate_retried_, times_recreate_retried_);
+ }
+
+ void ExpectRecreateToRetry() {
+ ++times_to_expect_recreate_retried_;
}
protected:
@@ -128,6 +216,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_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_;
};
class LayerTreeHostContextTestLostContextSucceeds :
@@ -151,8 +247,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 +281,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 +363,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 +386,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 +398,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 +429,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 +458,13 @@ class LayerTreeHostContextTestLostContextSucceedsWithContent :
// FakeWebGraphicsContext3D ensures that this resource is created with
// the active context.
EXPECT_TRUE(content_impl->HaveResourceForTileAt(0, 0));
+
+ GaneshContextProvider::ScopedContexts contexts(
+ host_impl->resourceProvider()->ganeshContextProvider());
+ if (use_surface_)
+ EXPECT_TRUE(contexts.context3d());
+ else
+ EXPECT_FALSE(contexts.context3d());
}
protected:

Powered by Google App Engine
This is Rietveld 408576698