summaryrefslogtreecommitdiff
path: root/src/gui/image/qpixmap_mac.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/image/qpixmap_mac.cpp')
-rw-r--r--src/gui/image/qpixmap_mac.cpp205
1 files changed, 26 insertions, 179 deletions
diff --git a/src/gui/image/qpixmap_mac.cpp b/src/gui/image/qpixmap_mac.cpp
index 3a9676d615..5cfdba90a9 100644
--- a/src/gui/image/qpixmap_mac.cpp
+++ b/src/gui/image/qpixmap_mac.cpp
@@ -38,7 +38,6 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-//#define QT_RASTER_PAINTENGINE
#include "qpixmap.h"
#include "qimage.h"
@@ -52,9 +51,6 @@
#include <private/qdrawhelper_p.h>
#include <private/qpixmap_mac_p.h>
#include <private/qpixmap_raster_p.h>
-#ifdef QT_RASTER_PAINTENGINE
-# include <private/qpaintengine_raster_p.h>
-#endif
#include <private/qpaintengine_mac_p.h>
#include <private/qt_mac_p.h>
#include <private/qt_cocoa_helpers_mac_p.h>
@@ -77,12 +73,12 @@ static int qt_pixmap_serial = 0;
Q_GUI_EXPORT quint32 *qt_mac_pixmap_get_base(const QPixmap *pix)
{
- return static_cast<QMacPixmapData*>(pix->data)->pixels;
+ return static_cast<QMacPixmapData*>(pix->data.data())->pixels;
}
Q_GUI_EXPORT int qt_mac_pixmap_get_bytes_per_line(const QPixmap *pix)
{
- return static_cast<QMacPixmapData*>(pix->data)->bytesPerRow;
+ return static_cast<QMacPixmapData*>(pix->data.data())->bytesPerRow;
}
void qt_mac_cgimage_data_free(void *info, const void *memoryToFree, size_t)
@@ -119,14 +115,9 @@ CGImageRef qt_mac_image_to_cgimage(const QImage &image)
CGDataProviderCreateWithData(0, image.bits(), image.bytesPerLine() * image.height(),
0);
-#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
uint cgflags = kCGImageAlphaPremultipliedFirst;
#ifdef kCGBitmapByteOrder32Host //only needed because CGImage.h added symbols in the minor version
- if(QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4)
- cgflags |= kCGBitmapByteOrder32Host;
-#endif
-#else
- CGImageAlphaInfo cgflags = kCGImageAlphaPremultipliedFirst;
+ cgflags |= kCGBitmapByteOrder32Host;
#endif
CGImageRef cgImage = CGImageCreate(image.width(), image.height(), bitsPerColor, bitsPerPixel,
@@ -168,12 +159,9 @@ static inline QRgb qt_conv16ToRgb(ushort c) {
QSet<QMacPixmapData*> QMacPixmapData::validDataPointers;
QMacPixmapData::QMacPixmapData(PixelType type)
- : QPixmapData(type, MacClass), w(0), h(0), d(0), has_alpha(0), has_mask(0),
+ : QPixmapData(type, MacClass), has_alpha(0), has_mask(0),
uninit(true), pixels(0), pixelsToFree(0), bytesPerRow(0),
cg_data(0), cg_dataBeingReleased(0), cg_mask(0),
-#ifndef QT_MAC_NO_QUICKDRAW
- qd_data(0), qd_alpha(0),
-#endif
pengine(0)
{
}
@@ -188,11 +176,13 @@ void QMacPixmapData::resize(int width, int height)
w = width;
h = height;
+ is_null = (w <= 0 || h <= 0);
d = (pixelType() == BitmapType ? 1 : 32);
bool make_null = w <= 0 || h <= 0; // create null pixmap
if (make_null || d == 0) {
w = 0;
h = 0;
+ is_null = true;
d = 0;
if (!make_null)
qWarning("Qt: QPixmap: Invalid pixmap parameters");
@@ -231,6 +221,7 @@ void QMacPixmapData::fromImage(const QImage &img,
w = img.width();
h = img.height();
+ is_null = (w <= 0 || h <= 0);
d = (pixelType() == BitmapType ? 1 : img.depth());
QImage image = img;
@@ -430,7 +421,7 @@ QPixmap QMacPixmapData::alphaChannel() const
void QMacPixmapData::setAlphaChannel(const QPixmap &alpha)
{
has_mask = true;
- QMacPixmapData *alphaData = static_cast<QMacPixmapData*>(alpha.data);
+ QMacPixmapData *alphaData = static_cast<QMacPixmapData*>(alpha.data.data());
macSetAlphaChannel(alphaData, false);
}
@@ -458,7 +449,7 @@ void QMacPixmapData::setMask(const QBitmap &mask)
has_alpha = false;
has_mask = true;
- QMacPixmapData *maskData = static_cast<QMacPixmapData*>(mask.data);
+ QMacPixmapData *maskData = static_cast<QMacPixmapData*>(mask.data.data());
macSetAlphaChannel(maskData, true);
}
@@ -496,13 +487,6 @@ int QMacPixmapData::metric(QPaintDevice::PaintDeviceMetric theMetric) const
QMacPixmapData::~QMacPixmapData()
{
validDataPointers.remove(this);
-#ifndef QT_MAC_NO_QUICKDRAW
- macQDDisposeAlpha();
- if (qd_data) {
- DisposeGWorld(qd_data);
- qd_data = 0;
- }
-#endif
if (cg_mask) {
CGImageRelease(cg_mask);
cg_mask = 0;
@@ -591,48 +575,9 @@ void QMacPixmapData::macGetAlphaChannel(QMacPixmapData *pix, bool asMask) const
void QMacPixmapData::macSetHasAlpha(bool b)
{
has_alpha = b;
-#ifndef QT_MAC_NO_QUICKDRAW
- macQDDisposeAlpha(); //let it get created lazily
-#endif
macReleaseCGImageRef();
}
-#ifndef QT_MAC_NO_QUICKDRAW
-void QMacPixmapData::macQDDisposeAlpha()
-{
- if (qd_alpha) {
- DisposeGWorld(qd_alpha);
- qd_alpha = 0;
- }
-}
-
-void QMacPixmapData::macQDUpdateAlpha()
-{
- macQDDisposeAlpha(); // get rid of alpha pixmap
- if (!has_alpha && !has_mask)
- return;
-
- //setup
- Rect rect;
- SetRect(&rect, 0, 0, w, h);
- const int params = alignPix | stretchPix | newDepth;
- NewGWorld(&qd_alpha, 32, &rect, 0, 0, params);
- int *dptr = (int *)GetPixBaseAddr(GetGWorldPixMap(qd_alpha)), *drow;
- unsigned short dbpr = GetPixRowBytes(GetGWorldPixMap(qd_alpha));
- const int *sptr = (int*)pixels, *srow;
- const uint sbpr = bytesPerRow;
- uchar clr;
- for (int y = 0; y < h; ++y) {
- drow = (int*)((char *)dptr + (y * dbpr));
- srow = (int*)((char *)sptr + (y * sbpr));
- for (int x=0; x < w; x++) {
- clr = qAlpha(*(srow + x));
- *(drow + x) = qRgba(~clr, ~clr, ~clr, 0);
- }
- }
-}
-#endif
-
void QMacPixmapData::macCreateCGImageRef()
{
Q_ASSERT(cg_data == 0);
@@ -642,14 +587,9 @@ void QMacPixmapData::macCreateCGImageRef()
pixels, bytesPerRow * h,
qt_mac_cgimage_data_free);
validDataPointers.insert(this);
-#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
uint cgflags = kCGImageAlphaPremultipliedFirst;
#ifdef kCGBitmapByteOrder32Host //only needed because CGImage.h added symbols in the minor version
- if(QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4)
- cgflags |= kCGBitmapByteOrder32Host;
-#endif
-#else
- CGImageAlphaInfo cgflags = kCGImageAlphaPremultipliedFirst;
+ cgflags |= kCGBitmapByteOrder32Host;
#endif
cg_data = CGImageCreate(w, h, 8, 32, bytesPerRow, colorspace,
cgflags, provider, 0, 0, kCGRenderingIntentDefault);
@@ -890,38 +830,6 @@ static void qt_mac_grabDisplayRect(CGDirectDisplayID display, const QRect &displ
ptrCGLDestroyContext(glContextObj); // and destroy the context
}
-static CGImageRef qt_mac_createImageFromBitmapContext(CGContextRef c)
-{
- void *rasterData = CGBitmapContextGetData(c);
- const int width = CGBitmapContextGetBytesPerRow(c),
- height = CGBitmapContextGetHeight(c);
- size_t imageDataSize = width*height;
-
- if(!rasterData)
- return 0;
-
- // Create the data provider from the image data, using
- // the image releaser function releaseBitmapContextImageData.
- CGDataProviderRef dataProvider = CGDataProviderCreateWithData(0, rasterData,
- imageDataSize,
- qt_mac_cgimage_data_free);
-
- if(!dataProvider)
- return 0;
-
- uint bitmapInfo = 0;
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
- if(CGBitmapContextGetBitmapInfo)
- bitmapInfo = CGBitmapContextGetBitmapInfo(c);
- else
-#endif
- bitmapInfo = CGBitmapContextGetAlphaInfo(c);
- return CGImageCreate(width, height, CGBitmapContextGetBitsPerComponent(c),
- CGBitmapContextGetBitsPerPixel(c), CGBitmapContextGetBytesPerRow(c),
- CGBitmapContextGetColorSpace(c), bitmapInfo, dataProvider,
- 0, true, kCGRenderingIntentDefault);
-}
-
// Returns a pixmap containing the screen contents at rect.
static QPixmap qt_mac_grabScreenRect(const QRect &rect)
{
@@ -955,19 +863,8 @@ static QPixmap qt_mac_grabScreenRect(const QRect &rect)
rect.height(), 8, bytewidth,
QCoreGraphicsPaintEngine::macGenericColorSpace(),
kCGImageAlphaNoneSkipFirst);
-
-#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
- if(QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) {
- QCFType<CGImageRef> image = CGBitmapContextCreateImage(bitmap);
- return QPixmap::fromMacCGImageRef(image);
- } else
-#endif
- {
- QCFType<CGImageRef> image = qt_mac_createImageFromBitmapContext(bitmap);
- if (!image)
- return QPixmap();
- return QPixmap::fromMacCGImageRef(image);
- }
+ QCFType<CGImageRef> image = CGBitmapContextCreateImage(bitmap);
+ return QPixmap::fromMacCGImageRef(image);
}
#ifndef QT_MAC_USE_COCOA // no QuickDraw in 64-bit mode
@@ -1029,37 +926,12 @@ QPixmap QPixmap::grabWindow(WId window, int x, int y, int w, int h)
relocated.
\warning This function is only available on Mac OS X.
+ \warning As of Qt 4.6, this function \e{always} returns zero.
*/
Qt::HANDLE QPixmap::macQDHandle() const
{
-#ifndef QT_MAC_NO_QUICKDRAW
- QMacPixmapData *d = static_cast<QMacPixmapData*>(data);
- if (!d->qd_data) { //create the qd data
- Rect rect;
- SetRect(&rect, 0, 0, d->w, d->h);
- unsigned long qdformat = k32ARGBPixelFormat;
- GWorldFlags qdflags = 0;
-#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
- if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) {
- //we play such games so we can use the same buffer in CG as QD this
- //makes our merge much simpler, at some point the hacks will go away
- //because QD will be removed, but until that day this keeps them coexisting
- if (QSysInfo::ByteOrder == QSysInfo::LittleEndian)
- qdformat = k32BGRAPixelFormat;
-#if 0
- qdflags |= kNativeEndianPixMap;
-#endif
- }
-#endif
- if(NewGWorldFromPtr(&d->qd_data, qdformat, &rect, 0, 0, qdflags,
- (char*)d->pixels, d->bytesPerRow) != noErr)
- qWarning("Qt: internal: QPixmap::init error (%d %d %d %d)", rect.left, rect.top, rect.right, rect.bottom);
- }
- return d->qd_data;
-#else
return 0;
-#endif
}
/*! \internal
@@ -1069,18 +941,11 @@ Qt::HANDLE QPixmap::macQDHandle() const
long as it can be relocated.
\warning This function is only available on Mac OS X.
+ \warning As of Qt 4.6, this function \e{always} returns zero.
*/
Qt::HANDLE QPixmap::macQDAlphaHandle() const
{
-#ifndef QT_MAC_NO_QUICKDRAW
- QMacPixmapData *d = static_cast<QMacPixmapData*>(data);
- if (d->has_alpha || d->has_mask) {
- if (!d->qd_alpha) //lazily created
- d->macQDUpdateAlpha();
- return d->qd_alpha;
- }
-#endif
return 0;
}
@@ -1096,14 +961,14 @@ Qt::HANDLE QPixmap::macQDAlphaHandle() const
Qt::HANDLE QPixmap::macCGHandle() const
{
if (data->classId() == QPixmapData::MacClass) {
- QMacPixmapData *d = static_cast<QMacPixmapData *>(data);
+ QMacPixmapData *d = static_cast<QMacPixmapData *>(data.data());
if (!d->cg_data)
d->macCreateCGImageRef();
CGImageRef ret = d->cg_data;
CGImageRetain(ret);
return ret;
} else if (data->classId() == QPixmapData::RasterClass) {
- return qt_mac_image_to_cgimage(static_cast<QRasterPixmapData *>(data)->image);
+ return qt_mac_image_to_cgimage(static_cast<QRasterPixmapData *>(data.data())->image);
}
return 0;
}
@@ -1115,7 +980,7 @@ bool QMacPixmapData::hasAlphaChannel() const
CGImageRef qt_mac_create_imagemask(const QPixmap &pixmap, const QRectF &sr)
{
- QMacPixmapData *px = static_cast<QMacPixmapData*>(pixmap.data);
+ QMacPixmapData *px = static_cast<QMacPixmapData*>(pixmap.data.data());
if (px->cg_mask) {
if (px->cg_mask_rect == sr) {
CGImageRetain(px->cg_mask); //reference for the caller
@@ -1150,7 +1015,6 @@ IconRef qt_mac_create_iconref(const QPixmap &px)
if (px.isNull())
return 0;
- QMacSavedPortInfo pi; //save the current state
//create icon
IconFamilyHandle iconFamily = reinterpret_cast<IconFamilyHandle>(NewHandle(0));
//create data
@@ -1225,38 +1089,12 @@ IconRef qt_mac_create_iconref(const QPixmap &px)
}
#endif
-QPixmap qt_mac_convert_iconref(const IconRef icon, int width, int height)
-{
- QPixmap ret(width, height);
- ret.fill(QColor(0, 0, 0, 0));
-
- CGRect rect = CGRectMake(0, 0, width, height);
-
- CGContextRef ctx = qt_mac_cg_context(&ret);
- CGAffineTransform old_xform = CGContextGetCTM(ctx);
- CGContextConcatCTM(ctx, CGAffineTransformInvert(old_xform));
- CGContextConcatCTM(ctx, CGAffineTransformIdentity);
-
- ::RGBColor b;
- b.blue = b.green = b.red = 255*255;
- PlotIconRefInContext(ctx, &rect, kAlignNone, kTransformNone, &b, kPlotIconRefNormalFlags, icon);
- CGContextRelease(ctx);
- return ret;
-}
-
/*! \internal */
QPaintEngine* QMacPixmapData::paintEngine() const
{
if (!pengine) {
QMacPixmapData *that = const_cast<QMacPixmapData*>(this);
-#ifdef QT_RASTER_PAINTENGINE
- if (qgetenv("QT_MAC_USE_COREGRAPHICS").isNull())
- that->pengine = new QRasterPaintEngine();
- else
- that->pengine = new QCoreGraphicsPaintEngine();
-#else
that->pengine = new QCoreGraphicsPaintEngine();
-#endif
}
return pengine;
}
@@ -1290,6 +1128,14 @@ void QMacPixmapData::copy(const QPixmapData *data, const QRect &rect)
has_mask = macData->has_mask;
}
+bool QMacPixmapData::scroll(int dx, int dy, const QRect &rect)
+{
+ Q_UNUSED(dx);
+ Q_UNUSED(dy);
+ Q_UNUSED(rect);
+ return false;
+}
+
/*!
\since 4.2
@@ -1321,6 +1167,7 @@ QPixmap QPixmap::fromMacCGImageRef(CGImageRef image)
const size_t w = CGImageGetWidth(image),
h = CGImageGetHeight(image);
QPixmap ret(w, h);
+ ret.fill(Qt::transparent);
CGRect rect = CGRectMake(0, 0, w, h);
CGContextRef ctx = qt_mac_cg_context(&ret);
qt_mac_drawCGImage(ctx, &rect, image);