Allow only one bookmark to be added for multiple fast starring
[chromium-blink-merge.git] / components / view_manager / surfaces / surfaces_context_provider.cc
bloba398c38eebd691a32d1aa3e54cdb798dfb608ae1
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/view_manager/surfaces/surfaces_context_provider.h"
7 #include "base/logging.h"
8 #include "third_party/mojo/src/mojo/public/cpp/environment/environment.h"
10 namespace surfaces {
12 SurfacesContextProvider::SurfacesContextProvider(
13 mojo::ScopedMessagePipeHandle command_buffer_handle)
14 : command_buffer_handle_(command_buffer_handle.Pass()), context_(nullptr) {
15 capabilities_.gpu.image = true;
18 bool SurfacesContextProvider::BindToCurrentThread() {
19 DCHECK(command_buffer_handle_.is_valid());
20 context_ = MojoGLES2CreateContext(command_buffer_handle_.release().value(),
21 &ContextLostThunk, this,
22 mojo::Environment::GetDefaultAsyncWaiter());
23 DCHECK(context_);
24 return !!context_;
27 gpu::gles2::GLES2Interface* SurfacesContextProvider::ContextGL() {
28 if (!context_)
29 return nullptr;
30 return static_cast<gpu::gles2::GLES2Interface*>(
31 MojoGLES2GetGLES2Interface(context_));
34 gpu::ContextSupport* SurfacesContextProvider::ContextSupport() {
35 if (!context_)
36 return nullptr;
37 return static_cast<gpu::ContextSupport*>(
38 MojoGLES2GetContextSupport(context_));
41 class GrContext* SurfacesContextProvider::GrContext() {
42 return NULL;
45 void SurfacesContextProvider::InvalidateGrContext(uint32_t state) {
48 cc::ContextProvider::Capabilities
49 SurfacesContextProvider::ContextCapabilities() {
50 return capabilities_;
53 void SurfacesContextProvider::SetupLock() {
56 base::Lock* SurfacesContextProvider::GetLock() {
57 return &context_lock_;
60 bool SurfacesContextProvider::DestroyedOnMainThread() {
61 return !context_;
64 void SurfacesContextProvider::SetLostContextCallback(
65 const LostContextCallback& lost_context_callback) {
66 lost_context_callback_ = lost_context_callback;
69 SurfacesContextProvider::~SurfacesContextProvider() {
70 if (context_)
71 MojoGLES2DestroyContext(context_);
74 void SurfacesContextProvider::ContextLost() {
75 if (!lost_context_callback_.is_null())
76 lost_context_callback_.Run();
79 } // namespace surfaces