When enabling new profile management programmatically, make sure to set the
[chromium-blink-merge.git] / mojo / cc / context_provider_mojo.cc
blob7356b587c4064e10048bde6be72f9ac188429cea
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"
9 namespace mojo {
11 ContextProviderMojo::ContextProviderMojo(
12 ScopedMessagePipeHandle command_buffer_handle)
13 : command_buffer_handle_(command_buffer_handle.Pass()) {}
15 bool ContextProviderMojo::BindToCurrentThread() {
16 DCHECK(command_buffer_handle_.is_valid());
17 context_ = MojoGLES2CreateContext(
18 command_buffer_handle_.release().value(),
19 &ContextLostThunk,
20 NULL,
21 this);
22 return !!context_;
25 gpu::gles2::GLES2Interface* ContextProviderMojo::ContextGL() {
26 if (!context_)
27 return NULL;
28 return static_cast<gpu::gles2::GLES2Interface*>(
29 MojoGLES2GetGLES2Interface(context_));
32 gpu::ContextSupport* ContextProviderMojo::ContextSupport() {
33 if (!context_)
34 return NULL;
35 return static_cast<gpu::ContextSupport*>(
36 MojoGLES2GetContextSupport(context_));
39 class GrContext* ContextProviderMojo::GrContext() { return NULL; }
41 cc::ContextProvider::Capabilities ContextProviderMojo::ContextCapabilities() {
42 return capabilities_;
45 bool ContextProviderMojo::IsContextLost() { return !context_; }
46 bool ContextProviderMojo::DestroyedOnMainThread() { return !context_; }
48 ContextProviderMojo::~ContextProviderMojo() {
49 if (context_)
50 MojoGLES2DestroyContext(context_);
53 void ContextProviderMojo::ContextLost() {
54 if (context_) {
55 MojoGLES2DestroyContext(context_);
56 context_ = NULL;
60 } // namespace mojo