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_
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"
16 class BrowserGpuMemoryBufferManager
;
17 class GpuMemoryBufferFactoryHostImpl
;
19 class CONTENT_EXPORT BrowserGpuChannelHostFactory
20 : public GpuChannelHostFactory
{
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(
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
,
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();
57 class EstablishRequest
;
59 BrowserGpuChannelHostFactory();
60 ~BrowserGpuChannelHostFactory() override
;
62 void GpuChannelEstablished();
63 void CreateViewCommandBufferOnIO(
64 CreateRequest
* request
,
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_
;
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_