author | jdv |
Fri, 21 Jun 2019 12:08:37 +0530 | |
branch | metal-prototype-branch |
changeset 57416 | e153174dba06 |
child 57472 | 5c986f86899e |
permissions | -rw-r--r-- |
57416
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
1 |
/* |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
4 |
* |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
10 |
* |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
15 |
* accompanied this code). |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
16 |
* |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
20 |
* |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
23 |
* questions. |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
24 |
*/ |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
25 |
|
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
26 |
#ifndef HEADLESS |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
27 |
|
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
28 |
#include "sun_java2d_metal_MTLMaskFill.h" |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
29 |
|
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
30 |
#include "MTLMaskFill.h" |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
31 |
#include "MTLRenderQueue.h" |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
32 |
#include "MTLVertexCache.h" |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
33 |
|
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
34 |
/** |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
35 |
* This implementation first copies the alpha tile into a texture and then |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
36 |
* maps that texture to the destination surface. This approach appears to |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
37 |
* offer the best performance despite being a two-step process. |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
38 |
* |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
39 |
* When the source paint is a Color, we can simply use the GL_MODULATE |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
40 |
* function to multiply the current color (already premultiplied with the |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
41 |
* extra alpha value from the AlphaComposite) with the alpha value from |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
42 |
* the mask texture tile. In picture form, this process looks like: |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
43 |
* |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
44 |
* A R G B |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
45 |
* primary color Pa Pr Pg Pb (modulated with...) |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
46 |
* texture unit 0 Ca Ca Ca Ca |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
47 |
* --------------------------------------- |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
48 |
* resulting color Ra Rr Rg Rb |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
49 |
* |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
50 |
* where: |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
51 |
* Px = current color (already premultiplied by extra alpha) |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
52 |
* Cx = coverage value from mask tile |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
53 |
* Rx = resulting color/alpha component |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
54 |
* |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
55 |
* When the source paint is not a Color, it means that we are rendering with |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
56 |
* a complex paint (e.g. GradientPaint, TexturePaint). In this case, we |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
57 |
* rely on the GL_ARB_multitexture extension to effectively multiply the |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
58 |
* paint fragments (autogenerated on texture unit 1, see the |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
59 |
* MTLPaints_Set{Gradient,Texture,etc}Paint() methods for more details) |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
60 |
* with the coverage values from the mask texture tile (provided on texture |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
61 |
* unit 0), all of which is multiplied with the current color value (which |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
62 |
* contains the extra alpha value). In picture form: |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
63 |
* |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
64 |
* A R G B |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
65 |
* primary color Ea Ea Ea Ea (modulated with...) |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
66 |
* texture unit 0 Ca Ca Ca Ca (modulated with...) |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
67 |
* texture unit 1 Pa Pr Pg Pb |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
68 |
* --------------------------------------- |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
69 |
* resulting color Ra Rr Rg Rb |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
70 |
* |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
71 |
* where: |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
72 |
* Ea = extra alpha |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
73 |
* Cx = coverage value from mask tile |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
74 |
* Px = gradient/texture paint color (generated for each fragment) |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
75 |
* Rx = resulting color/alpha component |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
76 |
* |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
77 |
* Here are some descriptions of the many variables used in this method: |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
78 |
* x,y - upper left corner of the tile destination |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
79 |
* w,h - width/height of the mask tile |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
80 |
* x0 - placekeeper for the original destination x location |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
81 |
* tw,th - width/height of the actual texture tile in pixels |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
82 |
* sx1,sy1 - upper left corner of the mask tile source region |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
83 |
* sx2,sy2 - lower left corner of the mask tile source region |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
84 |
* sx,sy - "current" upper left corner of the mask tile region of interest |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
85 |
*/ |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
86 |
void |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
87 |
MTLMaskFill_MaskFill(MTLContext *mtlc, BMTLSDOps * dstOps, |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
88 |
jint x, jint y, jint w, jint h, |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
89 |
jint maskoff, jint maskscan, jint masklen, |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
90 |
unsigned char *pMask) |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
91 |
{ |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
92 |
//TODO |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
93 |
J2dTraceLn(J2D_TRACE_INFO, "MTLMaskFill_MaskFill"); |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
94 |
} |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
95 |
|
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
96 |
JNIEXPORT void JNICALL |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
97 |
Java_sun_java2d_metal_MTLMaskFill_maskFill |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
98 |
(JNIEnv *env, jobject self, |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
99 |
jint x, jint y, jint w, jint h, |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
100 |
jint maskoff, jint maskscan, jint masklen, |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
101 |
jbyteArray maskArray) |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
102 |
{ |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
103 |
MTLContext *mtlc = MTLRenderQueue_GetCurrentContext(); |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
104 |
unsigned char *mask; |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
105 |
//TODO |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
106 |
J2dTraceLn(J2D_TRACE_ERROR, "MTLMaskFill_maskFill"); |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
107 |
} |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
108 |
|
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
109 |
#endif /* !HEADLESS */ |