1 /*
2 * Copyright (c) 2006, 2007, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
648
649 fillRaster(pixels, off, adjust, x, y, w, h); // delegate to subclass
650
651 return raster;
652 }
653
654 protected abstract void fillRaster(int pixels[], int off, int adjust,
655 int x, int y, int w, int h);
656
657
658 /**
659 * Took this cacheRaster code from GradientPaint. It appears to recycle
660 * rasters for use by any other instance, as long as they are sufficiently
661 * large.
662 */
663 private static synchronized Raster getCachedRaster(ColorModel cm,
664 int w, int h)
665 {
666 if (cm == cachedModel) {
667 if (cached != null) {
668 Raster ras = (Raster) cached.get();
669 if (ras != null &&
670 ras.getWidth() >= w &&
671 ras.getHeight() >= h)
672 {
673 cached = null;
674 return ras;
675 }
676 }
677 }
678 return cm.createCompatibleWritableRaster(w, h);
679 }
680
681 /**
682 * Took this cacheRaster code from GradientPaint. It appears to recycle
683 * rasters for use by any other instance, as long as they are sufficiently
684 * large.
685 */
686 private static synchronized void putCachedRaster(ColorModel cm,
687 Raster ras)
688 {
689 if (cached != null) {
690 Raster cras = (Raster) cached.get();
691 if (cras != null) {
692 int cw = cras.getWidth();
693 int ch = cras.getHeight();
694 int iw = ras.getWidth();
695 int ih = ras.getHeight();
696 if (cw >= iw && ch >= ih) {
697 return;
698 }
699 if (cw * ch >= iw * ih) {
700 return;
701 }
702 }
703 }
704 cachedModel = cm;
705 cached = new WeakReference<Raster>(ras);
706 }
707
708 /**
709 * {@inheritDoc}
710 */
|
1 /*
2 * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
648
649 fillRaster(pixels, off, adjust, x, y, w, h); // delegate to subclass
650
651 return raster;
652 }
653
654 protected abstract void fillRaster(int pixels[], int off, int adjust,
655 int x, int y, int w, int h);
656
657
658 /**
659 * Took this cacheRaster code from GradientPaint. It appears to recycle
660 * rasters for use by any other instance, as long as they are sufficiently
661 * large.
662 */
663 private static synchronized Raster getCachedRaster(ColorModel cm,
664 int w, int h)
665 {
666 if (cm == cachedModel) {
667 if (cached != null) {
668 Raster ras = cached.get();
669 if (ras != null &&
670 ras.getWidth() >= w &&
671 ras.getHeight() >= h)
672 {
673 cached = null;
674 return ras;
675 }
676 }
677 }
678 return cm.createCompatibleWritableRaster(w, h);
679 }
680
681 /**
682 * Took this cacheRaster code from GradientPaint. It appears to recycle
683 * rasters for use by any other instance, as long as they are sufficiently
684 * large.
685 */
686 private static synchronized void putCachedRaster(ColorModel cm,
687 Raster ras)
688 {
689 if (cached != null) {
690 Raster cras = cached.get();
691 if (cras != null) {
692 int cw = cras.getWidth();
693 int ch = cras.getHeight();
694 int iw = ras.getWidth();
695 int ih = ras.getHeight();
696 if (cw >= iw && ch >= ih) {
697 return;
698 }
699 if (cw * ch >= iw * ih) {
700 return;
701 }
702 }
703 }
704 cachedModel = cm;
705 cached = new WeakReference<Raster>(ras);
706 }
707
708 /**
709 * {@inheritDoc}
710 */
|