Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/share/classes/sun/java2d/loops/BlitBg.java
41159 views
1
/*
2
* Copyright (c) 1999, 2021, 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
23
* questions.
24
*/
25
26
package sun.java2d.loops;
27
28
import java.awt.AlphaComposite;
29
import java.awt.Color;
30
import java.awt.Composite;
31
import java.awt.Font;
32
import java.awt.image.BufferedImage;
33
import java.awt.image.ColorModel;
34
import java.awt.image.WritableRaster;
35
36
import sun.awt.image.BufImgSurfaceData;
37
import sun.java2d.SunGraphics2D;
38
import sun.java2d.SurfaceData;
39
import sun.java2d.pipe.Region;
40
41
/**
42
* BlitBg
43
* 1) copies rectangle of pixels from one surface to another
44
* 2) performs compositing of colors based upon a Composite
45
* parameter
46
* 3) assumes that non-opaque pixels are to be blended with
47
* the indicated Bg color before compositing with the
48
* destination
49
*
50
* precise behavior is undefined if the source surface
51
* and the destination surface are the same surface
52
* with overlapping regions of pixels
53
*/
54
public class BlitBg extends GraphicsPrimitive
55
{
56
public static final String methodSignature = "BlitBg(...)".toString();
57
58
public static final int primTypeID = makePrimTypeID();
59
60
private static RenderCache blitcache = new RenderCache(20);
61
62
public static BlitBg locate(SurfaceType srctype,
63
CompositeType comptype,
64
SurfaceType dsttype)
65
{
66
return (BlitBg)
67
GraphicsPrimitiveMgr.locate(primTypeID,
68
srctype, comptype, dsttype);
69
}
70
71
public static BlitBg getFromCache(SurfaceType src,
72
CompositeType comp,
73
SurfaceType dst)
74
{
75
Object o = blitcache.get(src, comp, dst);
76
if (o != null) {
77
return (BlitBg) o;
78
}
79
BlitBg blit = locate(src, comp, dst);
80
if (blit == null) {
81
System.out.println("blitbg loop not found for:");
82
System.out.println("src: "+src);
83
System.out.println("comp: "+comp);
84
System.out.println("dst: "+dst);
85
} else {
86
blitcache.put(src, comp, dst, blit);
87
}
88
return blit;
89
}
90
91
protected BlitBg(SurfaceType srctype,
92
CompositeType comptype,
93
SurfaceType dsttype)
94
{
95
super(methodSignature, primTypeID, srctype, comptype, dsttype);
96
}
97
98
public BlitBg(long pNativePrim,
99
SurfaceType srctype,
100
CompositeType comptype,
101
SurfaceType dsttype)
102
{
103
super(pNativePrim, methodSignature, primTypeID, srctype, comptype, dsttype);
104
}
105
106
/**
107
* All BlitBg implementors must have this invoker method
108
*/
109
public native void BlitBg(SurfaceData src, SurfaceData dst,
110
Composite comp, Region clip,
111
int bgColor,
112
int srcx, int srcy,
113
int dstx, int dsty,
114
int width, int height);
115
116
static {
117
GraphicsPrimitiveMgr.registerGeneral(new BlitBg(null, null, null));
118
}
119
120
protected GraphicsPrimitive makePrimitive(SurfaceType srctype,
121
CompositeType comptype,
122
SurfaceType dsttype)
123
{
124
/*
125
System.out.println("Constructing general blitbg for:");
126
System.out.println("src: "+srctype);
127
System.out.println("comp: "+comptype);
128
System.out.println("dst: "+dsttype);
129
*/
130
return new General(srctype, comptype, dsttype);
131
}
132
133
private static class General extends BlitBg {
134
CompositeType compositeType;
135
136
public General(SurfaceType srctype,
137
CompositeType comptype,
138
SurfaceType dsttype)
139
{
140
super(srctype, comptype, dsttype);
141
compositeType = comptype;
142
}
143
144
@Override
145
public void BlitBg(SurfaceData srcData,
146
SurfaceData dstData,
147
Composite comp,
148
Region clip,
149
int bgArgb,
150
int srcx, int srcy,
151
int dstx, int dsty,
152
int width, int height)
153
{
154
ColorModel dstModel = dstData.getColorModel();
155
boolean bgHasAlpha = (bgArgb >>> 24) != 0xff;
156
if (!dstModel.hasAlpha() && bgHasAlpha) {
157
dstModel = ColorModel.getRGBdefault();
158
}
159
WritableRaster wr =
160
dstModel.createCompatibleWritableRaster(width, height);
161
boolean isPremult = dstModel.isAlphaPremultiplied();
162
BufferedImage bimg =
163
new BufferedImage(dstModel, wr, isPremult, null);
164
SurfaceData tmpData = BufImgSurfaceData.createData(bimg);
165
Color bgColor = new Color(bgArgb, bgHasAlpha);
166
SunGraphics2D sg2d = new SunGraphics2D(tmpData, bgColor, bgColor,
167
defaultFont);
168
FillRect fillop = FillRect.locate(SurfaceType.AnyColor,
169
CompositeType.SrcNoEa,
170
tmpData.getSurfaceType());
171
Blit combineop = Blit.getFromCache(srcData.getSurfaceType(),
172
CompositeType.SrcOverNoEa,
173
tmpData.getSurfaceType());
174
Blit blitop = Blit.getFromCache(tmpData.getSurfaceType(), compositeType,
175
dstData.getSurfaceType());
176
fillop.FillRect(sg2d, tmpData, 0, 0, width, height);
177
combineop.Blit(srcData, tmpData, AlphaComposite.SrcOver, null,
178
srcx, srcy, 0, 0, width, height);
179
blitop.Blit(tmpData, dstData, comp, clip,
180
0, 0, dstx, dsty, width, height);
181
}
182
183
private static Font defaultFont = new Font("Dialog", Font.PLAIN, 12);
184
}
185
186
public GraphicsPrimitive traceWrap() {
187
return new TraceBlitBg(this);
188
}
189
190
private static class TraceBlitBg extends BlitBg {
191
BlitBg target;
192
193
public TraceBlitBg(BlitBg target) {
194
super(target.getSourceType(),
195
target.getCompositeType(),
196
target.getDestType());
197
this.target = target;
198
}
199
200
public GraphicsPrimitive traceWrap() {
201
return this;
202
}
203
204
@Override
205
public void BlitBg(SurfaceData src, SurfaceData dst,
206
Composite comp, Region clip,
207
int bgColor,
208
int srcx, int srcy, int dstx, int dsty,
209
int width, int height)
210
{
211
tracePrimitive(target);
212
target.BlitBg(src, dst, comp, clip, bgColor,
213
srcx, srcy, dstx, dsty, width, height);
214
}
215
}
216
}
217
218