summaryrefslogtreecommitdiffstats
path: root/cc/debug/fake_context_provider.cc
diff options
context:
space:
mode:
Diffstat (limited to 'cc/debug/fake_context_provider.cc')
-rw-r--r--cc/debug/fake_context_provider.cc93
1 files changed, 93 insertions, 0 deletions
diff --git a/cc/debug/fake_context_provider.cc b/cc/debug/fake_context_provider.cc
new file mode 100644
index 0000000..e2c78df
--- /dev/null
+++ b/cc/debug/fake_context_provider.cc
@@ -0,0 +1,93 @@
+// 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/debug/fake_context_provider.h"
+
+#include "base/logging.h"
+#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
+
+namespace cc {
+
+FakeContextProvider::FakeContextProvider()
+ : bound_(false),
+ destroyed_(false) {
+ DCHECK(main_thread_checker_.CalledOnValidThread());
+ context_thread_checker_.DetachFromThread();
+}
+
+FakeContextProvider::~FakeContextProvider() {
+ DCHECK(main_thread_checker_.CalledOnValidThread() ||
+ context_thread_checker_.CalledOnValidThread());
+}
+
+bool FakeContextProvider::InitializeOnMainThread(
+ const CreateCallback& create_callback) {
+ DCHECK(main_thread_checker_.CalledOnValidThread());
+
+ DCHECK(!context3d_);
+ DCHECK(!create_callback.is_null());
+ context3d_ = create_callback.Run();
+ return context3d_;
+}
+
+bool FakeContextProvider::BindToCurrentThread() {
+ DCHECK(context3d_);
+
+ // This is called on the thread the context will be used.
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+
+ if (bound_)
+ return true;
+
+ bound_ = true;
+ if (!context3d_->makeContextCurrent()) {
+ base::AutoLock lock(destroyed_lock_);
+ destroyed_ = true;
+ return false;
+ }
+ return true;
+}
+
+WebKit::WebGraphicsContext3D* FakeContextProvider::Context3d() {
+ DCHECK(context3d_);
+ DCHECK(bound_);
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+
+ return context3d_.get();
+}
+
+class GrContext* FakeContextProvider::GrContext() {
+ DCHECK(context3d_);
+ DCHECK(bound_);
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+
+ // TODO(danakj): Make a fake GrContext that works with a fake Context3d.
+ return NULL;
+}
+
+void FakeContextProvider::VerifyContexts() {
+ DCHECK(context3d_);
+ DCHECK(bound_);
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+
+ if (context3d_->isContextLost()) {
+ base::AutoLock lock(destroyed_lock_);
+ destroyed_ = true;
+ }
+}
+
+bool FakeContextProvider::DestroyedOnMainThread() {
+ DCHECK(main_thread_checker_.CalledOnValidThread());
+
+ base::AutoLock lock(destroyed_lock_);
+ return destroyed_;
+}
+
+void FakeContextProvider::SetLostContextCallback(
+ const LostContextCallback& cb) {
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+ NOTIMPLEMENTED();
+}
+
+} // namespace cc