#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());
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();
}
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());
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());
}
}
+void TestContextProvider::DeleteCachedResources() {
+}
+
bool TestContextProvider::DestroyedOnMainThread() {
DCHECK(main_thread_checker_.CalledOnValidThread());
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());
}
TestWebGraphicsContext3D* TestContextProvider::UnboundTestContext3d() {
- DCHECK(context3d_);
- DCHECK(context_thread_checker_.CalledOnValidThread());
-
return context3d_.get();
}
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());