• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CONTENT_BROWSER_GPU_BROWSER_GPU_CHANNEL_HOST_FACTORY_H_
6 #define CONTENT_BROWSER_GPU_BROWSER_GPU_CHANNEL_HOST_FACTORY_H_
7 
8 #include <vector>
9 
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"
14 
15 namespace content {
16 class GpuMemoryBufferImpl;
17 class GpuMemoryBufferFactoryHostImpl;
18 
19 class CONTENT_EXPORT BrowserGpuChannelHostFactory
20     : public GpuChannelHostFactory {
21  public:
22   static void Initialize(bool establish_gpu_channel);
23   static void Terminate();
instance()24   static BrowserGpuChannelHostFactory* instance() { return instance_; }
25 
26   // GpuChannelHostFactory implementation.
27   virtual bool IsMainThread() OVERRIDE;
28   virtual base::MessageLoop* GetMainLoop() OVERRIDE;
29   virtual scoped_refptr<base::MessageLoopProxy> GetIOLoopProxy() OVERRIDE;
30   virtual scoped_ptr<base::SharedMemory> AllocateSharedMemory(
31       size_t size) OVERRIDE;
32   virtual CreateCommandBufferResult CreateViewCommandBuffer(
33       int32 surface_id,
34       const GPUCreateCommandBufferConfig& init_params,
35       int32 route_id) OVERRIDE;
36   virtual scoped_ptr<gfx::GpuMemoryBuffer> AllocateGpuMemoryBuffer(
37       size_t width,
38       size_t height,
39       unsigned internalformat,
40       unsigned usage) OVERRIDE;
41 
42   // Specify a task runner and callback to be used for a set of messages. The
43   // callback will be set up on the current GpuProcessHost, identified by
44   // GpuProcessHostId().
45   virtual void SetHandlerForControlMessages(
46       const uint32* message_ids,
47       size_t num_messages,
48       const base::Callback<void(const IPC::Message&)>& handler,
49       base::TaskRunner* target_task_runner);
GpuProcessHostId()50   int GpuProcessHostId() { return gpu_host_id_; }
51   GpuChannelHost* EstablishGpuChannelSync(
52       CauseForGpuLaunch cause_for_gpu_launch);
53   void EstablishGpuChannel(CauseForGpuLaunch cause_for_gpu_launch,
54                            const base::Closure& callback);
55   GpuChannelHost* GetGpuChannel();
GetGpuChannelId()56   int GetGpuChannelId() { return gpu_client_id_; }
57 
58   // Used to skip GpuChannelHost tests when there can be no GPU process.
59   static bool CanUseForTesting();
60 
61  private:
62   struct CreateRequest;
63   struct AllocateGpuMemoryBufferRequest;
64   class EstablishRequest;
65 
66   BrowserGpuChannelHostFactory();
67   virtual ~BrowserGpuChannelHostFactory();
68 
69   void GpuChannelEstablished();
70   void CreateViewCommandBufferOnIO(
71       CreateRequest* request,
72       int32 surface_id,
73       const GPUCreateCommandBufferConfig& init_params);
74   static void CommandBufferCreatedOnIO(CreateRequest* request,
75                                        CreateCommandBufferResult result);
76   static void AddFilterOnIO(int gpu_host_id,
77                             scoped_refptr<IPC::MessageFilter> filter);
78   static void AllocateGpuMemoryBufferOnIO(
79       AllocateGpuMemoryBufferRequest* request);
80   static void OnGpuMemoryBufferCreated(AllocateGpuMemoryBufferRequest* request,
81                                        scoped_ptr<GpuMemoryBufferImpl> buffer);
82 
83   const int gpu_client_id_;
84   scoped_ptr<base::WaitableEvent> shutdown_event_;
85   scoped_refptr<GpuChannelHost> gpu_channel_;
86   scoped_ptr<GpuMemoryBufferFactoryHostImpl> gpu_memory_buffer_factory_host_;
87   int gpu_host_id_;
88   scoped_refptr<EstablishRequest> pending_request_;
89   std::vector<base::Closure> established_callbacks_;
90 
91   static BrowserGpuChannelHostFactory* instance_;
92 
93   DISALLOW_COPY_AND_ASSIGN(BrowserGpuChannelHostFactory);
94 };
95 
96 }  // namespace content
97 
98 #endif  // CONTENT_BROWSER_GPU_BROWSER_GPU_CHANNEL_HOST_FACTORY_H_
99