GraphicsSurfaceQt.cpp [plain text]
#include "config.h"
#include "GraphicsSurface.h"
#if USE(GRAPHICS_SURFACE) && PLATFORM(QT)
#include "BitmapImage.h"
#include <QImage>
#include <QPainter>
#include <QPixmap>
namespace WebCore {
void GraphicsSurface::didReleaseImage(void* data)
{
GraphicsSurface* surface = static_cast<GraphicsSurface*>(data);
surface->platformUnlock();
}
PassOwnPtr<GraphicsContext> GraphicsSurface::platformBeginPaint(const IntSize& size, char* bits, int stride)
{
QImage::Format format = (flags() & SupportsAlpha) ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32;
QImage* image = new QImage(reinterpret_cast<uchar*>(bits), size.width(), size.height(), stride, format, didReleaseImage, this);
QPainter* painter = new QPainter(image);
painter->setRenderHint(QPainter::SmoothPixmapTransform, true);
OwnPtr<GraphicsContext> graphicsContext = adoptPtr(new GraphicsContext(painter));
graphicsContext->takeOwnershipOfPlatformContext();
return graphicsContext.release();
}
PassRefPtr<Image> GraphicsSurface::createReadOnlyImage(const IntRect& rect)
{
int stride;
QImage::Format format = (flags() & SupportsAlpha) ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32;
char* data = platformLock(rect, &stride, RetainPixels | ReadOnly);
QImage image(reinterpret_cast<uchar*>(data), rect.width(), rect.height(), stride, format, didReleaseImage, this);
return BitmapImage::create(new QPixmap(QPixmap::fromImage(image)));
}
}
#endif