1 /*
2 * Copyright (c) 1997, 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
29 import sun.awt.image.IntegerComponentRaster;
30 import java.awt.image.ColorModel;
31 import java.awt.image.DirectColorModel;
32 import java.awt.geom.Point2D;
33 import java.awt.geom.AffineTransform;
34 import java.awt.geom.NoninvertibleTransformException;
35 import java.lang.ref.WeakReference;
36
37 class GradientPaintContext implements PaintContext {
38 static ColorModel xrgbmodel =
39 new DirectColorModel(24, 0x00ff0000, 0x0000ff00, 0x000000ff);
40 static ColorModel xbgrmodel =
41 new DirectColorModel(24, 0x000000ff, 0x0000ff00, 0x00ff0000);
42
43 static ColorModel cachedModel;
44 static WeakReference<Raster> cached;
45
46 static synchronized Raster getCachedRaster(ColorModel cm, int w, int h) {
47 if (cm == cachedModel) {
48 if (cached != null) {
49 Raster ras = (Raster) cached.get();
50 if (ras != null &&
51 ras.getWidth() >= w &&
52 ras.getHeight() >= h)
53 {
54 cached = null;
55 return ras;
56 }
57 }
58 }
59 return cm.createCompatibleWritableRaster(w, h);
60 }
61
62 static synchronized void putCachedRaster(ColorModel cm, Raster ras) {
63 if (cached != null) {
64 Raster cras = (Raster) cached.get();
65 if (cras != null) {
66 int cw = cras.getWidth();
67 int ch = cras.getHeight();
68 int iw = ras.getWidth();
69 int ih = ras.getHeight();
70 if (cw >= iw && ch >= ih) {
71 return;
72 }
73 if (cw * ch >= iw * ih) {
74 return;
75 }
76 }
77 }
78 cachedModel = cm;
79 cached = new WeakReference<>(ras);
80 }
81
82 double x1;
83 double y1;
84 double dx;
|
1 /*
2 * Copyright (c) 1997, 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
29 import sun.awt.image.IntegerComponentRaster;
30 import java.awt.image.ColorModel;
31 import java.awt.image.DirectColorModel;
32 import java.awt.geom.Point2D;
33 import java.awt.geom.AffineTransform;
34 import java.awt.geom.NoninvertibleTransformException;
35 import java.lang.ref.WeakReference;
36
37 class GradientPaintContext implements PaintContext {
38 static ColorModel xrgbmodel =
39 new DirectColorModel(24, 0x00ff0000, 0x0000ff00, 0x000000ff);
40 static ColorModel xbgrmodel =
41 new DirectColorModel(24, 0x000000ff, 0x0000ff00, 0x00ff0000);
42
43 static ColorModel cachedModel;
44 static WeakReference<Raster> cached;
45
46 static synchronized Raster getCachedRaster(ColorModel cm, int w, int h) {
47 if (cm == cachedModel) {
48 if (cached != null) {
49 Raster ras = cached.get();
50 if (ras != null &&
51 ras.getWidth() >= w &&
52 ras.getHeight() >= h)
53 {
54 cached = null;
55 return ras;
56 }
57 }
58 }
59 return cm.createCompatibleWritableRaster(w, h);
60 }
61
62 static synchronized void putCachedRaster(ColorModel cm, Raster ras) {
63 if (cached != null) {
64 Raster cras = cached.get();
65 if (cras != null) {
66 int cw = cras.getWidth();
67 int ch = cras.getHeight();
68 int iw = ras.getWidth();
69 int ih = ras.getHeight();
70 if (cw >= iw && ch >= ih) {
71 return;
72 }
73 if (cw * ch >= iw * ih) {
74 return;
75 }
76 }
77 }
78 cachedModel = cm;
79 cached = new WeakReference<>(ras);
80 }
81
82 double x1;
83 double y1;
84 double dx;
|