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 CONTENT_BROWSER_RENDERER_HOST_CONTEXT_PROVIDER_FACTORY_IMPL_ANDROID_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_CONTEXT_PROVIDER_FACTORY_IMPL_ANDROID_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_CONTEXT_PROVIDER_FACTORY_IMPL_ANDROID_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_CONTEXT_PROVIDER_FACTORY_IMPL_ANDROID_H_ |
7 | 7 |
8 #include <list> | 8 #include <queue> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
13 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
14 #include "content/common/gpu/client/command_buffer_metrics.h" | 14 #include "content/common/gpu/client/command_buffer_metrics.h" |
15 #include "gpu/command_buffer/client/shared_memory_limits.h" | 15 #include "gpu/command_buffer/client/shared_memory_limits.h" |
16 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 16 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
17 #include "gpu/ipc/common/surface_handle.h" | 17 #include "gpu/ipc/common/surface_handle.h" |
18 #include "ui/android/context_provider_factory.h" | 18 #include "ui/android/context_provider_factory.h" |
19 | 19 |
20 namespace base { | |
21 template <typename T> | |
22 struct DefaultSingletonTraits; | |
23 } | |
24 | |
25 namespace cc { | 20 namespace cc { |
26 class VulkanInProcessContextProvider; | 21 class VulkanInProcessContextProvider; |
27 } | 22 } |
28 | 23 |
29 namespace gpu { | 24 namespace gpu { |
30 class GpuChannelHost; | 25 class GpuChannelHost; |
| 26 class GpuChannelEstablishFactory; |
31 } | 27 } |
32 | 28 |
33 namespace content { | 29 namespace content { |
34 class ContextProviderCommandBuffer; | 30 class ContextProviderCommandBuffer; |
35 | 31 |
36 class CONTENT_EXPORT ContextProviderFactoryImpl | 32 class CONTENT_EXPORT ContextProviderFactoryImpl |
37 : public ui::ContextProviderFactory { | 33 : public ui::ContextProviderFactory { |
38 public: | 34 public: |
| 35 // The factory must outlive the ContextProviderFactoryImpl instance, which |
| 36 // will be destroyed when terminate is called. |
| 37 static void Initialize(gpu::GpuChannelEstablishFactory* gpu_channel_factory); |
| 38 |
| 39 static void Terminate(); |
| 40 |
39 static ContextProviderFactoryImpl* GetInstance(); | 41 static ContextProviderFactoryImpl* GetInstance(); |
40 | 42 |
41 ~ContextProviderFactoryImpl() override; | 43 ~ContextProviderFactoryImpl() override; |
42 | 44 |
43 // The callback may be triggered synchronously, if the Gpu Channel is already | 45 scoped_refptr<cc::ContextProvider> CreateDisplayContextProvider( |
44 // initialized. In case the surface_handle is invalidated before the context | |
45 // can be created, the request is dropped and the callback will *not* run. | |
46 void CreateDisplayContextProvider( | |
47 gpu::SurfaceHandle surface_handle, | 46 gpu::SurfaceHandle surface_handle, |
48 gpu::SharedMemoryLimits shared_memory_limits, | 47 gpu::SharedMemoryLimits shared_memory_limits, |
49 gpu::gles2::ContextCreationAttribHelper attributes, | 48 gpu::gles2::ContextCreationAttribHelper attributes, |
50 bool support_locking, | 49 bool support_locking, |
51 bool automatic_flushes, | 50 bool automatic_flushes, |
52 ContextProviderCallback result_callback); | 51 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host); |
53 | 52 |
54 // ContextProviderFactory implementation. | 53 // ContextProviderFactory implementation. |
55 scoped_refptr<cc::VulkanContextProvider> GetSharedVulkanContextProvider() | 54 scoped_refptr<cc::VulkanContextProvider> GetSharedVulkanContextProvider() |
56 override; | 55 override; |
57 void CreateOffscreenContextProvider( | 56 void RequestGpuChannelHost(GpuChannelHostCallback callback) override; |
| 57 scoped_refptr<cc::ContextProvider> CreateOffscreenContextProvider( |
58 ContextType context_type, | 58 ContextType context_type, |
59 gpu::SharedMemoryLimits shared_memory_limits, | 59 gpu::SharedMemoryLimits shared_memory_limits, |
60 gpu::gles2::ContextCreationAttribHelper attributes, | 60 gpu::gles2::ContextCreationAttribHelper attributes, |
61 bool support_locking, | 61 bool support_locking, |
62 bool automatic_flushes, | 62 bool automatic_flushes, |
63 cc::ContextProvider* shared_context_provider, | 63 cc::ContextProvider* shared_context_provider, |
64 ContextProviderCallback result_callback) override; | 64 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host) override; |
65 cc::SurfaceManager* GetSurfaceManager() override; | 65 cc::SurfaceManager* GetSurfaceManager() override; |
66 uint32_t AllocateSurfaceClientId() override; | 66 uint32_t AllocateSurfaceClientId() override; |
67 cc::SharedBitmapManager* GetSharedBitmapManager() override; | 67 cc::SharedBitmapManager* GetSharedBitmapManager() override; |
68 gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override; | 68 gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override; |
69 | 69 |
70 private: | 70 private: |
71 friend struct base::DefaultSingletonTraits<ContextProviderFactoryImpl>; | 71 ContextProviderFactoryImpl( |
| 72 gpu::GpuChannelEstablishFactory* gpu_channel_factory); |
72 | 73 |
73 void CreateContextProviderInternal( | 74 scoped_refptr<cc::ContextProvider> CreateContextProviderInternal( |
74 command_buffer_metrics::ContextType context_type, | 75 command_buffer_metrics::ContextType context_type, |
75 gpu::SurfaceHandle surface_handle, | 76 gpu::SurfaceHandle surface_handle, |
76 gpu::SharedMemoryLimits shared_memory_limits, | 77 gpu::SharedMemoryLimits shared_memory_limits, |
77 gpu::gles2::ContextCreationAttribHelper attributes, | 78 gpu::gles2::ContextCreationAttribHelper attributes, |
78 bool support_locking, | 79 bool support_locking, |
79 bool automatic_flushes, | 80 bool automatic_flushes, |
80 cc::ContextProvider* shared_context_provider, | 81 cc::ContextProvider* shared_context_provider, |
81 ContextProviderCallback result_callback); | 82 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host); |
82 | |
83 struct ContextProvidersRequest { | |
84 ContextProvidersRequest(); | |
85 ContextProvidersRequest(const ContextProvidersRequest& other); | |
86 ~ContextProvidersRequest(); | |
87 | |
88 command_buffer_metrics::ContextType context_type; | |
89 gpu::SurfaceHandle surface_handle; | |
90 gpu::SharedMemoryLimits shared_memory_limits; | |
91 gpu::gles2::ContextCreationAttribHelper attributes; | |
92 bool support_locking; | |
93 bool automatic_flushes; | |
94 cc::ContextProvider* shared_context_provider; | |
95 ContextProviderCallback result_callback; | |
96 }; | |
97 | |
98 ContextProviderFactoryImpl(); | |
99 | 83 |
100 // Will return nullptr if the Gpu channel has not been established. | 84 // Will return nullptr if the Gpu channel has not been established. |
101 gpu::GpuChannelHost* EnsureGpuChannelEstablished(); | 85 void EstablishGpuChannel(); |
102 void OnGpuChannelEstablished(scoped_refptr<gpu::GpuChannelHost> gpu_channel); | 86 void OnGpuChannelEstablished(scoped_refptr<gpu::GpuChannelHost> gpu_channel); |
103 void OnGpuChannelTimeout(); | 87 void OnGpuChannelTimeout(); |
104 | 88 |
105 void HandlePendingRequests(); | 89 void HandlePendingRequests( |
| 90 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, |
| 91 GpuChannelHostResult result); |
106 | 92 |
107 std::list<ContextProvidersRequest> context_provider_requests_; | 93 gpu::GpuChannelEstablishFactory* gpu_channel_factory_; |
| 94 |
| 95 std::queue<GpuChannelHostCallback> gpu_channel_requests_; |
108 | 96 |
109 scoped_refptr<ContextProviderCommandBuffer> shared_worker_context_provider_; | 97 scoped_refptr<ContextProviderCommandBuffer> shared_worker_context_provider_; |
110 | 98 |
111 scoped_refptr<cc::VulkanContextProvider> shared_vulkan_context_provider_; | 99 scoped_refptr<cc::VulkanContextProvider> shared_vulkan_context_provider_; |
112 | 100 |
113 bool in_handle_pending_requests_; | 101 bool in_handle_pending_requests_; |
114 | 102 |
| 103 bool in_shutdown_; |
| 104 |
115 base::OneShotTimer establish_gpu_channel_timeout_; | 105 base::OneShotTimer establish_gpu_channel_timeout_; |
116 | 106 |
117 std::unique_ptr<cc::SurfaceManager> surface_manager_; | 107 std::unique_ptr<cc::SurfaceManager> surface_manager_; |
118 int surface_client_id_; | 108 int surface_client_id_; |
119 | 109 |
120 base::WeakPtrFactory<ContextProviderFactoryImpl> weak_factory_; | 110 base::WeakPtrFactory<ContextProviderFactoryImpl> weak_factory_; |
121 | 111 |
122 DISALLOW_COPY_AND_ASSIGN(ContextProviderFactoryImpl); | 112 DISALLOW_COPY_AND_ASSIGN(ContextProviderFactoryImpl); |
123 }; | 113 }; |
124 | 114 |
125 } // namespace content | 115 } // namespace content |
126 | 116 |
127 #endif // CONTENT_BROWSER_RENDERER_HOST_CONTEXT_PROVIDER_FACTORY_IMPL_ANDROID_H
_ | 117 #endif // CONTENT_BROWSER_RENDERER_HOST_CONTEXT_PROVIDER_FACTORY_IMPL_ANDROID_H
_ |
OLD | NEW |