#ifndef ShareableBitmap_h
#define ShareableBitmap_h
#include "SharedMemory.h"
#include <WebCore/IntRect.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
#if USE(CG)
#include <wtf/RetainPtr.h>
#endif
#if USE(CAIRO)
#include <WebCore/RefPtrCairo.h>
#endif
#if PLATFORM(QT)
#include <QImage>
#ifdef Q_WS_X11
namespace WebCore { class Region; }
namespace WebKit { using WebCore::Region; }
#endif
#endif
namespace WebCore {
class Image;
class GraphicsContext;
}
namespace WebKit {
class ShareableBitmap : public RefCounted<ShareableBitmap> {
public:
enum Flag {
SupportsAlpha = 1 << 0,
};
typedef unsigned Flags;
class Handle {
WTF_MAKE_NONCOPYABLE(Handle);
public:
Handle();
bool isNull() const { return m_handle.isNull(); }
void encode(CoreIPC::ArgumentEncoder*) const;
static bool decode(CoreIPC::ArgumentDecoder*, Handle&);
private:
friend class ShareableBitmap;
mutable SharedMemory::Handle m_handle;
WebCore::IntSize m_size;
Flags m_flags;
};
static PassRefPtr<ShareableBitmap> create(const WebCore::IntSize&, Flags);
static PassRefPtr<ShareableBitmap> createShareable(const WebCore::IntSize&, Flags);
static PassRefPtr<ShareableBitmap> create(const WebCore::IntSize&, Flags, PassRefPtr<SharedMemory>);
static PassRefPtr<ShareableBitmap> create(const Handle&);
bool createHandle(Handle&);
~ShareableBitmap();
const WebCore::IntSize& size() const { return m_size; }
WebCore::IntRect bounds() const { return WebCore::IntRect(WebCore::IntPoint(), size()); }
bool resize(const WebCore::IntSize& size);
PassOwnPtr<WebCore::GraphicsContext> createGraphicsContext();
void paint(WebCore::GraphicsContext&, const WebCore::IntPoint& destination, const WebCore::IntRect& source);
void paint(WebCore::GraphicsContext&, float scaleFactor, const WebCore::IntPoint& destination, const WebCore::IntRect& source);
bool isBackedBySharedMemory() const { return m_sharedMemory; }
PassRefPtr<WebCore::Image> createImage();
#if PLATFORM(WIN)
HDC windowsContext() const;
#endif
#if USE(CG)
RetainPtr<CGImageRef> makeCGImageCopy();
RetainPtr<CGImageRef> makeCGImage();
#elif USE(CAIRO)
PassRefPtr<cairo_surface_t> createCairoSurface();
#elif PLATFORM(QT)
QImage createQImage();
static void releaseSharedMemoryData(void* typelessBitmap);
#endif
private:
ShareableBitmap(const WebCore::IntSize&, Flags, void*);
ShareableBitmap(const WebCore::IntSize&, Flags, PassRefPtr<SharedMemory>);
static size_t numBytesForSize(const WebCore::IntSize& size) { return size.width() * size.height() * 4; }
#if USE(CG)
RetainPtr<CGImageRef> createCGImage(CGDataProviderRef) const;
static void releaseBitmapContextData(void* typelessBitmap, void* typelessData);
static void releaseDataProviderData(void* typelessBitmap, const void* typelessData, size_t);
#endif
#if USE(CAIRO)
static void releaseSurfaceData(void* typelessBitmap);
#endif
void* data() const;
size_t sizeInBytes() const { return numBytesForSize(m_size); }
WebCore::IntSize m_size;
Flags m_flags;
RefPtr<SharedMemory> m_sharedMemory;
void* m_data;
#if PLATFORM(WIN)
mutable OwnPtr<HDC> m_windowsContext;
mutable OwnPtr<HBITMAP> m_windowsBitmap;
#endif
};
}
#endif // ShareableBitmap_h