Unverified Commit cf38e7e6 authored by Pavel's avatar Pavel Committed by GitHub

align `nMakeFromBackendRenderTarget` signature with kotlin counterpart (#630)

* align `nMakeFromBackendRenderTarget` signature with kotlin counterpart

* transfer `SurfaceProps` only via intArray

* rename `SurfacePropsObj` to `SurfacePropsInts`

* take `SurfaceProps` into account in `js/MakeFromBackendRenderTarget`
parent 75c33f3b
...@@ -354,7 +354,7 @@ extern "C" ...@@ -354,7 +354,7 @@ extern "C"
} }
JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_redrawer_Direct3DRedrawer_makeDirectXSurface( JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_redrawer_Direct3DRedrawer_makeDirectXSurface(
JNIEnv *env, jobject redrawer, jlong devicePtr, jlong contextPtr, jint width, jint height, jobject surfacePropsObj, jint index) JNIEnv *env, jobject redrawer, jlong devicePtr, jlong contextPtr, jint width, jint height, jintArray surfacePropsInts, jint index)
{ {
DirectXDevice *d3dDevice = fromJavaPointer<DirectXDevice *>(devicePtr); DirectXDevice *d3dDevice = fromJavaPointer<DirectXDevice *>(devicePtr);
GrDirectContext *context = fromJavaPointer<GrDirectContext *>(contextPtr); GrDirectContext *context = fromJavaPointer<GrDirectContext *>(contextPtr);
...@@ -369,7 +369,7 @@ extern "C" ...@@ -369,7 +369,7 @@ extern "C"
info.fResource = d3dDevice->buffers[index]; info.fResource = d3dDevice->buffers[index];
std::unique_ptr<SkSurfaceProps> surfaceProps = skija::SurfaceProps::toSkSurfaceProps(env, surfacePropsObj); std::unique_ptr<SkSurfaceProps> surfaceProps = skija::SurfaceProps::toSkSurfaceProps(env, surfacePropsInts);
GrBackendTexture backendTexture((int)d3dDevice->buffers[index]->GetDesc().Width, (int)d3dDevice->buffers[index]->GetDesc().Height, info); GrBackendTexture backendTexture((int)d3dDevice->buffers[index]->GetDesc().Width, (int)d3dDevice->buffers[index]->GetDesc().Height, info);
auto result = SkSurface::MakeFromBackendTexture( auto result = SkSurface::MakeFromBackendTexture(
context, backendTexture, kTopLeft_GrSurfaceOrigin, 0, context, backendTexture, kTopLeft_GrSurfaceOrigin, 0,
......
...@@ -6,7 +6,6 @@ class SurfaceProps constructor( ...@@ -6,7 +6,6 @@ class SurfaceProps constructor(
) { ) {
constructor(geo: PixelGeometry) : this(false, geo) constructor(geo: PixelGeometry) : this(false, geo)
// Used from JNI code.
private fun _getPixelGeometryOrdinal(): Int { private fun _getPixelGeometryOrdinal(): Int {
return pixelGeometry.ordinal return pixelGeometry.ordinal
} }
......
...@@ -68,13 +68,13 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_SurfaceKt__1nMakeRast ...@@ -68,13 +68,13 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_SurfaceKt__1nMakeRast
} }
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_SurfaceKt__1nMakeFromBackendRenderTarget extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_SurfaceKt__1nMakeFromBackendRenderTarget
(JNIEnv* env, jclass jclass, jlong pContext, jlong pBackendRenderTarget, jint surfaceOrigin, jint colorType, jlong colorSpacePtr, jobject surfacePropsObj) { (JNIEnv* env, jclass jclass, jlong pContext, jlong pBackendRenderTarget, jint surfaceOrigin, jint colorType, jlong colorSpacePtr, jintArray surfacePropsInts) {
GrDirectContext* context = reinterpret_cast<GrDirectContext*>(static_cast<uintptr_t>(pContext)); GrDirectContext* context = reinterpret_cast<GrDirectContext*>(static_cast<uintptr_t>(pContext));
GrBackendRenderTarget* backendRenderTarget = reinterpret_cast<GrBackendRenderTarget*>(static_cast<uintptr_t>(pBackendRenderTarget)); GrBackendRenderTarget* backendRenderTarget = reinterpret_cast<GrBackendRenderTarget*>(static_cast<uintptr_t>(pBackendRenderTarget));
GrSurfaceOrigin grSurfaceOrigin = static_cast<GrSurfaceOrigin>(surfaceOrigin); GrSurfaceOrigin grSurfaceOrigin = static_cast<GrSurfaceOrigin>(surfaceOrigin);
SkColorType skColorType = static_cast<SkColorType>(colorType); SkColorType skColorType = static_cast<SkColorType>(colorType);
sk_sp<SkColorSpace> colorSpace = sk_ref_sp<SkColorSpace>(reinterpret_cast<SkColorSpace*>(static_cast<uintptr_t>(colorSpacePtr))); sk_sp<SkColorSpace> colorSpace = sk_ref_sp<SkColorSpace>(reinterpret_cast<SkColorSpace*>(static_cast<uintptr_t>(colorSpacePtr)));
std::unique_ptr<SkSurfaceProps> surfaceProps = skija::SurfaceProps::toSkSurfaceProps(env, surfacePropsObj); std::unique_ptr<SkSurfaceProps> surfaceProps = skija::SurfaceProps::toSkSurfaceProps(env, surfacePropsInts);
sk_sp<SkSurface> surface = SkSurface::MakeFromBackendRenderTarget( sk_sp<SkSurface> surface = SkSurface::MakeFromBackendRenderTarget(
static_cast<GrRecordingContext*>(context), static_cast<GrRecordingContext*>(context),
...@@ -91,13 +91,13 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_SurfaceKt__1nMakeFrom ...@@ -91,13 +91,13 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_SurfaceKt__1nMakeFrom
#ifdef SK_METAL #ifdef SK_METAL
extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_SurfaceKt__1nMakeFromMTKView extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_SurfaceKt__1nMakeFromMTKView
(JNIEnv* env, jclass jclass, jlong contextPtr, jlong mtkViewPtr, jint surfaceOrigin, jint sampleCount, jint colorType, jlong colorSpacePtr, jobject surfacePropsObj) { (JNIEnv* env, jclass jclass, jlong contextPtr, jlong mtkViewPtr, jint surfaceOrigin, jint sampleCount, jint colorType, jlong colorSpacePtr, jintArray surfacePropsInts) {
GrDirectContext* context = reinterpret_cast<GrDirectContext*>(static_cast<uintptr_t>(contextPtr)); GrDirectContext* context = reinterpret_cast<GrDirectContext*>(static_cast<uintptr_t>(contextPtr));
GrMTLHandle* mtkView = reinterpret_cast<GrMTLHandle*>(static_cast<uintptr_t>(mtkViewPtr)); GrMTLHandle* mtkView = reinterpret_cast<GrMTLHandle*>(static_cast<uintptr_t>(mtkViewPtr));
GrSurfaceOrigin grSurfaceOrigin = static_cast<GrSurfaceOrigin>(surfaceOrigin); GrSurfaceOrigin grSurfaceOrigin = static_cast<GrSurfaceOrigin>(surfaceOrigin);
SkColorType skColorType = static_cast<SkColorType>(colorType); SkColorType skColorType = static_cast<SkColorType>(colorType);
sk_sp<SkColorSpace> colorSpace = sk_ref_sp<SkColorSpace>(reinterpret_cast<SkColorSpace*>(static_cast<uintptr_t>(colorSpacePtr))); sk_sp<SkColorSpace> colorSpace = sk_ref_sp<SkColorSpace>(reinterpret_cast<SkColorSpace*>(static_cast<uintptr_t>(colorSpacePtr)));
std::unique_ptr<SkSurfaceProps> surfaceProps = skija::SurfaceProps::toSkSurfaceProps(env, surfacePropsObj); std::unique_ptr<SkSurfaceProps> surfaceProps = skija::SurfaceProps::toSkSurfaceProps(env, surfacePropsInts);
sk_sp<SkSurface> surface = SkSurface::MakeFromMTKView( sk_sp<SkSurface> surface = SkSurface::MakeFromMTKView(
static_cast<GrRecordingContext*>(context), static_cast<GrRecordingContext*>(context),
...@@ -115,7 +115,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_SurfaceKt__1nMakeRend ...@@ -115,7 +115,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_SurfaceKt__1nMakeRend
(JNIEnv* env, jclass jclass, jlong contextPtr, jboolean budgeted, (JNIEnv* env, jclass jclass, jlong contextPtr, jboolean budgeted,
jint width, jint height, jint colorType, jint alphaType, jlong colorSpacePtr, jint width, jint height, jint colorType, jint alphaType, jlong colorSpacePtr,
jint sampleCount, jint surfaceOrigin, jint sampleCount, jint surfaceOrigin,
jobject surfacePropsObj, jintArray surfacePropsInts,
jboolean shouldCreateWithMips) jboolean shouldCreateWithMips)
{ {
GrDirectContext* context = reinterpret_cast<GrDirectContext*>(static_cast<uintptr_t>(contextPtr)); GrDirectContext* context = reinterpret_cast<GrDirectContext*>(static_cast<uintptr_t>(contextPtr));
...@@ -125,7 +125,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_SurfaceKt__1nMakeRend ...@@ -125,7 +125,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skia_SurfaceKt__1nMakeRend
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::MakeRenderTarget( sk_sp<SkSurface> instance = SkSurface::MakeRenderTarget(
context, budgeted ? SkBudgeted::kYes : SkBudgeted::kNo, context, budgeted ? SkBudgeted::kYes : SkBudgeted::kNo,
......
...@@ -861,27 +861,6 @@ namespace skija { ...@@ -861,27 +861,6 @@ namespace skija {
} }
namespace SurfaceProps { namespace SurfaceProps {
jmethodID _getFlags;
jmethodID _getPixelGeometryOrdinal;
void onLoad(JNIEnv* env) {
jclass cls = env->FindClass("org/jetbrains/skia/SurfaceProps");
_getFlags = env->GetMethodID(cls, "_getFlags", "()I");
_getPixelGeometryOrdinal = env->GetMethodID(cls, "_getPixelGeometryOrdinal", "()I");
}
std::unique_ptr<SkSurfaceProps> toSkSurfaceProps(JNIEnv* env, jobject surfacePropsObj) {
if (surfacePropsObj == nullptr)
return std::unique_ptr<SkSurfaceProps>(nullptr);
uint32_t flags = static_cast<uint32_t>(env->CallIntMethod(surfacePropsObj, _getFlags));
if (java::lang::Throwable::exceptionThrown(env))
std::unique_ptr<SkSurfaceProps>(nullptr);
SkPixelGeometry geom = static_cast<SkPixelGeometry>(env->CallIntMethod(surfacePropsObj, _getPixelGeometryOrdinal));
if (java::lang::Throwable::exceptionThrown(env))
std::unique_ptr<SkSurfaceProps>(nullptr);
return std::make_unique<SkSurfaceProps>(flags, geom);
}
std::unique_ptr<SkSurfaceProps> toSkSurfaceProps(JNIEnv* env, jintArray surfacePropsInts) { std::unique_ptr<SkSurfaceProps> toSkSurfaceProps(JNIEnv* env, jintArray surfacePropsInts) {
if (surfacePropsInts == nullptr) { if (surfacePropsInts == nullptr) {
return std::unique_ptr<SkSurfaceProps>(nullptr); return std::unique_ptr<SkSurfaceProps>(nullptr);
...@@ -932,7 +911,6 @@ namespace skija { ...@@ -932,7 +911,6 @@ namespace skija {
Rect::onLoad(env); Rect::onLoad(env);
RRect::onLoad(env); RRect::onLoad(env);
RSXform::onLoad(env); RSXform::onLoad(env);
SurfaceProps::onLoad(env);
impl::Native::onLoad(env); impl::Native::onLoad(env);
} }
......
...@@ -315,10 +315,6 @@ namespace skija { ...@@ -315,10 +315,6 @@ namespace skija {
} }
namespace SurfaceProps { namespace SurfaceProps {
extern jmethodID _getFlags;
extern jmethodID _getPixelGeometryOrdinal;
void onLoad(JNIEnv* env);
std::unique_ptr<SkSurfaceProps> toSkSurfaceProps(JNIEnv* env, jobject surfacePropsObj);
std::unique_ptr<SkSurfaceProps> toSkSurfaceProps(JNIEnv* env, jintArray surfacePropsInts); std::unique_ptr<SkSurfaceProps> toSkSurfaceProps(JNIEnv* env, jintArray surfacePropsInts);
} }
......
...@@ -75,14 +75,14 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_Surface__1nMakeRasterN32Premul ...@@ -75,14 +75,14 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_Surface__1nMakeRasterN32Premul
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Surface__1nMakeFromBackendRenderTarget SKIKO_EXPORT KNativePointer org_jetbrains_skia_Surface__1nMakeFromBackendRenderTarget
(KNativePointer pContext, KNativePointer pBackendRenderTarget, KInt surfaceOrigin, KInt colorType, KNativePointer colorSpacePtr, KInteropPointer surfacePropsObj) { (KNativePointer pContext, KNativePointer pBackendRenderTarget, KInt surfaceOrigin, KInt colorType, KNativePointer colorSpacePtr, KInteropPointer surfacePropsInts) {
GrDirectContext* context = reinterpret_cast<GrDirectContext*>((pContext)); GrDirectContext* context = reinterpret_cast<GrDirectContext*>((pContext));
GrBackendRenderTarget* backendRenderTarget = reinterpret_cast<GrBackendRenderTarget*>((pBackendRenderTarget)); GrBackendRenderTarget* backendRenderTarget = reinterpret_cast<GrBackendRenderTarget*>((pBackendRenderTarget));
GrSurfaceOrigin grSurfaceOrigin = static_cast<GrSurfaceOrigin>(surfaceOrigin); GrSurfaceOrigin grSurfaceOrigin = static_cast<GrSurfaceOrigin>(surfaceOrigin);
SkColorType skColorType = static_cast<SkColorType>(colorType); SkColorType skColorType = static_cast<SkColorType>(colorType);
sk_sp<SkColorSpace> colorSpace = sk_ref_sp<SkColorSpace>(reinterpret_cast<SkColorSpace*>((colorSpacePtr))); sk_sp<SkColorSpace> colorSpace = sk_ref_sp<SkColorSpace>(reinterpret_cast<SkColorSpace*>((colorSpacePtr)));
// std::unique_ptr<SkSurfaceProps> surfaceProps = skija::SurfaceProps::toSkSurfaceProps(surfacePropsObj); std::unique_ptr<SkSurfaceProps> surfaceProps = skija::SurfaceProps::toSkSurfaceProps(surfacePropsInts);
sk_sp<SkSurface> surface = SkSurface::MakeFromBackendRenderTarget( sk_sp<SkSurface> surface = SkSurface::MakeFromBackendRenderTarget(
static_cast<GrRecordingContext*>(context), static_cast<GrRecordingContext*>(context),
...@@ -90,9 +90,7 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_Surface__1nMakeFromBackendRenderT ...@@ -90,9 +90,7 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_Surface__1nMakeFromBackendRenderT
grSurfaceOrigin, grSurfaceOrigin,
skColorType, skColorType,
colorSpace, colorSpace,
// "TODO: we silently ignore the surfacePropsObj arg for now. surfaceProps.get(),
// surfaceProps,
nullptr,
/* RenderTargetReleaseProc */ nullptr, /* RenderTargetReleaseProc */ nullptr,
/* ReleaseContext */ nullptr /* ReleaseContext */ nullptr
); );
...@@ -100,14 +98,14 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_Surface__1nMakeFromBackendRenderT ...@@ -100,14 +98,14 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_Surface__1nMakeFromBackendRenderT
} }
SKIKO_EXPORT KNativePointer org_jetbrains_skia_Surface__1nMakeFromMTKView SKIKO_EXPORT KNativePointer org_jetbrains_skia_Surface__1nMakeFromMTKView
(KNativePointer contextPtr, KNativePointer mtkViewPtr, KInt surfaceOrigin, KInt sampleCount, KInt colorType, KNativePointer colorSpacePtr, KInteropPointer surfacePropsObj) { (KNativePointer contextPtr, KNativePointer mtkViewPtr, KInt surfaceOrigin, KInt sampleCount, KInt colorType, KNativePointer colorSpacePtr, KInteropPointer surfacePropsInts) {
#ifdef SK_METAL #ifdef SK_METAL
GrDirectContext* context = reinterpret_cast<GrDirectContext*>((contextPtr)); GrDirectContext* context = reinterpret_cast<GrDirectContext*>((contextPtr));
GrMTLHandle* mtkView = reinterpret_cast<GrMTLHandle*>((mtkViewPtr)); GrMTLHandle* mtkView = reinterpret_cast<GrMTLHandle*>((mtkViewPtr));
GrSurfaceOrigin grSurfaceOrigin = static_cast<GrSurfaceOrigin>(surfaceOrigin); GrSurfaceOrigin grSurfaceOrigin = static_cast<GrSurfaceOrigin>(surfaceOrigin);
SkColorType skColorType = static_cast<SkColorType>(colorType); SkColorType skColorType = static_cast<SkColorType>(colorType);
sk_sp<SkColorSpace> colorSpace = sk_ref_sp<SkColorSpace>(reinterpret_cast<SkColorSpace*>((colorSpacePtr))); sk_sp<SkColorSpace> colorSpace = sk_ref_sp<SkColorSpace>(reinterpret_cast<SkColorSpace*>((colorSpacePtr)));
std::unique_ptr<SkSurfaceProps> surfaceProps = skija::SurfaceProps::toSkSurfaceProps(surfacePropsObj); std::unique_ptr<SkSurfaceProps> surfaceProps = skija::SurfaceProps::toSkSurfaceProps(surfacePropsInts);
sk_sp<SkSurface> surface = SkSurface::MakeFromMTKView( sk_sp<SkSurface> surface = SkSurface::MakeFromMTKView(
static_cast<GrRecordingContext*>(context), static_cast<GrRecordingContext*>(context),
...@@ -127,7 +125,7 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_Surface__1nMakeRenderTarget ...@@ -127,7 +125,7 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_Surface__1nMakeRenderTarget
(KNativePointer contextPtr, KBoolean budgeted, (KNativePointer contextPtr, KBoolean budgeted,
KInt width, KInt height, KInt colorType, KInt alphaType, KNativePointer colorSpacePtr, KInt width, KInt height, KInt colorType, KInt alphaType, KNativePointer colorSpacePtr,
KInt sampleCount, KInt surfaceOrigin, KInt sampleCount, KInt surfaceOrigin,
KInteropPointer surfacePropsObj, KInteropPointer surfacePropsInts,
KBoolean shouldCreateWithMips) KBoolean shouldCreateWithMips)
{ {
GrDirectContext* context = reinterpret_cast<GrDirectContext*>((contextPtr)); GrDirectContext* context = reinterpret_cast<GrDirectContext*>((contextPtr));
...@@ -137,7 +135,7 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_Surface__1nMakeRenderTarget ...@@ -137,7 +135,7 @@ SKIKO_EXPORT KNativePointer org_jetbrains_skia_Surface__1nMakeRenderTarget
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(surfacePropsObj); std::unique_ptr<SkSurfaceProps> surfaceProps = skija::SurfaceProps::toSkSurfaceProps(surfacePropsInts);
sk_sp<SkSurface> instance = SkSurface::MakeRenderTarget( sk_sp<SkSurface> instance = SkSurface::MakeRenderTarget(
context, budgeted ? SkBudgeted::kYes : SkBudgeted::kNo, context, budgeted ? SkBudgeted::kYes : SkBudgeted::kNo,
......
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