| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ui/views/mus/surface_binding.h" | 5 #include "ui/views/mus/surface_binding.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 void Init(); | 58 void Init(); |
| 59 | 59 |
| 60 static base::LazyInstance< | 60 static base::LazyInstance< |
| 61 base::ThreadLocalPointer<ConnectionToStateMap>>::Leaky window_states; | 61 base::ThreadLocalPointer<ConnectionToStateMap>>::Leaky window_states; |
| 62 | 62 |
| 63 mojo::Shell* shell_; | 63 mojo::Shell* shell_; |
| 64 mus::WindowTreeConnection* connection_; | 64 mus::WindowTreeConnection* connection_; |
| 65 | 65 |
| 66 // Set of state needed to create an OutputSurface. | 66 // Set of state needed to create an OutputSurface. |
| 67 mojo::GpuPtr gpu_; | 67 mus::mojom::GpuPtr gpu_; |
| 68 | 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(PerConnectionState); | 69 DISALLOW_COPY_AND_ASSIGN(PerConnectionState); |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 // static | 72 // static |
| 73 base::LazyInstance<base::ThreadLocalPointer< | 73 base::LazyInstance<base::ThreadLocalPointer< |
| 74 SurfaceBinding::PerConnectionState::ConnectionToStateMap>>::Leaky | 74 SurfaceBinding::PerConnectionState::ConnectionToStateMap>>::Leaky |
| 75 SurfaceBinding::PerConnectionState::window_states; | 75 SurfaceBinding::PerConnectionState::window_states; |
| 76 | 76 |
| 77 // static | 77 // static |
| 78 SurfaceBinding::PerConnectionState* SurfaceBinding::PerConnectionState::Get( | 78 SurfaceBinding::PerConnectionState* SurfaceBinding::PerConnectionState::Get( |
| 79 mojo::Shell* shell, | 79 mojo::Shell* shell, |
| 80 mus::WindowTreeConnection* connection) { | 80 mus::WindowTreeConnection* connection) { |
| 81 ConnectionToStateMap* window_map = window_states.Pointer()->Get(); | 81 ConnectionToStateMap* window_map = window_states.Pointer()->Get(); |
| 82 if (!window_map) { | 82 if (!window_map) { |
| 83 window_map = new ConnectionToStateMap; | 83 window_map = new ConnectionToStateMap; |
| 84 window_states.Pointer()->Set(window_map); | 84 window_states.Pointer()->Set(window_map); |
| 85 } | 85 } |
| 86 if (!(*window_map)[connection]) { | 86 if (!(*window_map)[connection]) { |
| 87 (*window_map)[connection] = new PerConnectionState(shell, connection); | 87 (*window_map)[connection] = new PerConnectionState(shell, connection); |
| 88 (*window_map)[connection]->Init(); | 88 (*window_map)[connection]->Init(); |
| 89 } | 89 } |
| 90 return (*window_map)[connection]; | 90 return (*window_map)[connection]; |
| 91 } | 91 } |
| 92 | 92 |
| 93 scoped_ptr<cc::OutputSurface> | 93 scoped_ptr<cc::OutputSurface> |
| 94 SurfaceBinding::PerConnectionState::CreateOutputSurface(mus::Window* window) { | 94 SurfaceBinding::PerConnectionState::CreateOutputSurface(mus::Window* window) { |
| 95 // TODO(sky): figure out lifetime here. Do I need to worry about the return | 95 // TODO(sky): figure out lifetime here. Do I need to worry about the return |
| 96 // value outliving this? | 96 // value outliving this? |
| 97 mojo::CommandBufferPtr cb; | 97 mus::mojom::CommandBufferPtr cb; |
| 98 gpu_->CreateOffscreenGLES2Context(GetProxy(&cb)); | 98 gpu_->CreateOffscreenGLES2Context(GetProxy(&cb)); |
| 99 | 99 |
| 100 scoped_refptr<cc::ContextProvider> context_provider( | 100 scoped_refptr<cc::ContextProvider> context_provider( |
| 101 new mus::ContextProvider(cb.PassInterface().PassHandle())); | 101 new mus::ContextProvider(cb.PassInterface().PassHandle())); |
| 102 return make_scoped_ptr( | 102 return make_scoped_ptr( |
| 103 new mus::OutputSurface(context_provider, window->RequestSurface())); | 103 new mus::OutputSurface(context_provider, window->RequestSurface())); |
| 104 } | 104 } |
| 105 | 105 |
| 106 SurfaceBinding::PerConnectionState::PerConnectionState( | 106 SurfaceBinding::PerConnectionState::PerConnectionState( |
| 107 mojo::Shell* shell, | 107 mojo::Shell* shell, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 135 : window_(window), | 135 : window_(window), |
| 136 state_(PerConnectionState::Get(shell, window->connection())) {} | 136 state_(PerConnectionState::Get(shell, window->connection())) {} |
| 137 | 137 |
| 138 SurfaceBinding::~SurfaceBinding() {} | 138 SurfaceBinding::~SurfaceBinding() {} |
| 139 | 139 |
| 140 scoped_ptr<cc::OutputSurface> SurfaceBinding::CreateOutputSurface() { | 140 scoped_ptr<cc::OutputSurface> SurfaceBinding::CreateOutputSurface() { |
| 141 return state_->CreateOutputSurface(window_); | 141 return state_->CreateOutputSurface(window_); |
| 142 } | 142 } |
| 143 | 143 |
| 144 } // namespace views | 144 } // namespace views |
| OLD | NEW |