#ifndef CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_H_
#define CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_H_
#include <vector>
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "content/common/content_export.h"
#include "ipc/ipc_listener.h"
#include "ipc/ipc_message.h"
#include "ui/events/latency_info.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
#include "ui/gl/gl_surface.h"
struct AcceleratedSurfaceMsg_BufferPresented_Params;
struct GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params;
struct GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params;
namespace gfx {
class GLSurface;
}
namespace gpu {
class GpuScheduler;
class PreemptionFlag;
namespace gles2 {
class GLES2Decoder;
}
}
namespace content {
class GpuChannelManager;
class GpuCommandBufferStub;
class ImageTransportSurface {
public:
ImageTransportSurface();
virtual void OnBufferPresented(
const AcceleratedSurfaceMsg_BufferPresented_Params& params) = 0;
virtual void OnResizeViewACK() = 0;
virtual void OnResize(gfx::Size size, float scale_factor) = 0;
virtual void SetLatencyInfo(
const std::vector<ui::LatencyInfo>& latency_info) = 0;
virtual void WakeUpGpu() = 0;
static scoped_refptr<gfx::GLSurface> CreateSurface(
GpuChannelManager* manager,
GpuCommandBufferStub* stub,
const gfx::GLSurfaceHandle& handle);
#if defined(OS_MACOSX)
CONTENT_EXPORT static void SetAllowOSMesaForTesting(bool allow);
#endif
virtual gfx::Size GetSize() = 0;
protected:
virtual ~ImageTransportSurface();
private:
static scoped_refptr<gfx::GLSurface> CreateNativeSurface(
GpuChannelManager* manager,
GpuCommandBufferStub* stub,
const gfx::GLSurfaceHandle& handle);
DISALLOW_COPY_AND_ASSIGN(ImageTransportSurface);
};
class ImageTransportHelper
: public IPC::Listener,
public base::SupportsWeakPtr<ImageTransportHelper> {
public:
ImageTransportHelper(ImageTransportSurface* surface,
GpuChannelManager* manager,
GpuCommandBufferStub* stub,
gfx::PluginWindowHandle handle);
virtual ~ImageTransportHelper();
bool Initialize();
void Destroy();
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
void SendAcceleratedSurfaceBuffersSwapped(
GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params);
void SendAcceleratedSurfacePostSubBuffer(
GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params params);
void SendAcceleratedSurfaceRelease();
void SendResizeView(const gfx::Size& size);
void SendUpdateVSyncParameters(
base::TimeTicks timebase, base::TimeDelta interval);
void SendLatencyInfo(const std::vector<ui::LatencyInfo>& latency_info);
void SetScheduled(bool is_scheduled);
void DeferToFence(base::Closure task);
void SetPreemptByFlag(
scoped_refptr<gpu::PreemptionFlag> preemption_flag);
bool MakeCurrent();
static void SetSwapInterval(gfx::GLContext* context);
void Suspend();
GpuChannelManager* manager() const { return manager_; }
GpuCommandBufferStub* stub() const { return stub_.get(); }
private:
gpu::GpuScheduler* Scheduler();
gpu::gles2::GLES2Decoder* Decoder();
void OnBufferPresented(
const AcceleratedSurfaceMsg_BufferPresented_Params& params);
void OnResizeViewACK();
void OnWakeUpGpu();
void Resize(gfx::Size size, float scale_factor);
void SetLatencyInfo(const std::vector<ui::LatencyInfo>& latency_info);
ImageTransportSurface* surface_;
GpuChannelManager* manager_;
base::WeakPtr<GpuCommandBufferStub> stub_;
int32 route_id_;
gfx::PluginWindowHandle handle_;
DISALLOW_COPY_AND_ASSIGN(ImageTransportHelper);
};
class PassThroughImageTransportSurface
: public gfx::GLSurfaceAdapter,
public ImageTransportSurface {
public:
PassThroughImageTransportSurface(GpuChannelManager* manager,
GpuCommandBufferStub* stub,
gfx::GLSurface* surface,
bool transport);
virtual bool Initialize() OVERRIDE;
virtual void Destroy() OVERRIDE;
virtual bool DeferDraws() OVERRIDE;
virtual bool SwapBuffers() OVERRIDE;
virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE;
virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE;
virtual void OnBufferPresented(
const AcceleratedSurfaceMsg_BufferPresented_Params& params) OVERRIDE;
virtual void OnResizeViewACK() OVERRIDE;
virtual void OnResize(gfx::Size size, float scale_factor) OVERRIDE;
virtual gfx::Size GetSize() OVERRIDE;
virtual void SetLatencyInfo(
const std::vector<ui::LatencyInfo>& latency_info) OVERRIDE;
virtual void WakeUpGpu() OVERRIDE;
protected:
virtual ~PassThroughImageTransportSurface();
virtual void SendVSyncUpdateIfAvailable();
ImageTransportHelper* GetHelper() { return helper_.get(); }
private:
scoped_ptr<ImageTransportHelper> helper_;
gfx::Size new_size_;
bool transport_;
bool did_set_swap_interval_;
bool did_unschedule_;
bool is_swap_buffers_pending_;
std::vector<ui::LatencyInfo> latency_info_;
DISALLOW_COPY_AND_ASSIGN(PassThroughImageTransportSurface);
};
}
#endif