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

Unified Diff: cc/debug/test_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/debug/test_context_provider.h ('k') | cc/debug/test_web_graphics_context_3d.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/debug/test_context_provider.cc
diff --git a/cc/debug/test_context_provider.cc b/cc/debug/test_context_provider.cc
index 4a3a2fcee2fc3f8905db3dd35e1c2fe3f7425304..55fc74fead1a866b35952056d50006c8aa9c88ae 100644
--- a/cc/debug/test_context_provider.cc
+++ b/cc/debug/test_context_provider.cc
@@ -4,14 +4,57 @@
#include "cc/debug/test_context_provider.h"
+#include "base/bind.h"
+#include "base/callback_helpers.h"
#include "base/logging.h"
#include "cc/debug/test_web_graphics_context_3d.h"
namespace cc {
+class TestContextProvider::LostContextCallbackProxy
+ : public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback {
+ public:
+ explicit LostContextCallbackProxy(TestContextProvider* provider)
+ : provider_(provider) {
+ provider_->context3d_->setContextLostCallback(this);
+ }
+
+ virtual ~LostContextCallbackProxy() {
+ provider_->context3d_->setContextLostCallback(NULL);
+ }
+
+ virtual void onContextLost() {
+ provider_->OnLostContext();
+ }
+
+ private:
+ TestContextProvider* provider_;
+};
+
+class TestContextProvider::SwapBuffersCompleteCallbackProxy
+ : public WebKit::WebGraphicsContext3D::
+ WebGraphicsSwapBuffersCompleteCallbackCHROMIUM {
+ public:
+ explicit SwapBuffersCompleteCallbackProxy(TestContextProvider* provider)
+ : provider_(provider) {
+ provider_->context3d_->setSwapBuffersCompleteCallbackCHROMIUM(this);
+ }
+
+ virtual ~SwapBuffersCompleteCallbackProxy() {
+ provider_->context3d_->setSwapBuffersCompleteCallbackCHROMIUM(NULL);
+ }
+
+ virtual void onSwapBuffersComplete() {
+ provider_->OnSwapBuffersComplete();
+ }
+
+ private:
+ TestContextProvider* provider_;
+};
+
// static
scoped_refptr<TestContextProvider> TestContextProvider::Create() {
- return Create(TestWebGraphicsContext3D::CreateFactory());
+ return Create(TestWebGraphicsContext3D::Create().Pass());
}
// static
@@ -23,6 +66,17 @@ scoped_refptr<TestContextProvider> TestContextProvider::Create(
return provider;
}
+scoped_ptr<TestWebGraphicsContext3D> ReturnScopedContext(
+ scoped_ptr<TestWebGraphicsContext3D> context) {
+ return context.Pass();
+}
+
+// static
+scoped_refptr<TestContextProvider> TestContextProvider::Create(
+ scoped_ptr<TestWebGraphicsContext3D> context) {
+ return Create(base::Bind(&ReturnScopedContext, base::Passed(&context)));
+}
+
TestContextProvider::TestContextProvider()
: bound_(false),
destroyed_(false) {
@@ -60,6 +114,11 @@ bool TestContextProvider::BindToCurrentThread() {
destroyed_ = true;
return false;
}
+
+ lost_context_callback_proxy_.reset(new LostContextCallbackProxy(this));
+ swap_buffers_complete_callback_proxy_.reset(
+ new SwapBuffersCompleteCallbackProxy(this));
+
return true;
}
@@ -98,10 +157,52 @@ bool TestContextProvider::DestroyedOnMainThread() {
return destroyed_;
}
+void TestContextProvider::OnLostContext() {
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+ {
+ base::AutoLock lock(destroyed_lock_);
+ if (destroyed_)
+ return;
+ destroyed_ = true;
+ }
+ if (!lost_context_callback_.is_null())
+ base::ResetAndReturn(&lost_context_callback_).Run();
+}
+
+void TestContextProvider::OnSwapBuffersComplete() {
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+ if (!swap_buffers_complete_callback_.is_null())
+ swap_buffers_complete_callback_.Run();
+}
+
+void TestContextProvider::SetMemoryAllocation(
+ const ManagedMemoryPolicy& policy,
+ bool discard_backbuffer_when_not_visible) {
+ if (memory_policy_changed_callback_.is_null())
+ return;
+ memory_policy_changed_callback_.Run(
+ policy, discard_backbuffer_when_not_visible);
+}
+
void TestContextProvider::SetLostContextCallback(
const LostContextCallback& cb) {
DCHECK(context_thread_checker_.CalledOnValidThread());
- NOTIMPLEMENTED();
+ DCHECK(lost_context_callback_.is_null() || cb.is_null());
+ lost_context_callback_ = cb;
+}
+
+void TestContextProvider::SetSwapBuffersCompleteCallback(
+ const SwapBuffersCompleteCallback& cb) {
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+ DCHECK(swap_buffers_complete_callback_.is_null() || cb.is_null());
+ swap_buffers_complete_callback_ = cb;
+}
+
+void TestContextProvider::SetMemoryPolicyChangedCallback(
+ const MemoryPolicyChangedCallback& cb) {
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+ DCHECK(memory_policy_changed_callback_.is_null() || cb.is_null());
+ memory_policy_changed_callback_ = cb;
}
} // namespace cc
« no previous file with comments | « cc/debug/test_context_provider.h ('k') | cc/debug/test_web_graphics_context_3d.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698