Qt 4.8
Public Functions | Private Functions | Properties | Friends | List of all members
QGLPixmapData Class Reference

#include <qpixmapdata_gl_p.h>

Inheritance diagram for QGLPixmapData:
QPixmapData QMeeGoLivePixmapData QMeeGoPixmapData

Public Functions

GLuint bind (bool copyBack=true) const
 
void copy (const QPixmapData *data, const QRect &rect)
 
QPixmapDatacreateCompatiblePixmapData () const
 
void fill (const QColor &color)
 
bool fromData (const uchar *buffer, uint len, const char *format, Qt::ImageConversionFlags flags)
 
bool fromFile (const QString &filename, const char *format, Qt::ImageConversionFlags flags)
 
void fromImage (const QImage &image, Qt::ImageConversionFlags flags)
 
void fromImageReader (QImageReader *imageReader, Qt::ImageConversionFlags flags)
 
QGLPaintDeviceglDevice () const
 
bool hasAlphaChannel () const
 
bool isValidContext (const QGLContext *ctx) const
 
int metric (QPaintDevice::PaintDeviceMetric metric) const
 
QPaintEnginepaintEngine () const
 
 QGLPixmapData (PixelType type)
 
void resize (int width, int height)
 
bool scroll (int dx, int dy, const QRect &rect)
 
QGLTexturetexture () const
 
QImage toImage () const
 
 ~QGLPixmapData ()
 
- Public Functions inherited from QPixmapData
virtual QPixmap alphaChannel () const
 
virtual QImagebuffer ()
 
qint64 cacheKey () const
 
ClassId classId () const
 
int colorCount () const
 
int depth () const
 
int height () const
 
bool isNull () const
 
virtual QBitmap mask () const
 
QT_DEPRECATED int numColors () const
 
PixelType pixelType () const
 
 QPixmapData (PixelType pixelType, int classId)
 
virtual QPixmapDataruntimeData () const
 
int serialNumber () const
 
virtual void setAlphaChannel (const QPixmap &alphaChannel)
 
virtual void setMask (const QBitmap &mask)
 
virtual QImage toImage (const QRect &rect) const
 
virtual QPixmap transformed (const QTransform &matrix, Qt::TransformationMode mode) const
 
int width () const
 
virtual ~QPixmapData ()
 

Private Functions

void copyBackFromRenderFbo (bool keepCurrentFboBound) const
 
void createPixmapForImage (QImage &image, Qt::ImageConversionFlags flags, bool inPlace)
 out-of-place conversion (inPlace == false) will always detach() More...
 
void ensureCreated () const
 
QColor fillColor () const
 
QImage fillImage (const QColor &color) const
 
bool isUninitialized () const
 
bool isValid () const
 
bool needsFill () const
 
QGLPixmapDataoperator= (const QGLPixmapData &other)
 
 QGLPixmapData (const QGLPixmapData &other)
 
QSize size () const
 
bool useFramebufferObjects () const
 

Properties

QGLContextm_ctx
 
bool m_dirty
 
QPaintEnginem_engine
 
QColor m_fillColor
 
QGLPixmapGLPaintDevice m_glDevice
 
bool m_hasAlpha
 
bool m_hasFillColor
 
QGLFramebufferObjectm_renderFbo
 
QImage m_source
 
QGLTexture m_texture
 

Friends

class QGLPixmapGLPaintDevice
 
class QMeeGoLivePixmapData
 
class QMeeGoPixmapData
 

Additional Inherited Members

- Public Types inherited from QPixmapData
enum  ClassId {
  RasterClass, X11Class, MacClass, DirectFBClass,
  OpenGLClass, OpenVGClass, RuntimeClass, BlitterClass,
  CustomClass = 1024
}
 
enum  PixelType { PixmapType, BitmapType }
 
- Static Public Functions inherited from QPixmapData
static QPixmapDatacreate (int w, int h, PixelType type)
 
- Protected Functions inherited from QPixmapData
void setSerialNumber (int serNo)
 
- Protected Variables inherited from QPixmapData
int d
 
int h
 
bool is_null
 
int w
 

Detailed Description

Definition at line 109 of file qpixmapdata_gl_p.h.

Constructors and Destructors

◆ QGLPixmapData() [1/2]

QGLPixmapData::QGLPixmapData ( PixelType  type)

Definition at line 254 of file qpixmapdata_gl.cpp.

Referenced by createCompatiblePixmapData().

256  , m_renderFbo(0)
257  , m_engine(0)
258  , m_ctx(0)
259  , m_dirty(false)
260  , m_hasFillColor(false)
261  , m_hasAlpha(false)
262 {
265 }
QGLContext * m_ctx
QGLPixmapGLPaintDevice m_glDevice
QPaintEngine * m_engine
PixelType type
QPixmapData(PixelType pixelType, int classId)
Definition: qpixmapdata.cpp:68
void setPixmapData(QGLPixmapData *)
QGLFramebufferObject * m_renderFbo
void setSerialNumber(int serNo)
static int qt_gl_pixmap_serial

◆ ~QGLPixmapData()

QGLPixmapData::~QGLPixmapData ( )

Definition at line 267 of file qpixmapdata_gl.cpp.

268 {
269  const QGLContext *shareContext = qt_gl_share_context();
270  if (!shareContext)
271  return;
272 
273  delete m_engine;
274 
275  if (m_texture.id) {
276  QGLShareContextScope ctx(shareContext);
277  glDeleteTextures(1, &m_texture.id);
278  }
279 }
QGLTexture m_texture
Q_OPENGL_EXPORT const QGLContext * qt_gl_share_context()
QPaintEngine * m_engine
GLuint id
Definition: qgl_p.h:608
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
#define ctx
Definition: qgl.cpp:6094

◆ QGLPixmapData() [2/2]

QGLPixmapData::QGLPixmapData ( const QGLPixmapData other)
private

Functions

◆ bind()

GLuint QGLPixmapData::bind ( bool  copyBack = true) const

Definition at line 764 of file qpixmapdata_gl.cpp.

765 {
766  if (m_renderFbo && copyBack) {
767  copyBackFromRenderFbo(true);
768  } else {
769  ensureCreated();
770  }
771 
772  GLuint id = m_texture.id;
773  glBindTexture(GL_TEXTURE_2D, id);
774 
775  if (m_hasFillColor) {
776  if (!useFramebufferObjects()) {
779  }
780 
781  m_hasFillColor = false;
782 
786  glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, format, GL_UNSIGNED_BYTE, tx.bits());
787  }
788 
789  return id;
790 }
QGLTexture m_texture
void fill(uint pixel)
Fills the entire image with the given pixelValue.
Definition: qimage.cpp:2032
QRgb qt_gl_convertToGLFormat(QRgb src_pixel, GLenum texture_format)
Definition: qgl.cpp:2281
void copyBackFromRenderFbo(bool keepCurrentFboBound) const
#define GL_TEXTURE_2D
void ensureCreated() const
GLuint id
Definition: qgl_p.h:608
Q_STATIC_INLINE_FUNCTION uint PREMUL(uint x)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
bool useFramebufferObjects() const
unsigned int GLenum
Definition: main.cpp:50
#define GL_UNSIGNED_BYTE
QGLFramebufferObject * m_renderFbo
QRgb rgba() const
Returns the RGB value of the color, including its alpha.
Definition: qcolor.cpp:1019
GLenum qt_gl_preferredTextureFormat()
Definition: qgl_p.h:709

◆ copy()

void QGLPixmapData::copy ( const QPixmapData data,
const QRect rect 
)
virtual

Reimplemented from QPixmapData.

Definition at line 522 of file qpixmapdata_gl.cpp.

523 {
524  if (data->classId() != QPixmapData::OpenGLClass || !static_cast<const QGLPixmapData *>(data)->useFramebufferObjects()) {
525  QPixmapData::copy(data, rect);
526  return;
527  }
528 
529  const QGLPixmapData *other = static_cast<const QGLPixmapData *>(data);
530  if (other->m_renderFbo) {
532 
533  resize(rect.width(), rect.height());
534  m_hasAlpha = other->m_hasAlpha;
535  ensureCreated();
536 
537  if (!ctx->d_ptr->fbo)
538  glGenFramebuffers(1, &ctx->d_ptr->fbo);
539 
543 
544  if (!other->m_renderFbo->isBound())
546 
547  glDisable(GL_SCISSOR_TEST);
548  if (ctx->d_ptr->active_engine && ctx->d_ptr->active_engine->type() == QPaintEngine::OpenGL2)
549  static_cast<QGL2PaintEngineEx *>(ctx->d_ptr->active_engine)->invalidateState();
550 
551  glBlitFramebufferEXT(rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height(),
552  0, 0, w, h,
554  GL_NEAREST);
555 
556  glBindFramebuffer(GL_FRAMEBUFFER_EXT, ctx->d_ptr->current_fbo);
557  } else {
558  QPixmapData::copy(data, rect);
559  }
560 }
QGLTexture m_texture
Q_OPENGL_EXPORT const QGLContext * qt_gl_share_context()
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
#define GL_FRAMEBUFFER_EXT
#define glBindFramebuffer
#define GL_TEXTURE_2D
#define GL_COLOR_ATTACHMENT0_EXT
#define GL_SCISSOR_TEST
#define glBlitFramebufferEXT
void ensureCreated() const
GLuint id
Definition: qgl_p.h:608
void resize(int width, int height)
#define glGenFramebuffers
#define GL_COLOR_BUFFER_BIT
static const char * data(const QByteArray &arr)
ClassId classId() const
bool useFramebufferObjects() const
GLuint handle() const
Returns the GL framebuffer object handle for this framebuffer object (returned by the glGenFrameBuffe...
#define GL_DRAW_FRAMEBUFFER_EXT
#define GL_READ_FRAMEBUFFER_EXT
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
#define ctx
Definition: qgl.cpp:6094
virtual void copy(const QPixmapData *data, const QRect &rect)
QGLFramebufferObject * m_renderFbo
bool isBound() const
Returns true if the framebuffer object is currently bound to a context, otherwise false is returned...
#define glFramebufferTexture2D
#define GL_NEAREST

◆ copyBackFromRenderFbo()

void QGLPixmapData::copyBackFromRenderFbo ( bool  keepCurrentFboBound) const
private

Definition at line 668 of file qpixmapdata_gl.cpp.

Referenced by bind(), and toImage().

669 {
670  if (!isValid())
671  return;
672 
673  m_hasFillColor = false;
674 
675  const QGLContext *share_ctx = qt_gl_share_context();
676  QGLShareContextScope ctx(share_ctx);
677 
678  ensureCreated();
679 
680  if (!ctx->d_ptr->fbo)
681  glGenFramebuffers(1, &ctx->d_ptr->fbo);
682 
686 
687  const int x0 = 0;
688  const int x1 = w;
689  const int y0 = 0;
690  const int y1 = h;
691 
692  if (!m_renderFbo->isBound())
694 
695  glDisable(GL_SCISSOR_TEST);
696 
697  glBlitFramebufferEXT(x0, y0, x1, y1,
698  x0, y0, x1, y1,
700  GL_NEAREST);
701 
702  if (keepCurrentFboBound) {
703  glBindFramebuffer(GL_FRAMEBUFFER_EXT, ctx->d_ptr->current_fbo);
704  } else {
706  ctx->d_ptr->current_fbo = m_renderFbo->handle();
707  }
708 }
QGLTexture m_texture
Q_OPENGL_EXPORT const QGLContext * qt_gl_share_context()
#define GL_FRAMEBUFFER_EXT
#define glBindFramebuffer
#define GL_TEXTURE_2D
#define GL_COLOR_ATTACHMENT0_EXT
#define GL_SCISSOR_TEST
#define glBlitFramebufferEXT
void ensureCreated() const
GLuint id
Definition: qgl_p.h:608
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
bool isValid() const
#define glGenFramebuffers
#define GL_COLOR_BUFFER_BIT
GLuint handle() const
Returns the GL framebuffer object handle for this framebuffer object (returned by the glGenFrameBuffe...
#define GL_DRAW_FRAMEBUFFER_EXT
#define GL_READ_FRAMEBUFFER_EXT
#define ctx
Definition: qgl.cpp:6094
QGLFramebufferObject * m_renderFbo
bool isBound() const
Returns true if the framebuffer object is currently bound to a context, otherwise false is returned...
#define glFramebufferTexture2D
#define GL_NEAREST

◆ createCompatiblePixmapData()

QPixmapData * QGLPixmapData::createCompatiblePixmapData ( ) const
virtual

Reimplemented from QPixmapData.

Reimplemented in QMeeGoLivePixmapData, and QMeeGoPixmapData.

Definition at line 281 of file qpixmapdata_gl.cpp.

282 {
283  return new QGLPixmapData(pixelType());
284 }
PixelType pixelType() const
QGLPixmapData(PixelType type)

◆ createPixmapForImage()

void QGLPixmapData::createPixmapForImage ( QImage image,
Qt::ImageConversionFlags  flags,
bool  inPlace 
)
private

out-of-place conversion (inPlace == false) will always detach()

Definition at line 467 of file qpixmapdata_gl.cpp.

Referenced by fromData(), fromFile(), fromImage(), and fromImageReader().

468 {
469  if (image.size() == QSize(w, h))
471 
472  resize(image.width(), image.height());
473 
474  if (pixelType() == BitmapType) {
476 
477  } else {
479  if (qApp->desktop()->depth() == 16)
480  format = QImage::Format_RGB16;
481 
482  if (image.hasAlphaChannel()
483  && ((flags & Qt::NoOpaqueDetection)
484  || const_cast<QImage &>(image).data_ptr()->checkForAlphaPixels()))
486 
487  if (inPlace && image.data_ptr()->convertInPlace(format, flags)) {
488  m_source = image;
489  } else {
490  m_source = image.convertToFormat(format);
491 
492  // convertToFormat won't detach the image if format stays the same.
493  if (image.format() == format)
494  m_source.detach();
495  }
496  }
497 
498  m_dirty = true;
499  m_hasFillColor = false;
500 
502  w = image.width();
503  h = image.height();
504  is_null = (w <= 0 || h <= 0);
505  d = m_source.depth();
506 
507  if (m_texture.id) {
509  glDeleteTextures(1, &m_texture.id);
510  m_texture.id = 0;
511  }
512 }
QGLTexture m_texture
Q_OPENGL_EXPORT const QGLContext * qt_gl_share_context()
Format
The following image formats are available in Qt.
Definition: qimage.h:91
bool hasAlphaChannel() const
Returns true if the image has a format that respects the alpha channel, otherwise returns false...
Definition: qimage.cpp:6495
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
PixelType pixelType() const
GLuint id
Definition: qgl_p.h:608
#define qApp
void resize(int width, int height)
void detach()
If multiple images share common data, this image makes a copy of the data and detaches itself from th...
Definition: qimage.cpp:1359
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
DataPtr & data_ptr()
Definition: qimage.h:346
QSize size() const
Returns the size of the image, i.
Definition: qimage.cpp:1587
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
#define ctx
Definition: qgl.cpp:6094
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
bool convertInPlace(QImage::Format newFormat, Qt::ImageConversionFlags)
Definition: qimage.cpp:6935
void setSerialNumber(int serNo)
static int qt_gl_pixmap_serial

◆ ensureCreated()

void QGLPixmapData::ensureCreated ( ) const
private

Definition at line 326 of file qpixmapdata_gl.cpp.

Referenced by bind(), copy(), copyBackFromRenderFbo(), toImage(), and QMeeGoPixmapData::updateFromSoftImage().

327 {
328  if (!m_dirty)
329  return;
330 
331  m_dirty = false;
332 
334  m_ctx = ctx;
335 
336  const GLenum internal_format = m_hasAlpha ? GL_RGBA : GL_RGB;
337 #ifdef QT_OPENGL_ES_2
338  const GLenum external_format = internal_format;
339 #else
340  const GLenum external_format = qt_gl_preferredTextureFormat();
341 #endif
342  const GLenum target = GL_TEXTURE_2D;
343 
344  if (!m_texture.id) {
345  glGenTextures(1, &m_texture.id);
346  glBindTexture(target, m_texture.id);
347  glTexImage2D(target, 0, internal_format, w, h, 0, external_format, GL_UNSIGNED_BYTE, 0);
350  }
351 
352  if (!m_source.isNull()) {
353  if (external_format == GL_RGB) {
355 
356  glBindTexture(target, m_texture.id);
357  glTexSubImage2D(target, 0, 0, 0, w, h, external_format,
358  GL_UNSIGNED_BYTE, tx.bits());
359  } else {
360  const QImage tx = ctx->d_func()->convertToGLFormat(m_source, true, external_format);
361 
362  glBindTexture(target, m_texture.id);
363  glTexSubImage2D(target, 0, 0, 0, w, h, external_format,
364  GL_UNSIGNED_BYTE, tx.bits());
365  }
366 
367  if (useFramebufferObjects())
368  m_source = QImage();
369  }
370 
371  m_texture.options &= ~QGLContext::MemoryManagedBindOption;
372 }
QGLTexture m_texture
QGLContext * m_ctx
Q_OPENGL_EXPORT const QGLContext * qt_gl_share_context()
#define GL_RGB
#define GL_TEXTURE_MIN_FILTER
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
QGLContext::BindOptions options
Definition: qgl_p.h:611
#define GL_TEXTURE_2D
GLuint id
Definition: qgl_p.h:608
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
bool useFramebufferObjects() const
QImage mirrored(bool horizontally=false, bool vertically=true) const
Returns a mirror of the image, mirrored in the horizontal and/or the vertical direction depending on ...
Definition: qimage.cpp:4922
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
unsigned int GLenum
Definition: main.cpp:50
#define GL_UNSIGNED_BYTE
#define ctx
Definition: qgl.cpp:6094
#define GL_RGBA
#define GL_TEXTURE_MAG_FILTER
GLenum qt_gl_preferredTextureFormat()
Definition: qgl_p.h:709
#define GL_NEAREST

◆ fill()

void QGLPixmapData::fill ( const QColor color)
virtual

Implements QPixmapData.

Definition at line 562 of file qpixmapdata_gl.cpp.

563 {
564  if (!isValid())
565  return;
566 
567  bool hasAlpha = color.alpha() != 255;
568  if (hasAlpha && !m_hasAlpha) {
569  if (m_texture.id) {
570  glDeleteTextures(1, &m_texture.id);
571  m_texture.id = 0;
572  m_dirty = true;
573  }
574  m_hasAlpha = color.alpha() != 255;
575  }
576 
577  if (useFramebufferObjects()) {
578  m_source = QImage();
579  m_hasFillColor = true;
580  m_fillColor = color;
581  } else {
582 
583  if (m_source.isNull()) {
584  m_fillColor = color;
585  m_hasFillColor = true;
586 
587  } else if (m_source.depth() == 32) {
588  m_source.fill(PREMUL(color.rgba()));
589 
590  } else if (m_source.depth() == 1) {
591  if (color == Qt::color1)
592  m_source.fill(1);
593  else
594  m_source.fill(0);
595  }
596  }
597 }
QGLTexture m_texture
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
void fill(uint pixel)
Fills the entire image with the given pixelValue.
Definition: qimage.cpp:2032
GLuint id
Definition: qgl_p.h:608
bool isValid() const
Q_STATIC_INLINE_FUNCTION uint PREMUL(uint x)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
bool useFramebufferObjects() const
ushort alpha
Returns the alpha color component of this color.
Definition: qcolor.h:242
QRgb rgba() const
Returns the RGB value of the color, including its alpha.
Definition: qcolor.cpp:1019

◆ fillColor()

QColor QGLPixmapData::fillColor ( ) const
inlineprivate

Definition at line 175 of file qpixmapdata_gl_p.h.

175 { return m_fillColor; }

◆ fillImage()

QImage QGLPixmapData::fillImage ( const QColor color) const
private

Definition at line 604 of file qpixmapdata_gl.cpp.

Referenced by toImage().

605 {
606  QImage img;
607  if (pixelType() == BitmapType) {
608  img = QImage(w, h, QImage::Format_MonoLSB);
609 
610  img.setColorCount(2);
611  img.setColor(0, QColor(Qt::color0).rgba());
612  img.setColor(1, QColor(Qt::color1).rgba());
613 
614  if (color == Qt::color1)
615  img.fill(1);
616  else
617  img.fill(0);
618  } else {
619  img = QImage(w, h,
620  m_hasAlpha
623  img.fill(PREMUL(color.rgba()));
624  }
625  return img;
626 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
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 fill(uint pixel)
Fills the entire image with the given pixelValue.
Definition: qimage.cpp:2032
PixelType pixelType() const
void setColorCount(int)
Resizes the color table to contain colorCount entries.
Definition: qimage.cpp:2275
Q_STATIC_INLINE_FUNCTION uint PREMUL(uint x)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QRgb rgba() const
Returns the RGB value of the color, including its alpha.
Definition: qcolor.cpp:1019

◆ fromData()

bool QGLPixmapData::fromData ( const uchar buffer,
uint  len,
const char *  format,
Qt::ImageConversionFlags  flags 
)
virtual

Reimplemented from QPixmapData.

Definition at line 431 of file qpixmapdata_gl.cpp.

433 {
434  bool alpha;
435  const char *buf = reinterpret_cast<const char *>(buffer);
436  if (m_texture.canBindCompressedTexture(buf, int(len), format, &alpha)) {
437  resize(0, 0);
439  QSize size = m_texture.bindCompressedTexture(buf, int(len), format);
440  if (!size.isEmpty()) {
441  w = size.width();
442  h = size.height();
443  is_null = false;
444  d = 32;
445  m_hasAlpha = alpha;
446  m_source = QImage();
447  m_dirty = isValid();
448  return true;
449  }
450  }
451 
452  QByteArray a = QByteArray::fromRawData(reinterpret_cast<const char *>(buffer), len);
453  QBuffer b(&a);
454  b.open(QIODevice::ReadOnly);
455  QImage image = QImageReader(&b, format).read();
456  if (image.isNull())
457  return false;
458 
459  createPixmapForImage(image, flags, true);
460 
461  return !isNull();
462 }
QGLTexture m_texture
Q_OPENGL_EXPORT const QGLContext * qt_gl_share_context()
bool canBindCompressedTexture(const char *buf, int len, const char *format, bool *hasAlpha)
Definition: qgl.cpp:6057
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
long ASN1_INTEGER_get ASN1_INTEGER * a
The QBuffer class provides a QIODevice interface for a QByteArray.
Definition: qbuffer.h:57
int width() const
Returns the width.
Definition: qsize.h:126
bool isValid() const
void resize(int width, int height)
static QByteArray fromRawData(const char *, int size)
Constructs a QByteArray that uses the first size bytes of the data array.
QSize size() const
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
The QImageReader class provides a format independent interface for reading images from files or other...
Definition: qimagereader.h:62
void createPixmapForImage(QImage &image, Qt::ImageConversionFlags flags, bool inPlace)
out-of-place conversion (inPlace == false) will always detach()
#define ctx
Definition: qgl.cpp:6094
int height() const
Returns the height.
Definition: qsize.h:129
virtual QImage * buffer()
bool isNull() const
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
bool isEmpty() const
Returns true if either of the width and height is less than or equal to 0; otherwise returns false...
Definition: qsize.h:120
QSize bindCompressedTexture(const QString &fileName, const char *format=0)
Definition: qgl.cpp:5996
QImage read()
Reads an image from the device.

◆ fromFile()

bool QGLPixmapData::fromFile ( const QString filename,
const char *  format,
Qt::ImageConversionFlags  flags 
)
virtual

Reimplemented from QPixmapData.

Definition at line 391 of file qpixmapdata_gl.cpp.

393 {
395  return QPixmapData::fromFile(filename, format, flags);
396  QFile file(filename);
397  if (file.open(QIODevice::ReadOnly)) {
398  QByteArray data = file.peek(64);
399  bool alpha;
401  (data.constData(), data.size(), format, &alpha)) {
402  resize(0, 0);
403  data = file.readAll();
404  file.close();
407  (data.constData(), data.size(), format);
408  if (!size.isEmpty()) {
409  w = size.width();
410  h = size.height();
411  is_null = false;
412  d = 32;
413  m_hasAlpha = alpha;
414  m_source = QImage();
415  m_dirty = isValid();
416  return true;
417  }
418  return false;
419  }
420  }
421 
422  QImage image = QImageReader(filename, format).read();
423  if (image.isNull())
424  return false;
425 
426  createPixmapForImage(image, flags, true);
427 
428  return !isNull();
429 }
QGLTexture m_texture
virtual bool fromFile(const QString &filename, const char *format, Qt::ImageConversionFlags flags)
Q_OPENGL_EXPORT const QGLContext * qt_gl_share_context()
bool canBindCompressedTexture(const char *buf, int len, const char *format, bool *hasAlpha)
Definition: qgl.cpp:6057
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
PixelType pixelType() const
int width() const
Returns the width.
Definition: qsize.h:126
bool isValid() const
void resize(int width, int height)
QSize size() const
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static const char * data(const QByteArray &arr)
The QImageReader class provides a format independent interface for reading images from files or other...
Definition: qimagereader.h:62
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
void createPixmapForImage(QImage &image, Qt::ImageConversionFlags flags, bool inPlace)
out-of-place conversion (inPlace == false) will always detach()
#define ctx
Definition: qgl.cpp:6094
int height() const
Returns the height.
Definition: qsize.h:129
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
bool isNull() const
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
bool isEmpty() const
Returns true if either of the width and height is less than or equal to 0; otherwise returns false...
Definition: qsize.h:120
QSize bindCompressedTexture(const QString &fileName, const char *format=0)
Definition: qgl.cpp:5996
QImage read()
Reads an image from the device.

◆ fromImage()

void QGLPixmapData::fromImage ( const QImage image,
Qt::ImageConversionFlags  flags 
)
virtual

Implements QPixmapData.

Reimplemented in QMeeGoPixmapData.

Definition at line 374 of file qpixmapdata_gl.cpp.

Referenced by QMeeGoPixmapData::fromImage().

376 {
377  QImage img = image;
378  createPixmapForImage(img, flags, false);
379 }
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
void createPixmapForImage(QImage &image, Qt::ImageConversionFlags flags, bool inPlace)
out-of-place conversion (inPlace == false) will always detach()

◆ fromImageReader()

void QGLPixmapData::fromImageReader ( QImageReader imageReader,
Qt::ImageConversionFlags  flags 
)
virtual

Reimplemented from QPixmapData.

Definition at line 381 of file qpixmapdata_gl.cpp.

383 {
384  QImage image = imageReader->read();
385  if (image.isNull())
386  return;
387 
388  createPixmapForImage(image, flags, true);
389 }
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
void createPixmapForImage(QImage &image, Qt::ImageConversionFlags flags, bool inPlace)
out-of-place conversion (inPlace == false) will always detach()
QImage read()
Reads an image from the device.

◆ glDevice()

QGLPaintDevice * QGLPixmapData::glDevice ( ) const

Definition at line 827 of file qpixmapdata_gl.cpp.

828 {
829  return &m_glDevice;
830 }
QGLPixmapGLPaintDevice m_glDevice

◆ hasAlphaChannel()

bool QGLPixmapData::hasAlphaChannel ( ) const
virtual

Implements QPixmapData.

Definition at line 599 of file qpixmapdata_gl.cpp.

600 {
601  return m_hasAlpha;
602 }

◆ isUninitialized()

bool QGLPixmapData::isUninitialized ( ) const
inlineprivate

Definition at line 172 of file qpixmapdata_gl_p.h.

172 { return m_dirty && m_source.isNull(); }
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542

◆ isValid()

bool QGLPixmapData::isValid ( ) const
private

Definition at line 286 of file qpixmapdata_gl.cpp.

Referenced by copyBackFromRenderFbo(), fill(), fromData(), fromFile(), paintEngine(), resize(), and toImage().

287 {
288  return w > 0 && h > 0;
289 }

◆ isValidContext()

bool QGLPixmapData::isValidContext ( const QGLContext ctx) const

Definition at line 291 of file qpixmapdata_gl.cpp.

292 {
293  if (ctx == m_ctx)
294  return true;
295 
296  const QGLContext *share_ctx = qt_gl_share_context();
297  return ctx == share_ctx || QGLContext::areSharing(ctx, share_ctx);
298 }
QGLContext * m_ctx
Q_OPENGL_EXPORT const QGLContext * qt_gl_share_context()
static bool areSharing(const QGLContext *context1, const QGLContext *context2)
Returns true if context1 and context2 are sharing their GL resources such as textures, shader programs, etc; otherwise returns false.
Definition: qgl.cpp:3319
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310

◆ metric()

int QGLPixmapData::metric ( QPaintDevice::PaintDeviceMetric  metric) const
virtual

Implements QPixmapData.

Definition at line 797 of file qpixmapdata_gl.cpp.

798 {
799  if (w == 0)
800  return 0;
801 
802  switch (metric) {
804  return w;
806  return h;
808  return 0;
810  return d;
812  return qRound(w * 25.4 / qt_defaultDpiX());
814  return qRound(h * 25.4 / qt_defaultDpiY());
817  return qt_defaultDpiX();
820  return qt_defaultDpiY();
821  default:
822  qWarning("QGLPixmapData::metric(): Invalid metric");
823  return 0;
824  }
825 }
Q_GUI_EXPORT int qt_defaultDpiY()
Definition: qfont.cpp:201
Q_GUI_EXPORT int qt_defaultDpiX()
Definition: qfont.cpp:162
int metric(QPaintDevice::PaintDeviceMetric metric) const
Q_CORE_EXPORT void qWarning(const char *,...)
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ needsFill()

bool QGLPixmapData::needsFill ( ) const
inlineprivate

Definition at line 174 of file qpixmapdata_gl_p.h.

174 { return m_hasFillColor; }

◆ operator=()

QGLPixmapData& QGLPixmapData::operator= ( const QGLPixmapData other)
private

◆ paintEngine()

QPaintEngine * QGLPixmapData::paintEngine ( ) const
virtual

Implements QPixmapData.

Definition at line 718 of file qpixmapdata_gl.cpp.

719 {
720  if (!isValid())
721  return 0;
722 
723  if (m_renderFbo)
724  return m_engine;
725 
726  if (useFramebufferObjects()) {
727  extern QGLWidget* qt_gl_share_widget();
728 
730  const_cast<QGLContext *>(qt_gl_share_context())->makeCurrent();
732 
735  format.setSamples(4);
737 
738  m_renderFbo = qgl_fbo_pool()->acquire(size(), format);
739 
740  if (m_renderFbo) {
741  if (!m_engine)
743  return m_engine;
744  }
745 
746  qWarning() << "Failed to create pixmap texture buffer of size " << size() << ", falling back to raster paint engine";
747  }
748 
749  m_dirty = true;
750  if (m_source.size() != size())
752  if (m_hasFillColor) {
754  m_hasFillColor = false;
755  }
756  return m_source.paintEngine();
757 }
Q_OPENGL_EXPORT const QGLContext * qt_gl_share_context()
QGLFramebufferObjectPool * qgl_fbo_pool()
void setAttachment(QGLFramebufferObject::Attachment attachment)
Sets the attachment configuration of a framebuffer object to attachment.
#define GL_RGB
Q_OPENGL_EXPORT QGLWidget * qt_gl_share_widget()
void fill(uint pixel)
Fills the entire image with the given pixelValue.
Definition: qimage.cpp:2032
void setInternalTextureFormat(GLenum internalTextureFormat)
Sets the internal format of a framebuffer object&#39;s texture or multisample framebuffer object&#39;s color ...
QPaintEngine * m_engine
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
QGLFramebufferObject * acquire(const QSize &size, const QGLFramebufferObjectFormat &format, bool strictSize=false)
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
bool isValid() const
Q_STATIC_INLINE_FUNCTION uint PREMUL(uint x)
void setSamples(int samples)
Sets the number of samples per pixel for a multisample framebuffer object to samples.
QSize size() const
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
bool useFramebufferObjects() const
QSize size() const
Returns the size of the image, i.
Definition: qimage.cpp:1587
The QGLWidget class is a widget for rendering OpenGL graphics.
Definition: qgl.h:474
unsigned int GLenum
Definition: main.cpp:50
#define ctx
Definition: qgl.cpp:6094
QGLFramebufferObject * m_renderFbo
#define GL_RGBA
QPaintEngine * paintEngine() const
Used by QPainter to retrieve a paint engine for the image.
Definition: qimage.cpp:5970
QRgb rgba() const
Returns the RGB value of the color, including its alpha.
Definition: qcolor.cpp:1019
The QGLFramebufferObjectFormat class specifies the format of an OpenGL framebuffer object...

◆ resize()

void QGLPixmapData::resize ( int  width,
int  height 
)
virtual

Implements QPixmapData.

Definition at line 300 of file qpixmapdata_gl.cpp.

Referenced by copy(), createPixmapForImage(), fromData(), fromFile(), QMeeGoPixmapData::fromTexture(), QMeeGoLivePixmapData::initializeThroughEGLImage(), and QMeeGoGraphicsSystem::pixmapDataWithGLTexture().

301 {
302  if (width == w && height == h)
303  return;
304 
305  if (width <= 0 || height <= 0) {
306  width = 0;
307  height = 0;
308  }
309 
310  w = width;
311  h = height;
312  is_null = (w <= 0 || h <= 0);
313  d = pixelType() == QPixmapData::PixmapType ? 32 : 1;
314 
315  if (m_texture.id) {
317  glDeleteTextures(1, &m_texture.id);
318  m_texture.id = 0;
319  }
320 
321  m_source = QImage();
322  m_dirty = isValid();
324 }
QGLTexture m_texture
Q_OPENGL_EXPORT const QGLContext * qt_gl_share_context()
int width() const
PixelType pixelType() const
GLuint id
Definition: qgl_p.h:608
bool isValid() const
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
#define ctx
Definition: qgl.cpp:6094
int height() const
void setSerialNumber(int serNo)
static int qt_gl_pixmap_serial

◆ scroll()

bool QGLPixmapData::scroll ( int  dx,
int  dy,
const QRect rect 
)
virtual

Reimplemented from QPixmapData.

Reimplemented in QMeeGoLivePixmapData.

Definition at line 514 of file qpixmapdata_gl.cpp.

515 {
516  Q_UNUSED(dx);
517  Q_UNUSED(dy);
518  Q_UNUSED(rect);
519  return false;
520 }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ size()

QSize QGLPixmapData::size ( ) const
inlineprivate

Definition at line 183 of file qpixmapdata_gl_p.h.

Referenced by fillImage(), fromData(), fromFile(), and paintEngine().

183 { return QSize(w, h); }
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ texture()

QGLTexture * QGLPixmapData::texture ( ) const

◆ toImage()

QImage QGLPixmapData::toImage ( ) const
virtual

Implements QPixmapData.

Reimplemented in QMeeGoPixmapData.

Definition at line 630 of file qpixmapdata_gl.cpp.

631 {
632  if (!isValid())
633  return QImage();
634 
635  if (m_renderFbo) {
636  copyBackFromRenderFbo(true);
637  } else if (!m_source.isNull()) {
638  QImageData *data = const_cast<QImage &>(m_source).data_ptr();
639  if (data->paintEngine && data->paintEngine->isActive()
640  && data->paintEngine->paintDevice() == &m_source)
641  {
642  return m_source.copy();
643  }
644  return m_source;
645  } else if (m_dirty || m_hasFillColor) {
646  return fillImage(m_fillColor);
647  } else {
648  ensureCreated();
649  }
650 
652  glBindTexture(GL_TEXTURE_2D, m_texture.id);
653  return qt_gl_read_texture(QSize(w, h), true, true);
654 }
QGLTexture m_texture
Q_OPENGL_EXPORT const QGLContext * qt_gl_share_context()
QImage copy(const QRect &rect=QRect()) const
Returns a sub-area of the image as a new image.
Definition: qimage.cpp:1410
QImage qt_gl_read_texture(const QSize &size, bool alpha_format, bool include_alpha)
Definition: qgl.cpp:1871
QPaintDevice * paintDevice() const
Returns the device that this engine is painting on, if painting is active; otherwise returns 0...
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
void copyBackFromRenderFbo(bool keepCurrentFboBound) const
#define GL_TEXTURE_2D
bool isActive() const
Returns true if the paint engine is actively drawing; otherwise returns false.
Definition: qpaintengine.h:154
void ensureCreated() const
GLuint id
Definition: qgl_p.h:608
bool isValid() const
QPaintEngine * paintEngine
Definition: qimage_p.h:110
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static const char * data(const QByteArray &arr)
void * data_ptr(const QTransform &t)
Definition: qpainter_p.h:81
#define ctx
Definition: qgl.cpp:6094
QGLFramebufferObject * m_renderFbo
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QImage fillImage(const QColor &color) const

◆ useFramebufferObjects()

bool QGLPixmapData::useFramebufferObjects ( ) const
private

Definition at line 710 of file qpixmapdata_gl.cpp.

Referenced by bind(), copy(), ensureCreated(), fill(), and paintEngine().

711 {
715  && (w * h > 32*32); // avoid overhead of FBOs for small pixmaps
716 }
static bool hasOpenGLFramebufferObjects()
Returns true if the OpenGL GL_EXT_framebuffer_object extension is present on this system; otherwise r...
bool qt_gl_preferGL2Engine()
Definition: qgl.cpp:218
static bool hasOpenGLFramebufferBlit()
Returns true if the OpenGL GL_EXT_framebuffer_blit extension is present on this system; otherwise ret...

Friends and Related Functions

◆ QGLPixmapGLPaintDevice

Definition at line 219 of file qpixmapdata_gl_p.h.

◆ QMeeGoLivePixmapData

friend class QMeeGoLivePixmapData
friend

Definition at line 221 of file qpixmapdata_gl_p.h.

◆ QMeeGoPixmapData

friend class QMeeGoPixmapData
friend

Definition at line 220 of file qpixmapdata_gl_p.h.

Properties

◆ m_ctx

QGLContext* QGLPixmapData::m_ctx
mutableprivate

Definition at line 193 of file qpixmapdata_gl_p.h.

Referenced by ensureCreated(), and isValidContext().

◆ m_dirty

bool QGLPixmapData::m_dirty
mutableprivate

◆ m_engine

QPaintEngine* QGLPixmapData::m_engine
mutableprivate

Definition at line 192 of file qpixmapdata_gl_p.h.

Referenced by paintEngine(), and ~QGLPixmapData().

◆ m_fillColor

QColor QGLPixmapData::m_fillColor
mutableprivate

Definition at line 212 of file qpixmapdata_gl_p.h.

Referenced by bind(), fill(), paintEngine(), and toImage().

◆ m_glDevice

QGLPixmapGLPaintDevice QGLPixmapData::m_glDevice
mutableprivate

Definition at line 217 of file qpixmapdata_gl_p.h.

Referenced by glDevice(), and QGLPixmapData().

◆ m_hasAlpha

bool QGLPixmapData::m_hasAlpha
mutableprivate

◆ m_hasFillColor

bool QGLPixmapData::m_hasFillColor
mutableprivate

◆ m_renderFbo

QGLFramebufferObject* QGLPixmapData::m_renderFbo
mutableprivate

Definition at line 191 of file qpixmapdata_gl_p.h.

Referenced by bind(), copy(), copyBackFromRenderFbo(), paintEngine(), and toImage().

◆ m_source

QImage QGLPixmapData::m_source
mutableprivate

◆ m_texture

QGLTexture QGLPixmapData::m_texture
mutableprivate

The documentation for this class was generated from the following files: