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

Unified Diff: cc/test/fake_context_provider.cc

Issue 20185002: ContextProvider in OutputSurface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: contextprovider: don't access Context3d() in OutputSurface contructors, it's not bound yet Created 7 years, 4 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
« no previous file with comments | « cc/resources/video_resource_updater_unittest.cc ('k') | cc/test/fake_layer_tree_host_client.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/test/fake_context_provider.cc
diff --git a/cc/test/fake_context_provider.cc b/cc/test/fake_context_provider.cc
new file mode 100644
index 0000000000000000000000000000000000000000..806eb4fabaa701c5dc88514336af37ab2daeeefa
--- /dev/null
+++ b/cc/test/fake_context_provider.cc
@@ -0,0 +1,110 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/test/fake_context_provider.h"
+
+#include "base/bind.h"
+#include "cc/test/test_web_graphics_context_3d.h"
+
+namespace cc {
+
+// static
+scoped_refptr<FakeContextProvider> FakeContextProvider::
+ CreateForOtherThread() {
+ scoped_refptr<FakeContextProvider> provider = new FakeContextProvider();
+ if (!provider->InitializeOnMainThread())
+ return NULL;
+ return provider;
+}
+
+static scoped_ptr<TestWebGraphicsContext3D> ReturnContext(
+ scoped_ptr<TestWebGraphicsContext3D> context3d) {
+ return context3d.Pass();
+}
+
+// static
+scoped_refptr<FakeContextProvider> FakeContextProvider::CreateForOtherThread(
+ scoped_ptr<TestWebGraphicsContext3D> context3d) {
+ CreateCallback create_callback =
+ base::Bind(&ReturnContext, base::Passed(&context3d));
+ scoped_refptr<FakeContextProvider> provider =
+ new FakeContextProvider(create_callback);
+ if (!provider->InitializeOnMainThread())
+ return NULL;
+ return provider;
+}
+
+// static
+scoped_refptr<FakeContextProvider> FakeContextProvider::CreateForOtherThread(
+ const CreateCallback& create_callback) {
+ scoped_refptr<FakeContextProvider> provider =
+ new FakeContextProvider(create_callback);
+ if (!provider->InitializeOnMainThread())
+ return NULL;
+ return provider;
+}
+
+FakeContextProvider::FakeContextProvider()
+ : destroyed_(false) {
+}
+
+FakeContextProvider::FakeContextProvider(
+ const CreateCallback& create_callback)
+ : create_callback_(create_callback),
+ bound_(false),
+ destroyed_(false) {
+}
+
+FakeContextProvider::~FakeContextProvider() {}
+
+bool FakeContextProvider::InitializeOnMainThread() {
+ DCHECK(!context3d_);
+
+ if (create_callback_.is_null())
+ context3d_ = TestWebGraphicsContext3D::Create().Pass();
+ else
+ context3d_ = create_callback_.Run();
+ return context3d_;
+}
+
+bool FakeContextProvider::BindToCurrentThread() {
+ bound_ = true;
+ if (!context3d_->makeContextCurrent()) {
+ base::AutoLock lock(destroyed_lock_);
+ destroyed_ = true;
+ return false;
+ }
+ return true;
+}
+
+WebKit::WebGraphicsContext3D* FakeContextProvider::Context3d() {
+ DCHECK(context3d_);
+ DCHECK(bound_);
+
+ return context3d_.get();
+}
+class GrContext* FakeContextProvider::GrContext() {
+ DCHECK(context3d_);
+ DCHECK(bound_);
+
+ // TODO(danakj): Make a fake GrContext.
+ return NULL;
+}
+
+void FakeContextProvider::VerifyContexts() {
+ DCHECK(context3d_);
+ DCHECK(bound_);
+
+ if (context3d_->isContextLost()) {
+ base::AutoLock lock(destroyed_lock_);
+ destroyed_ = true;
+ }
+}
+
+bool FakeContextProvider::DestroyedOnMainThread() {
+ base::AutoLock lock(destroyed_lock_);
+ return destroyed_;
+}
+
+} // namespace cc
« no previous file with comments | « cc/resources/video_resource_updater_unittest.cc ('k') | cc/test/fake_layer_tree_host_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698