OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mojo/cc/context_provider_mojo.h" | 5 #include "mojo/cc/context_provider_mojo.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "mojo/public/cpp/environment/environment.h" | 8 #include "mojo/public/cpp/environment/environment.h" |
9 | 9 |
10 namespace mojo { | 10 namespace mojo { |
11 | 11 |
12 ContextProviderMojo::ContextProviderMojo( | 12 ContextProviderMojo::ContextProviderMojo( |
13 ScopedMessagePipeHandle command_buffer_handle) | 13 ScopedMessagePipeHandle command_buffer_handle) |
14 : command_buffer_handle_(command_buffer_handle.Pass()), | 14 : command_buffer_handle_(command_buffer_handle.Pass()), |
| 15 context_(nullptr), |
15 context_lost_(false) { | 16 context_lost_(false) { |
16 } | 17 } |
17 | 18 |
18 bool ContextProviderMojo::BindToCurrentThread() { | 19 bool ContextProviderMojo::BindToCurrentThread() { |
19 DCHECK(command_buffer_handle_.is_valid()); | 20 DCHECK(command_buffer_handle_.is_valid()); |
20 context_ = MojoGLES2CreateContext(command_buffer_handle_.release().value(), | 21 context_ = MojoGLES2CreateContext(command_buffer_handle_.release().value(), |
21 &ContextLostThunk, | 22 &ContextLostThunk, |
22 this, | 23 this, |
23 Environment::GetDefaultAsyncWaiter()); | 24 Environment::GetDefaultAsyncWaiter()); |
24 return !!context_; | 25 return !!context_; |
25 } | 26 } |
26 | 27 |
27 gpu::gles2::GLES2Interface* ContextProviderMojo::ContextGL() { | 28 gpu::gles2::GLES2Interface* ContextProviderMojo::ContextGL() { |
28 if (!context_) | 29 if (!context_) |
29 return NULL; | 30 return nullptr; |
30 return static_cast<gpu::gles2::GLES2Interface*>( | 31 return static_cast<gpu::gles2::GLES2Interface*>( |
31 MojoGLES2GetGLES2Interface(context_)); | 32 MojoGLES2GetGLES2Interface(context_)); |
32 } | 33 } |
33 | 34 |
34 gpu::ContextSupport* ContextProviderMojo::ContextSupport() { | 35 gpu::ContextSupport* ContextProviderMojo::ContextSupport() { |
35 if (!context_) | 36 if (!context_) |
36 return NULL; | 37 return nullptr; |
37 return static_cast<gpu::ContextSupport*>( | 38 return static_cast<gpu::ContextSupport*>( |
38 MojoGLES2GetContextSupport(context_)); | 39 MojoGLES2GetContextSupport(context_)); |
39 } | 40 } |
40 | 41 |
41 class GrContext* ContextProviderMojo::GrContext() { return NULL; } | 42 class GrContext* ContextProviderMojo::GrContext() { return NULL; } |
42 | 43 |
43 cc::ContextProvider::Capabilities ContextProviderMojo::ContextCapabilities() { | 44 cc::ContextProvider::Capabilities ContextProviderMojo::ContextCapabilities() { |
44 return capabilities_; | 45 return capabilities_; |
45 } | 46 } |
46 | 47 |
47 bool ContextProviderMojo::IsContextLost() { | 48 bool ContextProviderMojo::IsContextLost() { |
48 return context_lost_; | 49 return context_lost_; |
49 } | 50 } |
50 bool ContextProviderMojo::DestroyedOnMainThread() { return !context_; } | 51 bool ContextProviderMojo::DestroyedOnMainThread() { return !context_; } |
51 | 52 |
52 ContextProviderMojo::~ContextProviderMojo() { | 53 ContextProviderMojo::~ContextProviderMojo() { |
53 if (context_) | 54 if (context_) |
54 MojoGLES2DestroyContext(context_); | 55 MojoGLES2DestroyContext(context_); |
55 } | 56 } |
56 | 57 |
57 void ContextProviderMojo::ContextLost() { | 58 void ContextProviderMojo::ContextLost() { |
58 context_lost_ = true; | 59 context_lost_ = true; |
59 } | 60 } |
60 | 61 |
61 } // namespace mojo | 62 } // namespace mojo |
OLD | NEW |