1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/test/fake_context_provider.h"
8 #include "cc/test/test_web_graphics_context_3d.h"
13 scoped_refptr
<FakeContextProvider
> FakeContextProvider::
14 CreateForOtherThread() {
15 scoped_refptr
<FakeContextProvider
> provider
= new FakeContextProvider();
16 if (!provider
->InitializeOnMainThread())
21 static scoped_ptr
<TestWebGraphicsContext3D
> ReturnContext(
22 scoped_ptr
<TestWebGraphicsContext3D
> context3d
) {
23 return context3d
.Pass();
27 scoped_refptr
<FakeContextProvider
> FakeContextProvider::CreateForOtherThread(
28 scoped_ptr
<TestWebGraphicsContext3D
> context3d
) {
29 CreateCallback create_callback
=
30 base::Bind(&ReturnContext
, base::Passed(&context3d
));
31 scoped_refptr
<FakeContextProvider
> provider
=
32 new FakeContextProvider(create_callback
);
33 if (!provider
->InitializeOnMainThread())
39 scoped_refptr
<FakeContextProvider
> FakeContextProvider::CreateForOtherThread(
40 const CreateCallback
& create_callback
) {
41 scoped_refptr
<FakeContextProvider
> provider
=
42 new FakeContextProvider(create_callback
);
43 if (!provider
->InitializeOnMainThread())
48 FakeContextProvider::FakeContextProvider()
52 FakeContextProvider::FakeContextProvider(
53 const CreateCallback
& create_callback
)
54 : create_callback_(create_callback
),
59 FakeContextProvider::~FakeContextProvider() {}
61 bool FakeContextProvider::InitializeOnMainThread() {
64 if (create_callback_
.is_null())
65 context3d_
= TestWebGraphicsContext3D::Create().Pass();
67 context3d_
= create_callback_
.Run();
71 bool FakeContextProvider::BindToCurrentThread() {
73 if (!context3d_
->makeContextCurrent()) {
74 base::AutoLock
lock(destroyed_lock_
);
81 WebKit::WebGraphicsContext3D
* FakeContextProvider::Context3d() {
85 return context3d_
.get();
87 class GrContext
* FakeContextProvider::GrContext() {
91 // TODO(danakj): Make a fake GrContext.
95 void FakeContextProvider::VerifyContexts() {
99 if (context3d_
->isContextLost()) {
100 base::AutoLock
lock(destroyed_lock_
);
105 bool FakeContextProvider::DestroyedOnMainThread() {
106 base::AutoLock
lock(destroyed_lock_
);