// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CONTENT_BROWSER_GPU_BROWSER_GPU_CHANNEL_HOST_FACTORY_H_ #define CONTENT_BROWSER_GPU_BROWSER_GPU_CHANNEL_HOST_FACTORY_H_ #include #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "content/common/gpu/client/gpu_channel_host.h" #include "ipc/message_filter.h" namespace content { class GpuMemoryBufferImpl; class GpuMemoryBufferFactoryHostImpl; class CONTENT_EXPORT BrowserGpuChannelHostFactory : public GpuChannelHostFactory { public: static void Initialize(bool establish_gpu_channel); static void Terminate(); static BrowserGpuChannelHostFactory* instance() { return instance_; } // GpuChannelHostFactory implementation. virtual bool IsMainThread() OVERRIDE; virtual base::MessageLoop* GetMainLoop() OVERRIDE; virtual scoped_refptr GetIOLoopProxy() OVERRIDE; virtual scoped_ptr AllocateSharedMemory( size_t size) OVERRIDE; virtual CreateCommandBufferResult CreateViewCommandBuffer( int32 surface_id, const GPUCreateCommandBufferConfig& init_params, int32 route_id) OVERRIDE; virtual scoped_ptr AllocateGpuMemoryBuffer( size_t width, size_t height, unsigned internalformat, unsigned usage) OVERRIDE; virtual void DeleteGpuMemoryBuffer( scoped_ptr buffer) OVERRIDE; // Specify a task runner and callback to be used for a set of messages. The // callback will be set up on the current GpuProcessHost, identified by // GpuProcessHostId(). virtual void SetHandlerForControlMessages( const uint32* message_ids, size_t num_messages, const base::Callback& handler, base::TaskRunner* target_task_runner); int GpuProcessHostId() { return gpu_host_id_; } GpuChannelHost* EstablishGpuChannelSync( CauseForGpuLaunch cause_for_gpu_launch); void EstablishGpuChannel(CauseForGpuLaunch cause_for_gpu_launch, const base::Closure& callback); GpuChannelHost* GetGpuChannel(); int GetGpuChannelId() { return gpu_client_id_; } // Used to skip GpuChannelHost tests when there can be no GPU process. static bool CanUseForTesting(); private: struct CreateRequest; struct AllocateGpuMemoryBufferRequest; class EstablishRequest; BrowserGpuChannelHostFactory(); virtual ~BrowserGpuChannelHostFactory(); void GpuChannelEstablished(); void CreateViewCommandBufferOnIO( CreateRequest* request, int32 surface_id, const GPUCreateCommandBufferConfig& init_params); static void CommandBufferCreatedOnIO(CreateRequest* request, CreateCommandBufferResult result); static void AddFilterOnIO(int gpu_host_id, scoped_refptr filter); static void AllocateGpuMemoryBufferOnIO( AllocateGpuMemoryBufferRequest* request); static void DeleteGpuMemoryBufferOnIO( scoped_ptr buffer); static void OnGpuMemoryBufferCreated(AllocateGpuMemoryBufferRequest* request, scoped_ptr buffer); const int gpu_client_id_; scoped_ptr shutdown_event_; scoped_refptr gpu_channel_; scoped_ptr gpu_memory_buffer_factory_host_; int gpu_host_id_; scoped_refptr pending_request_; std::vector established_callbacks_; static BrowserGpuChannelHostFactory* instance_; DISALLOW_COPY_AND_ASSIGN(BrowserGpuChannelHostFactory); }; } // namespace content #endif // CONTENT_BROWSER_GPU_BROWSER_GPU_CHANNEL_HOST_FACTORY_H_