cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / cc / test / fake_context_provider.cc
blob806eb4fabaa701c5dc88514336af37ab2daeeefa
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"
7 #include "base/bind.h"
8 #include "cc/test/test_web_graphics_context_3d.h"
10 namespace cc {
12 // static
13 scoped_refptr<FakeContextProvider> FakeContextProvider::
14 CreateForOtherThread() {
15 scoped_refptr<FakeContextProvider> provider = new FakeContextProvider();
16 if (!provider->InitializeOnMainThread())
17 return NULL;
18 return provider;
21 static scoped_ptr<TestWebGraphicsContext3D> ReturnContext(
22 scoped_ptr<TestWebGraphicsContext3D> context3d) {
23 return context3d.Pass();
26 // static
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())
34 return NULL;
35 return provider;
38 // static
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())
44 return NULL;
45 return provider;
48 FakeContextProvider::FakeContextProvider()
49 : destroyed_(false) {
52 FakeContextProvider::FakeContextProvider(
53 const CreateCallback& create_callback)
54 : create_callback_(create_callback),
55 bound_(false),
56 destroyed_(false) {
59 FakeContextProvider::~FakeContextProvider() {}
61 bool FakeContextProvider::InitializeOnMainThread() {
62 DCHECK(!context3d_);
64 if (create_callback_.is_null())
65 context3d_ = TestWebGraphicsContext3D::Create().Pass();
66 else
67 context3d_ = create_callback_.Run();
68 return context3d_;
71 bool FakeContextProvider::BindToCurrentThread() {
72 bound_ = true;
73 if (!context3d_->makeContextCurrent()) {
74 base::AutoLock lock(destroyed_lock_);
75 destroyed_ = true;
76 return false;
78 return true;
81 WebKit::WebGraphicsContext3D* FakeContextProvider::Context3d() {
82 DCHECK(context3d_);
83 DCHECK(bound_);
85 return context3d_.get();
87 class GrContext* FakeContextProvider::GrContext() {
88 DCHECK(context3d_);
89 DCHECK(bound_);
91 // TODO(danakj): Make a fake GrContext.
92 return NULL;
95 void FakeContextProvider::VerifyContexts() {
96 DCHECK(context3d_);
97 DCHECK(bound_);
99 if (context3d_->isContextLost()) {
100 base::AutoLock lock(destroyed_lock_);
101 destroyed_ = true;
105 bool FakeContextProvider::DestroyedOnMainThread() {
106 base::AutoLock lock(destroyed_lock_);
107 return destroyed_;
110 } // namespace cc