Rename InputLatency::ScrollUpdate to Latency::ScrollUpdate
[chromium-blink-merge.git] / components / surfaces / context_provider_mojo.cc
blobf9efbcc4a826d8bb1ad0d5ff9cbda6d080e8cd9a
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 "components/surfaces/context_provider_mojo.h"
7 #include "base/logging.h"
8 #include "third_party/mojo/src/mojo/public/cpp/environment/environment.h"
10 namespace mojo {
12 ContextProviderMojo::ContextProviderMojo(
13 ScopedMessagePipeHandle command_buffer_handle)
14 : command_buffer_handle_(command_buffer_handle.Pass()),
15 context_(nullptr),
16 context_lost_(false) {
19 bool ContextProviderMojo::BindToCurrentThread() {
20 DCHECK(command_buffer_handle_.is_valid());
21 context_ = MojoGLES2CreateContext(command_buffer_handle_.release().value(),
22 &ContextLostThunk, this,
23 Environment::GetDefaultAsyncWaiter());
24 DCHECK(context_);
25 return !!context_;
28 gpu::gles2::GLES2Interface* ContextProviderMojo::ContextGL() {
29 if (!context_)
30 return nullptr;
31 return static_cast<gpu::gles2::GLES2Interface*>(
32 MojoGLES2GetGLES2Interface(context_));
35 gpu::ContextSupport* ContextProviderMojo::ContextSupport() {
36 if (!context_)
37 return nullptr;
38 return static_cast<gpu::ContextSupport*>(
39 MojoGLES2GetContextSupport(context_));
42 class GrContext* ContextProviderMojo::GrContext() {
43 return NULL;
46 cc::ContextProvider::Capabilities ContextProviderMojo::ContextCapabilities() {
47 return capabilities_;
50 void ContextProviderMojo::SetupLock() {
53 base::Lock* ContextProviderMojo::GetLock() {
54 return &context_lock_;
57 bool ContextProviderMojo::IsContextLost() {
58 return context_lost_;
60 bool ContextProviderMojo::DestroyedOnMainThread() {
61 return !context_;
64 void ContextProviderMojo::SetLostContextCallback(
65 const LostContextCallback& lost_context_callback) {
66 lost_context_callback_ = lost_context_callback;
69 ContextProviderMojo::~ContextProviderMojo() {
70 if (context_)
71 MojoGLES2DestroyContext(context_);
74 void ContextProviderMojo::ContextLost() {
75 context_lost_ = true;
76 if (!lost_context_callback_.is_null())
77 lost_context_callback_.Run();
80 } // namespace mojo