Skip to content

Commit

Permalink
8297681: Unnecessary color conversion during 4BYTE_ABGR_PRE to INT_AR…
Browse files Browse the repository at this point in the history
…GB_PRE blit

Reviewed-by: prr
  • Loading branch information
mrserb committed Nov 30, 2022
1 parent abe532a commit 8ffed34
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -69,6 +69,8 @@ DECLARE_SRCOVER_MASKBLIT(IntArgb, FourByteAbgrPre);
DECLARE_ALPHA_MASKBLIT(IntArgb, FourByteAbgrPre);
DECLARE_SRCOVER_MASKBLIT(IntArgbPre, FourByteAbgrPre);
DECLARE_ALPHA_MASKBLIT(IntArgbPre, FourByteAbgrPre);
DECLARE_SRCOVER_MASKBLIT(FourByteAbgrPre, IntArgbPre);
DECLARE_ALPHA_MASKBLIT(FourByteAbgrPre, IntArgbPre);
DECLARE_ALPHA_MASKBLIT(IntRgb, FourByteAbgrPre);
DECLARE_SOLID_DRAWGLYPHLISTAA(FourByteAbgrPre);
DECLARE_SOLID_DRAWGLYPHLISTLCD(FourByteAbgrPre);
Expand Down Expand Up @@ -103,6 +105,8 @@ NativePrimitive FourByteAbgrPrePrimitives[] = {
REGISTER_ALPHA_MASKBLIT(IntArgb, FourByteAbgrPre),
REGISTER_SRCOVER_MASKBLIT(IntArgbPre, FourByteAbgrPre),
REGISTER_ALPHA_MASKBLIT(IntArgbPre, FourByteAbgrPre),
REGISTER_SRCOVER_MASKBLIT(FourByteAbgrPre, IntArgbPre),
REGISTER_ALPHA_MASKBLIT(FourByteAbgrPre, IntArgbPre),
REGISTER_ALPHA_MASKBLIT(IntRgb, FourByteAbgrPre),
REGISTER_SOLID_DRAWGLYPHLISTAA(FourByteAbgrPre),
REGISTER_SOLID_DRAWGLYPHLISTLCD(FourByteAbgrPre),
Expand Down Expand Up @@ -177,6 +181,10 @@ DEFINE_SRCOVER_MASKBLIT(IntArgbPre, FourByteAbgrPre, 4ByteArgb)

DEFINE_ALPHA_MASKBLIT(IntArgbPre, FourByteAbgrPre, 4ByteArgb)

DEFINE_SRCOVER_MASKBLIT(FourByteAbgrPre, IntArgbPre, 4ByteArgb)

DEFINE_ALPHA_MASKBLIT(FourByteAbgrPre, IntArgbPre, 4ByteArgb)

DEFINE_ALPHA_MASKBLIT(IntRgb, FourByteAbgrPre, 4ByteArgb)

DEFINE_SOLID_DRAWGLYPHLISTAA(FourByteAbgrPre, 4ByteArgb)
Expand Down
89 changes: 89 additions & 0 deletions test/jdk/sun/java2d/loops/SkipConversionIfPossible.java
@@ -0,0 +1,89 @@
/*
* Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.util.Arrays;

import static java.awt.image.BufferedImage.TYPE_3BYTE_BGR;
import static java.awt.image.BufferedImage.TYPE_4BYTE_ABGR;
import static java.awt.image.BufferedImage.TYPE_4BYTE_ABGR_PRE;
import static java.awt.image.BufferedImage.TYPE_INT_ARGB;
import static java.awt.image.BufferedImage.TYPE_INT_ARGB_PRE;
import static java.awt.image.BufferedImage.TYPE_INT_BGR;
import static java.awt.image.BufferedImage.TYPE_INT_RGB;

/**
* @test
* @bug 8297681
* @summary The blit TYPE_4BYTE_ABGR_PRE to TYPE_INT_ARGB_PRE should be "direct"
*/
public final class SkipConversionIfPossible {

private static final int SIZE = 256;

public static void main(String[] args) {
// Initial bug was in the TYPE_4BYTE_ABGR_PRE to TYPE_INT_ARGB_PRE blit.
// But I checked other blits just in case.
test(new int[]{TYPE_INT_ARGB_PRE, TYPE_4BYTE_ABGR_PRE});
test(new int[]{TYPE_INT_RGB, TYPE_INT_BGR, TYPE_3BYTE_BGR});
test(new int[]{TYPE_INT_ARGB, TYPE_4BYTE_ABGR});
}

private static void test(int[] types) {
for (int src : types) {
for (int dst : types) {
render(src, dst);
}
}
}

private static void render(int src, int dst) {
BufferedImage from = new BufferedImage(SIZE, SIZE, src);
for (int a = 0; a < SIZE; ++a) {
for (int c = 0; c < SIZE; ++c) {
// The data is intentionally broken for the argb_pre format, but
// it should be stored as is in dst if no conversion was done.
from.getRaster().setPixel(c, a, new int[]{c, c << 24, -c, a});
}
}
BufferedImage to = new BufferedImage(SIZE, SIZE, dst);
Graphics2D g = to.createGraphics();
g.setComposite(AlphaComposite.Src);
g.drawImage(from, 0, 0, null);
g.dispose();

for (int a = 0; a < SIZE; ++a) {
for (int c = 0; c < SIZE; ++c) {
int[] pixel1 = from.getRaster().getPixel(c, a, (int[]) null);
int[] pixel2 = to.getRaster().getPixel(c, a, (int[]) null);
if (!Arrays.equals(pixel1, pixel2)) {
System.err.println(Arrays.toString(pixel1));
System.err.println(Arrays.toString(pixel2));
throw new RuntimeException();
}
}
}
}
}

5 comments on commit 8ffed34

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrserb
Copy link
Member Author

@mrserb mrserb commented on 8ffed34 May 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 8ffed34 May 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrserb the backport was successfully created on the branch mrserb-backport-8ffed34e in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 8ffed34e from the openjdk/jdk repository.

The commit being backported was authored by Sergey Bylokhov on 30 Nov 2022 and was reviewed by Phil Race.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev.git mrserb-backport-8ffed34e:mrserb-backport-8ffed34e
$ git checkout mrserb-backport-8ffed34e
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev.git mrserb-backport-8ffed34e

@mrserb
Copy link
Member Author

@mrserb mrserb commented on 8ffed34 Jul 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 8ffed34 Jul 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrserb the backport was successfully created on the branch mrserb-backport-8ffed34e in my personal fork of openjdk/jdk11u-dev. To create a pull request with this backport targeting openjdk/jdk11u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 8ffed34e from the openjdk/jdk repository.

The commit being backported was authored by Sergey Bylokhov on 30 Nov 2022 and was reviewed by Phil Race.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk11u-dev:

$ git fetch https://github.com/openjdk-bots/jdk11u-dev.git mrserb-backport-8ffed34e:mrserb-backport-8ffed34e
$ git checkout mrserb-backport-8ffed34e
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk11u-dev.git mrserb-backport-8ffed34e

Please sign in to comment.