Apply _RELATIVE relocations ahead of others.
[chromium-blink-merge.git] / content / browser / gpu / browser_gpu_channel_host_factory.h
blob4bc0b413153b8fd35230c09e390528a3045dc9fa
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 <vector>
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "content/common/gpu/client/gpu_channel_host.h"
13 #include "ipc/message_filter.h"
15 namespace content {
16 class BrowserGpuMemoryBufferManager;
17 class GpuMemoryBufferFactoryHostImpl;
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 // GpuChannelHostFactory implementation.
27 bool IsMainThread() override;
28 base::MessageLoop* GetMainLoop() override;
29 scoped_refptr<base::MessageLoopProxy> GetIOLoopProxy() override;
30 scoped_ptr<base::SharedMemory> AllocateSharedMemory(size_t size) override;
31 CreateCommandBufferResult CreateViewCommandBuffer(
32 int32 surface_id,
33 const GPUCreateCommandBufferConfig& init_params,
34 int32 route_id) override;
36 // Specify a task runner and callback to be used for a set of messages. The
37 // callback will be set up on the current GpuProcessHost, identified by
38 // GpuProcessHostId().
39 virtual void SetHandlerForControlMessages(
40 const uint32* message_ids,
41 size_t num_messages,
42 const base::Callback<void(const IPC::Message&)>& handler,
43 base::TaskRunner* target_task_runner);
44 int GpuProcessHostId() { return gpu_host_id_; }
45 GpuChannelHost* EstablishGpuChannelSync(
46 CauseForGpuLaunch cause_for_gpu_launch);
47 void EstablishGpuChannel(CauseForGpuLaunch cause_for_gpu_launch,
48 const base::Closure& callback);
49 GpuChannelHost* GetGpuChannel();
50 int GetGpuChannelId() { return gpu_client_id_; }
52 // Used to skip GpuChannelHost tests when there can be no GPU process.
53 static bool CanUseForTesting();
55 private:
56 struct CreateRequest;
57 class EstablishRequest;
59 BrowserGpuChannelHostFactory();
60 ~BrowserGpuChannelHostFactory() override;
62 void GpuChannelEstablished();
63 void CreateViewCommandBufferOnIO(
64 CreateRequest* request,
65 int32 surface_id,
66 const GPUCreateCommandBufferConfig& init_params);
67 static void CommandBufferCreatedOnIO(CreateRequest* request,
68 CreateCommandBufferResult result);
69 static void AddFilterOnIO(int gpu_host_id,
70 scoped_refptr<IPC::MessageFilter> filter);
72 const int gpu_client_id_;
73 scoped_ptr<base::WaitableEvent> shutdown_event_;
74 scoped_refptr<GpuChannelHost> gpu_channel_;
75 scoped_ptr<GpuMemoryBufferFactoryHostImpl> gpu_memory_buffer_factory_host_;
76 scoped_ptr<BrowserGpuMemoryBufferManager> gpu_memory_buffer_manager_;
77 int gpu_host_id_;
78 scoped_refptr<EstablishRequest> pending_request_;
79 std::vector<base::Closure> established_callbacks_;
81 static BrowserGpuChannelHostFactory* instance_;
83 DISALLOW_COPY_AND_ASSIGN(BrowserGpuChannelHostFactory);
86 } // namespace content
88 #endif // CONTENT_BROWSER_GPU_BROWSER_GPU_CHANNEL_HOST_FACTORY_H_