| Index: cc/test/test_context_provider.cc
|
| diff --git a/cc/test/test_context_provider.cc b/cc/test/test_context_provider.cc
|
| index b2683aed5f33611fa296b9b09fa8efdcfacd8e36..d6e5da437928711d23f4ec9ded4e313da74c2f6f 100644
|
| --- a/cc/test/test_context_provider.cc
|
| +++ b/cc/test/test_context_provider.cc
|
| @@ -26,16 +26,6 @@ scoped_refptr<TestContextProvider> TestContextProvider::Create() {
|
| }
|
|
|
| // static
|
| -scoped_refptr<TestContextProvider> TestContextProvider::CreateWorker() {
|
| - scoped_refptr<TestContextProvider> worker_context_provider =
|
| - Create(TestWebGraphicsContext3D::Create());
|
| - // Worker contexts are bound to the thread they are created on.
|
| - if (!worker_context_provider->BindToCurrentThread())
|
| - return nullptr;
|
| - return worker_context_provider;
|
| -}
|
| -
|
| -// static
|
| scoped_refptr<TestContextProvider> TestContextProvider::Create(
|
| std::unique_ptr<TestWebGraphicsContext3D> context) {
|
| if (!context)
|
| @@ -43,56 +33,59 @@ scoped_refptr<TestContextProvider> TestContextProvider::Create(
|
| return new TestContextProvider(std::move(context));
|
| }
|
|
|
| -TestContextProvider::TestContextProvider(
|
| +TestContextProvider::Factory::Factory() = default;
|
| +
|
| +TestContextProvider::Factory::Factory(
|
| std::unique_ptr<TestWebGraphicsContext3D> context)
|
| - : context3d_(std::move(context)),
|
| - context_gl_(new TestGLES2Interface(context3d_.get())),
|
| - bound_(false),
|
| - weak_ptr_factory_(this) {
|
| - DCHECK(main_thread_checker_.CalledOnValidThread());
|
| - DCHECK(context3d_);
|
| - context_thread_checker_.DetachFromThread();
|
| - context3d_->set_test_support(&support_);
|
| -}
|
| + : context_(std::move(context)) {}
|
|
|
| -TestContextProvider::~TestContextProvider() {
|
| - DCHECK(main_thread_checker_.CalledOnValidThread() ||
|
| - context_thread_checker_.CalledOnValidThread());
|
| -}
|
| +TestContextProvider::Factory::Factory(const gpu::Capabilities& capabilities)
|
| + : capabilities_(capabilities) {}
|
|
|
| -bool TestContextProvider::BindToCurrentThread() {
|
| - // This is called on the thread the context will be used.
|
| - DCHECK(context_thread_checker_.CalledOnValidThread());
|
| +TestContextProvider::Factory::Factory(FailCreate) : fail_create_(true) {}
|
|
|
| - if (bound_)
|
| - return true;
|
| +TestContextProvider::Factory::~Factory() = default;
|
|
|
| - if (context_gl_->GetGraphicsResetStatusKHR() != GL_NO_ERROR) {
|
| - return false;
|
| +scoped_refptr<ContextProvider> TestContextProvider::Factory::CreateContext() {
|
| + if (fail_create_)
|
| + return nullptr;
|
| + std::unique_ptr<TestWebGraphicsContext3D> context = std::move(context_);
|
| + if (!context) {
|
| + context = TestWebGraphicsContext3D::Create();
|
| + context->set_capabilities(capabilities_);
|
| }
|
| - bound_ = true;
|
| + return make_scoped_refptr(new TestContextProvider(std::move(context)));
|
| +}
|
|
|
| +TestContextProvider::TestContextProvider(
|
| + std::unique_ptr<TestWebGraphicsContext3D> context)
|
| + : context3d_(std::move(context)),
|
| + context_gl_(new TestGLES2Interface(context3d_.get())),
|
| + weak_ptr_factory_(this) {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + DCHECK(context3d_);
|
| + context3d_->set_test_support(&support_);
|
| context3d_->set_context_lost_callback(
|
| base::Bind(&TestContextProvider::OnLostContext,
|
| base::Unretained(this)));
|
| +}
|
|
|
| - return true;
|
| +TestContextProvider::~TestContextProvider() {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| }
|
|
|
| void TestContextProvider::DetachFromThread() {
|
| - context_thread_checker_.DetachFromThread();
|
| + thread_checker_.DetachFromThread();
|
| }
|
|
|
| gpu::Capabilities TestContextProvider::ContextCapabilities() {
|
| - DCHECK(bound_);
|
| - DCHECK(context_thread_checker_.CalledOnValidThread());
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| return context3d_->test_capabilities();
|
| }
|
|
|
| gpu::gles2::GLES2Interface* TestContextProvider::ContextGL() {
|
| DCHECK(context3d_);
|
| - DCHECK(bound_);
|
| - DCHECK(context_thread_checker_.CalledOnValidThread());
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
| return context_gl_.get();
|
| }
|
| @@ -102,8 +95,7 @@ gpu::ContextSupport* TestContextProvider::ContextSupport() {
|
| }
|
|
|
| class GrContext* TestContextProvider::GrContext() {
|
| - DCHECK(bound_);
|
| - DCHECK(context_thread_checker_.CalledOnValidThread());
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
| if (gr_context_)
|
| return gr_context_.get();
|
| @@ -121,8 +113,7 @@ class GrContext* TestContextProvider::GrContext() {
|
| }
|
|
|
| void TestContextProvider::InvalidateGrContext(uint32_t state) {
|
| - DCHECK(bound_);
|
| - DCHECK(context_thread_checker_.CalledOnValidThread());
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
| if (gr_context_)
|
| gr_context_.get()->resetContext(state);
|
| @@ -136,7 +127,7 @@ void TestContextProvider::DeleteCachedResources() {
|
| }
|
|
|
| void TestContextProvider::OnLostContext() {
|
| - DCHECK(context_thread_checker_.CalledOnValidThread());
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| if (!lost_context_callback_.is_null())
|
| lost_context_callback_.Run();
|
| if (gr_context_)
|
| @@ -144,19 +135,13 @@ void TestContextProvider::OnLostContext() {
|
| }
|
|
|
| TestWebGraphicsContext3D* TestContextProvider::TestContext3d() {
|
| - DCHECK(bound_);
|
| - DCHECK(context_thread_checker_.CalledOnValidThread());
|
| -
|
| - return context3d_.get();
|
| -}
|
| -
|
| -TestWebGraphicsContext3D* TestContextProvider::UnboundTestContext3d() {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| return context3d_.get();
|
| }
|
|
|
| void TestContextProvider::SetLostContextCallback(
|
| const LostContextCallback& cb) {
|
| - DCHECK(context_thread_checker_.CalledOnValidThread());
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| DCHECK(lost_context_callback_.is_null() || cb.is_null());
|
| lost_context_callback_ = cb;
|
| }
|
|
|