[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / content / browser / gpu / browser_gpu_channel_host_factory.h
blobc0bcedceebe72510b12294176ee0755798563a98
1 // Copyright (c) 2012 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.
5 #ifndef CONTENT_BROWSER_GPU_BROWSER_GPU_CHANNEL_HOST_FACTORY_H_
6 #define CONTENT_BROWSER_GPU_BROWSER_GPU_CHANNEL_HOST_FACTORY_H_
8 #include <map>
9 #include <vector>
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "content/common/gpu/client/gpu_channel_host.h"
14 #include "ipc/message_filter.h"
16 namespace content {
17 class BrowserGpuMemoryBufferManager;
19 class CONTENT_EXPORT BrowserGpuChannelHostFactory
20 : public GpuChannelHostFactory {
21 public:
22 static void Initialize(bool establish_gpu_channel);
23 static void Terminate();
24 static BrowserGpuChannelHostFactory* instance() { return instance_; }
26 // Overridden from GpuChannelHostFactory:
27 bool IsMainThread() override;
28 scoped_refptr<base::SingleThreadTaskRunner> GetIOThreadTaskRunner() override;
29 scoped_ptr<base::SharedMemory> AllocateSharedMemory(size_t size) override;
30 CreateCommandBufferResult CreateViewCommandBuffer(
31 int32 surface_id,
32 const GPUCreateCommandBufferConfig& init_params,
33 int32 route_id) override;
35 int GpuProcessHostId() { return gpu_host_id_; }
36 #if !defined(OS_ANDROID)
37 GpuChannelHost* EstablishGpuChannelSync(
38 CauseForGpuLaunch cause_for_gpu_launch);
39 #endif
40 void EstablishGpuChannel(CauseForGpuLaunch cause_for_gpu_launch,
41 const base::Closure& callback);
42 GpuChannelHost* GetGpuChannel();
43 int GetGpuChannelId() { return gpu_client_id_; }
45 // Used to skip GpuChannelHost tests when there can be no GPU process.
46 static bool CanUseForTesting();
48 private:
49 struct CreateRequest;
50 class EstablishRequest;
52 BrowserGpuChannelHostFactory();
53 ~BrowserGpuChannelHostFactory() override;
55 void GpuChannelEstablished();
56 void CreateViewCommandBufferOnIO(
57 CreateRequest* request,
58 int32 surface_id,
59 const GPUCreateCommandBufferConfig& init_params);
60 static void CommandBufferCreatedOnIO(CreateRequest* request,
61 CreateCommandBufferResult result);
62 static void AddFilterOnIO(int gpu_host_id,
63 scoped_refptr<IPC::MessageFilter> filter);
64 static void InitializeShaderDiskCacheOnIO(int gpu_client_id,
65 const base::FilePath& cache_dir);
67 const int gpu_client_id_;
68 const uint64_t gpu_client_tracing_id_;
69 scoped_ptr<base::WaitableEvent> shutdown_event_;
70 scoped_refptr<GpuChannelHost> gpu_channel_;
71 scoped_ptr<BrowserGpuMemoryBufferManager> gpu_memory_buffer_manager_;
72 int gpu_host_id_;
73 scoped_refptr<EstablishRequest> pending_request_;
74 std::vector<base::Closure> established_callbacks_;
76 static BrowserGpuChannelHostFactory* instance_;
78 DISALLOW_COPY_AND_ASSIGN(BrowserGpuChannelHostFactory);
81 } // namespace content
83 #endif // CONTENT_BROWSER_GPU_BROWSER_GPU_CHANNEL_HOST_FACTORY_H_