Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / cc / test / test_context_provider.cc
index 61660ea..e7697f1 100644 (file)
 #include "base/bind.h"
 #include "base/callback_helpers.h"
 #include "base/logging.h"
-#include "base/strings/string_split.h"
+#include "cc/test/test_gles2_interface.h"
 #include "cc/test/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::Create().Pass());
@@ -71,7 +30,11 @@ scoped_refptr<TestContextProvider> TestContextProvider::Create(
 
 TestContextProvider::TestContextProvider(
     scoped_ptr<TestWebGraphicsContext3D> context)
-    : context3d_(context.Pass()), bound_(false), destroyed_(false) {
+    : context3d_(context.Pass()),
+      context_gl_(new TestGLES2Interface(context3d_.get())),
+      bound_(false),
+      destroyed_(false),
+      weak_ptr_factory_(this) {
   DCHECK(main_thread_checker_.CalledOnValidThread());
   DCHECK(context3d_);
   context_thread_checker_.DetachFromThread();
@@ -84,54 +47,46 @@ TestContextProvider::~TestContextProvider() {
 }
 
 bool TestContextProvider::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()) {
+  if (context3d_->isContextLost()) {
     base::AutoLock lock(destroyed_lock_);
     destroyed_ = true;
     return false;
   }
+  bound_ = true;
 
-  lost_context_callback_proxy_.reset(new LostContextCallbackProxy(this));
-  swap_buffers_complete_callback_proxy_.reset(
-      new SwapBuffersCompleteCallbackProxy(this));
+  context3d_->set_context_lost_callback(
+      base::Bind(&TestContextProvider::OnLostContext,
+                 base::Unretained(this)));
 
   return true;
 }
 
 ContextProvider::Capabilities TestContextProvider::ContextCapabilities() {
-  DCHECK(context3d_);
   DCHECK(bound_);
   DCHECK(context_thread_checker_.CalledOnValidThread());
 
   return context3d_->test_capabilities();
 }
 
-WebKit::WebGraphicsContext3D* TestContextProvider::Context3d() {
+gpu::gles2::GLES2Interface* TestContextProvider::ContextGL() {
   DCHECK(context3d_);
   DCHECK(bound_);
   DCHECK(context_thread_checker_.CalledOnValidThread());
 
-  return context3d_.get();
+  return context_gl_.get();
 }
 
 gpu::ContextSupport* TestContextProvider::ContextSupport() {
-  DCHECK(context3d_);
-  DCHECK(bound_);
-  DCHECK(context_thread_checker_.CalledOnValidThread());
-
   return &support_;
 }
 
 class GrContext* TestContextProvider::GrContext() {
-  DCHECK(context3d_);
   DCHECK(bound_);
   DCHECK(context_thread_checker_.CalledOnValidThread());
 
@@ -139,8 +94,14 @@ class GrContext* TestContextProvider::GrContext() {
   return NULL;
 }
 
+bool TestContextProvider::IsContextLost() {
+  DCHECK(bound_);
+  DCHECK(context_thread_checker_.CalledOnValidThread());
+
+  return context3d_->isContextLost();
+}
+
 void TestContextProvider::VerifyContexts() {
-  DCHECK(context3d_);
   DCHECK(bound_);
   DCHECK(context_thread_checker_.CalledOnValidThread());
 
@@ -150,6 +111,9 @@ void TestContextProvider::VerifyContexts() {
   }
 }
 
+void TestContextProvider::DeleteCachedResources() {
+}
+
 bool TestContextProvider::DestroyedOnMainThread() {
   DCHECK(main_thread_checker_.CalledOnValidThread());
 
@@ -169,14 +133,7 @@ void TestContextProvider::OnLostContext() {
     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();
-}
-
 TestWebGraphicsContext3D* TestContextProvider::TestContext3d() {
-  DCHECK(context3d_);
   DCHECK(bound_);
   DCHECK(context_thread_checker_.CalledOnValidThread());
 
@@ -184,9 +141,6 @@ TestWebGraphicsContext3D* TestContextProvider::TestContext3d() {
 }
 
 TestWebGraphicsContext3D* TestContextProvider::UnboundTestContext3d() {
-  DCHECK(context3d_);
-  DCHECK(context_thread_checker_.CalledOnValidThread());
-
   return context3d_.get();
 }
 
@@ -204,13 +158,6 @@ void TestContextProvider::SetLostContextCallback(
   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());