layerdrawing.java

来自「The ElectricTM VLSI Design System is an 」· Java 代码 · 共 1,384 行 · 第 1/5 页

JAVA
1,384
字号
	/** the top-level window being rendered */				private boolean renderedWindow;	/** whether to occasionally update the display. */		private boolean periodicRefresh;	/** keeps track of when to update the display. */		private int objectCount;	/** keeps track of when to update the display. */		private long lastRefreshTime;	/** the EditWindow being drawn */						private EditWindow wnd;	/** the size of the top-level EditWindow */				private static Dimension topSz;    /** draw layers patterned (depends on scale). */        private boolean patternedDisplay;    /** Alpha blending with overcolor (depends on scale). */private static boolean alphaBlendingOvercolor;	/** list of cell expansions. */							private static Map<ExpandedCellKey,ExpandedCellInfo> expandedCells = null;    /** Set of changed cells. */                            private static final Set<CellId> changedCells = new HashSet<CellId>();	/** scale of cell expansions. */						private static double expandedScale = 0;	/** number of extra cells to render this time */		private static int numberToReconcile;	/** zero rectangle */									private static final Rectangle2D CENTERRECT = new Rectangle2D.Double(0, 0, 0, 0);    private static Color textColor;	private static final EGraphics textGraphics = new EGraphics(false, false, null, 0, 0,0,0, 1.0,true,		new int[] {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0});	private static final EGraphics instanceGraphics = new EGraphics(false, false, null, 0, 0,0,0, 1.0,true,		new int[] {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0});    private static final Layer instanceLayer = Layer.newInstanceFree(null, "Instance", instanceGraphics);	private static final EGraphics gridGraphics = new EGraphics(false, false, null, 0, 0,0,0, 1.0,true,		new int[] {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0});    private static final Layer gridLayer = Layer.newInstanceFree(null, "Grid", gridGraphics);	private static final EGraphics portGraphics = new EGraphics(false, false, null, 0, 255,0,0, 1.0,true,		new int[] {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0});    private int clipLX, clipHX, clipLY, clipHY;    private final int width;    private final EditWindow0 dummyWnd = new EditWindow0() {        public VarContext getVarContext() { return varContext; }        public double getScale() { return scale; }        public double getGlobalTextScale() { return wnd.getGlobalTextScale(); }    };    private static class DrawingData {        private final LayerDrawing offscreen;        private final int width;        private final int height;        private final int numIntsPerRow;        private final boolean patternedDisplay;        /** the map from layers to layer bitmaps */             private final Map<Layer,TransparentRaster> layerRasters;        private final GreekTextInfo[] greekText;        private final RenderTextInfo[] renderText;        private final CrossTextInfo[] crossText;                DrawingData(LayerDrawing offscreen) {            this.offscreen = offscreen;            width = offscreen.sz.width;            height = offscreen.sz.height;            numIntsPerRow = offscreen.numIntsPerRow;            patternedDisplay = offscreen.patternedDisplay;            layerRasters = new HashMap<Layer,TransparentRaster>(offscreen.layerRasters);            greekText = offscreen.greekTextList.toArray(new GreekTextInfo[offscreen.greekTextList.size()]);            crossText = offscreen.crossTextList.toArray(new CrossTextInfo[offscreen.crossTextList.size()]);            renderText = offscreen.renderTextList.toArray(new RenderTextInfo[offscreen.renderTextList.size()]);        }    }        static class Drawing extends AbstractDrawing {        private static final int SMALL_IMG_HEIGHT = 2;        /** the offscreen opaque image of the window */ private VolatileImage vImg;        private BufferedImage smallImg;        private int[] smallOpaqueData;        /** alpha blender of layer maps */                      private final AlphaBlender alphaBlender = new AlphaBlender();        // The following fields are produced by "render" method in Job thread.        private volatile boolean needComposite;        private volatile DrawingData drawingData;        Drawing(EditWindow wnd) {            super(wnd);        }        /**         * This method is called from AWT thread.         */        @Override        public boolean paintComponent(Graphics2D g, Dimension sz) {            assert SwingUtilities.isEventDispatchThread();            assert sz.equals(wnd.getSize());            DrawingData drawingData = this.drawingData;            if (drawingData == null || !drawingData.offscreen.getSize().equals(sz))                return false;            if (vImg == null || vImg.getWidth() != sz.width || vImg.getHeight() != sz.height) {                if (vImg != null)                    vImg.flush();                vImg = wnd.createVolatileImage(sz.width, sz.height);            }//            smallImg = (BufferedImage)wnd.createImage(sz.width, 1);            if (smallImg == null || smallImg.getWidth() != sz.width) {                smallImg = new BufferedImage(sz.width, SMALL_IMG_HEIGHT, BufferedImage.TYPE_INT_RGB);                DataBufferInt smallDbi = (DataBufferInt)smallImg.getRaster().getDataBuffer();                smallOpaqueData = smallDbi.getData();            }            // show the image            // copying from the image (here, gScreen is the Graphics            // object for the onscreen window)            do {                int returnCode = vImg.validate(wnd.getGraphicsConfiguration());                if (returnCode == VolatileImage.IMAGE_RESTORED) {                    // Contents need to be restored                    renderOffscreen(drawingData);	    // restore contents                } else if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE) {                    // old vImg doesn't work with new GraphicsConfig; re-create it                    vImg.flush();                    vImg = wnd.createVolatileImage(sz.width, sz.height);                    renderOffscreen(drawingData);                } else if (needComposite) {                    renderOffscreen(drawingData);                }                g.drawImage(vImg, 0, 0, wnd);            } while (vImg.contentsLost());            return true;        }        /**         * This method is called from AWT thread.         */        private void renderOffscreen(DrawingData dd) {            needComposite = false;            do {                if (vImg.validate(wnd.getGraphicsConfiguration()) == VolatileImage.IMAGE_INCOMPATIBLE) {                    // old vImg doesn't work with new GraphicsConfig; re-create it                    vImg = wnd.createVolatileImage(dd.width, dd.height);                }                long startTime = System.currentTimeMillis();                Graphics2D g = vImg.createGraphics();                if (User.isLegacyComposite())                    legacyLayerComposite(g, dd);                else                    layerComposite(g, dd);//                if (alphaBlendingComposite) {//                    boolean TRY_OVERBLEND = false;//                    if (TRY_OVERBLEND) {//                        layerCompositeSlow(g);//                    } else {//                        layerComposite(g);//                    }//                } else {//                    layerCompositeCompatable(g);//                }                long compositeTime = System.currentTimeMillis();                for (GreekTextInfo greekInfo: dd.greekText)                    greekInfo.draw(g);                for (CrossTextInfo crossInfo: dd.crossText)                    crossInfo.draw(g);                g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);                for (RenderTextInfo textInfo: dd.renderText)                    textInfo.draw(g);                g.dispose();                if (TAKE_STATS) {                    long endTime = System.currentTimeMillis();                    System.out.println((alphaBlendingOvercolor ? "alphaBlendingOvercolor took " : "alphaBlending took ")                    + (compositeTime - startTime) + " msec, textRendering " + dd.renderText.length + "+" + dd.greekText.length + "+" + dd.crossText.length + " took " + (endTime - compositeTime) + " msec");                }            } while (vImg.contentsLost());        }        @Override        public void opacityChanged() {            assert SwingUtilities.isEventDispatchThread();            needComposite = true;        }        @Override        public boolean hasOpacity() { return true; }        private void layerComposite(Graphics2D g, DrawingData dd) {            Map<Layer,int[]> layerBits = new HashMap<Layer,int[]>();            for (Map.Entry<Layer,TransparentRaster> e: dd.layerRasters.entrySet())                layerBits.put(e.getKey(), e.getValue().layerBitMap);            List<AbstractDrawing.LayerColor> blendingOrder = wnd.getBlendingOrder(layerBits.keySet(), dd.patternedDisplay, alphaBlendingOvercolor);            if (TAKE_STATS) {                System.out.print("BlendingOrder:");                for (AbstractDrawing.LayerColor lc: blendingOrder) {                    int alpha = (int)((1 - lc.inverseAlpha) * 100 + 0.5);                    System.out.print(" " + lc.layer.getName() + ":" + alpha);                }                System.out.println();            }            alphaBlender.init(User.getColor(User.ColorPrefType.BACKGROUND), blendingOrder, layerBits);            int width = dd.width;            int height = dd.height, clipLY = 0, clipHY = height - 1;            int numIntsPerRow = dd.numIntsPerRow;            int baseByteIndex = 0;            int y = 0;            while (y < height) {                int h = Math.min(SMALL_IMG_HEIGHT, height - y);                int baseIndex = 0;                for (int k = 0; k < h; k++) {                    alphaBlender.composeLine(baseByteIndex, 0, width - 1, smallOpaqueData, baseIndex);                    baseByteIndex += numIntsPerRow;                    baseIndex += width;                }                g.drawImage(smallImg, 0, y, null);                y += h;            }        }        /**         * Method to complete rendering by combining the transparent and opaque imagery.         * This is called after all rendering is done.         * @return the offscreen Image with the final display.         */        private void legacyLayerComposite(Graphics2D g, DrawingData dd) {            wnd.getBlendingOrder(dd.layerRasters.keySet(), false, false);            Technology curTech = Technology.getCurrent();            if (curTech == null) {                for (Layer layer: dd.layerRasters.keySet()) {                    int transparentDepth = layer.getGraphics().getTransparentLayer();                    if (transparentDepth != 0 && layer.getTechnology() != null)                        curTech = layer.getTechnology();                }            }            if (curTech == null)                curTech = Generic.tech();            // get the technology's color map            Color [] colorMap = curTech.getColorMap();            // adjust the colors if any of the transparent layers are dimmed            boolean dimmedTransparentLayers = false;            for(Iterator<Layer> it = curTech.getLayers(); it.hasNext(); ) {                Layer layer = it.next();                if (!layer.isDimmed()) continue;                if (layer.getGraphics().getTransparentLayer() == 0) continue;                dimmedTransparentLayers = true;                break;            }            if (dimmedTransparentLayers) {                Color [] newColorMap = new Color[colorMap.length];                int numTransparents = curTech.getNumTransparentLayers();                boolean [] dimLayer = new boolean[numTransparents];                for(int i=0; i<numTransparents; i++) dimLayer[i] = true;                for(Iterator<Layer> it = curTech.getLayers(); it.hasNext(); ) {                    Layer layer = it.next();                    if (layer.isDimmed()) continue;                    int tIndex = layer.getGraphics().getTransparentLayer();                    if (tIndex == 0) continue;                    dimLayer[tIndex-1] = false;                }                for(int i=0; i<colorMap.length; i++) {                    newColorMap[i] = colorMap[i];                    if (i == 0) continue;                    boolean dimThisEntry = true;                    for(int j=0; j<numTransparents; j++) {                        if ((i & (1<<j)) != 0) {                            if (!dimLayer[j]) {                                dimThisEntry = false;                                break;                            }                        }                    }                    if (dimThisEntry) {                        newColorMap[i] = new Color(dd.offscreen.dimColor(colorMap[i].getRGB()));                    } else {                        newColorMap[i] = new Color(dd.offscreen.brightenColor(colorMap[i].getRGB()));                    }                }                colorMap = newColorMap;            }            int numTransparent = 0, numOpaque = 0;            int deepestTransparentDepth = 0;            for (Layer layer: dd.layerRasters.keySet()) {                if (!layer.isVisible()) continue;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?