| 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_PUBLIC_CPP_GPU_SERVICE_H_ | 5 #ifndef SERVICES_UI_PUBLIC_CPP_GPU_SERVICE_H_ |
| 6 #define SERVICES_UI_PUBLIC_CPP_GPU_SERVICE_H_ | 6 #define SERVICES_UI_PUBLIC_CPP_GPU_SERVICE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 class GpuService : public gpu::GpuChannelHostFactory, | 28 class GpuService : public gpu::GpuChannelHostFactory, |
| 29 public gpu::GpuChannelEstablishFactory { | 29 public gpu::GpuChannelEstablishFactory { |
| 30 public: | 30 public: |
| 31 ~GpuService() override; | 31 ~GpuService() override; |
| 32 | 32 |
| 33 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager() const { | 33 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager() const { |
| 34 return gpu_memory_buffer_manager_.get(); | 34 return gpu_memory_buffer_manager_.get(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 // The GpuService has to be initialized in the main thread before establishing | 37 // The GpuService has to be initialized in the main thread before establishing |
| 38 // the gpu channel. | 38 // the gpu channel. If no |task_runner| is provided, then a new thread is |
| 39 static std::unique_ptr<GpuService> Initialize(shell::Connector* connector); | 39 // created and used. |
| 40 static std::unique_ptr<GpuService> Create( |
| 41 shell::Connector* connector, |
| 42 scoped_refptr<base::SingleThreadTaskRunner> task_runner = nullptr); |
| 40 | 43 |
| 41 // gpu::GpuChannelEstablishFactory: | 44 // gpu::GpuChannelEstablishFactory: |
| 42 void EstablishGpuChannel( | 45 void EstablishGpuChannel( |
| 43 const gpu::GpuChannelEstablishedCallback& callback) override; | 46 const gpu::GpuChannelEstablishedCallback& callback) override; |
| 44 scoped_refptr<gpu::GpuChannelHost> EstablishGpuChannelSync() override; | 47 scoped_refptr<gpu::GpuChannelHost> EstablishGpuChannelSync() override; |
| 45 gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override; | 48 gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override; |
| 46 | 49 |
| 47 private: | 50 private: |
| 48 friend struct base::DefaultSingletonTraits<GpuService>; | 51 friend struct base::DefaultSingletonTraits<GpuService>; |
| 49 | 52 |
| 50 explicit GpuService(shell::Connector* connector); | 53 GpuService(shell::Connector* connector, |
| 54 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 51 | 55 |
| 52 scoped_refptr<gpu::GpuChannelHost> GetGpuChannelLocked(); | 56 scoped_refptr<gpu::GpuChannelHost> GetGpuChannelLocked(); |
| 53 void EstablishGpuChannelOnMainThread(); | 57 void EstablishGpuChannelOnMainThread(); |
| 54 void EstablishGpuChannelOnMainThreadSyncLocked(); | 58 void EstablishGpuChannelOnMainThreadSyncLocked(); |
| 55 void EstablishGpuChannelOnMainThreadDone( | 59 void EstablishGpuChannelOnMainThreadDone( |
| 56 bool locked, | 60 bool locked, |
| 57 int client_id, | 61 int client_id, |
| 58 mojo::ScopedMessagePipeHandle channel_handle, | 62 mojo::ScopedMessagePipeHandle channel_handle, |
| 59 const gpu::GPUInfo& gpu_info); | 63 const gpu::GPUInfo& gpu_info); |
| 60 | 64 |
| 61 // gpu::GpuChannelHostFactory overrides: | 65 // gpu::GpuChannelHostFactory overrides: |
| 62 bool IsMainThread() override; | 66 bool IsMainThread() override; |
| 63 scoped_refptr<base::SingleThreadTaskRunner> GetIOThreadTaskRunner() override; | 67 scoped_refptr<base::SingleThreadTaskRunner> GetIOThreadTaskRunner() override; |
| 64 std::unique_ptr<base::SharedMemory> AllocateSharedMemory( | 68 std::unique_ptr<base::SharedMemory> AllocateSharedMemory( |
| 65 size_t size) override; | 69 size_t size) override; |
| 66 | 70 |
| 67 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 71 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| 72 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 68 shell::Connector* connector_; | 73 shell::Connector* connector_; |
| 69 base::WaitableEvent shutdown_event_; | 74 base::WaitableEvent shutdown_event_; |
| 70 base::Thread io_thread_; | 75 std::unique_ptr<base::Thread> io_thread_; |
| 71 std::unique_ptr<MojoGpuMemoryBufferManager> gpu_memory_buffer_manager_; | 76 std::unique_ptr<MojoGpuMemoryBufferManager> gpu_memory_buffer_manager_; |
| 72 | 77 |
| 73 // Lock for |gpu_channel_|, |establish_callbacks_| & |is_establishing_|. | 78 // Lock for |gpu_channel_|, |establish_callbacks_| & |is_establishing_|. |
| 74 base::Lock lock_; | 79 base::Lock lock_; |
| 75 bool is_establishing_; | 80 bool is_establishing_; |
| 76 ui::mojom::GpuServicePtr gpu_service_; | 81 ui::mojom::GpuServicePtr gpu_service_; |
| 77 scoped_refptr<gpu::GpuChannelHost> gpu_channel_; | 82 scoped_refptr<gpu::GpuChannelHost> gpu_channel_; |
| 78 std::vector<gpu::GpuChannelEstablishedCallback> establish_callbacks_; | 83 std::vector<gpu::GpuChannelEstablishedCallback> establish_callbacks_; |
| 79 base::ConditionVariable establishing_condition_; | 84 base::ConditionVariable establishing_condition_; |
| 80 | 85 |
| 81 DISALLOW_COPY_AND_ASSIGN(GpuService); | 86 DISALLOW_COPY_AND_ASSIGN(GpuService); |
| 82 }; | 87 }; |
| 83 | 88 |
| 84 } // namespace ui | 89 } // namespace ui |
| 85 | 90 |
| 86 #endif // SERVICES_UI_PUBLIC_CPP_GPU_SERVICE_H_ | 91 #endif // SERVICES_UI_PUBLIC_CPP_GPU_SERVICE_H_ |
| OLD | NEW |