Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2022-01-17 20:02:29 +0300
committerJulian Eisel <julian@blender.org>2022-01-17 20:26:10 +0300
commitaa0ecd17918d5f1c3ce684f8f14b6aa7080ea9e1 (patch)
treeda4beec20121acc32c54683a39277665f9f31633 /source/blender/editors/interface
parent4d10a46e6368f0b48a901325b94ebd43b672db32 (diff)
UI: Speed up icon scaling
Use GPU-side scaling to speed up the scaling itself, and to avoid having to copy the image buffer using the CPU. Mipmapping is used to get decent filtering when downscaling without ugly artifacts. In my comparisons, there was barely any difference between the methods for DPIs >= 1. Below that, the result looks a bit different due to the different filtering method. See D13144 for screen-recordings showing the difference. Part of T92922. Differential Revision: https://developer.blender.org/D13144 Reviewed by: Jeroen Bakker
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r--source/blender/editors/interface/interface_icons.c21
1 files changed, 7 insertions, 14 deletions
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index ca5d08ba40e..085b7d04be9 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -1546,7 +1546,7 @@ static void icon_draw_rect_fast(float x,
immUniform1f("factor", desaturate);
}
- immDrawPixelsTexScaled(
+ immDrawPixelsTexScaledFullSize(
&state, draw_x, draw_y, rw, rh, GPU_RGBA8, true, rect, scale_x, scale_y, 1.0f, 1.0f, col);
}
@@ -1561,7 +1561,6 @@ static void icon_draw_rect(float x,
float alpha,
const float desaturate)
{
- ImBuf *ima = NULL;
int draw_w = w;
int draw_h = h;
int draw_x = x;
@@ -1577,6 +1576,8 @@ static void icon_draw_rect(float x,
/* modulate color */
const float col[4] = {alpha, alpha, alpha, alpha};
+ float scale_x = 1.0f;
+ float scale_y = 1.0f;
/* rect contains image in 'rendersize', we only scale if needed */
if (rw != w || rh != h) {
/* preserve aspect ratio and center */
@@ -1590,13 +1591,9 @@ static void icon_draw_rect(float x,
draw_h = h;
draw_x += (w - draw_w) / 2;
}
+ scale_x = draw_w / (float)rw;
+ scale_y = draw_h / (float)rh;
/* If the image is squared, the `draw_*` initialization values are good. */
-
- /* first allocate imbuf for scaling and copy preview into it */
- ima = IMB_allocImBuf(rw, rh, 32, IB_rect);
- memcpy(ima->rect, rect, rw * rh * sizeof(uint));
- IMB_scaleImBuf(ima, draw_w, draw_h); /* scale it */
- rect = ima->rect;
}
/* draw */
@@ -1613,12 +1610,8 @@ static void icon_draw_rect(float x,
immUniform1f("factor", desaturate);
}
- immDrawPixelsTex(
- &state, draw_x, draw_y, draw_w, draw_h, GPU_RGBA8, false, rect, 1.0f, 1.0f, col);
-
- if (ima) {
- IMB_freeImBuf(ima);
- }
+ immDrawPixelsTexScaledFullSize(
+ &state, draw_x, draw_y, rw, rh, GPU_RGBA8, true, rect, scale_x, scale_y, 1.0f, 1.0f, col);
}
/* High enough to make a difference, low enough so that