Qt 4.8
Macros | Typedefs | Functions | Variables
qpixmap_mac.cpp File Reference
#include "qpixmap.h"
#include "qimage.h"
#include "qapplication.h"
#include "qbitmap.h"
#include "qmatrix.h"
#include "qtransform.h"
#include "qlibrary.h"
#include "qvarlengtharray.h"
#include "qdebug.h"
#include <private/qdrawhelper_p.h>
#include <private/qpixmap_mac_p.h>
#include <private/qpixmap_raster_p.h>
#include <private/qpaintengine_mac_p.h>
#include <private/qt_mac_p.h>
#include <private/qt_cocoa_helpers_mac_p.h>
#include <private/qapplication_p.h>
#include <limits.h>
#include <string.h>
#include <OpenGL/OpenGL.h>
#include <OpenGL/gl.h>

Go to the source code of this file.

Macros

#define BEST_BYTE_ALIGNMENT   16
 
#define COMPTUE_BEST_BYTES_PER_ROW(bpr)   (((bpr) + (BEST_BYTE_ALIGNMENT - 1)) & ~(BEST_BYTE_ALIGNMENT - 1))
 

Typedefs

typedef CGLError(* PtrCGLChoosePixelFormat) (const CGLPixelFormatAttribute *, CGLPixelFormatObj *, long *)
 
typedef CGLError(* PtrCGLClearDrawable) (CGLContextObj)
 
typedef CGLError(* PtrCGLCreateContext) (CGLPixelFormatObj, CGLContextObj, CGLContextObj *)
 
typedef CGLError(* PtrCGLDestroyContext) (CGLContextObj)
 
typedef CGLError(* PtrCGLDestroyPixelFormat) (CGLPixelFormatObj)
 
typedef CGLError(* PtrCGLSetCurrentContext) (CGLContextObj)
 
typedef CGLError(* PtrCGLSetFullScreen) (CGLContextObj)
 
typedef void(* PtrglFinish) ()
 
typedef void(* PtrglPixelStorei) (GLenum, GLint)
 
typedef void(* PtrglReadBuffer) (GLenum)
 
typedef void(* PtrglReadPixels) (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid *)
 

Functions

int get_index (QImage *qi, QRgb mycol)
 
static QRgb qt_conv16ToRgb (ushort c)
 
const ucharqt_get_bitflip_array ()
 
CGContextRef qt_mac_cg_context (const QPaintDevice *pdev)
 Returns the CoreGraphics CGContextRef of the paint device. More...
 
void qt_mac_cgimage_data_free (void *info, const void *memoryToFree, size_t)
 
QRegion qt_mac_convert_mac_region (RgnHandle rgn)
 
IconRef qt_mac_create_iconref (const QPixmap &px)
 
CGImageRef qt_mac_create_imagemask (const QPixmap &pixmap, const QRectF &sr)
 
void qt_mac_dispose_rgn (RgnHandle r)
 
static void qt_mac_flipPixmap (void *data, int rowBytes, int height)
 
RgnHandle qt_mac_get_rgn ()
 
static void qt_mac_grabDisplayRect (CGDirectDisplayID display, const QRect &displayRect, void *buffer)
 
static QPixmap qt_mac_grabScreenRect (const QRect &rect)
 
static QPixmap qt_mac_grabScreenRect_10_3 (int x, int y, int w, int h, QWidget *widget)
 
CGImageRef qt_mac_image_to_cgimage (const QImage &image)
 
Q_GUI_EXPORT quint32qt_mac_pixmap_get_base (const QPixmap *pix)
 
Q_GUI_EXPORT int qt_mac_pixmap_get_bytes_per_line (const QPixmap *pix)
 
static bool resolveOpenGLSymbols ()
 

Variables

static PtrCGLChoosePixelFormat ptrCGLChoosePixelFormat = 0
 
static PtrCGLClearDrawable ptrCGLClearDrawable = 0
 
static PtrCGLCreateContext ptrCGLCreateContext = 0
 
static PtrCGLDestroyContext ptrCGLDestroyContext = 0
 
static PtrCGLDestroyPixelFormat ptrCGLDestroyPixelFormat = 0
 
static PtrCGLSetCurrentContext ptrCGLSetCurrentContext = 0
 
static PtrCGLSetFullScreen ptrCGLSetFullScreen = 0
 
static PtrglFinish ptrglFinish = 0
 
static PtrglPixelStorei ptrglPixelStorei = 0
 
static PtrglReadBuffer ptrglReadBuffer = 0
 
static PtrglReadPixels ptrglReadPixels = 0
 
static int qt_pixmap_serial = 0
 

Macro Definition Documentation

◆ BEST_BYTE_ALIGNMENT

#define BEST_BYTE_ALIGNMENT   16

Definition at line 186 of file qpixmap_mac.cpp.

◆ COMPTUE_BEST_BYTES_PER_ROW

#define COMPTUE_BEST_BYTES_PER_ROW (   bpr)    (((bpr) + (BEST_BYTE_ALIGNMENT - 1)) & ~(BEST_BYTE_ALIGNMENT - 1))

Definition at line 187 of file qpixmap_mac.cpp.

Referenced by QMacPixmapData::resize().

Typedef Documentation

◆ PtrCGLChoosePixelFormat

typedef CGLError(* PtrCGLChoosePixelFormat) (const CGLPixelFormatAttribute *, CGLPixelFormatObj *, long *)

Definition at line 756 of file qpixmap_mac.cpp.

◆ PtrCGLClearDrawable

typedef CGLError(* PtrCGLClearDrawable) (CGLContextObj)

Definition at line 757 of file qpixmap_mac.cpp.

◆ PtrCGLCreateContext

typedef CGLError(* PtrCGLCreateContext) (CGLPixelFormatObj, CGLContextObj, CGLContextObj *)

Definition at line 758 of file qpixmap_mac.cpp.

◆ PtrCGLDestroyContext

typedef CGLError(* PtrCGLDestroyContext) (CGLContextObj)

Definition at line 759 of file qpixmap_mac.cpp.

◆ PtrCGLDestroyPixelFormat

typedef CGLError(* PtrCGLDestroyPixelFormat) (CGLPixelFormatObj)

Definition at line 760 of file qpixmap_mac.cpp.

◆ PtrCGLSetCurrentContext

typedef CGLError(* PtrCGLSetCurrentContext) (CGLContextObj)

Definition at line 761 of file qpixmap_mac.cpp.

◆ PtrCGLSetFullScreen

typedef CGLError(* PtrCGLSetFullScreen) (CGLContextObj)

Definition at line 762 of file qpixmap_mac.cpp.

◆ PtrglFinish

typedef void(* PtrglFinish) ()

Definition at line 763 of file qpixmap_mac.cpp.

◆ PtrglPixelStorei

typedef void(* PtrglPixelStorei) (GLenum, GLint)

Definition at line 764 of file qpixmap_mac.cpp.

◆ PtrglReadBuffer

typedef void(* PtrglReadBuffer) (GLenum)

Definition at line 765 of file qpixmap_mac.cpp.

◆ PtrglReadPixels

typedef void(* PtrglReadPixels) (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid *)

Definition at line 766 of file qpixmap_mac.cpp.

Function Documentation

◆ get_index()

int get_index ( QImage qi,
QRgb  mycol 
)

Definition at line 371 of file qpixmap_mac.cpp.

372 {
373  int loopc;
374  for(loopc=0;loopc<qi->colorCount();loopc++) {
375  if(qi->color(loopc)==mycol)
376  return loopc;
377  }
378  qi->setColorCount(qi->colorCount()+1);
379  qi->setColor(qi->colorCount(),mycol);
380  return qi->colorCount();
381 }
void setColor(int i, QRgb c)
Sets the color at the given index in the color table, to the given to colorValue. ...
Definition: qimage.cpp:1850
void setColorCount(int)
Resizes the color table to contain colorCount entries.
Definition: qimage.cpp:2275
int colorCount() const
Returns the size of the color table for the image.
Definition: qimage.cpp:1656
QRgb color(int i) const
Returns the color in the color table at index i.
Definition: qimage.cpp:1829

◆ qt_conv16ToRgb()

static QRgb qt_conv16ToRgb ( ushort  c)
inlinestatic

Definition at line 150 of file qpixmap_mac.cpp.

150  {
151  static const int qt_rbits = (565/100);
152  static const int qt_gbits = (565/10%10);
153  static const int qt_bbits = (565%10);
154  static const int qt_red_shift = qt_bbits+qt_gbits-(8-qt_rbits);
155  static const int qt_green_shift = qt_bbits-(8-qt_gbits);
156  static const int qt_neg_blue_shift = 8-qt_bbits;
157  static const int qt_blue_mask = (1<<qt_bbits)-1;
158  static const int qt_green_mask = (1<<(qt_gbits+qt_bbits))-((1<<qt_bbits)-1);
159  static const int qt_red_mask = (1<<(qt_rbits+qt_gbits+qt_bbits))-(1<<(qt_gbits+qt_bbits));
160 
161  const int r=(c & qt_red_mask);
162  const int g=(c & qt_green_mask);
163  const int b=(c & qt_blue_mask);
164  const int tr = r >> qt_red_shift;
165  const int tg = g >> qt_green_shift;
166  const int tb = b << qt_neg_blue_shift;
167 
168  return qRgb(tr,tg,tb);
169 }
unsigned char c[8]
Definition: qnumeric_p.h:62
static const int qt_bbits
Definition: qscreen_qws.h:73
static const int qt_blue_mask
Definition: qscreen_qws.h:77
static const int qt_red_mask
Definition: qscreen_qws.h:79
static const int qt_gbits
Definition: qscreen_qws.h:72
static const int qt_green_shift
Definition: qscreen_qws.h:75
static const int qt_green_mask
Definition: qscreen_qws.h:78
QRgb qRgb(int r, int g, int b)
Returns the ARGB quadruplet (255, {r}, {g}, {b}).
Definition: qrgb.h:69
static const int qt_rbits
Definition: qscreen_qws.h:71
static const int qt_neg_blue_shift
Definition: qscreen_qws.h:76
static const int qt_red_shift
Definition: qscreen_qws.h:74

◆ qt_get_bitflip_array()

const uchar* qt_get_bitflip_array ( )

Definition at line 765 of file qimage.cpp.

766 {
767  return bitflip;
768 }
static const uchar bitflip[256]
Definition: qimage.cpp:736

◆ qt_mac_cg_context()

CGContextRef qt_mac_cg_context ( const QPaintDevice pdev)

Returns the CoreGraphics CGContextRef of the paint device.

Warning
This function is not part of the public interface.

0 is returned if it can't be obtained. It is the caller's responsiblity to CGContextRelease the context when finished using it.

Warning
This function is only available on Mac OS X.

Definition at line 118 of file qpaintdevice_mac.cpp.

Referenced by QMacCGContext::QMacCGContext(), qt_mac_convert_iconref(), and QMacWindowSurface::scroll().

119 {
120  if (pdev->devType() == QInternal::Pixmap) {
121  const QPixmap *pm = static_cast<const QPixmap*>(pdev);
123  uint flags = kCGImageAlphaPremultipliedFirst;
124 #ifdef kCGBitmapByteOrder32Host //only needed because CGImage.h added symbols in the minor version
125  flags |= kCGBitmapByteOrder32Host;
126 #endif
127  CGContextRef ret = 0;
128 
129  // It would make sense to put this into a mac #ifdef'ed
130  // virtual function in the QPixmapData at some point
131  if (pm->data->classId() == QPixmapData::MacClass) {
132  const QMacPixmapData *pmData = static_cast<const QMacPixmapData*>(pm->data.data());
133  ret = CGBitmapContextCreate(pmData->pixels, pmData->w, pmData->h,
134  8, pmData->bytesPerRow, colorspace,
135  flags);
136  if(!ret)
137  qWarning("QPaintDevice: Unable to create context for pixmap (%d/%d/%d)",
138  pmData->w, pmData->h, (pmData->bytesPerRow * pmData->h));
139  } else if (pm->data->classId() == QPixmapData::RasterClass) {
140  QImage *image = pm->data->buffer();
141  ret = CGBitmapContextCreate(image->bits(), image->width(), image->height(),
142  8, image->bytesPerLine(), colorspace, flags);
143  }
144 
145  CGContextTranslateCTM(ret, 0, pm->height());
146  CGContextScaleCTM(ret, 1, -1);
147  return ret;
148  } else if (pdev->devType() == QInternal::Widget) {
149  CGContextRef ret = static_cast<CGContextRef>(static_cast<const QWidget *>(pdev)->macCGHandle());
150  CGContextRetain(ret);
151  return ret;
152  } else if (pdev->devType() == QInternal::MacQuartz) {
153  return static_cast<const QMacQuartzPaintDevice *>(pdev)->cgContext();
154  }
155  return 0;
156 }
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
CGColorSpaceRef qt_mac_colorSpaceForDeviceType(const QPaintDevice *pdev)
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
virtual int devType() const
Definition: qpaintdevice.h:167
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
unsigned int uint
Definition: qglobal.h:996
ClassId classId() const
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
struct CGColorSpace * CGColorSpaceRef
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
virtual QImage * buffer()
int height() const
Returns the height of the pixmap.
Definition: qpixmap.cpp:645
struct CGContext * CGContextRef
quint32 * pixels

◆ qt_mac_cgimage_data_free()

void qt_mac_cgimage_data_free ( void *  info,
const void *  memoryToFree,
size_t   
)

Definition at line 91 of file qpixmap_mac.cpp.

92 {
93  QMacPixmapData *pmdata = static_cast<QMacPixmapData *>(info);
94  if (!pmdata) {
95  free(const_cast<void *>(memoryToFree));
96  } else {
97  if (QMacPixmapData::validDataPointers.contains(pmdata) == false) {
98  free(const_cast<void *>(memoryToFree));
99  // mark data as freed
100  if (pmdata->pixels == memoryToFree)
101  pmdata->pixels = 0;
102  if (pmdata->pixelsToFree == memoryToFree)
103  pmdata->pixelsToFree = 0;
104  return;
105  }
106  if (pmdata->pixels == pmdata->pixelsToFree) {
107  // something we aren't expecting, just free it.
108  Q_ASSERT(memoryToFree != pmdata->pixelsToFree);
109  free(const_cast<void *>(memoryToFree));
110  } else {
111  free(pmdata->pixelsToFree);
112  pmdata->pixelsToFree = static_cast<quint32 *>(const_cast<void *>(memoryToFree));
113  }
114  pmdata->cg_dataBeingReleased = 0;
115  }
116 }
static mach_timebase_info_data_t info
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
unsigned int quint32
Definition: qglobal.h:938
quint32 * pixelsToFree
quint32 * pixels
static QSet< QMacPixmapData * > validDataPointers
CGImageRef cg_dataBeingReleased

◆ qt_mac_convert_mac_region()

QRegion qt_mac_convert_mac_region ( RgnHandle  rgn)

◆ qt_mac_create_iconref()

IconRef qt_mac_create_iconref ( const QPixmap px)

Definition at line 1109 of file qpixmap_mac.cpp.

Referenced by QWidgetPrivate::setWindowIcon_sys(), and QMenuPrivate::QMacMenuPrivate::syncAction().

1110 {
1111  if (px.isNull())
1112  return 0;
1113 
1114  //create icon
1115  IconFamilyHandle iconFamily = reinterpret_cast<IconFamilyHandle>(NewHandle(0));
1116  //create data
1117  {
1118  struct {
1119  OSType mac_type;
1120  int width, height, depth;
1121  bool mask;
1122  } images[] = {
1123  { kThumbnail32BitData, 128, 128, 32, false },
1124  { kThumbnail8BitMask, 128, 128, 8, true },
1125  { 0, 0, 0, 0, false } //end marker
1126  };
1127  for(int i = 0; images[i].mac_type; i++) {
1128  //get QPixmap data
1129  QImage scaled_px = px.toImage().scaled(images[i].width, images[i].height);
1130 
1131  quint32 *sptr = (quint32 *) scaled_px.bits();
1132  quint32 *srow;
1133  uint sbpr = scaled_px.bytesPerLine();
1134 
1135  //get Handle data
1136  const int dbpr = images[i].width * (images[i].depth/8);
1137  Handle hdl = NewHandle(dbpr*images[i].height);
1138  if(!sptr) { //handle null pixmap
1139  memset((*hdl), '\0', dbpr*images[i].height);
1140  } else if(images[i].mask) {
1141  if(images[i].mac_type == kThumbnail8BitMask) {
1142  for(int y = 0, hindex = 0; y < images[i].height; ++y) {
1143  srow = sptr + (y * (sbpr/4));
1144  for(int x = 0; x < images[i].width; ++x)
1145  *((*hdl)+(hindex++)) = qAlpha(*(srow+x));
1146  }
1147  }
1148  } else {
1149  char *dest = (*hdl);
1150 #if defined(__i386__)
1151  if(images[i].depth == 32) {
1152  for(int y = 0; y < images[i].height; ++y) {
1153  uint *source = (uint*)((const uchar*)sptr+(sbpr*y));
1154  for(int x = 0; x < images[i].width; ++x, dest += 4)
1155  *((uint*)dest) = CFSwapInt32(*(source + x));
1156  }
1157  } else
1158 #endif
1159  {
1160  for(int y = 0; y < images[i].height; ++y)
1161  memcpy(dest+(y*dbpr), ((const uchar*)sptr+(sbpr*y)), dbpr);
1162  }
1163  }
1164 
1165  //set the family data to the Handle
1166  OSStatus set = SetIconFamilyData(iconFamily, images[i].mac_type, hdl);
1167  if(set != noErr)
1168  qWarning("%s: %d -- Unable to create icon data[%d]!! %ld",
1169  __FILE__, __LINE__, i, long(set));
1170  DisposeHandle(hdl);
1171  }
1172  }
1173 
1174  //acquire and cleanup
1175  IconRef ret;
1176  static int counter = 0;
1177  const OSType kQtCreator = 'CUTE';
1178  RegisterIconRefFromIconFamily(kQtCreator, (OSType)counter, iconFamily, &ret);
1179  AcquireIconRef(ret);
1180  UnregisterIconRef(kQtCreator, (OSType)counter);
1181  DisposeHandle(reinterpret_cast<Handle>(iconFamily));
1182  counter++;
1183  return ret;
1184 
1185 }
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542
Q_GUI_EXPORT_INLINE int qAlpha(QRgb rgb)
Definition: qrgb.h:66
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
unsigned char uchar
Definition: qglobal.h:994
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
unsigned int uint
Definition: qglobal.h:996
signed long OSStatus
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
unsigned int quint32
Definition: qglobal.h:938
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
QImage scaled(int w, int h, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const
Definition: qimage.h:232
struct OpaqueIconRef * IconRef

◆ qt_mac_create_imagemask()

CGImageRef qt_mac_create_imagemask ( const QPixmap pixmap,
const QRectF sr 
)

Definition at line 1077 of file qpixmap_mac.cpp.

Referenced by QCoreGraphicsPaintEngine::drawPixmap(), and qt_mac_draw_pattern().

1078 {
1079  QMacPixmapData *px = static_cast<QMacPixmapData*>(pixmap.data.data());
1080  if (px->cg_mask) {
1081  if (px->cg_mask_rect == sr) {
1082  CGImageRetain(px->cg_mask); //reference for the caller
1083  return px->cg_mask;
1084  }
1085  CGImageRelease(px->cg_mask);
1086  px->cg_mask = 0;
1087  }
1088 
1089  const int sx = qRound(sr.x()), sy = qRound(sr.y()), sw = qRound(sr.width()), sh = qRound(sr.height());
1090  const int sbpr = px->bytesPerRow;
1091  const uint nbytes = sw * sh;
1092  // alpha is always 255 for bitmaps, ignore it in this case.
1093  const quint32 mask = px->depth() == 1 ? 0x00ffffff : 0xffffffff;
1094  quint8 *dptr = static_cast<quint8 *>(malloc(nbytes));
1095  quint32 *sptr = px->pixels, *srow;
1096  for(int y = sy, offset=0; y < sh; ++y) {
1097  srow = sptr + (y * (sbpr / 4));
1098  for(int x = sx; x < sw; ++x)
1099  *(dptr+(offset++)) = (*(srow+x) & mask) ? 255 : 0;
1100  }
1101  QCFType<CGDataProviderRef> provider = CGDataProviderCreateWithData(0, dptr, nbytes, qt_mac_cgimage_data_free);
1102  px->cg_mask = CGImageMaskCreate(sw, sh, 8, 8, nbytes / sh, provider, 0, 0);
1103  px->cg_mask_rect = sr;
1104  CGImageRetain(px->cg_mask); //reference for the caller
1105  return px->cg_mask;
1106 }
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
unsigned char quint8
Definition: qglobal.h:934
CGImageRef cg_mask
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
unsigned int uint
Definition: qglobal.h:996
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
int depth() const
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
void qt_mac_cgimage_data_free(void *info, const void *memoryToFree, size_t)
Definition: qpixmap_mac.cpp:91
unsigned int quint32
Definition: qglobal.h:938
quint32 * pixels
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ qt_mac_dispose_rgn()

void qt_mac_dispose_rgn ( RgnHandle  r)

◆ qt_mac_flipPixmap()

static void qt_mac_flipPixmap ( void *  data,
int  rowBytes,
int  height 
)
static

Definition at line 805 of file qpixmap_mac.cpp.

Referenced by qt_mac_grabScreenRect().

806 {
807  int bottom = height - 1;
808  void *base = data;
809  void *buffer = malloc(rowBytes);
810 
811  int top = 0;
812  while ( top < bottom )
813  {
814  void *topP = (void *)((top * rowBytes) + (intptr_t)base);
815  void *bottomP = (void *)((bottom * rowBytes) + (intptr_t)base);
816 
817  bcopy( topP, buffer, rowBytes );
818  bcopy( bottomP, topP, rowBytes );
819  bcopy( buffer, bottomP, rowBytes );
820 
821  ++top;
822  --bottom;
823  }
824  free(buffer);
825 }
static const uint base
Definition: qurl.cpp:268
static const char * data(const QByteArray &arr)
INT_PTR intptr_t

◆ qt_mac_get_rgn()

RgnHandle qt_mac_get_rgn ( )

◆ qt_mac_grabDisplayRect()

static void qt_mac_grabDisplayRect ( CGDirectDisplayID  display,
const QRect displayRect,
void *  buffer 
)
static

Definition at line 828 of file qpixmap_mac.cpp.

Referenced by qt_mac_grabScreenRect().

829 {
830  if (display == kCGNullDirectDisplay)
831  return;
832 
833  CGLPixelFormatAttribute attribs[] = {
834  kCGLPFAFullScreen,
835  kCGLPFADisplayMask,
836  (CGLPixelFormatAttribute)0, /* Display mask bit goes here */
837  (CGLPixelFormatAttribute)0
838  };
839 
840  attribs[2] = (CGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(display);
841 
842  // Build a full-screen GL context
843  CGLPixelFormatObj pixelFormatObj;
844  long numPixelFormats;
845 
846  ptrCGLChoosePixelFormat( attribs, &pixelFormatObj, &numPixelFormats );
847 
848  if (!pixelFormatObj) // No full screen context support
849  return;
850 
851  CGLContextObj glContextObj;
852  ptrCGLCreateContext(pixelFormatObj, 0, &glContextObj);
853  ptrCGLDestroyPixelFormat(pixelFormatObj) ;
854  if (!glContextObj)
855  return;
856 
857  ptrCGLSetCurrentContext(glContextObj);
858  ptrCGLSetFullScreen(glContextObj) ;
859 
861 
862  ptrglFinish(); // Finish all OpenGL commands
863  ptrglPixelStorei(GL_PACK_ALIGNMENT, 4); // Force 4-byte alignment
864  ptrglPixelStorei(GL_PACK_ROW_LENGTH, 0);
865  ptrglPixelStorei(GL_PACK_SKIP_ROWS, 0);
866  ptrglPixelStorei(GL_PACK_SKIP_PIXELS, 0);
867 
868  // Fetch the data in XRGB format, matching the bitmap context.
869  ptrglReadPixels(GLint(displayRect.x()), GLint(displayRect.y()),
870  GLint(displayRect.width()), GLint(displayRect.height()),
871 #ifdef __BIG_ENDIAN__
873 #else
874  GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, buffer
875 #endif
876  );
877 
879  ptrCGLClearDrawable(glContextObj); // disassociate from full screen
880  ptrCGLDestroyContext(glContextObj); // and destroy the context
881 }
#define GL_BGRA
Definition: glfunctions.h:63
static PtrglReadPixels ptrglReadPixels
static PtrglFinish ptrglFinish
static PtrCGLDestroyContext ptrCGLDestroyContext
static PtrCGLSetFullScreen ptrCGLSetFullScreen
static PtrCGLClearDrawable ptrCGLClearDrawable
#define GL_UNSIGNED_INT_8_8_8_8_REV
static PtrglPixelStorei ptrglPixelStorei
#define GL_PACK_ALIGNMENT
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
static PtrCGLSetCurrentContext ptrCGLSetCurrentContext
#define GL_FRONT
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
static PtrCGLCreateContext ptrCGLCreateContext
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
typedef GLint
Definition: glfunctions.h:67
static PtrCGLChoosePixelFormat ptrCGLChoosePixelFormat
static PtrCGLDestroyPixelFormat ptrCGLDestroyPixelFormat
static PtrglReadBuffer ptrglReadBuffer

◆ qt_mac_grabScreenRect()

static QPixmap qt_mac_grabScreenRect ( const QRect rect)
static

Definition at line 913 of file qpixmap_mac.cpp.

Referenced by QPixmap::grabWindow().

914 {
915  if (!resolveOpenGLSymbols())
916  return QPixmap();
917 
918  const int maxDisplays = 128; // 128 displays should be enough for everyone.
919  CGDirectDisplayID displays[maxDisplays];
920  CGDisplayCount displayCount;
921  const CGRect cgRect = CGRectMake(rect.x(), rect.y(), rect.width(), rect.height());
922  const CGDisplayErr err = CGGetDisplaysWithRect(cgRect, maxDisplays, displays, &displayCount);
923 
924  if (err && displayCount == 0)
925  return QPixmap();
926 
927  long bytewidth = rect.width() * 4; // Assume 4 bytes/pixel for now
928  bytewidth = (bytewidth + 3) & ~3; // Align to 4 bytes
929  QVarLengthArray<char> buffer(rect.height() * bytewidth);
930 
931  for (uint i = 0; i < displayCount; ++i) {
932  const CGRect bounds = CGDisplayBounds(displays[i]);
933  // Translate to display-local coordinates
934  QRect displayRect = rect.translated(qRound(-bounds.origin.x), qRound(-bounds.origin.y));
935  // Adjust for inverted y axis.
936  displayRect.moveTop(qRound(bounds.size.height) - displayRect.y() - rect.height());
937  qt_mac_grabDisplayRect(displays[i], displayRect, buffer.data());
938  }
939 
940  qt_mac_flipPixmap(buffer.data(), bytewidth, rect.height());
941  QCFType<CGContextRef> bitmap = CGBitmapContextCreate(buffer.data(), rect.width(),
942  rect.height(), 8, bytewidth,
944  kCGImageAlphaNoneSkipFirst);
945  QCFType<CGImageRef> image = CGBitmapContextCreateImage(bitmap);
946  return QPixmap::fromMacCGImageRef(image);
947 }
static CGColorSpaceRef macGenericColorSpace()
static void qt_mac_grabDisplayRect(CGDirectDisplayID display, const QRect &displayRect, void *buffer)
QRect translated(int dx, int dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:328
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
static QPixmap fromMacCGImageRef(CGImageRef image)
Returns a QPixmap that is equivalent to the given image.
unsigned int uint
Definition: qglobal.h:996
struct CGRect CGRect
static void qt_mac_flipPixmap(void *data, int rowBytes, int height)
static bool resolveOpenGLSymbols()
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
void moveTop(int pos)
Moves the rectangle vertically, leaving the rectangle&#39;s top edge at the given y coordinate.
Definition: qrect.h:353
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ qt_mac_grabScreenRect_10_3()

static QPixmap qt_mac_grabScreenRect_10_3 ( int  x,
int  y,
int  w,
int  h,
QWidget widget 
)
static

Definition at line 950 of file qpixmap_mac.cpp.

Referenced by QPixmap::grabWindow().

951 {
952  QPixmap pm = QPixmap(w, h);
953  extern WindowPtr qt_mac_window_for(const QWidget *); // qwidget_mac.cpp
954  const BitMap *windowPort = 0;
955  if((widget->windowType() == Qt::Desktop)) {
956  GDHandle gdh;
957  if(!(gdh=GetMainDevice()))
958  qDebug("Qt: internal: Unexpected condition reached: %s:%d", __FILE__, __LINE__);
959  windowPort = (BitMap*)(*(*gdh)->gdPMap);
960  } else {
961  windowPort = GetPortBitMapForCopyBits(GetWindowPort(qt_mac_window_for(widget)));
962  }
963  const BitMap *pixmapPort = GetPortBitMapForCopyBits(static_cast<GWorldPtr>(pm.macQDHandle()));
964  Rect macSrcRect, macDstRect;
965  SetRect(&macSrcRect, x, y, x + w, y + h);
966  SetRect(&macDstRect, 0, 0, w, h);
967  CopyBits(windowPort, pixmapPort, &macSrcRect, &macDstRect, srcCopy, 0);
968  return pm;
969 }
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
OSWindowRef qt_mac_window_for(const QWidget *)
Definition: qwidget_mac.mm:484
Q_CORE_EXPORT void qDebug(const char *,...)
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
Qt::WindowType windowType() const
Returns the window type of this widget.
Definition: qwidget.h:937
GDPtr * GDHandle

◆ qt_mac_image_to_cgimage()

CGImageRef qt_mac_image_to_cgimage ( const QImage image)

Definition at line 118 of file qpixmap_mac.cpp.

Referenced by QPixmap::grabWindow().

119 {
120  int bitsPerColor = 8;
121  int bitsPerPixel = 32;
122  if (image.depth() == 1) {
123  bitsPerColor = 1;
124  bitsPerPixel = 1;
125  }
126  QCFType<CGDataProviderRef> provider =
127  CGDataProviderCreateWithData(0, image.bits(), image.bytesPerLine() * image.height(),
128  0);
129 
130  uint cgflags = kCGImageAlphaPremultipliedFirst;
131 #ifdef kCGBitmapByteOrder32Host //only needed because CGImage.h added symbols in the minor version
132  cgflags |= kCGBitmapByteOrder32Host;
133 #endif
134 
135  CGImageRef cgImage = CGImageCreate(image.width(), image.height(), bitsPerColor, bitsPerPixel,
136  image.bytesPerLine(),
138  cgflags, provider,
139  0,
140  0,
141  kCGRenderingIntentDefault);
142 
143  return cgImage;
144 }
static CGColorSpaceRef macGenericColorSpace()
struct CGImage * CGImageRef
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
unsigned int uint
Definition: qglobal.h:996
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572

◆ qt_mac_pixmap_get_base()

Q_GUI_EXPORT quint32* qt_mac_pixmap_get_base ( const QPixmap pix)

Definition at line 75 of file qpixmap_mac.cpp.

Referenced by QGLContext::updatePaintDevice().

76 {
78  return reinterpret_cast<quint32 *>(static_cast<QRasterPixmapData*>(pix->data.data())->buffer()->bits());
79  else
80  return static_cast<QMacPixmapData*>(pix->data.data())->pixels;
81 }
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
static QString graphics_system_name
unsigned int quint32
Definition: qglobal.h:938

◆ qt_mac_pixmap_get_bytes_per_line()

Q_GUI_EXPORT int qt_mac_pixmap_get_bytes_per_line ( const QPixmap pix)

Definition at line 83 of file qpixmap_mac.cpp.

Referenced by QGLContext::updatePaintDevice().

84 {
86  return static_cast<QRasterPixmapData*>(pix->data.data())->buffer()->bytesPerLine();
87  else
88  return static_cast<QMacPixmapData*>(pix->data.data())->bytesPerRow;
89 }
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
static QString graphics_system_name

◆ resolveOpenGLSymbols()

static bool resolveOpenGLSymbols ( )
static

Definition at line 780 of file qpixmap_mac.cpp.

Referenced by qt_mac_grabScreenRect().

781 {
782  static bool triedResolve = false;
783  if (!triedResolve) {
784  QLibrary library(QLatin1String("/System/Library/Frameworks/OpenGL.framework/OpenGL"));
785  ptrCGLChoosePixelFormat = (PtrCGLChoosePixelFormat)(library.resolve("CGLChoosePixelFormat"));
786  ptrCGLClearDrawable = (PtrCGLClearDrawable)(library.resolve("CGLClearDrawable"));
787  ptrCGLCreateContext = (PtrCGLCreateContext)(library.resolve("CGLCreateContext"));
788  ptrCGLDestroyContext = (PtrCGLDestroyContext)(library.resolve("CGLDestroyContext"));
789  ptrCGLDestroyPixelFormat = (PtrCGLDestroyPixelFormat)(library.resolve("CGLDestroyPixelFormat"));
790  ptrCGLSetCurrentContext = (PtrCGLSetCurrentContext)(library.resolve("CGLSetCurrentContext"));
791  ptrCGLSetFullScreen = (PtrCGLSetFullScreen)(library.resolve("CGLSetFullScreen"));
792  ptrglFinish = (PtrglFinish)(library.resolve("glFinish"));
793  ptrglPixelStorei = (PtrglPixelStorei)(library.resolve("glPixelStorei"));
794  ptrglReadBuffer = (PtrglReadBuffer)(library.resolve("glReadBuffer"));
795  ptrglReadPixels = (PtrglReadPixels)(library.resolve("glReadPixels"));
796  triedResolve = true;
797  }
802 }
CGLError(* PtrCGLDestroyPixelFormat)(CGLPixelFormatObj)
static PtrglReadPixels ptrglReadPixels
static PtrglFinish ptrglFinish
static PtrCGLDestroyContext ptrCGLDestroyContext
static PtrCGLSetFullScreen ptrCGLSetFullScreen
static PtrCGLClearDrawable ptrCGLClearDrawable
static PtrglPixelStorei ptrglPixelStorei
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void(* PtrglFinish)()
CGLError(* PtrCGLSetCurrentContext)(CGLContextObj)
static PtrCGLSetCurrentContext ptrCGLSetCurrentContext
CGLError(* PtrCGLSetFullScreen)(CGLContextObj)
void(* PtrglReadBuffer)(GLenum)
CGLError(* PtrCGLDestroyContext)(CGLContextObj)
static PtrCGLCreateContext ptrCGLCreateContext
static PtrCGLChoosePixelFormat ptrCGLChoosePixelFormat
static PtrCGLDestroyPixelFormat ptrCGLDestroyPixelFormat
static PtrglReadBuffer ptrglReadBuffer
CGLError(* PtrCGLCreateContext)(CGLPixelFormatObj, CGLContextObj, CGLContextObj *)
CGLError(* PtrCGLClearDrawable)(CGLContextObj)
void(* PtrglPixelStorei)(GLenum, GLint)
The QLibrary class loads shared libraries at runtime.
Definition: qlibrary.h:62
void(* PtrglReadPixels)(GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid *)
CGLError(* PtrCGLChoosePixelFormat)(const CGLPixelFormatAttribute *, CGLPixelFormatObj *, long *)

Variable Documentation

◆ ptrCGLChoosePixelFormat

PtrCGLChoosePixelFormat ptrCGLChoosePixelFormat = 0
static

Definition at line 768 of file qpixmap_mac.cpp.

Referenced by qt_mac_grabDisplayRect(), and resolveOpenGLSymbols().

◆ ptrCGLClearDrawable

PtrCGLClearDrawable ptrCGLClearDrawable = 0
static

Definition at line 769 of file qpixmap_mac.cpp.

Referenced by qt_mac_grabDisplayRect(), and resolveOpenGLSymbols().

◆ ptrCGLCreateContext

PtrCGLCreateContext ptrCGLCreateContext = 0
static

Definition at line 770 of file qpixmap_mac.cpp.

Referenced by qt_mac_grabDisplayRect(), and resolveOpenGLSymbols().

◆ ptrCGLDestroyContext

PtrCGLDestroyContext ptrCGLDestroyContext = 0
static

Definition at line 771 of file qpixmap_mac.cpp.

Referenced by qt_mac_grabDisplayRect(), and resolveOpenGLSymbols().

◆ ptrCGLDestroyPixelFormat

PtrCGLDestroyPixelFormat ptrCGLDestroyPixelFormat = 0
static

Definition at line 772 of file qpixmap_mac.cpp.

Referenced by qt_mac_grabDisplayRect(), and resolveOpenGLSymbols().

◆ ptrCGLSetCurrentContext

PtrCGLSetCurrentContext ptrCGLSetCurrentContext = 0
static

Definition at line 773 of file qpixmap_mac.cpp.

Referenced by qt_mac_grabDisplayRect(), and resolveOpenGLSymbols().

◆ ptrCGLSetFullScreen

PtrCGLSetFullScreen ptrCGLSetFullScreen = 0
static

Definition at line 774 of file qpixmap_mac.cpp.

Referenced by qt_mac_grabDisplayRect(), and resolveOpenGLSymbols().

◆ ptrglFinish

PtrglFinish ptrglFinish = 0
static

Definition at line 775 of file qpixmap_mac.cpp.

Referenced by qt_mac_grabDisplayRect(), and resolveOpenGLSymbols().

◆ ptrglPixelStorei

PtrglPixelStorei ptrglPixelStorei = 0
static

Definition at line 776 of file qpixmap_mac.cpp.

Referenced by qt_mac_grabDisplayRect(), and resolveOpenGLSymbols().

◆ ptrglReadBuffer

PtrglReadBuffer ptrglReadBuffer = 0
static

Definition at line 777 of file qpixmap_mac.cpp.

Referenced by qt_mac_grabDisplayRect(), and resolveOpenGLSymbols().

◆ ptrglReadPixels

PtrglReadPixels ptrglReadPixels = 0
static

Definition at line 778 of file qpixmap_mac.cpp.

Referenced by qt_mac_grabDisplayRect(), and resolveOpenGLSymbols().

◆ qt_pixmap_serial

int qt_pixmap_serial = 0
static

Definition at line 73 of file qpixmap_mac.cpp.

Referenced by QMacPixmapData::fromImage(), and QMacPixmapData::resize().