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"
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());
27 gpu::gles2::GLES2Interface
* SurfacesContextProvider::ContextGL() {
30 return static_cast<gpu::gles2::GLES2Interface
*>(
31 MojoGLES2GetGLES2Interface(context_
));
34 gpu::ContextSupport
* SurfacesContextProvider::ContextSupport() {
37 return static_cast<gpu::ContextSupport
*>(
38 MojoGLES2GetContextSupport(context_
));
41 class GrContext
* SurfacesContextProvider::GrContext() {
45 void SurfacesContextProvider::InvalidateGrContext(uint32_t state
) {
48 cc::ContextProvider::Capabilities
49 SurfacesContextProvider::ContextCapabilities() {
53 void SurfacesContextProvider::SetupLock() {
56 base::Lock
* SurfacesContextProvider::GetLock() {
57 return &context_lock_
;
60 bool SurfacesContextProvider::DestroyedOnMainThread() {
64 void SurfacesContextProvider::SetLostContextCallback(
65 const LostContextCallback
& lost_context_callback
) {
66 lost_context_callback_
= lost_context_callback
;
69 SurfacesContextProvider::~SurfacesContextProvider() {
71 MojoGLES2DestroyContext(context_
);
74 void SurfacesContextProvider::ContextLost() {
75 if (!lost_context_callback_
.is_null())
76 lost_context_callback_
.Run();
79 } // namespace surfaces