Unverified Commit 839ae5e2 authored by Oleksandr Karpovich's avatar Oleksandr Karpovich Committed by GitHub

add more Surface Tests (#264)

* add more Surface Tests

* fix org_jetbrains_skia_Pixmap__1nMake
Co-authored-by: 's avatarOleksandr Karpovich <oleksandr.karpovich@jetbrains.com>
parent 71e2477d
...@@ -59,6 +59,10 @@ namespace skija { ...@@ -59,6 +59,10 @@ namespace skija {
namespace ImageInfo { namespace ImageInfo {
void writeImageInfoForInterop(SkImageInfo imageInfo, KInt* imageInfoResult, KNativePointer* colorSpacePtrsArray); void writeImageInfoForInterop(SkImageInfo imageInfo, KInt* imageInfoResult, KNativePointer* colorSpacePtrsArray);
} }
namespace SurfaceProps {
std::unique_ptr<SkSurfaceProps> toSkSurfaceProps(KInt* surfacePropsInts);
}
} }
std::unique_ptr<SkMatrix> skMatrix(KFloat* matrixArray); std::unique_ptr<SkMatrix> skMatrix(KFloat* matrixArray);
......
...@@ -157,4 +157,15 @@ namespace skija { ...@@ -157,4 +157,15 @@ namespace skija {
colorSpacePtrsArray[0] = imageInfo.refColorSpace().release(); colorSpacePtrsArray[0] = imageInfo.refColorSpace().release();
} }
} }
namespace SurfaceProps {
std::unique_ptr<SkSurfaceProps> toSkSurfaceProps(KInt* surfacePropsInts) {
if (surfacePropsInts == nullptr) {
return std::unique_ptr<SkSurfaceProps>(nullptr);
}
int flags = surfacePropsInts[0];
SkPixelGeometry geom = static_cast<SkPixelGeometry>(surfacePropsInts[1]);
return std::make_unique<SkSurfaceProps>(flags, geom);
}
}
} }
...@@ -19,8 +19,7 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_Pixmap__1nMakeNull ...@@ -19,8 +19,7 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_Pixmap__1nMakeNull
} }
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Pixmap__1nMake SKIKO_EXPORT KNativePointer org_jetbrains_skia_Pixmap__1nMake
(KInteropPointer __Kinstance, (KInt width, KInt height, KInt colorType, KInt alphaType, KNativePointer colorSpacePtr, KNativePointer pixelsPtr, KInt rowBytes) {
KInt width, KInt height, KInt colorType, KInt alphaType, KNativePointer colorSpacePtr, KNativePointer pixelsPtr, KInt rowBytes) {
SkColorSpace* colorSpace = interopToPtr<SkColorSpace*>(colorSpacePtr); SkColorSpace* colorSpace = interopToPtr<SkColorSpace*>(colorSpacePtr);
SkImageInfo imageInfo = SkImageInfo::Make(width, SkImageInfo imageInfo = SkImageInfo::Make(width,
height, height,
......
...@@ -8,85 +8,52 @@ ...@@ -8,85 +8,52 @@
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Surface__1nMakeRasterDirect SKIKO_EXPORT KNativePointer org_jetbrains_skia_Surface__1nMakeRasterDirect
(KInteropPointer __Kinstance, (KInt width, KInt height, KInt colorType, KInt alphaType, KNativePointer colorSpacePtr,
KInt width, KInt height, KInt colorType, KInt alphaType, KNativePointer colorSpacePtr, KNativePointer pixelsPtr, KInt rowBytes,
KNativePointer pixelsPtr, KNativePointer rowBytes, KInt* surfacePropsInts)
KInteropPointer surfacePropsObj)
{
TODO("implement org_jetbrains_skia_Surface__1nMakeRasterDirect");
}
#if 0
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Surface__1nMakeRasterDirect
(KInteropPointer __Kinstance,
KInt width, KInt height, KInt colorType, KInt alphaType, KNativePointer colorSpacePtr,
KNativePointer pixelsPtr, KNativePointer rowBytes,
KInteropPointer surfacePropsObj)
{ {
SkColorSpace* colorSpace = reinterpret_cast<SkColorSpace*>((colorSpacePtr)); SkColorSpace* colorSpace = reinterpret_cast<SkColorSpace*>(colorSpacePtr);
SkImageInfo imageInfo = SkImageInfo::Make(width, SkImageInfo imageInfo = SkImageInfo::Make(width,
height, height,
static_cast<SkColorType>(colorType), static_cast<SkColorType>(colorType),
static_cast<SkAlphaType>(alphaType), static_cast<SkAlphaType>(alphaType),
sk_ref_sp<SkColorSpace>(colorSpace)); sk_ref_sp<SkColorSpace>(colorSpace));
std::unique_ptr<SkSurfaceProps> surfaceProps = skija::SurfaceProps::toSkSurfaceProps(env, surfacePropsObj); std::unique_ptr<SkSurfaceProps> surfaceProps = skija::SurfaceProps::toSkSurfaceProps(surfacePropsInts);
sk_sp<SkSurface> instance = SkSurface::MakeRasterDirect( sk_sp<SkSurface> instance = SkSurface::MakeRasterDirect(
imageInfo, imageInfo,
reinterpret_cast<void*>((pixelsPtr)), reinterpret_cast<void*>(pixelsPtr),
rowBytes, rowBytes,
surfaceProps.get()); surfaceProps.get());
return reinterpret_cast<KNativePointer>(instance.release()); return reinterpret_cast<KNativePointer>(instance.release());
} }
#endif
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Surface__1nMakeRasterDirectWithPixmap
(KInteropPointer __Kinstance,
KNativePointer pixmapPtr, KInteropPointer surfacePropsObj)
{
TODO("implement org_jetbrains_skia_Surface__1nMakeRasterDirectWithPixmap");
}
#if 0
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Surface__1nMakeRasterDirectWithPixmap SKIKO_EXPORT KNativePointer org_jetbrains_skia_Surface__1nMakeRasterDirectWithPixmap
(KInteropPointer __Kinstance, (KNativePointer pixmapPtr, KInt* surfacePropsInts)
KNativePointer pixmapPtr, KInteropPointer surfacePropsObj)
{ {
SkPixmap* pixmap = reinterpret_cast<SkPixmap*>((pixmapPtr)); SkPixmap* pixmap = reinterpret_cast<SkPixmap*>(pixmapPtr);
std::unique_ptr<SkSurfaceProps> surfaceProps = skija::SurfaceProps::toSkSurfaceProps(env, surfacePropsObj); std::unique_ptr<SkSurfaceProps> surfaceProps = skija::SurfaceProps::toSkSurfaceProps(surfacePropsInts);
sk_sp<SkSurface> instance = SkSurface::MakeRasterDirect(*pixmap, surfaceProps.get()); sk_sp<SkSurface> instance = SkSurface::MakeRasterDirect(*pixmap, surfaceProps.get());
return reinterpret_cast<KNativePointer>(instance.release()); return reinterpret_cast<KNativePointer>(instance.release());
} }
#endif
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Surface__1nMakeRaster SKIKO_EXPORT KNativePointer org_jetbrains_skia_Surface__1nMakeRaster
(KInteropPointer __Kinstance, (KInt width, KInt height, KInt colorType, KInt alphaType, KNativePointer colorSpacePtr,
KInt width, KInt height, KInt colorType, KInt alphaType, KNativePointer colorSpacePtr, KInt rowBytes,
KNativePointer rowBytes, KInt* surfacePropsInts)
KInteropPointer surfacePropsObj)
{
TODO("implement org_jetbrains_skia_Surface__1nMakeRaster");
}
#if 0
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Surface__1nMakeRaster
(KInteropPointer __Kinstance,
KInt width, KInt height, KInt colorType, KInt alphaType, KNativePointer colorSpacePtr,
KNativePointer rowBytes,
KInteropPointer surfacePropsObj)
{ {
SkColorSpace* colorSpace = reinterpret_cast<SkColorSpace*>((colorSpacePtr)); SkColorSpace* colorSpace = reinterpret_cast<SkColorSpace*>(colorSpacePtr);
SkImageInfo imageInfo = SkImageInfo::Make(width, SkImageInfo imageInfo = SkImageInfo::Make(width,
height, height,
static_cast<SkColorType>(colorType), static_cast<SkColorType>(colorType),
static_cast<SkAlphaType>(alphaType), static_cast<SkAlphaType>(alphaType),
sk_ref_sp<SkColorSpace>(colorSpace)); sk_ref_sp<SkColorSpace>(colorSpace));
std::unique_ptr<SkSurfaceProps> surfaceProps = skija::SurfaceProps::toSkSurfaceProps(env, surfacePropsObj); std::unique_ptr<SkSurfaceProps> surfaceProps = skija::SurfaceProps::toSkSurfaceProps(surfacePropsInts);
sk_sp<SkSurface> instance = SkSurface::MakeRaster( sk_sp<SkSurface> instance = SkSurface::MakeRaster(
imageInfo, imageInfo,
...@@ -94,7 +61,6 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_Surface__1nMakeRaster ...@@ -94,7 +61,6 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_Surface__1nMakeRaster
surfaceProps.get()); surfaceProps.get());
return reinterpret_cast<KNativePointer>(instance.release()); return reinterpret_cast<KNativePointer>(instance.release());
} }
#endif
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Surface__1nMakeRasterN32Premul SKIKO_EXPORT KNativePointer org_jetbrains_skia_Surface__1nMakeRasterN32Premul
......
...@@ -39,7 +39,7 @@ class Surface : RefCnt { ...@@ -39,7 +39,7 @@ class Surface : RefCnt {
fun makeRasterDirect( fun makeRasterDirect(
imageInfo: ImageInfo, imageInfo: ImageInfo,
pixelsPtr: NativePointer, pixelsPtr: NativePointer,
rowBytes: NativePointer rowBytes: Int
): Surface { ): Surface {
return makeRasterDirect(imageInfo, pixelsPtr, rowBytes, null) return makeRasterDirect(imageInfo, pixelsPtr, rowBytes, null)
} }
...@@ -50,9 +50,11 @@ class Surface : RefCnt { ...@@ -50,9 +50,11 @@ class Surface : RefCnt {
): Surface { ): Surface {
return try { return try {
Stats.onNativeCall() Stats.onNativeCall()
val ptr = _nMakeRasterDirectWithPixmap( val ptr = interopScope {
getPtr(pixmap), surfaceProps _nMakeRasterDirectWithPixmap(
) getPtr(pixmap), toInterop(surfaceProps?.packToIntArray())
)
}
require(ptr != NullPointer) { require(ptr != NullPointer) {
"Failed Surface.makeRasterDirect($pixmap, $surfaceProps)" "Failed Surface.makeRasterDirect($pixmap, $surfaceProps)"
} }
...@@ -94,21 +96,23 @@ class Surface : RefCnt { ...@@ -94,21 +96,23 @@ class Surface : RefCnt {
fun makeRasterDirect( fun makeRasterDirect(
imageInfo: ImageInfo, imageInfo: ImageInfo,
pixelsPtr: NativePointer, pixelsPtr: NativePointer,
rowBytes: NativePointer, rowBytes: Int,
surfaceProps: SurfaceProps? surfaceProps: SurfaceProps?
): Surface { ): Surface {
return try { return try {
Stats.onNativeCall() Stats.onNativeCall()
val ptr = _nMakeRasterDirect( val ptr = interopScope {
imageInfo.width, _nMakeRasterDirect(
imageInfo.height, imageInfo.width,
imageInfo.colorInfo.colorType.ordinal, imageInfo.height,
imageInfo.colorInfo.alphaType.ordinal, imageInfo.colorInfo.colorType.ordinal,
getPtr(imageInfo.colorInfo.colorSpace), imageInfo.colorInfo.alphaType.ordinal,
pixelsPtr, getPtr(imageInfo.colorInfo.colorSpace),
rowBytes, pixelsPtr,
surfaceProps rowBytes,
) toInterop(surfaceProps?.packToIntArray())
)
}
require(ptr != NullPointer) { require(ptr != NullPointer) {
"Failed Surface.makeRasterDirect($imageInfo, $pixelsPtr, $rowBytes, $surfaceProps)" "Failed Surface.makeRasterDirect($imageInfo, $pixelsPtr, $rowBytes, $surfaceProps)"
} }
...@@ -135,7 +139,7 @@ class Surface : RefCnt { ...@@ -135,7 +139,7 @@ class Surface : RefCnt {
* @return new Surface * @return new Surface
*/ */
fun makeRaster(imageInfo: ImageInfo): Surface { fun makeRaster(imageInfo: ImageInfo): Surface {
return makeRaster(imageInfo, NullPointer, null) return makeRaster(imageInfo, imageInfo.minRowBytes, null)
} }
/** /**
...@@ -162,7 +166,7 @@ class Surface : RefCnt { ...@@ -162,7 +166,7 @@ class Surface : RefCnt {
*/ */
fun makeRaster( fun makeRaster(
imageInfo: ImageInfo, imageInfo: ImageInfo,
rowBytes: NativePointer rowBytes: Int
): Surface { ): Surface {
return makeRaster(imageInfo, rowBytes, null) return makeRaster(imageInfo, rowBytes, null)
} }
...@@ -193,20 +197,22 @@ class Surface : RefCnt { ...@@ -193,20 +197,22 @@ class Surface : RefCnt {
*/ */
fun makeRaster( fun makeRaster(
imageInfo: ImageInfo, imageInfo: ImageInfo,
rowBytes: NativePointer, rowBytes: Int,
surfaceProps: SurfaceProps? surfaceProps: SurfaceProps?
): Surface { ): Surface {
return try { return try {
Stats.onNativeCall() Stats.onNativeCall()
val ptr = _nMakeRaster( val ptr = interopScope {
imageInfo.width, _nMakeRaster(
imageInfo.height, imageInfo.width,
imageInfo.colorInfo.colorType.ordinal, imageInfo.height,
imageInfo.colorInfo.alphaType.ordinal, imageInfo.colorInfo.colorType.ordinal,
getPtr(imageInfo.colorInfo.colorSpace), imageInfo.colorInfo.alphaType.ordinal,
rowBytes, getPtr(imageInfo.colorInfo.colorSpace),
surfaceProps rowBytes,
) toInterop(surfaceProps?.packToIntArray())
)
}
require(ptr != NullPointer) { require(ptr != NullPointer) {
"Failed Surface.makeRaster($imageInfo, $rowBytes, $surfaceProps)" "Failed Surface.makeRaster($imageInfo, $rowBytes, $surfaceProps)"
} }
...@@ -1011,13 +1017,13 @@ private external fun _nMakeRasterDirect( ...@@ -1011,13 +1017,13 @@ private external fun _nMakeRasterDirect(
alphaType: Int, alphaType: Int,
colorSpacePtr: NativePointer, colorSpacePtr: NativePointer,
pixelsPtr: NativePointer, pixelsPtr: NativePointer,
rowBytes: NativePointer, rowBytes: Int,
surfaceProps: SurfaceProps? surfaceProps: InteropPointer
): NativePointer ): NativePointer
@ExternalSymbolName("org_jetbrains_skia_Surface__1nMakeRasterDirectWithPixmap") @ExternalSymbolName("org_jetbrains_skia_Surface__1nMakeRasterDirectWithPixmap")
private external fun _nMakeRasterDirectWithPixmap(pixmapPtr: NativePointer, surfaceProps: SurfaceProps?): NativePointer private external fun _nMakeRasterDirectWithPixmap(pixmapPtr: NativePointer, surfaceProps: InteropPointer): NativePointer
@ExternalSymbolName("org_jetbrains_skia_Surface__1nMakeRaster") @ExternalSymbolName("org_jetbrains_skia_Surface__1nMakeRaster")
private external fun _nMakeRaster( private external fun _nMakeRaster(
...@@ -1026,8 +1032,8 @@ private external fun _nMakeRaster( ...@@ -1026,8 +1032,8 @@ private external fun _nMakeRaster(
colorType: Int, colorType: Int,
alphaType: Int, alphaType: Int,
colorSpacePtr: NativePointer, colorSpacePtr: NativePointer,
rowBytes: NativePointer, rowBytes: Int,
surfaceProps: SurfaceProps? surfaceProps: InteropPointer
): NativePointer ): NativePointer
......
...@@ -44,4 +44,8 @@ class SurfaceProps constructor( ...@@ -44,4 +44,8 @@ class SurfaceProps constructor(
fun withPixelGeometry(_pixelGeometry: PixelGeometry): SurfaceProps { fun withPixelGeometry(_pixelGeometry: PixelGeometry): SurfaceProps {
return if (pixelGeometry == _pixelGeometry) this else SurfaceProps(isDeviceIndependentFonts, _pixelGeometry) return if (pixelGeometry == _pixelGeometry) this else SurfaceProps(isDeviceIndependentFonts, _pixelGeometry)
} }
}
\ No newline at end of file internal fun packToIntArray(): IntArray {
return intArrayOf(_getFlags(), _getPixelGeometryOrdinal())
}
}
package org.jetbrains.skia package org.jetbrains.skia
import org.jetbrains.skia.impl.interopScope
import org.jetbrains.skia.impl.use import org.jetbrains.skia.impl.use
import kotlin.test.Test import org.jetbrains.skiko.tests.allocateBytesForPixels
import kotlin.test.assertEquals import org.jetbrains.skiko.tests.runTest
import kotlin.test.assertFailsWith import kotlin.test.*
import kotlin.test.assertNotEquals
import kotlin.test.assertTrue
class SurfaceTest { class SurfaceTest {
...@@ -57,4 +56,49 @@ class SurfaceTest { ...@@ -57,4 +56,49 @@ class SurfaceTest {
assertEquals(context, null) assertEquals(context, null)
} }
} }
@Test
fun canMakeRaster() = runTest {
val imageInfo = ImageInfo.makeN32Premul(100, 100)
val surface1 = Surface.makeRaster(
imageInfo, imageInfo.minRowBytes, SurfaceProps()
)
assertEquals(100, surface1.width)
assertEquals(100, surface1.height)
val surface2 = Surface.makeRaster(
imageInfo, imageInfo.minRowBytes, null
)
}
@Test
fun canMakeRasterDirect() = runTest {
interopScope {
val imageInfo = ImageInfo.makeN32Premul(25, 25)
val addr = allocateBytesForPixels(25 * imageInfo.minRowBytes)
val surface = Surface.makeRasterDirect(imageInfo, addr, imageInfo.minRowBytes)
val writePixelsBitmap = Bitmap()
writePixelsBitmap.setImageInfo(ImageInfo.makeN32Premul(10, 20))
writePixelsBitmap.allocPixels()
surface.writePixels(writePixelsBitmap, 0, 0)
}
}
@Test
fun canMakeRasterDirectUsingPixmap() = runTest {
interopScope {
val imageInfo = ImageInfo.makeN32Premul(20, 20)
val addr = allocateBytesForPixels(20 * imageInfo.minRowBytes)
val pixmap = Pixmap.make(imageInfo, addr, imageInfo.minRowBytes)
val surface = Surface.makeRasterDirect(pixmap)
val writePixelsBitmap = Bitmap()
writePixelsBitmap.setImageInfo(ImageInfo.makeN32Premul(10, 10))
writePixelsBitmap.allocPixels()
surface.writePixels(writePixelsBitmap, 0, 0)
}
}
} }
package org.jetbrains.skiko.tests package org.jetbrains.skiko.tests
import org.jetbrains.skia.ByteBuffer
import org.jetbrains.skia.ExternalSymbolName import org.jetbrains.skia.ExternalSymbolName
import org.jetbrains.skia.impl.InteropPointer import org.jetbrains.skia.impl.*
import org.jetbrains.skia.impl.Library
import org.jetbrains.skia.impl.withResult
class TestHelpers { class TestHelpers {
...@@ -37,6 +36,12 @@ class TestHelpers { ...@@ -37,6 +36,12 @@ class TestHelpers {
} }
} }
fun getPointerFromByteBuffer(buffer: ByteBuffer): NativePointer {
val result = _nGetPointerFromByteBuffer(buffer)
require(result != Native.NullPointer) { "The given buffer " + buffer + "is not a direct buffer or current JVM doesn't support JNI direct buffer access!" }
return result
}
init { init {
Library.staticLoad() Library.staticLoad()
} }
...@@ -56,3 +61,6 @@ private external fun _nFillIntArrayOf5(interopPointer: InteropPointer) ...@@ -56,3 +61,6 @@ private external fun _nFillIntArrayOf5(interopPointer: InteropPointer)
@ExternalSymbolName("org_jetbrains_skiko_tests_TestHelpers__1nFillDoubleArrayOf5") @ExternalSymbolName("org_jetbrains_skiko_tests_TestHelpers__1nFillDoubleArrayOf5")
private external fun _nFillDoubleArrayOf5(interopPointer: InteropPointer) private external fun _nFillDoubleArrayOf5(interopPointer: InteropPointer)
@ExternalSymbolName("org_jetbrains_skiko_tests_TestHelpers__1nGetPointerFromByteBuffer")
private external fun _nGetPointerFromByteBuffer(buffer: ByteBuffer?): NativePointer
package org.jetbrains.skiko.tests package org.jetbrains.skiko.tests
import org.jetbrains.skia.impl.InteropScope
import org.jetbrains.skia.impl.NativePointer
expect annotation class IgnoreTestOnJvm() expect annotation class IgnoreTestOnJvm()
expect fun runTest(block: suspend () -> Unit) expect fun runTest(block: suspend () -> Unit)
expect fun InteropScope.allocateBytesForPixels(size: Int): NativePointer
...@@ -2,6 +2,8 @@ package org.jetbrains.skiko.tests ...@@ -2,6 +2,8 @@ package org.jetbrains.skiko.tests
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.promise import kotlinx.coroutines.promise
import org.jetbrains.skia.impl.InteropScope
import org.jetbrains.skia.impl.NativePointer
import org.jetbrains.skiko.wasm.await import org.jetbrains.skiko.wasm.await
import org.jetbrains.skiko.wasm.wasmSetup import org.jetbrains.skiko.wasm.wasmSetup
...@@ -12,3 +14,7 @@ actual fun runTest(block: suspend () -> Unit): dynamic = GlobalScope.promise { ...@@ -12,3 +14,7 @@ actual fun runTest(block: suspend () -> Unit): dynamic = GlobalScope.promise {
wasmSetup.await() wasmSetup.await()
block() block()
} }
actual fun InteropScope.allocateBytesForPixels(size: Int): NativePointer {
return toInterop(ByteArray(size))
}
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_SurfaceKt__1nMakeRasterDirect extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_SurfaceKt__1nMakeRasterDirect
(JNIEnv* env, jclass jclass, (JNIEnv* env, jclass jclass,
jint width, jint height, jint colorType, jint alphaType, jlong colorSpacePtr, jint width, jint height, jint colorType, jint alphaType, jlong colorSpacePtr,
jlong pixelsPtr, jlong rowBytes, jlong pixelsPtr, jint rowBytes,
jobject surfacePropsObj) jintArray surfacePropsInts)
{ {
SkColorSpace* colorSpace = reinterpret_cast<SkColorSpace*>(static_cast<uintptr_t>(colorSpacePtr)); SkColorSpace* colorSpace = reinterpret_cast<SkColorSpace*>(static_cast<uintptr_t>(colorSpacePtr));
SkImageInfo imageInfo = SkImageInfo::Make(width, SkImageInfo imageInfo = SkImageInfo::Make(width,
...@@ -16,7 +16,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_SurfaceKt__1nMakeRast ...@@ -16,7 +16,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_SurfaceKt__1nMakeRast
static_cast<SkColorType>(colorType), static_cast<SkColorType>(colorType),
static_cast<SkAlphaType>(alphaType), static_cast<SkAlphaType>(alphaType),
sk_ref_sp<SkColorSpace>(colorSpace)); sk_ref_sp<SkColorSpace>(colorSpace));
std::unique_ptr<SkSurfaceProps> surfaceProps = skija::SurfaceProps::toSkSurfaceProps(env, surfacePropsObj); std::unique_ptr<SkSurfaceProps> surfaceProps = skija::SurfaceProps::toSkSurfaceProps(env, surfacePropsInts);
sk_sp<SkSurface> instance = SkSurface::MakeRasterDirect( sk_sp<SkSurface> instance = SkSurface::MakeRasterDirect(
imageInfo, imageInfo,
...@@ -28,10 +28,10 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_SurfaceKt__1nMakeRast ...@@ -28,10 +28,10 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_SurfaceKt__1nMakeRast
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_SurfaceKt__1nMakeRasterDirectWithPixmap extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_SurfaceKt__1nMakeRasterDirectWithPixmap
(JNIEnv* env, jclass jclass, (JNIEnv* env, jclass jclass,
jlong pixmapPtr, jobject surfacePropsObj) jlong pixmapPtr, jintArray surfacePropsInts)
{ {
SkPixmap* pixmap = reinterpret_cast<SkPixmap*>(static_cast<uintptr_t>(pixmapPtr)); SkPixmap* pixmap = reinterpret_cast<SkPixmap*>(static_cast<uintptr_t>(pixmapPtr));
std::unique_ptr<SkSurfaceProps> surfaceProps = skija::SurfaceProps::toSkSurfaceProps(env, surfacePropsObj); std::unique_ptr<SkSurfaceProps> surfaceProps = skija::SurfaceProps::toSkSurfaceProps(env, surfacePropsInts);
sk_sp<SkSurface> instance = SkSurface::MakeRasterDirect(*pixmap, surfaceProps.get()); sk_sp<SkSurface> instance = SkSurface::MakeRasterDirect(*pixmap, surfaceProps.get());
return reinterpret_cast<jlong>(instance.release()); return reinterpret_cast<jlong>(instance.release());
...@@ -40,8 +40,8 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_SurfaceKt__1nMakeRast ...@@ -40,8 +40,8 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_SurfaceKt__1nMakeRast
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_SurfaceKt__1nMakeRaster extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_SurfaceKt__1nMakeRaster
(JNIEnv* env, jclass jclass, (JNIEnv* env, jclass jclass,
jint width, jint height, jint colorType, jint alphaType, jlong colorSpacePtr, jint width, jint height, jint colorType, jint alphaType, jlong colorSpacePtr,
jlong rowBytes, jint rowBytes,
jobject surfacePropsObj) jintArray surfacePropsInts)
{ {
SkColorSpace* colorSpace = reinterpret_cast<SkColorSpace*>(static_cast<uintptr_t>(colorSpacePtr)); SkColorSpace* colorSpace = reinterpret_cast<SkColorSpace*>(static_cast<uintptr_t>(colorSpacePtr));
SkImageInfo imageInfo = SkImageInfo::Make(width, SkImageInfo imageInfo = SkImageInfo::Make(width,
...@@ -49,7 +49,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_SurfaceKt__1nMakeRast ...@@ -49,7 +49,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_SurfaceKt__1nMakeRast
static_cast<SkColorType>(colorType), static_cast<SkColorType>(colorType),
static_cast<SkAlphaType>(alphaType), static_cast<SkAlphaType>(alphaType),
sk_ref_sp<SkColorSpace>(colorSpace)); sk_ref_sp<SkColorSpace>(colorSpace));
std::unique_ptr<SkSurfaceProps> surfaceProps = skija::SurfaceProps::toSkSurfaceProps(env, surfacePropsObj); std::unique_ptr<SkSurfaceProps> surfaceProps = skija::SurfaceProps::toSkSurfaceProps(env, surfacePropsInts);
sk_sp<SkSurface> instance = SkSurface::MakeRaster( sk_sp<SkSurface> instance = SkSurface::MakeRaster(
imageInfo, imageInfo,
......
...@@ -748,6 +748,17 @@ namespace skija { ...@@ -748,6 +748,17 @@ namespace skija {
std::unique_ptr<SkSurfaceProps>(nullptr); std::unique_ptr<SkSurfaceProps>(nullptr);
return std::make_unique<SkSurfaceProps>(flags, geom); return std::make_unique<SkSurfaceProps>(flags, geom);
} }
std::unique_ptr<SkSurfaceProps> toSkSurfaceProps(JNIEnv* env, jintArray surfacePropsInts) {
if (surfacePropsInts == nullptr) {
return std::unique_ptr<SkSurfaceProps>(nullptr);
}
jint *ints = env->GetIntArrayElements(surfacePropsInts, NULL);
uint32_t flags = ints[0];
SkPixelGeometry geom = static_cast<SkPixelGeometry>(ints[1]);
env->ReleaseIntArrayElements(surfacePropsInts, ints, 0);
return std::make_unique<SkSurfaceProps>(flags, geom);
}
} }
namespace impl { namespace impl {
......
...@@ -294,6 +294,7 @@ namespace skija { ...@@ -294,6 +294,7 @@ namespace skija {
extern jmethodID _getPixelGeometryOrdinal; extern jmethodID _getPixelGeometryOrdinal;
void onLoad(JNIEnv* env); void onLoad(JNIEnv* env);
std::unique_ptr<SkSurfaceProps> toSkSurfaceProps(JNIEnv* env, jobject surfacePropsObj); std::unique_ptr<SkSurfaceProps> toSkSurfaceProps(JNIEnv* env, jobject surfacePropsObj);
std::unique_ptr<SkSurfaceProps> toSkSurfaceProps(JNIEnv* env, jintArray surfacePropsInts);
} }
namespace SamplingMode { namespace SamplingMode {
......
...@@ -55,3 +55,9 @@ extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skiko_tests_TestHelpersKt__ ...@@ -55,3 +55,9 @@ extern "C" JNIEXPORT void JNICALL Java_org_jetbrains_skiko_tests_TestHelpersKt__
result_double[4] = 10000000.9991; result_double[4] = 10000000.9991;
env->ReleaseDoubleArrayElements(jdarray, result_double, 0); env->ReleaseDoubleArrayElements(jdarray, result_double, 0);
} }
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_tests_TestHelpersKt__1nGetPointerFromByteBuffer
(JNIEnv *env, jclass, jobject buffer) {
return reinterpret_cast<jlong>(env->GetDirectBufferAddress(buffer));
}
package org.jetbrains.skiko.tests package org.jetbrains.skiko.tests
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import org.jetbrains.skia.impl.InteropScope
import org.jetbrains.skia.impl.NativePointer
import java.nio.ByteBuffer
actual typealias IgnoreTestOnJvm = org.junit.Ignore actual typealias IgnoreTestOnJvm = org.junit.Ignore
actual fun runTest(block: suspend () -> Unit) { actual fun runTest(block: suspend () -> Unit) {
runBlocking { block() } runBlocking { block() }
} }
actual fun InteropScope.allocateBytesForPixels(size: Int): NativePointer {
return TestHelpers().getPointerFromByteBuffer(ByteBuffer.allocateDirect(size))
}
package org.jetbrains.skiko.tests package org.jetbrains.skiko.tests
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import org.jetbrains.skia.impl.InteropScope
import org.jetbrains.skia.impl.NativePointer
annotation class DoNothing annotation class DoNothing
actual typealias IgnoreTestOnJvm = DoNothing actual typealias IgnoreTestOnJvm = DoNothing
...@@ -8,3 +10,7 @@ actual typealias IgnoreTestOnJvm = DoNothing ...@@ -8,3 +10,7 @@ actual typealias IgnoreTestOnJvm = DoNothing
actual fun runTest(block: suspend () -> Unit) { actual fun runTest(block: suspend () -> Unit) {
runBlocking { block() } runBlocking { block() }
} }
actual fun InteropScope.allocateBytesForPixels(size: Int): NativePointer {
return toInterop(ByteArray(size))
}
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