Java Code Examples for sun.java2d.pipe.Region#clipScale()

The following examples show how to use sun.java2d.pipe.Region#clipScale() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SunGraphics2D.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private boolean drawHiDPIImage(Image img, int dx1, int dy1, int dx2,
                               int dy2, int sx1, int sy1, int sx2, int sy2,
                               Color bgcolor, ImageObserver observer) {
    final int scale = SurfaceManager.getImageScale(img);
    sx1 = Region.clipScale(sx1, scale);
    sx2 = Region.clipScale(sx2, scale);
    sy1 = Region.clipScale(sy1, scale);
    sy2 = Region.clipScale(sy2, scale);
    try {
        return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1, sy1,
                                    sx2, sy2, bgcolor, observer);
    } catch (InvalidPipeException e) {
        try {
            revalidateAll();
            return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1,
                                        sy1, sx2, sy2, bgcolor, observer);
        } catch (InvalidPipeException e2) {
            // Still catching the exception; we are not yet ready to
            // validate the surfaceData correctly.  Fail for now and
            // try again next time around.
            return false;
        }
    } finally {
        surfaceData.markDirty();
    }
}
 
Example 2
Source File: SunGraphics2D.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private boolean drawHiDPIImage(Image img, int dx1, int dy1, int dx2,
                               int dy2, int sx1, int sy1, int sx2, int sy2,
                               Color bgcolor, ImageObserver observer) {
    final int scale = SurfaceManager.getImageScale(img);
    sx1 = Region.clipScale(sx1, scale);
    sx2 = Region.clipScale(sx2, scale);
    sy1 = Region.clipScale(sy1, scale);
    sy2 = Region.clipScale(sy2, scale);
    try {
        return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1, sy1,
                                    sx2, sy2, bgcolor, observer);
    } catch (InvalidPipeException e) {
        try {
            revalidateAll();
            return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1,
                                        sy1, sx2, sy2, bgcolor, observer);
        } catch (InvalidPipeException e2) {
            // Still catching the exception; we are not yet ready to
            // validate the surfaceData correctly.  Fail for now and
            // try again next time around.
            return false;
        }
    } finally {
        surfaceData.markDirty();
    }
}
 
Example 3
Source File: IconInfo.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private static int[] getScaledWidthAndHeight(int width, int height) {
    AffineTransform tx = GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice().getDefaultConfiguration().
            getDefaultTransform();
    int w = Region.clipScale(width, tx.getScaleX());
    int h = Region.clipScale(height, tx.getScaleY());
    return new int[]{w, h};
}
 
Example 4
Source File: IconInfo.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static int[] getScaledWidthAndHeight(int width, int height) {
    AffineTransform tx = GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice().getDefaultConfiguration().
            getDefaultTransform();
    int w = Region.clipScale(width, tx.getScaleX());
    int h = Region.clipScale(height, tx.getScaleY());
    return new int[]{w, h};
}
 
Example 5
Source File: WTrayIconPeer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
synchronized void updateNativeImage(Image image) {
    if (isDisposed())
        return;

    boolean autosize = ((TrayIcon)target).isImageAutoSize();
    AffineTransform tx = GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice().getDefaultConfiguration().
            getDefaultTransform();
    int w = Region.clipScale(TRAY_ICON_WIDTH, tx.getScaleX());
    int h = Region.clipScale(TRAY_ICON_HEIGHT, tx.getScaleY());
    int imgWidth = Region.clipScale(image.getWidth(observer), tx.getScaleX());
    int imgHeight = Region.clipScale(image.getHeight(observer), tx.getScaleY());
    BufferedImage bufImage = new BufferedImage(w,
            h, BufferedImage.TYPE_INT_ARGB);
    Graphics2D gr = bufImage.createGraphics();
    if (gr != null) {
        try {
            gr.setPaintMode();

            gr.drawImage(image, 0, 0, (autosize ? w : imgWidth),
                         (autosize ? h : imgHeight), observer);

            createNativeImage(bufImage);

            updateNativeIcon(!firstUpdate);
            if (firstUpdate) firstUpdate = false;

        } finally {
            gr.dispose();
        }
    }
}
 
Example 6
Source File: WWindowPeer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void updateIconImages() {
    java.util.List<Image> imageList = ((Window)target).getIconImages();
    if (imageList == null || imageList.size() == 0) {
        setIconImagesData(null, 0, 0, null, 0, 0);
    } else {
        int w = getSysIconWidth();
        int h = getSysIconHeight();
        int smw = getSysSmIconWidth();
        int smh = getSysSmIconHeight();
        AffineTransform tx = getGraphicsConfiguration().getDefaultTransform();
        w = Region.clipScale(w, tx.getScaleX());
        h = Region.clipScale(h, tx.getScaleY());
        smw = Region.clipScale(smw, tx.getScaleX());
        smh = Region.clipScale(smh, tx.getScaleY());
        DataBufferInt iconData = SunToolkit.getScaledIconData(imageList,
                                                              w, h);
        DataBufferInt iconSmData = SunToolkit.getScaledIconData(imageList,
                                                                smw, smh);
        if (iconData != null && iconSmData != null) {
            setIconImagesData(iconData.getData(), w, h,
                              iconSmData.getData(), smw, smh);
        } else {
            setIconImagesData(null, 0, 0, null, 0, 0);
        }
    }
}
 
Example 7
Source File: SunGraphics2D.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private boolean drawHiDPIImage(Image img, int dx1, int dy1, int dx2,
                               int dy2, int sx1, int sy1, int sx2, int sy2,
                               Color bgcolor, ImageObserver observer) {

    if (SurfaceManager.getImageScale(img) != 1) {  // Volatile Image
        final int scale = SurfaceManager.getImageScale(img);
        sx1 = Region.clipScale(sx1, scale);
        sx2 = Region.clipScale(sx2, scale);
        sy1 = Region.clipScale(sy1, scale);
        sy2 = Region.clipScale(sy2, scale);
    } else if (img instanceof MultiResolutionImage) {
        // get scaled destination image size

        int width = img.getWidth(observer);
        int height = img.getHeight(observer);

        Image resolutionVariant = getResolutionVariant(
                (MultiResolutionImage) img, width, height,
                dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2);

        if (resolutionVariant != img && resolutionVariant != null) {
            // recalculate source region for the resolution variant

            ImageObserver rvObserver = MultiResolutionToolkitImage.
                    getResolutionVariantObserver(img, observer,
                            width, height, -1, -1);

            int rvWidth = resolutionVariant.getWidth(rvObserver);
            int rvHeight = resolutionVariant.getHeight(rvObserver);

            if (0 < width && 0 < height && 0 < rvWidth && 0 < rvHeight) {

                float widthScale = ((float) rvWidth) / width;
                float heightScale = ((float) rvHeight) / height;

                sx1 = Region.clipScale(sx1, widthScale);
                sy1 = Region.clipScale(sy1, heightScale);
                sx2 = Region.clipScale(sx2, widthScale);
                sy2 = Region.clipScale(sy2, heightScale);

                observer = rvObserver;
                img = resolutionVariant;
            }
        }
    }

    try {
        return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1, sy1,
                                    sx2, sy2, bgcolor, observer);
    } catch (InvalidPipeException e) {
        try {
            revalidateAll();
            return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1,
                                        sy1, sx2, sy2, bgcolor, observer);
        } catch (InvalidPipeException e2) {
            // Still catching the exception; we are not yet ready to
            // validate the surfaceData correctly.  Fail for now and
            // try again next time around.
            return false;
        }
    } finally {
        surfaceData.markDirty();
    }
}
 
Example 8
Source File: SunGraphics2D.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private boolean drawHiDPIImage(Image img, int dx1, int dy1, int dx2,
                               int dy2, int sx1, int sy1, int sx2, int sy2,
                               Color bgcolor, ImageObserver observer) {

    if (SurfaceManager.getImageScale(img) != 1) {  // Volatile Image
        final int scale = SurfaceManager.getImageScale(img);
        sx1 = Region.clipScale(sx1, scale);
        sx2 = Region.clipScale(sx2, scale);
        sy1 = Region.clipScale(sy1, scale);
        sy2 = Region.clipScale(sy2, scale);
    } else if (img instanceof MultiResolutionImage) {
        // get scaled destination image size

        int width = img.getWidth(observer);
        int height = img.getHeight(observer);

        Image resolutionVariant = getResolutionVariant(
                (MultiResolutionImage) img, width, height,
                dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2);

        if (resolutionVariant != img && resolutionVariant != null) {
            // recalculate source region for the resolution variant

            ImageObserver rvObserver = MultiResolutionToolkitImage.
                    getResolutionVariantObserver(img, observer,
                            width, height, -1, -1);

            int rvWidth = resolutionVariant.getWidth(rvObserver);
            int rvHeight = resolutionVariant.getHeight(rvObserver);

            if (0 < width && 0 < height && 0 < rvWidth && 0 < rvHeight) {

                float widthScale = ((float) rvWidth) / width;
                float heightScale = ((float) rvHeight) / height;

                sx1 = Region.clipScale(sx1, widthScale);
                sy1 = Region.clipScale(sy1, heightScale);
                sx2 = Region.clipScale(sx2, widthScale);
                sy2 = Region.clipScale(sy2, heightScale);

                observer = rvObserver;
                img = resolutionVariant;
            }
        }
    }

    try {
        return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1, sy1,
                                    sx2, sy2, bgcolor, observer);
    } catch (InvalidPipeException e) {
        try {
            revalidateAll();
            return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1,
                                        sy1, sx2, sy2, bgcolor, observer);
        } catch (InvalidPipeException e2) {
            // Still catching the exception; we are not yet ready to
            // validate the surfaceData correctly.  Fail for now and
            // try again next time around.
            return false;
        }
    } finally {
        surfaceData.markDirty();
    }
}
 
Example 9
Source File: SunGraphics2D.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private boolean drawHiDPIImage(Image img, int dx1, int dy1, int dx2,
                               int dy2, int sx1, int sy1, int sx2, int sy2,
                               Color bgcolor, ImageObserver observer) {

    if (SurfaceManager.getImageScale(img) != 1) {  // Volatile Image
        final int scale = SurfaceManager.getImageScale(img);
        sx1 = Region.clipScale(sx1, scale);
        sx2 = Region.clipScale(sx2, scale);
        sy1 = Region.clipScale(sy1, scale);
        sy2 = Region.clipScale(sy2, scale);
    } else if (img instanceof MultiResolutionImage) {
        // get scaled destination image size

        int width = img.getWidth(observer);
        int height = img.getHeight(observer);

        Image resolutionVariant = getResolutionVariant(
                (MultiResolutionImage) img, width, height,
                dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2);

        if (resolutionVariant != img && resolutionVariant != null) {
            // recalculate source region for the resolution variant

            ImageObserver rvObserver = MultiResolutionToolkitImage.
                    getResolutionVariantObserver(img, observer,
                            width, height, -1, -1);

            int rvWidth = resolutionVariant.getWidth(rvObserver);
            int rvHeight = resolutionVariant.getHeight(rvObserver);

            if (0 < width && 0 < height && 0 < rvWidth && 0 < rvHeight) {

                float widthScale = ((float) rvWidth) / width;
                float heightScale = ((float) rvHeight) / height;

                sx1 = Region.clipScale(sx1, widthScale);
                sy1 = Region.clipScale(sy1, heightScale);
                sx2 = Region.clipScale(sx2, widthScale);
                sy2 = Region.clipScale(sy2, heightScale);

                observer = rvObserver;
                img = resolutionVariant;
            }
        }
    }

    try {
        return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1, sy1,
                                    sx2, sy2, bgcolor, observer);
    } catch (InvalidPipeException e) {
        try {
            revalidateAll();
            return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1,
                                        sy1, sx2, sy2, bgcolor, observer);
        } catch (InvalidPipeException e2) {
            // Still catching the exception; we are not yet ready to
            // validate the surfaceData correctly.  Fail for now and
            // try again next time around.
            return false;
        }
    } finally {
        surfaceData.markDirty();
    }
}
 
Example 10
Source File: SunGraphics2D.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private boolean drawHiDPIImage(Image img, int dx1, int dy1, int dx2,
                               int dy2, int sx1, int sy1, int sx2, int sy2,
                               Color bgcolor, ImageObserver observer) {

    if (SurfaceManager.getImageScale(img) != 1) {  // Volatile Image
        final int scale = SurfaceManager.getImageScale(img);
        sx1 = Region.clipScale(sx1, scale);
        sx2 = Region.clipScale(sx2, scale);
        sy1 = Region.clipScale(sy1, scale);
        sy2 = Region.clipScale(sy2, scale);
    } else if (img instanceof MultiResolutionImage) {
        // get scaled destination image size

        int width = img.getWidth(observer);
        int height = img.getHeight(observer);

        Image resolutionVariant = getResolutionVariant(
                (MultiResolutionImage) img, width, height,
                dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2);

        if (resolutionVariant != img && resolutionVariant != null) {
            // recalculate source region for the resolution variant

            ImageObserver rvObserver = MultiResolutionToolkitImage.
                    getResolutionVariantObserver(img, observer,
                            width, height, -1, -1);

            int rvWidth = resolutionVariant.getWidth(rvObserver);
            int rvHeight = resolutionVariant.getHeight(rvObserver);

            if (0 < width && 0 < height && 0 < rvWidth && 0 < rvHeight) {

                float widthScale = ((float) rvWidth) / width;
                float heightScale = ((float) rvHeight) / height;

                sx1 = Region.clipScale(sx1, widthScale);
                sy1 = Region.clipScale(sy1, heightScale);
                sx2 = Region.clipScale(sx2, widthScale);
                sy2 = Region.clipScale(sy2, heightScale);

                observer = rvObserver;
                img = resolutionVariant;
            }
        }
    }

    try {
        return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1, sy1,
                                    sx2, sy2, bgcolor, observer);
    } catch (InvalidPipeException e) {
        try {
            revalidateAll();
            return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1,
                                        sy1, sx2, sy2, bgcolor, observer);
        } catch (InvalidPipeException e2) {
            // Still catching the exception; we are not yet ready to
            // validate the surfaceData correctly.  Fail for now and
            // try again next time around.
            return false;
        }
    } finally {
        surfaceData.markDirty();
    }
}
 
Example 11
Source File: SunGraphics2D.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private boolean drawHiDPIImage(Image img, int dx1, int dy1, int dx2,
                               int dy2, int sx1, int sy1, int sx2, int sy2,
                               Color bgcolor, ImageObserver observer) {

    if (SurfaceManager.getImageScale(img) != 1) {  // Volatile Image
        final int scale = SurfaceManager.getImageScale(img);
        sx1 = Region.clipScale(sx1, scale);
        sx2 = Region.clipScale(sx2, scale);
        sy1 = Region.clipScale(sy1, scale);
        sy2 = Region.clipScale(sy2, scale);
    } else if (img instanceof MultiResolutionImage) {
        // get scaled destination image size

        int width = img.getWidth(observer);
        int height = img.getHeight(observer);

        Image resolutionVariant = getResolutionVariant(
                (MultiResolutionImage) img, width, height,
                dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2);

        if (resolutionVariant != img && resolutionVariant != null) {
            // recalculate source region for the resolution variant

            ImageObserver rvObserver = MultiResolutionToolkitImage.
                    getResolutionVariantObserver(img, observer,
                            width, height, -1, -1);

            int rvWidth = resolutionVariant.getWidth(rvObserver);
            int rvHeight = resolutionVariant.getHeight(rvObserver);

            if (0 < width && 0 < height && 0 < rvWidth && 0 < rvHeight) {

                float widthScale = ((float) rvWidth) / width;
                float heightScale = ((float) rvHeight) / height;

                sx1 = Region.clipScale(sx1, widthScale);
                sy1 = Region.clipScale(sy1, heightScale);
                sx2 = Region.clipScale(sx2, widthScale);
                sy2 = Region.clipScale(sy2, heightScale);

                observer = rvObserver;
                img = resolutionVariant;
            }
        }
    }

    try {
        return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1, sy1,
                                    sx2, sy2, bgcolor, observer);
    } catch (InvalidPipeException e) {
        try {
            revalidateAll();
            return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1,
                                        sy1, sx2, sy2, bgcolor, observer);
        } catch (InvalidPipeException e2) {
            // Still catching the exception; we are not yet ready to
            // validate the surfaceData correctly.  Fail for now and
            // try again next time around.
            return false;
        }
    } finally {
        surfaceData.markDirty();
    }
}
 
Example 12
Source File: SunGraphics2D.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private boolean drawHiDPIImage(Image img, int dx1, int dy1, int dx2,
                               int dy2, int sx1, int sy1, int sx2, int sy2,
                               Color bgcolor, ImageObserver observer) {

    if (SurfaceManager.getImageScale(img) != 1) {  // Volatile Image
        final int scale = SurfaceManager.getImageScale(img);
        sx1 = Region.clipScale(sx1, scale);
        sx2 = Region.clipScale(sx2, scale);
        sy1 = Region.clipScale(sy1, scale);
        sy2 = Region.clipScale(sy2, scale);
    } else if (img instanceof MultiResolutionImage) {
        // get scaled destination image size

        int width = img.getWidth(observer);
        int height = img.getHeight(observer);

        Image resolutionVariant = getResolutionVariant(
                (MultiResolutionImage) img, width, height,
                dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2);

        if (resolutionVariant != img && resolutionVariant != null) {
            // recalculate source region for the resolution variant

            ImageObserver rvObserver = MultiResolutionToolkitImage.
                    getResolutionVariantObserver(img, observer,
                            width, height, -1, -1);

            int rvWidth = resolutionVariant.getWidth(rvObserver);
            int rvHeight = resolutionVariant.getHeight(rvObserver);

            if (0 < width && 0 < height && 0 < rvWidth && 0 < rvHeight) {

                float widthScale = ((float) rvWidth) / width;
                float heightScale = ((float) rvHeight) / height;

                sx1 = Region.clipScale(sx1, widthScale);
                sy1 = Region.clipScale(sy1, heightScale);
                sx2 = Region.clipScale(sx2, widthScale);
                sy2 = Region.clipScale(sy2, heightScale);

                observer = rvObserver;
                img = resolutionVariant;
            }
        }
    }

    try {
        return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1, sy1,
                                    sx2, sy2, bgcolor, observer);
    } catch (InvalidPipeException e) {
        try {
            revalidateAll();
            return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1,
                                        sy1, sx2, sy2, bgcolor, observer);
        } catch (InvalidPipeException e2) {
            // Still catching the exception; we are not yet ready to
            // validate the surfaceData correctly.  Fail for now and
            // try again next time around.
            return false;
        }
    } finally {
        surfaceData.markDirty();
    }
}
 
Example 13
Source File: SunGraphics2D.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private boolean drawHiDPIImage(Image img, int dx1, int dy1, int dx2,
                               int dy2, int sx1, int sy1, int sx2, int sy2,
                               Color bgcolor, ImageObserver observer) {

    if (SurfaceManager.getImageScale(img) != 1) {  // Volatile Image
        final int scale = SurfaceManager.getImageScale(img);
        sx1 = Region.clipScale(sx1, scale);
        sx2 = Region.clipScale(sx2, scale);
        sy1 = Region.clipScale(sy1, scale);
        sy2 = Region.clipScale(sy2, scale);
    } else if (img instanceof MultiResolutionImage) {
        // get scaled destination image size

        int width = img.getWidth(observer);
        int height = img.getHeight(observer);

        Image resolutionVariant = getResolutionVariant(
                (MultiResolutionImage) img, width, height,
                dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2);

        if (resolutionVariant != img && resolutionVariant != null) {
            // recalculate source region for the resolution variant

            ImageObserver rvObserver = MultiResolutionToolkitImage.
                    getResolutionVariantObserver(img, observer,
                            width, height, -1, -1);

            int rvWidth = resolutionVariant.getWidth(rvObserver);
            int rvHeight = resolutionVariant.getHeight(rvObserver);

            if (0 < width && 0 < height && 0 < rvWidth && 0 < rvHeight) {

                float widthScale = ((float) rvWidth) / width;
                float heightScale = ((float) rvHeight) / height;

                sx1 = Region.clipScale(sx1, widthScale);
                sy1 = Region.clipScale(sy1, heightScale);
                sx2 = Region.clipScale(sx2, widthScale);
                sy2 = Region.clipScale(sy2, heightScale);

                observer = rvObserver;
                img = resolutionVariant;
            }
        }
    }

    try {
        return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1, sy1,
                                    sx2, sy2, bgcolor, observer);
    } catch (InvalidPipeException e) {
        try {
            revalidateAll();
            return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1,
                                        sy1, sx2, sy2, bgcolor, observer);
        } catch (InvalidPipeException e2) {
            // Still catching the exception; we are not yet ready to
            // validate the surfaceData correctly.  Fail for now and
            // try again next time around.
            return false;
        }
    } finally {
        surfaceData.markDirty();
    }
}
 
Example 14
Source File: SunGraphics2D.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private boolean drawHiDPIImage(Image img, int dx1, int dy1, int dx2,
                               int dy2, int sx1, int sy1, int sx2, int sy2,
                               Color bgcolor, ImageObserver observer) {

    if (SurfaceManager.getImageScale(img) != 1) {  // Volatile Image
        final int scale = SurfaceManager.getImageScale(img);
        sx1 = Region.clipScale(sx1, scale);
        sx2 = Region.clipScale(sx2, scale);
        sy1 = Region.clipScale(sy1, scale);
        sy2 = Region.clipScale(sy2, scale);
    } else if (img instanceof MultiResolutionImage) {
        // get scaled destination image size

        int width = img.getWidth(observer);
        int height = img.getHeight(observer);

        Image resolutionVariant = getResolutionVariant(
                (MultiResolutionImage) img, width, height,
                dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2);

        if (resolutionVariant != img && resolutionVariant != null) {
            // recalculate source region for the resolution variant

            ImageObserver rvObserver = MultiResolutionToolkitImage.
                    getResolutionVariantObserver(img, observer,
                            width, height, -1, -1);

            int rvWidth = resolutionVariant.getWidth(rvObserver);
            int rvHeight = resolutionVariant.getHeight(rvObserver);

            if (0 < width && 0 < height && 0 < rvWidth && 0 < rvHeight) {

                float widthScale = ((float) rvWidth) / width;
                float heightScale = ((float) rvHeight) / height;

                sx1 = Region.clipScale(sx1, widthScale);
                sy1 = Region.clipScale(sy1, heightScale);
                sx2 = Region.clipScale(sx2, widthScale);
                sy2 = Region.clipScale(sy2, heightScale);

                observer = rvObserver;
                img = resolutionVariant;
            }
        }
    }

    try {
        return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1, sy1,
                                    sx2, sy2, bgcolor, observer);
    } catch (InvalidPipeException e) {
        try {
            revalidateAll();
            return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1,
                                        sy1, sx2, sy2, bgcolor, observer);
        } catch (InvalidPipeException e2) {
            // Still catching the exception; we are not yet ready to
            // validate the surfaceData correctly.  Fail for now and
            // try again next time around.
            return false;
        }
    } finally {
        surfaceData.markDirty();
    }
}
 
Example 15
Source File: SunGraphics2D.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
private boolean drawHiDPIImage(Image img, int dx1, int dy1, int dx2,
                               int dy2, int sx1, int sy1, int sx2, int sy2,
                               Color bgcolor, ImageObserver observer) {

    if (SurfaceManager.getImageScale(img) != 1) {  // Volatile Image
        final int scale = SurfaceManager.getImageScale(img);
        sx1 = Region.clipScale(sx1, scale);
        sx2 = Region.clipScale(sx2, scale);
        sy1 = Region.clipScale(sy1, scale);
        sy2 = Region.clipScale(sy2, scale);
    } else if (img instanceof MultiResolutionImage) {
        // get scaled destination image size

        int width = img.getWidth(observer);
        int height = img.getHeight(observer);

        Image resolutionVariant = getResolutionVariant(
                (MultiResolutionImage) img, width, height,
                dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2);

        if (resolutionVariant != img && resolutionVariant != null) {
            // recalculate source region for the resolution variant

            ImageObserver rvObserver = MultiResolutionToolkitImage.
                    getResolutionVariantObserver(img, observer,
                            width, height, -1, -1);

            int rvWidth = resolutionVariant.getWidth(rvObserver);
            int rvHeight = resolutionVariant.getHeight(rvObserver);

            if (0 < width && 0 < height && 0 < rvWidth && 0 < rvHeight) {

                float widthScale = ((float) rvWidth) / width;
                float heightScale = ((float) rvHeight) / height;

                sx1 = Region.clipScale(sx1, widthScale);
                sy1 = Region.clipScale(sy1, heightScale);
                sx2 = Region.clipScale(sx2, widthScale);
                sy2 = Region.clipScale(sy2, heightScale);

                observer = rvObserver;
                img = resolutionVariant;
            }
        }
    }

    try {
        return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1, sy1,
                                    sx2, sy2, bgcolor, observer);
    } catch (InvalidPipeException e) {
        try {
            revalidateAll();
            return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1,
                                        sy1, sx2, sy2, bgcolor, observer);
        } catch (InvalidPipeException e2) {
            // Still catching the exception; we are not yet ready to
            // validate the surfaceData correctly.  Fail for now and
            // try again next time around.
            return false;
        }
    } finally {
        surfaceData.markDirty();
    }
}