Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLMaskFill.m
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
#include "sun_java2d_metal_MTLMaskFill.h"
27
28
#include "MTLMaskFill.h"
29
#include "MTLRenderQueue.h"
30
#include "MTLVertexCache.h"
31
32
/**
33
* In case of Metal we use shader for texture mapping.
34
*
35
* Descriptions of the many variables used in this method:
36
* x,y - upper left corner of the tile destination
37
* w,h - width/height of the mask tile
38
* x0 - placekeeper for the original destination x location
39
* tw,th - width/height of the actual texture tile in pixels
40
* sx1,sy1 - upper left corner of the mask tile source region
41
* sx2,sy2 - lower left corner of the mask tile source region
42
* sx,sy - "current" upper left corner of the mask tile region of interest
43
*/
44
void
45
MTLMaskFill_MaskFill(MTLContext *mtlc, BMTLSDOps * dstOps,
46
jint x, jint y, jint w, jint h,
47
jint maskoff, jint maskscan, jint masklen,
48
unsigned char *pMask)
49
{
50
J2dTraceLn5(J2D_TRACE_INFO, "MTLMaskFill_MaskFill (x=%d y=%d w=%d h=%d pMask=%p)", x, y, w, h, dstOps->pTexture);
51
jint tw, th, x0;
52
jint sx1, sy1, sx2, sy2;
53
jint sx, sy, sw, sh;
54
55
x0 = x;
56
tw = MTLVC_MASK_CACHE_TILE_WIDTH;
57
th = MTLVC_MASK_CACHE_TILE_HEIGHT;
58
sx1 = maskoff % maskscan;
59
sy1 = maskoff / maskscan;
60
sx2 = sx1 + w;
61
sy2 = sy1 + h;
62
63
64
for (sy = sy1; sy < sy2; sy += th, y += th) {
65
x = x0;
66
sh = ((sy + th) > sy2) ? (sy2 - sy) : th;
67
68
for (sx = sx1; sx < sx2; sx += tw, x += tw) {
69
sw = ((sx + tw) > sx2) ? (sx2 - sx) : tw;
70
MTLVertexCache_AddMaskQuad(mtlc,
71
sx, sy, x, y, sw, sh,
72
maskscan, pMask, dstOps);
73
}
74
}
75
}
76
77
JNIEXPORT void JNICALL
78
Java_sun_java2d_metal_MTLMaskFill_maskFill
79
(JNIEnv *env, jobject self,
80
jint x, jint y, jint w, jint h,
81
jint maskoff, jint maskscan, jint masklen,
82
jbyteArray maskArray)
83
{
84
MTLContext *mtlc = MTLRenderQueue_GetCurrentContext();
85
BMTLSDOps *dstOps = MTLRenderQueue_GetCurrentDestination();
86
unsigned char *mask;
87
88
J2dTraceLn(J2D_TRACE_ERROR, "MTLMaskFill_maskFill");
89
90
if (maskArray != NULL) {
91
mask = (unsigned char *)
92
(*env)->GetPrimitiveArrayCritical(env, maskArray, NULL);
93
} else {
94
mask = NULL;
95
}
96
97
MTLMaskFill_MaskFill(mtlc, dstOps,
98
x, y, w, h,
99
maskoff, maskscan, masklen, mask);
100
if (mtlc != NULL) {
101
RESET_PREVIOUS_OP();
102
[mtlc.encoderManager endEncoder];
103
MTLCommandBufferWrapper * cbwrapper = [mtlc pullCommandBufferWrapper];
104
id<MTLCommandBuffer> commandbuf = [cbwrapper getCommandBuffer];
105
[commandbuf addCompletedHandler:^(id <MTLCommandBuffer> commandbuf) {
106
[cbwrapper release];
107
}];
108
[commandbuf commit];
109
}
110
111
if (mask != NULL) {
112
(*env)->ReleasePrimitiveArrayCritical(env, maskArray, mask, JNI_ABORT);
113
}
114
}
115
116