KisPaintDeviceSP TransformStrokeStrategy::createDeviceCache(KisPaintDeviceSP dev)
{
    KisPaintDeviceSP cache;

    if (m_selection) {
        QRect srcRect = m_selection->selectedExactRect();

        cache = dev->createCompositionSourceDevice();
        KisPainter gc(cache);
        gc.setSelection(m_selection);
        gc.bitBlt(srcRect.topLeft(), dev, srcRect);
    } else {
        cache = dev->createCompositionSourceDevice(dev);
    }

    return cache;
}
void KisFilterStrokeStrategy::initStrokeCallback()
{
    KisPainterBasedStrokeStrategy::initStrokeCallback();

    KisPaintDeviceSP dev = targetDevice();

    if (activeSelection() ||
        (dev->colorSpace() != dev->compositionSourceColorSpace() &&
         !(dev->colorSpace() == dev->compositionSourceColorSpace()))) {

        m_d->filterDevice = dev->createCompositionSourceDevice(dev);
        m_d->secondaryTransaction = new KisTransaction("", m_d->filterDevice);
    } else {
        m_d->filterDevice = dev;
    }
}
void FillProcessingVisitor::visitNodeWithPaintDevice(KisNode *node, KisUndoAdapter *undoAdapter)
{
    KisPaintDeviceSP device = node->paintDevice();
    Q_ASSERT(device);

    ProgressHelper helper(node);
    QRect fillRect = m_resources->image()->bounds();

    if (!device->defaultBounds()->wrapAroundMode() &&
        !fillRect.contains(m_startPoint)) {

        return;
    }

    if (m_selectionOnly) {
        KisPaintDeviceSP filledDevice = device->createCompositionSourceDevice();
        KisFillPainter fillPainter(filledDevice);
        fillPainter.setProgress(helper.updater());

        if (m_usePattern) {
            fillPainter.fillRect(fillRect, m_resources->currentPattern());
        } else if (m_useBgColor) {
            fillPainter.fillRect(fillRect,
                                 m_resources->currentBgColor(),
                                 m_resources->opacity());
        } else {
            fillPainter.fillRect(fillRect,
                                 m_resources->currentFgColor(),
                                 m_resources->opacity());
        }

        QVector<QRect> dirtyRect = fillPainter.takeDirtyRegion();

        KisPainter painter(device, m_selection);
        painter.beginTransaction();

        m_resources->setupPainter(&painter);

        foreach(const QRect &rc, dirtyRect) {
            painter.bitBlt(rc.topLeft(), filledDevice, rc);
        }

        painter.endTransaction(undoAdapter);

    } else {