Chromium Code Reviews| 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/synchronization/waitable_event.h" |
| 9 #include "components/mus/public/interfaces/gpu_service.mojom.h" | 9 #include "base/threading/thread.h" |
| 10 #include "build/build_config.h" | |
| 11 #include "gpu/command_buffer/service/gpu_preferences.h" | |
| 12 #include "gpu/config/gpu_info.h" | |
| 13 #include "gpu/ipc/client/gpu_channel_host.h" | |
| 10 #include "gpu/ipc/common/surface_handle.h" | 14 #include "gpu/ipc/common/surface_handle.h" |
| 15 #include "gpu/ipc/service/gpu_channel.h" | |
| 16 #include "gpu/ipc/service/gpu_channel_manager.h" | |
| 11 #include "gpu/ipc/service/gpu_channel_manager_delegate.h" | 17 #include "gpu/ipc/service/gpu_channel_manager_delegate.h" |
| 18 #include "gpu/ipc/service/gpu_config.h" | |
| 19 #include "gpu/ipc/service/x_util.h" | |
| 20 #include "ui/gfx/native_widget_types.h" | |
| 21 | |
| 22 namespace base { | |
| 23 template <typename T> | |
| 24 struct DefaultSingletonTraits; | |
| 25 } | |
| 26 | |
| 27 namespace IPC { | |
| 28 struct ChannelHandle; | |
| 29 } | |
| 30 | |
| 31 namespace gpu { | |
| 32 class GpuChannelHost; | |
| 33 class GpuMemoryBufferFactory; | |
| 34 class SyncPointManager; | |
| 35 } | |
| 36 | |
| 37 namespace media { | |
| 38 class MediaService; | |
| 39 } | |
| 12 | 40 |
| 13 namespace mus { | 41 namespace mus { |
| 14 | 42 |
| 43 class GpuMemoryBufferManagerMusLocal; | |
| 44 | |
| 15 // TODO(fsamuel): GpuServiceMus is intended to be the Gpu thread within Mus. | 45 // TODO(fsamuel): GpuServiceMus is intended to be the Gpu thread within Mus. |
| 16 // Similar to GpuChildThread, it is a GpuChannelManagerDelegate and will have a | 46 // Similar to GpuChildThread, it is a GpuChannelManagerDelegate and will have a |
| 17 // GpuChannelManager. | 47 // GpuChannelManager. |
| 18 class GpuServiceMus : public mojom::GpuService, | 48 class GpuServiceMus : public gpu::GpuChannelManagerDelegate, |
| 19 public gpu::GpuChannelManagerDelegate { | 49 public gpu::GpuChannelHostFactory { |
| 20 public: | 50 public: |
| 21 GpuServiceMus(); | 51 IPC::ChannelHandle EstablishGpuChannel(int client_id, |
| 22 ~GpuServiceMus() override; | 52 uint64_t client_tracing_id, |
| 53 bool preempts, | |
| 54 bool allow_view_command_buffers, | |
| 55 bool allow_real_time_streams); | |
| 56 gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer(gfx::GpuMemoryBufferId id, | |
| 57 const gfx::Size& size, | |
| 58 gfx::BufferFormat format, | |
| 59 gfx::BufferUsage usage, | |
| 60 int client_id, | |
| 61 int32_t surface_handle); | |
| 62 gfx::GpuMemoryBufferHandle CreateGpuMemoryBufferFromeHandle( | |
| 63 gfx::GpuMemoryBufferHandle buffer_handle, | |
| 64 gfx::GpuMemoryBufferId id, | |
| 65 const gfx::Size& size, | |
| 66 gfx::BufferFormat format, | |
| 67 int client_id); | |
| 68 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, | |
| 69 int client_id, | |
| 70 const gpu::SyncToken& sync_token); | |
| 23 | 71 |
| 24 // mojom::GpuService overrides: | 72 scoped_refptr<gpu::GpuChannelHost> gpu_channel_local() const { |
| 25 void EstablishGpuChannel( | 73 return gpu_channel_local_; |
| 26 bool prempts, | 74 } |
| 27 bool allow_view_command_buffers, | |
| 28 bool allow_real_time_streams, | |
| 29 const mojom::GpuService::EstablishGpuChannelCallback& callback) override; | |
| 30 | 75 |
| 31 void CreateGpuMemoryBuffer( | 76 const gpu::GPUInfo& gpu_info() const { return gpu_info_; } |
| 32 mojom::GpuMemoryBufferIdPtr id, | |
| 33 mojo::SizePtr 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 mojo::SizePtr 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 | 77 |
| 51 // GpuChannelManagerDelegate overrides: | 78 // GpuChannelManagerDelegate overrides: |
| 52 void DidCreateOffscreenContext(const GURL& active_url) override; | 79 void DidCreateOffscreenContext(const GURL& active_url) override; |
| 53 void DidDestroyChannel(int client_id) override; | 80 void DidDestroyChannel(int client_id) override; |
| 54 void DidDestroyOffscreenContext(const GURL& active_url) override; | 81 void DidDestroyOffscreenContext(const GURL& active_url) override; |
| 55 void DidLoseContext(bool offscreen, | 82 void DidLoseContext(bool offscreen, |
| 56 gpu::error::ContextLostReason reason, | 83 gpu::error::ContextLostReason reason, |
| 57 const GURL& active_url) override; | 84 const GURL& active_url) override; |
| 58 void GpuMemoryUmaStats(const gpu::GPUMemoryUmaStats& params) override; | 85 void GpuMemoryUmaStats(const gpu::GPUMemoryUmaStats& params) override; |
| 59 void StoreShaderToDisk(int32_t client_id, | 86 void StoreShaderToDisk(int client_id, |
| 60 const std::string& key, | 87 const std::string& key, |
| 61 const std::string& shader) override; | 88 const std::string& shader) override; |
| 62 #if defined(OS_WIN) | 89 #if defined(OS_WIN) |
| 63 void SendAcceleratedSurfaceCreatedChildWindow( | 90 void SendAcceleratedSurfaceCreatedChildWindow( |
| 64 gpu::SurfaceHandle parent_window, | 91 gpu::SurfaceHandle parent_window, |
| 65 gpu::SurfaceHandle child_window) override; | 92 gpu::SurfaceHandle child_window) override; |
| 66 #endif | 93 #endif |
| 67 void SetActiveURL(const GURL& url) override; | 94 void SetActiveURL(const GURL& url) override; |
| 68 | 95 |
| 96 // GpuChannelHostFactory overrides: | |
| 97 bool IsMainThread() override; | |
| 98 scoped_refptr<base::SingleThreadTaskRunner> GetIOThreadTaskRunner() override; | |
| 99 std::unique_ptr<base::SharedMemory> AllocateSharedMemory( | |
| 100 size_t size) override; | |
| 101 | |
| 102 static GpuServiceMus* GetInstance(); | |
| 103 | |
| 69 private: | 104 private: |
| 105 friend struct base::DefaultSingletonTraits<GpuServiceMus>; | |
| 106 | |
| 107 GpuServiceMus(); | |
| 108 ~GpuServiceMus() override; | |
| 109 | |
| 110 void Initialize(); | |
| 111 void InitializeOnGpuThread(IPC::ChannelHandle* channel_handle, | |
| 112 base::WaitableEvent* event); | |
| 113 void EstablishGpuChannelOnGpuThread(int client_id, | |
| 114 uint64_t client_tracing_id, | |
| 115 bool preempts, | |
| 116 bool allow_view_command_buffers, | |
| 117 bool allow_real_time_streams, | |
| 118 IPC::ChannelHandle* channel_handle, | |
| 119 base::WaitableEvent* event); | |
| 120 | |
| 121 // The main thread message loop. | |
| 122 base::MessageLoop* main_message_loop_; | |
| 123 | |
| 124 // An event that will be signalled when we shutdown. | |
| 125 base::WaitableEvent shutdown_event_; | |
| 126 | |
| 127 // The main thread for GpuService. | |
| 128 base::Thread gpu_thread_; | |
| 129 | |
| 130 // The thread that handles IO events for GpuService. | |
| 131 base::Thread io_thread_; | |
| 132 | |
| 133 // The thread that handles IO events for GpuChannelHost local. | |
|
piman
2016/05/24 22:46:54
Does this have to be different from io_thread_?
I
Peng
2016/05/25 19:42:55
Done.
| |
| 134 base::Thread io_thread_local_; | |
| 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 |