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_
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"
17 class BrowserGpuMemoryBufferManager
;
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 // 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(
32 const GPUCreateCommandBufferConfig
& init_params
,
33 int32 route_id
) override
;
34 IPC::AttachmentBroker
* GetAttachmentBroker() override
;
36 int GpuProcessHostId() { return gpu_host_id_
; }
37 #if !defined(OS_ANDROID)
38 GpuChannelHost
* EstablishGpuChannelSync(
39 CauseForGpuLaunch cause_for_gpu_launch
);
41 void EstablishGpuChannel(CauseForGpuLaunch cause_for_gpu_launch
,
42 const base::Closure
& callback
);
43 GpuChannelHost
* GetGpuChannel();
44 int GetGpuChannelId() { return gpu_client_id_
; }
46 // Used to skip GpuChannelHost tests when there can be no GPU process.
47 static bool CanUseForTesting();
51 class EstablishRequest
;
53 BrowserGpuChannelHostFactory();
54 ~BrowserGpuChannelHostFactory() override
;
56 void GpuChannelEstablished();
57 void CreateViewCommandBufferOnIO(
58 CreateRequest
* request
,
60 const GPUCreateCommandBufferConfig
& init_params
);
61 static void CommandBufferCreatedOnIO(CreateRequest
* request
,
62 CreateCommandBufferResult result
);
63 static void AddFilterOnIO(int gpu_host_id
,
64 scoped_refptr
<IPC::MessageFilter
> filter
);
66 const int gpu_client_id_
;
67 const uint64_t gpu_client_tracing_id_
;
68 scoped_ptr
<base::WaitableEvent
> shutdown_event_
;
69 scoped_refptr
<GpuChannelHost
> gpu_channel_
;
70 scoped_ptr
<BrowserGpuMemoryBufferManager
> gpu_memory_buffer_manager_
;
72 scoped_refptr
<EstablishRequest
> pending_request_
;
73 std::vector
<base::Closure
> established_callbacks_
;
75 static BrowserGpuChannelHostFactory
* instance_
;
77 DISALLOW_COPY_AND_ASSIGN(BrowserGpuChannelHostFactory
);
80 } // namespace content
82 #endif // CONTENT_BROWSER_GPU_BROWSER_GPU_CHANNEL_HOST_FACTORY_H_