Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Painting performance improvements - Tiled buffer #1776

Merged
merged 55 commits into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
2e9ec51
Canvaspainter improvement WIP
MrStevns Apr 22, 2023
69f7b81
Implement tiled buffer for faster painting WIP
MrStevns Apr 22, 2023
b8f8823
CanvasPainter painting improvements
MrStevns Apr 23, 2023
0999f48
Only update the dirty potion
MrStevns Apr 22, 2023
36d9b2e
Fix vector selection being slightly wider than the overall bounds
MrStevns Apr 23, 2023
3ee714f
Merge branch 'master' into painting-blitting-improvements
MrStevns Apr 23, 2023
e41218d
Fix stroke placement for vector polyline
MrStevns Apr 23, 2023
0bd437b
Implement faster hashing
MrStevns May 29, 2023
a6d03c7
Do some cleanup
J5lx May 30, 2023
85a9c1c
Fix next onion skin being drawn on current frame when it's the last
MrStevns May 31, 2023
8d56750
Re-add loadFile if the bitmap image hasn't been loaded yet
MrStevns May 31, 2023
9d7a2da
Update CanvasPainter interface to better match its usage
J5lx Jun 3, 2023
ec00ec1
Merge branch 'painting-blitting-improvements' into painting-blitting-…
MrStevns Jun 4, 2023
85b1b88
Cleanup TiledBuffer
MrStevns Jun 4, 2023
a911b10
Make polyline work
MrStevns Jun 8, 2023
e55d3fc
Fix blur logic of smudge tool
MrStevns Jun 27, 2023
9ef0eac
Replace use of BitmapImage buffer with TiledBuffer
MrStevns Jul 15, 2023
3eceedd
Make TiledBuffer work for VectorImage
MrStevns Jul 15, 2023
b958ce5
Cleanup dead code in TiledBuffer
MrStevns Jul 15, 2023
0086aa7
Merge remote-tracking branch 'origin/master' into painting-blitting-i…
MrStevns Jul 15, 2023
ec06502
Fix not painting bitmap layers when not on current frame
MrStevns Jul 15, 2023
e916591
Add missing license
MrStevns Jul 16, 2023
ed94ba6
Remove dead code
MrStevns Jul 16, 2023
a16efa9
Fix drawImage would not get proper update bounds
MrStevns Jul 16, 2023
63ed190
Cleanup TiledBuffer and fix warnings
MrStevns Jul 16, 2023
3d90e5c
Fix Eraser should use destinationOut composition
MrStevns Jul 16, 2023
7812bfd
Fix anti aliasing was causing unwanted floating precision error
MrStevns Jul 20, 2023
fb4bc79
Fix Polyline can't be removed after applying on vector
MrStevns Jul 20, 2023
3154b7c
Fix transformed selection was being painted in wrong order
MrStevns Jul 20, 2023
650ef97
Cleanup after testing
MrStevns Jul 20, 2023
6ac8c5f
Fix tabletRestorePrevTool would always ask for a full canvas update
MrStevns Jul 21, 2023
b8ef656
Remove unnecessary clear of cache when setting tool
MrStevns Jul 22, 2023
2fdc29d
Fix update artifacts when using dotted cursor
MrStevns Jul 23, 2023
856f509
Refactor TiledBuffer
MrStevns Jul 23, 2023
2c3bcc1
Some cleanup
J5lx Aug 9, 2023
9900f70
Remove redundant clear of tile before deleting it
MrStevns Aug 11, 2023
1a29932
Update signal/slot naming convention
MrStevns Aug 11, 2023
c27e00f
Merge branch 'master' into painting-blitting-improvements-v2
MrStevns Aug 13, 2023
239dc18
Apply some refactoring to tile
MrStevns Aug 15, 2023
836e34f
Fix blitRect::extend would make tiles odd numbered
MrStevns Aug 29, 2023
dd06086
Remove unused methods
MrStevns Aug 29, 2023
adcb3c1
Avoid invalidating cache till we're done drawing
MrStevns Aug 29, 2023
3566a5a
Remove various dead code from ScribbleArea
J5lx Sep 17, 2023
1f6d93c
Fix ScribbleArea repaint when tiled buffer does not cover update rect
J5lx Sep 17, 2023
e79a399
Merge pull request #21 from J5lx/MrStevns/painting-blitting-improveme…
MrStevns Sep 18, 2023
a9dd203
Fix canvas pixmap being too big when using devicePixelRatio > 1
MrStevns Sep 24, 2023
25624da
Merge branch 'master' into painting-blitting-improvements-v2
MrStevns Sep 24, 2023
70fb576
Try to fix seams appearing in Qt 6
MrStevns Sep 28, 2023
7f9687d
Fix canvas not being updated when using camera tool
MrStevns Sep 29, 2023
2ceed46
Cleanup CanvasPainter
MrStevns Sep 29, 2023
03ba9fa
Adjust blitRect explanation
MrStevns Sep 29, 2023
f3501ca
Remove the need to allocate an empty QPointF to draw pixmaps
MrStevns Sep 29, 2023
ad0afdf
TiledBuffer: Remove unused signals
MrStevns Sep 29, 2023
a7199f8
Fix typo
MrStevns Sep 30, 2023
ed2be11
Fix compiler warning
J5lx Sep 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions core_lib/src/canvaspainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ void CanvasPainter::reset()
{
mPostLayersPixmap = QPixmap(mCanvas.size());
mPreLayersPixmap = QPixmap(mCanvas.size());
mCurrentLayerPixmap = QPixmap(mCanvas.size());
mOnionSkinPixmap = QPixmap(mCanvas.size());
mPreLayersPixmap.fill(Qt::transparent);
mCanvas.fill(Qt::transparent);
mCurrentLayerPixmap = QPixmap(mCanvas.size());
mCurrentLayerPixmap.fill(Qt::transparent);
mPostLayersPixmap.fill(Qt::transparent);
mOnionSkinPixmap = QPixmap(mCanvas.size());
mOnionSkinPixmap.fill(Qt::transparent);
mCurrentLayerPixmap.setDevicePixelRatio(mCanvas.devicePixelRatioF());
mPreLayersPixmap.setDevicePixelRatio(mCanvas.devicePixelRatioF());
mPostLayersPixmap.setDevicePixelRatio(mCanvas.devicePixelRatioF());
mOnionSkinPixmap.setDevicePixelRatio(mCanvas.devicePixelRatioF());
}

void CanvasPainter::setViewTransform(const QTransform view, const QTransform viewInverse)
Expand Down Expand Up @@ -93,7 +97,7 @@ void CanvasPainter::paintCached(const QRect& blitRect)
QPainter mainPainter;
initializePainter(mainPainter, mCanvas, blitRect);
mainPainter.setWorldMatrixEnabled(false);
mainPainter.drawPixmap(blitRect, mPreLayersPixmap, blitRect);
mainPainter.drawPixmap(QPointF(), mPreLayersPixmap);
mainPainter.setWorldMatrixEnabled(true);

paintCurrentFrame(mainPainter, blitRect, mCurrentLayerIndex, mCurrentLayerIndex);
Expand All @@ -108,7 +112,7 @@ void CanvasPainter::paintCached(const QRect& blitRect)
}

mainPainter.setWorldMatrixEnabled(false);
mainPainter.drawPixmap(blitRect, mPostLayersPixmap, blitRect);
mainPainter.drawPixmap(QPointF(), mPostLayersPixmap);
mainPainter.setWorldMatrixEnabled(true);
}

Expand All @@ -122,6 +126,9 @@ void CanvasPainter::initializePainter(QPainter& painter, QPaintDevice& device, c
{
painter.begin(&device);

// Only draw inside the clipped rectangle
painter.setClipRect(blitRect);

// Clear the area that's about to be painted again, to avoid painting on top of existing pixels
// causing artifacts.
painter.setCompositionMode(QPainter::CompositionMode_Clear);
Expand Down Expand Up @@ -177,7 +184,7 @@ void CanvasPainter::paint(const QRect& blitRect)
preLayerPainter.end();

mainPainter.setWorldMatrixEnabled(false);
mainPainter.drawPixmap(blitRect, mPreLayersPixmap, blitRect);
mainPainter.drawPixmap(QPointF(), mPreLayersPixmap);
mainPainter.setWorldMatrixEnabled(true);

paintCurrentFrame(mainPainter, blitRect, mCurrentLayerIndex, mCurrentLayerIndex);
Expand All @@ -187,7 +194,7 @@ void CanvasPainter::paint(const QRect& blitRect)
postLayerPainter.end();

mainPainter.setWorldMatrixEnabled(false);
mainPainter.drawPixmap(blitRect, mPostLayersPixmap, blitRect);
mainPainter.drawPixmap(QPointF(), mPostLayersPixmap);
mainPainter.setWorldMatrixEnabled(true);

mPreLayersPixmapCacheValid = true;
Expand Down Expand Up @@ -273,7 +280,7 @@ void CanvasPainter::paintOnionSkinFrame(QPainter& painter, QPainter& onionSkinPa
onionSkinPainter.setBrush(colorBrush);
onionSkinPainter.drawRect(painter.viewport());
}
painter.drawPixmap(blitRect, mOnionSkinPixmap, blitRect);
painter.drawPixmap(QPointF(), mOnionSkinPixmap);
}

void CanvasPainter::paintCurrentBitmapFrame(QPainter& painter, const QRect& blitRect, Layer* layer, bool isCurrentLayer)
Expand Down Expand Up @@ -320,7 +327,8 @@ void CanvasPainter::paintCurrentBitmapFrame(QPainter& painter, const QRect& blit
paintTransformedSelection(currentBitmapPainter, paintedImage, mSelection);
}

painter.drawPixmap(blitRect, mCurrentLayerPixmap, blitRect);
// painter.setClipRect(blitRect);
J5lx marked this conversation as resolved.
Show resolved Hide resolved
painter.drawPixmap(QPointF(), mCurrentLayerPixmap);
}

void CanvasPainter::paintCurrentVectorFrame(QPainter& painter, const QRect& blitRect, Layer* layer, bool isCurrentLayer)
Expand Down Expand Up @@ -357,9 +365,10 @@ void CanvasPainter::paintCurrentVectorFrame(QPainter& painter, const QRect& blit
painter.setWorldMatrixEnabled(false);
painter.setTransform(QTransform());

// painter.setClipRect(blitRect);
J5lx marked this conversation as resolved.
Show resolved Hide resolved
// Remember to adjust opacity based on additional opacity value from the keyframe
painter.setOpacity(vectorImage->getOpacity() - (1.0-painter.opacity()));
painter.drawPixmap(blitRect, mCurrentLayerPixmap, blitRect);
painter.drawPixmap(QPointF(), mCurrentLayerPixmap);
}

void CanvasPainter::paintTransformedSelection(QPainter& painter, BitmapImage* bitmapImage, const QRect& selection) const
Expand Down
7 changes: 3 additions & 4 deletions core_lib/src/interface/scribblearea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void ScribbleArea::onTileUpdated(TiledBuffer* tiledBuffer, Tile* tile)
{
Q_UNUSED(tiledBuffer);
const QRectF& mappedRect = mEditor->view()->getView().mapRect(QRectF(tile->bounds()));
update(mappedRect.toRect());
update(mappedRect.toAlignedRect());
}

void ScribbleArea::onTileCreated(TiledBuffer* tiledBuffer, Tile* tile)
Expand All @@ -213,7 +213,7 @@ void ScribbleArea::onTileCreated(TiledBuffer* tiledBuffer, Tile* tile)
}

const QRectF& mappedRect = mEditor->view()->getView().mapRect(QRectF(tile->bounds()));
update(mappedRect.toRect());
update(mappedRect.toAlignedRect());
}

void ScribbleArea::updateFrame()
Expand Down Expand Up @@ -819,7 +819,7 @@ void ScribbleArea::resizeEvent(QResizeEvent* event)
QWidget::resizeEvent(event);
mDevicePixelRatio = devicePixelRatioF();
mCanvas = QPixmap(QSizeF(size() * mDevicePixelRatio).toSize());

mCanvas.setDevicePixelRatio(mDevicePixelRatio);
mEditor->view()->setCanvasSize(size());

invalidateCacheForFrame(mEditor->currentFrame());
Expand Down Expand Up @@ -1236,7 +1236,6 @@ void ScribbleArea::prepCanvas(int frame, QRect rect)

void ScribbleArea::drawCanvas(int frame, QRect rect)
{
mCanvas.setDevicePixelRatio(mDevicePixelRatio);
prepCanvas(frame, rect);
prepCameraPainter(frame);
prepOverlays(frame);
Expand Down