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

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

Issue 1725353003: Eliminate mojo::Shell client lib class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@15connector
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>
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/threading/thread_local.h" 15 #include "base/threading/thread_local.h"
16 #include "cc/output/compositor_frame.h" 16 #include "cc/output/compositor_frame.h"
17 #include "cc/output/output_surface.h" 17 #include "cc/output/output_surface.h"
18 #include "cc/output/output_surface_client.h" 18 #include "cc/output/output_surface_client.h"
19 #include "cc/output/software_output_device.h" 19 #include "cc/output/software_output_device.h"
20 #include "cc/resources/shared_bitmap_manager.h" 20 #include "cc/resources/shared_bitmap_manager.h"
21 #include "components/mus/public/cpp/context_provider.h" 21 #include "components/mus/public/cpp/context_provider.h"
22 #include "components/mus/public/cpp/output_surface.h" 22 #include "components/mus/public/cpp/output_surface.h"
23 #include "components/mus/public/cpp/window.h" 23 #include "components/mus/public/cpp/window.h"
24 #include "components/mus/public/cpp/window_tree_connection.h" 24 #include "components/mus/public/cpp/window_tree_connection.h"
25 #include "components/mus/public/interfaces/gpu.mojom.h" 25 #include "components/mus/public/interfaces/gpu.mojom.h"
26 #include "mojo/converters/geometry/geometry_type_converters.h" 26 #include "mojo/converters/geometry/geometry_type_converters.h"
27 #include "mojo/converters/surfaces/surfaces_type_converters.h" 27 #include "mojo/converters/surfaces/surfaces_type_converters.h"
28 #include "mojo/public/cpp/bindings/binding.h" 28 #include "mojo/public/cpp/bindings/binding.h"
29 #include "mojo/shell/public/cpp/shell.h" 29 #include "mojo/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 // PerConnectionState ----------------------------------------------------------
35 35
36 // State needed per ViewManager. Provides the real implementation of 36 // State needed per ViewManager. 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 // PerConnectionState appropriate for the ViewManager. PerConnectionState 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 PerConnectionState
40 // remain the PerConnectionState is deleted and the underlying map cleaned up. 40 // remain the PerConnectionState is deleted and the underlying map cleaned up.
41 class SurfaceBinding::PerConnectionState 41 class SurfaceBinding::PerConnectionState
42 : public base::RefCounted<PerConnectionState> { 42 : public base::RefCounted<PerConnectionState> {
43 public: 43 public:
44 static PerConnectionState* Get(mojo::Shell* shell, 44 static PerConnectionState* Get(mojo::Connector* connector,
45 mus::WindowTreeConnection* connection); 45 mus::WindowTreeConnection* connection);
46 46
47 scoped_ptr<cc::OutputSurface> CreateOutputSurface( 47 scoped_ptr<cc::OutputSurface> CreateOutputSurface(
48 mus::Window* window, 48 mus::Window* window,
49 mus::mojom::SurfaceType type); 49 mus::mojom::SurfaceType type);
50 50
51 private: 51 private:
52 typedef std::map<mus::WindowTreeConnection*, PerConnectionState*> 52 typedef std::map<mus::WindowTreeConnection*, PerConnectionState*>
53 ConnectionToStateMap; 53 ConnectionToStateMap;
54 54
55 friend class base::RefCounted<PerConnectionState>; 55 friend class base::RefCounted<PerConnectionState>;
56 56
57 PerConnectionState(mojo::Shell* shell, mus::WindowTreeConnection* connection); 57 PerConnectionState(mojo::Connector* connector,
58 mus::WindowTreeConnection* connection);
58 ~PerConnectionState(); 59 ~PerConnectionState();
59 60
60 void Init(); 61 void Init();
61 62
62 static base::LazyInstance< 63 static base::LazyInstance<
63 base::ThreadLocalPointer<ConnectionToStateMap>>::Leaky window_states; 64 base::ThreadLocalPointer<ConnectionToStateMap>>::Leaky window_states;
64 65
65 mojo::Shell* shell_; 66 mojo::Connector* connector_;
66 mus::WindowTreeConnection* connection_; 67 mus::WindowTreeConnection* connection_;
67 68
68 // Set of state needed to create an OutputSurface. 69 // Set of state needed to create an OutputSurface.
69 mus::mojom::GpuPtr gpu_; 70 mus::mojom::GpuPtr gpu_;
70 71
71 DISALLOW_COPY_AND_ASSIGN(PerConnectionState); 72 DISALLOW_COPY_AND_ASSIGN(PerConnectionState);
72 }; 73 };
73 74
74 // static 75 // static
75 base::LazyInstance<base::ThreadLocalPointer< 76 base::LazyInstance<base::ThreadLocalPointer<
76 SurfaceBinding::PerConnectionState::ConnectionToStateMap>>::Leaky 77 SurfaceBinding::PerConnectionState::ConnectionToStateMap>>::Leaky
77 SurfaceBinding::PerConnectionState::window_states; 78 SurfaceBinding::PerConnectionState::window_states;
78 79
79 // static 80 // static
80 SurfaceBinding::PerConnectionState* SurfaceBinding::PerConnectionState::Get( 81 SurfaceBinding::PerConnectionState* SurfaceBinding::PerConnectionState::Get(
81 mojo::Shell* shell, 82 mojo::Connector* connector,
82 mus::WindowTreeConnection* connection) { 83 mus::WindowTreeConnection* connection) {
83 ConnectionToStateMap* window_map = window_states.Pointer()->Get(); 84 ConnectionToStateMap* window_map = window_states.Pointer()->Get();
84 if (!window_map) { 85 if (!window_map) {
85 window_map = new ConnectionToStateMap; 86 window_map = new ConnectionToStateMap;
86 window_states.Pointer()->Set(window_map); 87 window_states.Pointer()->Set(window_map);
87 } 88 }
88 if (!(*window_map)[connection]) { 89 if (!(*window_map)[connection]) {
89 (*window_map)[connection] = new PerConnectionState(shell, connection); 90 (*window_map)[connection] = new PerConnectionState(connector, connection);
90 (*window_map)[connection]->Init(); 91 (*window_map)[connection]->Init();
91 } 92 }
92 return (*window_map)[connection]; 93 return (*window_map)[connection];
93 } 94 }
94 95
95 scoped_ptr<cc::OutputSurface> 96 scoped_ptr<cc::OutputSurface>
96 SurfaceBinding::PerConnectionState::CreateOutputSurface( 97 SurfaceBinding::PerConnectionState::CreateOutputSurface(
97 mus::Window* window, 98 mus::Window* window,
98 mus::mojom::SurfaceType surface_type) { 99 mus::mojom::SurfaceType surface_type) {
99 // 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
100 // value outliving this? 101 // value outliving this?
101 mus::mojom::CommandBufferPtr cb; 102 mus::mojom::CommandBufferPtr cb;
102 gpu_->CreateOffscreenGLES2Context(GetProxy(&cb)); 103 gpu_->CreateOffscreenGLES2Context(GetProxy(&cb));
103 104
104 scoped_refptr<cc::ContextProvider> context_provider( 105 scoped_refptr<cc::ContextProvider> context_provider(
105 new mus::ContextProvider(cb.PassInterface().PassHandle())); 106 new mus::ContextProvider(cb.PassInterface().PassHandle()));
106 return make_scoped_ptr(new mus::OutputSurface( 107 return make_scoped_ptr(new mus::OutputSurface(
107 context_provider, window->RequestSurface(surface_type))); 108 context_provider, window->RequestSurface(surface_type)));
108 } 109 }
109 110
110 SurfaceBinding::PerConnectionState::PerConnectionState( 111 SurfaceBinding::PerConnectionState::PerConnectionState(
111 mojo::Shell* shell, 112 mojo::Connector* connector,
112 mus::WindowTreeConnection* connection) 113 mus::WindowTreeConnection* connection)
113 : shell_(shell), connection_(connection) {} 114 : connector_(connector), connection_(connection) {}
114 115
115 SurfaceBinding::PerConnectionState::~PerConnectionState() { 116 SurfaceBinding::PerConnectionState::~PerConnectionState() {
116 ConnectionToStateMap* window_map = window_states.Pointer()->Get(); 117 ConnectionToStateMap* window_map = window_states.Pointer()->Get();
117 DCHECK(window_map); 118 DCHECK(window_map);
118 DCHECK_EQ(this, (*window_map)[connection_]); 119 DCHECK_EQ(this, (*window_map)[connection_]);
119 window_map->erase(connection_); 120 window_map->erase(connection_);
120 if (window_map->empty()) { 121 if (window_map->empty()) {
121 delete window_map; 122 delete window_map;
122 window_states.Pointer()->Set(nullptr); 123 window_states.Pointer()->Set(nullptr);
123 } 124 }
124 } 125 }
125 126
126 void SurfaceBinding::PerConnectionState::Init() { 127 void SurfaceBinding::PerConnectionState::Init() {
127 shell_->ConnectToInterface("mojo:mus", &gpu_); 128 connector_->ConnectToInterface("mojo:mus", &gpu_);
128 } 129 }
129 130
130 // SurfaceBinding -------------------------------------------------------------- 131 // SurfaceBinding --------------------------------------------------------------
131 132
132 SurfaceBinding::SurfaceBinding(mojo::Shell* shell, 133 SurfaceBinding::SurfaceBinding(mojo::Connector* connector,
133 mus::Window* window, 134 mus::Window* window,
134 mus::mojom::SurfaceType surface_type) 135 mus::mojom::SurfaceType surface_type)
135 : window_(window), 136 : window_(window),
136 surface_type_(surface_type), 137 surface_type_(surface_type),
137 state_(PerConnectionState::Get(shell, window->connection())) {} 138 state_(PerConnectionState::Get(connector, window->connection())) {}
138 139
139 SurfaceBinding::~SurfaceBinding() {} 140 SurfaceBinding::~SurfaceBinding() {}
140 141
141 scoped_ptr<cc::OutputSurface> SurfaceBinding::CreateOutputSurface() { 142 scoped_ptr<cc::OutputSurface> SurfaceBinding::CreateOutputSurface() {
142 return state_->CreateOutputSurface(window_, surface_type_); 143 return state_->CreateOutputSurface(window_, surface_type_);
143 } 144 }
144 145
145 } // namespace views 146 } // 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