| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" |
| 15 #include "base/threading/thread_local.h" | 16 #include "base/threading/thread_local.h" |
| 16 #include "cc/output/compositor_frame.h" | 17 #include "cc/output/compositor_frame.h" |
| 17 #include "cc/output/output_surface.h" | 18 #include "cc/output/output_surface.h" |
| 18 #include "cc/output/output_surface_client.h" | 19 #include "cc/output/output_surface_client.h" |
| 19 #include "cc/output/software_output_device.h" | 20 #include "cc/output/software_output_device.h" |
| 20 #include "cc/resources/shared_bitmap_manager.h" | 21 #include "cc/resources/shared_bitmap_manager.h" |
| 21 #include "components/mus/public/cpp/context_provider.h" | 22 #include "components/mus/public/cpp/context_provider.h" |
| 22 #include "components/mus/public/cpp/output_surface.h" | 23 #include "components/mus/public/cpp/output_surface.h" |
| 23 #include "components/mus/public/cpp/window.h" | 24 #include "components/mus/public/cpp/window.h" |
| 24 #include "components/mus/public/cpp/window_tree_connection.h" | 25 #include "components/mus/public/cpp/window_tree_connection.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 37 // CreateOutputSurface. SurfaceBinding obtains a pointer to the | 38 // CreateOutputSurface. SurfaceBinding obtains a pointer to the |
| 38 // PerConnectionState appropriate for the ViewManager. PerConnectionState is | 39 // PerConnectionState appropriate for the ViewManager. PerConnectionState is |
| 39 // stored in a thread local map. When no more refereces to a PerConnectionState | 40 // stored in a thread local map. When no more refereces to a PerConnectionState |
| 40 // remain the PerConnectionState is deleted and the underlying map cleaned up. | 41 // remain the PerConnectionState is deleted and the underlying map cleaned up. |
| 41 class SurfaceBinding::PerConnectionState | 42 class SurfaceBinding::PerConnectionState |
| 42 : public base::RefCounted<PerConnectionState> { | 43 : public base::RefCounted<PerConnectionState> { |
| 43 public: | 44 public: |
| 44 static PerConnectionState* Get(mojo::Connector* connector, | 45 static PerConnectionState* Get(mojo::Connector* connector, |
| 45 mus::WindowTreeConnection* connection); | 46 mus::WindowTreeConnection* connection); |
| 46 | 47 |
| 47 scoped_ptr<cc::OutputSurface> CreateOutputSurface( | 48 std::unique_ptr<cc::OutputSurface> CreateOutputSurface( |
| 48 mus::Window* window, | 49 mus::Window* window, |
| 49 mus::mojom::SurfaceType type); | 50 mus::mojom::SurfaceType type); |
| 50 | 51 |
| 51 private: | 52 private: |
| 52 typedef std::map<mus::WindowTreeConnection*, PerConnectionState*> | 53 typedef std::map<mus::WindowTreeConnection*, PerConnectionState*> |
| 53 ConnectionToStateMap; | 54 ConnectionToStateMap; |
| 54 | 55 |
| 55 friend class base::RefCounted<PerConnectionState>; | 56 friend class base::RefCounted<PerConnectionState>; |
| 56 | 57 |
| 57 PerConnectionState(mojo::Connector* connector, | 58 PerConnectionState(mojo::Connector* connector, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 86 window_map = new ConnectionToStateMap; | 87 window_map = new ConnectionToStateMap; |
| 87 window_states.Pointer()->Set(window_map); | 88 window_states.Pointer()->Set(window_map); |
| 88 } | 89 } |
| 89 if (!(*window_map)[connection]) { | 90 if (!(*window_map)[connection]) { |
| 90 (*window_map)[connection] = new PerConnectionState(connector, connection); | 91 (*window_map)[connection] = new PerConnectionState(connector, connection); |
| 91 (*window_map)[connection]->Init(); | 92 (*window_map)[connection]->Init(); |
| 92 } | 93 } |
| 93 return (*window_map)[connection]; | 94 return (*window_map)[connection]; |
| 94 } | 95 } |
| 95 | 96 |
| 96 scoped_ptr<cc::OutputSurface> | 97 std::unique_ptr<cc::OutputSurface> |
| 97 SurfaceBinding::PerConnectionState::CreateOutputSurface( | 98 SurfaceBinding::PerConnectionState::CreateOutputSurface( |
| 98 mus::Window* window, | 99 mus::Window* window, |
| 99 mus::mojom::SurfaceType surface_type) { | 100 mus::mojom::SurfaceType surface_type) { |
| 100 // TODO(sky): figure out lifetime here. Do I need to worry about the return | 101 // TODO(sky): figure out lifetime here. Do I need to worry about the return |
| 101 // value outliving this? | 102 // value outliving this? |
| 102 mus::mojom::CommandBufferPtr cb; | 103 mus::mojom::CommandBufferPtr cb; |
| 103 gpu_->CreateOffscreenGLES2Context(GetProxy(&cb)); | 104 gpu_->CreateOffscreenGLES2Context(GetProxy(&cb)); |
| 104 | 105 |
| 105 scoped_refptr<cc::ContextProvider> context_provider( | 106 scoped_refptr<cc::ContextProvider> context_provider( |
| 106 new mus::ContextProvider(cb.PassInterface().PassHandle())); | 107 new mus::ContextProvider(cb.PassInterface().PassHandle())); |
| 107 return make_scoped_ptr(new mus::OutputSurface( | 108 return base::WrapUnique(new mus::OutputSurface( |
| 108 context_provider, window->RequestSurface(surface_type))); | 109 context_provider, window->RequestSurface(surface_type))); |
| 109 } | 110 } |
| 110 | 111 |
| 111 SurfaceBinding::PerConnectionState::PerConnectionState( | 112 SurfaceBinding::PerConnectionState::PerConnectionState( |
| 112 mojo::Connector* connector, | 113 mojo::Connector* connector, |
| 113 mus::WindowTreeConnection* connection) | 114 mus::WindowTreeConnection* connection) |
| 114 : connector_(connector), connection_(connection) {} | 115 : connector_(connector), connection_(connection) {} |
| 115 | 116 |
| 116 SurfaceBinding::PerConnectionState::~PerConnectionState() { | 117 SurfaceBinding::PerConnectionState::~PerConnectionState() { |
| 117 ConnectionToStateMap* window_map = window_states.Pointer()->Get(); | 118 ConnectionToStateMap* window_map = window_states.Pointer()->Get(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 132 | 133 |
| 133 SurfaceBinding::SurfaceBinding(mojo::Connector* connector, | 134 SurfaceBinding::SurfaceBinding(mojo::Connector* connector, |
| 134 mus::Window* window, | 135 mus::Window* window, |
| 135 mus::mojom::SurfaceType surface_type) | 136 mus::mojom::SurfaceType surface_type) |
| 136 : window_(window), | 137 : window_(window), |
| 137 surface_type_(surface_type), | 138 surface_type_(surface_type), |
| 138 state_(PerConnectionState::Get(connector, window->connection())) {} | 139 state_(PerConnectionState::Get(connector, window->connection())) {} |
| 139 | 140 |
| 140 SurfaceBinding::~SurfaceBinding() {} | 141 SurfaceBinding::~SurfaceBinding() {} |
| 141 | 142 |
| 142 scoped_ptr<cc::OutputSurface> SurfaceBinding::CreateOutputSurface() { | 143 std::unique_ptr<cc::OutputSurface> SurfaceBinding::CreateOutputSurface() { |
| 143 return state_->CreateOutputSurface(window_, surface_type_); | 144 return state_->CreateOutputSurface(window_, surface_type_); |
| 144 } | 145 } |
| 145 | 146 |
| 146 } // namespace views | 147 } // namespace views |
| OLD | NEW |