| 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 "components/view_manager/surfaces/surfaces_context_provider.h" | 5 #include "components/view_manager/surfaces/surfaces_context_provider.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "third_party/mojo/src/mojo/public/cpp/environment/environment.h" | 8 #include "third_party/mojo/src/mojo/public/cpp/environment/environment.h" |
| 9 | 9 |
| 10 namespace surfaces { | 10 namespace surfaces { |
| 11 | 11 |
| 12 SurfacesContextProvider::SurfacesContextProvider( | 12 SurfacesContextProvider::SurfacesContextProvider( |
| 13 mojo::ScopedMessagePipeHandle command_buffer_handle) | 13 mojo::ScopedMessagePipeHandle command_buffer_handle) |
| 14 : command_buffer_handle_(command_buffer_handle.Pass()), | 14 : command_buffer_handle_(command_buffer_handle.Pass()), context_(nullptr) { |
| 15 context_(nullptr), | |
| 16 context_lost_(false) { | |
| 17 } | 15 } |
| 18 | 16 |
| 19 bool SurfacesContextProvider::BindToCurrentThread() { | 17 bool SurfacesContextProvider::BindToCurrentThread() { |
| 20 DCHECK(command_buffer_handle_.is_valid()); | 18 DCHECK(command_buffer_handle_.is_valid()); |
| 21 context_ = MojoGLES2CreateContext(command_buffer_handle_.release().value(), | 19 context_ = MojoGLES2CreateContext(command_buffer_handle_.release().value(), |
| 22 &ContextLostThunk, this, | 20 &ContextLostThunk, this, |
| 23 mojo::Environment::GetDefaultAsyncWaiter()); | 21 mojo::Environment::GetDefaultAsyncWaiter()); |
| 24 DCHECK(context_); | 22 DCHECK(context_); |
| 25 return !!context_; | 23 return !!context_; |
| 26 } | 24 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 51 return capabilities_; | 49 return capabilities_; |
| 52 } | 50 } |
| 53 | 51 |
| 54 void SurfacesContextProvider::SetupLock() { | 52 void SurfacesContextProvider::SetupLock() { |
| 55 } | 53 } |
| 56 | 54 |
| 57 base::Lock* SurfacesContextProvider::GetLock() { | 55 base::Lock* SurfacesContextProvider::GetLock() { |
| 58 return &context_lock_; | 56 return &context_lock_; |
| 59 } | 57 } |
| 60 | 58 |
| 61 bool SurfacesContextProvider::IsContextLost() { | |
| 62 return context_lost_; | |
| 63 } | |
| 64 bool SurfacesContextProvider::DestroyedOnMainThread() { | 59 bool SurfacesContextProvider::DestroyedOnMainThread() { |
| 65 return !context_; | 60 return !context_; |
| 66 } | 61 } |
| 67 | 62 |
| 68 void SurfacesContextProvider::SetLostContextCallback( | 63 void SurfacesContextProvider::SetLostContextCallback( |
| 69 const LostContextCallback& lost_context_callback) { | 64 const LostContextCallback& lost_context_callback) { |
| 70 lost_context_callback_ = lost_context_callback; | 65 lost_context_callback_ = lost_context_callback; |
| 71 } | 66 } |
| 72 | 67 |
| 73 SurfacesContextProvider::~SurfacesContextProvider() { | 68 SurfacesContextProvider::~SurfacesContextProvider() { |
| 74 if (context_) | 69 if (context_) |
| 75 MojoGLES2DestroyContext(context_); | 70 MojoGLES2DestroyContext(context_); |
| 76 } | 71 } |
| 77 | 72 |
| 78 void SurfacesContextProvider::ContextLost() { | 73 void SurfacesContextProvider::ContextLost() { |
| 79 context_lost_ = true; | |
| 80 if (!lost_context_callback_.is_null()) | 74 if (!lost_context_callback_.is_null()) |
| 81 lost_context_callback_.Run(); | 75 lost_context_callback_.Run(); |
| 82 } | 76 } |
| 83 | 77 |
| 84 } // namespace surfaces | 78 } // namespace surfaces |
| OLD | NEW |