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