+ wxCHECK_MSG(IsOk(), false, "invalid DC");
+ wxCHECK_MSG(source && source->IsOk(), false, "invalid source DC");
+
+ cairo_t* cr = NULL;
+ if (m_graphicContext)
+ cr = static_cast<cairo_t*>(m_graphicContext->GetNativeContext());
+ cairo_t* cr_src = NULL;
+ wxGraphicsContext* gc_src = source->GetGraphicsContext();
+ if (gc_src)
+ cr_src = static_cast<cairo_t*>(gc_src->GetNativeContext());
+
+ if (cr == NULL || cr_src == NULL)
+ return false;
+
+ const int xsrc_dev = source->LogicalToDeviceX(xsrc);
+ const int ysrc_dev = source->LogicalToDeviceY(ysrc);
+
+ cairo_surface_t* surface = cairo_get_target(cr_src);
+ cairo_surface_flush(surface);
+ cairo_save(cr);
+ cairo_translate(cr, xdest, ydest);
+ cairo_rectangle(cr, 0, 0, dstWidth, dstHeight);
+ double sx, sy;
+ source->GetUserScale(&sx, &sy);
+ cairo_scale(cr, dstWidth / (sx * srcWidth), dstHeight / (sy * srcHeight));
+ cairo_set_source_surface(cr, surface, -xsrc_dev, -ysrc_dev);
+ const wxRasterOperationMode rop_save = m_logicalFunction;
+ SetLogicalFunction(rop);
+ cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_NEAREST);
+ cairo_surface_t* maskSurf = NULL;
+ if (useMask)
+ {
+ const wxBitmap& bitmap = source->GetImpl()->GetSelectedBitmap();
+ if (bitmap.IsOk())
+ {
+ wxMask* mask = bitmap.GetMask();
+ if (mask)
+ maskSurf = *mask;
+ }
+ }
+ if (maskSurf)
+ {
+ int xsrcMask_dev = xsrc_dev;
+ int ysrcMask_dev = ysrc_dev;
+ if (xsrcMask != -1)
+ xsrcMask_dev = source->LogicalToDeviceX(xsrcMask);
+ if (ysrcMask != -1)
+ ysrcMask_dev = source->LogicalToDeviceY(ysrcMask);
+ cairo_clip(cr);
+ cairo_mask_surface(cr, maskSurf, -xsrcMask_dev, -ysrcMask_dev);
+ }
+ else
+ {
+ cairo_fill(cr);
+ }
+ cairo_restore(cr);
+ m_logicalFunction = rop_save;
+ return true;