[Sync] Fix invalidations on Android.
[chromium-blink-merge.git] / mojo / cc / context_provider_mojo.cc
blobaed1712e80a3f22d90e3990af8946306798dc6db
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.
5 #include "mojo/cc/context_provider_mojo.h"
7 #include "base/logging.h"
8 #include "mojo/gpu/mojo_gles2_impl_autogen.h"
9 #include "third_party/mojo/src/mojo/public/cpp/environment/environment.h"
11 namespace mojo {
13 ContextProviderMojo::ContextProviderMojo(
14 ScopedMessagePipeHandle command_buffer_handle)
15 : command_buffer_handle_(command_buffer_handle.Pass()),
16 context_lost_(false) {
19 bool ContextProviderMojo::BindToCurrentThread() {
20 DCHECK(command_buffer_handle_.is_valid());
21 context_ = MojoGLES2CreateContext(command_buffer_handle_.release().value(),
22 &ContextLostThunk,
23 this,
24 Environment::GetDefaultAsyncWaiter());
25 context_gl_.reset(new MojoGLES2Impl(context_));
26 return !!context_;
29 gpu::gles2::GLES2Interface* ContextProviderMojo::ContextGL() {
30 return context_gl_.get();
33 gpu::ContextSupport* ContextProviderMojo::ContextSupport() {
34 if (!context_)
35 return NULL;
36 return static_cast<gpu::ContextSupport*>(
37 MojoGLES2GetContextSupport(context_));
40 class GrContext* ContextProviderMojo::GrContext() { return NULL; }
42 cc::ContextProvider::Capabilities ContextProviderMojo::ContextCapabilities() {
43 return capabilities_;
46 void ContextProviderMojo::SetupLock() {
49 base::Lock* ContextProviderMojo::GetLock() {
50 return &context_lock_;
53 bool ContextProviderMojo::IsContextLost() {
54 return context_lost_;
56 bool ContextProviderMojo::DestroyedOnMainThread() { return !context_; }
58 ContextProviderMojo::~ContextProviderMojo() {
59 context_gl_.reset();
60 if (context_)
61 MojoGLES2DestroyContext(context_);
64 void ContextProviderMojo::ContextLost() {
65 context_lost_ = true;
68 } // namespace mojo