Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/java2d/xr/XRPMBlitLoops.java
32288 views
1
/*
2
* Copyright (c) 2010, 2013, 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.xr;
27
28
import sun.awt.SunToolkit;
29
import sun.awt.image.*;
30
import sun.java2d.loops.*;
31
import sun.java2d.pipe.*;
32
import sun.java2d.*;
33
import java.awt.*;
34
import java.awt.geom.*;
35
import java.lang.ref.*;
36
37
public class XRPMBlitLoops {
38
39
static WeakReference<SunVolatileImage> argbTmpPM = new WeakReference<SunVolatileImage>(null);
40
static WeakReference<SunVolatileImage> rgbTmpPM = new WeakReference<SunVolatileImage>(null);
41
42
public XRPMBlitLoops() {
43
}
44
45
public static void register() {
46
GraphicsPrimitive[] primitives = { new XRPMBlit(XRSurfaceData.IntRgbX11, XRSurfaceData.IntRgbX11),
47
new XRPMBlit(XRSurfaceData.IntRgbX11, XRSurfaceData.IntArgbPreX11),
48
new XRPMBlit(XRSurfaceData.IntArgbPreX11, XRSurfaceData.IntRgbX11),
49
new XRPMBlit(XRSurfaceData.IntArgbPreX11, XRSurfaceData.IntArgbPreX11),
50
51
new XRPMScaledBlit(XRSurfaceData.IntRgbX11, XRSurfaceData.IntRgbX11),
52
new XRPMScaledBlit(XRSurfaceData.IntRgbX11, XRSurfaceData.IntArgbPreX11),
53
new XRPMScaledBlit(XRSurfaceData.IntArgbPreX11, XRSurfaceData.IntRgbX11),
54
new XRPMScaledBlit(XRSurfaceData.IntArgbPreX11, XRSurfaceData.IntArgbPreX11),
55
56
new XRPMTransformedBlit(XRSurfaceData.IntRgbX11, XRSurfaceData.IntRgbX11),
57
new XRPMTransformedBlit(XRSurfaceData.IntRgbX11, XRSurfaceData.IntArgbPreX11),
58
new XRPMTransformedBlit(XRSurfaceData.IntArgbPreX11, XRSurfaceData.IntRgbX11),
59
new XRPMTransformedBlit(XRSurfaceData.IntArgbPreX11, XRSurfaceData.IntArgbPreX11),
60
61
/* SW -> Surface Blits */
62
new XrSwToPMBlit(SurfaceType.IntArgb, XRSurfaceData.IntRgbX11),
63
new XrSwToPMBlit(SurfaceType.IntRgb, XRSurfaceData.IntRgbX11),
64
new XrSwToPMBlit(SurfaceType.IntBgr, XRSurfaceData.IntRgbX11),
65
new XrSwToPMBlit(SurfaceType.ThreeByteBgr, XRSurfaceData.IntRgbX11),
66
new XrSwToPMBlit(SurfaceType.Ushort565Rgb, XRSurfaceData.IntRgbX11),
67
new XrSwToPMBlit(SurfaceType.Ushort555Rgb, XRSurfaceData.IntRgbX11),
68
new XrSwToPMBlit(SurfaceType.ByteIndexed, XRSurfaceData.IntRgbX11),
69
70
new XrSwToPMBlit(SurfaceType.IntArgb, XRSurfaceData.IntArgbPreX11),
71
new XrSwToPMBlit(SurfaceType.IntRgb, XRSurfaceData.IntArgbPreX11),
72
new XrSwToPMBlit(SurfaceType.IntBgr, XRSurfaceData.IntArgbPreX11),
73
new XrSwToPMBlit(SurfaceType.ThreeByteBgr, XRSurfaceData.IntArgbPreX11),
74
new XrSwToPMBlit(SurfaceType.Ushort565Rgb, XRSurfaceData.IntArgbPreX11),
75
new XrSwToPMBlit(SurfaceType.Ushort555Rgb, XRSurfaceData.IntArgbPreX11),
76
new XrSwToPMBlit(SurfaceType.ByteIndexed, XRSurfaceData.IntArgbPreX11),
77
78
/* SW->Surface Scales */
79
new XrSwToPMScaledBlit(SurfaceType.IntArgb, XRSurfaceData.IntRgbX11),
80
new XrSwToPMScaledBlit(SurfaceType.IntRgb, XRSurfaceData.IntRgbX11),
81
new XrSwToPMScaledBlit(SurfaceType.IntBgr, XRSurfaceData.IntRgbX11),
82
new XrSwToPMScaledBlit(SurfaceType.ThreeByteBgr, XRSurfaceData.IntRgbX11),
83
new XrSwToPMScaledBlit(SurfaceType.Ushort565Rgb, XRSurfaceData.IntRgbX11),
84
new XrSwToPMScaledBlit(SurfaceType.Ushort555Rgb, XRSurfaceData.IntRgbX11),
85
new XrSwToPMScaledBlit(SurfaceType.ByteIndexed, XRSurfaceData.IntRgbX11),
86
87
new XrSwToPMScaledBlit(SurfaceType.IntArgb, XRSurfaceData.IntArgbPreX11),
88
new XrSwToPMScaledBlit(SurfaceType.IntRgb, XRSurfaceData.IntArgbPreX11),
89
new XrSwToPMScaledBlit(SurfaceType.IntBgr, XRSurfaceData.IntArgbPreX11),
90
new XrSwToPMScaledBlit(SurfaceType.ThreeByteBgr, XRSurfaceData.IntArgbPreX11),
91
new XrSwToPMScaledBlit(SurfaceType.Ushort565Rgb, XRSurfaceData.IntArgbPreX11),
92
new XrSwToPMScaledBlit(SurfaceType.Ushort555Rgb, XRSurfaceData.IntArgbPreX11),
93
new XrSwToPMScaledBlit(SurfaceType.ByteIndexed, XRSurfaceData.IntArgbPreX11),
94
95
/* SW->Surface Transforms */
96
new XrSwToPMTransformedBlit(SurfaceType.IntArgb, XRSurfaceData.IntRgbX11),
97
new XrSwToPMTransformedBlit(SurfaceType.IntRgb, XRSurfaceData.IntRgbX11),
98
new XrSwToPMTransformedBlit(SurfaceType.IntBgr, XRSurfaceData.IntRgbX11),
99
new XrSwToPMTransformedBlit(SurfaceType.ThreeByteBgr, XRSurfaceData.IntRgbX11),
100
new XrSwToPMTransformedBlit(SurfaceType.Ushort565Rgb, XRSurfaceData.IntRgbX11),
101
new XrSwToPMTransformedBlit(SurfaceType.Ushort555Rgb, XRSurfaceData.IntRgbX11),
102
new XrSwToPMTransformedBlit(SurfaceType.ByteIndexed, XRSurfaceData.IntRgbX11),
103
104
new XrSwToPMTransformedBlit(SurfaceType.IntArgb, XRSurfaceData.IntArgbPreX11),
105
new XrSwToPMTransformedBlit(SurfaceType.IntRgb, XRSurfaceData.IntArgbPreX11),
106
new XrSwToPMTransformedBlit(SurfaceType.IntBgr, XRSurfaceData.IntArgbPreX11),
107
new XrSwToPMTransformedBlit(SurfaceType.ThreeByteBgr, XRSurfaceData.IntArgbPreX11),
108
new XrSwToPMTransformedBlit(SurfaceType.Ushort565Rgb, XRSurfaceData.IntArgbPreX11),
109
new XrSwToPMTransformedBlit(SurfaceType.Ushort555Rgb, XRSurfaceData.IntArgbPreX11),
110
new XrSwToPMTransformedBlit(SurfaceType.ByteIndexed, XRSurfaceData.IntArgbPreX11), };
111
GraphicsPrimitiveMgr.register(primitives);
112
}
113
114
/**
115
* Caches a SW surface using a temporary pixmap. The pixmap is held by a WeakReference,
116
* allowing it to shrink again after some time.
117
*/
118
protected static XRSurfaceData cacheToTmpSurface(SurfaceData src, XRSurfaceData dst, int w, int h, int sx, int sy) {
119
SunVolatileImage vImg;
120
SurfaceType vImgSurfaceType;
121
122
if (src.getTransparency() == Transparency.OPAQUE) {
123
vImg = rgbTmpPM.get();
124
vImgSurfaceType = SurfaceType.IntRgb;
125
} else {
126
vImg = argbTmpPM.get();
127
vImgSurfaceType = SurfaceType.IntArgbPre;
128
}
129
130
if (vImg == null || vImg.getWidth() < w || vImg.getHeight() < h ||
131
// Sometimes we get volatile image of wrong dest surface type,
132
// so recreating it
133
!(vImg.getDestSurface() instanceof XRSurfaceData))
134
{
135
if (vImg != null) {
136
vImg.flush();
137
}
138
vImg = (SunVolatileImage) dst.getGraphicsConfig().createCompatibleVolatileImage(w, h, src.getTransparency());
139
vImg.setAccelerationPriority(1.0f);
140
141
if (!(vImg.getDestSurface() instanceof XRSurfaceData)) {
142
throw new InvalidPipeException("Could not create XRSurfaceData");
143
}
144
if (src.getTransparency() == SurfaceData.OPAQUE) {
145
rgbTmpPM = new WeakReference<SunVolatileImage>(vImg);
146
} else {
147
argbTmpPM = new WeakReference<SunVolatileImage>(vImg);
148
}
149
}
150
151
Blit swToSurfaceBlit = Blit.getFromCache(src.getSurfaceType(), CompositeType.SrcNoEa, vImgSurfaceType);
152
153
if (!(vImg.getDestSurface() instanceof XRSurfaceData)) {
154
throw new InvalidPipeException("wrong surface data type: " + vImg.getDestSurface());
155
}
156
157
XRSurfaceData vImgSurface = (XRSurfaceData) vImg.getDestSurface();
158
swToSurfaceBlit.Blit(src, vImgSurface, AlphaComposite.Src, null,
159
sx, sy, 0, 0, w, h);
160
161
return vImgSurface;
162
}
163
}
164
165
class XRPMBlit extends Blit {
166
public XRPMBlit(SurfaceType srcType, SurfaceType dstType) {
167
super(srcType, CompositeType.AnyAlpha, dstType);
168
}
169
170
public void Blit(SurfaceData src, SurfaceData dst, Composite comp, Region clip, int sx, int sy, int dx, int dy, int w, int h) {
171
try {
172
SunToolkit.awtLock();
173
174
XRSurfaceData x11sdDst = (XRSurfaceData) dst;
175
x11sdDst.validateAsDestination(null, clip);
176
XRSurfaceData x11sdSrc = (XRSurfaceData) src;
177
x11sdSrc.validateAsSource(null, XRUtils.RepeatNone, XRUtils.FAST);
178
179
x11sdDst.maskBuffer.validateCompositeState(comp, null, null, null);
180
181
x11sdDst.maskBuffer.compositeBlit(x11sdSrc, x11sdDst, sx, sy, dx, dy, w, h);
182
} finally {
183
SunToolkit.awtUnlock();
184
}
185
}
186
}
187
188
class XRPMScaledBlit extends ScaledBlit {
189
public XRPMScaledBlit(SurfaceType srcType, SurfaceType dstType) {
190
super(srcType, CompositeType.AnyAlpha, dstType);
191
}
192
193
public void Scale(SurfaceData src, SurfaceData dst, Composite comp, Region clip, int sx1, int sy1, int sx2, int sy2, double dx1, double dy1,
194
double dx2, double dy2) {
195
try {
196
SunToolkit.awtLock();
197
198
XRSurfaceData x11sdDst = (XRSurfaceData) dst;
199
x11sdDst.validateAsDestination(null, clip);
200
XRSurfaceData x11sdSrc = (XRSurfaceData) src;
201
x11sdDst.maskBuffer.validateCompositeState(comp, null, null, null);
202
203
double xScale = (dx2 - dx1) / (sx2 - sx1);
204
double yScale = (dy2 - dy1) / (sy2 - sy1);
205
206
sx1 *= xScale;
207
sx2 *= xScale;
208
sy1 *= yScale;
209
sy2 *= yScale;
210
211
dx1 = Math.ceil(dx1 - 0.5);
212
dy1 = Math.ceil(dy1 - 0.5);
213
dx2 = Math.ceil(dx2 - 0.5);
214
dy2 = Math.ceil(dy2 - 0.5);
215
216
AffineTransform xForm = AffineTransform.getScaleInstance(1 / xScale, 1 / yScale);
217
218
x11sdSrc.validateAsSource(xForm, XRUtils.RepeatNone, XRUtils.FAST);
219
x11sdDst.maskBuffer.compositeBlit(x11sdSrc, x11sdDst, (int) sx1, (int) sy1, (int) dx1, (int) dy1, (int) (dx2 - dx1), (int) (dy2 - dy1));
220
} finally {
221
SunToolkit.awtUnlock();
222
}
223
}
224
}
225
226
/**
227
* Called also if scale+transform is set
228
*
229
* @author Clemens Eisserer
230
*/
231
class XRPMTransformedBlit extends TransformBlit {
232
final Rectangle compositeBounds = new Rectangle();
233
final double[] srcCoords = new double[8];
234
final double[] dstCoords = new double[8];
235
236
public XRPMTransformedBlit(SurfaceType srcType, SurfaceType dstType) {
237
super(srcType, CompositeType.AnyAlpha, dstType);
238
}
239
240
/*
241
* Calculates the composition-rectangle required for transformed blits.
242
* For composite operations where the composition-rectangle defines
243
* the modified destination area, coordinates are rounded.
244
* Otherwise the composition window rectangle is sized large enough
245
* to not clip away any pixels.
246
*/
247
protected void adjustCompositeBounds(boolean isQuadrantRotated, AffineTransform tr,
248
int dstx, int dsty, int width, int height) {
249
srcCoords[0] = dstx;
250
srcCoords[1] = dsty;
251
srcCoords[2] = dstx + width;
252
srcCoords[3] = dsty + height;
253
254
double minX, minY, maxX, maxY;
255
if (isQuadrantRotated) {
256
tr.transform(srcCoords, 0, dstCoords, 0, 2);
257
258
minX = Math.min(dstCoords[0], dstCoords[2]);
259
minY = Math.min(dstCoords[1], dstCoords[3]);
260
maxX = Math.max(dstCoords[0], dstCoords[2]);
261
maxY = Math.max(dstCoords[1], dstCoords[3]);
262
263
minX = Math.ceil(minX - 0.5);
264
minY = Math.ceil(minY - 0.5);
265
maxX = Math.ceil(maxX - 0.5);
266
maxY = Math.ceil(maxY - 0.5);
267
} else {
268
srcCoords[4] = dstx;
269
srcCoords[5] = dsty + height;
270
srcCoords[6] = dstx + width;
271
srcCoords[7] = dsty;
272
273
tr.transform(srcCoords, 0, dstCoords, 0, 4);
274
275
minX = Math.min(dstCoords[0], Math.min(dstCoords[2], Math.min(dstCoords[4], dstCoords[6])));
276
minY = Math.min(dstCoords[1], Math.min(dstCoords[3], Math.min(dstCoords[5], dstCoords[7])));
277
maxX = Math.max(dstCoords[0], Math.max(dstCoords[2], Math.max(dstCoords[4], dstCoords[6])));
278
maxY = Math.max(dstCoords[1], Math.max(dstCoords[3], Math.max(dstCoords[5], dstCoords[7])));
279
280
minX = Math.floor(minX);
281
minY = Math.floor(minY);
282
maxX = Math.ceil(maxX);
283
maxY = Math.ceil(maxY);
284
}
285
286
compositeBounds.x = (int) minX;
287
compositeBounds.y = (int) minY;
288
compositeBounds.width = (int) (maxX - minX);
289
compositeBounds.height = (int) (maxY - minY);
290
}
291
292
public void Transform(SurfaceData src, SurfaceData dst, Composite comp, Region clip, AffineTransform xform,
293
int hint, int srcx, int srcy, int dstx, int dsty, int width, int height) {
294
try {
295
SunToolkit.awtLock();
296
297
XRSurfaceData x11sdDst = (XRSurfaceData) dst;
298
XRSurfaceData x11sdSrc = (XRSurfaceData) src;
299
XRCompositeManager xrMgr = XRCompositeManager.getInstance(x11sdSrc);
300
301
float extraAlpha = ((AlphaComposite) comp).getAlpha();
302
int filter = XRUtils.ATransOpToXRQuality(hint);
303
boolean isQuadrantRotated = XRUtils.isTransformQuadrantRotated(xform);
304
305
adjustCompositeBounds(isQuadrantRotated, xform, dstx, dsty, width, height);
306
307
x11sdDst.validateAsDestination(null, clip);
308
x11sdDst.maskBuffer.validateCompositeState(comp, null, null, null);
309
310
AffineTransform trx = AffineTransform.getTranslateInstance(-compositeBounds.x, -compositeBounds.y);
311
trx.concatenate(xform);
312
AffineTransform maskTX = (AffineTransform) trx.clone();
313
trx.translate(-srcx, -srcy);
314
315
try {
316
trx.invert();
317
} catch (NoninvertibleTransformException ex) {
318
trx.setToIdentity();
319
}
320
321
if (filter != XRUtils.FAST && (!isQuadrantRotated || extraAlpha != 1.0f)) {
322
XRMaskImage mask = x11sdSrc.maskBuffer.getMaskImage();
323
324
// For quadrant-transformed blits geometry is not stored inside the mask
325
// therefore we can use a repeating 1x1 mask for applying extra alpha.
326
int maskPicture = isQuadrantRotated ? xrMgr.getExtraAlphaMask()
327
: mask.prepareBlitMask(x11sdDst, maskTX, width, height);
328
329
x11sdSrc.validateAsSource(trx, XRUtils.RepeatPad, filter);
330
x11sdDst.maskBuffer.con.renderComposite(xrMgr.getCompRule(), x11sdSrc.picture,
331
maskPicture, x11sdDst.picture, 0, 0, 0, 0, compositeBounds.x, compositeBounds.y,
332
compositeBounds.width, compositeBounds.height);
333
} else {
334
int repeat = filter == XRUtils.FAST ? XRUtils.RepeatNone : XRUtils.RepeatPad;
335
336
x11sdSrc.validateAsSource(trx, repeat, filter);
337
338
// compositeBlit takes care of extra alpha
339
x11sdDst.maskBuffer.compositeBlit(x11sdSrc, x11sdDst, 0, 0, compositeBounds.x,
340
compositeBounds.y, compositeBounds.width, compositeBounds.height);
341
}
342
} finally {
343
SunToolkit.awtUnlock();
344
}
345
}
346
}
347
348
class XrSwToPMBlit extends Blit {
349
Blit pmToSurfaceBlit;
350
351
XrSwToPMBlit(SurfaceType srcType, SurfaceType dstType) {
352
super(srcType, CompositeType.AnyAlpha, dstType);
353
pmToSurfaceBlit = new XRPMBlit(dstType, dstType);
354
}
355
356
public void Blit(SurfaceData src, SurfaceData dst, Composite comp, Region clip, int sx, int sy, int dx, int dy, int w, int h) {
357
// If the blit is write-only (putimge), no need for a temporary VI.
358
if (CompositeType.SrcOverNoEa.equals(comp) && (src.getTransparency() == Transparency.OPAQUE)) {
359
Blit opaqueSwToSurfaceBlit = Blit.getFromCache(src.getSurfaceType(), CompositeType.SrcNoEa, dst.getSurfaceType());
360
opaqueSwToSurfaceBlit.Blit(src, dst, comp, clip, sx, sy, dx, dy, w, h);
361
} else {
362
try {
363
SunToolkit.awtLock();
364
365
XRSurfaceData vImgSurface = XRPMBlitLoops.cacheToTmpSurface(src, (XRSurfaceData) dst, w, h, sx, sy);
366
pmToSurfaceBlit.Blit(vImgSurface, dst, comp, clip, 0, 0, dx, dy, w, h);
367
} finally {
368
SunToolkit.awtUnlock();
369
}
370
}
371
}
372
}
373
374
class XrSwToPMScaledBlit extends ScaledBlit {
375
ScaledBlit pmToSurfaceBlit;
376
377
XrSwToPMScaledBlit(SurfaceType srcType, SurfaceType dstType) {
378
super(srcType, CompositeType.AnyAlpha, dstType);
379
pmToSurfaceBlit = new XRPMScaledBlit(dstType, dstType);
380
}
381
382
public void Scale(SurfaceData src, SurfaceData dst, Composite comp, Region clip, int sx1, int sy1, int sx2, int sy2, double dx1, double dy1,
383
double dx2, double dy2) {
384
{
385
int w = sx2 - sx1;
386
int h = sy2 - sy1;
387
388
try {
389
SunToolkit.awtLock();
390
XRSurfaceData vImgSurface = XRPMBlitLoops.cacheToTmpSurface(src, (XRSurfaceData) dst, w, h, sx1, sy1);
391
pmToSurfaceBlit.Scale(vImgSurface, dst, comp, clip, 0, 0, w, h, dx1, dy1, dx2, dy2);
392
} finally {
393
SunToolkit.awtUnlock();
394
}
395
}
396
}
397
}
398
399
class XrSwToPMTransformedBlit extends TransformBlit {
400
TransformBlit pmToSurfaceBlit;
401
402
XrSwToPMTransformedBlit(SurfaceType srcType, SurfaceType dstType) {
403
super(srcType, CompositeType.AnyAlpha, dstType);
404
pmToSurfaceBlit = new XRPMTransformedBlit(dstType, dstType);
405
}
406
407
public void Transform(SurfaceData src, SurfaceData dst, Composite comp, Region clip, AffineTransform xform, int hint, int sx, int sy, int dstx,
408
int dsty, int w, int h) {
409
try {
410
SunToolkit.awtLock();
411
412
XRSurfaceData vImgSurface = XRPMBlitLoops.cacheToTmpSurface(src, (XRSurfaceData) dst, w, h, sx, sy);
413
pmToSurfaceBlit.Transform(vImgSurface, dst, comp, clip, xform, hint, 0, 0, dstx, dsty, w, h);
414
} finally {
415
SunToolkit.awtUnlock();
416
}
417
}
418
}
419
420