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
8a392951
Unverified
Commit
8a392951
authored
Oct 25, 2021
by
Aleksandr Veselov
Committed by
GitHub
Oct 25, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement native Paint::getColor4f, add test (#305)
parent
537bb123
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
21 deletions
+40
-21
Paint.kt
skiko/src/commonMain/kotlin/org/jetbrains/skia/Paint.kt
+5
-8
PaintTest.kt
skiko/src/commonTest/kotlin/org/jetbrains/skia/PaintTest.kt
+14
-0
assertCloseEnough.kt
...nTest/kotlin/org/jetbrains/skia/util/assertCloseEnough.kt
+9
-0
Paint.cc
skiko/src/jvmMain/cpp/common/Paint.cc
+4
-3
Paint.cc
skiko/src/nativeJsMain/cpp/Paint.cc
+8
-10
No files found.
skiko/src/commonMain/kotlin/org/jetbrains/skia/Paint.kt
View file @
8a392951
package
org.jetbrains.skia
package
org.jetbrains.skia
import
org.jetbrains.skia.impl.*
import
org.jetbrains.skia.impl.Library.Companion.staticLoad
import
org.jetbrains.skia.impl.Library.Companion.staticLoad
import
org.jetbrains.skia.impl.Managed
import
org.jetbrains.skia.impl.Native
import
org.jetbrains.skia.impl.Stats
import
org.jetbrains.skia.impl.reachabilityBarrier
import
org.jetbrains.skia.impl.NativePointer
import
org.jetbrains.skia.impl.getPtr
import
kotlin.math.round
import
kotlin.math.round
class
Paint
:
Managed
{
class
Paint
:
Managed
{
...
@@ -187,7 +182,9 @@ class Paint : Managed {
...
@@ -187,7 +182,9 @@ class Paint : Managed {
var
color4f
:
Color4f
var
color4f
:
Color4f
get
()
=
try
{
get
()
=
try
{
Stats
.
onNativeCall
()
Stats
.
onNativeCall
()
_nGetColor4f
(
_ptr
)
Color4f
(
withResult
(
FloatArray
(
4
))
{
_nGetColor4f
(
_ptr
,
it
)
})
}
finally
{
}
finally
{
reachabilityBarrier
(
this
)
reachabilityBarrier
(
this
)
}
}
...
@@ -644,7 +641,7 @@ private external fun _nSetMode(ptr: NativePointer, value: Int)
...
@@ -644,7 +641,7 @@ private external fun _nSetMode(ptr: NativePointer, value: Int)
private
external
fun
Paint_nGetColor
(
ptr
:
NativePointer
):
Int
private
external
fun
Paint_nGetColor
(
ptr
:
NativePointer
):
Int
@ExternalSymbolName
(
"org_jetbrains_skia_Paint__1nGetColor4f"
)
@ExternalSymbolName
(
"org_jetbrains_skia_Paint__1nGetColor4f"
)
private
external
fun
_nGetColor4f
(
ptr
:
NativePointer
):
Color4f
private
external
fun
_nGetColor4f
(
ptr
:
NativePointer
,
arr
:
InteropPointer
)
@ExternalSymbolName
(
"org_jetbrains_skia_Paint__1nSetColor"
)
@ExternalSymbolName
(
"org_jetbrains_skia_Paint__1nSetColor"
)
private
external
fun
_nSetColor
(
ptr
:
NativePointer
,
argb
:
Int
)
private
external
fun
_nSetColor
(
ptr
:
NativePointer
,
argb
:
Int
)
...
...
skiko/src/commonTest/kotlin/org/jetbrains/skia/PaintTest.kt
0 → 100644
View file @
8a392951
package
org.jetbrains.skia
import
org.jetbrains.skia.tests.assertCloseEnough
import
kotlin.test.Test
class
PaintTest
{
@Test
fun
color4f
()
{
val
paint
=
Paint
()
val
expected
=
Color4f
(
0.2f
,
0.4f
,
0.8f
,
1.0f
)
paint
.
setColor4f
(
expected
,
colorSpace
=
ColorSpace
.
sRGB
)
assertCloseEnough
(
expected
,
paint
.
color4f
)
}
}
\ No newline at end of file
skiko/src/commonTest/kotlin/org/jetbrains/skia/util/assertCloseEnough.kt
View file @
8a392951
package
org.jetbrains.skia.tests
package
org.jetbrains.skia.tests
import
org.jetbrains.skia.Color4f
import
org.jetbrains.skia.Matrix33
import
org.jetbrains.skia.Matrix33
import
org.jetbrains.skia.Point
import
org.jetbrains.skia.Point
import
kotlin.math.abs
import
kotlin.math.abs
...
@@ -19,3 +20,11 @@ internal fun assertCloseEnough(expected: Point, actual: Point?, epsilon: Float =
...
@@ -19,3 +20,11 @@ internal fun assertCloseEnough(expected: Point, actual: Point?, epsilon: Float =
internal
fun
assertCloseEnough
(
expected
:
Matrix33
,
actual
:
Matrix33
?,
epsilon
:
Float
=
EPSILON
)
{
internal
fun
assertCloseEnough
(
expected
:
Matrix33
,
actual
:
Matrix33
?,
epsilon
:
Float
=
EPSILON
)
{
expected
.
mat
.
zip
(
actual
!!
.
mat
).
forEach
{
(
a
,
b
)
->
assertCloseEnough
(
a
,
b
,
epsilon
)
}
expected
.
mat
.
zip
(
actual
!!
.
mat
).
forEach
{
(
a
,
b
)
->
assertCloseEnough
(
a
,
b
,
epsilon
)
}
}
}
internal
fun
assertCloseEnough
(
expected
:
Color4f
,
actual
:
Color4f
?,
epsilon
:
Float
=
EPSILON
)
{
assertCloseEnough
(
expected
.
r
,
actual
!!
.
r
,
epsilon
)
assertCloseEnough
(
expected
.
g
,
actual
.
g
,
epsilon
)
assertCloseEnough
(
expected
.
b
,
actual
.
b
,
epsilon
)
assertCloseEnough
(
expected
.
a
,
actual
.
a
,
epsilon
)
}
\ No newline at end of file
skiko/src/jvmMain/cpp/common/Paint.cc
View file @
8a392951
...
@@ -80,11 +80,12 @@ extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PaintKt__1nSetColor
...
@@ -80,11 +80,12 @@ extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PaintKt__1nSetColor
instance
->
setColor
(
color
);
instance
->
setColor
(
color
);
}
}
extern
"C"
JNIEXPORT
jobject
JNICALL
Java_org_jetbrains_skia_PaintKt__1nGetColor4f
extern
"C"
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skia_PaintKt__1nGetColor4f
(
JNIEnv
*
env
,
jclass
jclass
,
jlong
ptr
)
{
(
JNIEnv
*
env
,
jclass
jclass
,
jlong
ptr
,
jfloatArray
result
)
{
SkPaint
*
instance
=
reinterpret_cast
<
SkPaint
*>
(
static_cast
<
uintptr_t
>
(
ptr
));
SkPaint
*
instance
=
reinterpret_cast
<
SkPaint
*>
(
static_cast
<
uintptr_t
>
(
ptr
));
SkColor4f
color
=
instance
->
getColor4f
();
SkColor4f
color
=
instance
->
getColor4f
();
return
env
->
NewObject
(
skija
::
Color4f
::
cls
,
skija
::
Color4f
::
ctor
,
color
.
fR
,
color
.
fG
,
color
.
fB
,
color
.
fA
);
float
data
[
4
]
{
color
.
fR
,
color
.
fG
,
color
.
fB
,
color
.
fA
};
env
->
SetFloatArrayRegion
(
result
,
0
,
4
,
data
);
}
}
extern
"C"
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skia_PaintKt__1nSetColor4f
extern
"C"
JNIEXPORT
void
JNICALL
Java_org_jetbrains_skia_PaintKt__1nSetColor4f
...
...
skiko/src/nativeJsMain/cpp/Paint.cc
View file @
8a392951
...
@@ -81,19 +81,17 @@ SKIKO_EXPORT void org_jetbrains_skia_Paint__1nSetColor
...
@@ -81,19 +81,17 @@ SKIKO_EXPORT void org_jetbrains_skia_Paint__1nSetColor
}
}
SKIKO_EXPORT
KInteropPointer
org_jetbrains_skia_Paint__1nGetColor4f
SKIKO_EXPORT
void
org_jetbrains_skia_Paint__1nGetColor4f
(
KNativePointer
ptr
)
{
(
KNativePointer
ptr
,
KInteropPointer
result
)
{
TODO
(
"implement org_jetbrains_skia_Paint__1nGetColor4f"
);
}
#if 0
SKIKO_EXPORT KInteropPointer org_jetbrains_skia_Paint__1nGetColor4f
(KNativePointer ptr) {
SkPaint
*
instance
=
reinterpret_cast
<
SkPaint
*>
((
ptr
));
SkPaint
*
instance
=
reinterpret_cast
<
SkPaint
*>
((
ptr
));
float
*
res
=
reinterpret_cast
<
float
*>
(
result
);
SkColor4f
color
=
instance
->
getColor4f
();
SkColor4f
color
=
instance
->
getColor4f
();
return env->NewObject(skija::Color4f::cls, skija::Color4f::ctor, color.fR, color.fG, color.fB, color.fA);
res
[
0
]
=
color
.
fR
;
res
[
1
]
=
color
.
fG
;
res
[
2
]
=
color
.
fB
;
res
[
3
]
=
color
.
fA
;
}
}
#endif
SKIKO_EXPORT
void
org_jetbrains_skia_Paint__1nSetColor4f
SKIKO_EXPORT
void
org_jetbrains_skia_Paint__1nSetColor4f
...
...
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