| 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 <queue> | |
| 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 "gpu/command_buffer/client/shared_memory_limits.h" | |
| 15 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | |
| 16 #include "gpu/ipc/common/surface_handle.h" | |
| 17 #include "services/ui/public/cpp/gpu/command_buffer_metrics.h" | |
| 18 #include "ui/android/context_provider_factory.h" | |
| 19 | |
| 20 namespace gpu { | |
| 21 class GpuChannelHost; | |
| 22 class GpuChannelEstablishFactory; | |
| 23 } | |
| 24 | |
| 25 namespace ui { | |
| 26 class ContextProviderCommandBuffer; | |
| 27 } | |
| 28 | |
| 29 namespace content { | |
| 30 | |
| 31 class CONTENT_EXPORT ContextProviderFactoryImpl | |
| 32 : public ui::ContextProviderFactory { | |
| 33 public: | |
| 34 // The factory must outlive the ContextProviderFactoryImpl instance, which | |
| 35 // will be destroyed when terminate is called. | |
| 36 static void Initialize(gpu::GpuChannelEstablishFactory* gpu_channel_factory); | |
| 37 | |
| 38 static void Terminate(); | |
| 39 | |
| 40 static ContextProviderFactoryImpl* GetInstance(); | |
| 41 | |
| 42 ~ContextProviderFactoryImpl() override; | |
| 43 | |
| 44 scoped_refptr<cc::ContextProvider> CreateDisplayContextProvider( | |
| 45 gpu::SurfaceHandle surface_handle, | |
| 46 gpu::SharedMemoryLimits shared_memory_limits, | |
| 47 gpu::gles2::ContextCreationAttribHelper attributes, | |
| 48 bool support_locking, | |
| 49 bool automatic_flushes, | |
| 50 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host); | |
| 51 | |
| 52 // ContextProviderFactory implementation. | |
| 53 scoped_refptr<cc::VulkanContextProvider> GetSharedVulkanContextProvider() | |
| 54 override; | |
| 55 void RequestGpuChannelHost(GpuChannelHostCallback callback) override; | |
| 56 scoped_refptr<cc::ContextProvider> CreateOffscreenContextProvider( | |
| 57 ContextType context_type, | |
| 58 gpu::SharedMemoryLimits shared_memory_limits, | |
| 59 gpu::gles2::ContextCreationAttribHelper attributes, | |
| 60 bool support_locking, | |
| 61 bool automatic_flushes, | |
| 62 cc::ContextProvider* shared_context_provider, | |
| 63 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host) override; | |
| 64 cc::SurfaceManager* GetSurfaceManager() override; | |
| 65 cc::FrameSinkId AllocateFrameSinkId() override; | |
| 66 gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override; | |
| 67 | |
| 68 private: | |
| 69 ContextProviderFactoryImpl( | |
| 70 gpu::GpuChannelEstablishFactory* gpu_channel_factory); | |
| 71 | |
| 72 scoped_refptr<cc::ContextProvider> CreateContextProviderInternal( | |
| 73 ui::command_buffer_metrics::ContextType context_type, | |
| 74 gpu::SurfaceHandle surface_handle, | |
| 75 gpu::SharedMemoryLimits shared_memory_limits, | |
| 76 gpu::gles2::ContextCreationAttribHelper attributes, | |
| 77 bool support_locking, | |
| 78 bool automatic_flushes, | |
| 79 cc::ContextProvider* shared_context_provider, | |
| 80 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host); | |
| 81 | |
| 82 // Will return nullptr if the Gpu channel has not been established. | |
| 83 void EstablishGpuChannel(); | |
| 84 void OnGpuChannelEstablished(scoped_refptr<gpu::GpuChannelHost> gpu_channel); | |
| 85 void OnGpuChannelTimeout(); | |
| 86 | |
| 87 void HandlePendingRequests( | |
| 88 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, | |
| 89 GpuChannelHostResult result); | |
| 90 | |
| 91 gpu::GpuChannelEstablishFactory* gpu_channel_factory_; | |
| 92 | |
| 93 std::queue<GpuChannelHostCallback> gpu_channel_requests_; | |
| 94 | |
| 95 scoped_refptr<ui::ContextProviderCommandBuffer> | |
| 96 shared_worker_context_provider_; | |
| 97 | |
| 98 scoped_refptr<cc::VulkanContextProvider> shared_vulkan_context_provider_; | |
| 99 | |
| 100 bool in_handle_pending_requests_; | |
| 101 | |
| 102 bool in_shutdown_; | |
| 103 | |
| 104 base::OneShotTimer establish_gpu_channel_timeout_; | |
| 105 | |
| 106 std::unique_ptr<cc::SurfaceManager> surface_manager_; | |
| 107 uint32_t next_sink_id_; | |
| 108 | |
| 109 base::WeakPtrFactory<ContextProviderFactoryImpl> weak_factory_; | |
| 110 | |
| 111 DISALLOW_COPY_AND_ASSIGN(ContextProviderFactoryImpl); | |
| 112 }; | |
| 113 | |
| 114 } // namespace content | |
| 115 | |
| 116 #endif // CONTENT_BROWSER_RENDERER_HOST_CONTEXT_PROVIDER_FACTORY_IMPL_ANDROID_H
_ | |
| OLD | NEW |