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

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

Issue 1976703003: Impl mus::mojom::GpuService to enable using Chrome IPC version gpu CmdBuf in mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build error 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
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_client.h" 26 #include "components/mus/public/cpp/window_tree_client.h"
27 #include "components/mus/public/interfaces/gpu.mojom.h"
28 #include "mojo/public/cpp/bindings/binding.h" 27 #include "mojo/public/cpp/bindings/binding.h"
29 #include "services/shell/public/cpp/connector.h"
30 #include "ui/views/mus/window_tree_host_mus.h" 28 #include "ui/views/mus/window_tree_host_mus.h"
31 29
32 namespace views { 30 namespace views {
33 31
34 // PerClientState -------------------------------------------------------------- 32 // PerClientState --------------------------------------------------------------
35 33
36 // State needed per WindowTreeClient. Provides the real implementation of 34 // State needed per WindowTreeClient. Provides the real implementation of
37 // CreateOutputSurface. SurfaceBinding obtains a pointer to the 35 // CreateOutputSurface. SurfaceBinding obtains a pointer to the
38 // PerClientState appropriate for the WindowTreeClient. PerClientState is 36 // PerClientState appropriate for the WindowTreeClient. PerClientState is
39 // stored in a thread local map. When no more refereces to a PerClientState 37 // stored in a thread local map. When no more refereces to a PerClientState
40 // remain the PerClientState is deleted and the underlying map cleaned up. 38 // remain the PerClientState is deleted and the underlying map cleaned up.
41 class SurfaceBinding::PerClientState : public base::RefCounted<PerClientState> { 39 class SurfaceBinding::PerClientState : public base::RefCounted<PerClientState> {
42 public: 40 public:
43 static PerClientState* Get(shell::Connector* connector, 41 static PerClientState* Get(shell::Connector* connector,
44 mus::WindowTreeClient* client); 42 mus::WindowTreeClient* client);
45 43
46 std::unique_ptr<cc::OutputSurface> CreateOutputSurface( 44 std::unique_ptr<cc::OutputSurface> CreateOutputSurface(
47 mus::Window* window, 45 mus::Window* window,
48 mus::mojom::SurfaceType type); 46 mus::mojom::SurfaceType type);
49 47
50 private: 48 private:
51 typedef std::map<mus::WindowTreeClient*, PerClientState*> ClientToStateMap; 49 typedef std::map<mus::WindowTreeClient*, PerClientState*> ClientToStateMap;
52 50
53 friend class base::RefCounted<PerClientState>; 51 friend class base::RefCounted<PerClientState>;
54 52
55 PerClientState(shell::Connector* connector, 53 PerClientState(shell::Connector* connector,
56 mus::WindowTreeClient* client); 54 mus::WindowTreeClient* client);
57 ~PerClientState(); 55 ~PerClientState();
58 56
59 void Init();
60
61 static base::LazyInstance< 57 static base::LazyInstance<
62 base::ThreadLocalPointer<ClientToStateMap>>::Leaky window_states; 58 base::ThreadLocalPointer<ClientToStateMap>>::Leaky window_states;
63 59
64 shell::Connector* connector_; 60 shell::Connector* connector_;
65 mus::WindowTreeClient* client_; 61 mus::WindowTreeClient* client_;
66 62
67 // Set of state needed to create an OutputSurface.
68 mus::mojom::GpuPtr gpu_;
69
70 DISALLOW_COPY_AND_ASSIGN(PerClientState); 63 DISALLOW_COPY_AND_ASSIGN(PerClientState);
71 }; 64 };
72 65
73 // static 66 // static
74 base::LazyInstance<base::ThreadLocalPointer< 67 base::LazyInstance<base::ThreadLocalPointer<
75 SurfaceBinding::PerClientState::ClientToStateMap>>::Leaky 68 SurfaceBinding::PerClientState::ClientToStateMap>>::Leaky
76 SurfaceBinding::PerClientState::window_states; 69 SurfaceBinding::PerClientState::window_states;
77 70
78 // static 71 // static
79 SurfaceBinding::PerClientState* SurfaceBinding::PerClientState::Get( 72 SurfaceBinding::PerClientState* SurfaceBinding::PerClientState::Get(
80 shell::Connector* connector, 73 shell::Connector* connector,
81 mus::WindowTreeClient* client) { 74 mus::WindowTreeClient* client) {
82 ClientToStateMap* window_map = window_states.Pointer()->Get(); 75 ClientToStateMap* window_map = window_states.Pointer()->Get();
83 if (!window_map) { 76 if (!window_map) {
84 window_map = new ClientToStateMap; 77 window_map = new ClientToStateMap;
85 window_states.Pointer()->Set(window_map); 78 window_states.Pointer()->Set(window_map);
86 } 79 }
87 if (!(*window_map)[client]) { 80 if (!(*window_map)[client])
88 (*window_map)[client] = new PerClientState(connector, client); 81 (*window_map)[client] = new PerClientState(connector, client);
89 (*window_map)[client]->Init();
90 }
91 return (*window_map)[client]; 82 return (*window_map)[client];
92 } 83 }
93 84
94 std::unique_ptr<cc::OutputSurface> 85 std::unique_ptr<cc::OutputSurface>
95 SurfaceBinding::PerClientState::CreateOutputSurface( 86 SurfaceBinding::PerClientState::CreateOutputSurface(
96 mus::Window* window, 87 mus::Window* window,
97 mus::mojom::SurfaceType surface_type) { 88 mus::mojom::SurfaceType surface_type) {
98 if (gpu_.encountered_error())
99 return nullptr;
100 // TODO(sky): figure out lifetime here. Do I need to worry about the return
101 // value outliving this?
102 mus::mojom::CommandBufferPtr cb;
103 gpu_->CreateOffscreenGLES2Context(GetProxy(&cb));
104
105 scoped_refptr<cc::ContextProvider> context_provider( 89 scoped_refptr<cc::ContextProvider> context_provider(
106 new mus::ContextProvider(cb.PassInterface().PassHandle())); 90 new mus::ContextProvider(connector_));
107 return base::WrapUnique(new mus::OutputSurface( 91 return base::WrapUnique(new mus::OutputSurface(
108 context_provider, window->RequestSurface(surface_type))); 92 context_provider, window->RequestSurface(surface_type)));
109 } 93 }
110 94
111 SurfaceBinding::PerClientState::PerClientState( 95 SurfaceBinding::PerClientState::PerClientState(
112 shell::Connector* connector, 96 shell::Connector* connector,
113 mus::WindowTreeClient* client) 97 mus::WindowTreeClient* client)
114 : connector_(connector), client_(client) {} 98 : connector_(connector), client_(client) {}
115 99
116 SurfaceBinding::PerClientState::~PerClientState() { 100 SurfaceBinding::PerClientState::~PerClientState() {
117 ClientToStateMap* window_map = window_states.Pointer()->Get(); 101 ClientToStateMap* window_map = window_states.Pointer()->Get();
118 DCHECK(window_map); 102 DCHECK(window_map);
119 DCHECK_EQ(this, (*window_map)[client_]); 103 DCHECK_EQ(this, (*window_map)[client_]);
120 window_map->erase(client_); 104 window_map->erase(client_);
121 if (window_map->empty()) { 105 if (window_map->empty()) {
122 delete window_map; 106 delete window_map;
123 window_states.Pointer()->Set(nullptr); 107 window_states.Pointer()->Set(nullptr);
124 } 108 }
125 } 109 }
126 110
127 void SurfaceBinding::PerClientState::Init() {
128 connector_->ConnectToInterface("mojo:mus", &gpu_);
129
130 // TODO(sad): If service connection is lost (e.g. if gpu crashes), then the
131 // clients need to be restored. https://crbug.com/613366
132 // TODO(rockot|yzshen): It is necessary to install a connection-error handler,
133 // even if the handler doesn't actually do anything. https://crbug.com/613371
134 gpu_.set_connection_error_handler([]{});
sky 2016/06/01 15:45:29 Where does this code end up now?
Peng 2016/06/01 16:23:21 With CL, we will create a new GpuPtr in GLES2Conte
135 }
136
137 // SurfaceBinding -------------------------------------------------------------- 111 // SurfaceBinding --------------------------------------------------------------
138 112
139 SurfaceBinding::SurfaceBinding(shell::Connector* connector, 113 SurfaceBinding::SurfaceBinding(shell::Connector* connector,
140 mus::Window* window, 114 mus::Window* window,
141 mus::mojom::SurfaceType surface_type) 115 mus::mojom::SurfaceType surface_type)
142 : window_(window), 116 : window_(window),
143 surface_type_(surface_type), 117 surface_type_(surface_type),
144 state_(PerClientState::Get(connector, window->window_tree())) {} 118 state_(PerClientState::Get(connector, window->window_tree())) {}
145 119
146 SurfaceBinding::~SurfaceBinding() {} 120 SurfaceBinding::~SurfaceBinding() {}
147 121
148 std::unique_ptr<cc::OutputSurface> SurfaceBinding::CreateOutputSurface() { 122 std::unique_ptr<cc::OutputSurface> SurfaceBinding::CreateOutputSurface() {
149 return state_->CreateOutputSurface(window_, surface_type_); 123 return state_->CreateOutputSurface(window_, surface_type_);
150 } 124 }
151 125
152 } // namespace views 126 } // namespace views
OLDNEW
« components/bitmap_uploader/bitmap_uploader.cc ('K') | « media/gpu/ipc/service/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698