QDirectFbBlitter::QDirectFbBlitter(const QSize &rect, bool alpha) : QBlittable(rect, dfb_blitter_capabilities()) , m_premult(false) , m_debugPaint(false) { DFBSurfaceDescription surfaceDesc; memset(&surfaceDesc,0,sizeof(DFBSurfaceDescription)); surfaceDesc.width = rect.width(); surfaceDesc.height = rect.height(); // force alpha format to get AlphaFillRectCapability and ExtendedPixmapCapability support alpha = true; if (alpha) { m_premult = true; surfaceDesc.caps = DSCAPS_PREMULTIPLIED; surfaceDesc.pixelformat = QDirectFbBlitter::alphaPixmapFormat(); surfaceDesc.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_CAPS | DSDESC_PIXELFORMAT); } else { surfaceDesc.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT); surfaceDesc.pixelformat = QDirectFbBlitter::pixmapFormat(); } if (qEnvironmentVariableIntValue("QT_DIRECTFB_BLITTER_DEBUGPAINT")) m_debugPaint = true; IDirectFB *dfb = QDirectFbConvenience::dfbInterface(); dfb->CreateSurface(dfb , &surfaceDesc, m_surface.outPtr()); m_surface->Clear(m_surface.data(), 0, 0, 0, 0); }
IDirectFBSurface *QDirectFbTextureGlyphCache::sourceSurface() { if (m_surface.isNull()) { const QImage &source = image(); DFBSurfaceDescription desc; memset(&desc, 0, sizeof(desc)); desc.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_PREALLOCATED | DSDESC_CAPS); desc.width = source.width(); desc.height = source.height(); desc.caps = DSCAPS_SYSTEMONLY; switch (source.format()) { case QImage::Format_Mono: desc.pixelformat = DSPF_A1; break; case QImage::Format_Alpha8: desc.pixelformat = DSPF_A8; break; default: qFatal("QDirectFBTextureGlyphCache: Unsupported source texture image format."); break; } desc.preallocated[0].data = const_cast<void*>(static_cast<const void*>(source.bits())); desc.preallocated[0].pitch = source.bytesPerLine(); desc.preallocated[1].data = 0; desc.preallocated[1].pitch = 0; IDirectFB *dfb = QDirectFbConvenience::dfbInterface(); dfb->CreateSurface(dfb , &desc, m_surface.outPtr()); } return m_surface.data(); }
void QDirectFBPixmapData::resize(int width, int height) { if (width <= 0 || height <= 0) { setSerialNumber(0); return; } IDirectFB *dfb = QDirectFBScreen::instance()->dfb(); if (!dfb) qFatal("QDirectFBPixmapData::resize(): " "Unable to get DirectFB handle!"); DFBSurfaceDescription description; description.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH | DSDESC_HEIGHT); description.width = width; description.height = height; DFBResult result = dfb->CreateSurface(dfb, &description, &surface); if (result != DFB_OK) { DirectFBErrorFatal("QDirectFBPixmapData::resize(): " "Unable to allocate surface", result); } setSerialNumber(++global_ser_no); }
QDirectFbBlitter::QDirectFbBlitter(const QSize &rect, bool alpha) : QBlittable(rect, dfb_blitter_capabilities()) { DFBSurfaceDescription surfaceDesc; memset(&surfaceDesc,0,sizeof(DFBSurfaceDescription)); surfaceDesc.width = rect.width(); surfaceDesc.height = rect.height(); if (alpha) { surfaceDesc.caps = DSCAPS_PREMULTIPLIED; surfaceDesc.pixelformat = QDirectFbBlitter::alphaPixmapFormat(); surfaceDesc.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_CAPS | DSDESC_PIXELFORMAT); } else { surfaceDesc.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT); surfaceDesc.pixelformat = QDirectFbBlitter::pixmapFormat(); } IDirectFB *dfb = QDirectFbConvenience::dfbInterface(); dfb->CreateSurface(dfb , &surfaceDesc, m_surface.outPtr()); m_surface->Clear(m_surface.data(), 0, 0, 0, 0); }
void QDirectFBPixmapData::fill(const QColor &color) { if (!serialNumber()) return; Q_ASSERT(surface); if (color.alpha() < 255 && !hasAlphaChannel()) { // convert to surface supporting alpha channel DFBSurfacePixelFormat format; surface->GetPixelFormat(surface, &format); switch (format) { case DSPF_YUY2: case DSPF_UYVY: format = DSPF_AYUV; break; #if (Q_DIRECTFB_VERSION >= 0x010100) case DSPF_RGB444: format = DSPF_ARGB4444; break; case DSPF_RGB555: #endif case DSPF_RGB18: format = DSPF_ARGB6666; break; default: format = DSPF_ARGB; break; } DFBSurfaceDescription description; description.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT); surface->GetSize(surface, &description.width, &description.height); description.pixelformat = format; surface->Release(surface); // release old surface IDirectFB *fb = QDirectFBScreen::instance()->dfb(); DFBResult result = fb->CreateSurface(fb, &description, &surface); if (result != DFB_OK) { DirectFBError("QDirectFBPixmapData::fill()", result); setSerialNumber(0); return; } } surface->Clear(surface, color.red(), color.green(), color.blue(), color.alpha()); }
void QDirectFBPixmapData::copy(const QPixmapData *data, const QRect &rect) { if (data->classId() != DirectFBClass) { QPixmapData::copy(data, rect); return; } IDirectFBSurface *src = static_cast<const QDirectFBPixmapData*>(data)->surface; DFBSurfaceDescription description; description.flags = DFBSurfaceDescriptionFlags(DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT); description.width = rect.width(); description.height = rect.height(); src->GetPixelFormat(src, &description.pixelformat); IDirectFB *fb = QDirectFBScreen::instance()->dfb(); DFBResult result = fb->CreateSurface(fb, &description, &surface); if (result != DFB_OK) { DirectFBError("QDirectFBPixmapData::copy()", result); setSerialNumber(0); return; } #ifndef QT_NO_DIRECTFB_PALETTE IDirectFBPalette *palette; src->GetPalette(src, &palette); surface->SetPalette(surface, palette); #endif surface->SetBlittingFlags(surface, DSBLIT_NOFX); const DFBRectangle blitRect = { rect.x(), rect.y(), rect.width(), rect.height() }; result = surface->Blit(surface, src, &blitRect, 0, 0); if (result != DFB_OK) DirectFBError("QDirectFBPixmapData::copy()", result); setSerialNumber(++global_ser_no); }
void QDirectFBPixmapData::fromImage(const QImage &img, Qt::ImageConversionFlags) { QImage image; if (QDirectFBScreen::getSurfacePixelFormat(img) == DSPF_UNKNOWN) image = img.convertToFormat(QImage::Format_ARGB32_Premultiplied); else image = img; DFBSurfaceDescription description; description = QDirectFBScreen::getSurfaceDescription(image); IDirectFB *fb = QDirectFBScreen::instance()->dfb(); DFBResult result; #ifndef QT_NO_DIRECTFB_PREALLOCATED IDirectFBSurface *imgSurface; result = fb->CreateSurface(fb, &description, &imgSurface); if (result != DFB_OK) { DirectFBError("QDirectFBPixmapData::fromImage()", result); setSerialNumber(0); return; } #ifndef QT_NO_DIRECTFB_PALETTE QDirectFBScreen::setSurfaceColorTable(imgSurface, image); #endif #endif // QT_NO_DIRECTFB_PREALLOCATED description.flags = DFBSurfaceDescriptionFlags(description.flags ^ DSDESC_PREALLOCATED); result = fb->CreateSurface(fb, &description, &surface); if (result != DFB_OK) { DirectFBError("QDirectFBPixmapData::fromImage()", result); setSerialNumber(0); return; } #ifndef QT_NO_DIRECTFB_PALETTE QDirectFBScreen::setSurfaceColorTable(surface, image); #endif #ifdef QT_NO_DIRECTFB_PREALLOCATED char *mem; int bpl; surface->Lock(surface, DSLF_WRITE, (void**)&mem, &bpl); const int w = image.width() * image.depth() / 8; for (int i = 0; i < image.height(); ++i) { memcpy(mem, image.scanLine(i), w); mem += bpl; } surface->Unlock(surface); #else surface->SetBlittingFlags(surface, DSBLIT_NOFX); result = surface->Blit(surface, imgSurface, 0, 0, 0); if (result != DFB_OK) DirectFBError("QDirectFBPixmapData::fromImage()", result); surface->Flip(surface, 0, DSFLIP_NONE); imgSurface->Release(imgSurface); #endif // QT_NO_DIRECTFB_PREALLOCATED setSerialNumber(++global_ser_no); }