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