| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_CONTEXT_PROVIDER_FACTORY_IMPL_ANDROID_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_CONTEXT_PROVIDER_FACTORY_IMPL_ANDROID_H_ |
| 7 |
| 8 #include <list> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/timer/timer.h" |
| 13 #include "content/common/content_export.h" |
| 14 #include "content/common/gpu/client/command_buffer_metrics.h" |
| 15 #include "gpu/command_buffer/client/shared_memory_limits.h" |
| 16 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
| 17 #include "gpu/ipc/common/surface_handle.h" |
| 18 #include "ui/android/context_provider_factory.h" |
| 19 |
| 20 namespace base { |
| 21 template <typename T> |
| 22 struct DefaultSingletonTraits; |
| 23 } |
| 24 |
| 25 namespace cc { |
| 26 class VulkanInProcessContextProvider; |
| 27 } |
| 28 |
| 29 namespace gpu { |
| 30 class GpuChannelHost; |
| 31 } |
| 32 |
| 33 namespace content { |
| 34 class ContextProviderCommandBuffer; |
| 35 |
| 36 class CONTENT_EXPORT ContextProviderFactoryImpl |
| 37 : public ui::ContextProviderFactory { |
| 38 public: |
| 39 static ContextProviderFactoryImpl* GetInstance(); |
| 40 |
| 41 ~ContextProviderFactoryImpl() override; |
| 42 |
| 43 // The callback may be triggered synchronously, if the Gpu Channel is already |
| 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, |
| 48 gpu::SharedMemoryLimits shared_memory_limits, |
| 49 gpu::gles2::ContextCreationAttribHelper attributes, |
| 50 bool support_locking, |
| 51 bool automatic_flushes, |
| 52 ContextProviderCallback result_callback); |
| 53 |
| 54 // ContextProviderFactory implementation. |
| 55 scoped_refptr<cc::VulkanContextProvider> GetSharedVulkanContextProvider() |
| 56 override; |
| 57 void CreateOffscreenContextProvider( |
| 58 ContextType context_type, |
| 59 gpu::SharedMemoryLimits shared_memory_limits, |
| 60 gpu::gles2::ContextCreationAttribHelper attributes, |
| 61 bool support_locking, |
| 62 bool automatic_flushes, |
| 63 cc::ContextProvider* shared_context_provider, |
| 64 ContextProviderCallback result_callback) override; |
| 65 cc::SurfaceManager* GetSurfaceManager() override; |
| 66 uint32_t AllocateSurfaceClientId() override; |
| 67 cc::SharedBitmapManager* GetSharedBitmapManager() override; |
| 68 gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override; |
| 69 |
| 70 private: |
| 71 friend struct base::DefaultSingletonTraits<ContextProviderFactoryImpl>; |
| 72 |
| 73 void CreateContextProviderInternal( |
| 74 command_buffer_metrics::ContextType context_type, |
| 75 gpu::SurfaceHandle surface_handle, |
| 76 gpu::SharedMemoryLimits shared_memory_limits, |
| 77 gpu::gles2::ContextCreationAttribHelper attributes, |
| 78 bool support_locking, |
| 79 bool automatic_flushes, |
| 80 cc::ContextProvider* shared_context_provider, |
| 81 ContextProviderCallback result_callback); |
| 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 |
| 100 // Will return nullptr if the Gpu channel has not been established. |
| 101 gpu::GpuChannelHost* EnsureGpuChannelEstablished(); |
| 102 void OnGpuChannelEstablished(); |
| 103 void OnGpuChannelTimeout(); |
| 104 |
| 105 void HandlePendingRequests(); |
| 106 |
| 107 std::list<ContextProvidersRequest> context_provider_requests_; |
| 108 |
| 109 scoped_refptr<ContextProviderCommandBuffer> shared_worker_context_provider_; |
| 110 |
| 111 scoped_refptr<cc::VulkanContextProvider> shared_vulkan_context_provider_; |
| 112 |
| 113 bool in_handle_pending_requests_; |
| 114 |
| 115 base::OneShotTimer establish_gpu_channel_timeout_; |
| 116 |
| 117 std::unique_ptr<cc::SurfaceManager> surface_manager_; |
| 118 int surface_client_id_; |
| 119 |
| 120 base::WeakPtrFactory<ContextProviderFactoryImpl> weak_factory_; |
| 121 |
| 122 DISALLOW_COPY_AND_ASSIGN(ContextProviderFactoryImpl); |
| 123 }; |
| 124 |
| 125 } // namespace content |
| 126 |
| 127 #endif // CONTENT_BROWSER_RENDERER_HOST_CONTEXT_PROVIDER_FACTORY_IMPL_ANDROID_H
_ |
| OLD | NEW |