Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / mojo / cc / context_provider_mojo.cc
blobed8643de382ac1df465eb56be3aa7b284888bccd
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"
12 namespace mojo {
14 ContextProviderMojo::ContextProviderMojo(
15 ScopedMessagePipeHandle command_buffer_handle)
16 : command_buffer_handle_(command_buffer_handle.Pass()),
17 context_(nullptr) {
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(),
26 nullptr,
27 &ContextLostThunk,
28 this,
29 Environment::GetDefaultAsyncWaiter());
30 context_gl_.reset(new MojoGLES2Impl(context_));
31 return !!context_;
34 gpu::gles2::GLES2Interface* ContextProviderMojo::ContextGL() {
35 return context_gl_.get();
38 gpu::ContextSupport* ContextProviderMojo::ContextSupport() {
39 if (!context_)
40 return NULL;
41 // TODO(rjkroege): Ensure that UIP does not take this code path.
42 return static_cast<gles2::GLES2Context*>(context_)->context_support();
45 class GrContext* ContextProviderMojo::GrContext() { return NULL; }
47 void ContextProviderMojo::InvalidateGrContext(uint32_t state) {
50 cc::ContextProvider::Capabilities ContextProviderMojo::ContextCapabilities() {
51 return capabilities_;
54 void ContextProviderMojo::SetupLock() {
57 base::Lock* ContextProviderMojo::GetLock() {
58 return &context_lock_;
61 bool ContextProviderMojo::DestroyedOnMainThread() { return !context_; }
63 ContextProviderMojo::~ContextProviderMojo() {
64 context_gl_.reset();
65 if (context_)
66 MojoGLES2DestroyContext(context_);
69 void ContextProviderMojo::ContextLost() {
72 } // namespace mojo