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