OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/test/fake_context_provider.h" | 5 #include "cc/debug/fake_context_provider.h" |
6 | 6 |
7 #include "cc/test/test_web_graphics_context_3d.h" | 7 #include "base/logging.h" |
| 8 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
8 | 9 |
9 namespace cc { | 10 namespace cc { |
10 | 11 |
11 FakeContextProvider::FakeContextProvider() | 12 FakeContextProvider::FakeContextProvider() |
12 : bound_(false), | 13 : bound_(false), |
13 destroyed_(false) { | 14 destroyed_(false) { |
14 DCHECK(main_thread_checker_.CalledOnValidThread()); | 15 DCHECK(main_thread_checker_.CalledOnValidThread()); |
15 context_thread_checker_.DetachFromThread(); | 16 context_thread_checker_.DetachFromThread(); |
16 } | 17 } |
17 | 18 |
18 FakeContextProvider::~FakeContextProvider() { | 19 FakeContextProvider::~FakeContextProvider() { |
19 DCHECK(main_thread_checker_.CalledOnValidThread() || | 20 DCHECK(main_thread_checker_.CalledOnValidThread() || |
20 context_thread_checker_.CalledOnValidThread()); | 21 context_thread_checker_.CalledOnValidThread()); |
21 } | 22 } |
22 | 23 |
23 bool FakeContextProvider::InitializeOnMainThread( | 24 bool FakeContextProvider::InitializeOnMainThread( |
24 const CreateCallback& create_callback) { | 25 const CreateCallback& create_callback) { |
25 DCHECK(main_thread_checker_.CalledOnValidThread()); | 26 DCHECK(main_thread_checker_.CalledOnValidThread()); |
26 | 27 |
27 DCHECK(!context3d_); | 28 DCHECK(!context3d_); |
28 if (create_callback.is_null()) | 29 DCHECK(!create_callback.is_null()); |
29 context3d_ = TestWebGraphicsContext3D::Create().Pass(); | 30 context3d_ = create_callback.Run(); |
30 else | |
31 context3d_ = create_callback.Run(); | |
32 return context3d_; | 31 return context3d_; |
33 } | 32 } |
34 | 33 |
35 bool FakeContextProvider::BindToCurrentThread() { | 34 bool FakeContextProvider::BindToCurrentThread() { |
36 DCHECK(context3d_); | 35 DCHECK(context3d_); |
37 | 36 |
38 // This is called on the thread the context will be used. | 37 // This is called on the thread the context will be used. |
39 DCHECK(context_thread_checker_.CalledOnValidThread()); | 38 DCHECK(context_thread_checker_.CalledOnValidThread()); |
40 | 39 |
41 if (bound_) | 40 if (bound_) |
42 return true; | 41 return true; |
43 | 42 |
44 bound_ = true; | 43 bound_ = true; |
45 if (!context3d_->makeContextCurrent()) { | 44 if (!context3d_->makeContextCurrent()) { |
46 base::AutoLock lock(destroyed_lock_); | 45 base::AutoLock lock(destroyed_lock_); |
47 destroyed_ = true; | 46 destroyed_ = true; |
48 return false; | 47 return false; |
49 } | 48 } |
50 return true; | 49 return true; |
51 } | 50 } |
52 | 51 |
53 WebKit::WebGraphicsContext3D* FakeContextProvider::Context3d() { | 52 WebKit::WebGraphicsContext3D* FakeContextProvider::Context3d() { |
54 DCHECK(context3d_); | 53 DCHECK(context3d_); |
55 DCHECK(bound_); | 54 DCHECK(bound_); |
56 DCHECK(context_thread_checker_.CalledOnValidThread()); | 55 DCHECK(context_thread_checker_.CalledOnValidThread()); |
57 | 56 |
58 return context3d_.get(); | 57 return context3d_.get(); |
59 } | 58 } |
| 59 |
60 class GrContext* FakeContextProvider::GrContext() { | 60 class GrContext* FakeContextProvider::GrContext() { |
61 DCHECK(context3d_); | 61 DCHECK(context3d_); |
62 DCHECK(bound_); | 62 DCHECK(bound_); |
63 DCHECK(context_thread_checker_.CalledOnValidThread()); | 63 DCHECK(context_thread_checker_.CalledOnValidThread()); |
64 | 64 |
65 // TODO(danakj): Make a fake GrContext. | 65 // TODO(danakj): Make a fake GrContext that works with a fake Context3d. |
66 return NULL; | 66 return NULL; |
67 } | 67 } |
68 | 68 |
69 void FakeContextProvider::VerifyContexts() { | 69 void FakeContextProvider::VerifyContexts() { |
70 DCHECK(context3d_); | 70 DCHECK(context3d_); |
71 DCHECK(bound_); | 71 DCHECK(bound_); |
72 DCHECK(context_thread_checker_.CalledOnValidThread()); | 72 DCHECK(context_thread_checker_.CalledOnValidThread()); |
73 | 73 |
74 if (context3d_->isContextLost()) { | 74 if (context3d_->isContextLost()) { |
75 base::AutoLock lock(destroyed_lock_); | 75 base::AutoLock lock(destroyed_lock_); |
76 destroyed_ = true; | 76 destroyed_ = true; |
77 } | 77 } |
78 } | 78 } |
79 | 79 |
80 bool FakeContextProvider::DestroyedOnMainThread() { | 80 bool FakeContextProvider::DestroyedOnMainThread() { |
81 DCHECK(main_thread_checker_.CalledOnValidThread()); | 81 DCHECK(main_thread_checker_.CalledOnValidThread()); |
82 | 82 |
83 base::AutoLock lock(destroyed_lock_); | 83 base::AutoLock lock(destroyed_lock_); |
84 return destroyed_; | 84 return destroyed_; |
85 } | 85 } |
86 | 86 |
87 void FakeContextProvider::SetLostContextCallback( | 87 void FakeContextProvider::SetLostContextCallback( |
88 const LostContextCallback& cb) { | 88 const LostContextCallback& cb) { |
89 DCHECK(context_thread_checker_.CalledOnValidThread()); | 89 DCHECK(context_thread_checker_.CalledOnValidThread()); |
90 NOTIMPLEMENTED(); | 90 NOTIMPLEMENTED(); |
91 } | 91 } |
92 | 92 |
93 } // namespace cc | 93 } // namespace cc |
OLD | NEW |