8354191: GTK LaF should use pre-multiplied alpha same as cairo

Reviewed-by: avu, prr
This commit is contained in:
Maxim Kartashev 2025-04-17 06:59:01 +00:00 committed by Alexey Ushakov
parent e00355a036
commit a4e9da3747

View File

@ -532,14 +532,7 @@ class GTKEngine {
native_paint_background(widget, state, x - x0, y - y0, w, h);
}
private static final ColorModel[] COLOR_MODELS = {
// Transparency.OPAQUE
new DirectColorModel(24, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000),
// Transparency.BITMASK
new DirectColorModel(25, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x01000000),
// Transparency.TRANSLUCENT
ColorModel.getRGBdefault(),
};
private static final ColorModel[] COLOR_MODELS = new ColorModel[3];
private static final int[][] BAND_OFFSETS = {
{ 0x00ff0000, 0x0000ff00, 0x000000ff }, // OPAQUE
@ -609,8 +602,8 @@ class GTKEngine {
WritableRaster raster = Raster.createPackedRaster(
dataBuffer, w0, h0, w0, bands, null);
ColorModel cm = COLOR_MODELS[transparency - 1];
BufferedImage img = new BufferedImage(cm, raster, false, null);
ColorModel cm = colorModelFor(transparency);
BufferedImage img = new BufferedImage(cm, raster, true, null);
if (useCache) {
cache.setImage(getClass(), null, w0, h0, cacheArgs, img);
}
@ -618,6 +611,18 @@ class GTKEngine {
return img;
}
private ColorModel colorModelFor(int transparency) {
synchronized (COLOR_MODELS) {
int index = transparency - 1;
if (COLOR_MODELS[index] == null) {
COLOR_MODELS[index] = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice().getDefaultConfiguration()
.getColorModel(transparency);
}
return COLOR_MODELS[index];
}
}
/**
* Notify native layer of theme change, and flush cache
*/