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 COMPONENTS_MUS_COMMON_GPU_SERVICE_H_ | 5 #ifndef COMPONENTS_MUS_COMMON_GPU_SERVICE_H_ |
6 #define COMPONENTS_MUS_COMMON_GPU_SERVICE_H_ | 6 #define COMPONENTS_MUS_COMMON_GPU_SERVICE_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/lock.h" | 14 #include "base/synchronization/lock.h" |
15 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 17 #include "components/mus/common/mojo_gpu_memory_buffer_manager.h" |
17 #include "components/mus/common/mus_common_export.h" | 18 #include "components/mus/common/mus_common_export.h" |
| 19 #include "components/mus/public/interfaces/gpu_service.mojom.h" |
18 #include "gpu/ipc/client/gpu_channel_host.h" | 20 #include "gpu/ipc/client/gpu_channel_host.h" |
19 | 21 |
20 namespace shell { | 22 namespace shell { |
21 class Connector; | 23 class Connector; |
22 } | 24 } |
23 | 25 |
24 namespace mus { | 26 namespace mus { |
25 | 27 |
26 class MojoGpuMemoryBufferManager; | |
27 | |
28 class MUS_COMMON_EXPORT GpuService : public gpu::GpuChannelHostFactory { | 28 class MUS_COMMON_EXPORT GpuService : public gpu::GpuChannelHostFactory { |
29 public: | 29 public: |
30 scoped_refptr<gpu::GpuChannelHost> EstablishGpuChannel( | 30 void EstablishGpuChannel(const base::Closure& callback); |
31 shell::Connector* connector); | 31 scoped_refptr<gpu::GpuChannelHost> EstablishGpuChannelSync(); |
| 32 scoped_refptr<gpu::GpuChannelHost> GetGpuChannel(); |
| 33 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager() const { |
| 34 return gpu_memory_buffer_manager_.get(); |
| 35 } |
32 | 36 |
33 static bool UseChromeGpuCommandBuffer(); | 37 static bool UseChromeGpuCommandBuffer(); |
| 38 |
| 39 // The GpuService has to be initialized in the main thread before establishing |
| 40 // the gpu channel. |
| 41 static void Initialize(shell::Connector* connector); |
| 42 // The GpuService has to be terminated in the main thread. |
| 43 static void Terminate(); |
34 static GpuService* GetInstance(); | 44 static GpuService* GetInstance(); |
35 | 45 |
36 private: | 46 private: |
37 friend struct base::DefaultSingletonTraits<GpuService>; | 47 friend struct base::DefaultSingletonTraits<GpuService>; |
38 | 48 |
39 GpuService(); | 49 explicit GpuService(shell::Connector* connector); |
40 ~GpuService() override; | 50 ~GpuService() override; |
41 | 51 |
| 52 scoped_refptr<gpu::GpuChannelHost> GetGpuChannelLocked(); |
| 53 void EstablishGpuChannelOnMainThread(); |
| 54 void EstablishGpuChannelOnMainThreadSyncLocked(); |
| 55 void EstablishGpuChannelOnMainThreadDone( |
| 56 bool locked, |
| 57 int client_id, |
| 58 mojom::ChannelHandlePtr channel_handle, |
| 59 mojom::GpuInfoPtr gpu_info); |
| 60 |
42 // gpu::GpuChannelHostFactory overrides: | 61 // gpu::GpuChannelHostFactory overrides: |
43 bool IsMainThread() override; | 62 bool IsMainThread() override; |
44 scoped_refptr<base::SingleThreadTaskRunner> GetIOThreadTaskRunner() override; | 63 scoped_refptr<base::SingleThreadTaskRunner> GetIOThreadTaskRunner() override; |
45 std::unique_ptr<base::SharedMemory> AllocateSharedMemory( | 64 std::unique_ptr<base::SharedMemory> AllocateSharedMemory( |
46 size_t size) override; | 65 size_t size) override; |
47 | 66 |
48 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 67 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| 68 shell::Connector* connector_; |
49 base::WaitableEvent shutdown_event_; | 69 base::WaitableEvent shutdown_event_; |
50 base::Thread io_thread_; | 70 base::Thread io_thread_; |
51 std::unique_ptr<MojoGpuMemoryBufferManager> gpu_memory_buffer_manager_; | 71 std::unique_ptr<MojoGpuMemoryBufferManager> gpu_memory_buffer_manager_; |
52 | 72 |
53 // Lock for |gpu_channel_|. | 73 // Lock for |gpu_channel_|, |establish_callbacks_| & |is_establishing_|. |
54 base::Lock lock_; | 74 base::Lock lock_; |
| 75 bool is_establishing_; |
| 76 mus::mojom::GpuServicePtr gpu_service_; |
55 scoped_refptr<gpu::GpuChannelHost> gpu_channel_; | 77 scoped_refptr<gpu::GpuChannelHost> gpu_channel_; |
| 78 std::vector<base::Closure> establish_callbacks_; |
| 79 base::ConditionVariable establishing_condition_; |
56 | 80 |
57 DISALLOW_COPY_AND_ASSIGN(GpuService); | 81 DISALLOW_COPY_AND_ASSIGN(GpuService); |
58 }; | 82 }; |
59 | 83 |
60 } // namespace mus | 84 } // namespace mus |
61 | 85 |
62 #endif // COMPONENTS_MUS_PUBLIC_CPP_LIB_GPU_SERVICE_CONNECTION_H_ | 86 #endif // COMPONENTS_MUS_PUBLIC_CPP_LIB_GPU_SERVICE_CONNECTION_H_ |
OLD | NEW |