| 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_GPU_H_ | 5 #ifndef SERVICES_UI_PUBLIC_CPP_GPU_GPU_H_ |
| 6 #define SERVICES_UI_PUBLIC_CPP_GPU_GPU_H_ | 6 #define SERVICES_UI_PUBLIC_CPP_GPU_GPU_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
| 15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 16 #include "gpu/ipc/client/gpu_channel_host.h" | 16 #include "gpu/ipc/client/gpu_channel_host.h" |
| 17 #include "services/ui/public/cpp/gpu/client_gpu_memory_buffer_manager.h" | 17 #include "services/ui/public/cpp/gpu/client_gpu_memory_buffer_manager.h" |
| 18 #include "services/ui/public/interfaces/gpu.mojom.h" | 18 #include "services/ui/public/interfaces/gpu.mojom.h" |
| 19 | 19 |
| 20 namespace service_manager { | 20 namespace service_manager { |
| 21 class Connector; | 21 class Connector; |
| 22 class InterfaceProvider; |
| 22 } | 23 } |
| 23 | 24 |
| 24 namespace ui { | 25 namespace ui { |
| 25 | 26 |
| 26 class Gpu : public gpu::GpuChannelHostFactory, | 27 class Gpu : public gpu::GpuChannelHostFactory, |
| 27 public gpu::GpuChannelEstablishFactory { | 28 public gpu::GpuChannelEstablishFactory { |
| 28 public: | 29 public: |
| 29 ~Gpu() override; | 30 ~Gpu() override; |
| 30 | 31 |
| 31 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager() const { | 32 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager() const { |
| 32 return gpu_memory_buffer_manager_.get(); | 33 return gpu_memory_buffer_manager_.get(); |
| 33 } | 34 } |
| 34 | 35 |
| 35 // The Gpu has to be initialized in the main thread before establishing | 36 // The Gpu has to be initialized in the main thread before establishing |
| 36 // the gpu channel. If no |task_runner| is provided, then a new thread is | 37 // the gpu channel. If no |task_runner| is provided, then a new thread is |
| 37 // created and used. | 38 // created and used. |
| 38 static std::unique_ptr<Gpu> Create( | 39 static std::unique_ptr<Gpu> Create( |
| 39 service_manager::Connector* connector, | 40 service_manager::Connector* connector, |
| 40 scoped_refptr<base::SingleThreadTaskRunner> task_runner = nullptr); | 41 scoped_refptr<base::SingleThreadTaskRunner> task_runner = nullptr); |
| 42 static std::unique_ptr<Gpu> Create( |
| 43 service_manager::InterfaceProvider*, |
| 44 scoped_refptr<base::SingleThreadTaskRunner> task_runner = nullptr); |
| 41 | 45 |
| 42 // gpu::GpuChannelEstablishFactory: | 46 // gpu::GpuChannelEstablishFactory: |
| 43 void EstablishGpuChannel( | 47 void EstablishGpuChannel( |
| 44 const gpu::GpuChannelEstablishedCallback& callback) override; | 48 const gpu::GpuChannelEstablishedCallback& callback) override; |
| 45 scoped_refptr<gpu::GpuChannelHost> EstablishGpuChannelSync() override; | 49 scoped_refptr<gpu::GpuChannelHost> EstablishGpuChannelSync() override; |
| 46 gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override; | 50 gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override; |
| 47 | 51 |
| 48 private: | 52 private: |
| 49 friend struct base::DefaultSingletonTraits<Gpu>; | 53 friend struct base::DefaultSingletonTraits<Gpu>; |
| 50 | 54 |
| 51 Gpu(service_manager::Connector* connector, | 55 Gpu(service_manager::Connector* connector, |
| 56 service_manager::InterfaceProvider* provider, |
| 52 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 57 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 53 | 58 |
| 54 scoped_refptr<gpu::GpuChannelHost> GetGpuChannel(); | 59 scoped_refptr<gpu::GpuChannelHost> GetGpuChannel(); |
| 55 void EstablishGpuChannelOnMainThreadSyncLocked(); | 60 void EstablishGpuChannelOnMainThreadSyncLocked(); |
| 56 void OnEstablishedGpuChannel(int client_id, | 61 void OnEstablishedGpuChannel(int client_id, |
| 57 mojo::ScopedMessagePipeHandle channel_handle, | 62 mojo::ScopedMessagePipeHandle channel_handle, |
| 58 const gpu::GPUInfo& gpu_info); | 63 const gpu::GPUInfo& gpu_info); |
| 59 | 64 |
| 60 // gpu::GpuChannelHostFactory overrides: | 65 // gpu::GpuChannelHostFactory overrides: |
| 61 bool IsMainThread() override; | 66 bool IsMainThread() override; |
| 62 scoped_refptr<base::SingleThreadTaskRunner> GetIOThreadTaskRunner() override; | 67 scoped_refptr<base::SingleThreadTaskRunner> GetIOThreadTaskRunner() override; |
| 63 std::unique_ptr<base::SharedMemory> AllocateSharedMemory( | 68 std::unique_ptr<base::SharedMemory> AllocateSharedMemory( |
| 64 size_t size) override; | 69 size_t size) override; |
| 65 | 70 |
| 66 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 71 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| 67 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 72 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 68 service_manager::Connector* connector_; | 73 service_manager::Connector* connector_; |
| 74 service_manager::InterfaceProvider* interface_provider_; |
| 69 base::WaitableEvent shutdown_event_; | 75 base::WaitableEvent shutdown_event_; |
| 70 std::unique_ptr<base::Thread> io_thread_; | 76 std::unique_ptr<base::Thread> io_thread_; |
| 71 std::unique_ptr<ClientGpuMemoryBufferManager> gpu_memory_buffer_manager_; | 77 std::unique_ptr<ClientGpuMemoryBufferManager> gpu_memory_buffer_manager_; |
| 72 | 78 |
| 73 ui::mojom::GpuPtr gpu_service_; | 79 ui::mojom::GpuPtr gpu_; |
| 74 scoped_refptr<gpu::GpuChannelHost> gpu_channel_; | 80 scoped_refptr<gpu::GpuChannelHost> gpu_channel_; |
| 75 std::vector<gpu::GpuChannelEstablishedCallback> establish_callbacks_; | 81 std::vector<gpu::GpuChannelEstablishedCallback> establish_callbacks_; |
| 76 | 82 |
| 77 DISALLOW_COPY_AND_ASSIGN(Gpu); | 83 DISALLOW_COPY_AND_ASSIGN(Gpu); |
| 78 }; | 84 }; |
| 79 | 85 |
| 80 } // namespace ui | 86 } // namespace ui |
| 81 | 87 |
| 82 #endif // SERVICES_UI_PUBLIC_CPP_GPU_GPU_H_ | 88 #endif // SERVICES_UI_PUBLIC_CPP_GPU_GPU_H_ |
| OLD | NEW |