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( |
| 61 gfx::GpuMemoryBufferId id, |
| 62 const gfx::Size& size, |
| 63 gfx::BufferFormat format, |
| 64 gfx::BufferUsage usage, |
| 65 int client_id, |
| 66 gpu::SurfaceHandle surface_handle); |
| 67 gfx::GpuMemoryBufferHandle CreateGpuMemoryBufferFromeHandle( |
| 68 gfx::GpuMemoryBufferHandle buffer_handle, |
| 69 gfx::GpuMemoryBufferId id, |
| 70 const gfx::Size& size, |
| 71 gfx::BufferFormat format, |
| 72 int client_id); |
| 73 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, |
| 74 int client_id, |
| 75 const gpu::SyncToken& sync_token); |
23 | 76 |
24 // mojom::GpuService overrides: | 77 scoped_refptr<gpu::GpuChannelHost> gpu_channel_local() const { |
25 void EstablishGpuChannel( | 78 return gpu_channel_local_; |
26 bool prempts, | 79 } |
27 bool allow_view_command_buffers, | |
28 bool allow_real_time_streams, | |
29 const mojom::GpuService::EstablishGpuChannelCallback& callback) override; | |
30 | 80 |
31 void CreateGpuMemoryBuffer( | 81 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 | 82 |
51 // GpuChannelManagerDelegate overrides: | 83 // GpuChannelManagerDelegate overrides: |
52 void DidCreateOffscreenContext(const GURL& active_url) override; | 84 void DidCreateOffscreenContext(const GURL& active_url) override; |
53 void DidDestroyChannel(int client_id) override; | 85 void DidDestroyChannel(int client_id) override; |
54 void DidDestroyOffscreenContext(const GURL& active_url) override; | 86 void DidDestroyOffscreenContext(const GURL& active_url) override; |
55 void DidLoseContext(bool offscreen, | 87 void DidLoseContext(bool offscreen, |
56 gpu::error::ContextLostReason reason, | 88 gpu::error::ContextLostReason reason, |
57 const GURL& active_url) override; | 89 const GURL& active_url) override; |
58 void GpuMemoryUmaStats(const gpu::GPUMemoryUmaStats& params) override; | 90 void GpuMemoryUmaStats(const gpu::GPUMemoryUmaStats& params) override; |
59 void StoreShaderToDisk(int32_t client_id, | 91 void StoreShaderToDisk(int client_id, |
60 const std::string& key, | 92 const std::string& key, |
61 const std::string& shader) override; | 93 const std::string& shader) override; |
62 #if defined(OS_WIN) | 94 #if defined(OS_WIN) |
63 void SendAcceleratedSurfaceCreatedChildWindow( | 95 void SendAcceleratedSurfaceCreatedChildWindow( |
64 gpu::SurfaceHandle parent_window, | 96 gpu::SurfaceHandle parent_window, |
65 gpu::SurfaceHandle child_window) override; | 97 gpu::SurfaceHandle child_window) override; |
66 #endif | 98 #endif |
67 void SetActiveURL(const GURL& url) override; | 99 void SetActiveURL(const GURL& url) override; |
68 | 100 |
| 101 // GpuChannelHostFactory overrides: |
| 102 bool IsMainThread() override; |
| 103 scoped_refptr<base::SingleThreadTaskRunner> GetIOThreadTaskRunner() override; |
| 104 std::unique_ptr<base::SharedMemory> AllocateSharedMemory( |
| 105 size_t size) override; |
| 106 |
| 107 static GpuServiceMus* GetInstance(); |
| 108 |
69 private: | 109 private: |
| 110 friend struct base::DefaultSingletonTraits<GpuServiceMus>; |
| 111 |
| 112 GpuServiceMus(); |
| 113 ~GpuServiceMus() override; |
| 114 |
| 115 void Initialize(); |
| 116 void InitializeOnGpuThread(IPC::ChannelHandle* channel_handle, |
| 117 base::WaitableEvent* event); |
| 118 void EstablishGpuChannelOnGpuThread(int client_id, |
| 119 uint64_t client_tracing_id, |
| 120 bool preempts, |
| 121 bool allow_view_command_buffers, |
| 122 bool allow_real_time_streams, |
| 123 IPC::ChannelHandle* channel_handle); |
| 124 |
| 125 // The main thread message loop. |
| 126 base::MessageLoop* main_message_loop_; |
| 127 |
| 128 // An event that will be signalled when we shutdown. |
| 129 base::WaitableEvent shutdown_event_; |
| 130 |
| 131 // The main thread for GpuService. |
| 132 base::Thread gpu_thread_; |
| 133 |
| 134 // The thread that handles IO events for GpuService. |
| 135 base::Thread io_thread_; |
| 136 |
| 137 std::unique_ptr<gpu::SyncPointManager> owned_sync_point_manager_; |
| 138 |
| 139 std::unique_ptr<gpu::GpuChannelManager> gpu_channel_manager_; |
| 140 |
| 141 std::unique_ptr<media::MediaService> media_service_; |
| 142 |
| 143 std::unique_ptr<gpu::GpuMemoryBufferFactory> gpu_memory_buffer_factory_; |
| 144 |
| 145 // A GPU memory buffer manager used locally. |
| 146 std::unique_ptr<GpuMemoryBufferManagerMusLocal> |
| 147 gpu_memory_buffer_manager_mus_local_; |
| 148 |
| 149 // A GPU channel used locally. |
| 150 scoped_refptr<gpu::GpuChannelHost> gpu_channel_local_; |
| 151 |
| 152 gpu::GpuPreferences gpu_preferences_; |
| 153 |
| 154 // Information about the GPU, such as device and vendor ID. |
| 155 gpu::GPUInfo gpu_info_; |
| 156 |
70 DISALLOW_COPY_AND_ASSIGN(GpuServiceMus); | 157 DISALLOW_COPY_AND_ASSIGN(GpuServiceMus); |
71 }; | 158 }; |
72 | 159 |
73 } // namespace mus | 160 } // namespace mus |
74 | 161 |
75 #endif // COMPONENTS_MUS_GPU_GPU_SERVICE_MUS_H_ | 162 #endif // COMPONENTS_MUS_GPU_GPU_SERVICE_MUS_H_ |
OLD | NEW |