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/gles2/gles2_context.h"
9 #include "mojo/gpu/mojo_gles2_impl_autogen.h"
10 #include "third_party/mojo/src/mojo/public/cpp/environment/environment.h"
14 ContextProviderMojo::ContextProviderMojo(
15 ScopedMessagePipeHandle command_buffer_handle
)
16 : command_buffer_handle_(command_buffer_handle
.Pass()),
18 // Enabled the CHROMIUM_image extension to use GpuMemoryBuffers. The
19 // implementation of which is used in CommandBufferDriver.
20 capabilities_
.gpu
.image
= true;
23 bool ContextProviderMojo::BindToCurrentThread() {
24 DCHECK(command_buffer_handle_
.is_valid());
25 context_
= MojoGLES2CreateContext(command_buffer_handle_
.release().value(),
28 Environment::GetDefaultAsyncWaiter());
29 context_gl_
.reset(new MojoGLES2Impl(context_
));
33 gpu::gles2::GLES2Interface
* ContextProviderMojo::ContextGL() {
34 return context_gl_
.get();
37 gpu::ContextSupport
* ContextProviderMojo::ContextSupport() {
40 // TODO(rjkroege): Ensure that UIP does not take this code path.
41 return static_cast<gles2::GLES2Context
*>(context_
)->context_support();
44 class GrContext
* ContextProviderMojo::GrContext() { return NULL
; }
46 void ContextProviderMojo::InvalidateGrContext(uint32_t state
) {
49 cc::ContextProvider::Capabilities
ContextProviderMojo::ContextCapabilities() {
53 void ContextProviderMojo::SetupLock() {
56 base::Lock
* ContextProviderMojo::GetLock() {
57 return &context_lock_
;
60 bool ContextProviderMojo::DestroyedOnMainThread() { return !context_
; }
62 ContextProviderMojo::~ContextProviderMojo() {
65 MojoGLES2DestroyContext(context_
);
68 void ContextProviderMojo::ContextLost() {