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