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/MTLComposite.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 "MTLComposite.h"
27
#include "sun_java2d_SunGraphics2D.h"
28
#include "java_awt_AlphaComposite.h"
29
30
@implementation MTLComposite {
31
jint _compState;
32
jint _compositeRule;
33
jint _xorPixel;
34
jfloat _extraAlpha;
35
}
36
37
- (id)init {
38
self = [super init];
39
if (self) {
40
_compositeRule = -1;
41
_compState = -1;
42
_xorPixel = 0;
43
_extraAlpha = 1;
44
}
45
return self;
46
}
47
48
- (BOOL)isEqual:(MTLComposite *)other {
49
if (self == other)
50
return YES;
51
52
if (_compState == other->_compState) {
53
if (_compState == sun_java2d_SunGraphics2D_COMP_XOR) {
54
return _xorPixel == other->_xorPixel;
55
}
56
57
if (_compState == sun_java2d_SunGraphics2D_COMP_ALPHA) {
58
return _extraAlpha == other->_extraAlpha
59
&& _compositeRule == other->_compositeRule;
60
}
61
}
62
63
return NO;
64
}
65
66
- (void)copyFrom:(MTLComposite *)other {
67
_extraAlpha = other->_extraAlpha;
68
_compositeRule = other->_compositeRule;
69
_compState = other->_compState;
70
_xorPixel = other->_xorPixel;
71
}
72
73
- (void)setRule:(jint)rule {
74
_extraAlpha = 1.f;
75
_compositeRule = rule;
76
}
77
78
- (void)setRule:(jint)rule extraAlpha:(jfloat)extraAlpha {
79
_compState = sun_java2d_SunGraphics2D_COMP_ALPHA;
80
_extraAlpha = extraAlpha;
81
_compositeRule = rule;
82
}
83
84
- (void)reset {
85
_compState = sun_java2d_SunGraphics2D_COMP_ISCOPY;
86
_compositeRule = java_awt_AlphaComposite_SRC;
87
_extraAlpha = 1.f;
88
}
89
90
- (jint)getRule {
91
return _compositeRule;
92
}
93
94
- (NSString *)getDescription {
95
const char * result = "";
96
switch (_compositeRule) {
97
case java_awt_AlphaComposite_CLEAR:
98
{
99
result = "CLEAR";
100
}
101
break;
102
case java_awt_AlphaComposite_SRC:
103
{
104
result = "SRC";
105
}
106
break;
107
case java_awt_AlphaComposite_DST:
108
{
109
result = "DST";
110
}
111
break;
112
case java_awt_AlphaComposite_SRC_OVER:
113
{
114
result = "SRC_OVER";
115
}
116
break;
117
case java_awt_AlphaComposite_DST_OVER:
118
{
119
result = "DST_OVER";
120
}
121
break;
122
case java_awt_AlphaComposite_SRC_IN:
123
{
124
result = "SRC_IN";
125
}
126
break;
127
case java_awt_AlphaComposite_DST_IN:
128
{
129
result = "DST_IN";
130
}
131
break;
132
case java_awt_AlphaComposite_SRC_OUT:
133
{
134
result = "SRC_OUT";
135
}
136
break;
137
case java_awt_AlphaComposite_DST_OUT:
138
{
139
result = "DST_OUT";
140
}
141
break;
142
case java_awt_AlphaComposite_SRC_ATOP:
143
{
144
result = "SRC_ATOP";
145
}
146
break;
147
case java_awt_AlphaComposite_DST_ATOP:
148
{
149
result = "DST_ATOP";
150
}
151
break;
152
case java_awt_AlphaComposite_XOR:
153
{
154
result = "XOR";
155
}
156
break;
157
default:
158
result = "UNKNOWN";
159
break;
160
}
161
const double epsilon = 0.001f;
162
if (fabs(_extraAlpha - 1.f) > epsilon) {
163
return [NSString stringWithFormat:@"%s [%1.2f]", result, _extraAlpha];
164
}
165
return [NSString stringWithFormat:@"%s", result];
166
}
167
168
- (void)setAlphaComposite:(jint)rule {
169
_compState = sun_java2d_SunGraphics2D_COMP_ALPHA;
170
[self setRule:rule];
171
}
172
173
174
- (jint)getCompositeState {
175
return _compState;
176
}
177
178
179
-(void)setXORComposite:(jint)color {
180
_compState = sun_java2d_SunGraphics2D_COMP_XOR;
181
_xorPixel = color;
182
}
183
184
-(jint)getXorColor {
185
return _xorPixel;
186
}
187
188
- (jfloat)getExtraAlpha {
189
return _extraAlpha;
190
}
191
192
@end
193
194