Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
skiko
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liuqiang
skiko
Commits
81cbf367
Unverified
Commit
81cbf367
authored
Oct 27, 2021
by
Aleksandr Veselov
Committed by
GitHub
Oct 27, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement native Shader methods, add creation test (#317)
parent
b508c81c
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
207 additions
and
169 deletions
+207
-169
Shader.kt
skiko/src/commonMain/kotlin/org/jetbrains/skia/Shader.kt
+24
-16
ShaderTest.kt
skiko/src/commonTest/kotlin/org/jetbrains/skia/ShaderTest.kt
+101
-0
Shader.cc
skiko/src/jvmMain/cpp/common/Shader.cc
+14
-24
PaintTest.kt
skiko/src/jvmTest/kotlin/org/jetbrains/skiko/PaintTest.kt
+15
-0
org_jetbrains_skiko_PaintTest_canDrawShader.png
...reenshots/org_jetbrains_skiko_PaintTest_canDrawShader.png
+0
-0
Shader.cc
skiko/src/nativeJsMain/cpp/Shader.cc
+53
-129
No files found.
skiko/src/commonMain/kotlin/org/jetbrains/skia/Shader.kt
View file @
81cbf367
...
...
@@ -44,6 +44,7 @@ class Shader internal constructor(ptr: NativePointer) : RefCnt(ptr) {
y1
,
toInterop
(
colors
),
toInterop
(
positions
),
colors
.
size
,
style
.
tileMode
.
ordinal
,
style
.
_getFlags
(),
toInterop
(
style
.
_getMatrixArray
())
...
...
@@ -86,6 +87,7 @@ class Shader internal constructor(ptr: NativePointer) : RefCnt(ptr) {
toInterop
(
Color4f
.
flattenArray
(
colors
)),
getPtr
(
cs
),
toInterop
(
positions
),
colors
.
size
,
style
.
tileMode
.
ordinal
,
style
.
_getFlags
(),
toInterop
(
style
.
_getMatrixArray
())
...
...
@@ -134,6 +136,7 @@ class Shader internal constructor(ptr: NativePointer) : RefCnt(ptr) {
r
,
toInterop
(
colors
),
toInterop
(
positions
),
colors
.
size
,
style
.
tileMode
.
ordinal
,
style
.
_getFlags
(),
toInterop
(
style
.
_getMatrixArray
())
...
...
@@ -174,6 +177,7 @@ class Shader internal constructor(ptr: NativePointer) : RefCnt(ptr) {
toInterop
(
Color4f
.
flattenArray
(
colors
)),
getPtr
(
cs
),
toInterop
(
positions
),
colors
.
size
,
style
.
tileMode
.
ordinal
,
style
.
_getFlags
(),
toInterop
(
style
.
_getMatrixArray
())
...
...
@@ -237,6 +241,7 @@ class Shader internal constructor(ptr: NativePointer) : RefCnt(ptr) {
r1
,
toInterop
(
colors
),
toInterop
(
positions
),
colors
.
size
,
style
.
tileMode
.
ordinal
,
style
.
_getFlags
(),
toInterop
(
style
.
_getMatrixArray
())
...
...
@@ -285,6 +290,7 @@ class Shader internal constructor(ptr: NativePointer) : RefCnt(ptr) {
toInterop
(
Color4f
.
flattenArray
(
colors
)),
getPtr
(
cs
),
toInterop
(
positions
),
colors
.
size
,
style
.
tileMode
.
ordinal
,
style
.
_getFlags
(),
toInterop
(
style
.
_getMatrixArray
())
...
...
@@ -358,6 +364,7 @@ class Shader internal constructor(ptr: NativePointer) : RefCnt(ptr) {
endAngle
,
toInterop
(
colors
),
toInterop
(
positions
),
colors
.
size
,
style
.
tileMode
.
ordinal
,
style
.
_getFlags
(),
toInterop
(
style
.
_getMatrixArray
())
...
...
@@ -401,6 +408,7 @@ class Shader internal constructor(ptr: NativePointer) : RefCnt(ptr) {
toInterop
(
Color4f
.
flattenArray
(
colors
)),
getPtr
(
cs
),
toInterop
(
positions
),
colors
.
size
,
style
.
tileMode
.
ordinal
,
style
.
_getFlags
(),
toInterop
(
style
.
_getMatrixArray
())
...
...
@@ -461,18 +469,13 @@ class Shader internal constructor(ptr: NativePointer) : RefCnt(ptr) {
baseFrequencyY
:
Float
,
numOctaves
:
Int
,
seed
:
Float
,
tile
s
:
Array
<
ISize
>
tile
Size
:
ISize
=
ISize
.
makeEmpty
()
):
Shader
{
return
try
{
val
arr
=
IntArray
(
tiles
.
size
*
2
)
for
(
i
in
tiles
.
indices
)
{
arr
[
i
*
2
]
=
tiles
[
i
].
width
arr
[
i
*
2
+
1
]
=
tiles
[
i
].
height
}
Stats
.
onNativeCall
()
Shader
(
interopScope
{
_nMakeFractalNoise
(
baseFrequencyX
,
baseFrequencyY
,
numOctaves
,
seed
,
t
oInterop
(
arr
)
)
_nMakeFractalNoise
(
baseFrequencyX
,
baseFrequencyY
,
numOctaves
,
seed
,
t
ileSize
.
width
,
tileSize
.
height
)
}
)
}
finally
{
...
...
@@ -485,18 +488,13 @@ class Shader internal constructor(ptr: NativePointer) : RefCnt(ptr) {
baseFrequencyY
:
Float
,
numOctaves
:
Int
,
seed
:
Float
,
tile
s
:
Array
<
ISize
>
tile
Size
:
ISize
=
ISize
.
makeEmpty
()
):
Shader
{
return
try
{
val
arr
=
IntArray
(
tiles
.
size
*
2
)
for
(
i
in
tiles
.
indices
)
{
arr
[
i
*
2
]
=
tiles
[
i
].
width
arr
[
i
*
2
+
1
]
=
tiles
[
i
].
height
}
Stats
.
onNativeCall
()
Shader
(
interopScope
{
_nMakeTurbulence
(
baseFrequencyX
,
baseFrequencyY
,
numOctaves
,
seed
,
t
oInterop
(
arr
)
)
_nMakeTurbulence
(
baseFrequencyX
,
baseFrequencyY
,
numOctaves
,
seed
,
t
ileSize
.
width
,
tileSize
.
height
)
}
)
}
finally
{
...
...
@@ -533,6 +531,7 @@ private external fun _nMakeLinearGradient(
y1
:
Float
,
colors
:
InteropPointer
,
positions
:
InteropPointer
,
count
:
Int
,
tileType
:
Int
,
flags
:
Int
,
matrix
:
InteropPointer
...
...
@@ -548,6 +547,7 @@ private external fun _nMakeLinearGradientCS(
colors
:
InteropPointer
,
colorSpacePtr
:
NativePointer
,
positions
:
InteropPointer
,
count
:
Int
,
tileType
:
Int
,
flags
:
Int
,
matrix
:
InteropPointer
...
...
@@ -561,6 +561,7 @@ private external fun _nMakeRadialGradient(
r
:
Float
,
colors
:
InteropPointer
,
positions
:
InteropPointer
,
count
:
Int
,
tileType
:
Int
,
flags
:
Int
,
matrix
:
InteropPointer
...
...
@@ -575,6 +576,7 @@ private external fun _nMakeRadialGradientCS(
colors
:
InteropPointer
,
colorSpacePtr
:
NativePointer
,
positions
:
InteropPointer
,
count
:
Int
,
tileType
:
Int
,
flags
:
Int
,
matrix
:
InteropPointer
...
...
@@ -591,6 +593,7 @@ private external fun _nMakeTwoPointConicalGradient(
r1
:
Float
,
colors
:
InteropPointer
,
positions
:
InteropPointer
,
count
:
Int
,
tileType
:
Int
,
flags
:
Int
,
matrix
:
InteropPointer
...
...
@@ -608,6 +611,7 @@ private external fun _nMakeTwoPointConicalGradientCS(
colors
:
InteropPointer
,
colorSpacePtr
:
NativePointer
,
positions
:
InteropPointer
,
count
:
Int
,
tileType
:
Int
,
flags
:
Int
,
matrix
:
InteropPointer
...
...
@@ -622,6 +626,7 @@ private external fun _nMakeSweepGradient(
endAngle
:
Float
,
colors
:
InteropPointer
,
positions
:
InteropPointer
,
count
:
Int
,
tileType
:
Int
,
flags
:
Int
,
matrix
:
InteropPointer
...
...
@@ -637,6 +642,7 @@ private external fun _nMakeSweepGradientCS(
colors
:
InteropPointer
,
colorSpacePtr
:
NativePointer
,
positions
:
InteropPointer
,
count
:
Int
,
tileType
:
Int
,
flags
:
Int
,
matrix
:
InteropPointer
...
...
@@ -649,7 +655,8 @@ private external fun _nMakeFractalNoise(
baseFrequencyY
:
Float
,
numOctaves
:
Int
,
seed
:
Float
,
tiles
:
InteropPointer
tileWidth
:
Int
,
tileHeight
:
Int
,
):
NativePointer
...
...
@@ -659,7 +666,8 @@ private external fun _nMakeTurbulence(
baseFrequencyY
:
Float
,
numOctaves
:
Int
,
seed
:
Float
,
tiles
:
InteropPointer
tileWidth
:
Int
,
tileHeight
:
Int
,
):
NativePointer
@ExternalSymbolName
(
"org_jetbrains_skia_Shader__1nMakeColor"
)
...
...
skiko/src/commonTest/kotlin/org/jetbrains/skia/ShaderTest.kt
0 → 100644
View file @
81cbf367
package
org.jetbrains.skia
import
kotlin.math.PI
import
kotlin.test.Test
class
ShaderTest
{
@Test
fun
canMakeLinear
()
{
val
start
=
Point
(
0.0f
,
0.0f
)
val
end
=
Point
(
16.0f
,
16.0f
)
val
colors
=
intArrayOf
(
Color
.
RED
,
Color
.
BLUE
,
Color
.
GREEN
)
val
positions
=
floatArrayOf
(
0.0f
,
0.7f
,
1.0f
)
val
colorSpace
=
ColorSpace
.
sRGBLinear
val
colorsF
=
colors
.
map
{
Color4f
(
it
)
}.
toTypedArray
()
Shader
.
makeLinearGradient
(
start
,
end
,
colors
)
Shader
.
makeLinearGradient
(
start
,
end
,
colors
,
positions
)
Shader
.
makeLinearGradient
(
start
,
end
,
colors
,
positions
,
style
=
GradientStyle
.
DEFAULT
)
Shader
.
makeLinearGradient
(
start
,
end
,
colorsF
,
colorSpace
,
positions
,
GradientStyle
.
DEFAULT
)
}
@Test
fun
canMakeRadial
()
{
val
center
=
Point
(
8.0f
,
8.0f
)
val
radius
=
8.0f
val
colors
=
intArrayOf
(
Color
.
RED
,
Color
.
BLUE
,
Color
.
GREEN
)
val
positions
=
floatArrayOf
(
0.0f
,
0.7f
,
1.0f
)
val
colorSpace
=
ColorSpace
.
sRGBLinear
val
colorsF
=
colors
.
map
{
Color4f
(
it
)
}.
toTypedArray
()
Shader
.
makeRadialGradient
(
center
,
radius
,
colors
)
Shader
.
makeRadialGradient
(
center
,
radius
,
colors
,
positions
)
Shader
.
makeRadialGradient
(
center
,
radius
,
colors
,
positions
,
style
=
GradientStyle
.
DEFAULT
)
Shader
.
makeRadialGradient
(
center
,
radius
,
colorsF
,
colorSpace
,
positions
,
GradientStyle
.
DEFAULT
)
}
@Test
fun
canMakeConical
()
{
val
start
=
Point
(
8.0f
,
8.0f
)
val
startRadius
=
2.0f
val
end
=
Point
(
16.0f
,
16.0f
)
val
endRadius
=
8.0f
val
colors
=
intArrayOf
(
Color
.
RED
,
Color
.
BLUE
,
Color
.
GREEN
)
val
positions
=
floatArrayOf
(
0.0f
,
0.7f
,
1.0f
)
val
colorSpace
=
ColorSpace
.
sRGBLinear
val
colorsF
=
colors
.
map
{
Color4f
(
it
)
}.
toTypedArray
()
Shader
.
makeTwoPointConicalGradient
(
start
,
startRadius
,
end
,
endRadius
,
colors
)
Shader
.
makeTwoPointConicalGradient
(
start
,
startRadius
,
end
,
endRadius
,
colors
,
positions
)
Shader
.
makeTwoPointConicalGradient
(
start
,
startRadius
,
end
,
endRadius
,
colors
,
positions
,
style
=
GradientStyle
.
DEFAULT
)
Shader
.
makeTwoPointConicalGradient
(
start
,
startRadius
,
end
,
endRadius
,
colorsF
,
colorSpace
,
positions
,
GradientStyle
.
DEFAULT
)
}
@Test
fun
canMakeSweep
()
{
val
center
=
Point
(
8.0f
,
8.0f
)
val
startAngle
=
0.0f
val
endAngle
=
PI
.
toFloat
()
val
colors
=
intArrayOf
(
Color
.
RED
,
Color
.
BLUE
,
Color
.
GREEN
)
val
positions
=
floatArrayOf
(
0.0f
,
0.7f
,
1.0f
)
val
colorSpace
=
ColorSpace
.
sRGBLinear
val
colorsF
=
colors
.
map
{
Color4f
(
it
)
}.
toTypedArray
()
Shader
.
makeSweepGradient
(
center
,
colors
)
Shader
.
makeSweepGradient
(
center
,
colors
,
positions
)
Shader
.
makeSweepGradient
(
center
,
colors
,
positions
,
style
=
GradientStyle
.
DEFAULT
)
Shader
.
makeSweepGradient
(
center
,
startAngle
,
endAngle
,
colors
,
positions
,
GradientStyle
.
DEFAULT
)
Shader
.
makeSweepGradient
(
center
,
startAngle
,
endAngle
,
colorsF
,
colorSpace
,
positions
,
GradientStyle
.
DEFAULT
)
}
@Test
fun
canMakeEmpty
()
{
Shader
.
makeEmpty
()
}
@Test
fun
canMakeColor
()
{
Shader
.
makeColor
(
Color
.
RED
)
Shader
.
makeColor
(
Color4f
(
Color
.
BLUE
),
ColorSpace
.
sRGB
)
}
@Test
fun
canMakeBlend
()
{
Shader
.
makeBlend
(
mode
=
BlendMode
.
MULTIPLY
,
src
=
Shader
.
makeLinearGradient
(
0.0f
,
0.0f
,
16.0f
,
16.0f
,
intArrayOf
(
Color
.
BLACK
,
Color
.
WHITE
)),
dst
=
Shader
.
makeRadialGradient
(
8.0f
,
8.0f
,
8.0f
,
intArrayOf
(
Color
.
RED
,
Color
.
BLUE
))
)
}
@Test
fun
canMakeNoise
()
{
Shader
.
makeFractalNoise
(
0.4f
,
0.5f
,
10
,
0.5f
)
Shader
.
makeFractalNoise
(
0.4f
,
0.5f
,
10
,
0.5f
,
ISize
(
16
,
16
))
Shader
.
makeTurbulence
(
0.4f
,
0.5f
,
10
,
0.5f
)
Shader
.
makeTurbulence
(
0.4f
,
0.5f
,
10
,
0.5f
,
ISize
(
16
,
16
))
}
}
\ No newline at end of file
skiko/src/jvmMain/cpp/common/Shader.cc
View file @
81cbf367
...
...
@@ -17,7 +17,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_ShaderKt__1nMakeWithC
}
extern
"C"
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skia_ShaderKt__1nMakeLinearGradient
(
JNIEnv
*
env
,
jclass
jclass
,
jfloat
x0
,
jfloat
y0
,
jfloat
x1
,
jfloat
y1
,
jintArray
colorsArray
,
jfloatArray
posArray
,
jint
tileModeInt
,
jint
flags
,
jfloatArray
matrixArray
)
{
(
JNIEnv
*
env
,
jclass
jclass
,
jfloat
x0
,
jfloat
y0
,
jfloat
x1
,
jfloat
y1
,
jintArray
colorsArray
,
jfloatArray
posArray
,
jint
_count
,
jint
tileModeInt
,
jint
flags
,
jfloatArray
matrixArray
)
{
SkPoint
pts
[
2
]
{
SkPoint
::
Make
(
x0
,
y0
),
SkPoint
::
Make
(
x1
,
y1
)};
jint
*
colors
=
env
->
GetIntArrayElements
(
colorsArray
,
nullptr
);
float
*
pos
=
posArray
==
nullptr
?
nullptr
:
env
->
GetFloatArrayElements
(
posArray
,
nullptr
);
...
...
@@ -31,7 +31,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_ShaderKt__1nMakeLinea
}
extern
"C"
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skia_ShaderKt__1nMakeLinearGradientCS
(
JNIEnv
*
env
,
jclass
jclass
,
jfloat
x0
,
jfloat
y0
,
jfloat
x1
,
jfloat
y1
,
jfloatArray
colorsArray
,
jlong
colorSpacePtr
,
jfloatArray
posArray
,
jint
tileModeInt
,
jint
flags
,
jfloatArray
matrixArray
)
{
(
JNIEnv
*
env
,
jclass
jclass
,
jfloat
x0
,
jfloat
y0
,
jfloat
x1
,
jfloat
y1
,
jfloatArray
colorsArray
,
jlong
colorSpacePtr
,
jfloatArray
posArray
,
jint
_count
,
jint
tileModeInt
,
jint
flags
,
jfloatArray
matrixArray
)
{
SkPoint
pts
[
2
]
{
SkPoint
::
Make
(
x0
,
y0
),
SkPoint
::
Make
(
x1
,
y1
)};
float
*
colors
=
env
->
GetFloatArrayElements
(
colorsArray
,
nullptr
);
sk_sp
<
SkColorSpace
>
colorSpace
=
sk_ref_sp
<
SkColorSpace
>
(
reinterpret_cast
<
SkColorSpace
*>
(
static_cast
<
uintptr_t
>
(
colorSpacePtr
)));
...
...
@@ -45,7 +45,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_ShaderKt__1nMakeLinea
}
extern
"C"
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skia_ShaderKt__1nMakeRadialGradient
(
JNIEnv
*
env
,
jclass
jclass
,
jfloat
x
,
jfloat
y
,
jfloat
r
,
jintArray
colorsArray
,
jfloatArray
posArray
,
jint
tileModeInt
,
jint
flags
,
jfloatArray
matrixArray
)
{
(
JNIEnv
*
env
,
jclass
jclass
,
jfloat
x
,
jfloat
y
,
jfloat
r
,
jintArray
colorsArray
,
jfloatArray
posArray
,
jint
_count
,
jint
tileModeInt
,
jint
flags
,
jfloatArray
matrixArray
)
{
jint
*
colors
=
env
->
GetIntArrayElements
(
colorsArray
,
nullptr
);
float
*
pos
=
posArray
==
nullptr
?
nullptr
:
env
->
GetFloatArrayElements
(
posArray
,
nullptr
);
SkTileMode
tileMode
=
static_cast
<
SkTileMode
>
(
tileModeInt
);
...
...
@@ -58,7 +58,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_ShaderKt__1nMakeRadia
}
extern
"C"
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skia_ShaderKt__1nMakeRadialGradientCS
(
JNIEnv
*
env
,
jclass
jclass
,
jfloat
x
,
jfloat
y
,
jfloat
r
,
jfloatArray
colorsArray
,
jlong
colorSpacePtr
,
jfloatArray
posArray
,
jint
tileModeInt
,
jint
flags
,
jfloatArray
matrixArray
)
{
(
JNIEnv
*
env
,
jclass
jclass
,
jfloat
x
,
jfloat
y
,
jfloat
r
,
jfloatArray
colorsArray
,
jlong
colorSpacePtr
,
jfloatArray
posArray
,
jint
_count
,
jint
tileModeInt
,
jint
flags
,
jfloatArray
matrixArray
)
{
float
*
colors
=
env
->
GetFloatArrayElements
(
colorsArray
,
nullptr
);
sk_sp
<
SkColorSpace
>
colorSpace
=
sk_ref_sp
<
SkColorSpace
>
(
reinterpret_cast
<
SkColorSpace
*>
(
static_cast
<
uintptr_t
>
(
colorSpacePtr
)));
float
*
pos
=
env
->
GetFloatArrayElements
(
posArray
,
nullptr
);
...
...
@@ -71,7 +71,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_ShaderKt__1nMakeRadia
}
extern
"C"
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skia_ShaderKt__1nMakeTwoPointConicalGradient
(
JNIEnv
*
env
,
jclass
jclass
,
jfloat
x0
,
jfloat
y0
,
jfloat
r0
,
jfloat
x1
,
jfloat
y1
,
jfloat
r1
,
jintArray
colorsArray
,
jfloatArray
posArray
,
jint
tileModeInt
,
jint
flags
,
jfloatArray
matrixArray
)
{
(
JNIEnv
*
env
,
jclass
jclass
,
jfloat
x0
,
jfloat
y0
,
jfloat
r0
,
jfloat
x1
,
jfloat
y1
,
jfloat
r1
,
jintArray
colorsArray
,
jfloatArray
posArray
,
jint
_count
,
jint
tileModeInt
,
jint
flags
,
jfloatArray
matrixArray
)
{
jint
*
colors
=
env
->
GetIntArrayElements
(
colorsArray
,
nullptr
);
float
*
pos
=
posArray
==
nullptr
?
nullptr
:
env
->
GetFloatArrayElements
(
posArray
,
nullptr
);
SkTileMode
tileMode
=
static_cast
<
SkTileMode
>
(
tileModeInt
);
...
...
@@ -84,7 +84,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_ShaderKt__1nMakeTwoPo
}
extern
"C"
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skia_ShaderKt__1nMakeTwoPointConicalGradientCS
(
JNIEnv
*
env
,
jclass
jclass
,
jfloat
x0
,
jfloat
y0
,
jfloat
r0
,
jfloat
x1
,
jfloat
y1
,
jfloat
r1
,
jfloatArray
colorsArray
,
jlong
colorSpacePtr
,
jfloatArray
posArray
,
jint
tileModeInt
,
jint
flags
,
jfloatArray
matrixArray
)
{
(
JNIEnv
*
env
,
jclass
jclass
,
jfloat
x0
,
jfloat
y0
,
jfloat
r0
,
jfloat
x1
,
jfloat
y1
,
jfloat
r1
,
jfloatArray
colorsArray
,
jlong
colorSpacePtr
,
jfloatArray
posArray
,
jint
_count
,
jint
tileModeInt
,
jint
flags
,
jfloatArray
matrixArray
)
{
float
*
colors
=
env
->
GetFloatArrayElements
(
colorsArray
,
nullptr
);
sk_sp
<
SkColorSpace
>
colorSpace
=
sk_ref_sp
<
SkColorSpace
>
(
reinterpret_cast
<
SkColorSpace
*>
(
static_cast
<
uintptr_t
>
(
colorSpacePtr
)));
float
*
pos
=
env
->
GetFloatArrayElements
(
posArray
,
nullptr
);
...
...
@@ -97,7 +97,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_ShaderKt__1nMakeTwoPo
}
extern
"C"
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skia_ShaderKt__1nMakeSweepGradient
(
JNIEnv
*
env
,
jclass
jclass
,
jfloat
x
,
jfloat
y
,
jfloat
start
,
jfloat
end
,
jintArray
colorsArray
,
jfloatArray
posArray
,
jint
tileModeInt
,
jint
flags
,
jfloatArray
matrixArray
)
{
(
JNIEnv
*
env
,
jclass
jclass
,
jfloat
x
,
jfloat
y
,
jfloat
start
,
jfloat
end
,
jintArray
colorsArray
,
jfloatArray
posArray
,
jint
_count
,
jint
tileModeInt
,
jint
flags
,
jfloatArray
matrixArray
)
{
jint
*
colors
=
env
->
GetIntArrayElements
(
colorsArray
,
nullptr
);
float
*
pos
=
posArray
==
nullptr
?
nullptr
:
env
->
GetFloatArrayElements
(
posArray
,
nullptr
);
SkTileMode
tileMode
=
static_cast
<
SkTileMode
>
(
tileModeInt
);
...
...
@@ -110,7 +110,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_ShaderKt__1nMakeSweep
}
extern
"C"
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skia_ShaderKt__1nMakeSweepGradientCS
(
JNIEnv
*
env
,
jclass
jclass
,
jfloat
x
,
jfloat
y
,
jfloat
start
,
jfloat
end
,
jfloatArray
colorsArray
,
jlong
colorSpacePtr
,
jfloatArray
posArray
,
jint
tileModeInt
,
jint
flags
,
jfloatArray
matrixArray
)
{
(
JNIEnv
*
env
,
jclass
jclass
,
jfloat
x
,
jfloat
y
,
jfloat
start
,
jfloat
end
,
jfloatArray
colorsArray
,
jlong
colorSpacePtr
,
jfloatArray
posArray
,
jint
_count
,
jint
tileModeInt
,
jint
flags
,
jfloatArray
matrixArray
)
{
float
*
colors
=
env
->
GetFloatArrayElements
(
colorsArray
,
nullptr
);
sk_sp
<
SkColorSpace
>
colorSpace
=
sk_ref_sp
<
SkColorSpace
>
(
reinterpret_cast
<
SkColorSpace
*>
(
static_cast
<
uintptr_t
>
(
colorSpacePtr
)));
float
*
pos
=
env
->
GetFloatArrayElements
(
posArray
,
nullptr
);
...
...
@@ -147,25 +147,15 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_ShaderKt__1nMakeBlend
}
extern
"C"
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skia_ShaderKt__1nMakeFractalNoise
(
JNIEnv
*
env
,
jclass
jclass
,
jfloat
baseFrequencyX
,
jfloat
baseFrequencyY
,
jint
numOctaves
,
jfloat
seed
,
jintArray
tilesArray
)
{
int
len
=
env
->
GetArrayLength
(
tilesArray
);
std
::
vector
<
SkISize
>
tiles
(
len
/
2
);
jint
*
arr
=
env
->
GetIntArrayElements
(
tilesArray
,
0
);
for
(
int
i
=
0
;
i
<
len
;
i
+=
2
)
tiles
[
i
/
2
]
=
{
arr
[
i
],
arr
[
i
+
1
]};
env
->
ReleaseIntArrayElements
(
tilesArray
,
arr
,
0
);
SkShader
*
ptr
=
SkPerlinNoiseShader
::
MakeFractalNoise
(
baseFrequencyX
,
baseFrequencyY
,
numOctaves
,
seed
,
tiles
.
data
()).
release
();
(
JNIEnv
*
env
,
jclass
jclass
,
jfloat
baseFrequencyX
,
jfloat
baseFrequencyY
,
jint
numOctaves
,
jfloat
seed
,
jint
tileW
,
jint
tileH
)
{
const
SkISize
tileSize
=
SkISize
::
Make
(
tileW
,
tileH
);
SkShader
*
ptr
=
SkPerlinNoiseShader
::
MakeFractalNoise
(
baseFrequencyX
,
baseFrequencyY
,
numOctaves
,
seed
,
&
tileSize
).
release
();
return
reinterpret_cast
<
jlong
>
(
ptr
);
}
extern
"C"
JNIEXPORT
jlong
JNICALL
Java_org_jetbrains_skia_ShaderKt__1nMakeTurbulence
(
JNIEnv
*
env
,
jclass
jclass
,
jfloat
baseFrequencyX
,
jfloat
baseFrequencyY
,
jint
numOctaves
,
jfloat
seed
,
jintArray
tilesArray
)
{
int
len
=
env
->
GetArrayLength
(
tilesArray
);
std
::
vector
<
SkISize
>
tiles
(
len
/
2
);
jint
*
arr
=
env
->
GetIntArrayElements
(
tilesArray
,
0
);
for
(
int
i
=
0
;
i
<
len
;
i
+=
2
)
tiles
[
i
/
2
]
=
{
arr
[
i
],
arr
[
i
+
1
]};
env
->
ReleaseIntArrayElements
(
tilesArray
,
arr
,
0
);
SkShader
*
ptr
=
SkPerlinNoiseShader
::
MakeTurbulence
(
baseFrequencyX
,
baseFrequencyY
,
numOctaves
,
seed
,
tiles
.
data
()).
release
();
(
JNIEnv
*
env
,
jclass
jclass
,
jfloat
baseFrequencyX
,
jfloat
baseFrequencyY
,
jint
numOctaves
,
jfloat
seed
,
jint
tileW
,
jint
tileH
)
{
const
SkISize
tileSize
=
SkISize
::
Make
(
tileW
,
tileH
);
SkShader
*
ptr
=
SkPerlinNoiseShader
::
MakeTurbulence
(
baseFrequencyX
,
baseFrequencyY
,
numOctaves
,
seed
,
&
tileSize
).
release
();
return
reinterpret_cast
<
jlong
>
(
ptr
);
}
skiko/src/jvmTest/kotlin/org/jetbrains/skiko/PaintTest.kt
View file @
81cbf367
...
...
@@ -48,6 +48,21 @@ class PaintTest {
screenshots
.
assert
(
surface
.
makeImageSnapshot
())
}
@Test
fun
canDrawShader
()
{
val
surface
=
Surface
.
makeRasterN32Premul
(
16
,
16
)
val
rect
=
Rect
(
1.0f
,
1.0f
,
15.0f
,
15.0f
)
surface
.
canvas
.
drawRect
(
r
=
rect
,
paint
=
Paint
().
apply
{
shader
=
Shader
.
makeLinearGradient
(
rect
.
left
,
rect
.
top
,
rect
.
right
,
rect
.
bottom
,
intArrayOf
(
Color
.
RED
,
Color
.
BLUE
))
}
)
screenshots
.
assert
(
surface
.
makeImageSnapshot
())
}
@Test
fun
paintTest
()
{
// TODO: ported from skija and we need address the commented out assertions
...
...
skiko/src/jvmTest/screenshots/org_jetbrains_skiko_PaintTest_canDrawShader.png
0 → 100644
View file @
81cbf367
195 Bytes
skiko/src/nativeJsMain/cpp/Shader.cc
View file @
81cbf367
...
...
@@ -5,6 +5,8 @@
#include "SkColorFilter.h"
#include "SkShader.h"
#include "SkGradientShader.h"
#include "SkPerlinNoiseShader.h"
#include "SkSize.h"
#include "common.h"
SKIKO_EXPORT
KNativePointer
org_jetbrains_skia_Shader__1nMakeWithColorFilter
...
...
@@ -17,165 +19,96 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_Shader__1nMakeWithColorFilter
SKIKO_EXPORT
KNativePointer
org_jetbrains_skia_Shader__1nMakeLinearGradient
(
KFloat
x0
,
KFloat
y0
,
KFloat
x1
,
KFloat
y1
,
KInt
*
colorsArray
,
KFloat
*
posArray
,
KInt
tileModeInt
,
KInt
flags
,
KFloat
*
matrixArray
)
{
TODO
(
"implement org_jetbrains_skia_Shader__1nMakeLinearGradient"
);
}
#if 0
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Shader__1nMakeLinearGradient
(KFloat x0, KFloat y0, KFloat x1, KFloat y1, KInt* colorsArray, KFloat* posArray, KInt tileModeInt, KInt flags, KFloat* matrixArray) {
(
KFloat
x0
,
KFloat
y0
,
KFloat
x1
,
KFloat
y1
,
KInt
*
colorsArray
,
KFloat
*
posArray
,
KInt
count
,
KInt
tileModeInt
,
KInt
flags
,
KFloat
*
matrixArray
)
{
SkPoint
pts
[
2
]
{
SkPoint
::
Make
(
x0
,
y0
),
SkPoint
::
Make
(
x1
,
y1
)};
KInt* colors = env->GetIntArrayElements(colorsArray, nullptr
);
float* pos =
posArray == nullptr ? nullptr : env->GetFloatArrayElements(posArray, nullptr
);
SkColor
*
colors
=
reinterpret_cast
<
SkColor
*>
(
colorsArray
);
float
*
pos
=
reinterpret_cast
<
float
*>
(
posArray
);
SkTileMode
tileMode
=
static_cast
<
SkTileMode
>
(
tileModeInt
);
std::unique_ptr<SkMatrix> localMatrix = skMatrix(env, matrixArray);
SkShader* ptr = SkGradientShader::MakeLinear(pts, reinterpret_cast<SkColor*>(colors), pos, env->GetArrayLength(colorsArray), tileMode, static_cast<uint32_t>(flags), localMatrix.get()).release();
env->ReleaseIntArrayElements(colorsArray, colors, 0);
if (posArray != nullptr)
env->ReleaseFloatArrayElements(posArray, pos, 0);
std
::
unique_ptr
<
SkMatrix
>
localMatrix
=
skMatrix
(
matrixArray
);
SkShader
*
ptr
=
SkGradientShader
::
MakeLinear
(
pts
,
colors
,
pos
,
count
,
tileMode
,
static_cast
<
uint32_t
>
(
flags
),
localMatrix
.
get
()).
release
();
return
reinterpret_cast
<
KNativePointer
>
(
ptr
);
}
#endif
SKIKO_EXPORT
KNativePointer
org_jetbrains_skia_Shader__1nMakeLinearGradientCS
(
KFloat
x0
,
KFloat
y0
,
KFloat
x1
,
KFloat
y1
,
KFloat
*
colorsArray
,
KNativePointer
colorSpacePtr
,
KFloat
*
posArray
,
KInt
tileModeInt
,
KInt
flags
,
KFloat
*
matrixArray
)
{
TODO
(
"implement org_jetbrains_skia_Shader__1nMakeLinearGradientCS"
);
}
#if 0
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Shader__1nMakeLinearGradientCS
(KFloat x0, KFloat y0, KFloat x1, KFloat y1, KFloat* colorsArray, KNativePointer colorSpacePtr, KFloat* posArray, KInt tileModeInt, KInt flags, KFloat* matrixArray) {
(
KFloat
x0
,
KFloat
y0
,
KFloat
x1
,
KFloat
y1
,
KFloat
*
colorsArray
,
KNativePointer
colorSpacePtr
,
KFloat
*
posArray
,
KInt
count
,
KInt
tileModeInt
,
KInt
flags
,
KFloat
*
matrixArray
)
{
SkPoint
pts
[
2
]
{
SkPoint
::
Make
(
x0
,
y0
),
SkPoint
::
Make
(
x1
,
y1
)};
float* colors = env->GetFloatArrayElements(colorsArray, nullptr
);
SkColor4f
*
colors
=
reinterpret_cast
<
SkColor4f
*>
(
colorsArray
);
sk_sp
<
SkColorSpace
>
colorSpace
=
sk_ref_sp
<
SkColorSpace
>
(
reinterpret_cast
<
SkColorSpace
*>
((
colorSpacePtr
)));
float* pos =
env->GetFloatArrayElements(posArray, nullptr
);
float
*
pos
=
reinterpret_cast
<
float
*>
(
posArray
);
SkTileMode
tileMode
=
static_cast
<
SkTileMode
>
(
tileModeInt
);
std::unique_ptr<SkMatrix> localMatrix = skMatrix(env, matrixArray);
SkShader* ptr = SkGradientShader::MakeLinear(pts, reinterpret_cast<SkColor4f*>(colors), colorSpace, pos, env->GetArrayLength(posArray), tileMode, static_cast<uint32_t>(flags), localMatrix.get()).release();
env->ReleaseFloatArrayElements(colorsArray, colors, 0);
env->ReleaseFloatArrayElements(posArray, pos, 0);
std
::
unique_ptr
<
SkMatrix
>
localMatrix
=
skMatrix
(
matrixArray
);
SkShader
*
ptr
=
SkGradientShader
::
MakeLinear
(
pts
,
colors
,
colorSpace
,
pos
,
count
,
tileMode
,
static_cast
<
uint32_t
>
(
flags
),
localMatrix
.
get
()).
release
();
return
reinterpret_cast
<
KNativePointer
>
(
ptr
);
}
#endif
SKIKO_EXPORT
KNativePointer
org_jetbrains_skia_Shader__1nMakeRadialGradient
(
KFloat
x
,
KFloat
y
,
KFloat
r
,
KInt
*
colorsArray
,
KFloat
*
posArray
,
KInt
tileModeInt
,
KInt
flags
,
KFloat
*
matrixArray
)
{
TODO
(
"implement org_jetbrains_skia_Shader__1nMakeRadialGradient"
);
}
#if 0
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Shader__1nMakeRadialGradient
(KFloat x, KFloat y, KFloat r, KInt* colorsArray, KFloat* posArray, KInt tileModeInt, KInt flags, KFloat* matrixArray) {
KInt* colors = env->GetIntArrayElements(colorsArray, nullptr);
float* pos = posArray == nullptr ? nullptr : env->GetFloatArrayElements(posArray, nullptr);
(
KFloat
x
,
KFloat
y
,
KFloat
r
,
KInt
*
colorsArray
,
KFloat
*
posArray
,
KInt
count
,
KInt
tileModeInt
,
KInt
flags
,
KFloat
*
matrixArray
)
{
SkColor
*
colors
=
reinterpret_cast
<
SkColor
*>
(
colorsArray
);
float
*
pos
=
reinterpret_cast
<
float
*>
(
posArray
);
SkTileMode
tileMode
=
static_cast
<
SkTileMode
>
(
tileModeInt
);
std::unique_ptr<SkMatrix> localMatrix = skMatrix(env, matrixArray);
SkShader* ptr = SkGradientShader::MakeRadial(SkPoint::Make(x, y), r, reinterpret_cast<SkColor*>(colors), pos, env->GetArrayLength(colorsArray), tileMode, static_cast<uint32_t>(flags), localMatrix.get()).release();
env->ReleaseIntArrayElements(colorsArray, colors, 0);
if (posArray != nullptr)
env->ReleaseFloatArrayElements(posArray, pos, 0);
std
::
unique_ptr
<
SkMatrix
>
localMatrix
=
skMatrix
(
matrixArray
);
SkShader
*
ptr
=
SkGradientShader
::
MakeRadial
(
SkPoint
::
Make
(
x
,
y
),
r
,
colors
,
pos
,
count
,
tileMode
,
static_cast
<
uint32_t
>
(
flags
),
localMatrix
.
get
()).
release
();
return
reinterpret_cast
<
KNativePointer
>
(
ptr
);
}
#endif
SKIKO_EXPORT
KNativePointer
org_jetbrains_skia_Shader__1nMakeRadialGradientCS
(
KFloat
x
,
KFloat
y
,
KFloat
r
,
KFloat
*
colorsArray
,
KNativePointer
colorSpacePtr
,
KFloat
*
posArray
,
KInt
tileModeInt
,
KInt
flags
,
KFloat
*
matrixArray
)
{
TODO
(
"implement org_jetbrains_skia_Shader__1nMakeRadialGradientCS"
);
}
#if 0
SKIKO_EXPORT
KNativePointer
org_jetbrains_skia_Shader__1nMakeRadialGradientCS
(KFloat x, KFloat y, KFloat r, KFloat* colorsArray, KNativePointer colorSpacePtr, KFloat* posArray, KInt tileModeInt, KInt flags, KFloat* matrixArray) {
float* colors = env->GetFloatArrayElements(colorsArray, nullptr
);
(
KFloat
x
,
KFloat
y
,
KFloat
r
,
KFloat
*
colorsArray
,
KNativePointer
colorSpacePtr
,
KFloat
*
posArray
,
KInt
count
,
KInt
tileModeInt
,
KInt
flags
,
KFloat
*
matrixArray
)
{
SkColor4f
*
colors
=
reinterpret_cast
<
SkColor4f
*>
(
colorsArray
);
sk_sp
<
SkColorSpace
>
colorSpace
=
sk_ref_sp
<
SkColorSpace
>
(
reinterpret_cast
<
SkColorSpace
*>
((
colorSpacePtr
)));
float* pos =
env->GetFloatArrayElements(posArray, nullptr
);
float
*
pos
=
reinterpret_cast
<
float
*>
(
posArray
);
SkTileMode
tileMode
=
static_cast
<
SkTileMode
>
(
tileModeInt
);
std::unique_ptr<SkMatrix> localMatrix = skMatrix(env, matrixArray);
SkShader* ptr = SkGradientShader::MakeRadial(SkPoint::Make(x, y), r, reinterpret_cast<SkColor4f*>(colors), colorSpace, pos, env->GetArrayLength(posArray), tileMode, static_cast<uint32_t>(flags), localMatrix.get()).release();
env->ReleaseFloatArrayElements(colorsArray, colors, 0);
env->ReleaseFloatArrayElements(posArray, pos, 0);
std
::
unique_ptr
<
SkMatrix
>
localMatrix
=
skMatrix
(
matrixArray
);
SkShader
*
ptr
=
SkGradientShader
::
MakeRadial
(
SkPoint
::
Make
(
x
,
y
),
r
,
colors
,
colorSpace
,
pos
,
count
,
tileMode
,
static_cast
<
uint32_t
>
(
flags
),
localMatrix
.
get
()).
release
();
return
reinterpret_cast
<
KNativePointer
>
(
ptr
);
}
#endif
SKIKO_EXPORT
KNativePointer
org_jetbrains_skia_Shader__1nMakeTwoPointConicalGradient
(
KFloat
x0
,
KFloat
y0
,
KFloat
r0
,
KFloat
x1
,
KFloat
y1
,
KFloat
r1
,
KInt
*
colorsArray
,
KFloat
*
posArray
,
KInt
tileModeInt
,
KInt
flags
,
KFloat
*
matrixArray
)
{
TODO
(
"implement org_jetbrains_skia_Shader__1nMakeTwoPointConicalGradient"
);
}
#if 0
SKIKO_EXPORT
KNativePointer
org_jetbrains_skia_Shader__1nMakeTwoPointConicalGradient
(KFloat x0, KFloat y0, KFloat r0, KFloat x1, KFloat y1, KFloat r1, KInt* colorsArray, KFloat* posArray, KInt tileModeInt, KInt flags, KFloat* matrixArray) {
KInt* colors = env->GetIntArrayElements(colorsArray, nullptr
);
float* pos =
posArray == nullptr ? nullptr : env->GetFloatArrayElements(posArray, nullptr
);
(
KFloat
x0
,
KFloat
y0
,
KFloat
r0
,
KFloat
x1
,
KFloat
y1
,
KFloat
r1
,
KInt
*
colorsArray
,
KFloat
*
posArray
,
KInt
count
,
KInt
tileModeInt
,
KInt
flags
,
KFloat
*
matrixArray
)
{
SkColor
*
colors
=
reinterpret_cast
<
SkColor
*>
(
colorsArray
);
float
*
pos
=
reinterpret_cast
<
float
*>
(
posArray
);
SkTileMode
tileMode
=
static_cast
<
SkTileMode
>
(
tileModeInt
);
std::unique_ptr<SkMatrix> localMatrix = skMatrix(env, matrixArray);
SkShader* ptr = SkGradientShader::MakeTwoPointConical(SkPoint::Make(x0, y0), r0, SkPoint::Make(x1, y1), r1, reinterpret_cast<SkColor*>(colors), pos, env->GetArrayLength(colorsArray), tileMode, static_cast<uint32_t>(flags), localMatrix.get()).release();
env->ReleaseIntArrayElements(colorsArray, colors, 0);
if (posArray != nullptr)
env->ReleaseFloatArrayElements(posArray, pos, 0);
std
::
unique_ptr
<
SkMatrix
>
localMatrix
=
skMatrix
(
matrixArray
);
SkShader
*
ptr
=
SkGradientShader
::
MakeTwoPointConical
(
SkPoint
::
Make
(
x0
,
y0
),
r0
,
SkPoint
::
Make
(
x1
,
y1
),
r1
,
colors
,
pos
,
count
,
tileMode
,
static_cast
<
uint32_t
>
(
flags
),
localMatrix
.
get
()).
release
();
return
reinterpret_cast
<
KNativePointer
>
(
ptr
);
}
#endif
SKIKO_EXPORT
KNativePointer
org_jetbrains_skia_Shader__1nMakeTwoPointConicalGradientCS
(
KFloat
x0
,
KFloat
y0
,
KFloat
r0
,
KFloat
x1
,
KFloat
y1
,
KFloat
r1
,
KFloat
*
colorsArray
,
KNativePointer
colorSpacePtr
,
KFloat
*
posArray
,
KInt
tileModeInt
,
KInt
flags
,
KFloat
*
matrixArray
)
{
TODO
(
"implement org_jetbrains_skia_Shader__1nMakeTwoPointConicalGradientCS"
);
}
#if 0
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Shader__1nMakeTwoPointConicalGradientCS
(KFloat x0, KFloat y0, KFloat r0, KFloat x1, KFloat y1, KFloat r1, KFloat* colorsArray, KNativePointer colorSpacePtr, KFloat* posArray, KInt tileModeInt, KInt flags, KFloat* matrixArray) {
float* colors = env->GetFloatArrayElements(colorsArray, nullptr);
(
KFloat
x0
,
KFloat
y0
,
KFloat
r0
,
KFloat
x1
,
KFloat
y1
,
KFloat
r1
,
KFloat
*
colorsArray
,
KNativePointer
colorSpacePtr
,
KFloat
*
posArray
,
KInt
count
,
KInt
tileModeInt
,
KInt
flags
,
KFloat
*
matrixArray
)
{
SkColor4f
*
colors
=
reinterpret_cast
<
SkColor4f
*>
(
colorsArray
);
sk_sp
<
SkColorSpace
>
colorSpace
=
sk_ref_sp
<
SkColorSpace
>
(
reinterpret_cast
<
SkColorSpace
*>
((
colorSpacePtr
)));
float* pos =
env->GetFloatArrayElements(posArray, nullptr
);
float
*
pos
=
reinterpret_cast
<
float
*>
(
posArray
);
SkTileMode
tileMode
=
static_cast
<
SkTileMode
>
(
tileModeInt
);
std::unique_ptr<SkMatrix> localMatrix = skMatrix(env, matrixArray);
SkShader* ptr = SkGradientShader::MakeTwoPointConical(SkPoint::Make(x0, y0), r0, SkPoint::Make(x1, y1), r1, reinterpret_cast<SkColor4f*>(colors), colorSpace, pos, env->GetArrayLength(posArray), tileMode, static_cast<uint32_t>(flags), localMatrix.get()).release();
env->ReleaseFloatArrayElements(colorsArray, colors, 0);
env->ReleaseFloatArrayElements(posArray, pos, 0);
std
::
unique_ptr
<
SkMatrix
>
localMatrix
=
skMatrix
(
matrixArray
);
SkShader
*
ptr
=
SkGradientShader
::
MakeTwoPointConical
(
SkPoint
::
Make
(
x0
,
y0
),
r0
,
SkPoint
::
Make
(
x1
,
y1
),
r1
,
colors
,
colorSpace
,
pos
,
count
,
tileMode
,
static_cast
<
uint32_t
>
(
flags
),
localMatrix
.
get
()).
release
();
return
reinterpret_cast
<
KNativePointer
>
(
ptr
);
}
#endif
SKIKO_EXPORT
KNativePointer
org_jetbrains_skia_Shader__1nMakeSweepGradient
(
KFloat
x
,
KFloat
y
,
KFloat
start
,
KFloat
end
,
KInt
*
colorsArray
,
KFloat
*
posArray
,
KInt
tileModeInt
,
KInt
flags
,
KFloat
*
matrixArray
)
{
TODO
(
"implement org_jetbrains_skia_Shader__1nMakeSweepGradient"
);
}
#if 0
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Shader__1nMakeSweepGradient
(KFloat x, KFloat y, KFloat start, KFloat end, KInt* colorsArray, KFloat* posArray, KInt tileModeInt, KInt flags, KFloat* matrixArray) {
KInt* colors = env->GetIntArrayElements(colorsArray, nullptr);
float* pos = posArray == nullptr ? nullptr : env->GetFloatArrayElements(posArray, nullptr);
(
KFloat
x
,
KFloat
y
,
KFloat
start
,
KFloat
end
,
KInt
*
colorsArray
,
KFloat
*
posArray
,
KInt
count
,
KInt
tileModeInt
,
KInt
flags
,
KFloat
*
matrixArray
)
{
SkColor
*
colors
=
reinterpret_cast
<
SkColor
*>
(
colorsArray
);
float
*
pos
=
reinterpret_cast
<
float
*>
(
posArray
);
SkTileMode
tileMode
=
static_cast
<
SkTileMode
>
(
tileModeInt
);
std::unique_ptr<SkMatrix> localMatrix = skMatrix(env, matrixArray);
SkShader* ptr = SkGradientShader::MakeSweep(x, y, reinterpret_cast<SkColor*>(colors), pos, env->GetArrayLength(colorsArray), tileMode, start, end, static_cast<uint32_t>(flags), localMatrix.get()).release();
env->ReleaseIntArrayElements(colorsArray, colors, 0);
if (posArray != nullptr)
env->ReleaseFloatArrayElements(posArray, pos, 0);
std
::
unique_ptr
<
SkMatrix
>
localMatrix
=
skMatrix
(
matrixArray
);
SkShader
*
ptr
=
SkGradientShader
::
MakeSweep
(
x
,
y
,
colors
,
pos
,
count
,
tileMode
,
start
,
end
,
static_cast
<
uint32_t
>
(
flags
),
localMatrix
.
get
()).
release
();
return
reinterpret_cast
<
KNativePointer
>
(
ptr
);
}
#endif
SKIKO_EXPORT
KNativePointer
org_jetbrains_skia_Shader__1nMakeSweepGradientCS
(
KFloat
x
,
KFloat
y
,
KFloat
start
,
KFloat
end
,
KFloat
*
colorsArray
,
KNativePointer
colorSpacePtr
,
KFloat
*
posArray
,
KInt
tileModeInt
,
KInt
flags
,
KFloat
*
matrixArray
)
{
TODO
(
"implement org_jetbrains_skia_Shader__1nMakeSweepGradientCS"
);
}
(
KFloat
x
,
KFloat
y
,
KFloat
start
,
KFloat
end
,
KFloat
*
colorsArray
,
KNativePointer
colorSpacePtr
,
KFloat
*
posArray
,
KInt
count
,
KInt
tileModeInt
,
KInt
flags
,
KFloat
*
matrixArray
)
{
SkColor4f
*
colors
=
reinterpret_cast
<
SkColor4f
*>
(
colorsArray
);
sk_sp
<
SkColorSpace
>
colorSpace
=
sk_ref_sp
<
SkColorSpace
>
(
reinterpret_cast
<
SkColorSpace
*>
((
colorSpacePtr
)));
float
*
pos
=
reinterpret_cast
<
float
*>
(
posArray
);
SkTileMode
tileMode
=
static_cast
<
SkTileMode
>
(
tileModeInt
);
std
::
unique_ptr
<
SkMatrix
>
localMatrix
=
skMatrix
(
matrixArray
);
SkShader
*
ptr
=
SkGradientShader
::
MakeSweep
(
x
,
y
,
colors
,
colorSpace
,
pos
,
count
,
tileMode
,
start
,
end
,
static_cast
<
uint32_t
>
(
flags
),
localMatrix
.
get
()).
release
();
return
reinterpret_cast
<
KNativePointer
>
(
ptr
);}
SKIKO_EXPORT
KNativePointer
org_jetbrains_skia_Shader__1nMakeEmpty
()
{
...
...
@@ -194,7 +127,7 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_Shader__1nMakeColorCS(KFloat r, K
return
reinterpret_cast
<
KNativePointer
>
(
ptr
);
}
extern
"C"
KNativePointer
org_jetbrains_skia_Shader__1nMakeBlend
(
KInt
blendModeInt
,
KNativePointer
dstPtr
,
KNativePointer
srcPtr
)
{
SKIKO_EXPORT
KNativePointer
org_jetbrains_skia_Shader__1nMakeBlend
(
KInt
blendModeInt
,
KNativePointer
dstPtr
,
KNativePointer
srcPtr
)
{
SkShader
*
dst
=
reinterpret_cast
<
SkShader
*>
((
dstPtr
));
SkShader
*
src
=
reinterpret_cast
<
SkShader
*>
((
srcPtr
));
SkBlendMode
blendMode
=
static_cast
<
SkBlendMode
>
(
blendModeInt
);
...
...
@@ -203,24 +136,15 @@ extern "C" KNativePointer org_jetbrains_skia_Shader__1nMakeBlend(KInt blendModeI
}
SKIKO_EXPORT
KNativePointer
org_jetbrains_skia_Shader__1nMakeFractalNoise
(
KFloat
baseFrequencyX
,
KFloat
baseFrequencyY
,
KInt
numOctaves
,
KFloat
seed
,
KInt
*
tilesArray
)
{
TODO
(
"implement org_jetbrains_skia_Shader__1nMakeFractalNoise"
);
}
#if 0
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Shader__1nMakeFractalNoise
(KFloat baseFrequencyX, KFloat baseFrequencyY, KInt numOctaves, KFloat seed, KInt* tilesArray) {
int len = env->GetArrayLength(tilesArray);
std::vector<SkISize> tiles(len / 2);
KInt* arr = env->GetIntArrayElements(tilesArray, 0);
for (int i = 0; i < len; i += 2)
tiles[i / 2] = {arr[i], arr[i+1]};
env->ReleaseIntArrayElements(tilesArray, arr, 0);
SkShader* ptr = SkPerlinNoiseShader::MakeFractalNoise(baseFrequencyX, baseFrequencyY, numOctaves, seed, tiles.data()).release();
(
KFloat
baseFrequencyX
,
KFloat
baseFrequencyY
,
KInt
numOctaves
,
KFloat
seed
,
KInt
tileW
,
KInt
tileH
)
{
const
SkISize
tileSize
=
SkISize
::
Make
(
tileW
,
tileH
);
SkShader
*
ptr
=
SkPerlinNoiseShader
::
MakeFractalNoise
(
baseFrequencyX
,
baseFrequencyY
,
numOctaves
,
seed
,
&
tileSize
).
release
();
return
reinterpret_cast
<
KNativePointer
>
(
ptr
);
}
#endif
SKIKO_EXPORT
KNativePointer
org_jetbrains_skia_Shader__1nMakeTurbulence
(
KFloat
baseFrequencyX
,
KFloat
baseFrequencyY
,
KInt
numOctaves
,
KFloat
seed
,
KInt
*
tilesArray
)
{
TODO
(
"implement org_jetbrains_skia_Shader__1nMakeTurbulence"
);
(
KFloat
baseFrequencyX
,
KFloat
baseFrequencyY
,
KInt
numOctaves
,
KFloat
seed
,
KInt
tileW
,
KInt
tileH
)
{
const
SkISize
tileSize
=
SkISize
::
Make
(
tileW
,
tileH
);
SkShader
*
ptr
=
SkPerlinNoiseShader
::
MakeTurbulence
(
baseFrequencyX
,
baseFrequencyY
,
numOctaves
,
seed
,
&
tileSize
).
release
();
return
reinterpret_cast
<
KNativePointer
>
(
ptr
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment