| 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 <list> |
| 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 |
| 20 namespace cc { | 25 namespace cc { |
| 21 class VulkanInProcessContextProvider; | 26 class VulkanInProcessContextProvider; |
| 22 } | 27 } |
| 23 | 28 |
| 24 namespace gpu { | 29 namespace gpu { |
| 25 class GpuChannelHost; | 30 class GpuChannelHost; |
| 26 class GpuChannelEstablishFactory; | |
| 27 } | 31 } |
| 28 | 32 |
| 29 namespace content { | 33 namespace content { |
| 30 class ContextProviderCommandBuffer; | 34 class ContextProviderCommandBuffer; |
| 31 | 35 |
| 32 class CONTENT_EXPORT ContextProviderFactoryImpl | 36 class CONTENT_EXPORT ContextProviderFactoryImpl |
| 33 : public ui::ContextProviderFactory { | 37 : public ui::ContextProviderFactory { |
| 34 public: | 38 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 | |
| 41 static ContextProviderFactoryImpl* GetInstance(); | 39 static ContextProviderFactoryImpl* GetInstance(); |
| 42 | 40 |
| 43 ~ContextProviderFactoryImpl() override; | 41 ~ContextProviderFactoryImpl() override; |
| 44 | 42 |
| 45 // The callback may be triggered synchronously, if the Gpu Channel is already | 43 // The callback may be triggered synchronously, if the Gpu Channel is already |
| 46 // initialized. In case the context creation fails, a null context is passed | 44 // initialized. In case the surface_handle is invalidated before the context |
| 47 // with the failure reason. | 45 // can be created, the request is dropped and the callback will *not* run. |
| 48 void CreateDisplayContextProvider( | 46 void CreateDisplayContextProvider( |
| 49 gpu::SurfaceHandle surface_handle, | 47 gpu::SurfaceHandle surface_handle, |
| 50 gpu::SharedMemoryLimits shared_memory_limits, | 48 gpu::SharedMemoryLimits shared_memory_limits, |
| 51 gpu::gles2::ContextCreationAttribHelper attributes, | 49 gpu::gles2::ContextCreationAttribHelper attributes, |
| 52 bool support_locking, | 50 bool support_locking, |
| 53 bool automatic_flushes, | 51 bool automatic_flushes, |
| 54 ContextProviderCallback result_callback); | 52 ContextProviderCallback result_callback); |
| 55 | 53 |
| 56 // ContextProviderFactory implementation. | 54 // ContextProviderFactory implementation. |
| 57 scoped_refptr<cc::VulkanContextProvider> GetSharedVulkanContextProvider() | 55 scoped_refptr<cc::VulkanContextProvider> GetSharedVulkanContextProvider() |
| 58 override; | 56 override; |
| 59 void CreateOffscreenContextProvider( | 57 void CreateOffscreenContextProvider( |
| 60 ContextType context_type, | 58 ContextType context_type, |
| 61 gpu::SharedMemoryLimits shared_memory_limits, | 59 gpu::SharedMemoryLimits shared_memory_limits, |
| 62 gpu::gles2::ContextCreationAttribHelper attributes, | 60 gpu::gles2::ContextCreationAttribHelper attributes, |
| 63 bool support_locking, | 61 bool support_locking, |
| 64 bool automatic_flushes, | 62 bool automatic_flushes, |
| 65 cc::ContextProvider* shared_context_provider, | 63 cc::ContextProvider* shared_context_provider, |
| 66 ContextProviderCallback result_callback) override; | 64 ContextProviderCallback result_callback) override; |
| 67 cc::SurfaceManager* GetSurfaceManager() override; | 65 cc::SurfaceManager* GetSurfaceManager() override; |
| 68 uint32_t AllocateSurfaceClientId() override; | 66 uint32_t AllocateSurfaceClientId() override; |
| 69 cc::SharedBitmapManager* GetSharedBitmapManager() override; | 67 cc::SharedBitmapManager* GetSharedBitmapManager() override; |
| 70 gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override; | 68 gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override; |
| 71 | 69 |
| 72 private: | 70 private: |
| 73 ContextProviderFactoryImpl( | 71 friend struct base::DefaultSingletonTraits<ContextProviderFactoryImpl>; |
| 74 gpu::GpuChannelEstablishFactory* gpu_channel_factory); | |
| 75 | 72 |
| 76 void CreateContextProviderInternal( | 73 void CreateContextProviderInternal( |
| 77 command_buffer_metrics::ContextType context_type, | 74 command_buffer_metrics::ContextType context_type, |
| 78 gpu::SurfaceHandle surface_handle, | 75 gpu::SurfaceHandle surface_handle, |
| 79 gpu::SharedMemoryLimits shared_memory_limits, | 76 gpu::SharedMemoryLimits shared_memory_limits, |
| 80 gpu::gles2::ContextCreationAttribHelper attributes, | 77 gpu::gles2::ContextCreationAttribHelper attributes, |
| 81 bool support_locking, | 78 bool support_locking, |
| 82 bool automatic_flushes, | 79 bool automatic_flushes, |
| 83 cc::ContextProvider* shared_context_provider, | 80 cc::ContextProvider* shared_context_provider, |
| 84 ContextProviderCallback result_callback); | 81 ContextProviderCallback result_callback); |
| 85 | 82 |
| 86 struct ContextProvidersRequest { | 83 struct ContextProvidersRequest { |
| 87 ContextProvidersRequest(); | 84 ContextProvidersRequest(); |
| 88 ContextProvidersRequest(const ContextProvidersRequest& other); | 85 ContextProvidersRequest(const ContextProvidersRequest& other); |
| 89 ~ContextProvidersRequest(); | 86 ~ContextProvidersRequest(); |
| 90 | 87 |
| 91 command_buffer_metrics::ContextType context_type; | 88 command_buffer_metrics::ContextType context_type; |
| 92 gpu::SurfaceHandle surface_handle; | 89 gpu::SurfaceHandle surface_handle; |
| 93 gpu::SharedMemoryLimits shared_memory_limits; | 90 gpu::SharedMemoryLimits shared_memory_limits; |
| 94 gpu::gles2::ContextCreationAttribHelper attributes; | 91 gpu::gles2::ContextCreationAttribHelper attributes; |
| 95 bool support_locking; | 92 bool support_locking; |
| 96 bool automatic_flushes; | 93 bool automatic_flushes; |
| 97 cc::ContextProvider* shared_context_provider; | 94 cc::ContextProvider* shared_context_provider; |
| 98 ContextProviderCallback result_callback; | 95 ContextProviderCallback result_callback; |
| 99 }; | 96 }; |
| 100 | 97 |
| 98 ContextProviderFactoryImpl(); |
| 99 |
| 101 // Will return nullptr if the Gpu channel has not been established. | 100 // Will return nullptr if the Gpu channel has not been established. |
| 102 void EstablishGpuChannel(); | 101 gpu::GpuChannelHost* EnsureGpuChannelEstablished(); |
| 103 void OnGpuChannelEstablished(scoped_refptr<gpu::GpuChannelHost> gpu_channel); | 102 void OnGpuChannelEstablished(scoped_refptr<gpu::GpuChannelHost> gpu_channel); |
| 104 void OnGpuChannelTimeout(); | 103 void OnGpuChannelTimeout(); |
| 105 | 104 |
| 106 void HandlePendingRequests( | 105 void HandlePendingRequests(); |
| 107 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, | |
| 108 ContextCreationResult result); | |
| 109 | |
| 110 gpu::GpuChannelEstablishFactory* gpu_channel_factory_; | |
| 111 | 106 |
| 112 std::list<ContextProvidersRequest> context_provider_requests_; | 107 std::list<ContextProvidersRequest> context_provider_requests_; |
| 113 | 108 |
| 114 scoped_refptr<ContextProviderCommandBuffer> shared_worker_context_provider_; | 109 scoped_refptr<ContextProviderCommandBuffer> shared_worker_context_provider_; |
| 115 | 110 |
| 116 scoped_refptr<cc::VulkanContextProvider> shared_vulkan_context_provider_; | 111 scoped_refptr<cc::VulkanContextProvider> shared_vulkan_context_provider_; |
| 117 | 112 |
| 118 bool in_handle_pending_requests_; | 113 bool in_handle_pending_requests_; |
| 119 | 114 |
| 120 bool in_shutdown_; | |
| 121 | |
| 122 base::OneShotTimer establish_gpu_channel_timeout_; | 115 base::OneShotTimer establish_gpu_channel_timeout_; |
| 123 | 116 |
| 124 std::unique_ptr<cc::SurfaceManager> surface_manager_; | 117 std::unique_ptr<cc::SurfaceManager> surface_manager_; |
| 125 int surface_client_id_; | 118 int surface_client_id_; |
| 126 | 119 |
| 127 base::WeakPtrFactory<ContextProviderFactoryImpl> weak_factory_; | 120 base::WeakPtrFactory<ContextProviderFactoryImpl> weak_factory_; |
| 128 | 121 |
| 129 DISALLOW_COPY_AND_ASSIGN(ContextProviderFactoryImpl); | 122 DISALLOW_COPY_AND_ASSIGN(ContextProviderFactoryImpl); |
| 130 }; | 123 }; |
| 131 | 124 |
| 132 } // namespace content | 125 } // namespace content |
| 133 | 126 |
| 134 #endif // CONTENT_BROWSER_RENDERER_HOST_CONTEXT_PROVIDER_FACTORY_IMPL_ANDROID_H
_ | 127 #endif // CONTENT_BROWSER_RENDERER_HOST_CONTEXT_PROVIDER_FACTORY_IMPL_ANDROID_H
_ |
| OLD | NEW |