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
;
35 int GpuProcessHostId() { return gpu_host_id_
; }
36 #if !defined(OS_ANDROID)
37 GpuChannelHost
* EstablishGpuChannelSync(
38 CauseForGpuLaunch cause_for_gpu_launch
);
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();
50 class EstablishRequest
;
52 BrowserGpuChannelHostFactory();
53 ~BrowserGpuChannelHostFactory() override
;
55 void GpuChannelEstablished();
56 void CreateViewCommandBufferOnIO(
57 CreateRequest
* request
,
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_
;
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_