Add remoting and PPAPI tests to GN build
[chromium-blink-merge.git] / content / browser / gpu / browser_gpu_channel_host_factory.h
blob9cc0cd5c98b4f212082e3d23e06d66a5c56f9d1c
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 "content/common/gpu/client/gpu_memory_buffer_factory_host.h"
15 #include "ipc/message_filter.h"
17 namespace content {
18 class BrowserGpuMemoryBufferManager;
20 class CONTENT_EXPORT BrowserGpuChannelHostFactory
21 : public GpuChannelHostFactory,
22 public GpuMemoryBufferFactoryHost {
23 public:
24 static void Initialize(bool establish_gpu_channel);
25 static void Terminate();
26 static BrowserGpuChannelHostFactory* instance() { return instance_; }
28 static void EnableGpuMemoryBufferFactoryUsage(
29 gfx::GpuMemoryBuffer::Usage usage);
30 static bool IsGpuMemoryBufferFactoryUsageEnabled(
31 gfx::GpuMemoryBuffer::Usage usage);
32 static uint32 GetImageTextureTarget();
34 // Overridden from GpuChannelHostFactory:
35 bool IsMainThread() override;
36 base::MessageLoop* GetMainLoop() override;
37 scoped_refptr<base::MessageLoopProxy> GetIOLoopProxy() override;
38 scoped_ptr<base::SharedMemory> AllocateSharedMemory(size_t size) override;
39 CreateCommandBufferResult CreateViewCommandBuffer(
40 int32 surface_id,
41 const GPUCreateCommandBufferConfig& init_params,
42 int32 route_id) override;
44 // Overridden from GpuMemoryBufferFactoryHost:
45 bool IsGpuMemoryBufferConfigurationSupported(
46 gfx::GpuMemoryBuffer::Format format,
47 gfx::GpuMemoryBuffer::Usage usage) override;
48 void CreateGpuMemoryBuffer(
49 gfx::GpuMemoryBufferId id,
50 const gfx::Size& size,
51 gfx::GpuMemoryBuffer::Format format,
52 gfx::GpuMemoryBuffer::Usage usage,
53 int client_id,
54 int32 surface_id,
55 const CreateGpuMemoryBufferCallback& callback) override;
56 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
57 int client_id,
58 int32 sync_point) override;
60 int GpuProcessHostId() { return gpu_host_id_; }
61 #if !defined(OS_ANDROID)
62 GpuChannelHost* EstablishGpuChannelSync(
63 CauseForGpuLaunch cause_for_gpu_launch);
64 #endif
65 void EstablishGpuChannel(CauseForGpuLaunch cause_for_gpu_launch,
66 const base::Closure& callback);
67 GpuChannelHost* GetGpuChannel();
68 int GetGpuChannelId() { return gpu_client_id_; }
70 // Used to skip GpuChannelHost tests when there can be no GPU process.
71 static bool CanUseForTesting();
73 private:
74 struct CreateRequest;
75 class EstablishRequest;
77 BrowserGpuChannelHostFactory();
78 ~BrowserGpuChannelHostFactory() override;
80 void GpuChannelEstablished();
81 void CreateViewCommandBufferOnIO(
82 CreateRequest* request,
83 int32 surface_id,
84 const GPUCreateCommandBufferConfig& init_params);
85 static void CommandBufferCreatedOnIO(CreateRequest* request,
86 CreateCommandBufferResult result);
87 static void AddFilterOnIO(int gpu_host_id,
88 scoped_refptr<IPC::MessageFilter> filter);
89 void DestroyGpuMemoryBufferOnIO(gfx::GpuMemoryBufferId id,
90 int client_id,
91 int32 sync_point);
92 void OnGpuMemoryBufferCreated(uint32 request_id,
93 const gfx::GpuMemoryBufferHandle& handle);
95 const int gpu_client_id_;
96 scoped_ptr<base::WaitableEvent> shutdown_event_;
97 scoped_refptr<GpuChannelHost> gpu_channel_;
98 scoped_ptr<BrowserGpuMemoryBufferManager> gpu_memory_buffer_manager_;
99 int gpu_host_id_;
100 scoped_refptr<EstablishRequest> pending_request_;
101 std::vector<base::Closure> established_callbacks_;
102 uint32 next_create_gpu_memory_buffer_request_id_;
103 typedef std::map<uint32, CreateGpuMemoryBufferCallback>
104 CreateGpuMemoryBufferCallbackMap;
105 CreateGpuMemoryBufferCallbackMap create_gpu_memory_buffer_requests_;
107 static BrowserGpuChannelHostFactory* instance_;
109 DISALLOW_COPY_AND_ASSIGN(BrowserGpuChannelHostFactory);
112 } // namespace content
114 #endif // CONTENT_BROWSER_GPU_BROWSER_GPU_CHANNEL_HOST_FACTORY_H_