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

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

Issue 1679573002: Move shell interfaces into the shell.mojom namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@delegate
Patch Set: . Created 4 years, 10 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/surface_context_factory.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>
(...skipping 28 matching lines...) Expand all
39 // PerConnectionState ---------------------------------------------------------- 39 // PerConnectionState ----------------------------------------------------------
40 40
41 // State needed per ViewManager. Provides the real implementation of 41 // State needed per ViewManager. Provides the real implementation of
42 // CreateOutputSurface. SurfaceBinding obtains a pointer to the 42 // CreateOutputSurface. SurfaceBinding obtains a pointer to the
43 // PerConnectionState appropriate for the ViewManager. PerConnectionState is 43 // PerConnectionState appropriate for the ViewManager. PerConnectionState is
44 // stored in a thread local map. When no more refereces to a PerConnectionState 44 // stored in a thread local map. When no more refereces to a PerConnectionState
45 // remain the PerConnectionState is deleted and the underlying map cleaned up. 45 // remain the PerConnectionState is deleted and the underlying map cleaned up.
46 class SurfaceBinding::PerConnectionState 46 class SurfaceBinding::PerConnectionState
47 : public base::RefCounted<PerConnectionState> { 47 : public base::RefCounted<PerConnectionState> {
48 public: 48 public:
49 static PerConnectionState* Get(mojo::Shell* shell, 49 static PerConnectionState* Get(mojo::shell::mojom::Shell* shell,
50 mus::WindowTreeConnection* connection); 50 mus::WindowTreeConnection* connection);
51 51
52 scoped_ptr<cc::OutputSurface> CreateOutputSurface( 52 scoped_ptr<cc::OutputSurface> CreateOutputSurface(
53 mus::Window* window, 53 mus::Window* window,
54 mus::mojom::SurfaceType type); 54 mus::mojom::SurfaceType type);
55 55
56 private: 56 private:
57 typedef std::map<mus::WindowTreeConnection*, PerConnectionState*> 57 typedef std::map<mus::WindowTreeConnection*, PerConnectionState*>
58 ConnectionToStateMap; 58 ConnectionToStateMap;
59 59
60 friend class base::RefCounted<PerConnectionState>; 60 friend class base::RefCounted<PerConnectionState>;
61 61
62 PerConnectionState(mojo::Shell* shell, mus::WindowTreeConnection* connection); 62 PerConnectionState(mojo::shell::mojom::Shell* shell,
63 mus::WindowTreeConnection* connection);
63 ~PerConnectionState(); 64 ~PerConnectionState();
64 65
65 void Init(); 66 void Init();
66 67
67 static base::LazyInstance< 68 static base::LazyInstance<
68 base::ThreadLocalPointer<ConnectionToStateMap>>::Leaky window_states; 69 base::ThreadLocalPointer<ConnectionToStateMap>>::Leaky window_states;
69 70
70 mojo::Shell* shell_; 71 mojo::shell::mojom::Shell* shell_;
71 mus::WindowTreeConnection* connection_; 72 mus::WindowTreeConnection* connection_;
72 73
73 // Set of state needed to create an OutputSurface. 74 // Set of state needed to create an OutputSurface.
74 mus::mojom::GpuPtr gpu_; 75 mus::mojom::GpuPtr gpu_;
75 76
76 DISALLOW_COPY_AND_ASSIGN(PerConnectionState); 77 DISALLOW_COPY_AND_ASSIGN(PerConnectionState);
77 }; 78 };
78 79
79 // static 80 // static
80 base::LazyInstance<base::ThreadLocalPointer< 81 base::LazyInstance<base::ThreadLocalPointer<
81 SurfaceBinding::PerConnectionState::ConnectionToStateMap>>::Leaky 82 SurfaceBinding::PerConnectionState::ConnectionToStateMap>>::Leaky
82 SurfaceBinding::PerConnectionState::window_states; 83 SurfaceBinding::PerConnectionState::window_states;
83 84
84 // static 85 // static
85 SurfaceBinding::PerConnectionState* SurfaceBinding::PerConnectionState::Get( 86 SurfaceBinding::PerConnectionState* SurfaceBinding::PerConnectionState::Get(
86 mojo::Shell* shell, 87 mojo::shell::mojom::Shell* shell,
87 mus::WindowTreeConnection* connection) { 88 mus::WindowTreeConnection* connection) {
88 ConnectionToStateMap* window_map = window_states.Pointer()->Get(); 89 ConnectionToStateMap* window_map = window_states.Pointer()->Get();
89 if (!window_map) { 90 if (!window_map) {
90 window_map = new ConnectionToStateMap; 91 window_map = new ConnectionToStateMap;
91 window_states.Pointer()->Set(window_map); 92 window_states.Pointer()->Set(window_map);
92 } 93 }
93 if (!(*window_map)[connection]) { 94 if (!(*window_map)[connection]) {
94 (*window_map)[connection] = new PerConnectionState(shell, connection); 95 (*window_map)[connection] = new PerConnectionState(shell, connection);
95 (*window_map)[connection]->Init(); 96 (*window_map)[connection]->Init();
96 } 97 }
97 return (*window_map)[connection]; 98 return (*window_map)[connection];
98 } 99 }
99 100
100 scoped_ptr<cc::OutputSurface> 101 scoped_ptr<cc::OutputSurface>
101 SurfaceBinding::PerConnectionState::CreateOutputSurface( 102 SurfaceBinding::PerConnectionState::CreateOutputSurface(
102 mus::Window* window, 103 mus::Window* window,
103 mus::mojom::SurfaceType surface_type) { 104 mus::mojom::SurfaceType surface_type) {
104 // TODO(sky): figure out lifetime here. Do I need to worry about the return 105 // TODO(sky): figure out lifetime here. Do I need to worry about the return
105 // value outliving this? 106 // value outliving this?
106 mus::mojom::CommandBufferPtr cb; 107 mus::mojom::CommandBufferPtr cb;
107 gpu_->CreateOffscreenGLES2Context(GetProxy(&cb)); 108 gpu_->CreateOffscreenGLES2Context(GetProxy(&cb));
108 109
109 scoped_refptr<cc::ContextProvider> context_provider( 110 scoped_refptr<cc::ContextProvider> context_provider(
110 new mus::ContextProvider(cb.PassInterface().PassHandle())); 111 new mus::ContextProvider(cb.PassInterface().PassHandle()));
111 return make_scoped_ptr(new mus::OutputSurface( 112 return make_scoped_ptr(new mus::OutputSurface(
112 context_provider, window->RequestSurface(surface_type))); 113 context_provider, window->RequestSurface(surface_type)));
113 } 114 }
114 115
115 SurfaceBinding::PerConnectionState::PerConnectionState( 116 SurfaceBinding::PerConnectionState::PerConnectionState(
116 mojo::Shell* shell, 117 mojo::shell::mojom::Shell* shell,
117 mus::WindowTreeConnection* connection) 118 mus::WindowTreeConnection* connection)
118 : shell_(shell), connection_(connection) {} 119 : shell_(shell), connection_(connection) {}
119 120
120 SurfaceBinding::PerConnectionState::~PerConnectionState() { 121 SurfaceBinding::PerConnectionState::~PerConnectionState() {
121 ConnectionToStateMap* window_map = window_states.Pointer()->Get(); 122 ConnectionToStateMap* window_map = window_states.Pointer()->Get();
122 DCHECK(window_map); 123 DCHECK(window_map);
123 DCHECK_EQ(this, (*window_map)[connection_]); 124 DCHECK_EQ(this, (*window_map)[connection_]);
124 window_map->erase(connection_); 125 window_map->erase(connection_);
125 if (window_map->empty()) { 126 if (window_map->empty()) {
126 delete window_map; 127 delete window_map;
127 window_states.Pointer()->Set(nullptr); 128 window_states.Pointer()->Set(nullptr);
128 } 129 }
129 } 130 }
130 131
131 void SurfaceBinding::PerConnectionState::Init() { 132 void SurfaceBinding::PerConnectionState::Init() {
132 mojo::ServiceProviderPtr service_provider; 133 mojo::ServiceProviderPtr service_provider;
133 mojo::URLRequestPtr request(mojo::URLRequest::New()); 134 mojo::URLRequestPtr request(mojo::URLRequest::New());
134 request->url = mojo::String::From("mojo:mus"); 135 request->url = mojo::String::From("mojo:mus");
135 shell_->ConnectToApplication(std::move(request), GetProxy(&service_provider), 136 shell_->ConnectToApplication(std::move(request), GetProxy(&service_provider),
136 nullptr, 137 nullptr,
137 mojo::CreatePermissiveCapabilityFilter(), 138 mojo::CreatePermissiveCapabilityFilter(),
138 base::Bind(&OnGotRemoteIDs)); 139 base::Bind(&OnGotRemoteIDs));
139 ConnectToService(service_provider.get(), &gpu_); 140 ConnectToService(service_provider.get(), &gpu_);
140 } 141 }
141 142
142 // SurfaceBinding -------------------------------------------------------------- 143 // SurfaceBinding --------------------------------------------------------------
143 144
144 SurfaceBinding::SurfaceBinding(mojo::Shell* shell, 145 SurfaceBinding::SurfaceBinding(mojo::shell::mojom::Shell* shell,
145 mus::Window* window, 146 mus::Window* window,
146 mus::mojom::SurfaceType surface_type) 147 mus::mojom::SurfaceType surface_type)
147 : window_(window), 148 : window_(window),
148 surface_type_(surface_type), 149 surface_type_(surface_type),
149 state_(PerConnectionState::Get(shell, window->connection())) {} 150 state_(PerConnectionState::Get(shell, window->connection())) {}
150 151
151 SurfaceBinding::~SurfaceBinding() {} 152 SurfaceBinding::~SurfaceBinding() {}
152 153
153 scoped_ptr<cc::OutputSurface> SurfaceBinding::CreateOutputSurface() { 154 scoped_ptr<cc::OutputSurface> SurfaceBinding::CreateOutputSurface() {
154 return state_->CreateOutputSurface(window_, surface_type_); 155 return state_->CreateOutputSurface(window_, surface_type_);
155 } 156 }
156 157
157 } // namespace views 158 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/surface_binding.h ('k') | ui/views/mus/surface_context_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698