Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / common / gpu / client / gpu_channel_host.h
index e073db0..ebbbdac 100644 (file)
 #include "base/synchronization/lock.h"
 #include "content/common/content_export.h"
 #include "content/common/gpu/gpu_process_launch_causes.h"
+#include "content/common/gpu/gpu_result_codes.h"
 #include "content/common/message_router.h"
 #include "gpu/config/gpu_info.h"
 #include "ipc/ipc_channel_handle.h"
-#include "ipc/ipc_channel_proxy.h"
 #include "ipc/ipc_sync_channel.h"
-#include "media/video/video_decode_accelerator.h"
-#include "media/video/video_encode_accelerator.h"
+#include "ipc/message_filter.h"
 #include "ui/gfx/gpu_memory_buffer.h"
 #include "ui/gfx/native_widget_types.h"
 #include "ui/gfx/size.h"
@@ -43,6 +42,15 @@ namespace IPC {
 class SyncMessageFilter;
 }
 
+namespace media {
+class VideoDecodeAccelerator;
+class VideoEncodeAccelerator;
+}
+
+namespace gpu {
+class GpuMemoryBufferManager;
+}
+
 namespace content {
 class CommandBufferProxyImpl;
 class GpuChannelHost;
@@ -57,25 +65,16 @@ struct GpuListenerInfo {
 
 class CONTENT_EXPORT GpuChannelHostFactory {
  public:
-  typedef base::Callback<void(const gfx::Size)> CreateImageCallback;
-
   virtual ~GpuChannelHostFactory() {}
 
   virtual bool IsMainThread() = 0;
   virtual base::MessageLoop* GetMainLoop() = 0;
   virtual scoped_refptr<base::MessageLoopProxy> GetIOLoopProxy() = 0;
   virtual scoped_ptr<base::SharedMemory> AllocateSharedMemory(size_t size) = 0;
-  virtual int32 CreateViewCommandBuffer(
-      int32 surface_id, const GPUCreateCommandBufferConfig& init_params) = 0;
-  virtual void CreateImage(
-      gfx::PluginWindowHandle window,
-      int32 image_id,
-      const CreateImageCallback& callback) = 0;
-  virtual void DeleteImage(int32 image_id, int32 sync_point) = 0;
-  virtual scoped_ptr<gfx::GpuMemoryBuffer> AllocateGpuMemoryBuffer(
-      size_t width,
-      size_t height,
-      unsigned internalformat) = 0;
+  virtual CreateCommandBufferResult CreateViewCommandBuffer(
+      int32 surface_id,
+      const GPUCreateCommandBufferConfig& init_params,
+      int32 route_id) = 0;
 };
 
 // Encapsulates an IPC channel between the client and one GPU process.
@@ -90,11 +89,8 @@ class GpuChannelHost : public IPC::Sender,
       GpuChannelHostFactory* factory,
       const gpu::GPUInfo& gpu_info,
       const IPC::ChannelHandle& channel_handle,
-      base::WaitableEvent* shutdown_event);
-
-  // Returns true if |handle| is a valid GpuMemoryBuffer handle that
-  // can be shared to the GPU process.
-  static bool IsValidGpuMemoryBuffer(gfx::GpuMemoryBufferHandle handle);
+      base::WaitableEvent* shutdown_event,
+      gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager);
 
   bool IsLost() const {
     DCHECK(channel_filter_.get());
@@ -105,7 +101,7 @@ class GpuChannelHost : public IPC::Sender,
   const gpu::GPUInfo& gpu_info() const { return gpu_info_; }
 
   // IPC::Sender implementation:
-  virtual bool Send(IPC::Message* msg) OVERRIDE;
+  bool Send(IPC::Message* msg) override;
 
   // Create and connect to a command buffer in the GPU process.
   CommandBufferProxyImpl* CreateViewCommandBuffer(
@@ -125,11 +121,11 @@ class GpuChannelHost : public IPC::Sender,
 
   // Creates a video decoder in the GPU process.
   scoped_ptr<media::VideoDecodeAccelerator> CreateVideoDecoder(
-      int command_buffer_route_id,
-      media::VideoCodecProfile profile);
+      int command_buffer_route_id);
 
   // Creates a video encoder in the GPU process.
-  scoped_ptr<media::VideoEncodeAccelerator> CreateVideoEncoder();
+  scoped_ptr<media::VideoEncodeAccelerator> CreateVideoEncoder(
+      int command_buffer_route_id);
 
   // Destroy a command buffer created by this channel.
   void DestroyCommandBuffer(CommandBufferProxyImpl* command_buffer);
@@ -140,6 +136,10 @@ class GpuChannelHost : public IPC::Sender,
 
   GpuChannelHostFactory* factory() const { return factory_; }
 
+  gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager() const {
+    return gpu_memory_buffer_manager_;
+  }
+
   // Returns a handle to the shared memory that can be sent via IPC to the
   // GPU process. The caller is responsible for ensuring it is closed. Returns
   // an invalid handle on failure.
@@ -153,23 +153,28 @@ class GpuChannelHost : public IPC::Sender,
   // IPC to the GPU process. The caller is responsible for ensuring it is
   // closed. Returns an invalid handle on failure.
   gfx::GpuMemoryBufferHandle ShareGpuMemoryBufferToGpuProcess(
-      gfx::GpuMemoryBufferHandle source_handle);
+      const gfx::GpuMemoryBufferHandle& source_handle,
+      bool* requires_sync_point);
 
-  // Reserve one unused gpu memory buffer ID.
-  int32 ReserveGpuMemoryBufferId();
+  // Reserve one unused image ID.
+  int32 ReserveImageId();
+
+  // Generate a route ID guaranteed to be unique for this channel.
+  int32 GenerateRouteID();
 
  private:
   friend class base::RefCountedThreadSafe<GpuChannelHost>;
   GpuChannelHost(GpuChannelHostFactory* factory,
-                 const gpu::GPUInfo& gpu_info);
-  virtual ~GpuChannelHost();
+                 const gpu::GPUInfo& gpu_info,
+                 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager);
+  ~GpuChannelHost() override;
   void Connect(const IPC::ChannelHandle& channel_handle,
                base::WaitableEvent* shutdown_event);
 
   // A filter used internally to route incoming messages from the IO thread
   // to the correct message loop. It also maintains some shared state between
   // all the contexts.
-  class MessageFilter : public IPC::ChannelProxy::MessageFilter {
+  class MessageFilter : public IPC::MessageFilter {
    public:
     MessageFilter();
 
@@ -180,10 +185,10 @@ class GpuChannelHost : public IPC::Sender,
     // Called on the IO thread.
     void RemoveRoute(int route_id);
 
-    // IPC::ChannelProxy::MessageFilter implementation
+    // IPC::MessageFilter implementation
     // (called on the IO thread):
-    virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
-    virtual void OnChannelError() OVERRIDE;
+    bool OnMessageReceived(const IPC::Message& msg) override;
+    void OnChannelError() override;
 
     // The following methods can be called on any thread.
 
@@ -191,7 +196,7 @@ class GpuChannelHost : public IPC::Sender,
     bool IsLost() const;
 
    private:
-    virtual ~MessageFilter();
+    ~MessageFilter() override;
 
     // Threading notes: |listeners_| is only accessed on the IO thread. Every
     // other field is protected by |lock_|.
@@ -208,7 +213,8 @@ class GpuChannelHost : public IPC::Sender,
   // Threading notes: all fields are constant during the lifetime of |this|
   // except:
   // - |next_transfer_buffer_id_|, atomic type
-  // - |next_gpu_memory_buffer_id_|, atomic type
+  // - |next_image_id_|, atomic type
+  // - |next_route_id_|, atomic type
   // - |proxies_|, protected by |context_lock_|
   GpuChannelHostFactory* const factory_;
 
@@ -217,14 +223,19 @@ class GpuChannelHost : public IPC::Sender,
   scoped_ptr<IPC::SyncChannel> channel_;
   scoped_refptr<MessageFilter> channel_filter_;
 
+  gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager_;
+
   // A filter for sending messages from thread other than the main thread.
   scoped_refptr<IPC::SyncMessageFilter> sync_filter_;
 
   // Transfer buffer IDs are allocated in sequence.
   base::AtomicSequenceNumber next_transfer_buffer_id_;
 
-  // Gpu memory buffer IDs are allocated in sequence.
-  base::AtomicSequenceNumber next_gpu_memory_buffer_id_;
+  // Image IDs are allocated in sequence.
+  base::AtomicSequenceNumber next_image_id_;
+
+  // Route IDs are allocated in sequence.
+  base::AtomicSequenceNumber next_route_id_;
 
   // Protects proxies_.
   mutable base::Lock context_lock_;