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 "base/memory/ref_counted.h" 9 #include "base/memory/scoped_ptr.h" 10 #include "base/process/process.h" 11 #include "base/synchronization/waitable_event.h" 12 #include "content/common/gpu/client/gpu_channel_host.h" 13 #include "ipc/ipc_channel_handle.h" 14 15 namespace content { 16 17 class CONTENT_EXPORT BrowserGpuChannelHostFactory 18 : public GpuChannelHostFactory { 19 public: 20 static void Initialize(); 21 static void Terminate(); 22 static BrowserGpuChannelHostFactory* instance() { return instance_; } 23 24 // GpuChannelHostFactory implementation. 25 virtual bool IsMainThread() OVERRIDE; 26 virtual base::MessageLoop* GetMainLoop() OVERRIDE; 27 virtual scoped_refptr<base::MessageLoopProxy> GetIOLoopProxy() OVERRIDE; 28 virtual base::WaitableEvent* GetShutDownEvent() OVERRIDE; 29 virtual scoped_ptr<base::SharedMemory> AllocateSharedMemory( 30 size_t size) OVERRIDE; 31 virtual int32 CreateViewCommandBuffer( 32 int32 surface_id, 33 const GPUCreateCommandBufferConfig& init_params) OVERRIDE; 34 virtual void CreateImage( 35 gfx::PluginWindowHandle window, 36 int32 image_id, 37 const CreateImageCallback& callback) OVERRIDE; 38 virtual void DeleteImage(int32 image_idu, int32 sync_point) OVERRIDE; 39 virtual GpuChannelHost* EstablishGpuChannelSync( 40 CauseForGpuLaunch cause_for_gpu_launch) 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); 50 int GpuProcessHostId() { return gpu_host_id_; } 51 52 private: 53 struct CreateRequest { 54 CreateRequest(); 55 ~CreateRequest(); 56 base::WaitableEvent event; 57 int gpu_host_id; 58 int32 route_id; 59 }; 60 61 struct EstablishRequest { 62 explicit EstablishRequest(CauseForGpuLaunch); 63 ~EstablishRequest(); 64 base::WaitableEvent event; 65 CauseForGpuLaunch cause_for_gpu_launch; 66 int gpu_host_id; 67 bool reused_gpu_process; 68 IPC::ChannelHandle channel_handle; 69 gpu::GPUInfo gpu_info; 70 }; 71 72 BrowserGpuChannelHostFactory(); 73 virtual ~BrowserGpuChannelHostFactory(); 74 75 void CreateViewCommandBufferOnIO( 76 CreateRequest* request, 77 int32 surface_id, 78 const GPUCreateCommandBufferConfig& init_params); 79 static void CommandBufferCreatedOnIO(CreateRequest* request, int32 route_id); 80 void CreateImageOnIO( 81 gfx::PluginWindowHandle window, 82 int32 image_id, 83 const CreateImageCallback& callback); 84 static void ImageCreatedOnIO( 85 const CreateImageCallback& callback, const gfx::Size size); 86 static void OnImageCreated( 87 const CreateImageCallback& callback, const gfx::Size size); 88 void DeleteImageOnIO(int32 image_id, int32 sync_point); 89 void EstablishGpuChannelOnIO(EstablishRequest* request); 90 void GpuChannelEstablishedOnIO( 91 EstablishRequest* request, 92 const IPC::ChannelHandle& channel_handle, 93 const gpu::GPUInfo& gpu_info); 94 static void AddFilterOnIO( 95 int gpu_host_id, 96 scoped_refptr<IPC::ChannelProxy::MessageFilter> filter); 97 98 int gpu_client_id_; 99 scoped_ptr<base::WaitableEvent> shutdown_event_; 100 scoped_refptr<GpuChannelHost> gpu_channel_; 101 int gpu_host_id_; 102 103 static BrowserGpuChannelHostFactory* instance_; 104 105 DISALLOW_COPY_AND_ASSIGN(BrowserGpuChannelHostFactory); 106 }; 107 108 } // namespace content 109 110 #endif // CONTENT_BROWSER_GPU_BROWSER_GPU_CHANNEL_HOST_FACTORY_H_ 111