Unverified Commit c9083760 authored by Ivan Matkov's avatar Ivan Matkov Committed by GitHub

Update skia to to m146 (#1187)

[SKIKO-1098](https://youtrack.jetbrains.com/issue/SKIKO-1098) Update
skia to m146
parent 086d8181
......@@ -86,9 +86,6 @@ fun skiaPreprocessorFlags(os: OS, buildType: SkiaBuildType): Array<String> {
"-DU_DISABLE_VERSION_SUFFIX=1",
"-DU_HAVE_LIB_SUFFIX=1",
"-DU_LIB_SUFFIX_C_NAME=_skiko",
// Temporary (m144) skia flag for migration to SkPathBuilder
"-USK_HIDE_PATH_EDIT_METHODS",
*buildType.flags
)
......
......@@ -7,7 +7,7 @@ kotlin.mpp.enableCInteropCommonization=true
deploy.version=0.0.0
# a tag from https://github.com/JetBrains/skia/releases
dependencies.skia=m144-22f58c9fd4
dependencies.skia=m146-0619918005
# a tag from https://github.com/JetBrains/angle-pack
dependencies.angle=ec4d8f8e4d
......
......@@ -56,7 +56,18 @@ class PaintTest {
surface.canvas.drawRect(
r = rect,
paint = Paint().apply {
shader = Shader.makeLinearGradient(rect.left, rect.top, rect.right, rect.bottom, intArrayOf(Color.RED, Color.BLUE))
shader = Shader.makeLinearGradient(
rect.left,
rect.top,
rect.right,
rect.bottom,
Gradient(
Gradient.Colors(
colors = arrayOf(Color4f(Color.RED), Color4f(Color.BLUE)),
tileMode = FilterTileMode.CLAMP
)
)
)
}
)
......
package org.jetbrains.skia
/**
* Specification for the colors in a gradient.
*/
class Gradient(
val colors: Colors,
val interpolation: Interpolation = Interpolation()
) {
/**
* Specification for the colors in a gradient.
*
* @param colors The span of colors for the gradient.
* @param positions Relative positions of each color across the gradient. If empty,
* the the colors are distributed evenly. If this is not null, the values
* must lie between 0.0 and 1.0, and be strictly increasing. If the first
* value is not 0.0, then an additional color stop is added at position 0.0,
* with the same color as colors[0]. If the the last value is less than 1.0,
* then an additional color stop is added at position 1.0, with the same color
* as colors[count - 1].
* @param tileMode Tiling mode for the gradient.
* @param colorSpace Optional colorspace associated with the span of colors. If this is null,
* the colors are treated as sRGB.
*/
class Colors(
val colors: Array<Color4f>,
val positions: FloatArray? = null,
val tileMode: FilterTileMode,
val colorSpace: ColorSpace? = null
) {
init {
require(positions == null || colors.size == positions.size) {
"colors.length ${colors.size} != positions.length ${positions!!.size}"
}
}
override fun equals(other: Any?): Boolean {
if (other === this) return true
if (other !is Colors) return false
if (!colors.contentEquals(other.colors)) return false
if (!(positions?.contentEquals(other.positions) ?: (other.positions == null))) return false
if (tileMode != other.tileMode) return false
return colorSpace == other.colorSpace
}
override fun hashCode(): Int {
val prime = 59
var result = 1
result = result * prime + colors.contentHashCode()
result = result * prime + (positions?.contentHashCode() ?: 43)
result = result * prime + tileMode.hashCode()
result = result * prime + (colorSpace?.hashCode() ?: 43)
return result
}
}
/**
* Description of the colors and interpolation method.
*/
class Interpolation(
val inPremul: InPremul = InPremul.NO,
val colorSpace: ColorSpace = ColorSpace.DESTINATION,
val hueMethod: HueMethod = HueMethod.SHORTER
) {
enum class InPremul {
NO,
YES
}
enum class ColorSpace {
// Default Skia behavior: interpolate in the color space of the destination surface
DESTINATION,
// https://www.w3.org/TR/css-color-4/#interpolation-space
SRGB_LINEAR,
LAB,
OKLAB,
// This is the same as OKLAB, except it has a simplified version of the CSS gamut
// mapping algorithm (https://www.w3.org/TR/css-color-4/#css-gamut-mapping)
// into REC2020 space applied to it.
// Warning: This space is experimental and should not be used in production.
OKLAB_GAMUT_MAP,
LCH,
OKLCH,
// This is the same as OKLCH, except it has the same gamut mapping applied to it
// as OKLAB_GAMUT_MAP does.
// Warning: This space is experimental and should not be used in production.
OKLCH_GAMUT_MAP,
SRGB,
HSL,
HWB,
DISPLAY_P3,
REC2020,
PROPHOTO_RGB,
A98_RGB
}
enum class HueMethod {
// https://www.w3.org/TR/css-color-4/#hue-interpolation
SHORTER,
LONGER,
INCREASING,
DECREASING
}
override fun equals(other: Any?): Boolean {
if (other === this) return true
if (other !is Interpolation) return false
if (inPremul != other.inPremul) return false
if (colorSpace != other.colorSpace) return false
return hueMethod == other.hueMethod
}
override fun hashCode(): Int {
val prime = 59
var result = 1
result = result * prime + inPremul.hashCode()
result = result * prime + colorSpace.hashCode()
result = result * prime + hueMethod.hashCode()
return result
}
}
override fun equals(other: Any?): Boolean {
if (other === this) return true
if (other !is Gradient) return false
if (colors != other.colors) return false
return interpolation == other.interpolation
}
override fun hashCode(): Int {
val prime = 59
var result = 1
result = result * prime + colors.hashCode()
result = result * prime + interpolation.hashCode()
return result
}
}
package org.jetbrains.skia
class GradientStyle(
val tileMode: FilterTileMode,
val isPremul: Boolean,
val localMatrix: Matrix33?
) {
internal fun _getFlags(): Int {
return 0 or if (isPremul) _INTERPOLATE_PREMUL else 0
}
internal fun _getMatrixArray(): FloatArray? {
return localMatrix?.mat
}
override fun equals(other: Any?): Boolean {
if (other === this) return true
if (other !is GradientStyle) return false
if (isPremul != other.isPremul) return false
if (this.tileMode != other.tileMode) return false
return !if (this.localMatrix == null) other.localMatrix != null else this.localMatrix != other.localMatrix
}
override fun hashCode(): Int {
val PRIME = 59
var result = 1
result = result * PRIME + if (isPremul) 79 else 97
result = result * PRIME + tileMode.hashCode()
result = result * PRIME + (localMatrix?.hashCode() ?: 43)
return result
}
override fun toString(): String {
return "GradientStyle(_tileMode=$tileMode, _premul=$isPremul, _localMatrix=$localMatrix)"
}
fun withTileMode(_tileMode: FilterTileMode): GradientStyle {
return if (tileMode == _tileMode) this else GradientStyle(_tileMode, isPremul, localMatrix)
}
fun withPremul(_premul: Boolean): GradientStyle {
return if (isPremul == _premul) this else GradientStyle(tileMode, _premul, localMatrix)
}
fun withLocalMatrix(_localMatrix: Matrix33): GradientStyle {
return if (localMatrix === _localMatrix) this else GradientStyle(tileMode, isPremul, _localMatrix)
}
companion object {
internal val _INTERPOLATE_PREMUL = 1
var DEFAULT = GradientStyle(FilterTileMode.CLAMP, true, null)
}
}
\ No newline at end of file
......@@ -1181,567 +1181,6 @@ class Path internal constructor(ptr: NativePointer) : Managed(ptr, _FinalizerHol
} finally {
reachabilityBarrier(this)
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun reset(): Path {
Stats.onNativeCall()
Path_nReset(_ptr)
return this
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun rewind(): Path {
Stats.onNativeCall()
_nRewind(_ptr)
return this
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun incReserve(extraPtCount: Int): Path {
Stats.onNativeCall()
_nIncReserve(_ptr, extraPtCount)
return this
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun moveTo(x: Float, y: Float): Path {
Stats.onNativeCall()
_nMoveTo(_ptr, x, y)
return this
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun moveTo(p: Point): Path {
@Suppress("DEPRECATION_ERROR")
return moveTo(p.x, p.y)
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun rMoveTo(dx: Float, dy: Float): Path {
Stats.onNativeCall()
_nRMoveTo(_ptr, dx, dy)
return this
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun lineTo(x: Float, y: Float): Path {
Stats.onNativeCall()
_nLineTo(_ptr, x, y)
return this
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun lineTo(p: Point): Path {
@Suppress("DEPRECATION_ERROR")
return lineTo(p.x, p.y)
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun rLineTo(dx: Float, dy: Float): Path {
Stats.onNativeCall()
_nRLineTo(_ptr, dx, dy)
return this
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun quadTo(x1: Float, y1: Float, x2: Float, y2: Float): Path {
Stats.onNativeCall()
_nQuadTo(_ptr, x1, y1, x2, y2)
return this
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun quadTo(p1: Point, p2: Point): Path {
@Suppress("DEPRECATION_ERROR")
return quadTo(p1.x, p1.y, p2.x, p2.y)
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun rQuadTo(dx1: Float, dy1: Float, dx2: Float, dy2: Float): Path {
Stats.onNativeCall()
_nRQuadTo(_ptr, dx1, dy1, dx2, dy2)
return this
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun conicTo(x1: Float, y1: Float, x2: Float, y2: Float, w: Float): Path {
Stats.onNativeCall()
_nConicTo(_ptr, x1, y1, x2, y2, w)
return this
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun conicTo(p1: Point, p2: Point, w: Float): Path {
@Suppress("DEPRECATION_ERROR")
return conicTo(p1.x, p1.y, p2.x, p2.y, w)
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun rConicTo(dx1: Float, dy1: Float, dx2: Float, dy2: Float, w: Float): Path {
Stats.onNativeCall()
_nRConicTo(_ptr, dx1, dy1, dx2, dy2, w)
return this
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun cubicTo(x1: Float, y1: Float, x2: Float, y2: Float, x3: Float, y3: Float): Path {
Stats.onNativeCall()
_nCubicTo(_ptr, x1, y1, x2, y2, x3, y3)
return this
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun cubicTo(p1: Point, p2: Point, p3: Point): Path {
@Suppress("DEPRECATION_ERROR")
return cubicTo(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y)
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun rCubicTo(dx1: Float, dy1: Float, dx2: Float, dy2: Float, dx3: Float, dy3: Float): Path {
Stats.onNativeCall()
_nRCubicTo(_ptr, dx1, dy1, dx2, dy2, dx3, dy3)
return this
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun arcTo(oval: Rect, startAngle: Float, sweepAngle: Float, forceMoveTo: Boolean): Path {
@Suppress("DEPRECATION_ERROR")
return arcTo(oval.left, oval.top, oval.right, oval.bottom, startAngle, sweepAngle, forceMoveTo)
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun arcTo(left: Float, top: Float, right: Float, bottom: Float, startAngle: Float, sweepAngle: Float, forceMoveTo: Boolean): Path {
Stats.onNativeCall()
_nArcTo(_ptr, left, top, right, bottom, startAngle, sweepAngle, forceMoveTo)
return this
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun tangentArcTo(x1: Float, y1: Float, x2: Float, y2: Float, radius: Float): Path {
Stats.onNativeCall()
_nTangentArcTo(_ptr, x1, y1, x2, y2, radius)
return this
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun tangentArcTo(p1: Point, p2: Point, radius: Float): Path {
@Suppress("DEPRECATION_ERROR")
return tangentArcTo(p1.x, p1.y, p2.x, p2.y, radius)
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun ellipticalArcTo(
rx: Float,
ry: Float,
xAxisRotate: Float,
arc: PathEllipseArc,
direction: PathDirection,
x: Float,
y: Float
): Path {
Stats.onNativeCall()
_nEllipticalArcTo(_ptr, rx, ry, xAxisRotate, arc.ordinal, direction.ordinal, x, y)
return this
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun ellipticalArcTo(r: Point, xAxisRotate: Float, arc: PathEllipseArc, direction: PathDirection, xy: Point): Path {
@Suppress("DEPRECATION_ERROR")
return ellipticalArcTo(r.x, r.y, xAxisRotate, arc, direction, xy.x, xy.y)
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun rEllipticalArcTo(
rx: Float,
ry: Float,
xAxisRotate: Float,
arc: PathEllipseArc,
direction: PathDirection,
dx: Float,
dy: Float
): Path {
Stats.onNativeCall()
_nREllipticalArcTo(_ptr, rx, ry, xAxisRotate, arc.ordinal, direction.ordinal, dx, dy)
return this
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun closePath(): Path {
Stats.onNativeCall()
_nClosePath(_ptr)
return this
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun addRect(rect: Rect, dir: PathDirection = PathDirection.CLOCKWISE, start: Int = 0): Path {
@Suppress("DEPRECATION_ERROR")
return addRect(rect.left, rect.top, rect.right, rect.bottom, dir, start)
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun addRect(left: Float, top: Float, right: Float, bottom: Float, dir: PathDirection = PathDirection.CLOCKWISE, start: Int = 0): Path {
Stats.onNativeCall()
_nAddRect(_ptr, left, top, right, bottom, dir.ordinal, start)
return this
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun addOval(oval: Rect, dir: PathDirection = PathDirection.CLOCKWISE, start: Int = 1): Path {
@Suppress("DEPRECATION_ERROR")
return addOval(oval.left, oval.top, oval.right, oval.bottom, dir, start)
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun addOval(left: Float, top: Float, right: Float, bottom: Float, dir: PathDirection = PathDirection.CLOCKWISE, start: Int = 1): Path {
Stats.onNativeCall()
_nAddOval(_ptr, left, top, right, bottom, dir.ordinal, start)
return this
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun addCircle(x: Float, y: Float, radius: Float, dir: PathDirection = PathDirection.CLOCKWISE): Path {
Stats.onNativeCall()
_nAddCircle(_ptr, x, y, radius, dir.ordinal)
return this
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun addArc(oval: Rect, startAngle: Float, sweepAngle: Float): Path {
@Suppress("DEPRECATION_ERROR")
return addArc(oval.left, oval.top, oval.right, oval.bottom, startAngle, sweepAngle)
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun addArc(left: Float, top: Float, right: Float, bottom: Float, startAngle: Float, sweepAngle: Float): Path {
Stats.onNativeCall()
_nAddArc(_ptr, left, top, right, bottom, startAngle, sweepAngle)
return this
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun addRRect(rrect: RRect, dir: PathDirection = PathDirection.CLOCKWISE, start: Int = 6): Path {
@Suppress("DEPRECATION_ERROR")
return addRRect(rrect.left, rrect.top, rrect.right, rrect.bottom, rrect.radii, dir, start)
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun addRRect(left: Float, top: Float, right: Float, bottom: Float, radii: FloatArray, dir: PathDirection = PathDirection.CLOCKWISE, start: Int = 6): Path {
Stats.onNativeCall()
interopScope {
_nAddRRect(_ptr, left, top, right, bottom, toInterop(radii), radii.size, dir.ordinal, start)
}
return this
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun addPoly(pts: Array<Point>, close: Boolean): Path {
val flat = FloatArray(pts.size * 2)
for (i in pts.indices) {
flat[i * 2] = pts[i].x
flat[i * 2 + 1] = pts[i].y
}
@Suppress("DEPRECATION_ERROR")
return addPoly(flat, close)
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun addPoly(pts: FloatArray, close: Boolean): Path {
require(pts.size % 2 == 0) { "Expected even amount of pts, got " + pts.size }
Stats.onNativeCall()
interopScope {
_nAddPoly(_ptr, toInterop(pts), pts.size / 2, close)
}
return this
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun addPath(src: Path?, extend: Boolean = false): Path {
return try {
Stats.onNativeCall()
_nAddPath(
_ptr,
getPtr(src),
extend
)
this
} finally {
reachabilityBarrier(this)
reachabilityBarrier(src)
}
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun addPath(src: Path?, dx: Float, dy: Float, extend: Boolean = false): Path {
return try {
Stats.onNativeCall()
_nAddPathOffset(
_ptr,
getPtr(src),
dx,
dy,
extend
)
this
} finally {
reachabilityBarrier(this)
reachabilityBarrier(src)
}
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun addPath(src: Path?, matrix: Matrix33, extend: Boolean = false): Path {
return try {
Stats.onNativeCall()
interopScope {
_nAddPathTransform(
_ptr,
getPtr(src),
toInterop(matrix.mat),
extend
)
}
this
} finally {
reachabilityBarrier(this)
reachabilityBarrier(src)
}
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun reverseAddPath(src: Path?): Path {
return try {
Stats.onNativeCall()
_nReverseAddPath(_ptr, getPtr(src))
this
} finally {
reachabilityBarrier(this)
reachabilityBarrier(src)
}
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun offset(dx: Float, dy: Float, dst: Path? = null): Path {
return try {
Stats.onNativeCall()
_nOffset(_ptr, dx, dy, getPtr(dst))
this
} finally {
reachabilityBarrier(this)
reachabilityBarrier(dst)
}
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun transform(matrix: Matrix33, applyPerspectiveClip: Boolean): Path {
@Suppress("DEPRECATION_ERROR")
return transform(matrix, null, applyPerspectiveClip)
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun transform(matrix: Matrix33, dst: Path? = null, applyPerspectiveClip: Boolean = true): Path {
return try {
Stats.onNativeCall()
interopScope {
_nTransform(
_ptr,
toInterop(matrix.mat),
getPtr(dst),
applyPerspectiveClip
)
}
this
} finally {
reachabilityBarrier(this)
reachabilityBarrier(dst)
}
}
@Deprecated(
message = "Mutating Path API was moved to PathBuilder in Skia m144",
replaceWith = ReplaceWith("PathBuilder"),
level = DeprecationLevel.ERROR,
)
fun setLastPt(x: Float, y: Float): Path {
Stats.onNativeCall()
_nSetLastPt(_ptr, x, y)
return this
}
}
@ExternalSymbolName("org_jetbrains_skia_Path__1nGetFinalizer")
......@@ -1944,140 +1383,3 @@ private external fun _nMakeFromBytes(data: InteropPointer, size: Int): NativePoi
@ExternalSymbolName("org_jetbrains_skia_Path__1nIsValid")
private external fun _nIsValid(ptr: NativePointer): Boolean
// ================ DEPRECATED ================
@ExternalSymbolName("org_jetbrains_skia_Path__1nReset")
private external fun Path_nReset(ptr: NativePointer)
@ExternalSymbolName("org_jetbrains_skia_Path__1nRewind")
private external fun _nRewind(ptr: NativePointer)
@ExternalSymbolName("org_jetbrains_skia_Path__1nIncReserve")
private external fun _nIncReserve(ptr: NativePointer, extraPtCount: Int)
@ExternalSymbolName("org_jetbrains_skia_Path__1nMoveTo")
private external fun _nMoveTo(ptr: NativePointer, x: Float, y: Float)
@ExternalSymbolName("org_jetbrains_skia_Path__1nRMoveTo")
private external fun _nRMoveTo(ptr: NativePointer, dx: Float, dy: Float)
@ExternalSymbolName("org_jetbrains_skia_Path__1nLineTo")
private external fun _nLineTo(ptr: NativePointer, x: Float, y: Float)
@ExternalSymbolName("org_jetbrains_skia_Path__1nRLineTo")
private external fun _nRLineTo(ptr: NativePointer, dx: Float, dy: Float)
@ExternalSymbolName("org_jetbrains_skia_Path__1nQuadTo")
private external fun _nQuadTo(ptr: NativePointer, x1: Float, y1: Float, x2: Float, y2: Float)
@ExternalSymbolName("org_jetbrains_skia_Path__1nRQuadTo")
private external fun _nRQuadTo(ptr: NativePointer, dx1: Float, dy1: Float, dx2: Float, dy2: Float)
@ExternalSymbolName("org_jetbrains_skia_Path__1nConicTo")
private external fun _nConicTo(ptr: NativePointer, x1: Float, y1: Float, x2: Float, y2: Float, w: Float)
@ExternalSymbolName("org_jetbrains_skia_Path__1nRConicTo")
private external fun _nRConicTo(ptr: NativePointer, dx1: Float, dy1: Float, dx2: Float, dy2: Float, w: Float)
@ExternalSymbolName("org_jetbrains_skia_Path__1nCubicTo")
private external fun _nCubicTo(ptr: NativePointer, x1: Float, y1: Float, x2: Float, y2: Float, x3: Float, y3: Float)
@ExternalSymbolName("org_jetbrains_skia_Path__1nRCubicTo")
private external fun _nRCubicTo(ptr: NativePointer, dx1: Float, dy1: Float, dx2: Float, dy2: Float, dx3: Float, dy3: Float)
@ExternalSymbolName("org_jetbrains_skia_Path__1nArcTo")
private external fun _nArcTo(
ptr: NativePointer,
left: Float,
top: Float,
right: Float,
bottom: Float,
startAngle: Float,
sweepAngle: Float,
forceMoveTo: Boolean
)
@ExternalSymbolName("org_jetbrains_skia_Path__1nTangentArcTo")
private external fun _nTangentArcTo(ptr: NativePointer, x1: Float, y1: Float, x2: Float, y2: Float, radius: Float)
@ExternalSymbolName("org_jetbrains_skia_Path__1nEllipticalArcTo")
private external fun _nEllipticalArcTo(
ptr: NativePointer,
rx: Float,
ry: Float,
xAxisRotate: Float,
size: Int,
direction: Int,
x: Float,
y: Float
)
@ExternalSymbolName("org_jetbrains_skia_Path__1nREllipticalArcTo")
private external fun _nREllipticalArcTo(
ptr: NativePointer,
rx: Float,
ry: Float,
xAxisRotate: Float,
size: Int,
direction: Int,
dx: Float,
dy: Float
)
@ExternalSymbolName("org_jetbrains_skia_Path__1nClosePath")
private external fun _nClosePath(ptr: NativePointer)
@ExternalSymbolName("org_jetbrains_skia_Path__1nAddRect")
private external fun _nAddRect(ptr: NativePointer, l: Float, t: Float, r: Float, b: Float, dir: Int, start: Int)
@ExternalSymbolName("org_jetbrains_skia_Path__1nAddOval")
private external fun _nAddOval(ptr: NativePointer, l: Float, t: Float, r: Float, b: Float, dir: Int, start: Int)
@ExternalSymbolName("org_jetbrains_skia_Path__1nAddCircle")
private external fun _nAddCircle(ptr: NativePointer, x: Float, y: Float, r: Float, dir: Int)
@ExternalSymbolName("org_jetbrains_skia_Path__1nAddArc")
private external fun _nAddArc(ptr: NativePointer, l: Float, t: Float, r: Float, b: Float, startAngle: Float, sweepAngle: Float)
@ExternalSymbolName("org_jetbrains_skia_Path__1nAddRRect")
private external fun _nAddRRect(
ptr: NativePointer,
l: Float,
t: Float,
r: Float,
b: Float,
radii: InteropPointer,
size: Int,
dir: Int,
start: Int
)
@ExternalSymbolName("org_jetbrains_skia_Path__1nAddPoly")
private external fun _nAddPoly(ptr: NativePointer, coords: InteropPointer, count: Int, close: Boolean)
@ExternalSymbolName("org_jetbrains_skia_Path__1nAddPath")
private external fun _nAddPath(ptr: NativePointer, srcPtr: NativePointer, extend: Boolean)
@ExternalSymbolName("org_jetbrains_skia_Path__1nAddPathOffset")
private external fun _nAddPathOffset(ptr: NativePointer, srcPtr: NativePointer, dx: Float, dy: Float, extend: Boolean)
@ExternalSymbolName("org_jetbrains_skia_Path__1nAddPathTransform")
private external fun _nAddPathTransform(ptr: NativePointer, srcPtr: NativePointer, matrix: InteropPointer, extend: Boolean)
@ExternalSymbolName("org_jetbrains_skia_Path__1nReverseAddPath")
private external fun _nReverseAddPath(ptr: NativePointer, srcPtr: NativePointer)
@ExternalSymbolName("org_jetbrains_skia_Path__1nOffset")
private external fun _nOffset(ptr: NativePointer, dx: Float, dy: Float, dst: NativePointer)
@ExternalSymbolName("org_jetbrains_skia_Path__1nTransform")
private external fun _nTransform(ptr: NativePointer, matrix: InteropPointer, dst: NativePointer, applyPerspectiveClip: Boolean)
@ExternalSymbolName("org_jetbrains_skia_Path__1nSetLastPt")
private external fun _nSetLastPt(ptr: NativePointer, x: Float, y: Float)
......@@ -163,13 +163,13 @@ class PathMeasure internal constructor(ptr: NativePointer) : Managed(ptr, _Final
}
/**
* Given a start and stop distance, return in dst the intervening segment(s).
* Given a start and stop distance, append to [dst] the intervening segment(s).
* If the segment is zero-length, return false, else return true.
* startD and stopD are pinned to legal values (0..getLength()). If startD &gt; stopD
* then return false (and leave dst untouched).
* startD and endD are pinned to legal values (0..length). If startD &gt; endD
* then return false (and leave [dst] untouched).
* Begin the segment with a moveTo if startWithMoveTo is true
*/
fun getSegment(startD: Float, endD: Float, dst: Path, startWithMoveTo: Boolean): Boolean {
fun getSegment(startD: Float, endD: Float, dst: PathBuilder, startWithMoveTo: Boolean): Boolean {
return try {
Stats.onNativeCall()
_nGetSegment(
......
......@@ -7,47 +7,37 @@ import org.jetbrains.skia.impl.reachabilityBarrier
object PathUtils {
/**
* Returns the filled equivalent of the stroked path using the provided paint attributes.
*
* @param src Path to create a filled version of.
* @param paint Paint from which attributes such as stroke cap, width, miter, join, and
* pathEffect will be used.
* @param cull Optional limit passed to the path effect.
* @param resScale If &gt; 1, increase precision, else if (0 &lt; resScale &lt; 1) reduce precision
* to favor speed and size.
* @return A filled version of the source path.
*/
fun fillPathWithPaint(src: Path, paint: Paint, cull: Rect?, resScale: Float): Path {
return fillPathWithPaint(src, paint, cull, Matrix33.makeScale(resScale))
/** Returns the filled equivalent of the stroked path. */
fun fillPathWithPaint(src: Path, paint: Paint, dst: PathBuilder, cull: Rect?, resScale: Float): Boolean {
return fillPathWithPaint(src, paint, dst, cull, Matrix33.makeScale(resScale))
}
/**
* Returns the filled equivalent of the stroked path using the provided paint attributes.
* Returns the filled equivalent of the stroked path.
*
* @param src Path to create a filled version of.
* @param paint Paint from which attributes such as stroke cap, width, miter, join, and
* pathEffect will be used.
* @param cull Optional limit passed to the path effect.
* @param matrix Current transformation matrix.
* @return A filled version of the source path.
* @param src SkPath read to create a filled version
* @param paint uses settings for stroke cap, width, miter, join, and patheffect.
* @param dst results are written to this builder.
* @param cull optional limit passed to SkPathEffect
* @param matrix matrix to take into acount for increased precision (if it scales up).
* @return true if the result can be filled, or false if it is a hairline (to be stroked).
*/
fun fillPathWithPaint(src: Path, paint: Paint, cull: Rect?, matrix: Matrix33): Path {
fun fillPathWithPaint(src: Path, paint: Paint, dst: PathBuilder, cull: Rect?, matrix: Matrix33): Boolean {
return try {
Stats.onNativeCall()
if (cull == null) org.jetbrains.skia.Path(
interopScope {
_nFillPathWithPaint(
if (cull == null) {
_nFillPathWithPaintMatrix(
getPtr(src),
getPtr(paint),
getPtr(dst),
toInterop(matrix.mat)
)
}
) else org.jetbrains.skia.Path(
interopScope {
} else {
_nFillPathWithPaintCull(
getPtr(src),
getPtr(paint),
getPtr(dst),
cull.left,
cull.top,
cull.right,
......@@ -55,22 +45,48 @@ object PathUtils {
toInterop(matrix.mat)
)
}
)
}
} finally {
reachabilityBarrier(matrix)
reachabilityBarrier(src)
reachabilityBarrier(paint)
reachabilityBarrier(dst)
}
}
/**
* Returns the filled equivalent of the stroked path using the provided paint attributes.
* Returns the filled equivalent of the stroked path.
*
* @param src Path to create a filled version of.
* @param paint Paint attributes such as stroke cap, width, miter, join, and pathEffect.
* @return A filled version of the source path.
* @param src SkPath read to create a filled version
* @param paint uses settings for stroke cap, width, miter, join, and patheffect.
*/
fun fillPathWithPaint(src: Path, paint: Paint): Path {
return fillPathWithPaint(src, paint, null, 1f)
return try {
Stats.onNativeCall()
Path(_nFillPathWithPaint(getPtr(src), getPtr(paint)))
} finally {
reachabilityBarrier(src)
reachabilityBarrier(paint)
}
}
/**
* Returns the filled equivalent of the stroked path.
*
* @param src SkPath read to create a filled version
* @param paint uses settings for stroke cap, width, miter, join, and patheffect.
* @param dst results are written to this builder.
* @return true if the result can be filled, or false if it is a hairline (to be stroked).
*/
fun fillPathWithPaint(src: Path, paint: Paint, dst: PathBuilder): Boolean {
return try {
Stats.onNativeCall()
_nFillPathWithPaintBuilder(getPtr(src), getPtr(paint), getPtr(dst))
} finally {
reachabilityBarrier(src)
reachabilityBarrier(paint)
reachabilityBarrier(dst)
}
}
init {
......@@ -80,18 +96,33 @@ object PathUtils {
@ExternalSymbolName("org_jetbrains_skia_PathUtils__1nFillPathWithPaint")
private external fun _nFillPathWithPaint(
srcPtr: NativePointer,
paintPtr: NativePointer
): NativePointer
@ExternalSymbolName("org_jetbrains_skia_PathUtils__1nFillPathWithPaintBuilder")
private external fun _nFillPathWithPaintBuilder(
srcPtr: NativePointer,
paintPtr: NativePointer,
dstPtr: NativePointer
): Boolean
@ExternalSymbolName("org_jetbrains_skia_PathUtils__1nFillPathWithPaintMatrix")
private external fun _nFillPathWithPaintMatrix(
srcPtr: NativePointer,
paintPtr: NativePointer,
dstPtr: NativePointer,
matrix: InteropPointer
): NativePointer
): Boolean
@ExternalSymbolName("org_jetbrains_skia_PathUtils__1nFillPathWithPaintCull")
private external fun _nFillPathWithPaintCull(
srcPtr: NativePointer,
paintPtr: NativePointer,
dstPtr: NativePointer,
left: Float,
top: Float,
right: Float,
bottom: Float,
matrix: InteropPointer
): NativePointer
): Boolean
......@@ -18,63 +18,20 @@ class Shader internal constructor(ptr: NativePointer) : RefCnt(ptr) {
staticLoad()
}
// Linear
fun makeLinearGradient(p0: Point, p1: Point, colors: IntArray): Shader {
return makeLinearGradient(p0.x, p0.y, p1.x, p1.y, colors)
}
fun makeLinearGradient(p0: Point, p1: Point, colors: IntArray, positions: FloatArray?): Shader {
return makeLinearGradient(p0.x, p0.y, p1.x, p1.y, colors, positions)
}
fun makeLinearGradient(
p0: Point,
p1: Point,
colors: IntArray,
positions: FloatArray?,
style: GradientStyle
): Shader {
return makeLinearGradient(p0.x, p0.y, p1.x, p1.y, colors, positions, style)
}
fun makeLinearGradient(
x0: Float,
y0: Float,
x1: Float,
y1: Float,
colors: IntArray,
positions: FloatArray? = null,
style: GradientStyle = GradientStyle.Companion.DEFAULT
): Shader {
require(positions == null || colors.size == positions.size) { "colors.length " + colors.size + "!= positions.length " + positions!!.size }
Stats.onNativeCall()
return Shader(
interopScope {
_nMakeLinearGradient(
x0,
y0,
x1,
y1,
toInterop(colors),
toInterop(positions),
colors.size,
style.tileMode.ordinal,
style._getFlags(),
toInterop(style._getMatrixArray())
)
}
)
}
/**
* Returns a shader that generates a linear gradient between the two specified points.
* If the inputs are invalid, this will return nullptr.
* @param points Array of 2 points, the end-points of the line segment
* @param gradient Description of the colors and interpolation method
* @param localMatrix Optional local matrix, may be null
*/
fun makeLinearGradient(
p0: Point,
p1: Point,
colors: Array<Color4f>,
cs: ColorSpace?,
positions: FloatArray?,
style: GradientStyle
gradient: Gradient,
localMatrix: Matrix33? = null
): Shader {
return makeLinearGradient(p0.x, p0.y, p1.x, p1.y, colors, cs, positions, style)
return makeLinearGradient(p0.x, p0.y, p1.x, p1.y, gradient, localMatrix)
}
fun makeLinearGradient(
......@@ -82,320 +39,212 @@ class Shader internal constructor(ptr: NativePointer) : RefCnt(ptr) {
y0: Float,
x1: Float,
y1: Float,
colors: Array<Color4f>,
cs: ColorSpace?,
positions: FloatArray?,
style: GradientStyle
gradient: Gradient,
localMatrix: Matrix33? = null
): Shader {
return try {
require(positions == null || colors.size == positions.size) { "colors.length " + colors.size + "!= positions.length " + positions!!.size }
Stats.onNativeCall()
Shader(
interopScope {
_nMakeLinearGradientCS(
_nMakeLinearGradient(
x0,
y0,
x1,
y1,
toInterop(Color4f.flattenArray(colors)),
getPtr(cs),
toInterop(positions),
colors.size,
style.tileMode.ordinal,
style._getFlags(),
toInterop(style._getMatrixArray())
toInterop(Color4f.flattenArray(gradient.colors.colors)),
getPtr(gradient.colors.colorSpace),
toInterop(gradient.colors.positions),
gradient.colors.colors.size,
gradient.colors.tileMode.ordinal,
gradient.interpolation.inPremul.ordinal,
gradient.interpolation.colorSpace.ordinal,
gradient.interpolation.hueMethod.ordinal,
toInterop(localMatrix?.mat)
)
}
)
} finally {
reachabilityBarrier(cs)
}
}
// Radial
fun makeRadialGradient(center: Point, r: Float, colors: IntArray): Shader {
return makeRadialGradient(center.x, center.y, r, colors)
}
fun makeRadialGradient(center: Point, r: Float, colors: IntArray, positions: FloatArray?): Shader {
return makeRadialGradient(center.x, center.y, r, colors, positions)
}
fun makeRadialGradient(
center: Point,
r: Float,
colors: IntArray,
positions: FloatArray?,
style: GradientStyle
): Shader {
return makeRadialGradient(center.x, center.y, r, colors, positions, style)
}
fun makeRadialGradient(
x: Float,
y: Float,
r: Float,
colors: IntArray,
positions: FloatArray? = null,
style: GradientStyle = GradientStyle.Companion.DEFAULT
): Shader {
require(positions == null || colors.size == positions.size) { "colors.length " + colors.size + "!= positions.length " + positions!!.size }
Stats.onNativeCall()
return Shader(
interopScope {
_nMakeRadialGradient(
x,
y,
r,
toInterop(colors),
toInterop(positions),
colors.size,
style.tileMode.ordinal,
style._getFlags(),
toInterop(style._getMatrixArray())
)
reachabilityBarrier(gradient)
reachabilityBarrier(gradient.colors.colorSpace)
reachabilityBarrier(localMatrix)
}
)
}
/**
* Returns a shader that generates a radial gradient given the center and radius.
* @param center The center of the circle for this gradient
* @param radius Must be positive. The radius of the circle for this gradient
* @param gradient Description of the colors and interpolation method
* @param localMatrix Optional local matrix, may be null
*/
fun makeRadialGradient(
center: Point,
r: Float,
colors: Array<Color4f>,
cs: ColorSpace?,
positions: FloatArray?,
style: GradientStyle
radius: Float,
gradient: Gradient,
localMatrix: Matrix33? = null
): Shader {
return makeRadialGradient(center.x, center.y, r, colors, cs, positions, style)
return makeRadialGradient(center.x, center.y, radius, gradient, localMatrix)
}
fun makeRadialGradient(
x: Float,
y: Float,
r: Float,
colors: Array<Color4f>,
cs: ColorSpace?,
positions: FloatArray?,
style: GradientStyle
radius: Float,
gradient: Gradient,
localMatrix: Matrix33? = null
): Shader {
return try {
require(positions == null || colors.size == positions.size) { "colors.length " + colors.size + "!= positions.length " + positions!!.size }
Stats.onNativeCall()
Shader(
interopScope {
_nMakeRadialGradientCS(
_nMakeRadialGradient(
x,
y,
r,
toInterop(Color4f.flattenArray(colors)),
getPtr(cs),
toInterop(positions),
colors.size,
style.tileMode.ordinal,
style._getFlags(),
toInterop(style._getMatrixArray())
radius,
toInterop(Color4f.flattenArray(gradient.colors.colors)),
getPtr(gradient.colors.colorSpace),
toInterop(gradient.colors.positions),
gradient.colors.colors.size,
gradient.colors.tileMode.ordinal,
gradient.interpolation.inPremul.ordinal,
gradient.interpolation.colorSpace.ordinal,
gradient.interpolation.hueMethod.ordinal,
toInterop(localMatrix?.mat)
)
}
)
} finally {
reachabilityBarrier(cs)
}
reachabilityBarrier(gradient)
reachabilityBarrier(gradient.colors.colorSpace)
reachabilityBarrier(localMatrix)
}
// Two-point Conical
fun makeTwoPointConicalGradient(p0: Point, r0: Float, p1: Point, r1: Float, colors: IntArray): Shader {
return makeTwoPointConicalGradient(p0.x, p0.y, r0, p1.x, p1.y, r1, colors)
}
fun makeTwoPointConicalGradient(
p0: Point,
r0: Float,
p1: Point,
r1: Float,
colors: IntArray,
positions: FloatArray?
): Shader {
return makeTwoPointConicalGradient(p0.x, p0.y, r0, p1.x, p1.y, r1, colors, positions)
}
fun makeTwoPointConicalGradient(
p0: Point,
r0: Float,
p1: Point,
r1: Float,
colors: IntArray,
positions: FloatArray?,
style: GradientStyle
): Shader {
return makeTwoPointConicalGradient(p0.x, p0.y, r0, p1.x, p1.y, r1, colors, positions, style)
}
/**
* Returns a shader that generates a conical gradient given two circles, or
* returns null if the inputs are invalid. The gradient interprets the
* two circles according to the following HTML spec.
* http://dev.w3.org/html5/2dcontext/#dom-context-2d-createradialgradient
* @param start The center of the circle for this gradient
* @param startRadius Must be positive. The radius of the circle for this gradient
* @param end The center of the circle for this gradient
* @param endRadius Must be positive. The radius of the circle for this gradient
* @param gradient Description of the colors and interpolation method
* @param localMatrix Optional local matrix, may be null
*/
fun makeTwoPointConicalGradient(
x0: Float,
y0: Float,
r0: Float,
x1: Float,
y1: Float,
r1: Float,
colors: IntArray,
positions: FloatArray? = null,
style: GradientStyle = GradientStyle.Companion.DEFAULT
start: Point,
startRadius: Float,
end: Point,
endRadius: Float,
gradient: Gradient,
localMatrix: Matrix33? = null
): Shader {
require(positions == null || colors.size == positions.size) { "colors.length " + colors.size + "!= positions.length " + positions!!.size }
Stats.onNativeCall()
return Shader(
interopScope {
_nMakeTwoPointConicalGradient(
x0,
y0,
r0,
x1,
y1,
r1,
toInterop(colors),
toInterop(positions),
colors.size,
style.tileMode.ordinal,
style._getFlags(),
toInterop(style._getMatrixArray())
)
}
return makeTwoPointConicalGradient(
start.x,
start.y,
startRadius,
end.x,
end.y,
endRadius,
gradient,
localMatrix
)
}
fun makeTwoPointConicalGradient(
p0: Point,
r0: Float,
p1: Point,
r1: Float,
colors: Array<Color4f>,
cs: ColorSpace?,
positions: FloatArray?,
style: GradientStyle
): Shader {
return makeTwoPointConicalGradient(p0.x, p0.y, r0, p1.x, p1.y, r1, colors, cs, positions, style)
}
fun makeTwoPointConicalGradient(
x0: Float,
y0: Float,
r0: Float,
startRadius: Float,
x1: Float,
y1: Float,
r1: Float,
colors: Array<Color4f>,
cs: ColorSpace?,
positions: FloatArray?,
style: GradientStyle
endRadius: Float,
gradient: Gradient,
localMatrix: Matrix33? = null
): Shader {
return try {
require(positions == null || colors.size == positions.size) { "colors.length " + colors.size + "!= positions.length " + positions!!.size }
Stats.onNativeCall()
Shader(
interopScope {
_nMakeTwoPointConicalGradientCS(
_nMakeTwoPointConicalGradient(
x0,
y0,
r0,
startRadius,
x1,
y1,
r1,
toInterop(Color4f.flattenArray(colors)),
getPtr(cs),
toInterop(positions),
colors.size,
style.tileMode.ordinal,
style._getFlags(),
toInterop(style._getMatrixArray())
endRadius,
toInterop(Color4f.flattenArray(gradient.colors.colors)),
getPtr(gradient.colors.colorSpace),
toInterop(gradient.colors.positions),
gradient.colors.colors.size,
gradient.colors.tileMode.ordinal,
gradient.interpolation.inPremul.ordinal,
gradient.interpolation.colorSpace.ordinal,
gradient.interpolation.hueMethod.ordinal,
toInterop(localMatrix?.mat)
)
}
)
} finally {
reachabilityBarrier(cs)
}
}
// Sweep
fun makeSweepGradient(center: Point, colors: IntArray): Shader {
return makeSweepGradient(center.x, center.y, colors)
}
fun makeSweepGradient(x: Float, y: Float, colors: IntArray): Shader {
return makeSweepGradient(x, y, 0f, 360f, colors, null, GradientStyle.Companion.DEFAULT)
}
fun makeSweepGradient(center: Point, colors: IntArray, positions: FloatArray?): Shader {
return makeSweepGradient(center.x, center.y, colors, positions)
}
fun makeSweepGradient(x: Float, y: Float, colors: IntArray, positions: FloatArray?): Shader {
return makeSweepGradient(x, y, 0f, 360f, colors, positions, GradientStyle.Companion.DEFAULT)
reachabilityBarrier(gradient)
reachabilityBarrier(gradient.colors.colorSpace)
reachabilityBarrier(localMatrix)
}
fun makeSweepGradient(center: Point, colors: IntArray, positions: FloatArray?, style: GradientStyle): Shader {
return makeSweepGradient(center.x, center.y, colors, positions, style)
}
fun makeSweepGradient(
x: Float,
y: Float,
colors: IntArray,
positions: FloatArray?,
style: GradientStyle
): Shader {
return makeSweepGradient(x, y, 0f, 360f, colors, positions, style)
}
/**
* Returns a shader that generates a sweep gradient given a center.
* The shader accepts negative angles and angles larger than 360, draws
* between 0 and 360 degrees, similar to the CSS conic-gradient
* semantics. 0 degrees means horizontal positive x axis. The start angle
* must be less than the end angle, otherwise a null pointer is
* returned. If color stops do not contain 0 and 1 but are within this
* range, the respective outer color stop is repeated for 0 and 1. Color
* stops less than 0 are clamped to 0, and greater than 1 are clamped to 1.
* @param center The center of the sweep
* @param gradient Description of the colors and interpolation method
* @param localMatrix Optional local matrix, may be null
*/
fun makeSweepGradient(
center: Point,
startAngle: Float,
endAngle: Float,
colors: IntArray,
positions: FloatArray?,
style: GradientStyle
gradient: Gradient,
localMatrix: Matrix33? = null
): Shader {
return makeSweepGradient(center.x, center.y, startAngle, endAngle, colors, positions, style)
return makeSweepGradient(center.x, center.y, gradient, localMatrix)
}
fun makeSweepGradient(
x: Float,
y: Float,
startAngle: Float,
endAngle: Float,
colors: IntArray,
positions: FloatArray?,
style: GradientStyle
gradient: Gradient,
localMatrix: Matrix33? = null
): Shader {
require(positions == null || colors.size == positions.size) { "colors.length " + colors.size + "!= positions.length " + positions!!.size }
Stats.onNativeCall()
return Shader(
interopScope {
_nMakeSweepGradient(
x,
y,
startAngle,
endAngle,
toInterop(colors),
toInterop(positions),
colors.size,
style.tileMode.ordinal,
style._getFlags(),
toInterop(style._getMatrixArray())
)
}
)
return makeSweepGradient(x, y, 0f, 360f, gradient, localMatrix)
}
/**
* Returns a shader that generates a sweep gradient given a center.
* The shader accepts negative angles and angles larger than 360, draws
* between 0 and 360 degrees, similar to the CSS conic-gradient
* semantics. 0 degrees means horizontal positive x axis. The start angle
* must be less than the end angle, otherwise a null pointer is
* returned. If color stops do not contain 0 and 1 but are within this
* range, the respective outer color stop is repeated for 0 and 1. Color
* stops less than 0 are clamped to 0, and greater than 1 are clamped to 1.
* @param center The center of the sweep
* @param startAngle Start of the angular range, corresponding to pos == 0.
* @param endAngle End of the angular range, corresponding to pos == 1.
* @param gradient Description of the colors and interpolation method
* @param localMatrix Optional local matrix, may be null
*/
fun makeSweepGradient(
center: Point,
startAngle: Float,
endAngle: Float,
colors: Array<Color4f>,
cs: ColorSpace?,
positions: FloatArray?,
style: GradientStyle
gradient: Gradient,
localMatrix: Matrix33? = null
): Shader {
return makeSweepGradient(center.x, center.y, startAngle, endAngle, colors, cs, positions, style)
return makeSweepGradient(center.x, center.y, startAngle, endAngle, gradient, localMatrix)
}
fun makeSweepGradient(
......@@ -403,37 +252,37 @@ class Shader internal constructor(ptr: NativePointer) : RefCnt(ptr) {
y: Float,
startAngle: Float,
endAngle: Float,
colors: Array<Color4f>,
cs: ColorSpace?,
positions: FloatArray?,
style: GradientStyle
gradient: Gradient,
localMatrix: Matrix33? = null
): Shader {
return try {
require(positions == null || colors.size == positions.size) { "colors.length " + colors.size + "!= positions.length " + positions!!.size }
Stats.onNativeCall()
Shader(
interopScope {
_nMakeSweepGradientCS(
_nMakeSweepGradient(
x,
y,
startAngle,
endAngle,
toInterop(Color4f.flattenArray(colors)),
getPtr(cs),
toInterop(positions),
colors.size,
style.tileMode.ordinal,
style._getFlags(),
toInterop(style._getMatrixArray())
toInterop(Color4f.flattenArray(gradient.colors.colors)),
getPtr(gradient.colors.colorSpace),
toInterop(gradient.colors.positions),
gradient.colors.colors.size,
gradient.colors.tileMode.ordinal,
gradient.interpolation.inPremul.ordinal,
gradient.interpolation.colorSpace.ordinal,
gradient.interpolation.hueMethod.ordinal,
toInterop(localMatrix?.mat)
)
}
)
} finally {
reachabilityBarrier(cs)
reachabilityBarrier(gradient)
reachabilityBarrier(gradient.colors.colorSpace)
reachabilityBarrier(localMatrix)
}
}
//
fun makeEmpty(): Shader {
Stats.onNativeCall()
return Shader(Shader_nMakeEmpty())
......@@ -559,21 +408,6 @@ private external fun _nMakeWithColorFilter(ptr: NativePointer, colorFilterPtr: N
@ExternalSymbolName("org_jetbrains_skia_Shader__1nMakeLinearGradient")
private external fun _nMakeLinearGradient(
x0: Float,
y0: Float,
x1: Float,
y1: Float,
colors: InteropPointer,
positions: InteropPointer,
count: Int,
tileType: Int,
flags: Int,
matrix: InteropPointer
): NativePointer
@ExternalSymbolName("org_jetbrains_skia_Shader__1nMakeLinearGradientCS")
private external fun _nMakeLinearGradientCS(
x0: Float,
y0: Float,
x1: Float,
......@@ -582,93 +416,50 @@ private external fun _nMakeLinearGradientCS(
colorSpacePtr: NativePointer,
positions: InteropPointer,
count: Int,
tileType: Int,
flags: Int,
tileMode: Int,
inPremul: Int,
interpolationColorSpace: Int,
hueMethod: Int,
matrix: InteropPointer
): NativePointer
@ExternalSymbolName("org_jetbrains_skia_Shader__1nMakeRadialGradient")
private external fun _nMakeRadialGradient(
x: Float,
y: Float,
r: Float,
colors: InteropPointer,
positions: InteropPointer,
count: Int,
tileType: Int,
flags: Int,
matrix: InteropPointer
): NativePointer
@ExternalSymbolName("org_jetbrains_skia_Shader__1nMakeRadialGradientCS")
private external fun _nMakeRadialGradientCS(
x: Float,
y: Float,
r: Float,
radius: Float,
colors: InteropPointer,
colorSpacePtr: NativePointer,
positions: InteropPointer,
count: Int,
tileType: Int,
flags: Int,
tileMode: Int,
inPremul: Int,
interpolationColorSpace: Int,
hueMethod: Int,
matrix: InteropPointer
): NativePointer
@ExternalSymbolName("org_jetbrains_skia_Shader__1nMakeTwoPointConicalGradient")
private external fun _nMakeTwoPointConicalGradient(
x0: Float,
y0: Float,
r0: Float,
x1: Float,
y1: Float,
r1: Float,
colors: InteropPointer,
positions: InteropPointer,
count: Int,
tileType: Int,
flags: Int,
matrix: InteropPointer
): NativePointer
@ExternalSymbolName("org_jetbrains_skia_Shader__1nMakeTwoPointConicalGradientCS")
private external fun _nMakeTwoPointConicalGradientCS(
x0: Float,
y0: Float,
r0: Float,
startRadius: Float,
x1: Float,
y1: Float,
r1: Float,
endRadius: Float,
colors: InteropPointer,
colorSpacePtr: NativePointer,
positions: InteropPointer,
count: Int,
tileType: Int,
flags: Int,
tileMode: Int,
inPremul: Int,
interpolationColorSpace: Int,
hueMethod: Int,
matrix: InteropPointer
): NativePointer
@ExternalSymbolName("org_jetbrains_skia_Shader__1nMakeSweepGradient")
private external fun _nMakeSweepGradient(
x: Float,
y: Float,
startAngle: Float,
endAngle: Float,
colors: InteropPointer,
positions: InteropPointer,
count: Int,
tileType: Int,
flags: Int,
matrix: InteropPointer
): NativePointer
@ExternalSymbolName("org_jetbrains_skia_Shader__1nMakeSweepGradientCS")
private external fun _nMakeSweepGradientCS(
x: Float,
y: Float,
startAngle: Float,
......@@ -677,12 +468,13 @@ private external fun _nMakeSweepGradientCS(
colorSpacePtr: NativePointer,
positions: InteropPointer,
count: Int,
tileType: Int,
flags: Int,
tileMode: Int,
inPremul: Int,
interpolationColorSpace: Int,
hueMethod: Int,
matrix: InteropPointer
): NativePointer
@ExternalSymbolName("org_jetbrains_skia_Shader__1nMakeFractalNoise")
private external fun _nMakeFractalNoise(
baseFrequencyX: Float,
......@@ -693,7 +485,6 @@ private external fun _nMakeFractalNoise(
tileHeight: Int,
): NativePointer
@ExternalSymbolName("org_jetbrains_skia_Shader__1nMakeTurbulence")
private external fun _nMakeTurbulence(
baseFrequencyX: Float,
......
......@@ -103,16 +103,28 @@ class FontCollection internal constructor(ptr: NativePointer) : RefCnt(ptr) {
}
} finally {
reachabilityBarrier(this)
reachabilityBarrier(familyNames)
}
}
fun defaultFallback(unicode: Int, style: FontStyle, locale: String?): Typeface? {
fun defaultFallback(unicode: Int, familyNames: Array<String>?, style: FontStyle, locale: String?): Typeface? {
return try {
Stats.onNativeCall()
val ptr = interopScope { _nDefaultFallbackChar(_ptr, unicode, style._value, toInterop(locale)) }
val ptr = interopScope {
_nDefaultFallbackChar(
_ptr,
unicode,
toInterop(familyNames),
familyNames?.size ?: 0,
style._value,
toInterop(locale)
)
}
if (ptr == NullPointer) null else Typeface(ptr)
} finally {
reachabilityBarrier(this)
reachabilityBarrier(familyNames)
reachabilityBarrier(locale)
}
}
......@@ -166,7 +178,14 @@ private external fun _nGetFallbackManager(ptr: NativePointer): NativePointer
private external fun _nFindTypefaces(ptr: NativePointer, familyNames: InteropPointer, len: Int, fontStyle: Int): NativePointer
@ExternalSymbolName("org_jetbrains_skia_paragraph_FontCollection__1nDefaultFallbackChar")
private external fun _nDefaultFallbackChar(ptr: NativePointer, unicode: Int, fontStyle: Int, locale: InteropPointer): NativePointer
private external fun _nDefaultFallbackChar(
ptr: NativePointer,
unicode: Int,
familyNames: InteropPointer,
len: Int,
fontStyle: Int,
locale: InteropPointer
): NativePointer
@ExternalSymbolName("org_jetbrains_skia_paragraph_FontCollection__1nDefaultFallback")
private external fun _nDefaultFallback(ptr: NativePointer): NativePointer
......
......@@ -23,7 +23,7 @@ class FontFallbackTest {
it.setDefaultFontManager(FontMgrWithFallback(fm))
// 0x6C34 = "水"
val df = it.defaultFallback(0x6C34, FontStyle.NORMAL, null)!!
val df = it.defaultFallback(0x6C34, null, FontStyle.NORMAL, null)!!
val glyphs = df.getStringGlyphs("水")
if (kotlinBackend.isWeb()) {
......
......@@ -553,8 +553,12 @@ class ImageFilterTest {
Shader.makeLinearGradient(
x0 = 0.0f, y0 = 0.0f,
x1 = 200.0f, y1 = 0.0f,
colors = intArrayOf(Color.RED, Color.BLUE),
style = GradientStyle.DEFAULT
gradient = Gradient(
Gradient.Colors(
colors = arrayOf(Color4f(Color.RED), Color4f(Color.BLUE)),
tileMode = FilterTileMode.CLAMP
)
)
)
)
......
......@@ -2,6 +2,7 @@ package org.jetbrains.skia
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
import org.jetbrains.skia.tests.assertCloseEnough
import org.jetbrains.skia.impl.use
import org.jetbrains.skiko.tests.runTest
......@@ -36,6 +37,19 @@ class PathMeasureTest {
}
}
@Test
fun getSegmentAppendsToPathBuilder() = runTest {
PathBuilder().moveTo(0f, 0f).lineTo(40f, 0f).detach().use { path ->
PathMeasure(path, false).use { measure ->
val builder = PathBuilder().moveTo(10f, 10f)
assertTrue(measure.getSegment(5f, 20f, builder, true))
val segment = builder.detach()
assertTrue(segment.pointsCount > 0)
assertTrue(segment.verbsCount > 0)
}
}
}
@Test
@Ignore
......
package org.jetbrains.skia
import org.jetbrains.skiko.tests.runTest
import kotlin.test.Test
@Suppress("DEPRECATION_ERROR")
class PathMutatingMethodsCompatTest {
@Test
fun restoredMutatingMethodsAreCallable() = runTest {
val path = Path()
val src = PathBuilder().moveTo(0f, 0f).lineTo(10f, 10f).detach()
val dst = Path()
val point1 = Point(1f, 2f)
val point2 = Point(3f, 4f)
val point3 = Point(5f, 6f)
val oval = Rect.makeLTRB(0f, 0f, 20f, 30f)
val rrect = RRect.makeLTRB(0f, 0f, 20f, 30f, 4f)
val matrix = Matrix33.makeTranslate(7f, 8f)
val radii = floatArrayOf(1f, 1f, 2f, 2f, 3f, 3f, 4f, 4f)
path.reset()
path.rewind()
path.incReserve(8)
path.moveTo(0f, 0f)
path.moveTo(point1)
path.rMoveTo(1f, 1f)
path.lineTo(2f, 2f)
path.lineTo(point2)
path.rLineTo(1f, 1f)
path.quadTo(1f, 2f, 3f, 4f)
path.quadTo(point1, point2)
path.rQuadTo(1f, 1f, 2f, 2f)
path.conicTo(1f, 2f, 3f, 4f, 0.5f)
path.conicTo(point1, point2, 0.5f)
path.rConicTo(1f, 1f, 2f, 2f, 0.75f)
path.cubicTo(1f, 2f, 3f, 4f, 5f, 6f)
path.cubicTo(point1, point2, point3)
path.rCubicTo(1f, 1f, 2f, 2f, 3f, 3f)
path.arcTo(oval, 0f, 90f, false)
path.arcTo(0f, 0f, 20f, 30f, 90f, 45f, true)
path.tangentArcTo(1f, 2f, 3f, 4f, 5f)
path.tangentArcTo(point1, point2, 6f)
path.ellipticalArcTo(10f, 20f, 30f, PathEllipseArc.SMALLER, PathDirection.CLOCKWISE, 40f, 50f)
path.ellipticalArcTo(point1, 15f, PathEllipseArc.LARGER, PathDirection.COUNTER_CLOCKWISE, point2)
path.rEllipticalArcTo(10f, 20f, 30f, PathEllipseArc.SMALLER, PathDirection.CLOCKWISE, 5f, 6f)
path.closePath()
path.addRect(oval, PathDirection.CLOCKWISE, 0)
path.addRect(0f, 0f, 20f, 30f, PathDirection.COUNTER_CLOCKWISE, 2)
path.addOval(oval, PathDirection.CLOCKWISE, 1)
path.addOval(0f, 0f, 20f, 30f, PathDirection.COUNTER_CLOCKWISE, 3)
path.addCircle(5f, 5f, 4f, PathDirection.CLOCKWISE)
path.addArc(oval, 45f, 90f)
path.addArc(0f, 0f, 20f, 30f, 10f, 15f)
path.addRRect(rrect, PathDirection.CLOCKWISE, 6)
path.addRRect(0f, 0f, 20f, 30f, radii, PathDirection.COUNTER_CLOCKWISE, 5)
path.addPoly(arrayOf(point1, point2, point3), true)
path.addPoly(floatArrayOf(0f, 0f, 1f, 1f, 2f, 2f), false)
path.addPath(src, false)
path.addPath(src, 1f, 2f, true)
path.addPath(src, matrix, false)
path.reverseAddPath(src)
path.offset(3f, 4f, dst)
path.transform(matrix, true)
path.transform(matrix, dst, false)
path.setLastPt(9f, 10f)
}
}
......@@ -31,8 +31,12 @@ class PathUtilsTest {
}
val path = PathBuilder().arcTo(0f, 0f, 40f, 40f, 0f, 90f, false).detach()
val fillPath1 = PathUtils.fillPathWithPaint(path, paint,null, 1f)
val fillPath001 = PathUtils.fillPathWithPaint(path, paint,null, 0.01f)
val fillPath1Builder = PathBuilder()
val fillPath001Builder = PathBuilder()
assertTrue(PathUtils.fillPathWithPaint(path, paint, fillPath1Builder, null, 1f))
assertTrue(PathUtils.fillPathWithPaint(path, paint, fillPath001Builder, null, 0.01f))
val fillPath1 = fillPath1Builder.detach()
val fillPath001 = fillPath001Builder.detach()
// assert 1f scale has higher precision (more points) than 0.01f
assertTrue(fillPath1.pointsCount > fillPath001.pointsCount)
......
......@@ -8,16 +8,12 @@ class ShaderTest {
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, null, GradientStyle.DEFAULT)
Shader.makeLinearGradient(start, end, colorsF, colorSpace, positions, GradientStyle.DEFAULT)
val colors = arrayOf(Color4f(Color.RED), Color4f(Color.BLUE), Color4f(Color.GREEN))
val gradient = Gradient(Gradient.Colors(colors, positions, FilterTileMode.CLAMP, ColorSpace.sRGBLinear))
Shader.makeLinearGradient(start, end, gradient)
Shader.makeLinearGradient(start.x, start.y, end.x, end.y, gradient, Matrix33.IDENTITY)
}
......@@ -25,16 +21,12 @@ class ShaderTest {
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, null, GradientStyle.DEFAULT)
Shader.makeRadialGradient(center, radius, colorsF, colorSpace, positions, GradientStyle.DEFAULT)
val colors = arrayOf(Color4f(Color.RED), Color4f(Color.BLUE), Color4f(Color.GREEN))
val gradient = Gradient(Gradient.Colors(colors, positions, FilterTileMode.CLAMP, ColorSpace.sRGBLinear))
Shader.makeRadialGradient(center, radius, gradient)
Shader.makeRadialGradient(center.x, center.y, radius, gradient, Matrix33.IDENTITY)
}
......@@ -44,16 +36,12 @@ class ShaderTest {
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, null, GradientStyle.DEFAULT)
Shader.makeTwoPointConicalGradient(start, startRadius, end, endRadius, colorsF, colorSpace, positions, GradientStyle.DEFAULT)
val colors = arrayOf(Color4f(Color.RED), Color4f(Color.BLUE), Color4f(Color.GREEN))
val gradient = Gradient(Gradient.Colors(colors, positions, FilterTileMode.CLAMP, ColorSpace.sRGBLinear))
Shader.makeTwoPointConicalGradient(start, startRadius, end, endRadius, gradient)
Shader.makeTwoPointConicalGradient(start.x, start.y, startRadius, end.x, end.y, endRadius, gradient, Matrix33.IDENTITY)
}
@Test
......@@ -61,17 +49,14 @@ class ShaderTest {
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, null, GradientStyle.DEFAULT)
Shader.makeSweepGradient(center, startAngle, endAngle, colorsF, colorSpace, positions, GradientStyle.DEFAULT)
val colors = arrayOf(Color4f(Color.RED), Color4f(Color.BLUE), Color4f(Color.GREEN))
val gradient = Gradient(Gradient.Colors(colors, positions, FilterTileMode.CLAMP, ColorSpace.sRGBLinear))
Shader.makeSweepGradient(center, gradient)
Shader.makeSweepGradient(center.x, center.y, gradient, Matrix33.IDENTITY)
Shader.makeSweepGradient(center, startAngle, endAngle, gradient)
Shader.makeSweepGradient(center.x, center.y, startAngle, endAngle, gradient, Matrix33.IDENTITY)
}
@Test
......@@ -87,10 +72,16 @@ class ShaderTest {
@Test
fun canMakeBlend() {
val srcGradient = Gradient(
Gradient.Colors(arrayOf(Color4f(Color.BLACK), Color4f(Color.WHITE)), tileMode = FilterTileMode.CLAMP)
)
val dstGradient = Gradient(
Gradient.Colors(arrayOf(Color4f(Color.RED), Color4f(Color.BLUE)), tileMode = FilterTileMode.CLAMP)
)
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))
src = Shader.makeLinearGradient(0.0f, 0.0f, 16.0f, 16.0f, srcGradient),
dst = Shader.makeRadialGradient(8.0f, 8.0f, 8.0f, dstGradient)
)
}
......
......@@ -88,9 +88,9 @@ class FontCollectionTest {
}
if (kotlinBackend.isNotJs()) {
fontCollection.defaultFallback(65 /* A */, FontStyle.NORMAL, "en-US")!!.use { t1 ->
fontCollection.defaultFallback(65 /* A */, null, FontStyle.NORMAL, "en-US")!!.use { t1 ->
val refCnt: Int = t1.refCount
fontCollection.defaultFallback(65 /* A */, FontStyle.NORMAL, "en-US")!!.use { t2 ->
fontCollection.defaultFallback(65 /* A */, null, FontStyle.NORMAL, "en-US")!!.use { t2 ->
assertEquals(refCnt + 1, t1.refCount)
assertEquals(refCnt + 1, t2.refCount)
assertEquals(t1, t2)
......
......@@ -435,198 +435,3 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_PathKt__1nMakeFromPol
SkPath* instance = new SkPath(path);
return reinterpret_cast<jlong>(instance);
}
// ================ DEPRECATED ================
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PathKt_Path_1nReset(JNIEnv* env, jclass jclass, jlong ptr) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
instance->reset();
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PathKt__1nRewind(JNIEnv* env, jclass jclass, jlong ptr) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
instance->rewind();
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PathKt__1nUpdateBoundsCache(JNIEnv* env, jclass jclass, jlong ptr) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
instance->updateBoundsCache();
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PathKt__1nIncReserve(JNIEnv* env, jclass jclass, jlong ptr, int extraPtCount) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
instance->incReserve(extraPtCount);
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PathKt__1nMoveTo(JNIEnv* env, jclass jclass, jlong ptr, jfloat x, jfloat y) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
instance->moveTo(x, y);
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PathKt__1nRMoveTo(JNIEnv* env, jclass jclass, jlong ptr, jfloat dx, jfloat dy) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
instance->rMoveTo(dx, dy);
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PathKt__1nLineTo(JNIEnv* env, jclass jclass, jlong ptr, jfloat x, jfloat y) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
instance->lineTo(x, y);
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PathKt__1nRLineTo(JNIEnv* env, jclass jclass, jlong ptr, jfloat dx, jfloat dy) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
instance->rLineTo(dx, dy);
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PathKt__1nQuadTo(JNIEnv* env, jclass jclass, jlong ptr, jfloat x1, jfloat y1, jfloat x2, jfloat y2) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
instance->quadTo(x1, y1, x2, y2);
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PathKt__1nRQuadTo(JNIEnv* env, jclass jclass, jlong ptr, jfloat dx1, jfloat dy1, jfloat dx2, jfloat dy2) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
instance->rQuadTo(dx1, dy1, dx2, dy2);
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PathKt__1nConicTo(JNIEnv* env, jclass jclass, jlong ptr, jfloat x1, jfloat y1, jfloat x2, jfloat y2, jfloat w) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
instance->conicTo(x1, y1, x2, y2, w);
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PathKt__1nRConicTo(JNIEnv* env, jclass jclass, jlong ptr, jfloat dx1, jfloat dy1, jfloat dx2, jfloat dy2, jfloat w) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
instance->rConicTo(dx1, dy1, dx2, dy2, w);
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PathKt__1nCubicTo(JNIEnv* env, jclass jclass, jlong ptr, jfloat x1, jfloat y1, jfloat x2, jfloat y2, jfloat x3, jfloat y3) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
instance->cubicTo(x1, y1, x2, y2, x3, y3);
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PathKt__1nRCubicTo(JNIEnv* env, jclass jclass, jlong ptr, jfloat dx1, jfloat dy1, jfloat dx2, jfloat dy2, jfloat dx3, jfloat dy3) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
instance->rCubicTo(dx1, dy1, dx2, dy2, dx3, dy3);
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PathKt__1nArcTo(JNIEnv* env, jclass jclass, jlong ptr, jfloat left, jfloat top, jfloat right, jfloat bottom, jfloat startAngle, jfloat sweepAngle, jboolean forceMoveTo) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
instance->arcTo({left, top, right, bottom}, startAngle, sweepAngle, forceMoveTo);
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PathKt__1nTangentArcTo(JNIEnv* env, jclass jclass, jlong ptr, jfloat x1, jfloat y1, jfloat x2, jfloat y2, jfloat radius) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
instance->arcTo(x1, y1, x2, y2, radius);
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PathKt__1nEllipticalArcTo(JNIEnv* env, jclass jclass, jlong ptr, jfloat rx, jfloat ry, jfloat xAxisRotate, jint size, jint direction, jfloat x, float y) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
instance->arcTo(rx, ry, xAxisRotate, static_cast<SkPath::ArcSize>(size), static_cast<SkPathDirection>(direction), x, y);
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PathKt__1nREllipticalArcTo(JNIEnv* env, jclass jclass, jlong ptr, jfloat rx, jfloat ry, jfloat xAxisRotate, jint size, jint direction, jfloat dx, float dy) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
instance->rArcTo(rx, ry, xAxisRotate, static_cast<SkPath::ArcSize>(size), static_cast<SkPathDirection>(direction), dx, dy);
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PathKt__1nClosePath(JNIEnv* env, jclass jclass, jlong ptr) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
instance->close();
}
extern "C" JNIEXPORT void Java_org_jetbrains_skia_PathKt__1nAddRect
(JNIEnv* env, jclass jclass, jlong ptr, jfloat l, jfloat t, jfloat r, jfloat b, jint dirInt, jint start) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
SkPathDirection dir = static_cast<SkPathDirection>(dirInt);
instance->addRect({l, t, r, b}, dir, start);
}
extern "C" JNIEXPORT void Java_org_jetbrains_skia_PathKt__1nAddOval
(JNIEnv* env, jclass jclass, jlong ptr, jfloat l, jfloat t, jfloat r, jfloat b, jint dirInt, jint start) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
SkPathDirection dir = static_cast<SkPathDirection>(dirInt);
instance->addOval({l, t, r, b}, dir, start);
}
extern "C" JNIEXPORT void Java_org_jetbrains_skia_PathKt__1nAddCircle
(JNIEnv* env, jclass jclass, jlong ptr, jfloat x, jfloat y, jfloat r, jint dirInt) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
SkPathDirection dir = static_cast<SkPathDirection>(dirInt);
instance->addCircle(x, y, r, dir);
}
extern "C" JNIEXPORT void Java_org_jetbrains_skia_PathKt__1nAddArc
(JNIEnv* env, jclass jclass, jlong ptr, jfloat l, jfloat t, jfloat r, jfloat b, jfloat startAngle, jfloat sweepAngle) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
instance->addArc({l, t, r, b}, startAngle, sweepAngle);
}
extern "C" JNIEXPORT void Java_org_jetbrains_skia_PathKt__1nAddRRect
(JNIEnv* env, jclass jclass, jlong ptr, jfloat l, jfloat t, jfloat r, jfloat b, jfloatArray radii, jint radiiSize, jint dirInt, jint start) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
SkRRect rrect = skija::RRect::toSkRRect(env, l, t, r, b, radii);
SkPathDirection dir = static_cast<SkPathDirection>(dirInt);
instance->addRRect(rrect, dir, start);
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PathKt__1nAddPoly
(JNIEnv* env, jclass jclass, jlong ptr, jfloatArray coords, jint _count, jboolean close) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
jsize len = env->GetArrayLength(coords);
jfloat* arr = env->GetFloatArrayElements(coords, 0);
instance->addPoly({reinterpret_cast<SkPoint*>(arr), len / 2}, close);
env->ReleaseFloatArrayElements(coords, arr, 0);
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PathKt__1nAddPath
(JNIEnv* env, jclass jclass, jlong ptr, jlong srcPtr, jboolean extend) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
SkPath* src = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(srcPtr));
SkPath::AddPathMode mode = extend ? SkPath::AddPathMode::kExtend_AddPathMode : SkPath::AddPathMode::kAppend_AddPathMode;
instance->addPath(*src, mode);
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PathKt__1nAddPathOffset
(JNIEnv* env, jclass jclass, jlong ptr, jlong srcPtr, jfloat dx, jfloat dy, jboolean extend) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
SkPath* src = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(srcPtr));
SkPath::AddPathMode mode = extend ? SkPath::AddPathMode::kExtend_AddPathMode : SkPath::AddPathMode::kAppend_AddPathMode;
instance->addPath(*src, dx, dy, mode);
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PathKt__1nAddPathTransform
(JNIEnv* env, jclass jclass, jlong ptr, jlong srcPtr, jfloatArray matrixArr, jboolean extend) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
SkPath* src = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(srcPtr));
std::unique_ptr<SkMatrix> matrix = skMatrix(env, matrixArr);
SkPath::AddPathMode mode = extend ? SkPath::AddPathMode::kExtend_AddPathMode : SkPath::AddPathMode::kAppend_AddPathMode;
instance->addPath(*src, *matrix, mode);
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PathKt__1nReverseAddPath
(JNIEnv* env, jclass jclass, jlong ptr, jlong srcPtr) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
SkPath* src = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(srcPtr));
instance->reverseAddPath(*src);
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PathKt__1nOffset
(JNIEnv* env, jclass jclass, jlong ptr, jfloat dx, jfloat dy, jlong dstPtr) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
SkPath* dst = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(dstPtr));
*dst = instance->makeOffset(dx, dy);
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PathKt__1nTransform
(JNIEnv* env, jclass jclass, jlong ptr, jfloatArray matrixArr, jlong dstPtr, jboolean pcBool) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
SkPath* dst = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(dstPtr));
std::unique_ptr<SkMatrix> matrix = skMatrix(env, matrixArr);
// SkApplyPerspectiveClip is deleted on skia side, ignore
instance->transform(*matrix, dst);
}
extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skia_PathKt__1nSetLastPt
(JNIEnv* env, jclass jclass, jlong ptr, jfloat x, jfloat y) {
SkPath* instance = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(ptr));
instance->setLastPt(x, y);
}
#include <jni.h>
#include "SkPathBuilder.h"
#include "SkPathMeasure.h"
#include "interop.hh"
......@@ -88,23 +89,9 @@ extern "C" JNIEXPORT jboolean JNICALL Java_org_jetbrains_skia_PathMeasureKt__1nG
flags |= SkPathMeasure::MatrixFlags::kGetTangent_MatrixFlag;
if (instance->getMatrix(distance, &matrix, static_cast<SkPathMeasure::MatrixFlags>(flags))) {
float* floats;
matrix.get9(floats);
jfloat d[9] = {
floats[0],
floats[1],
floats[2],
floats[3],
floats[4],
floats[5],
floats[6],
floats[7],
floats[8]
};
env->SetFloatArrayRegion(data, 0, 9, d);
jfloat values[9];
matrix.get9(values);
env->SetFloatArrayRegion(data, 0, 9, values);
return true;
}
......@@ -114,7 +101,7 @@ extern "C" JNIEXPORT jboolean JNICALL Java_org_jetbrains_skia_PathMeasureKt__1nG
extern "C" JNIEXPORT jboolean JNICALL Java_org_jetbrains_skia_PathMeasureKt__1nGetSegment
(JNIEnv* env, jclass jclass, jlong ptr, jfloat startD, jfloat endD, jlong dstPtr, jboolean startWithMoveTo) {
SkPathMeasure* instance = reinterpret_cast<SkPathMeasure*>(static_cast<uintptr_t>(ptr));
SkPath* dst = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(dstPtr));
SkPathBuilder* dst = reinterpret_cast<SkPathBuilder*>(static_cast<uintptr_t>(dstPtr));
return instance->getSegment(startD, endD, dst, startWithMoveTo);
}
......
#include <jni.h>
#include "SkPathUtils.h"
#include "SkPath.h"
#include "SkPaint.h"
#include "SkPath.h"
#include "SkPathBuilder.h"
#include "SkPathUtils.h"
#include "interop.hh"
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_PathUtilsKt__1nFillPathWithPaint
(JNIEnv* env, jclass jclass, jlong srcPtr, jlong paintPtr, jfloatArray matrixArr) {
std::unique_ptr<SkMatrix> matrix = skMatrix(env, matrixArr);
(JNIEnv* env, jclass jclass, jlong srcPtr, jlong paintPtr) {
SkPath* src = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(srcPtr));
SkPaint* paint = reinterpret_cast<SkPaint*>(static_cast<uintptr_t>(paintPtr));
SkPath* dst = new SkPath();
skpathutils::FillPathWithPaint(*src, *paint, dst, nullptr, *matrix);
SkPath* dst = new SkPath(skpathutils::FillPathWithPaint(*src, *paint));
return reinterpret_cast<jlong>(dst);
}
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_PathUtilsKt__1nFillPathWithPaintCull
(JNIEnv* env, jclass jclass, jlong srcPtr, jlong paintPtr, jfloat left, jfloat top, jfloat right, jfloat bottom, jfloatArray matrixArr) {
extern "C" JNIEXPORT jboolean JNICALL Java_org_jetbrains_skia_PathUtilsKt__1nFillPathWithPaintBuilder
(JNIEnv* env, jclass jclass, jlong srcPtr, jlong paintPtr, jlong dstPtr) {
SkPath* src = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(srcPtr));
SkPaint* paint = reinterpret_cast<SkPaint*>(static_cast<uintptr_t>(paintPtr));
SkPathBuilder* dst = reinterpret_cast<SkPathBuilder*>(static_cast<uintptr_t>(dstPtr));
return skpathutils::FillPathWithPaint(*src, *paint, dst);
}
extern "C" JNIEXPORT jboolean JNICALL Java_org_jetbrains_skia_PathUtilsKt__1nFillPathWithPaintMatrix
(JNIEnv* env, jclass jclass, jlong srcPtr, jlong paintPtr, jlong dstPtr, jfloatArray matrixArr) {
std::unique_ptr<SkMatrix> matrix = skMatrix(env, matrixArr);
SkPath* src = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(srcPtr));
SkPaint* paint = reinterpret_cast<SkPaint*>(static_cast<uintptr_t>(paintPtr));
SkPath* dst = new SkPath();
SkPathBuilder* dst = reinterpret_cast<SkPathBuilder*>(static_cast<uintptr_t>(dstPtr));
return skpathutils::FillPathWithPaint(*src, *paint, dst, nullptr, *matrix);
}
extern "C" JNIEXPORT jboolean JNICALL Java_org_jetbrains_skia_PathUtilsKt__1nFillPathWithPaintCull
(JNIEnv* env, jclass jclass, jlong srcPtr, jlong paintPtr, jlong dstPtr, jfloat left, jfloat top, jfloat right, jfloat bottom, jfloatArray matrixArr) {
std::unique_ptr<SkMatrix> matrix = skMatrix(env, matrixArr);
SkPath* src = reinterpret_cast<SkPath*>(static_cast<uintptr_t>(srcPtr));
SkPaint* paint = reinterpret_cast<SkPaint*>(static_cast<uintptr_t>(paintPtr));
SkPathBuilder* dst = reinterpret_cast<SkPathBuilder*>(static_cast<uintptr_t>(dstPtr));
SkRect cull {left, top, right, bottom};
skpathutils::FillPathWithPaint(*src, *paint, dst, &cull, *matrix);
return reinterpret_cast<jlong>(dst);
return skpathutils::FillPathWithPaint(*src, *paint, dst, &cull, *matrix);
}
#include <iostream>
#include <jni.h>
#include "interop.hh"
#include "SkColorFilter.h"
#include "SkShader.h"
#include "SkGradientShader.h"
#include "SkGradient.h"
#include "SkPerlinNoiseShader.h"
#include "SkShader.h"
#include "SkSize.h"
#include "interop.hh"
static SkGradient makeGradient(const SkColor4f* colors,
sk_sp<SkColorSpace> colorSpace,
const float* positions,
int count,
SkTileMode tileMode,
jint inPremul,
jint interpolationColorSpace,
jint hueMethod) {
SkGradient::Interpolation interpolation{
inPremul == 0 ? SkGradient::Interpolation::InPremul::kNo
: SkGradient::Interpolation::InPremul::kYes,
static_cast<SkGradient::Interpolation::ColorSpace>(interpolationColorSpace),
static_cast<SkGradient::Interpolation::HueMethod>(hueMethod)
};
return SkGradient(
SkGradient::Colors(
SkSpan<const SkColor4f>(colors, count),
positions == nullptr ? SkSpan<const float>() : SkSpan<const float>(positions, count),
tileMode,
std::move(colorSpace)),
interpolation);
}
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_ShaderKt__1nMakeWithLocalMatrix
(JNIEnv* env, jclass jclass, jlong ptr, jfloatArray localMatrixArr) {
SkShader* instance = reinterpret_cast<SkShader*>(static_cast<uintptr_t>(ptr));
......@@ -25,112 +47,63 @@ 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 _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);
SkTileMode tileMode = static_cast<SkTileMode>(tileModeInt);
std::unique_ptr<SkMatrix> localMatrix = skMatrix(env, matrixArray);
SkShader* ptr = SkGradientShader::MakeLinear(pts, reinterpret_cast<SkColor*>(colors), pos, _count, tileMode, static_cast<uint32_t>(flags), localMatrix.get()).release();
env->ReleaseIntArrayElements(colorsArray, colors, 0);
if (posArray != nullptr)
env->ReleaseFloatArrayElements(posArray, pos, 0);
return reinterpret_cast<jlong>(ptr);
}
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 _count, jint tileModeInt, jint flags, jfloatArray matrixArray) {
(JNIEnv* env, jclass jclass, jfloat x0, jfloat y0, jfloat x1, jfloat y1, jfloatArray colorsArray, jlong colorSpacePtr, jfloatArray positionsArray, jint count, jint tileModeInt, jint inPremul, jint interpolationColorSpace, jint hueMethod, 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)));
float* pos = posArray == nullptr ? nullptr : env->GetFloatArrayElements(posArray, nullptr);
float* positions = positionsArray == nullptr ? nullptr : env->GetFloatArrayElements(positionsArray, nullptr);
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, _count, tileMode, static_cast<uint32_t>(flags), localMatrix.get()).release();
SkGradient gradient = makeGradient(reinterpret_cast<SkColor4f*>(colors), colorSpace, positions, count, tileMode, inPremul, interpolationColorSpace, hueMethod);
SkShader* ptr = SkShaders::LinearGradient(pts, gradient, localMatrix.get()).release();
env->ReleaseFloatArrayElements(colorsArray, colors, 0);
if (posArray != nullptr)
env->ReleaseFloatArrayElements(posArray, pos, 0);
if (positionsArray != nullptr)
env->ReleaseFloatArrayElements(positionsArray, positions, 0);
return reinterpret_cast<jlong>(ptr);
}
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 _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);
std::unique_ptr<SkMatrix> localMatrix = skMatrix(env, matrixArray);
SkShader* ptr = SkGradientShader::MakeRadial(SkPoint::Make(x, y), r, reinterpret_cast<SkColor*>(colors), pos, _count, tileMode, static_cast<uint32_t>(flags), localMatrix.get()).release();
env->ReleaseIntArrayElements(colorsArray, colors, 0);
if (posArray != nullptr)
env->ReleaseFloatArrayElements(posArray, pos, 0);
return reinterpret_cast<jlong>(ptr);
}
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 _count, jint tileModeInt, jint flags, jfloatArray matrixArray) {
(JNIEnv* env, jclass jclass, jfloat x, jfloat y, jfloat radius, jfloatArray colorsArray, jlong colorSpacePtr, jfloatArray positionsArray, jint count, jint tileModeInt, jint inPremul, jint interpolationColorSpace, jint hueMethod, 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 = posArray == nullptr ? nullptr : env->GetFloatArrayElements(posArray, nullptr);
float* positions = positionsArray == nullptr ? nullptr : env->GetFloatArrayElements(positionsArray, nullptr);
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, _count, tileMode, static_cast<uint32_t>(flags), localMatrix.get()).release();
SkGradient gradient = makeGradient(reinterpret_cast<SkColor4f*>(colors), colorSpace, positions, count, tileMode, inPremul, interpolationColorSpace, hueMethod);
SkShader* ptr = SkShaders::RadialGradient(SkPoint::Make(x, y), radius, gradient, localMatrix.get()).release();
env->ReleaseFloatArrayElements(colorsArray, colors, 0);
if (posArray != nullptr)
env->ReleaseFloatArrayElements(posArray, pos, 0);
if (positionsArray != nullptr)
env->ReleaseFloatArrayElements(positionsArray, positions, 0);
return reinterpret_cast<jlong>(ptr);
}
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 _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);
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, _count, tileMode, static_cast<uint32_t>(flags), localMatrix.get()).release();
env->ReleaseIntArrayElements(colorsArray, colors, 0);
if (posArray != nullptr)
env->ReleaseFloatArrayElements(posArray, pos, 0);
return reinterpret_cast<jlong>(ptr);
}
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 _count, jint tileModeInt, jint flags, jfloatArray matrixArray) {
(JNIEnv* env, jclass jclass, jfloat x0, jfloat y0, jfloat startRadius, jfloat x1, jfloat y1, jfloat endRadius, jfloatArray colorsArray, jlong colorSpacePtr, jfloatArray positionsArray, jint count, jint tileModeInt, jint inPremul, jint interpolationColorSpace, jint hueMethod, 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 = posArray == nullptr ? nullptr : env->GetFloatArrayElements(posArray, nullptr);
float* positions = positionsArray == nullptr ? nullptr : env->GetFloatArrayElements(positionsArray, nullptr);
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, _count, tileMode, static_cast<uint32_t>(flags), localMatrix.get()).release();
SkGradient gradient = makeGradient(reinterpret_cast<SkColor4f*>(colors), colorSpace, positions, count, tileMode, inPremul, interpolationColorSpace, hueMethod);
SkShader* ptr = SkShaders::TwoPointConicalGradient(SkPoint::Make(x0, y0), startRadius, SkPoint::Make(x1, y1), endRadius, gradient, localMatrix.get()).release();
env->ReleaseFloatArrayElements(colorsArray, colors, 0);
if (posArray != nullptr)
env->ReleaseFloatArrayElements(posArray, pos, 0);
if (positionsArray != nullptr)
env->ReleaseFloatArrayElements(positionsArray, positions, 0);
return reinterpret_cast<jlong>(ptr);
}
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 _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);
std::unique_ptr<SkMatrix> localMatrix = skMatrix(env, matrixArray);
SkShader* ptr = SkGradientShader::MakeSweep(x, y, reinterpret_cast<SkColor*>(colors), pos, _count, tileMode, start, end, static_cast<uint32_t>(flags), localMatrix.get()).release();
env->ReleaseIntArrayElements(colorsArray, colors, 0);
if (posArray != nullptr)
env->ReleaseFloatArrayElements(posArray, pos, 0);
return reinterpret_cast<jlong>(ptr);
}
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 _count, jint tileModeInt, jint flags, jfloatArray matrixArray) {
(JNIEnv* env, jclass jclass, jfloat x, jfloat y, jfloat startAngle, jfloat endAngle, jfloatArray colorsArray, jlong colorSpacePtr, jfloatArray positionsArray, jint count, jint tileModeInt, jint inPremul, jint interpolationColorSpace, jint hueMethod, 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 = posArray == nullptr ? nullptr : env->GetFloatArrayElements(posArray, nullptr);
float* positions = positionsArray == nullptr ? nullptr : env->GetFloatArrayElements(positionsArray, nullptr);
SkTileMode tileMode = static_cast<SkTileMode>(tileModeInt);
std::unique_ptr<SkMatrix> localMatrix = skMatrix(env, matrixArray);
SkShader* ptr = SkGradientShader::MakeSweep(x, y, reinterpret_cast<SkColor4f*>(colors), colorSpace, pos, _count, tileMode, start, end, static_cast<uint32_t>(flags), localMatrix.get()).release();
SkGradient gradient = makeGradient(reinterpret_cast<SkColor4f*>(colors), colorSpace, positions, count, tileMode, inPremul, interpolationColorSpace, hueMethod);
SkShader* ptr = SkShaders::SweepGradient(SkPoint::Make(x, y), startAngle, endAngle, gradient, localMatrix.get()).release();
env->ReleaseFloatArrayElements(colorsArray, colors, 0);
if (posArray != nullptr)
env->ReleaseFloatArrayElements(posArray, pos, 0);
if (positionsArray != nullptr)
env->ReleaseFloatArrayElements(positionsArray, positions, 0);
return reinterpret_cast<jlong>(ptr);
}
......
#include <iostream>
#include <jni.h>
#include <vector>
#include "../interop.hh"
#include "SkRefCnt.h"
#include "FontCollection.h"
#include "SkRefCnt.h"
using namespace std;
using namespace skia::textlayout;
......@@ -73,9 +74,15 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_paragraph_FontCollect
}
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_paragraph_FontCollectionKt__1nDefaultFallbackChar
(JNIEnv* env, jclass jclass, jlong ptr, jint unicode, jint fontStyle, jstring locale) {
(JNIEnv* env, jclass jclass, jlong ptr, jint unicode, jobjectArray familyNamesArray, jsize len, jint fontStyle, jstring locale) {
FontCollection* instance = reinterpret_cast<FontCollection*>(static_cast<uintptr_t>(ptr));
return reinterpret_cast<jlong>(instance->defaultFallback(unicode, skija::FontStyle::fromJava(fontStyle), skString(env, locale), std::nullopt).release());
return reinterpret_cast<jlong>(instance->defaultFallback(
unicode,
skStringVector(env, familyNamesArray),
skija::FontStyle::fromJava(fontStyle),
skString(env, locale),
std::nullopt
).release());
}
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_paragraph_FontCollectionKt__1nDefaultFallback
......
#include <iostream>
#include <jni.h>
#include <string>
#include "ParagraphBuilder.h"
#include "../interop.hh"
#include "modules/skunicode/include/SkUnicode_icu.h"
#include "ParagraphBuilder.h"
using namespace std;
using namespace skia::textlayout;
......@@ -15,7 +16,11 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_paragraph_ParagraphBu
(JNIEnv* env, jclass jclass, jlong paragraphStylePtr, jlong fontCollectionPtr) {
ParagraphStyle* paragraphStyle = reinterpret_cast<ParagraphStyle*>(static_cast<uintptr_t>(paragraphStylePtr));
FontCollection* fontCollection = reinterpret_cast<FontCollection*>(static_cast<uintptr_t>(fontCollectionPtr));
ParagraphBuilder* instance = ParagraphBuilder::make(*paragraphStyle, sk_ref_sp(fontCollection)).release();
ParagraphBuilder* instance = ParagraphBuilder::make(
*paragraphStyle,
sk_ref_sp(fontCollection),
SkUnicodes::ICU::Make()
).release();
return reinterpret_cast<jlong>(instance);
}
......
......@@ -402,198 +402,3 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_Path__1nMakeFromPolygon
SkPath* instance = new SkPath(path);
return reinterpret_cast<KNativePointer>(instance);
}
// ================ DEPRECATED ================
SKIKO_EXPORT void org_jetbrains_skia_Path__1nReset(KNativePointer ptr) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
instance->reset();
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nRewind(KNativePointer ptr) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
instance->rewind();
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nUpdateBoundsCache(KNativePointer ptr) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
instance->updateBoundsCache();
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nIncReserve(KNativePointer ptr, int extraPtCount) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
instance->incReserve(extraPtCount);
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nMoveTo(KNativePointer ptr, KFloat x, KFloat y) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
instance->moveTo(x, y);
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nRMoveTo(KNativePointer ptr, KFloat dx, KFloat dy) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
instance->rMoveTo(dx, dy);
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nLineTo(KNativePointer ptr, KFloat x, KFloat y) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
instance->lineTo(x, y);
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nRLineTo(KNativePointer ptr, KFloat dx, KFloat dy) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
instance->rLineTo(dx, dy);
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nQuadTo(KNativePointer ptr, KFloat x1, KFloat y1, KFloat x2, KFloat y2) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
instance->quadTo(x1, y1, x2, y2);
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nRQuadTo(KNativePointer ptr, KFloat dx1, KFloat dy1, KFloat dx2, KFloat dy2) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
instance->rQuadTo(dx1, dy1, dx2, dy2);
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nConicTo(KNativePointer ptr, KFloat x1, KFloat y1, KFloat x2, KFloat y2, KFloat w) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
instance->conicTo(x1, y1, x2, y2, w);
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nRConicTo(KNativePointer ptr, KFloat dx1, KFloat dy1, KFloat dx2, KFloat dy2, KFloat w) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
instance->rConicTo(dx1, dy1, dx2, dy2, w);
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nCubicTo(KNativePointer ptr, KFloat x1, KFloat y1, KFloat x2, KFloat y2, KFloat x3, KFloat y3) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
instance->cubicTo(x1, y1, x2, y2, x3, y3);
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nRCubicTo(KNativePointer ptr, KFloat dx1, KFloat dy1, KFloat dx2, KFloat dy2, KFloat dx3, KFloat dy3) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
instance->rCubicTo(dx1, dy1, dx2, dy2, dx3, dy3);
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nArcTo(KNativePointer ptr, KFloat left, KFloat top, KFloat right, KFloat bottom, KFloat startAngle, KFloat sweepAngle, KBoolean forceMoveTo) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
instance->arcTo({left, top, right, bottom}, startAngle, sweepAngle, forceMoveTo);
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nTangentArcTo(KNativePointer ptr, KFloat x1, KFloat y1, KFloat x2, KFloat y2, KFloat radius) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
instance->arcTo(x1, y1, x2, y2, radius);
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nEllipticalArcTo(KNativePointer ptr, KFloat rx, KFloat ry, KFloat xAxisRotate, KInt size, KInt direction, KFloat x, float y) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
instance->arcTo(rx, ry, xAxisRotate, static_cast<SkPath::ArcSize>(size), static_cast<SkPathDirection>(direction), x, y);
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nREllipticalArcTo(KNativePointer ptr, KFloat rx, KFloat ry, KFloat xAxisRotate, KInt size, KInt direction, KFloat dx, float dy) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
instance->rArcTo(rx, ry, xAxisRotate, static_cast<SkPath::ArcSize>(size), static_cast<SkPathDirection>(direction), dx, dy);
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nClosePath(KNativePointer ptr) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
instance->close();
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nAddRect
(KNativePointer ptr, KFloat l, KFloat t, KFloat r, KFloat b, KInt dirInt, KInt start) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
SkPathDirection dir = static_cast<SkPathDirection>(dirInt);
instance->addRect({l, t, r, b}, dir, start);
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nAddOval
(KNativePointer ptr, KFloat l, KFloat t, KFloat r, KFloat b, KInt dirInt, KInt start) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
SkPathDirection dir = static_cast<SkPathDirection>(dirInt);
instance->addOval({l, t, r, b}, dir, start);
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nAddCircle
(KNativePointer ptr, KFloat x, KFloat y, KFloat r, KInt dirInt) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
SkPathDirection dir = static_cast<SkPathDirection>(dirInt);
instance->addCircle(x, y, r, dir);
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nAddArc
(KNativePointer ptr, KFloat l, KFloat t, KFloat r, KFloat b, KFloat startAngle, KFloat sweepAngle) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
instance->addArc({l, t, r, b}, startAngle, sweepAngle);
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nAddRRect
(KNativePointer ptr, KFloat l, KFloat t, KFloat r, KFloat b, KFloat* radii, KInt radiiSize, KInt dirInt, KInt start) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
SkRRect rrect = skija::RRect::toSkRRect(l, t, r, b, radii, radiiSize);
SkPathDirection dir = static_cast<SkPathDirection>(dirInt);
instance->addRRect(rrect, dir, start);
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nAddPoly
(KNativePointer ptr, KFloat* coords, KInt count, KBoolean close) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
instance->addPoly({reinterpret_cast<SkPoint*>(coords), count}, close);
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nAddPath
(KNativePointer ptr, KNativePointer srcPtr, KBoolean extend) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
SkPath* src = reinterpret_cast<SkPath*>((srcPtr));
SkPath::AddPathMode mode = extend ? SkPath::AddPathMode::kExtend_AddPathMode : SkPath::AddPathMode::kAppend_AddPathMode;
instance->addPath(*src, mode);
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nAddPathOffset
(KNativePointer ptr, KNativePointer srcPtr, KFloat dx, KFloat dy, KBoolean extend) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
SkPath* src = reinterpret_cast<SkPath*>((srcPtr));
SkPath::AddPathMode mode = extend ? SkPath::AddPathMode::kExtend_AddPathMode : SkPath::AddPathMode::kAppend_AddPathMode;
instance->addPath(*src, dx, dy, mode);
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nAddPathTransform
(KNativePointer ptr, KNativePointer srcPtr, KFloat* matrixArr, KBoolean extend) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
SkPath* src = reinterpret_cast<SkPath*>((srcPtr));
std::unique_ptr<SkMatrix> matrix = skMatrix(matrixArr);
SkPath::AddPathMode mode = extend ? SkPath::AddPathMode::kExtend_AddPathMode : SkPath::AddPathMode::kAppend_AddPathMode;
instance->addPath(*src, *matrix, mode);
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nReverseAddPath
(KNativePointer ptr, KNativePointer srcPtr) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
SkPath* src = reinterpret_cast<SkPath*>((srcPtr));
instance->reverseAddPath(*src);
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nOffset
(KNativePointer ptr, KFloat dx, KFloat dy, KNativePointer dstPtr) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
SkPath* dst = reinterpret_cast<SkPath*>((dstPtr));
*dst = instance->makeOffset(dx, dy);
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nTransform
(KNativePointer ptr, KFloat* matrixArr, KNativePointer dstPtr, KBoolean pcBool) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
SkPath* dst = reinterpret_cast<SkPath*>((dstPtr));
std::unique_ptr<SkMatrix> matrix = skMatrix(matrixArr);
// SkApplyPerspectiveClip is deleted on skia side, ignore
instance->transform(*matrix, dst);
}
SKIKO_EXPORT void org_jetbrains_skia_Path__1nSetLastPt
(KNativePointer ptr, KFloat x, KFloat y) {
SkPath* instance = reinterpret_cast<SkPath*>((ptr));
instance->setLastPt(x, y);
}
#include "SkPathBuilder.h"
#include "SkPathMeasure.h"
#include "common.h"
......@@ -89,19 +90,7 @@ SKIKO_EXPORT KBoolean org_jetbrains_skia_PathMeasure__1nGetMatrix
flags |= SkPathMeasure::MatrixFlags::kGetTangent_MatrixFlag;
if (instance->getMatrix(distance, &matrix, static_cast<SkPathMeasure::MatrixFlags>(flags))) {
float* f;
matrix.get9(f);
data[0] = data[0];
data[1] = data[1];
data[2] = data[2];
data[3] = data[3];
data[4] = data[4];
data[5] = data[5];
data[6] = data[6];
data[7] = data[7];
data[8] = data[8];
matrix.get9(data);
return true;
}
......@@ -111,7 +100,7 @@ SKIKO_EXPORT KBoolean org_jetbrains_skia_PathMeasure__1nGetMatrix
SKIKO_EXPORT KBoolean org_jetbrains_skia_PathMeasure__1nGetSegment
(KNativePointer ptr, KFloat startD, KFloat endD, KNativePointer dstPtr, KBoolean startWithMoveTo) {
SkPathMeasure* instance = reinterpret_cast<SkPathMeasure*>((ptr));
SkPath* dst = reinterpret_cast<SkPath*>((dstPtr));
SkPathBuilder* dst = reinterpret_cast<SkPathBuilder*>((dstPtr));
return instance->getSegment(startD, endD, dst, startWithMoveTo);
}
......
#include "SkPathUtils.h"
#include "SkPath.h"
#include "SkPaint.h"
#include "SkPath.h"
#include "SkPathBuilder.h"
#include "SkPathUtils.h"
#include "common.h"
SKIKO_EXPORT KNativePointer org_jetbrains_skia_PathUtils__1nFillPathWithPaint
(KNativePointer srcPtr, KNativePointer paintPtr, KFloat* matrixArr) {
std::unique_ptr<SkMatrix> matrix = skMatrix(matrixArr);
(KNativePointer srcPtr, KNativePointer paintPtr) {
SkPath* src = reinterpret_cast<SkPath*>((srcPtr));
SkPaint* paint = reinterpret_cast<SkPaint*>((paintPtr));
SkPath* dst = new SkPath();
skpathutils::FillPathWithPaint(*src, *paint, dst, nullptr, *matrix);
return reinterpret_cast<KNativePointer>(dst);
return reinterpret_cast<KNativePointer>(new SkPath(skpathutils::FillPathWithPaint(*src, *paint)));
}
SKIKO_EXPORT KBoolean org_jetbrains_skia_PathUtils__1nFillPathWithPaintBuilder
(KNativePointer srcPtr, KNativePointer paintPtr, KNativePointer dstPtr) {
SkPath* src = reinterpret_cast<SkPath*>(srcPtr);
SkPaint* paint = reinterpret_cast<SkPaint*>(paintPtr);
SkPathBuilder* dst = reinterpret_cast<SkPathBuilder*>(dstPtr);
return skpathutils::FillPathWithPaint(*src, *paint, dst);
}
SKIKO_EXPORT KBoolean org_jetbrains_skia_PathUtils__1nFillPathWithPaintMatrix
(KNativePointer srcPtr, KNativePointer paintPtr, KNativePointer dstPtr, KFloat* matrixArr) {
std::unique_ptr<SkMatrix> matrix = skMatrix(matrixArr);
SkPath* src = reinterpret_cast<SkPath*>(srcPtr);
SkPaint* paint = reinterpret_cast<SkPaint*>(paintPtr);
SkPathBuilder* dst = reinterpret_cast<SkPathBuilder*>(dstPtr);
return skpathutils::FillPathWithPaint(*src, *paint, dst, nullptr, *matrix);
}
SKIKO_EXPORT KNativePointer org_jetbrains_skia_PathUtils__1nFillPathWithPaintCull
(KNativePointer srcPtr, KNativePointer paintPtr, KFloat left, KFloat top, KFloat right, KFloat bottom, KFloat* matrixArr) {
SKIKO_EXPORT KBoolean org_jetbrains_skia_PathUtils__1nFillPathWithPaintCull
(KNativePointer srcPtr, KNativePointer paintPtr, KNativePointer dstPtr, KFloat left, KFloat top, KFloat right, KFloat bottom, KFloat* matrixArr) {
std::unique_ptr<SkMatrix> matrix = skMatrix(matrixArr);
SkPath* src = reinterpret_cast<SkPath*>((srcPtr));
SkPaint* paint = reinterpret_cast<SkPaint*>((paintPtr));
SkPath* dst = new SkPath();
SkPathBuilder* dst = reinterpret_cast<SkPathBuilder*>(dstPtr);
SkRect cull {left, top, right, bottom};
skpathutils::FillPathWithPaint(*src, *paint, dst, &cull, *matrix);
return reinterpret_cast<KNativePointer>(dst);
return skpathutils::FillPathWithPaint(*src, *paint, dst, &cull, *matrix);
}
#include <iostream>
#include "SkColorFilter.h"
#include "SkShader.h"
#include "SkGradientShader.h"
#include "SkGradient.h"
#include "SkPerlinNoiseShader.h"
#include "SkShader.h"
#include "SkSize.h"
#include "common.h"
static SkGradient makeGradient(const SkColor4f* colors,
sk_sp<SkColorSpace> colorSpace,
const float* positions,
int count,
SkTileMode tileMode,
KInt inPremul,
KInt interpolationColorSpace,
KInt hueMethod) {
SkGradient::Interpolation interpolation{
inPremul == 0 ? SkGradient::Interpolation::InPremul::kNo
: SkGradient::Interpolation::InPremul::kYes,
static_cast<SkGradient::Interpolation::ColorSpace>(interpolationColorSpace),
static_cast<SkGradient::Interpolation::HueMethod>(hueMethod)
};
return SkGradient(
SkGradient::Colors(
SkSpan<const SkColor4f>(colors, count),
positions == nullptr ? SkSpan<const float>() : SkSpan<const float>(positions, count),
tileMode,
std::move(colorSpace)),
interpolation);
}
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Shader__1nMakeWithLocalMatrix
(KNativePointer ptr, KFloat* localMatrixArr) {
SkShader* instance = reinterpret_cast<SkShader*>((ptr));
......@@ -23,96 +46,53 @@ 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 count, KInt tileModeInt, KInt flags, KFloat* matrixArray) {
SkPoint pts[2] {SkPoint::Make(x0, y0), SkPoint::Make(x1, y1)};
SkColor* colors = reinterpret_cast<SkColor*>(colorsArray);
float* pos = reinterpret_cast<float*>(posArray);
SkTileMode tileMode = static_cast<SkTileMode>(tileModeInt);
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);
}
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Shader__1nMakeLinearGradientCS
(KFloat x0, KFloat y0, KFloat x1, KFloat y1, KFloat* colorsArray, KNativePointer colorSpacePtr, KFloat* posArray, KInt count, KInt tileModeInt, KInt flags, KFloat* matrixArray) {
(KFloat x0, KFloat y0, KFloat x1, KFloat y1, KFloat* colorsArray, KNativePointer colorSpacePtr, KFloat* positionsArray, KInt count, KInt tileModeInt, KInt inPremul, KInt interpolationColorSpace, KInt hueMethod, KFloat* matrixArray) {
SkPoint pts[2] {SkPoint::Make(x0, y0), SkPoint::Make(x1, y1)};
SkColor4f* colors = reinterpret_cast<SkColor4f*>(colorsArray);
sk_sp<SkColorSpace> colorSpace = sk_ref_sp<SkColorSpace>(reinterpret_cast<SkColorSpace*>((colorSpacePtr)));
float* pos = reinterpret_cast<float*>(posArray);
float* positions = reinterpret_cast<float*>(positionsArray);
SkTileMode tileMode = static_cast<SkTileMode>(tileModeInt);
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();
SkGradient gradient = makeGradient(colors, colorSpace, positions, count, tileMode, inPremul, interpolationColorSpace, hueMethod);
SkShader* ptr = SkShaders::LinearGradient(pts, gradient, localMatrix.get()).release();
return reinterpret_cast<KNativePointer>(ptr);
}
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Shader__1nMakeRadialGradient
(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(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);
}
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Shader__1nMakeRadialGradientCS
(KFloat x, KFloat y, KFloat r, KFloat* colorsArray, KNativePointer colorSpacePtr, KFloat* posArray, KInt count, KInt tileModeInt, KInt flags, KFloat* matrixArray) {
(KFloat x, KFloat y, KFloat radius, KFloat* colorsArray, KNativePointer colorSpacePtr, KFloat* positionsArray, KInt count, KInt tileModeInt, KInt inPremul, KInt interpolationColorSpace, KInt hueMethod, 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);
float* positions = reinterpret_cast<float*>(positionsArray);
SkTileMode tileMode = static_cast<SkTileMode>(tileModeInt);
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();
SkGradient gradient = makeGradient(colors, colorSpace, positions, count, tileMode, inPremul, interpolationColorSpace, hueMethod);
SkShader* ptr = SkShaders::RadialGradient(SkPoint::Make(x, y), radius, gradient, localMatrix.get()).release();
return reinterpret_cast<KNativePointer>(ptr);
}
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 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(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);
}
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 count, KInt tileModeInt, KInt flags, KFloat* matrixArray) {
(KFloat x0, KFloat y0, KFloat startRadius, KFloat x1, KFloat y1, KFloat endRadius, KFloat* colorsArray, KNativePointer colorSpacePtr, KFloat* positionsArray, KInt count, KInt tileModeInt, KInt inPremul, KInt interpolationColorSpace, KInt hueMethod, 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);
float* positions = reinterpret_cast<float*>(positionsArray);
SkTileMode tileMode = static_cast<SkTileMode>(tileModeInt);
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();
SkGradient gradient = makeGradient(colors, colorSpace, positions, count, tileMode, inPremul, interpolationColorSpace, hueMethod);
SkShader* ptr = SkShaders::TwoPointConicalGradient(SkPoint::Make(x0, y0), startRadius, SkPoint::Make(x1, y1), endRadius, gradient, localMatrix.get()).release();
return reinterpret_cast<KNativePointer>(ptr);
}
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Shader__1nMakeSweepGradient
(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(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);
}
SKIKO_EXPORT KNativePointer 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) {
(KFloat x, KFloat y, KFloat startAngle, KFloat endAngle, KFloat* colorsArray, KNativePointer colorSpacePtr, KFloat* positionsArray, KInt count, KInt tileModeInt, KInt inPremul, KInt interpolationColorSpace, KInt hueMethod, 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);
float* positions = reinterpret_cast<float*>(positionsArray);
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);}
SkGradient gradient = makeGradient(colors, colorSpace, positions, count, tileMode, inPremul, interpolationColorSpace, hueMethod);
SkShader* ptr = SkShaders::SweepGradient(SkPoint::Make(x, y), startAngle, endAngle, gradient, localMatrix.get()).release();
return reinterpret_cast<KNativePointer>(ptr);
}
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Shader__1nMakeEmpty() {
SkShader* ptr = SkShaders::Empty().release();
......
#include <iostream>
#include "SkRefCnt.h"
#include <vector>
#include "FontCollection.h"
#include "SkRefCnt.h"
using namespace std;
using namespace skia::textlayout;
#include "common.h"
......@@ -75,9 +77,15 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_paragraph_FontCollection__1nFindT
}
SKIKO_EXPORT KNativePointer org_jetbrains_skia_paragraph_FontCollection__1nDefaultFallbackChar
(KNativePointer ptr, KInt unicode, KInt fontStyle, KInteropPointer locale) {
(KNativePointer ptr, KInt unicode, KInteropPointerArray familyNamesArray, KInt len, KInt fontStyle, KInteropPointer locale) {
FontCollection* instance = reinterpret_cast<FontCollection*>(ptr);
return reinterpret_cast<KNativePointer>(instance->defaultFallback(unicode, skija::FontStyle::fromKotlin(fontStyle), skString(locale), std::nullopt).release());
return reinterpret_cast<KNativePointer>(instance->defaultFallback(
unicode,
skStringVector(familyNamesArray, len),
skija::FontStyle::fromKotlin(fontStyle),
skString(locale),
std::nullopt
).release());
}
SKIKO_EXPORT KNativePointer org_jetbrains_skia_paragraph_FontCollection__1nDefaultFallback
......
#include <iostream>
#include <string>
#include "modules/skunicode/include/SkUnicode_icu.h"
#include "ParagraphBuilder.h"
using namespace std;
using namespace skia::textlayout;
#include "common.h"
......@@ -13,7 +15,11 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_paragraph_ParagraphBuilder__1nMak
(KNativePointer paragraphStylePtr, KNativePointer fontCollectionPtr) {
ParagraphStyle* paragraphStyle = reinterpret_cast<ParagraphStyle*>((paragraphStylePtr));
FontCollection* fontCollection = reinterpret_cast<FontCollection*>((fontCollectionPtr));
ParagraphBuilder* instance = ParagraphBuilder::make(*paragraphStyle, sk_ref_sp(fontCollection)).release();
ParagraphBuilder* instance = ParagraphBuilder::make(
*paragraphStyle,
sk_ref_sp(fontCollection),
SkUnicodes::ICU::Make()
).release();
return reinterpret_cast<KNativePointer>(instance);
}
......
......@@ -14,7 +14,7 @@ class FontFallbackWebTest {
it.setDefaultFontManager(FontMgr.default)
// 0x6C34 = "水"
val df = it.defaultFallback(0x6C34, FontStyle.NORMAL, null)
val df = it.defaultFallback(0x6C34, null, FontStyle.NORMAL, null)
assertEquals(null, df)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment