X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/071f5576a0cc0926887b0e5c83da907d2c9edea6..9d5507f7a2701395e1d5c121bd877bb9066ee6ea:/src/dfb/dc.cpp diff --git a/src/dfb/dc.cpp b/src/dfb/dc.cpp index a02dd8f7a1..a78c2c8d5e 100644 --- a/src/dfb/dc.cpp +++ b/src/dfb/dc.cpp @@ -25,6 +25,7 @@ #ifndef WX_PRECOMP #include "wx/dc.h" + #include "wx/dcmemory.h" #include "wx/log.h" #endif @@ -53,13 +54,13 @@ wxDC::wxDC() wxDC::wxDC(const wxIDirectFBSurfacePtr& surface) { - Init(surface); + DFBInit(surface); } -void wxDC::Init(const wxIDirectFBSurfacePtr& surface) +void wxDC::DFBInit(const wxIDirectFBSurfacePtr& surface) { m_ok = (surface != NULL); - wxCHECK_RET( surface != NULL, _T("invalid surface") ); + wxCHECK_RET( surface != NULL, "invalid surface" ); m_surface = surface; @@ -78,25 +79,23 @@ void wxDC::Init(const wxIDirectFBSurfacePtr& surface) // clipping // --------------------------------------------------------------------------- - -#define DO_SET_CLIPPING_BOX(rg) \ -{ \ - wxRect rect = rg.GetBox(); \ - m_clipX1 = (wxCoord) XDEV2LOG(rect.GetLeft()); \ - m_clipY1 = (wxCoord) YDEV2LOG(rect.GetTop()); \ - m_clipX2 = (wxCoord) XDEV2LOG(rect.GetRight()); \ - m_clipY2 = (wxCoord) YDEV2LOG(rect.GetBottom()); \ -} - void wxDC::DoSetClippingRegion(wxCoord cx, wxCoord cy, wxCoord cw, wxCoord ch) { wxCHECK_RET( Ok(), wxT("invalid dc") ); + wxSize size(GetSize()); + + wxASSERT_MSG( !m_clipping, + "narrowing clipping region not implemented yet" ); + + // NB: We intersect the clipping rectangle with surface's area here because + // DirectFB will return an error if you try to set clipping rectangle + // that is partially outside of the surface. DFBRegion r; - r.x1 = XLOG2DEV(cx); - r.y1 = YLOG2DEV(cy); - r.x2 = r.x1 + XLOG2DEVREL(cw) - 1; - r.y2 = r.y1 + XLOG2DEVREL(ch) - 1; + r.x1 = wxMax(0, XLOG2DEV(cx)); + r.y1 = wxMax(0, YLOG2DEV(cy)); + r.x2 = wxMin(r.x1 + XLOG2DEVREL(cw), size.x) - 1; + r.y2 = wxMin(r.y1 + YLOG2DEVREL(ch), size.y) - 1; if ( !m_surface->SetClip(&r) ) return; @@ -110,8 +109,7 @@ void wxDC::DoSetClippingRegion(wxCoord cx, wxCoord cy, wxCoord cw, wxCoord ch) void wxDC::DoSetClippingRegionAsRegion(const wxRegion& region) { - // NB: this can be done because wxDFB only supports - // rectangular regions + // NB: this can be done because wxDFB only supports rectangular regions SetClippingRegion(region.AsRect()); } @@ -130,7 +128,7 @@ void wxDC::DestroyClippingRegion() int wxDC::GetDepth() const { - return wxDfbGetSurfaceDepth(m_surface); + return m_surface->GetDepth(); } // --------------------------------------------------------------------------- @@ -146,6 +144,10 @@ void wxDC::Clear() wxColour clr = m_backgroundBrush.GetColour(); m_surface->Clear(clr.Red(), clr.Green(), clr.Blue(), clr.Alpha()); + + wxSize size(GetSize()); + CalcBoundingBox(XDEV2LOG(0), YDEV2LOG(0)); + CalcBoundingBox(XDEV2LOG(size.x), YDEV2LOG(size.y)); } extern bool wxDoFloodFill(wxDC *dc, wxCoord x, wxCoord y, @@ -159,9 +161,9 @@ bool wxDC::DoFloodFill(wxCoord x, wxCoord y, bool wxDC::DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const { - wxCHECK_MSG( col, false, _T("NULL colour parameter in wxDC::GetPixel")); + wxCHECK_MSG( col, false, "NULL colour parameter in wxDC::GetPixel"); - wxFAIL_MSG( _T("GetPixel not implemented") ); + wxFAIL_MSG( "GetPixel not implemented" ); return false; } @@ -169,7 +171,7 @@ void wxDC::DoCrossHair(wxCoord x, wxCoord y) { wxCHECK_RET( Ok(), wxT("invalid dc") ); - wxFAIL_MSG( _T("CrossHair not implemented") ); + wxFAIL_MSG( "CrossHair not implemented" ); } void wxDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) @@ -179,8 +181,32 @@ void wxDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) if ( m_pen.GetStyle() == wxTRANSPARENT ) return; - m_surface->DrawLine(XLOG2DEV(x1), YLOG2DEV(y1), - XLOG2DEV(x2), YLOG2DEV(y2)); + wxCoord xx1 = XLOG2DEV(x1); + wxCoord yy1 = YLOG2DEV(y1); + wxCoord xx2 = XLOG2DEV(x2); + wxCoord yy2 = YLOG2DEV(y2); + + // FIXME: DrawLine() shouldn't draw the last pixel, but DFB's DrawLine() + // does draw it. We should undo any change to the last pixel by + // using GetPixel() and PutPixel(), but until they are implemented, + // handle at least the special case of vertical and horizontal + // lines correctly: + if ( xx1 == xx2 ) + { + if ( yy1 < yy2 ) + yy2--; + else if ( yy1 > yy2 ) + yy2++; + } + if ( yy1 == yy2 ) + { + if ( xx1 < xx2 ) + xx2--; + else if ( xx1 > xx2 ) + xx2++; + } + + m_surface->DrawLine(xx1, yy1, xx2, yy2); CalcBoundingBox(x1, y1); CalcBoundingBox(x2, y2); @@ -194,21 +220,26 @@ void wxDC::DoDrawArc(wxCoord x1, wxCoord y1, { wxCHECK_RET( Ok(), wxT("invalid dc") ); - wxFAIL_MSG( _T("DrawArc not implemented") ); + wxFAIL_MSG( "DrawArc not implemented" ); } void wxDC::DoDrawPoint(wxCoord x, wxCoord y) { wxCHECK_RET( Ok(), wxT("invalid dc") ); - wxFAIL_MSG( _T("DrawPoint not implemented") ); + // NB: DirectFB API doesn't provide a function for drawing points, so + // implement it as 1px long line. This is inefficient, but then, so is + // using DrawPoint() for drawing more than a few points. + DoDrawLine(x, y, x, y); + + // FIXME_DFB: implement special cases for common formats (RGB24,RGBA/RGB32) } void wxDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset,int WXUNUSED(fillStyle)) { wxCHECK_RET( Ok(), wxT("invalid dc") ); - wxFAIL_MSG( _T("DrawPolygon not implemented") ); + wxFAIL_MSG( "DrawPolygon not implemented" ); } void wxDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset) @@ -216,7 +247,7 @@ void wxDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset wxCHECK_RET( Ok(), wxT("invalid dc") ); // TODO: impl. using DirectDB's DrawLines - wxFAIL_MSG( _T("DrawLines not implemented") ); + wxFAIL_MSG( "DrawLines not implemented" ); } void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) @@ -245,7 +276,8 @@ void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { SelectColour(m_brush.GetColour()); m_surface->FillRectangle(xx, yy, ww, hh); - // restore pen's colour + // restore pen's colour, because other drawing functions expect the + // colour to be set to the pen: SelectColour(m_pen.GetColour()); } @@ -262,21 +294,21 @@ void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord h { wxCHECK_RET( Ok(), wxT("invalid dc") ); - wxFAIL_MSG( _T("DrawRoundedRectangle not implemented") ); + wxFAIL_MSG( "DrawRoundedRectangle not implemented" ); } void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { wxCHECK_RET( Ok(), wxT("invalid dc") ); - wxFAIL_MSG( _T("DrawElipse not implemented") ); + wxFAIL_MSG( "DrawElipse not implemented" ); } void wxDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea) { wxCHECK_RET( Ok(), wxT("invalid dc") ); - wxFAIL_MSG( _T("DrawElipticArc not implemented") ); + wxFAIL_MSG( "DrawElipticArc not implemented" ); } void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y) @@ -284,7 +316,7 @@ void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y) wxCHECK_RET( Ok(), wxT("invalid dc") ); wxCoord xx = XLOG2DEV(x); - wxCoord yy = XLOG2DEV(y); + wxCoord yy = YLOG2DEV(y); // update the bounding box wxCoord w, h; @@ -295,16 +327,22 @@ void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y) // if background mode is solid, DrawText must paint text's background: if ( m_backgroundMode == wxSOLID ) { - wxCHECK_RET( m_backgroundBrush.Ok(), wxT("invalid background brush") ); + wxCHECK_RET( m_textBackgroundColour.Ok(), + wxT("invalid background color") ); - SelectColour(m_backgroundBrush.GetColour()); + SelectColour(m_textBackgroundColour); m_surface->FillRectangle(xx, yy, XLOG2DEVREL(w), YLOG2DEVREL(h)); - // restore pen's colour - SelectColour(m_pen.GetColour()); } // finally draw the text itself: - m_surface->DrawString(wxSTR_TO_DFB(text), -1, xx, yy, DSTF_LEFT | DSTF_TOP); + wxCHECK_RET( m_textForegroundColour.Ok(), + wxT("invalid foreground color") ); + SelectColour(m_textForegroundColour); + m_surface->DrawString(text.utf8_str(), -1, xx, yy, DSTF_LEFT | DSTF_TOP); + + // restore pen's colour, because other drawing functions expect the colour + // to be set to the pen: + SelectColour(m_pen.GetColour()); } void wxDC::DoDrawRotatedText(const wxString& text, @@ -313,7 +351,7 @@ void wxDC::DoDrawRotatedText(const wxString& text, { wxCHECK_RET( Ok(), wxT("invalid dc") ); - wxFAIL_MSG( _T("DrawRotatedText not implemented") ); + wxFAIL_MSG( "DrawRotatedText not implemented" ); } // --------------------------------------------------------------------------- @@ -343,7 +381,7 @@ void wxDC::SetPalette(const wxPalette& WXUNUSED(palette)) { wxCHECK_RET( Ok(), wxT("invalid dc") ); - wxFAIL_MSG( _T("SetPalette not implemented") ); + wxFAIL_MSG( "SetPalette not implemented" ); } #endif // wxUSE_PALETTE @@ -353,10 +391,21 @@ void wxDC::SetFont(const wxFont& font) wxFont f(font.Ok() ? font : DEFAULT_FONT); - if ( !m_surface->SetFont(f.GetDirectFBFont()) ) - return; + wxFont oldfont(m_font); m_font = f; + + if ( !m_surface->SetFont(GetCurrentFont()) ) + { + m_font = oldfont; + return; + } +} + +wxIDirectFBFontPtr wxDC::GetCurrentFont() const +{ + bool aa = (GetDepth() > 8); + return m_font.GetDirectFBFont(aa); } void wxDC::SetBackground(const wxBrush& brush) @@ -377,7 +426,10 @@ void wxDC::SetLogicalFunction(int function) { wxCHECK_RET( Ok(), wxT("invalid dc") ); - wxFAIL_MSG( _T("SetLogicalFunction not implemented") ); + // NB: we could also support XOR, but for blitting only (via DSBLIT_XOR); + // and possibly others via SetSrc/DstBlendFunction() + wxASSERT_MSG( function == wxCOPY, + "only wxCOPY logical function supported" ); m_logicalFunction = function; } @@ -410,7 +462,7 @@ wxCoord wxDC::GetCharHeight() const wxCHECK_MSG( m_font.Ok(), -1, wxT("no font selected") ); int h = -1; - m_font.GetDirectFBFont()->GetHeight(&h); + GetCurrentFont()->GetHeight(&h); return YDEV2LOGREL(h); } @@ -420,7 +472,7 @@ wxCoord wxDC::GetCharWidth() const wxCHECK_MSG( m_font.Ok(), -1, wxT("no font selected") ); int w = -1; - m_font.GetDirectFBFont()->GetStringWidth("H", 1, &w); + GetCurrentFont()->GetStringWidth("H", 1, &w); // VS: YDEV is corrent, it should *not* be XDEV, because font's are only // scaled according to m_scaleY return YDEV2LOGREL(w); @@ -428,7 +480,7 @@ wxCoord wxDC::GetCharWidth() const void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y, wxCoord *descent, wxCoord *externalLeading, - wxFont *theFont) const + const wxFont *theFont) const { wxCHECK_RET( Ok(), wxT("invalid dc") ); wxCHECK_RET( m_font.Ok(), wxT("no font selected") ); @@ -443,9 +495,9 @@ void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y, wxCoord xx = 0, yy = 0; DFBRectangle rect; - wxIDirectFBFontPtr f = m_font.GetDirectFBFont(); + wxIDirectFBFontPtr f = GetCurrentFont(); - if ( f->GetStringExtents(wxSTR_TO_DFB(string), -1, &rect, NULL) ) + if ( f->GetStringExtents(string.utf8_str(), -1, &rect, NULL) ) { // VS: YDEV is corrent, it should *not* be XDEV, because font's are // only scaled according to m_scaleY @@ -476,132 +528,10 @@ void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y, // mapping modes // --------------------------------------------------------------------------- -void wxDC::ComputeScaleAndOrigin() -{ - m_scaleX = m_logicalScaleX * m_userScaleX; - m_scaleY = m_logicalScaleY * m_userScaleY; - - // FIXME_DFB: scaling affects pixel size of font, pens, brushes, which - // is not currently implemented here; probably makes sense to - // switch to Cairo instead of implementing everything for DFB - wxASSERT_MSG( m_scaleX == 1.0 && m_scaleY == 1.0, - _T("scaling is not implemented in wxDFB") ); -} - -void wxDC::SetMapMode(int mode) -{ - #warning "move this to common code, it's shared by almost all ports!" - switch (mode) - { - case wxMM_TWIPS: - SetLogicalScale(twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y); - break; - case wxMM_POINTS: - SetLogicalScale(pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y); - break; - case wxMM_METRIC: - SetLogicalScale(m_mm_to_pix_x, m_mm_to_pix_y); - break; - case wxMM_LOMETRIC: - SetLogicalScale(m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0); - break; - default: - case wxMM_TEXT: - SetLogicalScale(1.0, 1.0); - break; - } - m_mappingMode = mode; -} - -void wxDC::SetUserScale(double x, double y) -{ - #warning "move this to common code?" - // allow negative ? -> no - m_userScaleX = x; - m_userScaleY = y; - ComputeScaleAndOrigin(); -} - -void wxDC::SetLogicalScale(double x, double y) -{ - #warning "move this to common code?" - // allow negative ? - m_logicalScaleX = x; - m_logicalScaleY = y; - ComputeScaleAndOrigin(); -} - -void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y ) -{ - #warning "move this to common code?" - m_logicalOriginX = x * m_signX; // is this still correct ? - m_logicalOriginY = y * m_signY; - ComputeScaleAndOrigin(); -} - -void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y ) -{ - #warning "move this to common code?" - // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there - m_deviceOriginX = x; - m_deviceOriginY = y; - ComputeScaleAndOrigin(); -} - -void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) -{ - #warning "move this to common code?" - // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there - m_signX = (xLeftRight ? 1 : -1); - m_signY = (yBottomUp ? -1 : 1); - ComputeScaleAndOrigin(); -} - -// --------------------------------------------------------------------------- -// coordinates transformations -// --------------------------------------------------------------------------- - -wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const -{ - return ((wxDC *)this)->XDEV2LOG(x); -} - -wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const -{ - return ((wxDC *)this)->YDEV2LOG(y); -} - -wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const -{ - return ((wxDC *)this)->XDEV2LOGREL(x); -} - -wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const -{ - return ((wxDC *)this)->YDEV2LOGREL(y); -} - -wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const -{ - return ((wxDC *)this)->XLOG2DEV(x); -} - -wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const -{ - return ((wxDC *)this)->YLOG2DEV(y); -} - -wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const -{ - return ((wxDC *)this)->XLOG2DEVREL(x); -} - -wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const -{ - return ((wxDC *)this)->YLOG2DEVREL(y); -} - - +// FIXME_DFB: scaling affects pixel size of font, pens, brushes, which +// is not currently implemented here; probably makes sense to +// switch to Cairo instead of implementing everything for DFB + void wxDC::DoGetSize(int *w, int *h) const { wxCHECK_RET( Ok(), wxT("invalid dc") ); @@ -637,17 +567,21 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, int rop, bool useMask, wxCoord xsrcMask, wxCoord ysrcMask) { -#warning "FIXME" - return false; -#if 0 - wxCHECK_MSG( Ok(), false, wxT("invalid dc") ); - wxCHECK_MSG( source, false, wxT("invalid source dc") ); + wxCHECK_MSG( Ok(), false, "invalid dc" ); + wxCHECK_MSG( source, false, "invalid source dc" ); + + // NB: we could also support XOR here (via DSBLIT_XOR) + // and possibly others via SetSrc/DstBlendFunction() + wxCHECK_MSG( rop == wxCOPY, false, "only wxCOPY function supported" ); // transform the source DC coords to the device ones xsrc = source->LogicalToDeviceX(xsrc); ysrc = source->LogicalToDeviceY(ysrc); - /* FIXME_MGL: use the mask origin when drawing transparently */ + // FIXME_DFB: use the mask origin when drawing transparently + wxASSERT_MSG( xsrcMask == -1 && ysrcMask == -1, + "non-default source mask offset not implemented" ); +#if 0 if (xsrcMask == -1 && ysrcMask == -1) { xsrcMask = xsrc; ysrcMask = ysrc; @@ -657,32 +591,27 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, xsrcMask = source->LogicalToDeviceX(xsrcMask); ysrcMask = source->LogicalToDeviceY(ysrcMask); } +#endif - CalcBoundingBox(xdest, ydest); - CalcBoundingBox(xdest + width, ydest + height); - - /* scale/translate size and position */ - wxCoord xx = XLOG2DEV(xdest); - wxCoord yy = YLOG2DEV(ydest); - wxCoord ww = XLOG2DEVREL(width); - wxCoord hh = YLOG2DEVREL(height); - - if ( source->m_isMemDC ) + wxMemoryDC *sourceAsMemDC = wxDynamicCast(source, wxMemoryDC); + if ( sourceAsMemDC ) { - wxMemoryDC *memDC = (wxMemoryDC*) source; - DoDrawSubBitmap(memDC->GetSelectedObject(), xsrc, ysrc, ww, hh, - xdest, ydest, rop, useMask); + DoDrawSubBitmap(sourceAsMemDC->GetSelectedObject(), + xsrc, ysrc, + width, height, + xdest, ydest, + rop, + useMask); } else { - m_MGLDC->makeCurrent(); // will go away with MGL6.0 - m_MGLDC->bitBlt(*source->GetMGLDC(), - xsrc, ysrc, xsrc + ww, ysrc + hh, - xx, yy, LogicalFunctionToMGLRop(rop)); + return DoBlitFromSurface(source->GetDirectFBSurface(), + xsrc, ysrc, + width, height, + xdest, ydest); } return true; -#endif } void wxDC::DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask) @@ -690,10 +619,10 @@ void wxDC::DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask) wxCHECK_RET( Ok(), wxT("invalid dc") ); wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") ); - wxCoord w = bmp.GetWidth(); - wxCoord h = bmp.GetHeight(); - - DoDrawSubBitmap(bmp, 0, 0, w, h, x, y, m_logicalFunction, useMask); + DoDrawSubBitmap(bmp, + 0, 0, bmp.GetWidth(), bmp.GetHeight(), + x, y, + m_logicalFunction, useMask); } void wxDC::DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) @@ -706,94 +635,78 @@ void wxDC::DoDrawSubBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, wxCoord w, wxCoord h, wxCoord destx, wxCoord desty, int rop, bool useMask) { -#if 0 wxCHECK_RET( Ok(), wxT("invalid dc") ); wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") ); - CalcBoundingBox(x, y); - CalcBoundingBox(x + w, y + h); - - wxCoord dx = XLOG2DEV(destx); - wxCoord dy = YLOG2DEV(desty); - wxCoord dw = XLOG2DEVREL(w); - wxCoord dh = YLOG2DEVREL(h); - - m_MGLDC->makeCurrent(); // will go away with MGL6.0 - - bool useStretching = ((w != dw) || (h != dh)); - bool putSection = (w != bmp.GetWidth() || h != bmp.GetHeight()); - MGL_writeModeType mglRop = (MGL_writeModeType)LogicalFunctionToMGLRop(rop); + // NB: we could also support XOR here (via DSBLIT_XOR) + // and possibly others via SetSrc/DstBlendFunction() + wxCHECK_RET( rop == wxCOPY, "only wxCOPY function supported" ); if ( bmp.GetDepth() == 1 ) { // Mono bitmaps are handled in special way -- all 1s are drawn in // foreground colours, all 0s in background colour. - - ((wxBitmap&)bmp).SetMonoPalette(m_textForegroundColour, m_textBackgroundColour); + wxFAIL_MSG( "drawing mono bitmaps not implemented" ); + return; } if ( useMask && bmp.GetMask() ) { - // Since MGL does not support masks directly (in MGL, mask is handled - // in same way as in wxImage, i.e. there is one "key" color), we - // simulate masked bitblt in 6 steps (same as in MSW): - // - // 1. Create a temporary bitmap and copy the destination area into it. - // 2. Copy the source area into the temporary bitmap using the - // specified logical function. - // 3. Set the masked area in the temporary bitmap to BLACK by ANDing - // the mask bitmap with the temp bitmap with the foreground colour - // set to WHITE and the bg colour set to BLACK. - // 4. Set the unmasked area in the destination area to BLACK by - // ANDing the mask bitmap with the destination area with the - // foreground colour set to BLACK and the background colour set - // to WHITE. - // 5. OR the temporary bitmap with the destination area. - // 6. Delete the temporary bitmap. - // - // This sequence of operations ensures that the source's transparent - // area need not be black, and logical functions are supported. - - wxBitmap *mask = bmp.GetMask()->GetBitmap(); - - MGLMemoryDC *temp; - - if ( GetDepth() <= 8 ) - { - temp = new MGLMemoryDC(dw, dh, GetDepth(), NULL); - wxDC tempdc; - tempdc.SetMGLDC(temp, false); - tempdc.SetPalette(m_palette); - } - else - { - pixel_format_t pf; - m_MGLDC->getPixelFormat(pf); - temp = new MGLMemoryDC(dw, dh, GetDepth(), &pf); - } + // FIXME_DFB: see MGL sources for a way to do it, but it's not directly + // applicable because DirectFB doesn't implement ROPs; OTOH, + // it has blitting modes that can be useful; finally, see + // DFB's SetSrcBlendFunction() and SetSrcColorKey() + wxFAIL_MSG( "drawing bitmaps with masks not implemented" ); + return; + } - wxCHECK_RET( temp->isValid(), wxT("cannot create temporary dc") ); + DoBlitFromSurface(bmp.GetDirectFBSurface(), + x, y, + w, h, + destx, desty); +} + +bool wxDC::DoBlitFromSurface(const wxIDirectFBSurfacePtr& src, + wxCoord srcx, wxCoord srcy, + wxCoord w, wxCoord h, + wxCoord dstx, wxCoord dsty) +{ + // don't do anything if the source rectangle is outside of source surface, + // DirectFB would assert in that case: + wxSize srcsize; + src->GetSize(&srcsize.x, &srcsize.y); + if ( !wxRect(srcx, srcy, w, h).Intersects(wxRect(srcsize)) ) + { + wxLogDebug("Blitting from area outside of the source surface, caller code needs fixing."); + return false; + } - temp->bitBlt(*m_MGLDC, dx, dy, dx + dw, dy + dh, 0, 0, MGL_REPLACE_MODE); + CalcBoundingBox(dstx, dsty); + CalcBoundingBox(dstx + w, dsty + h); - DoBitBlt(bmp, temp, x, y, w, h, 0, 0, dw, dh, mglRop, - useStretching, putSection); + DFBRectangle srcRect = { srcx, srcy, w, h }; + DFBRectangle dstRect = { XLOG2DEV(dstx), YLOG2DEV(dsty), + XLOG2DEVREL(w), YLOG2DEVREL(h) }; - mask->SetMonoPalette(wxColour(0,0,0), wxColour(255,255,255)); - DoBitBlt(*mask, temp, x, y, w, h, 0, 0, dw, dh, MGL_R2_MASKSRC, - useStretching, putSection); - DoBitBlt(*mask, m_MGLDC, x, y, w, h, dx, dy, dw, dh, MGL_R2_MASKNOTSRC, - useStretching, putSection); + wxIDirectFBSurfacePtr dst(m_surface); - m_MGLDC->bitBlt(*temp, 0, 0, dw, dh, dx, dy, MGL_OR_MODE); + // FIXME: this will have to be different in useMask case, see above + DFBSurfaceBlittingFlags blitFlag = (src->GetPixelFormat() == DSPF_ARGB) + ? DSBLIT_BLEND_ALPHACHANNEL + : DSBLIT_NOFX; + if ( !dst->SetBlittingFlags(blitFlag) ) + return false; - delete temp; + if ( srcRect.w != dstRect.w || srcRect.h != dstRect.h ) + { + // the bitmap is drawn stretched: + dst->StretchBlit(src, &srcRect, &dstRect); } - else { - DoBitBlt(bmp, m_MGLDC, x, y, w, h, dx, dy, dw, dh, mglRop, - useStretching, putSection); + // no stretching, size is preserved: + dst->Blit(src, &srcRect, dstRect.x, dstRect.y); } -#endif + + return true; }