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/MTLRenderQueue.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 <stdlib.h>
27
28
#include "sun_java2d_pipe_BufferedOpCodes.h"
29
30
#include "jlong.h"
31
#include "MTLBlitLoops.h"
32
#include "MTLBufImgOps.h"
33
#include "MTLMaskBlit.h"
34
#include "MTLMaskFill.h"
35
#include "MTLPaints.h"
36
#include "MTLRenderQueue.h"
37
#include "MTLRenderer.h"
38
#include "MTLTextRenderer.h"
39
#import "ThreadUtilities.h"
40
41
/**
42
* References to the "current" context and destination surface.
43
*/
44
static MTLContext *mtlc = NULL;
45
static BMTLSDOps *dstOps = NULL;
46
jint mtlPreviousOp = MTL_OP_INIT;
47
48
49
extern void MTLGC_DestroyMTLGraphicsConfig(jlong pConfigInfo);
50
51
void MTLRenderQueue_CheckPreviousOp(jint op) {
52
53
if (mtlPreviousOp == op) {
54
// The op is the same as last time, so we can return immediately.
55
return;
56
}
57
58
if (op == MTL_OP_SET_COLOR) {
59
if (mtlPreviousOp != MTL_OP_MASK_OP) {
60
return; // SET_COLOR should not cause endEncoder
61
}
62
} else if (op == MTL_OP_MASK_OP) {
63
MTLVertexCache_EnableMaskCache(mtlc, dstOps);
64
mtlPreviousOp = op;
65
return;
66
}
67
68
J2dTraceLn1(J2D_TRACE_VERBOSE,
69
"MTLRenderQueue_CheckPreviousOp: new op=%d", op);
70
71
switch (mtlPreviousOp) {
72
case MTL_OP_INIT :
73
mtlPreviousOp = op;
74
return;
75
case MTL_OP_MASK_OP :
76
MTLVertexCache_DisableMaskCache(mtlc);
77
break;
78
}
79
80
if (mtlc != NULL) {
81
[mtlc.encoderManager endEncoder];
82
83
if (op == MTL_OP_RESET_PAINT || op == MTL_OP_SYNC || op == MTL_OP_SHAPE_CLIP_SPANS) {
84
MTLCommandBufferWrapper *cbwrapper = [mtlc pullCommandBufferWrapper];
85
id <MTLCommandBuffer> commandbuf = [cbwrapper getCommandBuffer];
86
[commandbuf addCompletedHandler:^(id <MTLCommandBuffer> commandbuf) {
87
[cbwrapper release];
88
}];
89
[commandbuf commit];
90
if (op == MTL_OP_SYNC || op == MTL_OP_SHAPE_CLIP_SPANS) {
91
[commandbuf waitUntilCompleted];
92
}
93
}
94
}
95
mtlPreviousOp = op;
96
}
97
98
JNIEXPORT void JNICALL
99
Java_sun_java2d_metal_MTLRenderQueue_flushBuffer
100
(JNIEnv *env, jobject mtlrq,
101
jlong buf, jint limit)
102
{
103
unsigned char *b, *end;
104
105
J2dTraceLn1(J2D_TRACE_INFO,
106
"MTLRenderQueue_flushBuffer: limit=%d", limit);
107
108
b = (unsigned char *)jlong_to_ptr(buf);
109
if (b == NULL) {
110
J2dRlsTraceLn(J2D_TRACE_ERROR,
111
"MTLRenderQueue_flushBuffer: cannot get direct buffer address");
112
return;
113
}
114
115
end = b + limit;
116
@autoreleasepool {
117
while (b < end) {
118
jint opcode = NEXT_INT(b);
119
120
J2dTraceLn2(J2D_TRACE_VERBOSE,
121
"MTLRenderQueue_flushBuffer: opcode=%d, rem=%d",
122
opcode, (end-b));
123
124
switch (opcode) {
125
126
// draw ops
127
case sun_java2d_pipe_BufferedOpCodes_DRAW_LINE:
128
{
129
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
130
131
if ([mtlc useXORComposite]) {
132
commitEncodedCommands();
133
J2dTraceLn(J2D_TRACE_VERBOSE,
134
"DRAW_LINE in XOR mode - Force commit earlier draw calls before DRAW_LINE.");
135
}
136
jint x1 = NEXT_INT(b);
137
jint y1 = NEXT_INT(b);
138
jint x2 = NEXT_INT(b);
139
jint y2 = NEXT_INT(b);
140
MTLRenderer_DrawLine(mtlc, dstOps, x1, y1, x2, y2);
141
break;
142
}
143
case sun_java2d_pipe_BufferedOpCodes_DRAW_RECT:
144
{
145
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
146
147
if ([mtlc useXORComposite]) {
148
commitEncodedCommands();
149
J2dTraceLn(J2D_TRACE_VERBOSE,
150
"DRAW_RECT in XOR mode - Force commit earlier draw calls before DRAW_RECT.");
151
}
152
jint x = NEXT_INT(b);
153
jint y = NEXT_INT(b);
154
jint w = NEXT_INT(b);
155
jint h = NEXT_INT(b);
156
MTLRenderer_DrawRect(mtlc, dstOps, x, y, w, h);
157
break;
158
}
159
case sun_java2d_pipe_BufferedOpCodes_DRAW_POLY:
160
{
161
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
162
jint nPoints = NEXT_INT(b);
163
jboolean isClosed = NEXT_BOOLEAN(b);
164
jint transX = NEXT_INT(b);
165
jint transY = NEXT_INT(b);
166
jint *xPoints = (jint *)b;
167
jint *yPoints = ((jint *)b) + nPoints;
168
169
if ([mtlc useXORComposite]) {
170
commitEncodedCommands();
171
J2dTraceLn(J2D_TRACE_VERBOSE,
172
"DRAW_POLY in XOR mode - Force commit earlier draw calls before DRAW_POLY.");
173
174
// draw separate (N-1) lines using N points
175
for(int point = 0; point < nPoints-1; point++) {
176
jint x1 = xPoints[point] + transX;
177
jint y1 = yPoints[point] + transY;
178
jint x2 = xPoints[point + 1] + transX;
179
jint y2 = yPoints[point + 1] + transY;
180
MTLRenderer_DrawLine(mtlc, dstOps, x1, y1, x2, y2);
181
}
182
183
if (isClosed) {
184
MTLRenderer_DrawLine(mtlc, dstOps, xPoints[0] + transX, yPoints[0] + transY,
185
xPoints[nPoints-1] + transX, yPoints[nPoints-1] + transY);
186
}
187
} else {
188
MTLRenderer_DrawPoly(mtlc, dstOps, nPoints, isClosed, transX, transY, xPoints, yPoints);
189
}
190
191
SKIP_BYTES(b, nPoints * BYTES_PER_POLY_POINT);
192
break;
193
}
194
case sun_java2d_pipe_BufferedOpCodes_DRAW_PIXEL:
195
{
196
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
197
198
if ([mtlc useXORComposite]) {
199
commitEncodedCommands();
200
J2dTraceLn(J2D_TRACE_VERBOSE,
201
"DRAW_PIXEL in XOR mode - Force commit earlier draw calls before DRAW_PIXEL.");
202
}
203
204
jint x = NEXT_INT(b);
205
jint y = NEXT_INT(b);
206
CONTINUE_IF_NULL(mtlc);
207
MTLRenderer_DrawPixel(mtlc, dstOps, x, y);
208
break;
209
}
210
case sun_java2d_pipe_BufferedOpCodes_DRAW_SCANLINES:
211
{
212
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
213
214
if ([mtlc useXORComposite]) {
215
commitEncodedCommands();
216
J2dTraceLn(J2D_TRACE_VERBOSE,
217
"DRAW_SCANLINES in XOR mode - Force commit earlier draw calls before "
218
"DRAW_SCANLINES.");
219
}
220
221
jint count = NEXT_INT(b);
222
MTLRenderer_DrawScanlines(mtlc, dstOps, count, (jint *)b);
223
224
SKIP_BYTES(b, count * BYTES_PER_SCANLINE);
225
break;
226
}
227
case sun_java2d_pipe_BufferedOpCodes_DRAW_PARALLELOGRAM:
228
{
229
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
230
231
if ([mtlc useXORComposite]) {
232
commitEncodedCommands();
233
J2dTraceLn(J2D_TRACE_VERBOSE,
234
"DRAW_PARALLELOGRAM in XOR mode - Force commit earlier draw calls before "
235
"DRAW_PARALLELOGRAM.");
236
}
237
238
jfloat x11 = NEXT_FLOAT(b);
239
jfloat y11 = NEXT_FLOAT(b);
240
jfloat dx21 = NEXT_FLOAT(b);
241
jfloat dy21 = NEXT_FLOAT(b);
242
jfloat dx12 = NEXT_FLOAT(b);
243
jfloat dy12 = NEXT_FLOAT(b);
244
jfloat lwr21 = NEXT_FLOAT(b);
245
jfloat lwr12 = NEXT_FLOAT(b);
246
247
MTLRenderer_DrawParallelogram(mtlc, dstOps,
248
x11, y11,
249
dx21, dy21,
250
dx12, dy12,
251
lwr21, lwr12);
252
break;
253
}
254
case sun_java2d_pipe_BufferedOpCodes_DRAW_AAPARALLELOGRAM:
255
{
256
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
257
jfloat x11 = NEXT_FLOAT(b);
258
jfloat y11 = NEXT_FLOAT(b);
259
jfloat dx21 = NEXT_FLOAT(b);
260
jfloat dy21 = NEXT_FLOAT(b);
261
jfloat dx12 = NEXT_FLOAT(b);
262
jfloat dy12 = NEXT_FLOAT(b);
263
jfloat lwr21 = NEXT_FLOAT(b);
264
jfloat lwr12 = NEXT_FLOAT(b);
265
266
MTLRenderer_DrawAAParallelogram(mtlc, dstOps,
267
x11, y11,
268
dx21, dy21,
269
dx12, dy12,
270
lwr21, lwr12);
271
break;
272
}
273
274
// fill ops
275
case sun_java2d_pipe_BufferedOpCodes_FILL_RECT:
276
{
277
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
278
279
if ([mtlc useXORComposite]) {
280
commitEncodedCommands();
281
J2dTraceLn(J2D_TRACE_VERBOSE,
282
"FILL_RECT in XOR mode - Force commit earlier draw calls before FILL_RECT.");
283
}
284
285
jint x = NEXT_INT(b);
286
jint y = NEXT_INT(b);
287
jint w = NEXT_INT(b);
288
jint h = NEXT_INT(b);
289
MTLRenderer_FillRect(mtlc, dstOps, x, y, w, h);
290
break;
291
}
292
case sun_java2d_pipe_BufferedOpCodes_FILL_SPANS:
293
{
294
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
295
296
if ([mtlc useXORComposite]) {
297
commitEncodedCommands();
298
J2dTraceLn(J2D_TRACE_VERBOSE,
299
"FILL_SPANS in XOR mode - Force commit earlier draw calls before FILL_SPANS.");
300
}
301
302
jint count = NEXT_INT(b);
303
MTLRenderer_FillSpans(mtlc, dstOps, count, (jint *)b);
304
SKIP_BYTES(b, count * BYTES_PER_SPAN);
305
break;
306
}
307
case sun_java2d_pipe_BufferedOpCodes_FILL_PARALLELOGRAM:
308
{
309
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
310
311
if ([mtlc useXORComposite]) {
312
commitEncodedCommands();
313
J2dTraceLn(J2D_TRACE_VERBOSE,
314
"FILL_PARALLELOGRAM in XOR mode - Force commit earlier draw calls before "
315
"FILL_PARALLELOGRAM.");
316
}
317
318
jfloat x11 = NEXT_FLOAT(b);
319
jfloat y11 = NEXT_FLOAT(b);
320
jfloat dx21 = NEXT_FLOAT(b);
321
jfloat dy21 = NEXT_FLOAT(b);
322
jfloat dx12 = NEXT_FLOAT(b);
323
jfloat dy12 = NEXT_FLOAT(b);
324
MTLRenderer_FillParallelogram(mtlc, dstOps,
325
x11, y11,
326
dx21, dy21,
327
dx12, dy12);
328
break;
329
}
330
case sun_java2d_pipe_BufferedOpCodes_FILL_AAPARALLELOGRAM:
331
{
332
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
333
jfloat x11 = NEXT_FLOAT(b);
334
jfloat y11 = NEXT_FLOAT(b);
335
jfloat dx21 = NEXT_FLOAT(b);
336
jfloat dy21 = NEXT_FLOAT(b);
337
jfloat dx12 = NEXT_FLOAT(b);
338
jfloat dy12 = NEXT_FLOAT(b);
339
MTLRenderer_FillAAParallelogram(mtlc, dstOps,
340
x11, y11,
341
dx21, dy21,
342
dx12, dy12);
343
break;
344
}
345
346
// text-related ops
347
case sun_java2d_pipe_BufferedOpCodes_DRAW_GLYPH_LIST:
348
{
349
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
350
351
if ([mtlc useXORComposite]) {
352
commitEncodedCommands();
353
J2dTraceLn(J2D_TRACE_VERBOSE,
354
"DRAW_GLYPH_LIST in XOR mode - Force commit earlier draw calls before "
355
"DRAW_GLYPH_LIST.");
356
}
357
358
jint numGlyphs = NEXT_INT(b);
359
jint packedParams = NEXT_INT(b);
360
jfloat glyphListOrigX = NEXT_FLOAT(b);
361
jfloat glyphListOrigY = NEXT_FLOAT(b);
362
jboolean usePositions = EXTRACT_BOOLEAN(packedParams,
363
OFFSET_POSITIONS);
364
jboolean subPixPos = EXTRACT_BOOLEAN(packedParams,
365
OFFSET_SUBPIXPOS);
366
jboolean rgbOrder = EXTRACT_BOOLEAN(packedParams,
367
OFFSET_RGBORDER);
368
jint lcdContrast = EXTRACT_BYTE(packedParams,
369
OFFSET_CONTRAST);
370
unsigned char *images = b;
371
unsigned char *positions;
372
jint bytesPerGlyph;
373
if (usePositions) {
374
positions = (b + numGlyphs * BYTES_PER_GLYPH_IMAGE);
375
bytesPerGlyph = BYTES_PER_POSITIONED_GLYPH;
376
} else {
377
positions = NULL;
378
bytesPerGlyph = BYTES_PER_GLYPH_IMAGE;
379
}
380
MTLTR_DrawGlyphList(env, mtlc, dstOps,
381
numGlyphs, usePositions,
382
subPixPos, rgbOrder, lcdContrast,
383
glyphListOrigX, glyphListOrigY,
384
images, positions);
385
SKIP_BYTES(b, numGlyphs * bytesPerGlyph);
386
break;
387
}
388
389
// copy-related ops
390
case sun_java2d_pipe_BufferedOpCodes_COPY_AREA:
391
{
392
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
393
jint x = NEXT_INT(b);
394
jint y = NEXT_INT(b);
395
jint w = NEXT_INT(b);
396
jint h = NEXT_INT(b);
397
jint dx = NEXT_INT(b);
398
jint dy = NEXT_INT(b);
399
MTLBlitLoops_CopyArea(env, mtlc, dstOps,
400
x, y, w, h, dx, dy);
401
break;
402
}
403
case sun_java2d_pipe_BufferedOpCodes_BLIT:
404
{
405
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
406
jint packedParams = NEXT_INT(b);
407
jint sx1 = NEXT_INT(b);
408
jint sy1 = NEXT_INT(b);
409
jint sx2 = NEXT_INT(b);
410
jint sy2 = NEXT_INT(b);
411
jdouble dx1 = NEXT_DOUBLE(b);
412
jdouble dy1 = NEXT_DOUBLE(b);
413
jdouble dx2 = NEXT_DOUBLE(b);
414
jdouble dy2 = NEXT_DOUBLE(b);
415
jlong pSrc = NEXT_LONG(b);
416
jlong pDst = NEXT_LONG(b);
417
jint hint = EXTRACT_BYTE(packedParams, OFFSET_HINT);
418
jboolean texture = EXTRACT_BOOLEAN(packedParams,
419
OFFSET_TEXTURE);
420
jboolean xform = EXTRACT_BOOLEAN(packedParams,
421
OFFSET_XFORM);
422
jboolean isoblit = EXTRACT_BOOLEAN(packedParams,
423
OFFSET_ISOBLIT);
424
if (isoblit) {
425
MTLBlitLoops_IsoBlit(env, mtlc, pSrc, pDst,
426
xform, hint, texture,
427
sx1, sy1, sx2, sy2,
428
dx1, dy1, dx2, dy2);
429
} else {
430
jint srctype = EXTRACT_BYTE(packedParams, OFFSET_SRCTYPE);
431
MTLBlitLoops_Blit(env, mtlc, pSrc, pDst,
432
xform, hint, srctype, texture,
433
sx1, sy1, sx2, sy2,
434
dx1, dy1, dx2, dy2);
435
}
436
break;
437
}
438
case sun_java2d_pipe_BufferedOpCodes_SURFACE_TO_SW_BLIT:
439
{
440
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
441
jint sx = NEXT_INT(b);
442
jint sy = NEXT_INT(b);
443
jint dx = NEXT_INT(b);
444
jint dy = NEXT_INT(b);
445
jint w = NEXT_INT(b);
446
jint h = NEXT_INT(b);
447
jint dsttype = NEXT_INT(b);
448
jlong pSrc = NEXT_LONG(b);
449
jlong pDst = NEXT_LONG(b);
450
MTLBlitLoops_SurfaceToSwBlit(env, mtlc,
451
pSrc, pDst, dsttype,
452
sx, sy, dx, dy, w, h);
453
break;
454
}
455
case sun_java2d_pipe_BufferedOpCodes_MASK_FILL:
456
{
457
jint x = NEXT_INT(b);
458
jint y = NEXT_INT(b);
459
jint w = NEXT_INT(b);
460
jint h = NEXT_INT(b);
461
jint maskoff = NEXT_INT(b);
462
jint maskscan = NEXT_INT(b);
463
jint masklen = NEXT_INT(b);
464
unsigned char *pMask = (masklen > 0) ? b : NULL;
465
if (mtlc == nil)
466
return;
467
CHECK_PREVIOUS_OP(MTL_OP_MASK_OP);
468
MTLMaskFill_MaskFill(mtlc, dstOps, x, y, w, h,
469
maskoff, maskscan, masklen, pMask);
470
SKIP_BYTES(b, masklen);
471
break;
472
}
473
case sun_java2d_pipe_BufferedOpCodes_MASK_BLIT:
474
{
475
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
476
jint dstx = NEXT_INT(b);
477
jint dsty = NEXT_INT(b);
478
jint width = NEXT_INT(b);
479
jint height = NEXT_INT(b);
480
jint masklen = width * height * sizeof(jint);
481
MTLMaskBlit_MaskBlit(env, mtlc, dstOps,
482
dstx, dsty, width, height, b);
483
SKIP_BYTES(b, masklen);
484
break;
485
}
486
487
// state-related ops
488
case sun_java2d_pipe_BufferedOpCodes_SET_RECT_CLIP:
489
{
490
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
491
jint x1 = NEXT_INT(b);
492
jint y1 = NEXT_INT(b);
493
jint x2 = NEXT_INT(b);
494
jint y2 = NEXT_INT(b);
495
[mtlc setClipRectX1:x1 Y1:y1 X2:x2 Y2:y2];
496
break;
497
}
498
case sun_java2d_pipe_BufferedOpCodes_BEGIN_SHAPE_CLIP:
499
{
500
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
501
[mtlc beginShapeClip:dstOps];
502
break;
503
}
504
case sun_java2d_pipe_BufferedOpCodes_SET_SHAPE_CLIP_SPANS:
505
{
506
CHECK_PREVIOUS_OP(MTL_OP_SHAPE_CLIP_SPANS);
507
// This results in creation of new render encoder with
508
// stencil buffer set as render target
509
jint count = NEXT_INT(b);
510
MTLRenderer_FillSpans(mtlc, dstOps, count, (jint *)b);
511
SKIP_BYTES(b, count * BYTES_PER_SPAN);
512
break;
513
}
514
case sun_java2d_pipe_BufferedOpCodes_END_SHAPE_CLIP:
515
{
516
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
517
[mtlc endShapeClip:dstOps];
518
break;
519
}
520
case sun_java2d_pipe_BufferedOpCodes_RESET_CLIP:
521
{
522
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
523
[mtlc resetClip];
524
break;
525
}
526
case sun_java2d_pipe_BufferedOpCodes_SET_ALPHA_COMPOSITE:
527
{
528
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
529
jint rule = NEXT_INT(b);
530
jfloat extraAlpha = NEXT_FLOAT(b);
531
jint flags = NEXT_INT(b);
532
[mtlc setAlphaCompositeRule:rule extraAlpha:extraAlpha flags:flags];
533
break;
534
}
535
case sun_java2d_pipe_BufferedOpCodes_SET_XOR_COMPOSITE:
536
{
537
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
538
jint xorPixel = NEXT_INT(b);
539
[mtlc setXorComposite:xorPixel];
540
break;
541
}
542
case sun_java2d_pipe_BufferedOpCodes_RESET_COMPOSITE:
543
{
544
/* TODO: check whether something needs to be done here if we are moving out of XOR composite
545
commitEncodedCommands();
546
MTLCommandBufferWrapper * cbwrapper = [mtlc pullCommandBufferWrapper];
547
[cbwrapper onComplete];
548
549
J2dTraceLn(J2D_TRACE_VERBOSE,
550
"RESET_COMPOSITE - Force commit earlier draw calls before RESET_COMPOSITE.");*/
551
552
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
553
[mtlc resetComposite];
554
break;
555
}
556
case sun_java2d_pipe_BufferedOpCodes_SET_TRANSFORM:
557
{
558
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
559
jdouble m00 = NEXT_DOUBLE(b);
560
jdouble m10 = NEXT_DOUBLE(b);
561
jdouble m01 = NEXT_DOUBLE(b);
562
jdouble m11 = NEXT_DOUBLE(b);
563
jdouble m02 = NEXT_DOUBLE(b);
564
jdouble m12 = NEXT_DOUBLE(b);
565
[mtlc setTransformM00:m00 M10:m10 M01:m01 M11:m11 M02:m02 M12:m12];
566
break;
567
}
568
case sun_java2d_pipe_BufferedOpCodes_RESET_TRANSFORM:
569
{
570
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
571
[mtlc resetTransform];
572
break;
573
}
574
575
// context-related ops
576
case sun_java2d_pipe_BufferedOpCodes_SET_SURFACES:
577
{
578
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
579
jlong pSrc = NEXT_LONG(b);
580
jlong pDst = NEXT_LONG(b);
581
582
if (mtlc != NULL) {
583
[mtlc.encoderManager endEncoder];
584
MTLCommandBufferWrapper * cbwrapper = [mtlc pullCommandBufferWrapper];
585
id<MTLCommandBuffer> commandbuf = [cbwrapper getCommandBuffer];
586
[commandbuf addCompletedHandler:^(id <MTLCommandBuffer> commandbuf) {
587
[cbwrapper release];
588
}];
589
[commandbuf commit];
590
}
591
mtlc = [MTLContext setSurfacesEnv:env src:pSrc dst:pDst];
592
dstOps = (BMTLSDOps *)jlong_to_ptr(pDst);
593
break;
594
}
595
case sun_java2d_pipe_BufferedOpCodes_SET_SCRATCH_SURFACE:
596
{
597
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
598
jlong pConfigInfo = NEXT_LONG(b);
599
MTLGraphicsConfigInfo *mtlInfo =
600
(MTLGraphicsConfigInfo *)jlong_to_ptr(pConfigInfo);
601
602
if (mtlInfo == NULL) {
603
604
} else {
605
MTLContext *newMtlc = mtlInfo->context;
606
if (newMtlc == NULL) {
607
608
} else {
609
if (mtlc != NULL) {
610
[mtlc.encoderManager endEncoder];
611
MTLCommandBufferWrapper * cbwrapper = [mtlc pullCommandBufferWrapper];
612
id<MTLCommandBuffer> commandbuf = [cbwrapper getCommandBuffer];
613
[commandbuf addCompletedHandler:^(id <MTLCommandBuffer> commandbuf) {
614
[cbwrapper release];
615
}];
616
[commandbuf commit];
617
}
618
mtlc = newMtlc;
619
dstOps = NULL;
620
}
621
}
622
break;
623
}
624
case sun_java2d_pipe_BufferedOpCodes_FLUSH_SURFACE:
625
{
626
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
627
jlong pData = NEXT_LONG(b);
628
BMTLSDOps *mtlsdo = (BMTLSDOps *)jlong_to_ptr(pData);
629
if (mtlsdo != NULL) {
630
CONTINUE_IF_NULL(mtlc);
631
MTLTR_FreeGlyphCaches();
632
MTLSD_Delete(env, mtlsdo);
633
}
634
break;
635
}
636
case sun_java2d_pipe_BufferedOpCodes_DISPOSE_SURFACE:
637
{
638
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
639
jlong pData = NEXT_LONG(b);
640
BMTLSDOps *mtlsdo = (BMTLSDOps *)jlong_to_ptr(pData);
641
if (mtlsdo != NULL) {
642
CONTINUE_IF_NULL(mtlc);
643
MTLSD_Delete(env, mtlsdo);
644
if (mtlsdo->privOps != NULL) {
645
free(mtlsdo->privOps);
646
}
647
}
648
break;
649
}
650
case sun_java2d_pipe_BufferedOpCodes_DISPOSE_CONFIG:
651
{
652
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
653
jlong pConfigInfo = NEXT_LONG(b);
654
CONTINUE_IF_NULL(mtlc);
655
656
if (mtlc != NULL) {
657
[mtlc.encoderManager endEncoder];
658
}
659
660
MTLGC_DestroyMTLGraphicsConfig(pConfigInfo);
661
662
mtlc = NULL;
663
// dstOps = NULL;
664
break;
665
}
666
667
case sun_java2d_pipe_BufferedOpCodes_SYNC:
668
{
669
CHECK_PREVIOUS_OP(MTL_OP_SYNC);
670
break;
671
}
672
673
// special no-op (mainly used for achieving 8-byte alignment)
674
case sun_java2d_pipe_BufferedOpCodes_NOOP:
675
break;
676
677
// paint-related ops
678
case sun_java2d_pipe_BufferedOpCodes_RESET_PAINT:
679
{
680
CHECK_PREVIOUS_OP(MTL_OP_RESET_PAINT);
681
[mtlc resetPaint];
682
break;
683
}
684
case sun_java2d_pipe_BufferedOpCodes_SET_COLOR:
685
{
686
CHECK_PREVIOUS_OP(MTL_OP_SET_COLOR);
687
jint pixel = NEXT_INT(b);
688
[mtlc setColorPaint:pixel];
689
break;
690
}
691
case sun_java2d_pipe_BufferedOpCodes_SET_GRADIENT_PAINT:
692
{
693
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
694
jboolean useMask= NEXT_BOOLEAN(b);
695
jboolean cyclic = NEXT_BOOLEAN(b);
696
jdouble p0 = NEXT_DOUBLE(b);
697
jdouble p1 = NEXT_DOUBLE(b);
698
jdouble p3 = NEXT_DOUBLE(b);
699
jint pixel1 = NEXT_INT(b);
700
jint pixel2 = NEXT_INT(b);
701
[mtlc setGradientPaintUseMask:useMask
702
cyclic:cyclic
703
p0:p0
704
p1:p1
705
p3:p3
706
pixel1:pixel1
707
pixel2:pixel2];
708
break;
709
}
710
case sun_java2d_pipe_BufferedOpCodes_SET_LINEAR_GRADIENT_PAINT:
711
{
712
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
713
jboolean useMask = NEXT_BOOLEAN(b);
714
jboolean linear = NEXT_BOOLEAN(b);
715
jint cycleMethod = NEXT_INT(b);
716
jint numStops = NEXT_INT(b);
717
jfloat p0 = NEXT_FLOAT(b);
718
jfloat p1 = NEXT_FLOAT(b);
719
jfloat p3 = NEXT_FLOAT(b);
720
void *fractions, *pixels;
721
fractions = b; SKIP_BYTES(b, numStops * sizeof(jfloat));
722
pixels = b; SKIP_BYTES(b, numStops * sizeof(jint));
723
[mtlc setLinearGradientPaint:useMask
724
linear:linear
725
cycleMethod:cycleMethod
726
numStops:numStops
727
p0:p0
728
p1:p1
729
p3:p3
730
fractions:fractions
731
pixels:pixels];
732
break;
733
}
734
case sun_java2d_pipe_BufferedOpCodes_SET_RADIAL_GRADIENT_PAINT:
735
{
736
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
737
jboolean useMask = NEXT_BOOLEAN(b);
738
jboolean linear = NEXT_BOOLEAN(b);
739
jint numStops = NEXT_INT(b);
740
jint cycleMethod = NEXT_INT(b);
741
jfloat m00 = NEXT_FLOAT(b);
742
jfloat m01 = NEXT_FLOAT(b);
743
jfloat m02 = NEXT_FLOAT(b);
744
jfloat m10 = NEXT_FLOAT(b);
745
jfloat m11 = NEXT_FLOAT(b);
746
jfloat m12 = NEXT_FLOAT(b);
747
jfloat focusX = NEXT_FLOAT(b);
748
void *fractions, *pixels;
749
fractions = b; SKIP_BYTES(b, numStops * sizeof(jfloat));
750
pixels = b; SKIP_BYTES(b, numStops * sizeof(jint));
751
[mtlc setRadialGradientPaint:useMask
752
linear:linear
753
cycleMethod:cycleMethod
754
numStops:numStops
755
m00:m00
756
m01:m01
757
m02:m02
758
m10:m10
759
m11:m11
760
m12:m12
761
focusX:focusX
762
fractions:fractions
763
pixels:pixels];
764
break;
765
}
766
case sun_java2d_pipe_BufferedOpCodes_SET_TEXTURE_PAINT:
767
{
768
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
769
jboolean useMask= NEXT_BOOLEAN(b);
770
jboolean filter = NEXT_BOOLEAN(b);
771
jlong pSrc = NEXT_LONG(b);
772
jdouble xp0 = NEXT_DOUBLE(b);
773
jdouble xp1 = NEXT_DOUBLE(b);
774
jdouble xp3 = NEXT_DOUBLE(b);
775
jdouble yp0 = NEXT_DOUBLE(b);
776
jdouble yp1 = NEXT_DOUBLE(b);
777
jdouble yp3 = NEXT_DOUBLE(b);
778
[mtlc setTexturePaint:useMask
779
pSrcOps:pSrc
780
filter:filter
781
xp0:xp0
782
xp1:xp1
783
xp3:xp3
784
yp0:yp0
785
yp1:yp1
786
yp3:yp3];
787
break;
788
}
789
790
// BufferedImageOp-related ops
791
case sun_java2d_pipe_BufferedOpCodes_ENABLE_CONVOLVE_OP:
792
{
793
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
794
jlong pSrc = NEXT_LONG(b);
795
jboolean edgeZero = NEXT_BOOLEAN(b);
796
jint kernelWidth = NEXT_INT(b);
797
jint kernelHeight = NEXT_INT(b);
798
799
BMTLSDOps * bmtlsdOps = (BMTLSDOps *)pSrc;
800
MTLConvolveOp * convolveOp = [[MTLConvolveOp alloc] init:edgeZero
801
kernelWidth:kernelWidth
802
kernelHeight:kernelHeight
803
srcWidth:bmtlsdOps->width
804
srcHeight:bmtlsdOps->height
805
kernel:b
806
device:mtlc.device
807
];
808
[mtlc setBufImgOp:convolveOp];
809
SKIP_BYTES(b, kernelWidth * kernelHeight * sizeof(jfloat));
810
break;
811
}
812
case sun_java2d_pipe_BufferedOpCodes_DISABLE_CONVOLVE_OP:
813
{
814
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
815
[mtlc setBufImgOp:NULL];
816
break;
817
}
818
case sun_java2d_pipe_BufferedOpCodes_ENABLE_RESCALE_OP:
819
{
820
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
821
jlong pSrc = NEXT_LONG(b);
822
jboolean nonPremult = NEXT_BOOLEAN(b);
823
jint numFactors = 4;
824
unsigned char *scaleFactors = b;
825
unsigned char *offsets = (b + numFactors * sizeof(jfloat));
826
MTLRescaleOp * rescaleOp =
827
[[MTLRescaleOp alloc] init:nonPremult factors:scaleFactors offsets:offsets];
828
[mtlc setBufImgOp:rescaleOp];
829
SKIP_BYTES(b, numFactors * sizeof(jfloat) * 2);
830
break;
831
}
832
case sun_java2d_pipe_BufferedOpCodes_DISABLE_RESCALE_OP:
833
{
834
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
835
[mtlc setBufImgOp:NULL];
836
break;
837
}
838
case sun_java2d_pipe_BufferedOpCodes_ENABLE_LOOKUP_OP:
839
{
840
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
841
jlong pSrc = NEXT_LONG(b);
842
jboolean nonPremult = NEXT_BOOLEAN(b);
843
jboolean shortData = NEXT_BOOLEAN(b);
844
jint numBands = NEXT_INT(b);
845
jint bandLength = NEXT_INT(b);
846
jint offset = NEXT_INT(b);
847
jint bytesPerElem = shortData ? sizeof(jshort):sizeof(jbyte);
848
void *tableValues = b;
849
850
MTLLookupOp * lookupOp = [[MTLLookupOp alloc] init:nonPremult
851
shortData:shortData
852
numBands:numBands
853
bandLength:bandLength
854
offset:offset
855
tableValues:tableValues
856
device:mtlc.device];
857
[mtlc setBufImgOp:lookupOp];
858
SKIP_BYTES(b, numBands * bandLength * bytesPerElem);
859
break;
860
}
861
case sun_java2d_pipe_BufferedOpCodes_DISABLE_LOOKUP_OP:
862
{
863
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
864
[mtlc setBufImgOp:NULL];
865
break;
866
}
867
868
default:
869
J2dRlsTraceLn1(J2D_TRACE_ERROR,
870
"MTLRenderQueue_flushBuffer: invalid opcode=%d", opcode);
871
return;
872
}
873
}
874
875
if (mtlc != NULL) {
876
if (mtlPreviousOp == MTL_OP_MASK_OP) {
877
MTLVertexCache_DisableMaskCache(mtlc);
878
}
879
[mtlc.encoderManager endEncoder];
880
MTLCommandBufferWrapper * cbwrapper = [mtlc pullCommandBufferWrapper];
881
id<MTLCommandBuffer> commandbuf = [cbwrapper getCommandBuffer];
882
[commandbuf addCompletedHandler:^(id <MTLCommandBuffer> commandbuf) {
883
[cbwrapper release];
884
}];
885
[commandbuf commit];
886
BMTLSDOps *dstOps = MTLRenderQueue_GetCurrentDestination();
887
if (dstOps != NULL) {
888
MTLSDOps *dstMTLOps = (MTLSDOps *)dstOps->privOps;
889
MTLLayer *layer = (MTLLayer*)dstMTLOps->layer;
890
if (layer != NULL) {
891
[layer startDisplayLink];
892
}
893
}
894
}
895
RESET_PREVIOUS_OP();
896
}
897
}
898
899
/**
900
* Returns a pointer to the "current" context, as set by the last SET_SURFACES
901
* or SET_SCRATCH_SURFACE operation.
902
*/
903
MTLContext *
904
MTLRenderQueue_GetCurrentContext()
905
{
906
return mtlc;
907
}
908
909
/**
910
* Returns a pointer to the "current" destination surface, as set by the last
911
* SET_SURFACES operation.
912
*/
913
BMTLSDOps *
914
MTLRenderQueue_GetCurrentDestination()
915
{
916
return dstOps;
917
}
918
919
/**
920
* commit earlier encoded commmands
921
* these would be rendered to the back-buffer - which is read in shader while rendering in XOR mode
922
*/
923
void commitEncodedCommands() {
924
[mtlc.encoderManager endEncoder];
925
926
MTLCommandBufferWrapper *cbwrapper = [mtlc pullCommandBufferWrapper];
927
id <MTLCommandBuffer> commandbuf = [cbwrapper getCommandBuffer];
928
[commandbuf addCompletedHandler:^(id <MTLCommandBuffer> commandbuf) {
929
[cbwrapper release];
930
}];
931
[commandbuf commit];
932
[commandbuf waitUntilCompleted];
933
}
934
935