| // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #ifndef CONTENT_BROWSER_GPU_BROWSER_GPU_CHANNEL_HOST_FACTORY_H_ |
| #define CONTENT_BROWSER_GPU_BROWSER_GPU_CHANNEL_HOST_FACTORY_H_ |
| |
| #include <stddef.h> |
| #include <stdint.h> |
| |
| #include <map> |
| #include <memory> |
| #include <vector> |
| |
| #include "base/macros.h" |
| #include "base/memory/ref_counted.h" |
| #include "base/single_thread_task_runner.h" |
| #include "base/timer/timer.h" |
| #include "build/build_config.h" |
| #include "content/common/content_export.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "gpu/ipc/client/gpu_channel_host.h" |
| #include "ipc/message_filter.h" |
| |
| namespace gpu { |
| class GpuMemoryBufferManager; |
| } |
| |
| namespace content { |
| |
| class CONTENT_EXPORT BrowserGpuChannelHostFactory |
| : public gpu::GpuChannelEstablishFactory { |
| public: |
| static void Initialize(bool establish_gpu_channel); |
| static void Terminate(); |
| static BrowserGpuChannelHostFactory* instance() { return instance_; } |
| |
| gpu::GpuChannelHost* GetGpuChannel(); |
| int GetGpuChannelId() { return gpu_client_id_; } |
| |
| // Closes the channel to the GPU process. This should be called before the IO |
| // thread stops. |
| void CloseChannel(); |
| |
| // Notify the BrowserGpuChannelHostFactory of visibility, used to prevent |
| // timeouts while backgrounded. |
| void SetApplicationVisible(bool is_visible); |
| |
| // Overridden from gpu::GpuChannelEstablishFactory: |
| // The factory will return a null GpuChannelHost in the callback during |
| // shutdown. |
| void EstablishGpuChannel( |
| gpu::GpuChannelEstablishedCallback callback) override; |
| scoped_refptr<gpu::GpuChannelHost> EstablishGpuChannelSync() override; |
| gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override; |
| |
| private: |
| class EstablishRequest; |
| |
| BrowserGpuChannelHostFactory(); |
| ~BrowserGpuChannelHostFactory() override; |
| |
| void GpuChannelEstablished(); |
| void RestartTimeout(); |
| |
| static void InitializeShaderDiskCacheOnIO(int gpu_client_id, |
| const base::FilePath& cache_dir); |
| static void InitializeGrShaderDiskCacheOnIO(const base::FilePath& cache_dir); |
| |
| const int gpu_client_id_; |
| const uint64_t gpu_client_tracing_id_; |
| scoped_refptr<gpu::GpuChannelHost> gpu_channel_; |
| std::unique_ptr<gpu::GpuMemoryBufferManager, BrowserThread::DeleteOnIOThread> |
| gpu_memory_buffer_manager_; |
| scoped_refptr<EstablishRequest> pending_request_; |
| bool is_visible_ = true; |
| |
| base::OneShotTimer timeout_; |
| |
| static BrowserGpuChannelHostFactory* instance_; |
| |
| DISALLOW_COPY_AND_ASSIGN(BrowserGpuChannelHostFactory); |
| }; |
| |
| } // namespace content |
| |
| #endif // CONTENT_BROWSER_GPU_BROWSER_GPU_CHANNEL_HOST_FACTORY_H_ |