Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
askmeaboutlo0m committed Sep 6, 2023
1 parent abaf31f commit e7219de
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/drawdance/libengine/dpengine/draw_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@ DP_DrawContext *DP_draw_context_new(void)
DP_DrawContext *dc = DP_malloc_simd(sizeof(*dc));
dc->pool_size = 0;
dc->pool = NULL;
DP_warn("Allocate draw context %p", (void *)dc);
return dc;
}

void DP_draw_context_free(DP_DrawContext *dc)
{
if (dc) {
DP_warn("Free draw context %p", (void *)dc);
DP_free(dc->pool);
DP_free_simd(dc);
}
Expand Down Expand Up @@ -203,8 +205,12 @@ unsigned char *DP_draw_context_raster_pool_resize(DP_DrawContext *dc,
{
DP_ASSERT(dc);
DP_ASSERT(new_size > dc->pool_size);
DP_ASSERT(new_size < DP_DRAW_CONTEXT_RASTER_POOL_MAX_SIZE);
DP_ASSERT(new_size <= DP_DRAW_CONTEXT_RASTER_POOL_MAX_SIZE);
DP_ASSERT(dc->pool);
DP_warn("Raster pool resize form %zu to %zu (min %zu/max %zu)",
dc->pool_size, new_size,
(size_t)DP_DRAW_CONTEXT_RASTER_POOL_MIN_SIZE,
(size_t)DP_DRAW_CONTEXT_RASTER_POOL_MAX_SIZE);
DP_free(dc->pool);
void *new_raster_pool = DP_malloc(new_size);
dc->pool = new_raster_pool;
Expand Down
1 change: 1 addition & 0 deletions src/drawdance/libengine/dpengine/paint_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -2364,6 +2364,7 @@ void DP_paint_engine_preview_transform(
DP_canvas_state_height(cs), offset_x, offset_y);
}
else {
DP_warn("Invalid transform preview dimensions %dx%d", width, height);
dispose_pixels(user);
DP_paint_engine_preview_clear(pe, DP_PREVIEW_TRANSFORM);
}
Expand Down
1 change: 1 addition & 0 deletions src/drawdance/libengine/dpengine/preview.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ static bool preview_transform_prepare_image(DP_PreviewTransform *pvtf,
pvtf->pixels.dispose = NULL;

if (img) {
DP_warn("Transformed on layer %d", pvtf->target_layer_id);
pvtf->img = img;
return true;
}
Expand Down
7 changes: 7 additions & 0 deletions src/libclient/canvas/canvasmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,9 @@ void CanvasModel::setSelection(Selection *selection)

QImage CanvasModel::selectionToImage(int layerId) const
{
qInfo("selectionToImage(%d)", layerId);
if(m_selection && !m_selection->pasteImage().isNull()) {
qInfo("selectionToImage: paste image already exists");
return m_selection->transformedPasteImage();
}

Expand All @@ -370,10 +372,13 @@ QImage CanvasModel::selectionToImage(int layerId) const
return QImage{};
}

qInfo("selectionToImage: x%d y%d w%d h%d", rect.x(), rect.y(), rect.width(), rect.height());
QImage img;
if(layerId == 0) {
qInfo("selectionToImage: with background to image");
img = canvasState.toFlatImage(true, true, &rect);
} else if(layerId == -1) {
qInfo("selectionToImage: without background to image");
img = canvasState.toFlatImage(false, true, &rect);
} else {
drawdance::LayerContent layerContent = canvasState.searchLayerContent(layerId);
Expand All @@ -383,10 +388,12 @@ QImage CanvasModel::selectionToImage(int layerId) const
img.fill(0);
return img;
}
qInfo("selectionToImage: layer %d to image", layerId);
img = layerContent.toImage(rect);
}

if(m_selection && !m_selection->isAxisAlignedRectangle()) {
qInfo("selectionToImage: mask outside pixels");
// Mask out pixels outside the selection
QPainter mp(&img);
mp.setCompositionMode(QPainter::CompositionMode_DestinationIn);
Expand Down
7 changes: 4 additions & 3 deletions src/libclient/drawdance/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ DrawContext DrawContextPool::acquireContext()
DP_DrawContext *dc;
if(m_available.isEmpty()) {
dc = DP_draw_context_new();
m_contexts.append(dc);
// m_contexts.append(dc);
} else {
dc = m_available.pop();
}
Expand All @@ -141,8 +141,9 @@ DrawContext DrawContextPool::acquireContext()
void DrawContextPool::releaseContext(DP_DrawContext *dc)
{
Q_ASSERT(dc);
QMutexLocker locker{&m_mutex};
m_available.push(dc);
// QMutexLocker locker{&m_mutex};
// m_available.push(dc);
DP_draw_context_free(dc);
}

DrawContextPoolStatistics DrawContextPool::instanceStatistics()
Expand Down
11 changes: 9 additions & 2 deletions src/libclient/tools/selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,16 @@ void SelectionTool::startMove()

// Copy layer content into move preview buffer.
int layerId = m_owner.activeLayer();
const QImage img = model->selectionToImage(layerId);
sel->setMoveImage(img, maskBounds, model->size(), layerId);
QImage img = model->selectionToImage(layerId);
if(img.isNull()) {
qWarning("startMove: selected image is null");
return;
} else {
img = QImage{img.size(), QImage::Format_ARGB32_Premultiplied};
img.fill(Qt::red);
}

sel->setMoveImage(img, maskBounds, model->size(), layerId);
// The actual canvas pixels aren't touch yet, so we create a temporary sublayer
// to erase the selected region.
model->paintEngine()->previewCut(layerId, maskBounds, eraseMask);
Expand Down
3 changes: 3 additions & 0 deletions src/libclient/tools/toolcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,17 +236,20 @@ void ToolController::onSelectionChange(canvas::Selection *sel)
void ToolController::updateSelectionPreview()
{
if(!m_model) {
qInfo("updateSelectionPreview: no model set");
return;
}

canvas::PaintEngine *paintEngine = m_model->paintEngine();
canvas::Selection *sel = m_model->selection();
if(sel && sel->hasPasteImage()) {
qInfo("updateSelectionPreview: preview transform");
QPoint point = sel->shape().boundingRect().topLeft().toPoint();
paintEngine->previewTransform(
m_activeLayer, point.x(), point.y(), sel->pasteImage(),
sel->destinationQuad(), m_selectInterpolation);
} else {
qInfo("updateSelectionPreview: clear preview transform");
paintEngine->clearTransformPreview();
}
}
Expand Down

0 comments on commit e7219de

Please sign in to comment.