1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Direct2DImage: Sync CPU storage when creating a BitmapData view over a subsection of the image

When syncing from CPU->GPU storage, we currently copy the entire image
contents. The contents of the CPU backup completely replace the old GPU
image. Therefore, if any pixels need to retain their existing values, we
need to read those pixels before overwriting them. This in turn implies
that, when a BitmapData refers to a subsection of the image, we should
always flush GPU->CPU storage first, so that the subsequent CPU->GPU
sync doesn't clobber pixels outside of the BitmapData region with
outdated values.

It's clear that copying the entire image back and forth could be
suboptimal when writing to image subsections, but to optimise this
process we'd have to keep track of dirty image regions or similar, which
may in turn pessimise more common cases.
This commit is contained in:
reuk 2025-05-27 13:57:36 +01:00
parent 4012677fdf
commit 415aed4bea
No known key found for this signature in database

View file

@ -764,8 +764,11 @@ void Direct2DPixelData::initialiseBitmapData (Image::BitmapData& bitmap,
// If we're about to read from the image, and the main-memory copy of the image is outdated,
// then we must force a backup so that we can return up-to-date data
if (mode != Image::BitmapData::writeOnly && state == State::outdated)
if (mode != Image::BitmapData::writeOnly
|| Rectangle { x, y, bitmap.width, bitmap.height } != Rectangle { width, height })
{
createPersistentBackup (nullptr);
}
backingData->initialiseBitmapData (bitmap, x, y, mode);