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