| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/cc/context_provider_mojo.h" | 5 #include "mojo/services/surfaces/context_provider_mojo.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "mojo/gpu/mojo_gles2_impl_autogen.h" | 8 #include "mojo/public/cpp/environment/environment.h" |
| 9 #include "third_party/mojo/src/mojo/public/cpp/environment/environment.h" | |
| 10 | 9 |
| 11 namespace mojo { | 10 namespace mojo { |
| 12 | 11 |
| 13 ContextProviderMojo::ContextProviderMojo( | 12 ContextProviderMojo::ContextProviderMojo( |
| 14 ScopedMessagePipeHandle command_buffer_handle) | 13 ScopedMessagePipeHandle command_buffer_handle) |
| 15 : command_buffer_handle_(command_buffer_handle.Pass()), | 14 : command_buffer_handle_(command_buffer_handle.Pass()), |
| 15 context_(nullptr), |
| 16 context_lost_(false) { | 16 context_lost_(false) { |
| 17 } | 17 } |
| 18 | 18 |
| 19 bool ContextProviderMojo::BindToCurrentThread() { | 19 bool ContextProviderMojo::BindToCurrentThread() { |
| 20 DCHECK(command_buffer_handle_.is_valid()); | 20 DCHECK(command_buffer_handle_.is_valid()); |
| 21 context_ = MojoGLES2CreateContext(command_buffer_handle_.release().value(), | 21 context_ = MojoGLES2CreateContext(command_buffer_handle_.release().value(), |
| 22 &ContextLostThunk, | 22 &ContextLostThunk, this, |
| 23 this, | |
| 24 Environment::GetDefaultAsyncWaiter()); | 23 Environment::GetDefaultAsyncWaiter()); |
| 25 context_gl_.reset(new MojoGLES2Impl(context_)); | 24 DCHECK(context_); |
| 26 return !!context_; | 25 return !!context_; |
| 27 } | 26 } |
| 28 | 27 |
| 29 gpu::gles2::GLES2Interface* ContextProviderMojo::ContextGL() { | 28 gpu::gles2::GLES2Interface* ContextProviderMojo::ContextGL() { |
| 30 return context_gl_.get(); | 29 if (!context_) |
| 30 return nullptr; |
| 31 return static_cast<gpu::gles2::GLES2Interface*>( |
| 32 MojoGLES2GetGLES2Interface(context_)); |
| 31 } | 33 } |
| 32 | 34 |
| 33 gpu::ContextSupport* ContextProviderMojo::ContextSupport() { | 35 gpu::ContextSupport* ContextProviderMojo::ContextSupport() { |
| 34 if (!context_) | 36 if (!context_) |
| 35 return NULL; | 37 return nullptr; |
| 36 return static_cast<gpu::ContextSupport*>( | 38 return static_cast<gpu::ContextSupport*>( |
| 37 MojoGLES2GetContextSupport(context_)); | 39 MojoGLES2GetContextSupport(context_)); |
| 38 } | 40 } |
| 39 | 41 |
| 40 class GrContext* ContextProviderMojo::GrContext() { return NULL; } | 42 class GrContext* ContextProviderMojo::GrContext() { |
| 43 return NULL; |
| 44 } |
| 41 | 45 |
| 42 cc::ContextProvider::Capabilities ContextProviderMojo::ContextCapabilities() { | 46 cc::ContextProvider::Capabilities ContextProviderMojo::ContextCapabilities() { |
| 43 return capabilities_; | 47 return capabilities_; |
| 44 } | 48 } |
| 45 | 49 |
| 46 void ContextProviderMojo::SetupLock() { | 50 void ContextProviderMojo::SetupLock() { |
| 47 } | 51 } |
| 48 | 52 |
| 49 base::Lock* ContextProviderMojo::GetLock() { | 53 base::Lock* ContextProviderMojo::GetLock() { |
| 50 return &context_lock_; | 54 return &context_lock_; |
| 51 } | 55 } |
| 52 | 56 |
| 53 bool ContextProviderMojo::IsContextLost() { | 57 bool ContextProviderMojo::IsContextLost() { |
| 54 return context_lost_; | 58 return context_lost_; |
| 55 } | 59 } |
| 56 bool ContextProviderMojo::DestroyedOnMainThread() { return !context_; } | 60 bool ContextProviderMojo::DestroyedOnMainThread() { |
| 61 return !context_; |
| 62 } |
| 63 |
| 64 void ContextProviderMojo::SetLostContextCallback( |
| 65 const LostContextCallback& lost_context_callback) { |
| 66 lost_context_callback_ = lost_context_callback; |
| 67 } |
| 57 | 68 |
| 58 ContextProviderMojo::~ContextProviderMojo() { | 69 ContextProviderMojo::~ContextProviderMojo() { |
| 59 context_gl_.reset(); | |
| 60 if (context_) | 70 if (context_) |
| 61 MojoGLES2DestroyContext(context_); | 71 MojoGLES2DestroyContext(context_); |
| 62 } | 72 } |
| 63 | 73 |
| 64 void ContextProviderMojo::ContextLost() { | 74 void ContextProviderMojo::ContextLost() { |
| 65 context_lost_ = true; | 75 context_lost_ = true; |
| 76 if (!lost_context_callback_.is_null()) |
| 77 lost_context_callback_.Run(); |
| 66 } | 78 } |
| 67 | 79 |
| 68 } // namespace mojo | 80 } // namespace mojo |
| OLD | NEW |