fixup! cc: Handle overflow/underflow in MathUtil::RoundUp/RoundDown
[chromium-blink-merge.git] / mojo / cc / context_provider_mojo.cc
blob5b0a640287fd8176bf0f9cb776583b395876fcad
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_(nullptr) {
17 // Enabled the CHROMIUM_image extension to use GpuMemoryBuffers. The
18 // implementation of which is used in CommandBufferDriver.
19 capabilities_.gpu.image = true;
22 bool ContextProviderMojo::BindToCurrentThread() {
23 DCHECK(command_buffer_handle_.is_valid());
24 context_ = MojoGLES2CreateContext(command_buffer_handle_.release().value(),
25 &ContextLostThunk,
26 this,
27 Environment::GetDefaultAsyncWaiter());
28 context_gl_.reset(new MojoGLES2Impl(context_));
29 return !!context_;
32 gpu::gles2::GLES2Interface* ContextProviderMojo::ContextGL() {
33 return context_gl_.get();
36 gpu::ContextSupport* ContextProviderMojo::ContextSupport() {
37 if (!context_)
38 return NULL;
39 return static_cast<gpu::ContextSupport*>(
40 MojoGLES2GetContextSupport(context_));
43 class GrContext* ContextProviderMojo::GrContext() { return NULL; }
45 void ContextProviderMojo::InvalidateGrContext(uint32_t state) {
48 cc::ContextProvider::Capabilities ContextProviderMojo::ContextCapabilities() {
49 return capabilities_;
52 void ContextProviderMojo::SetupLock() {
55 base::Lock* ContextProviderMojo::GetLock() {
56 return &context_lock_;
59 bool ContextProviderMojo::DestroyedOnMainThread() { return !context_; }
61 ContextProviderMojo::~ContextProviderMojo() {
62 context_gl_.reset();
63 if (context_)
64 MojoGLES2DestroyContext(context_);
67 void ContextProviderMojo::ContextLost() {
70 } // namespace mojo