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> |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 // PerClientState -------------------------------------------------------------- | 31 // PerClientState -------------------------------------------------------------- |
32 | 32 |
33 // State needed per WindowTreeClient. Provides the real implementation of | 33 // State needed per WindowTreeClient. Provides the real implementation of |
34 // CreateOutputSurface. SurfaceBinding obtains a pointer to the | 34 // CreateOutputSurface. SurfaceBinding obtains a pointer to the |
35 // PerClientState appropriate for the WindowTreeClient. PerClientState is | 35 // PerClientState appropriate for the WindowTreeClient. PerClientState is |
36 // stored in a thread local map. When no more refereces to a PerClientState | 36 // stored in a thread local map. When no more refereces to a PerClientState |
37 // remain the PerClientState is deleted and the underlying map cleaned up. | 37 // remain the PerClientState is deleted and the underlying map cleaned up. |
38 class SurfaceBinding::PerClientState : public base::RefCounted<PerClientState> { | 38 class SurfaceBinding::PerClientState : public base::RefCounted<PerClientState> { |
39 public: | 39 public: |
40 static PerClientState* Get(ui::WindowTreeClient* client); | 40 static PerClientState* Get(shell::Connector* connector, |
| 41 ui::WindowTreeClient* client); |
41 | 42 |
42 std::unique_ptr<cc::OutputSurface> CreateOutputSurface( | 43 std::unique_ptr<cc::OutputSurface> CreateOutputSurface( |
43 ui::Window* window, | 44 ui::Window* window, |
44 ui::mojom::SurfaceType type); | 45 ui::mojom::SurfaceType type); |
45 | 46 |
46 private: | 47 private: |
47 typedef std::map<ui::WindowTreeClient*, PerClientState*> ClientToStateMap; | 48 typedef std::map<ui::WindowTreeClient*, PerClientState*> ClientToStateMap; |
48 | 49 |
49 friend class base::RefCounted<PerClientState>; | 50 friend class base::RefCounted<PerClientState>; |
50 | 51 |
51 explicit PerClientState(ui::WindowTreeClient* client); | 52 PerClientState(shell::Connector* connector, ui::WindowTreeClient* client); |
52 ~PerClientState(); | 53 ~PerClientState(); |
53 | 54 |
54 static base::LazyInstance< | 55 static base::LazyInstance< |
55 base::ThreadLocalPointer<ClientToStateMap>>::Leaky window_states; | 56 base::ThreadLocalPointer<ClientToStateMap>>::Leaky window_states; |
56 | 57 |
| 58 shell::Connector* connector_; |
57 ui::WindowTreeClient* client_; | 59 ui::WindowTreeClient* client_; |
58 | 60 |
59 DISALLOW_COPY_AND_ASSIGN(PerClientState); | 61 DISALLOW_COPY_AND_ASSIGN(PerClientState); |
60 }; | 62 }; |
61 | 63 |
62 // static | 64 // static |
63 base::LazyInstance<base::ThreadLocalPointer< | 65 base::LazyInstance<base::ThreadLocalPointer< |
64 SurfaceBinding::PerClientState::ClientToStateMap>>::Leaky | 66 SurfaceBinding::PerClientState::ClientToStateMap>>::Leaky |
65 SurfaceBinding::PerClientState::window_states; | 67 SurfaceBinding::PerClientState::window_states; |
66 | 68 |
67 // static | 69 // static |
68 SurfaceBinding::PerClientState* SurfaceBinding::PerClientState::Get( | 70 SurfaceBinding::PerClientState* SurfaceBinding::PerClientState::Get( |
| 71 shell::Connector* connector, |
69 ui::WindowTreeClient* client) { | 72 ui::WindowTreeClient* client) { |
| 73 // |connector| can be null in some unit-tests. |
| 74 if (!connector) |
| 75 return nullptr; |
70 ClientToStateMap* window_map = window_states.Pointer()->Get(); | 76 ClientToStateMap* window_map = window_states.Pointer()->Get(); |
71 if (!window_map) { | 77 if (!window_map) { |
72 window_map = new ClientToStateMap; | 78 window_map = new ClientToStateMap; |
73 window_states.Pointer()->Set(window_map); | 79 window_states.Pointer()->Set(window_map); |
74 } | 80 } |
75 if (!(*window_map)[client]) | 81 if (!(*window_map)[client]) |
76 (*window_map)[client] = new PerClientState(client); | 82 (*window_map)[client] = new PerClientState(connector, client); |
77 return (*window_map)[client]; | 83 return (*window_map)[client]; |
78 } | 84 } |
79 | 85 |
80 std::unique_ptr<cc::OutputSurface> | 86 std::unique_ptr<cc::OutputSurface> |
81 SurfaceBinding::PerClientState::CreateOutputSurface( | 87 SurfaceBinding::PerClientState::CreateOutputSurface( |
82 ui::Window* window, | 88 ui::Window* window, |
83 ui::mojom::SurfaceType surface_type) { | 89 ui::mojom::SurfaceType surface_type) { |
84 scoped_refptr<cc::ContextProvider> context_provider(new ui::ContextProvider); | 90 scoped_refptr<cc::ContextProvider> context_provider( |
| 91 new ui::ContextProvider(connector_)); |
85 return base::WrapUnique(new ui::OutputSurface( | 92 return base::WrapUnique(new ui::OutputSurface( |
86 context_provider, window->RequestSurface(surface_type))); | 93 context_provider, window->RequestSurface(surface_type))); |
87 } | 94 } |
88 | 95 |
89 SurfaceBinding::PerClientState::PerClientState(ui::WindowTreeClient* client) | 96 SurfaceBinding::PerClientState::PerClientState(shell::Connector* connector, |
90 : client_(client) {} | 97 ui::WindowTreeClient* client) |
| 98 : connector_(connector), client_(client) {} |
91 | 99 |
92 SurfaceBinding::PerClientState::~PerClientState() { | 100 SurfaceBinding::PerClientState::~PerClientState() { |
93 ClientToStateMap* window_map = window_states.Pointer()->Get(); | 101 ClientToStateMap* window_map = window_states.Pointer()->Get(); |
94 DCHECK(window_map); | 102 DCHECK(window_map); |
95 DCHECK_EQ(this, (*window_map)[client_]); | 103 DCHECK_EQ(this, (*window_map)[client_]); |
96 window_map->erase(client_); | 104 window_map->erase(client_); |
97 if (window_map->empty()) { | 105 if (window_map->empty()) { |
98 delete window_map; | 106 delete window_map; |
99 window_states.Pointer()->Set(nullptr); | 107 window_states.Pointer()->Set(nullptr); |
100 } | 108 } |
101 } | 109 } |
102 | 110 |
103 // SurfaceBinding -------------------------------------------------------------- | 111 // SurfaceBinding -------------------------------------------------------------- |
104 | 112 |
105 SurfaceBinding::SurfaceBinding(ui::Window* window, | 113 SurfaceBinding::SurfaceBinding(shell::Connector* connector, |
| 114 ui::Window* window, |
106 ui::mojom::SurfaceType surface_type) | 115 ui::mojom::SurfaceType surface_type) |
107 : window_(window), | 116 : window_(window), |
108 surface_type_(surface_type), | 117 surface_type_(surface_type), |
109 state_(PerClientState::Get(window->window_tree())) {} | 118 state_(PerClientState::Get(connector, window->window_tree())) {} |
110 | 119 |
111 SurfaceBinding::~SurfaceBinding() {} | 120 SurfaceBinding::~SurfaceBinding() {} |
112 | 121 |
113 std::unique_ptr<cc::OutputSurface> SurfaceBinding::CreateOutputSurface() { | 122 std::unique_ptr<cc::OutputSurface> SurfaceBinding::CreateOutputSurface() { |
114 return state_ ? state_->CreateOutputSurface(window_, surface_type_) : nullptr; | 123 return state_ ? state_->CreateOutputSurface(window_, surface_type_) : nullptr; |
115 } | 124 } |
116 | 125 |
117 } // namespace views | 126 } // namespace views |
OLD | NEW |