本文整理汇总了C++中QPixmapData类的典型用法代码示例。如果您正苦于以下问题:C++ QPixmapData类的具体用法?C++ QPixmapData怎么用?C++ QPixmapData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QPixmapData类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Q_ASSERT
void QDirectFbBlitter::drawPixmap(const QRectF &rect, const QPixmap &pixmap, const QRectF &srcRect)
{
QPixmapData *data = pixmap.pixmapData();
Q_ASSERT(data->width() && data->height());
Q_ASSERT(data->classId() == QPixmapData::BlitterClass);
QBlittablePixmapData *blitPm = static_cast<QBlittablePixmapData*>(data);
QDirectFbBlitter *dfbBlitter = static_cast<QDirectFbBlitter *>(blitPm->blittable());
dfbBlitter->unlock();
IDirectFBSurface *s = dfbBlitter->m_surface.data();
DFBSurfaceBlittingFlags blittingFlags = DSBLIT_NOFX;
DFBSurfacePorterDuffRule porterDuff = DSPD_SRC;
if (pixmap.hasAlpha()) {
blittingFlags = DSBLIT_BLEND_ALPHACHANNEL;
porterDuff = DSPD_SRC_OVER;
}
m_surface->SetBlittingFlags(m_surface.data(), DFBSurfaceBlittingFlags(blittingFlags));
m_surface->SetPorterDuff(m_surface.data(), porterDuff);
m_surface->SetDstBlendFunction(m_surface.data(), DSBF_INVSRCALPHA);
const DFBRectangle sRect = { srcRect.x(), srcRect.y(), srcRect.width(), srcRect.height() };
DFBResult result;
if (rect.width() == srcRect.width() && rect.height() == srcRect.height())
result = m_surface->Blit(m_surface.data(), s, &sRect, rect.x(), rect.y());
else {
const DFBRectangle dRect = { rect.x(), rect.y(), rect.width(), rect.height() };
result = m_surface->StretchBlit(m_surface.data(), s, &sRect, &dRect);
}
if (result != DFB_OK)
DirectFBError("QDirectFBBlitter::drawPixmap()", result);
}
示例2: rasterPixmap
QPixmap rasterPixmap(const QImage &image)
{
QPixmapData *data =
new QRasterPixmapData(QPixmapData::PixmapType);
data->fromImage(image, Qt::AutoColor);
return QPixmap(data);
}
示例3: GetDC
HBITMAP QPixmap::toWinHBITMAP(HBitmapFormat format) const
{
if (isNull())
return 0;
HBITMAP bitmap = 0;
if (data->classId() == QPixmapData::RasterClass) {
QRasterPixmapData* d = static_cast<QRasterPixmapData*>(data.data());
int w = d->image.width();
int h = d->image.height();
HDC display_dc = GetDC(0);
// Define the header
BITMAPINFO bmi;
memset(&bmi, 0, sizeof(bmi));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = w;
bmi.bmiHeader.biHeight = -h;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biSizeImage = w * h * 4;
// Create the pixmap
uchar *pixels = 0;
bitmap = CreateDIBSection(display_dc, &bmi, DIB_RGB_COLORS, (void **) &pixels, 0, 0);
ReleaseDC(0, display_dc);
if (!bitmap) {
qErrnoWarning("QPixmap::toWinHBITMAP(), failed to create dibsection");
return 0;
}
if (!pixels) {
qErrnoWarning("QPixmap::toWinHBITMAP(), did not allocate pixel data");
return 0;
}
// Copy over the data
QImage::Format imageFormat = QImage::Format_ARGB32;
if (format == NoAlpha)
imageFormat = QImage::Format_RGB32;
else if (format == PremultipliedAlpha)
imageFormat = QImage::Format_ARGB32_Premultiplied;
const QImage image = d->image.convertToFormat(imageFormat);
int bytes_per_line = w * 4;
for (int y=0; y<h; ++y)
memcpy(pixels + y * bytes_per_line, image.scanLine(y), bytes_per_line);
} else {
QPixmapData *data = new QRasterPixmapData(depth() == 1 ?
QPixmapData::BitmapType : QPixmapData::PixmapType);
data->fromImage(toImage(), Qt::AutoColor);
return QPixmap(data).toWinHBITMAP(format);
}
return bitmap;
}
示例4: switch
// returns the QGLPaintDevice for the given QPaintDevice
QGLPaintDevice* QGLPaintDevice::getDevice(QPaintDevice* pd)
{
QGLPaintDevice* glpd = 0;
switch(pd->devType()) {
case QInternal::Widget:
// Should not be called on a non-gl widget:
Q_ASSERT(qobject_cast<QGLWidget*>(static_cast<QWidget*>(pd)));
glpd = &(static_cast<QGLWidget*>(pd)->d_func()->glDevice);
break;
case QInternal::Pbuffer:
glpd = &(static_cast<QGLPixelBuffer*>(pd)->d_func()->glDevice);
break;
case QInternal::FramebufferObject:
glpd = &(static_cast<QGLFramebufferObject*>(pd)->d_func()->glDevice);
break;
case QInternal::Pixmap: {
#if !defined(QT_OPENGL_ES_1)
QPixmapData* pmd = static_cast<QPixmap*>(pd)->pixmapData();
if (pmd->classId() == QPixmapData::OpenGLClass)
glpd = static_cast<QGLPixmapData*>(pmd)->glDevice();
#ifdef Q_WS_X11
else if (pmd->classId() == QPixmapData::X11Class)
glpd = static_cast<QX11GLPixmapData*>(pmd);
#endif
else
qWarning("Pixmap type not supported for GL rendering");
#else
qWarning("Pixmap render targets not supported on OpenGL ES 1.x");
#endif
break;
}
default:
qWarning("QGLPaintDevice::getDevice() - Unknown device type %d", pd->devType());
break;
}
return glpd;
}
示例5: eglSurfaceForDevice
EGLSurface QGLContextPrivate::eglSurfaceForDevice() const
{
// If a QPixmapData had to create the QGLContext, we don't have a paintDevice
if (!paintDevice)
return eglSurface;
#ifdef Q_WS_X11
if (paintDevice->devType() == QInternal::Pixmap) {
QPixmapData *pmd = static_cast<QPixmap*>(paintDevice)->data_ptr().data();
if (pmd->classId() == QPixmapData::X11Class) {
QX11PixmapData* x11PixmapData = static_cast<QX11PixmapData*>(pmd);
return (EGLSurface)x11PixmapData->gl_surface;
}
}
#endif
if (paintDevice->devType() == QInternal::Pbuffer) {
QGLPixelBuffer* pbuf = static_cast<QGLPixelBuffer*>(paintDevice);
return pbuf->d_func()->pbuf;
}
return eglSurface;
}
示例6: Q_UNUSED
// NOTE: The X11 version of createSurface will re-create the native drawable if it's visual doesn't
// match the one for the passed in EGLConfig
EGLSurface QEgl::createSurface(QPaintDevice *device, EGLConfig config, const QEglProperties *unusedProperties)
{
Q_UNUSED(unusedProperties);
int devType = device->devType();
if (devType == QInternal::Pbuffer) {
// TODO
return EGL_NO_SURFACE;
}
QX11PixmapData *x11PixmapData = 0;
if (devType == QInternal::Pixmap) {
QPixmapData *pmd = static_cast<QPixmap*>(device)->data_ptr().data();
if (pmd->classId() == QPixmapData::X11Class)
x11PixmapData = static_cast<QX11PixmapData*>(pmd);
else {
// TODO: Replace the pixmap's data with a new QX11PixmapData
qWarning("WARNING: Creating an EGL surface on a QPixmap is only supported for QX11PixmapData");
return EGL_NO_SURFACE;
}
} else if ((devType != QInternal::Widget) && (devType != QInternal::Pbuffer)) {
qWarning("WARNING: Creating an EGLSurface for device type %d isn't supported", devType);
return EGL_NO_SURFACE;
}
VisualID visualId = QEgl::getCompatibleVisualId(config);
EGLint alphaSize;
eglGetConfigAttrib(QEgl::display(), config, EGL_ALPHA_SIZE, &alphaSize);
if (devType == QInternal::Widget) {
QWidget *widget = static_cast<QWidget*>(device);
VisualID currentVisualId = 0;
if (widget->testAttribute(Qt::WA_WState_Created))
currentVisualId = XVisualIDFromVisual((Visual*)widget->x11Info().visual());
if (currentVisualId != visualId) {
// The window is either not created or has the wrong visual. Either way, we need
// to create a window with the correct visual and call create() on the widget:
bool visible = widget->isVisible();
if (visible)
widget->hide();
XVisualInfo visualInfo;
visualInfo.visualid = visualId;
{
XVisualInfo *visualInfoPtr;
int matchingCount = 0;
visualInfoPtr = XGetVisualInfo(widget->x11Info().display(), VisualIDMask,
&visualInfo, &matchingCount);
Q_ASSERT(visualInfoPtr); // visualId really should be valid!
visualInfo = *visualInfoPtr;
XFree(visualInfoPtr);
}
Window parentWindow = RootWindow(widget->x11Info().display(), widget->x11Info().screen());
if (widget->parentWidget())
parentWindow = widget->parentWidget()->winId();
XSetWindowAttributes windowAttribs;
QColormap colmap = QColormap::instance(widget->x11Info().screen());
windowAttribs.background_pixel = colmap.pixel(widget->palette().color(widget->backgroundRole()));
windowAttribs.border_pixel = colmap.pixel(Qt::black);
unsigned int valueMask = CWBackPixel|CWBorderPixel;
if (alphaSize > 0) {
windowAttribs.colormap = XCreateColormap(widget->x11Info().display(), parentWindow,
visualInfo.visual, AllocNone);
valueMask |= CWColormap;
}
Window window = XCreateWindow(widget->x11Info().display(), parentWindow,
widget->x(), widget->y(), widget->width(), widget->height(),
0, visualInfo.depth, InputOutput, visualInfo.visual,
valueMask, &windowAttribs);
// This is a nasty hack to get round the fact that we can't be a friend of QWidget:
qt_set_winid_on_widget(widget, window);
if (visible)
widget->show();
}
// At this point, the widget's window should be created and have the correct visual. Now we
// just need to create the EGL surface for it:
EGLSurface surf = eglCreateWindowSurface(QEgl::display(), config, (EGLNativeWindowType)widget->winId(), 0);
if (surf == EGL_NO_SURFACE)
qWarning("QEglContext::createSurface(): Unable to create EGL surface, error = 0x%x", eglGetError());
return surf;
}
if (x11PixmapData) {
// X11 Pixmaps are only created with a depth, so that's all we need to check
EGLint configDepth;
eglGetConfigAttrib(QEgl::display(), config, EGL_BUFFER_SIZE , &configDepth);
if (x11PixmapData->depth() != configDepth) {
//.........这里部分代码省略.........
示例7: Q_D
// Chooses the EGL config and creates the EGL context
bool QGLContext::chooseContext(const QGLContext* shareContext)
{
Q_D(QGLContext);
if (!device())
return false;
int devType = device()->devType();
QX11PixmapData *x11PixmapData = 0;
if (devType == QInternal::Pixmap) {
QPixmapData *pmd = static_cast<QPixmap*>(device())->data_ptr().data();
if (pmd->classId() == QPixmapData::X11Class)
x11PixmapData = static_cast<QX11PixmapData*>(pmd);
else {
// TODO: Replace the pixmap's data with a new QX11PixmapData
qWarning("WARNING: Creating a QGLContext on a QPixmap is only supported for X11 pixmap backend");
return false;
}
} else if ((devType != QInternal::Widget) && (devType != QInternal::Pbuffer)) {
qWarning("WARNING: Creating a QGLContext not supported on device type %d", devType);
return false;
}
// Only create the eglContext if we don't already have one:
if (d->eglContext == 0) {
d->eglContext = new QEglContext();
d->ownsEglContext = true;
d->eglContext->setApi(QEgl::OpenGL);
// If the device is a widget with WA_TranslucentBackground set, make sure the glFormat
// has the alpha channel option set:
if (devType == QInternal::Widget) {
QWidget* widget = static_cast<QWidget*>(device());
if (widget->testAttribute(Qt::WA_TranslucentBackground))
d->glFormat.setAlpha(true);
}
// Construct the configuration we need for this surface.
QEglProperties configProps;
configProps.setDeviceType(devType);
configProps.setRenderableType(QEgl::OpenGL);
qt_eglproperties_set_glformat(configProps, d->glFormat);
// Set buffer preserved for regular QWidgets, QGLWidgets are ok with either preserved or destroyed:
if ((devType == QInternal::Widget) && qobject_cast<QGLWidget*>(static_cast<QWidget*>(device())) == 0)
configProps.setValue(EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED);
if (!d->eglContext->chooseConfig(configProps, QEgl::BestPixelFormat)) {
delete d->eglContext;
d->eglContext = 0;
return false;
}
// Create a new context for the configuration.
QEglContext* eglSharedContext = shareContext ? shareContext->d_func()->eglContext : 0;
if (!d->eglContext->createContext(eglSharedContext)) {
delete d->eglContext;
d->eglContext = 0;
return false;
}
d->sharing = d->eglContext->isSharing();
if (d->sharing && shareContext)
const_cast<QGLContext *>(shareContext)->d_func()->sharing = true;
}
// Inform the higher layers about the actual format properties
qt_glformat_from_eglconfig(d->glFormat, d->eglContext->config());
// Do don't create the EGLSurface for everything.
// QWidget - yes, create the EGLSurface and store it in QGLContextPrivate::eglSurface
// QGLWidget - yes, create the EGLSurface and store it in QGLContextPrivate::eglSurface
// QPixmap - yes, create the EGLSurface but store it in QX11PixmapData::gl_surface
// QGLPixelBuffer - no, it creates the surface itself and stores it in QGLPixelBufferPrivate::pbuf
if (devType == QInternal::Widget) {
if (d->eglSurface != EGL_NO_SURFACE)
eglDestroySurface(d->eglContext->display(), d->eglSurface);
// extraWindowSurfaceCreationProps default to NULL unless were specifically set before
d->eglSurface = QEgl::createSurface(device(), d->eglContext->config(), d->extraWindowSurfaceCreationProps);
XFlush(X11->display);
setWindowCreated(true);
}
if (x11PixmapData) {
// TODO: Actually check to see if the existing surface can be re-used
if (x11PixmapData->gl_surface)
eglDestroySurface(d->eglContext->display(), (EGLSurface)x11PixmapData->gl_surface);
x11PixmapData->gl_surface = (void*)QEgl::createSurface(device(), d->eglContext->config());
}
return true;
}