Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: ui/views/mus/surface_binding.cc

Issue 2018823002: Eliminate WindowTreeConnection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@connection
Patch Set: . Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/mus/surface_binding.h ('k') | ui/views/mus/window_manager_connection.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/memory/ptr_util.h"
16 #include "base/threading/thread_local.h" 16 #include "base/threading/thread_local.h"
17 #include "cc/output/compositor_frame.h" 17 #include "cc/output/compositor_frame.h"
18 #include "cc/output/output_surface.h" 18 #include "cc/output/output_surface.h"
19 #include "cc/output/output_surface_client.h" 19 #include "cc/output/output_surface_client.h"
20 #include "cc/output/software_output_device.h" 20 #include "cc/output/software_output_device.h"
21 #include "cc/resources/shared_bitmap_manager.h" 21 #include "cc/resources/shared_bitmap_manager.h"
22 #include "components/mus/public/cpp/context_provider.h" 22 #include "components/mus/public/cpp/context_provider.h"
23 #include "components/mus/public/cpp/output_surface.h" 23 #include "components/mus/public/cpp/output_surface.h"
24 #include "components/mus/public/cpp/surfaces/surfaces_type_converters.h" 24 #include "components/mus/public/cpp/surfaces/surfaces_type_converters.h"
25 #include "components/mus/public/cpp/window.h" 25 #include "components/mus/public/cpp/window.h"
26 #include "components/mus/public/cpp/window_tree_connection.h" 26 #include "components/mus/public/cpp/window_tree_client.h"
27 #include "components/mus/public/interfaces/gpu.mojom.h" 27 #include "components/mus/public/interfaces/gpu.mojom.h"
28 #include "mojo/public/cpp/bindings/binding.h" 28 #include "mojo/public/cpp/bindings/binding.h"
29 #include "services/shell/public/cpp/connector.h" 29 #include "services/shell/public/cpp/connector.h"
30 #include "ui/views/mus/window_tree_host_mus.h" 30 #include "ui/views/mus/window_tree_host_mus.h"
31 31
32 namespace views { 32 namespace views {
33 33
34 // PerConnectionState ---------------------------------------------------------- 34 // PerClientState --------------------------------------------------------------
35 35
36 // State needed per ViewManager. Provides the real implementation of 36 // State needed per WindowTreeClient. Provides the real implementation of
37 // CreateOutputSurface. SurfaceBinding obtains a pointer to the 37 // CreateOutputSurface. SurfaceBinding obtains a pointer to the
38 // PerConnectionState appropriate for the ViewManager. PerConnectionState is 38 // PerClientState appropriate for the WindowTreeClient. PerClientState is
39 // stored in a thread local map. When no more refereces to a PerConnectionState 39 // stored in a thread local map. When no more refereces to a PerClientState
40 // remain the PerConnectionState is deleted and the underlying map cleaned up. 40 // remain the PerClientState is deleted and the underlying map cleaned up.
41 class SurfaceBinding::PerConnectionState 41 class SurfaceBinding::PerClientState : public base::RefCounted<PerClientState> {
42 : public base::RefCounted<PerConnectionState> {
43 public: 42 public:
44 static PerConnectionState* Get(shell::Connector* connector, 43 static PerClientState* Get(shell::Connector* connector,
45 mus::WindowTreeConnection* connection); 44 mus::WindowTreeClient* client);
46 45
47 std::unique_ptr<cc::OutputSurface> CreateOutputSurface( 46 std::unique_ptr<cc::OutputSurface> CreateOutputSurface(
48 mus::Window* window, 47 mus::Window* window,
49 mus::mojom::SurfaceType type); 48 mus::mojom::SurfaceType type);
50 49
51 private: 50 private:
52 typedef std::map<mus::WindowTreeConnection*, PerConnectionState*> 51 typedef std::map<mus::WindowTreeClient*, PerClientState*> ClientToStateMap;
53 ConnectionToStateMap;
54 52
55 friend class base::RefCounted<PerConnectionState>; 53 friend class base::RefCounted<PerClientState>;
56 54
57 PerConnectionState(shell::Connector* connector, 55 PerClientState(shell::Connector* connector,
58 mus::WindowTreeConnection* connection); 56 mus::WindowTreeClient* client);
59 ~PerConnectionState(); 57 ~PerClientState();
60 58
61 void Init(); 59 void Init();
62 60
63 static base::LazyInstance< 61 static base::LazyInstance<
64 base::ThreadLocalPointer<ConnectionToStateMap>>::Leaky window_states; 62 base::ThreadLocalPointer<ClientToStateMap>>::Leaky window_states;
65 63
66 shell::Connector* connector_; 64 shell::Connector* connector_;
67 mus::WindowTreeConnection* connection_; 65 mus::WindowTreeClient* client_;
68 66
69 // Set of state needed to create an OutputSurface. 67 // Set of state needed to create an OutputSurface.
70 mus::mojom::GpuPtr gpu_; 68 mus::mojom::GpuPtr gpu_;
71 69
72 DISALLOW_COPY_AND_ASSIGN(PerConnectionState); 70 DISALLOW_COPY_AND_ASSIGN(PerClientState);
73 }; 71 };
74 72
75 // static 73 // static
76 base::LazyInstance<base::ThreadLocalPointer< 74 base::LazyInstance<base::ThreadLocalPointer<
77 SurfaceBinding::PerConnectionState::ConnectionToStateMap>>::Leaky 75 SurfaceBinding::PerClientState::ClientToStateMap>>::Leaky
78 SurfaceBinding::PerConnectionState::window_states; 76 SurfaceBinding::PerClientState::window_states;
79 77
80 // static 78 // static
81 SurfaceBinding::PerConnectionState* SurfaceBinding::PerConnectionState::Get( 79 SurfaceBinding::PerClientState* SurfaceBinding::PerClientState::Get(
82 shell::Connector* connector, 80 shell::Connector* connector,
83 mus::WindowTreeConnection* connection) { 81 mus::WindowTreeClient* client) {
84 ConnectionToStateMap* window_map = window_states.Pointer()->Get(); 82 ClientToStateMap* window_map = window_states.Pointer()->Get();
85 if (!window_map) { 83 if (!window_map) {
86 window_map = new ConnectionToStateMap; 84 window_map = new ClientToStateMap;
87 window_states.Pointer()->Set(window_map); 85 window_states.Pointer()->Set(window_map);
88 } 86 }
89 if (!(*window_map)[connection]) { 87 if (!(*window_map)[client]) {
90 (*window_map)[connection] = new PerConnectionState(connector, connection); 88 (*window_map)[client] = new PerClientState(connector, client);
91 (*window_map)[connection]->Init(); 89 (*window_map)[client]->Init();
92 } 90 }
93 return (*window_map)[connection]; 91 return (*window_map)[client];
94 } 92 }
95 93
96 std::unique_ptr<cc::OutputSurface> 94 std::unique_ptr<cc::OutputSurface>
97 SurfaceBinding::PerConnectionState::CreateOutputSurface( 95 SurfaceBinding::PerClientState::CreateOutputSurface(
98 mus::Window* window, 96 mus::Window* window,
99 mus::mojom::SurfaceType surface_type) { 97 mus::mojom::SurfaceType surface_type) {
100 if (gpu_.encountered_error()) 98 if (gpu_.encountered_error())
101 return nullptr; 99 return nullptr;
102 // TODO(sky): figure out lifetime here. Do I need to worry about the return 100 // TODO(sky): figure out lifetime here. Do I need to worry about the return
103 // value outliving this? 101 // value outliving this?
104 mus::mojom::CommandBufferPtr cb; 102 mus::mojom::CommandBufferPtr cb;
105 gpu_->CreateOffscreenGLES2Context(GetProxy(&cb)); 103 gpu_->CreateOffscreenGLES2Context(GetProxy(&cb));
106 104
107 scoped_refptr<cc::ContextProvider> context_provider( 105 scoped_refptr<cc::ContextProvider> context_provider(
108 new mus::ContextProvider(cb.PassInterface().PassHandle())); 106 new mus::ContextProvider(cb.PassInterface().PassHandle()));
109 return base::WrapUnique(new mus::OutputSurface( 107 return base::WrapUnique(new mus::OutputSurface(
110 context_provider, window->RequestSurface(surface_type))); 108 context_provider, window->RequestSurface(surface_type)));
111 } 109 }
112 110
113 SurfaceBinding::PerConnectionState::PerConnectionState( 111 SurfaceBinding::PerClientState::PerClientState(
114 shell::Connector* connector, 112 shell::Connector* connector,
115 mus::WindowTreeConnection* connection) 113 mus::WindowTreeClient* client)
116 : connector_(connector), connection_(connection) {} 114 : connector_(connector), client_(client) {}
117 115
118 SurfaceBinding::PerConnectionState::~PerConnectionState() { 116 SurfaceBinding::PerClientState::~PerClientState() {
119 ConnectionToStateMap* window_map = window_states.Pointer()->Get(); 117 ClientToStateMap* window_map = window_states.Pointer()->Get();
120 DCHECK(window_map); 118 DCHECK(window_map);
121 DCHECK_EQ(this, (*window_map)[connection_]); 119 DCHECK_EQ(this, (*window_map)[client_]);
122 window_map->erase(connection_); 120 window_map->erase(client_);
123 if (window_map->empty()) { 121 if (window_map->empty()) {
124 delete window_map; 122 delete window_map;
125 window_states.Pointer()->Set(nullptr); 123 window_states.Pointer()->Set(nullptr);
126 } 124 }
127 } 125 }
128 126
129 void SurfaceBinding::PerConnectionState::Init() { 127 void SurfaceBinding::PerClientState::Init() {
130 connector_->ConnectToInterface("mojo:mus", &gpu_); 128 connector_->ConnectToInterface("mojo:mus", &gpu_);
131 129
132 // TODO(sad): If connection is lost (e.g. if gpu crashes), then the 130 // TODO(sad): If service connection is lost (e.g. if gpu crashes), then the
133 // connections need to be restored. https://crbug.com/613366 131 // clients need to be restored. https://crbug.com/613366
134 // TODO(rockot|yzshen): It is necessary to install a connection-error handler, 132 // TODO(rockot|yzshen): It is necessary to install a connection-error handler,
135 // even if the handler doesn't actually do anything. https://crbug.com/613371 133 // even if the handler doesn't actually do anything. https://crbug.com/613371
136 gpu_.set_connection_error_handler([]{}); 134 gpu_.set_connection_error_handler([]{});
137 } 135 }
138 136
139 // SurfaceBinding -------------------------------------------------------------- 137 // SurfaceBinding --------------------------------------------------------------
140 138
141 SurfaceBinding::SurfaceBinding(shell::Connector* connector, 139 SurfaceBinding::SurfaceBinding(shell::Connector* connector,
142 mus::Window* window, 140 mus::Window* window,
143 mus::mojom::SurfaceType surface_type) 141 mus::mojom::SurfaceType surface_type)
144 : window_(window), 142 : window_(window),
145 surface_type_(surface_type), 143 surface_type_(surface_type),
146 state_(PerConnectionState::Get(connector, window->connection())) {} 144 state_(PerClientState::Get(connector, window->window_tree())) {}
147 145
148 SurfaceBinding::~SurfaceBinding() {} 146 SurfaceBinding::~SurfaceBinding() {}
149 147
150 std::unique_ptr<cc::OutputSurface> SurfaceBinding::CreateOutputSurface() { 148 std::unique_ptr<cc::OutputSurface> SurfaceBinding::CreateOutputSurface() {
151 return state_->CreateOutputSurface(window_, surface_type_); 149 return state_->CreateOutputSurface(window_, surface_type_);
152 } 150 }
153 151
154 } // namespace views 152 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/surface_binding.h ('k') | ui/views/mus/window_manager_connection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698