| 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(uint64_t client_tracing_id, |
| 78 bool preempts, |
| 79 bool allow_view_command_buffers, |
| 80 bool allow_real_time_streams, |
| 81 const EstablishGpuChannelCallback& callback); |
| 58 gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer( | 82 gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer( |
| 59 gfx::GpuMemoryBufferId id, | 83 gfx::GpuMemoryBufferId id, |
| 60 const gfx::Size& size, | 84 const gfx::Size& size, |
| 61 gfx::BufferFormat format, | 85 gfx::BufferFormat format, |
| 62 gfx::BufferUsage usage, | 86 gfx::BufferUsage usage, |
| 63 int client_id, | 87 int client_id, |
| 64 gpu::SurfaceHandle surface_handle); | 88 gpu::SurfaceHandle surface_handle); |
| 65 gfx::GpuMemoryBufferHandle CreateGpuMemoryBufferFromeHandle( | 89 gfx::GpuMemoryBufferHandle CreateGpuMemoryBufferFromeHandle( |
| 66 gfx::GpuMemoryBufferHandle buffer_handle, | 90 gfx::GpuMemoryBufferHandle buffer_handle, |
| 67 gfx::GpuMemoryBufferId id, | 91 gfx::GpuMemoryBufferId id, |
| 68 const gfx::Size& size, | 92 const gfx::Size& size, |
| 69 gfx::BufferFormat format, | 93 gfx::BufferFormat format, |
| 70 int client_id); | 94 int client_id); |
| 71 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, | 95 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, |
| 72 int client_id, | 96 int client_id, |
| 73 const gpu::SyncToken& sync_token); | 97 const gpu::SyncToken& sync_token); |
| 74 | 98 |
| 75 gpu::GpuChannelManager* gpu_channel_manager() const { | 99 // 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; | 100 void DidCreateOffscreenContext(const GURL& active_url) override; |
| 91 void DidDestroyChannel(int client_id) override; | 101 void DidDestroyChannel(int client_id) override; |
| 92 void DidDestroyOffscreenContext(const GURL& active_url) override; | 102 void DidDestroyOffscreenContext(const GURL& active_url) override; |
| 93 void DidLoseContext(bool offscreen, | 103 void DidLoseContext(bool offscreen, |
| 94 gpu::error::ContextLostReason reason, | 104 gpu::error::ContextLostReason reason, |
| 95 const GURL& active_url) override; | 105 const GURL& active_url) override; |
| 96 void GpuMemoryUmaStats(const gpu::GPUMemoryUmaStats& params) override; | 106 void GpuMemoryUmaStats(const gpu::GPUMemoryUmaStats& params) override; |
| 97 void StoreShaderToDisk(int client_id, | 107 void StoreShaderToDisk(int client_id, |
| 98 const std::string& key, | 108 const std::string& key, |
| 99 const std::string& shader) override; | 109 const std::string& shader) override; |
| 100 #if defined(OS_WIN) | 110 #if defined(OS_WIN) |
| 101 void SendAcceleratedSurfaceCreatedChildWindow( | 111 void SendAcceleratedSurfaceCreatedChildWindow( |
| 102 gpu::SurfaceHandle parent_window, | 112 gpu::SurfaceHandle parent_window, |
| 103 gpu::SurfaceHandle child_window) override; | 113 gpu::SurfaceHandle child_window) override; |
| 104 #endif | 114 #endif |
| 105 void SetActiveURL(const GURL& url) override; | 115 void SetActiveURL(const GURL& url) override; |
| 106 | 116 |
| 107 // GpuChannelHostFactory overrides: | 117 // gpu::GpuChannelHostFactory: |
| 108 bool IsMainThread() override; | 118 bool IsMainThread() override; |
| 109 scoped_refptr<base::SingleThreadTaskRunner> GetIOThreadTaskRunner() override; | 119 scoped_refptr<base::SingleThreadTaskRunner> GetIOThreadTaskRunner() override; |
| 110 std::unique_ptr<base::SharedMemory> AllocateSharedMemory( | 120 std::unique_ptr<base::SharedMemory> AllocateSharedMemory( |
| 111 size_t size) override; | 121 size_t size) override; |
| 112 | 122 |
| 113 // TODO(sad): This should not be a singleton. | 123 // mojom::GpuServiceInternal: |
| 114 static GpuServiceInternal* GetInstance(); | 124 void Initialize(const InitializeCallback& callback) override; |
| 125 void EstablishGpuChannel( |
| 126 const EstablishGpuChannelCallback& callback) override; |
| 115 | 127 |
| 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, | 128 void InitializeOnGpuThread(mojo::ScopedMessagePipeHandle* channel_handle, |
| 124 base::WaitableEvent* event); | 129 base::WaitableEvent* event); |
| 125 void EstablishGpuChannelOnGpuThread( | 130 void EstablishGpuChannelOnGpuThread( |
| 126 int client_id, | 131 int client_id, |
| 127 uint64_t client_tracing_id, | 132 uint64_t client_tracing_id, |
| 128 bool preempts, | 133 bool preempts, |
| 129 bool allow_view_command_buffers, | 134 bool allow_view_command_buffers, |
| 130 bool allow_real_time_streams, | 135 bool allow_real_time_streams, |
| 131 mojo::ScopedMessagePipeHandle* channel_handle); | 136 mojo::ScopedMessagePipeHandle* channel_handle); |
| 132 | 137 |
| (...skipping 24 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 |