X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.g2d%2Fsrc%2Forg%2Fsimantics%2Fg2d%2Fimage%2Fimpl%2FVRamBufferedImage.java;fp=bundles%2Forg.simantics.g2d%2Fsrc%2Forg%2Fsimantics%2Fg2d%2Fimage%2Fimpl%2FVRamBufferedImage.java;h=1a7be154eca7055381bce3fca3ea5388078c8ed0;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=962e0bba2985985f72be2eac762b024a742d3814;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/image/impl/VRamBufferedImage.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/image/impl/VRamBufferedImage.java index 962e0bba2..1a7be154e 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/image/impl/VRamBufferedImage.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/image/impl/VRamBufferedImage.java @@ -1,99 +1,99 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.g2d.image.impl; - -import java.awt.Color; -import java.awt.Graphics2D; -import java.awt.GraphicsConfiguration; -import java.awt.RenderingHints; -import java.awt.Shape; -import java.awt.Transparency; -import java.awt.geom.Rectangle2D; -import java.awt.image.VolatileImage; - -import org.simantics.g2d.image.Image; - -/** - * Video-ram cache suitable for rasterized PaintableSymbols. - * - * @see VRamImage - * @author Toni Kalajainen - */ -public class VRamBufferedImage extends ImageProxy { - - Shape outline; - final GraphicsConfiguration gc; - VolatileImage image; - int wid, hei; - - public VRamBufferedImage(Image original, GraphicsConfiguration gc) { - super(original); - assert(gc!=null); - this.gc = gc; - Rectangle2D bounds = original.getBounds(); - wid = (int) Math.ceil( bounds.getWidth() ); - hei = (int) Math.ceil( bounds.getHeight() ); - } - - synchronized VolatileImage restore() - { - if (image==null) { - image = gc.createCompatibleVolatileImage( - wid, hei, - Transparency.TRANSLUCENT); - } - int validateResult = image.validate(gc); - if (validateResult == VolatileImage.IMAGE_INCOMPATIBLE) - return null; - - if (validateResult == VolatileImage.IMAGE_OK) - return image; - - if (validateResult == VolatileImage.IMAGE_RESTORED /*raster.contentsLost()*/) { - Rectangle2D bounds = source.getBounds(); - outline = source.getOutline(); - Graphics2D target = image.createGraphics(); - target.setBackground(new Color(255,255,255,0)); - target.clearRect(0, 0, image.getWidth(), image.getHeight()); - target.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - target.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); - target.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); - target.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); - target.translate(-bounds.getMinX(), -bounds.getMinY()); - source.init(null);//new GraphicsContextImpl(new Rectangle2D.Double(0,0, image.getWidth(), image.getHeight()), null) ); - target.dispose(); - return image; - } - return null; - } - - @Override - public int hashCode() { - return gc.hashCode() ^source.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof VRamBufferedImage)) return false; - VRamBufferedImage o = (VRamBufferedImage) obj; - return o.gc == gc && o.source.equals(source); - } - - public Image getSource() { - return source; - } - - public GraphicsConfiguration getGraphicsConfiguration() { - return gc; - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.g2d.image.impl; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.GraphicsConfiguration; +import java.awt.RenderingHints; +import java.awt.Shape; +import java.awt.Transparency; +import java.awt.geom.Rectangle2D; +import java.awt.image.VolatileImage; + +import org.simantics.g2d.image.Image; + +/** + * Video-ram cache suitable for rasterized PaintableSymbols. + * + * @see VRamImage + * @author Toni Kalajainen + */ +public class VRamBufferedImage extends ImageProxy { + + Shape outline; + final GraphicsConfiguration gc; + VolatileImage image; + int wid, hei; + + public VRamBufferedImage(Image original, GraphicsConfiguration gc) { + super(original); + assert(gc!=null); + this.gc = gc; + Rectangle2D bounds = original.getBounds(); + wid = (int) Math.ceil( bounds.getWidth() ); + hei = (int) Math.ceil( bounds.getHeight() ); + } + + synchronized VolatileImage restore() + { + if (image==null) { + image = gc.createCompatibleVolatileImage( + wid, hei, + Transparency.TRANSLUCENT); + } + int validateResult = image.validate(gc); + if (validateResult == VolatileImage.IMAGE_INCOMPATIBLE) + return null; + + if (validateResult == VolatileImage.IMAGE_OK) + return image; + + if (validateResult == VolatileImage.IMAGE_RESTORED /*raster.contentsLost()*/) { + Rectangle2D bounds = source.getBounds(); + outline = source.getOutline(); + Graphics2D target = image.createGraphics(); + target.setBackground(new Color(255,255,255,0)); + target.clearRect(0, 0, image.getWidth(), image.getHeight()); + target.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + target.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); + target.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); + target.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + target.translate(-bounds.getMinX(), -bounds.getMinY()); + source.init(null);//new GraphicsContextImpl(new Rectangle2D.Double(0,0, image.getWidth(), image.getHeight()), null) ); + target.dispose(); + return image; + } + return null; + } + + @Override + public int hashCode() { + return gc.hashCode() ^source.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof VRamBufferedImage)) return false; + VRamBufferedImage o = (VRamBufferedImage) obj; + return o.gc == gc && o.source.equals(source); + } + + public Image getSource() { + return source; + } + + public GraphicsConfiguration getGraphicsConfiguration() { + return gc; + } + +}