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 "content/common/gpu/client/gpu_memory_buffer_factory_host.h"
15 #include "ipc/message_filter.h"
18 class BrowserGpuMemoryBufferManager
;
20 class CONTENT_EXPORT BrowserGpuChannelHostFactory
21 : public GpuChannelHostFactory
,
22 public GpuMemoryBufferFactoryHost
{
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 scoped_refptr
<base::MessageLoopProxy
> GetIOLoopProxy() override
;
37 scoped_ptr
<base::SharedMemory
> AllocateSharedMemory(size_t size
) override
;
38 CreateCommandBufferResult
CreateViewCommandBuffer(
40 const GPUCreateCommandBufferConfig
& init_params
,
41 int32 route_id
) override
;
43 // Overridden from GpuMemoryBufferFactoryHost:
44 bool IsGpuMemoryBufferConfigurationSupported(
45 gfx::GpuMemoryBuffer::Format format
,
46 gfx::GpuMemoryBuffer::Usage usage
) override
;
47 void CreateGpuMemoryBuffer(
48 gfx::GpuMemoryBufferId id
,
49 const gfx::Size
& size
,
50 gfx::GpuMemoryBuffer::Format format
,
51 gfx::GpuMemoryBuffer::Usage usage
,
54 const CreateGpuMemoryBufferCallback
& callback
) override
;
55 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id
,
57 int32 sync_point
) override
;
59 int GpuProcessHostId() { return gpu_host_id_
; }
60 #if !defined(OS_ANDROID)
61 GpuChannelHost
* EstablishGpuChannelSync(
62 CauseForGpuLaunch cause_for_gpu_launch
);
64 void EstablishGpuChannel(CauseForGpuLaunch cause_for_gpu_launch
,
65 const base::Closure
& callback
);
66 GpuChannelHost
* GetGpuChannel();
67 int GetGpuChannelId() { return gpu_client_id_
; }
69 // Used to skip GpuChannelHost tests when there can be no GPU process.
70 static bool CanUseForTesting();
74 class EstablishRequest
;
76 BrowserGpuChannelHostFactory();
77 ~BrowserGpuChannelHostFactory() override
;
79 void GpuChannelEstablished();
80 void CreateViewCommandBufferOnIO(
81 CreateRequest
* request
,
83 const GPUCreateCommandBufferConfig
& init_params
);
84 static void CommandBufferCreatedOnIO(CreateRequest
* request
,
85 CreateCommandBufferResult result
);
86 static void AddFilterOnIO(int gpu_host_id
,
87 scoped_refptr
<IPC::MessageFilter
> filter
);
88 void DestroyGpuMemoryBufferOnIO(gfx::GpuMemoryBufferId id
,
91 void OnGpuMemoryBufferCreated(uint32 request_id
,
92 const gfx::GpuMemoryBufferHandle
& handle
);
94 const int gpu_client_id_
;
95 scoped_ptr
<base::WaitableEvent
> shutdown_event_
;
96 scoped_refptr
<GpuChannelHost
> gpu_channel_
;
97 scoped_ptr
<BrowserGpuMemoryBufferManager
> gpu_memory_buffer_manager_
;
99 scoped_refptr
<EstablishRequest
> pending_request_
;
100 std::vector
<base::Closure
> established_callbacks_
;
101 uint32 next_create_gpu_memory_buffer_request_id_
;
102 typedef std::map
<uint32
, CreateGpuMemoryBufferCallback
>
103 CreateGpuMemoryBufferCallbackMap
;
104 CreateGpuMemoryBufferCallbackMap create_gpu_memory_buffer_requests_
;
106 static BrowserGpuChannelHostFactory
* instance_
;
108 DISALLOW_COPY_AND_ASSIGN(BrowserGpuChannelHostFactory
);
111 } // namespace content
113 #endif // CONTENT_BROWSER_GPU_BROWSER_GPU_CHANNEL_HOST_FACTORY_H_