Skip to content

Commit a2036e6

Browse files
committed
Improve dialog performance, especially on Linux
1 parent 6550b55 commit a2036e6

File tree

3 files changed

+15
-26
lines changed

3 files changed

+15
-26
lines changed

Source/NVGSurface.cpp

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -412,29 +412,23 @@ void NVGSurface::renderFrameToImage(Image& image, Rectangle<int> area)
412412
auto bufferSize = fbHeight * fbWidth;
413413
if (bufferSize != backupPixelData.size())
414414
backupPixelData.resize(bufferSize);
415-
nvgReadPixels(nvg, invalidFBO->image, 0, 0, fbWidth, fbHeight, backupPixelData.data()); // TODO: would be nice to read only a part of the image, but that gets tricky with openGL
415+
416+
auto region = area.getIntersection(getLocalBounds()) * getRenderScale();
417+
nvgReadPixels(nvg, invalidFBO, region.getX(), region.getY(), region.getWidth(), region.getHeight(), fbHeight, backupPixelData.data());
416418

417419
if (!image.isValid() || image.getWidth() != fbWidth || image.getHeight() != fbHeight) {
418420
image = Image(Image::PixelFormat::ARGB, fbWidth, fbHeight, true);
419421
}
420422
Image::BitmapData imageData(image, Image::BitmapData::readOnly);
421423

422-
int width = imageData.width;
423-
int height = imageData.height;
424-
425-
auto region = area.getIntersection(getLocalBounds()) * getRenderScale();
426-
for (int y = 0; y < height; ++y) {
427-
if (y < region.getY() || y > region.getBottom())
428-
continue;
429-
auto* scanLine = (uint32*)imageData.getLinePointer(y);
430-
for (int x = 0; x < width; ++x) {
431-
if (x < region.getX() || x > region.getRight())
432-
continue;
424+
for (int y = 0; y < region.getHeight(); y++) {
425+
auto* scanLine = (uint32*)imageData.getLinePointer(y + region.getY());
426+
for (int x = 0; x < region.getWidth(); x++) {
433427
#if NANOVG_GL_IMPLEMENTATION
434428
// OpenGL images are upside down
435-
uint32 argb = backupPixelData[(height - (y + 1)) * width + x];
429+
uint32 argb = backupPixelData[(region.getHeight() - (y + 1)) * region.getWidth() + x];
436430
#else
437-
uint32 argb = backupPixelData[y * width + x];
431+
uint32 argb = backupPixelData[y * region.getWidth() + x];
438432
#endif
439433
uint8 a = argb >> 24;
440434
uint8 r = argb >> 16;
@@ -443,13 +437,13 @@ void NVGSurface::renderFrameToImage(Image& image, Rectangle<int> area)
443437

444438
// order bytes as abgr
445439
#if NANOVG_GL_IMPLEMENTATION
446-
scanLine[x] = (a << 24) | (b << 16) | (g << 8) | r;
440+
scanLine[x + region.getX()] = (a << 24) | (b << 16) | (g << 8) | r;
447441
#else
448-
scanLine[x] = (a << 24) | (r << 16) | (g << 8) | b;
442+
scanLine[x + region.getX()] = (a << 24) | (r << 16) | (g << 8) | b;
449443
#endif
450444
}
451445
}
452-
446+
453447
backupImageComponent.setVisible(true);
454448
backupImageComponent.setImage(image);
455449
backupImageComponent.repaint();
@@ -459,12 +453,6 @@ void NVGSurface::setRenderThroughImage(bool shouldRenderThroughImage)
459453
{
460454
renderThroughImage = shouldRenderThroughImage;
461455
invalidateAll();
462-
463-
#if JUCE_LINUX
464-
detachContext();
465-
initialise();
466-
#endif
467-
468456
updateWindowContextVisibility();
469457
}
470458

Source/NVGSurface.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,16 @@ class NVGSurface :
7676
auto invalidatedBounds = surface.getLocalArea(originComponent, rect.expanded(2).toFloat()).getSmallestIntegerContainer();
7777
surface.invalidateArea(invalidatedBounds);
7878
}
79-
return passEvents;
79+
80+
return surface.renderThroughImage || passEvents;
8081
}
8182

8283
bool invalidateAll() override
8384
{
8485
if (originComponent->isVisible()) {
8586
surface.invalidateArea(originComponent->getLocalBounds());
8687
}
87-
return passEvents;
88+
return surface.renderThroughImage || passEvents;
8889
}
8990

9091
void releaseResources() override { };

0 commit comments

Comments
 (0)