| 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 } | 16 } |
| 16 | 17 |
| 17 FakeContextProvider::~FakeContextProvider() { | 18 FakeContextProvider::~FakeContextProvider() { |
| 18 DCHECK(main_thread_checker_.CalledOnValidThread() || | 19 DCHECK(main_thread_checker_.CalledOnValidThread() || |
| 19 context_thread_checker_.CalledOnValidThread()); | 20 context_thread_checker_.CalledOnValidThread()); |
| 20 } | 21 } |
| 21 | 22 |
| 22 bool FakeContextProvider::InitializeOnMainThread( | 23 bool FakeContextProvider::InitializeOnMainThread( |
| 23 const CreateCallback& create_callback) { | 24 const CreateCallback& create_callback) { |
| 24 DCHECK(main_thread_checker_.CalledOnValidThread()); | 25 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 25 | 26 |
| 26 DCHECK(!context3d_); | 27 DCHECK(!context3d_); |
| 27 if (create_callback.is_null()) | 28 DCHECK(!create_callback.is_null()); |
| 28 context3d_ = TestWebGraphicsContext3D::Create().Pass(); | 29 context3d_ = create_callback.Run(); |
| 29 else | |
| 30 context3d_ = create_callback.Run(); | |
| 31 return context3d_; | 30 return context3d_; |
| 32 } | 31 } |
| 33 | 32 |
| 34 bool FakeContextProvider::BindToCurrentThread() { | 33 bool FakeContextProvider::BindToCurrentThread() { |
| 35 DCHECK(context3d_); | 34 DCHECK(context3d_); |
| 36 | 35 |
| 37 if (bound_) { | 36 if (bound_) { |
| 38 DCHECK(context_thread_checker_.CalledOnValidThread()); | 37 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 39 return true; | 38 return true; |
| 40 } | 39 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 52 return true; | 51 return true; |
| 53 } | 52 } |
| 54 | 53 |
| 55 WebKit::WebGraphicsContext3D* FakeContextProvider::Context3d() { | 54 WebKit::WebGraphicsContext3D* FakeContextProvider::Context3d() { |
| 56 DCHECK(context3d_); | 55 DCHECK(context3d_); |
| 57 DCHECK(bound_); | 56 DCHECK(bound_); |
| 58 DCHECK(context_thread_checker_.CalledOnValidThread()); | 57 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 59 | 58 |
| 60 return context3d_.get(); | 59 return context3d_.get(); |
| 61 } | 60 } |
| 61 |
| 62 class GrContext* FakeContextProvider::GrContext() { | 62 class GrContext* FakeContextProvider::GrContext() { |
| 63 DCHECK(context3d_); | 63 DCHECK(context3d_); |
| 64 DCHECK(bound_); | 64 DCHECK(bound_); |
| 65 DCHECK(context_thread_checker_.CalledOnValidThread()); | 65 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 66 | 66 |
| 67 // TODO(danakj): Make a fake GrContext. | 67 // TODO(danakj): Make a fake GrContext that works with a fake Context3d. |
| 68 return NULL; | 68 return NULL; |
| 69 } | 69 } |
| 70 | 70 |
| 71 void FakeContextProvider::VerifyContexts() { | 71 void FakeContextProvider::VerifyContexts() { |
| 72 DCHECK(context3d_); | 72 DCHECK(context3d_); |
| 73 DCHECK(bound_); | 73 DCHECK(bound_); |
| 74 DCHECK(context_thread_checker_.CalledOnValidThread()); | 74 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 75 | 75 |
| 76 if (context3d_->isContextLost()) { | 76 if (context3d_->isContextLost()) { |
| 77 base::AutoLock lock(destroyed_lock_); | 77 base::AutoLock lock(destroyed_lock_); |
| 78 destroyed_ = true; | 78 destroyed_ = true; |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 | 81 |
| 82 bool FakeContextProvider::DestroyedOnMainThread() { | 82 bool FakeContextProvider::DestroyedOnMainThread() { |
| 83 DCHECK(main_thread_checker_.CalledOnValidThread()); | 83 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 84 | 84 |
| 85 base::AutoLock lock(destroyed_lock_); | 85 base::AutoLock lock(destroyed_lock_); |
| 86 return destroyed_; | 86 return destroyed_; |
| 87 } | 87 } |
| 88 | 88 |
| 89 void FakeContextProvider::SetLostContextCallback( | 89 void FakeContextProvider::SetLostContextCallback( |
| 90 const LostContextCallback& cb) { | 90 const LostContextCallback& cb) { |
| 91 DCHECK(context_thread_checker_.CalledOnValidThread()); | 91 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 92 NOTIMPLEMENTED(); | 92 NOTIMPLEMENTED(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 } // namespace cc | 95 } // namespace cc |
| OLD | NEW |