Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/macosx/classes/sun/java2d/metal/MTLBufImgOps.java
41159 views
1
/*
2
* Copyright (c) 2019, 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.metal;
27
28
import sun.java2d.SunGraphics2D;
29
import sun.java2d.SurfaceData;
30
import sun.java2d.loops.CompositeType;
31
import sun.java2d.pipe.BufferedBufImgOps;
32
33
import java.awt.image.AffineTransformOp;
34
import java.awt.image.BufferedImage;
35
import java.awt.image.BufferedImageOp;
36
import java.awt.image.ConvolveOp;
37
import java.awt.image.LookupOp;
38
import java.awt.image.RescaleOp;
39
40
import static sun.java2d.metal.MTLContext.MTLContextCaps.CAPS_EXT_BIOP_SHADER;
41
42
class MTLBufImgOps extends BufferedBufImgOps {
43
44
/**
45
* This method is called from MTLDrawImage.transformImage() only. It
46
* validates the provided BufferedImageOp to determine whether the op
47
* is one that can be accelerated by the MTL pipeline. If the operation
48
* cannot be completed for any reason, this method returns false;
49
* otherwise, the given BufferedImage is rendered to the destination
50
* using the provided BufferedImageOp and this method returns true.
51
*/
52
static boolean renderImageWithOp(SunGraphics2D sg, BufferedImage img,
53
BufferedImageOp biop, int x, int y)
54
{
55
// Validate the provided BufferedImage (make sure it is one that
56
// is supported, and that its properties are acceleratable)
57
if (biop instanceof ConvolveOp) {
58
if (!isConvolveOpValid((ConvolveOp)biop)) {
59
return false;
60
}
61
} else if (biop instanceof RescaleOp) {
62
if (!isRescaleOpValid((RescaleOp)biop, img)) {
63
return false;
64
}
65
} else if (biop instanceof LookupOp) {
66
if (!isLookupOpValid((LookupOp)biop, img)) {
67
return false;
68
}
69
} else {
70
// No acceleration for other BufferedImageOps (yet)
71
return false;
72
}
73
74
SurfaceData dstData = sg.surfaceData;
75
if (!(dstData instanceof MTLSurfaceData) ||
76
(sg.interpolationType == AffineTransformOp.TYPE_BICUBIC) ||
77
(sg.compositeState > SunGraphics2D.COMP_ALPHA))
78
{
79
return false;
80
}
81
82
SurfaceData srcData =
83
dstData.getSourceSurfaceData(img, SunGraphics2D.TRANSFORM_ISIDENT,
84
CompositeType.SrcOver, null);
85
if (!(srcData instanceof MTLSurfaceData)) {
86
// REMIND: this hack tries to ensure that we have a cached texture
87
srcData =
88
dstData.getSourceSurfaceData(img, SunGraphics2D.TRANSFORM_ISIDENT,
89
CompositeType.SrcOver, null);
90
if (!(srcData instanceof MTLSurfaceData)) {
91
return false;
92
}
93
}
94
95
// Verify that the source surface is actually a texture and
96
// that the operation is supported
97
MTLSurfaceData mtlSrc = (MTLSurfaceData)srcData;
98
MTLGraphicsConfig gc = mtlSrc.getMTLGraphicsConfig();
99
if (mtlSrc.getType() != MTLSurfaceData.TEXTURE ||
100
!gc.isCapPresent(CAPS_EXT_BIOP_SHADER))
101
{
102
return false;
103
}
104
105
int sw = img.getWidth();
106
int sh = img.getHeight();
107
MTLBlitLoops.IsoBlit(srcData, dstData,
108
img, biop,
109
sg.composite, sg.getCompClip(),
110
sg.transform, sg.interpolationType,
111
0, 0, sw, sh,
112
x, y, x+sw, y+sh,
113
true);
114
115
return true;
116
}
117
}
118
119