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