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 COMPONENTS_MUS_GPU_GPU_SERVICE_MUS_H_ | 5 #ifndef COMPONENTS_MUS_GPU_GPU_SERVICE_MUS_H_ |
6 #define COMPONENTS_MUS_GPU_GPU_SERVICE_MUS_H_ | 6 #define COMPONENTS_MUS_GPU_GPU_SERVICE_MUS_H_ |
7 | 7 |
8 #include "components/mus/public/interfaces/gpu_memory_buffer.mojom.h" | 8 #include "base/callback.h" |
9 #include "components/mus/public/interfaces/gpu_service.mojom.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "base/threading/thread.h" |
| 11 #include "build/build_config.h" |
| 12 #include "gpu/command_buffer/service/gpu_preferences.h" |
| 13 #include "gpu/config/gpu_info.h" |
| 14 #include "gpu/ipc/client/gpu_channel_host.h" |
10 #include "gpu/ipc/common/surface_handle.h" | 15 #include "gpu/ipc/common/surface_handle.h" |
| 16 #include "gpu/ipc/service/gpu_channel.h" |
| 17 #include "gpu/ipc/service/gpu_channel_manager.h" |
11 #include "gpu/ipc/service/gpu_channel_manager_delegate.h" | 18 #include "gpu/ipc/service/gpu_channel_manager_delegate.h" |
| 19 #include "gpu/ipc/service/gpu_config.h" |
| 20 #include "gpu/ipc/service/x_util.h" |
| 21 #include "ui/gfx/native_widget_types.h" |
| 22 |
| 23 namespace base { |
| 24 template <typename T> |
| 25 struct DefaultSingletonTraits; |
| 26 } |
| 27 |
| 28 namespace IPC { |
| 29 struct ChannelHandle; |
| 30 } |
| 31 |
| 32 namespace gpu { |
| 33 class GpuChannelHost; |
| 34 class GpuMemoryBufferFactory; |
| 35 class SyncPointManager; |
| 36 } |
| 37 |
| 38 namespace media { |
| 39 class MediaService; |
| 40 } |
12 | 41 |
13 namespace mus { | 42 namespace mus { |
14 | 43 |
| 44 class GpuMemoryBufferManagerMusLocal; |
| 45 |
15 // TODO(fsamuel): GpuServiceMus is intended to be the Gpu thread within Mus. | 46 // TODO(fsamuel): GpuServiceMus is intended to be the Gpu thread within Mus. |
16 // Similar to GpuChildThread, it is a GpuChannelManagerDelegate and will have a | 47 // Similar to GpuChildThread, it is a GpuChannelManagerDelegate and will have a |
17 // GpuChannelManager. | 48 // GpuChannelManager. |
18 class GpuServiceMus : public mojom::GpuService, | 49 class GpuServiceMus : public gpu::GpuChannelManagerDelegate, |
19 public gpu::GpuChannelManagerDelegate { | 50 public gpu::GpuChannelHostFactory { |
20 public: | 51 public: |
21 GpuServiceMus(); | 52 typedef base::Callback<void(const IPC::ChannelHandle&)> |
22 ~GpuServiceMus() override; | 53 EstablishGpuChannelCallback; |
| 54 void EstablishGpuChannel(int client_id, |
| 55 uint64_t client_tracing_id, |
| 56 bool preempts, |
| 57 bool allow_view_command_buffers, |
| 58 bool allow_real_time_streams, |
| 59 const EstablishGpuChannelCallback& callback); |
| 60 gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer(gfx::GpuMemoryBufferId id, |
| 61 const gfx::Size& size, |
| 62 gfx::BufferFormat format, |
| 63 gfx::BufferUsage usage, |
| 64 int client_id, |
| 65 int32_t surface_handle); |
| 66 gfx::GpuMemoryBufferHandle CreateGpuMemoryBufferFromeHandle( |
| 67 gfx::GpuMemoryBufferHandle buffer_handle, |
| 68 gfx::GpuMemoryBufferId id, |
| 69 const gfx::Size& size, |
| 70 gfx::BufferFormat format, |
| 71 int client_id); |
| 72 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, |
| 73 int client_id, |
| 74 const gpu::SyncToken& sync_token); |
23 | 75 |
24 // mojom::GpuService overrides: | 76 scoped_refptr<gpu::GpuChannelHost> gpu_channel_local() const { |
25 void EstablishGpuChannel( | 77 return gpu_channel_local_; |
26 bool prempts, | 78 } |
27 bool allow_view_command_buffers, | |
28 bool allow_real_time_streams, | |
29 const mojom::GpuService::EstablishGpuChannelCallback& callback) override; | |
30 | 79 |
31 void CreateGpuMemoryBuffer( | 80 const gpu::GPUInfo& gpu_info() const { return gpu_info_; } |
32 mojom::GpuMemoryBufferIdPtr id, | |
33 const gfx::Size& size, | |
34 mojom::BufferFormat format, | |
35 mojom::BufferUsage usage, | |
36 uint64_t surface_id, | |
37 const mojom::GpuService::CreateGpuMemoryBufferCallback& callback) | |
38 override; | |
39 | |
40 void CreateGpuMemoryBufferFromHandle( | |
41 mojom::GpuMemoryBufferHandlePtr buffer_handle, | |
42 mojom::GpuMemoryBufferIdPtr id, | |
43 const gfx::Size& size, | |
44 mojom::BufferFormat format, | |
45 const mojom::GpuService::CreateGpuMemoryBufferFromHandleCallback& | |
46 callback) override; | |
47 | |
48 void DestroyGpuMemoryBuffer(mojom::GpuMemoryBufferIdPtr id, | |
49 const gpu::SyncToken& sync_token) override; | |
50 | 81 |
51 // GpuChannelManagerDelegate overrides: | 82 // GpuChannelManagerDelegate overrides: |
52 void DidCreateOffscreenContext(const GURL& active_url) override; | 83 void DidCreateOffscreenContext(const GURL& active_url) override; |
53 void DidDestroyChannel(int client_id) override; | 84 void DidDestroyChannel(int client_id) override; |
54 void DidDestroyOffscreenContext(const GURL& active_url) override; | 85 void DidDestroyOffscreenContext(const GURL& active_url) override; |
55 void DidLoseContext(bool offscreen, | 86 void DidLoseContext(bool offscreen, |
56 gpu::error::ContextLostReason reason, | 87 gpu::error::ContextLostReason reason, |
57 const GURL& active_url) override; | 88 const GURL& active_url) override; |
58 void GpuMemoryUmaStats(const gpu::GPUMemoryUmaStats& params) override; | 89 void GpuMemoryUmaStats(const gpu::GPUMemoryUmaStats& params) override; |
59 void StoreShaderToDisk(int32_t client_id, | 90 void StoreShaderToDisk(int client_id, |
60 const std::string& key, | 91 const std::string& key, |
61 const std::string& shader) override; | 92 const std::string& shader) override; |
62 #if defined(OS_WIN) | 93 #if defined(OS_WIN) |
63 void SendAcceleratedSurfaceCreatedChildWindow( | 94 void SendAcceleratedSurfaceCreatedChildWindow( |
64 gpu::SurfaceHandle parent_window, | 95 gpu::SurfaceHandle parent_window, |
65 gpu::SurfaceHandle child_window) override; | 96 gpu::SurfaceHandle child_window) override; |
66 #endif | 97 #endif |
67 void SetActiveURL(const GURL& url) override; | 98 void SetActiveURL(const GURL& url) override; |
68 | 99 |
| 100 // GpuChannelHostFactory overrides: |
| 101 bool IsMainThread() override; |
| 102 scoped_refptr<base::SingleThreadTaskRunner> GetIOThreadTaskRunner() override; |
| 103 std::unique_ptr<base::SharedMemory> AllocateSharedMemory( |
| 104 size_t size) override; |
| 105 |
| 106 static GpuServiceMus* GetInstance(); |
| 107 |
69 private: | 108 private: |
| 109 friend struct base::DefaultSingletonTraits<GpuServiceMus>; |
| 110 |
| 111 GpuServiceMus(); |
| 112 ~GpuServiceMus() override; |
| 113 |
| 114 void Initialize(); |
| 115 void InitializeOnGpuThread(IPC::ChannelHandle* channel_handle, |
| 116 base::WaitableEvent* event); |
| 117 void EstablishGpuChannelOnGpuThread(int client_id, |
| 118 uint64_t client_tracing_id, |
| 119 bool preempts, |
| 120 bool allow_view_command_buffers, |
| 121 bool allow_real_time_streams, |
| 122 IPC::ChannelHandle* channel_handle); |
| 123 |
| 124 // The main thread message loop. |
| 125 base::MessageLoop* main_message_loop_; |
| 126 |
| 127 // An event that will be signalled when we shutdown. |
| 128 base::WaitableEvent shutdown_event_; |
| 129 |
| 130 // The main thread for GpuService. |
| 131 base::Thread gpu_thread_; |
| 132 |
| 133 // The thread that handles IO events for GpuService. |
| 134 base::Thread io_thread_; |
| 135 |
| 136 std::unique_ptr<gpu::SyncPointManager> owned_sync_point_manager_; |
| 137 |
| 138 std::unique_ptr<gpu::GpuChannelManager> gpu_channel_manager_; |
| 139 |
| 140 std::unique_ptr<media::MediaService> media_service_; |
| 141 |
| 142 std::unique_ptr<gpu::GpuMemoryBufferFactory> gpu_memory_buffer_factory_; |
| 143 |
| 144 // A GPU memory buffer manager used locally. |
| 145 std::unique_ptr<GpuMemoryBufferManagerMusLocal> |
| 146 gpu_memory_buffer_manager_mus_local_; |
| 147 |
| 148 // A GPU channel used locally. |
| 149 scoped_refptr<gpu::GpuChannelHost> gpu_channel_local_; |
| 150 |
| 151 gpu::GpuPreferences gpu_preferences_; |
| 152 |
| 153 // Information about the GPU, such as device and vendor ID. |
| 154 gpu::GPUInfo gpu_info_; |
| 155 |
70 DISALLOW_COPY_AND_ASSIGN(GpuServiceMus); | 156 DISALLOW_COPY_AND_ASSIGN(GpuServiceMus); |
71 }; | 157 }; |
72 | 158 |
73 } // namespace mus | 159 } // namespace mus |
74 | 160 |
75 #endif // COMPONENTS_MUS_GPU_GPU_SERVICE_MUS_H_ | 161 #endif // COMPONENTS_MUS_GPU_GPU_SERVICE_MUS_H_ |
OLD | NEW |