Home | History | Annotate | Download | only in cc
      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 "mojo/cc/context_provider_mojo.h"
      6 
      7 #include "base/logging.h"
      8 
      9 namespace mojo {
     10 
     11 ContextProviderMojo::ContextProviderMojo(
     12     ScopedMessagePipeHandle command_buffer_handle)
     13     : command_buffer_handle_(command_buffer_handle.Pass()) {}
     14 
     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_;
     23 }
     24 
     25 gpu::gles2::GLES2Interface* ContextProviderMojo::ContextGL() {
     26   if (!context_)
     27     return NULL;
     28   return static_cast<gpu::gles2::GLES2Interface*>(
     29       MojoGLES2GetGLES2Interface(context_));
     30 }
     31 
     32 gpu::ContextSupport* ContextProviderMojo::ContextSupport() {
     33   if (!context_)
     34     return NULL;
     35   return static_cast<gpu::ContextSupport*>(
     36       MojoGLES2GetContextSupport(context_));
     37 }
     38 
     39 class GrContext* ContextProviderMojo::GrContext() { return NULL; }
     40 
     41 cc::ContextProvider::Capabilities ContextProviderMojo::ContextCapabilities() {
     42   return capabilities_;
     43 }
     44 
     45 bool ContextProviderMojo::IsContextLost() { return !context_; }
     46 bool ContextProviderMojo::DestroyedOnMainThread() { return !context_; }
     47 
     48 ContextProviderMojo::~ContextProviderMojo() {
     49   if (context_)
     50     MojoGLES2DestroyContext(context_);
     51 }
     52 
     53 void ContextProviderMojo::ContextLost() {
     54   if (context_) {
     55     MojoGLES2DestroyContext(context_);
     56     context_ = NULL;
     57   }
     58 }
     59 
     60 }  // namespace mojo
     61