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 "cc/output/context_provider.h" | 16 #include "cc/output/context_provider.h" |
17 #include "gpu/ipc/client/gpu_channel_host.h" | 17 #include "gpu/ipc/client/gpu_channel_host.h" |
18 #include "services/ui/public/cpp/gpu/client_gpu_memory_buffer_manager.h" | 18 #include "services/ui/public/cpp/gpu/client_gpu_memory_buffer_manager.h" |
19 #include "services/ui/public/interfaces/gpu.mojom.h" | 19 #include "services/ui/public/interfaces/gpu.mojom.h" |
20 | 20 |
21 namespace service_manager { | 21 namespace service_manager { |
22 class Connector; | 22 class Connector; |
23 class InterfaceProvider; | |
24 } | 23 } |
25 | 24 |
26 namespace ui { | 25 namespace ui { |
27 | 26 |
28 class Gpu : public gpu::GpuChannelHostFactory, | 27 class Gpu : public gpu::GpuChannelHostFactory, |
29 public gpu::GpuChannelEstablishFactory { | 28 public gpu::GpuChannelEstablishFactory { |
30 public: | 29 public: |
31 ~Gpu() override; | 30 ~Gpu() override; |
32 | 31 |
33 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager() const { | 32 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager() const { |
34 return gpu_memory_buffer_manager_.get(); | 33 return gpu_memory_buffer_manager_.get(); |
35 } | 34 } |
36 | 35 |
37 // 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 |
38 // 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 |
39 // created and used. | 38 // created and used. |
40 static std::unique_ptr<Gpu> Create( | 39 static std::unique_ptr<Gpu> Create( |
41 service_manager::Connector* connector, | 40 service_manager::Connector* connector, |
42 scoped_refptr<base::SingleThreadTaskRunner> task_runner = nullptr); | 41 const std::string& service_name, |
43 static std::unique_ptr<Gpu> Create( | |
44 service_manager::InterfaceProvider*, | |
45 scoped_refptr<base::SingleThreadTaskRunner> task_runner = nullptr); | 42 scoped_refptr<base::SingleThreadTaskRunner> task_runner = nullptr); |
46 | 43 |
47 scoped_refptr<cc::ContextProvider> CreateContextProvider( | 44 scoped_refptr<cc::ContextProvider> CreateContextProvider( |
48 scoped_refptr<gpu::GpuChannelHost> gpu_channel); | 45 scoped_refptr<gpu::GpuChannelHost> gpu_channel); |
49 | 46 |
50 // gpu::GpuChannelEstablishFactory: | 47 // gpu::GpuChannelEstablishFactory: |
51 void EstablishGpuChannel( | 48 void EstablishGpuChannel( |
52 const gpu::GpuChannelEstablishedCallback& callback) override; | 49 const gpu::GpuChannelEstablishedCallback& callback) override; |
53 scoped_refptr<gpu::GpuChannelHost> EstablishGpuChannelSync() override; | 50 scoped_refptr<gpu::GpuChannelHost> EstablishGpuChannelSync() override; |
54 gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override; | 51 gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override; |
55 | 52 |
56 private: | 53 private: |
57 friend struct base::DefaultSingletonTraits<Gpu>; | 54 friend struct base::DefaultSingletonTraits<Gpu>; |
58 | 55 |
59 Gpu(service_manager::Connector* connector, | 56 Gpu(service_manager::Connector* connector, |
60 service_manager::InterfaceProvider* provider, | 57 const std::string& service_name, |
61 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 58 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
62 | 59 |
63 scoped_refptr<gpu::GpuChannelHost> GetGpuChannel(); | 60 scoped_refptr<gpu::GpuChannelHost> GetGpuChannel(); |
64 void OnEstablishedGpuChannel(int client_id, | 61 void OnEstablishedGpuChannel(int client_id, |
65 mojo::ScopedMessagePipeHandle channel_handle, | 62 mojo::ScopedMessagePipeHandle channel_handle, |
66 const gpu::GPUInfo& gpu_info); | 63 const gpu::GPUInfo& gpu_info); |
67 | 64 |
68 // gpu::GpuChannelHostFactory overrides: | 65 // gpu::GpuChannelHostFactory overrides: |
69 bool IsMainThread() override; | 66 bool IsMainThread() override; |
70 scoped_refptr<base::SingleThreadTaskRunner> GetIOThreadTaskRunner() override; | 67 scoped_refptr<base::SingleThreadTaskRunner> GetIOThreadTaskRunner() override; |
71 std::unique_ptr<base::SharedMemory> AllocateSharedMemory( | 68 std::unique_ptr<base::SharedMemory> AllocateSharedMemory( |
72 size_t size) override; | 69 size_t size) override; |
73 | 70 |
74 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 71 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
75 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 72 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
76 service_manager::Connector* connector_; | 73 service_manager::Connector* connector_; |
77 service_manager::InterfaceProvider* interface_provider_; | 74 const std::string service_name_; |
78 base::WaitableEvent shutdown_event_; | 75 base::WaitableEvent shutdown_event_; |
79 std::unique_ptr<base::Thread> io_thread_; | 76 std::unique_ptr<base::Thread> io_thread_; |
80 std::unique_ptr<ClientGpuMemoryBufferManager> gpu_memory_buffer_manager_; | 77 std::unique_ptr<ClientGpuMemoryBufferManager> gpu_memory_buffer_manager_; |
81 | 78 |
82 ui::mojom::GpuPtr gpu_; | 79 ui::mojom::GpuPtr gpu_; |
83 scoped_refptr<gpu::GpuChannelHost> gpu_channel_; | 80 scoped_refptr<gpu::GpuChannelHost> gpu_channel_; |
84 std::vector<gpu::GpuChannelEstablishedCallback> establish_callbacks_; | 81 std::vector<gpu::GpuChannelEstablishedCallback> establish_callbacks_; |
85 | 82 |
86 DISALLOW_COPY_AND_ASSIGN(Gpu); | 83 DISALLOW_COPY_AND_ASSIGN(Gpu); |
87 }; | 84 }; |
88 | 85 |
89 } // namespace ui | 86 } // namespace ui |
90 | 87 |
91 #endif // SERVICES_UI_PUBLIC_CPP_GPU_GPU_H_ | 88 #endif // SERVICES_UI_PUBLIC_CPP_GPU_GPU_H_ |
OLD | NEW |