OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef SERVICES_UI_GPU_GPU_SERVICE_INTERNAL_H_ | 5 #ifndef SERVICES_UI_GPU_GPU_SERVICE_INTERNAL_H_ |
6 #define SERVICES_UI_GPU_GPU_SERVICE_INTERNAL_H_ | 6 #define SERVICES_UI_GPU_GPU_SERVICE_INTERNAL_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
10 #include "base/threading/non_thread_safe.h" | 10 #include "base/threading/non_thread_safe.h" |
11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "gpu/command_buffer/service/gpu_preferences.h" | 13 #include "gpu/command_buffer/service/gpu_preferences.h" |
14 #include "gpu/config/gpu_info.h" | 14 #include "gpu/config/gpu_info.h" |
15 #include "gpu/ipc/client/gpu_channel_host.h" | 15 #include "gpu/ipc/client/gpu_channel_host.h" |
16 #include "gpu/ipc/common/surface_handle.h" | 16 #include "gpu/ipc/common/surface_handle.h" |
17 #include "gpu/ipc/service/gpu_channel.h" | 17 #include "gpu/ipc/service/gpu_channel.h" |
18 #include "gpu/ipc/service/gpu_channel_manager.h" | 18 #include "gpu/ipc/service/gpu_channel_manager.h" |
19 #include "gpu/ipc/service/gpu_channel_manager_delegate.h" | 19 #include "gpu/ipc/service/gpu_channel_manager_delegate.h" |
20 #include "gpu/ipc/service/gpu_config.h" | 20 #include "gpu/ipc/service/gpu_config.h" |
21 #include "gpu/ipc/service/x_util.h" | 21 #include "gpu/ipc/service/x_util.h" |
| 22 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 23 #include "services/ui/gpu/interfaces/gpu_service_internal.mojom.h" |
22 #include "ui/gfx/native_widget_types.h" | 24 #include "ui/gfx/native_widget_types.h" |
23 | 25 |
24 namespace base { | 26 namespace base { |
25 template <typename T> | 27 template <typename T> |
26 struct DefaultSingletonTraits; | 28 struct DefaultSingletonTraits; |
27 } | 29 } |
28 | 30 |
29 namespace gpu { | 31 namespace gpu { |
30 class GpuChannelHost; | 32 class GpuChannelHost; |
31 class GpuMemoryBufferFactory; | 33 class GpuMemoryBufferFactory; |
32 class SyncPointManager; | 34 class SyncPointManager; |
33 } | 35 } |
34 | 36 |
35 namespace media { | 37 namespace media { |
36 class MediaService; | 38 class MediaService; |
37 } | 39 } |
38 | 40 |
39 namespace ui { | 41 namespace ui { |
40 | 42 |
41 class MusGpuMemoryBufferManager; | 43 class MusGpuMemoryBufferManager; |
42 | 44 |
43 // TODO(sad): GpuChannelManagerDelegate implementation should be in the gpu | 45 // TODO(sad): GpuChannelManagerDelegate implementation should be in the gpu |
44 // process, and the GpuChannelHostFactory should be in the host process (i.e. | 46 // process, and the GpuChannelHostFactory should be in the host process (i.e. |
45 // the window-server process). So the GpuChannelHostFactory parts of this should | 47 // the window-server process). So the GpuChannelHostFactory parts of this should |
46 // be split out. | 48 // be split out. |
47 class GpuServiceInternal : public gpu::GpuChannelManagerDelegate, | 49 class GpuServiceInternal : public gpu::GpuChannelManagerDelegate, |
48 public gpu::GpuChannelHostFactory, | 50 public gpu::GpuChannelHostFactory, |
| 51 public mojom::GpuServiceInternal, |
49 public base::NonThreadSafe { | 52 public base::NonThreadSafe { |
50 public: | 53 public: |
51 typedef base::Callback<void(int client_id, mojo::ScopedMessagePipeHandle)> | 54 void Add(mojom::GpuServiceInternalRequest request); |
52 EstablishGpuChannelCallback; | 55 |
53 void EstablishGpuChannel(uint64_t client_tracing_id, | 56 // TODO(sad): This should not be a singleton. |
54 bool preempts, | 57 static GpuServiceInternal* GetInstance(); |
55 bool allow_view_command_buffers, | 58 |
56 bool allow_real_time_streams, | 59 scoped_refptr<gpu::GpuChannelHost> gpu_channel_local() const { |
57 const EstablishGpuChannelCallback& callback); | 60 return gpu_channel_local_; |
| 61 } |
| 62 |
| 63 gpu::GpuChannelManager* gpu_channel_manager() const { |
| 64 return gpu_channel_manager_.get(); |
| 65 } |
| 66 |
| 67 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory() const { |
| 68 return gpu_memory_buffer_factory_.get(); |
| 69 } |
| 70 |
| 71 private: |
| 72 friend struct base::DefaultSingletonTraits<GpuServiceInternal>; |
| 73 |
| 74 GpuServiceInternal(); |
| 75 ~GpuServiceInternal() override; |
| 76 |
| 77 void EstablishGpuChannelInternal(int32_t client_id, |
| 78 uint64_t client_tracing_id, |
| 79 bool preempts, |
| 80 bool allow_view_command_buffers, |
| 81 bool allow_real_time_streams, |
| 82 const EstablishGpuChannelCallback& callback); |
58 gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer( | 83 gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer( |
59 gfx::GpuMemoryBufferId id, | 84 gfx::GpuMemoryBufferId id, |
60 const gfx::Size& size, | 85 const gfx::Size& size, |
61 gfx::BufferFormat format, | 86 gfx::BufferFormat format, |
62 gfx::BufferUsage usage, | 87 gfx::BufferUsage usage, |
63 int client_id, | 88 int client_id, |
64 gpu::SurfaceHandle surface_handle); | 89 gpu::SurfaceHandle surface_handle); |
65 gfx::GpuMemoryBufferHandle CreateGpuMemoryBufferFromeHandle( | 90 gfx::GpuMemoryBufferHandle CreateGpuMemoryBufferFromeHandle( |
66 gfx::GpuMemoryBufferHandle buffer_handle, | 91 gfx::GpuMemoryBufferHandle buffer_handle, |
67 gfx::GpuMemoryBufferId id, | 92 gfx::GpuMemoryBufferId id, |
68 const gfx::Size& size, | 93 const gfx::Size& size, |
69 gfx::BufferFormat format, | 94 gfx::BufferFormat format, |
70 int client_id); | 95 int client_id); |
71 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, | 96 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, |
72 int client_id, | 97 int client_id, |
73 const gpu::SyncToken& sync_token); | 98 const gpu::SyncToken& sync_token); |
74 | 99 |
75 gpu::GpuChannelManager* gpu_channel_manager() const { | 100 // gpu::GpuChannelManagerDelegate: |
76 return gpu_channel_manager_.get(); | |
77 } | |
78 | |
79 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory() const { | |
80 return gpu_memory_buffer_factory_.get(); | |
81 } | |
82 | |
83 scoped_refptr<gpu::GpuChannelHost> gpu_channel_local() const { | |
84 return gpu_channel_local_; | |
85 } | |
86 | |
87 const gpu::GPUInfo& gpu_info() const { return gpu_info_; } | |
88 | |
89 // GpuChannelManagerDelegate overrides: | |
90 void DidCreateOffscreenContext(const GURL& active_url) override; | 101 void DidCreateOffscreenContext(const GURL& active_url) override; |
91 void DidDestroyChannel(int client_id) override; | 102 void DidDestroyChannel(int client_id) override; |
92 void DidDestroyOffscreenContext(const GURL& active_url) override; | 103 void DidDestroyOffscreenContext(const GURL& active_url) override; |
93 void DidLoseContext(bool offscreen, | 104 void DidLoseContext(bool offscreen, |
94 gpu::error::ContextLostReason reason, | 105 gpu::error::ContextLostReason reason, |
95 const GURL& active_url) override; | 106 const GURL& active_url) override; |
96 void GpuMemoryUmaStats(const gpu::GPUMemoryUmaStats& params) override; | 107 void GpuMemoryUmaStats(const gpu::GPUMemoryUmaStats& params) override; |
97 void StoreShaderToDisk(int client_id, | 108 void StoreShaderToDisk(int client_id, |
98 const std::string& key, | 109 const std::string& key, |
99 const std::string& shader) override; | 110 const std::string& shader) override; |
100 #if defined(OS_WIN) | 111 #if defined(OS_WIN) |
101 void SendAcceleratedSurfaceCreatedChildWindow( | 112 void SendAcceleratedSurfaceCreatedChildWindow( |
102 gpu::SurfaceHandle parent_window, | 113 gpu::SurfaceHandle parent_window, |
103 gpu::SurfaceHandle child_window) override; | 114 gpu::SurfaceHandle child_window) override; |
104 #endif | 115 #endif |
105 void SetActiveURL(const GURL& url) override; | 116 void SetActiveURL(const GURL& url) override; |
106 | 117 |
107 // GpuChannelHostFactory overrides: | 118 // gpu::GpuChannelHostFactory: |
108 bool IsMainThread() override; | 119 bool IsMainThread() override; |
109 scoped_refptr<base::SingleThreadTaskRunner> GetIOThreadTaskRunner() override; | 120 scoped_refptr<base::SingleThreadTaskRunner> GetIOThreadTaskRunner() override; |
110 std::unique_ptr<base::SharedMemory> AllocateSharedMemory( | 121 std::unique_ptr<base::SharedMemory> AllocateSharedMemory( |
111 size_t size) override; | 122 size_t size) override; |
112 | 123 |
113 // TODO(sad): This should not be a singleton. | 124 // mojom::GpuServiceInternal: |
114 static GpuServiceInternal* GetInstance(); | 125 void Initialize(const InitializeCallback& callback) override; |
| 126 void EstablishGpuChannel( |
| 127 int32_t client_id, |
| 128 uint64_t client_tracing_id, |
| 129 const EstablishGpuChannelCallback& callback) override; |
115 | 130 |
116 private: | |
117 friend struct base::DefaultSingletonTraits<GpuServiceInternal>; | |
118 | |
119 GpuServiceInternal(); | |
120 ~GpuServiceInternal() override; | |
121 | |
122 void Initialize(); | |
123 void InitializeOnGpuThread(mojo::ScopedMessagePipeHandle* channel_handle, | 131 void InitializeOnGpuThread(mojo::ScopedMessagePipeHandle* channel_handle, |
124 base::WaitableEvent* event); | 132 base::WaitableEvent* event); |
125 void EstablishGpuChannelOnGpuThread( | 133 void EstablishGpuChannelOnGpuThread( |
126 int client_id, | 134 int client_id, |
127 uint64_t client_tracing_id, | 135 uint64_t client_tracing_id, |
128 bool preempts, | 136 bool preempts, |
129 bool allow_view_command_buffers, | 137 bool allow_view_command_buffers, |
130 bool allow_real_time_streams, | 138 bool allow_real_time_streams, |
131 mojo::ScopedMessagePipeHandle* channel_handle); | 139 mojo::ScopedMessagePipeHandle* channel_handle); |
132 | 140 |
133 // The next client id. | |
134 int next_client_id_; | |
135 | |
136 // The main thread task runner. | 141 // The main thread task runner. |
137 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 142 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
138 | 143 |
139 // An event that will be signalled when we shutdown. | 144 // An event that will be signalled when we shutdown. |
140 base::WaitableEvent shutdown_event_; | 145 base::WaitableEvent shutdown_event_; |
141 | 146 |
142 // The main thread for GpuService. | 147 // The main thread for GpuService. |
143 base::Thread gpu_thread_; | 148 base::Thread gpu_thread_; |
144 | 149 |
145 // The thread that handles IO events for GpuService. | 150 // The thread that handles IO events for GpuService. |
(...skipping 11 matching lines...) Expand all Loading... |
157 std::unique_ptr<MusGpuMemoryBufferManager> gpu_memory_buffer_manager_local_; | 162 std::unique_ptr<MusGpuMemoryBufferManager> gpu_memory_buffer_manager_local_; |
158 | 163 |
159 // A GPU channel used locally. | 164 // A GPU channel used locally. |
160 scoped_refptr<gpu::GpuChannelHost> gpu_channel_local_; | 165 scoped_refptr<gpu::GpuChannelHost> gpu_channel_local_; |
161 | 166 |
162 gpu::GpuPreferences gpu_preferences_; | 167 gpu::GpuPreferences gpu_preferences_; |
163 | 168 |
164 // Information about the GPU, such as device and vendor ID. | 169 // Information about the GPU, such as device and vendor ID. |
165 gpu::GPUInfo gpu_info_; | 170 gpu::GPUInfo gpu_info_; |
166 | 171 |
| 172 mojo::StrongBinding<mojom::GpuServiceInternal> binding_; |
| 173 |
167 DISALLOW_COPY_AND_ASSIGN(GpuServiceInternal); | 174 DISALLOW_COPY_AND_ASSIGN(GpuServiceInternal); |
168 }; | 175 }; |
169 | 176 |
170 } // namespace ui | 177 } // namespace ui |
171 | 178 |
172 #endif // SERVICES_UI_GPU_GPU_SERVICE_INTERNAL_H_ | 179 #endif // SERVICES_UI_GPU_GPU_SERVICE_INTERNAL_H_ |
OLD | NEW |