[androidkit] support GL surfaces in AndroidKit

Currently backed by sk_app, we need to move the Android window context files out of sk_app into its own module.

Vulkan is only supported by Android devices running SDK 24+, added guards to Create_VK and annotations for developers.

Change-Id: Ica64a1feef4a3daf50758df05df488da0346ed72
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/401796
Commit-Queue: Jorge Betancourt <jmbetancourt@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
This commit is contained in:
Jorge Betancourt 2021-04-27 13:59:51 -04:00 committed by Skia Commit-Bot
parent 47c88cc9d6
commit 972abe9baa
3 changed files with 37 additions and 2 deletions

View File

@ -171,7 +171,7 @@ private:
SurfaceThread fThread;
};
// JNI methods
// *** JNI methods ***
static jlong Surface_CreateBitmap(JNIEnv* env, jobject, jobject bitmap) {
return reinterpret_cast<jlong>(new BitmapSurface(env, bitmap));
@ -182,6 +182,7 @@ static jlong Surface_CreateThreadedSurface(JNIEnv* env, jobject, jobject surface
}
static jlong Surface_CreateVK(JNIEnv* env, jobject, jobject jsurface) {
#ifdef SK_VULKAN
auto* win = ANativeWindow_fromSurface(env, jsurface);
if (!win) {
return 0;
@ -195,6 +196,27 @@ static jlong Surface_CreateVK(JNIEnv* env, jobject, jobject jsurface) {
}
return reinterpret_cast<jlong>(sk_make_sp<WindowSurface>(win, std::move(winctx)).release());
#endif // SK_VULKAN
return 0;
}
static jlong Surface_CreateGL(JNIEnv* env, jobject, jobject jsurface) {
#ifdef SK_GL
auto* win = ANativeWindow_fromSurface(env, jsurface);
if (!win) {
return 0;
}
// TODO: match window params?
sk_app::DisplayParams params;
auto winctx = sk_app::window_context_factory::MakeGLForAndroid(win, params);
if (!winctx) {
return 0;
}
return reinterpret_cast<jlong>(sk_make_sp<WindowSurface>(win, std::move(winctx)).release());
#endif // SK_GL
return 0;
}
static void Surface_Release(JNIEnv* env, jobject, jlong native_surface) {
@ -227,6 +249,8 @@ static int Surface_GetHeight(JNIEnv* env, jobject, jlong native_surface) {
return surface ? surface->height() : 0;
}
// *** End of JNI methods ***
} // namespace
int register_androidkit_Surface(JNIEnv* env) {
@ -237,6 +261,8 @@ int register_androidkit_Surface(JNIEnv* env) {
reinterpret_cast<void*>(Surface_CreateThreadedSurface) },
{"nCreateVKSurface", "(Landroid/view/Surface;)J",
reinterpret_cast<void*>(Surface_CreateVK) },
{"nCreateGLSurface", "(Landroid/view/Surface;)J",
reinterpret_cast<void*>(Surface_CreateGL) },
{"nRelease" , "(J)V", reinterpret_cast<void*>(Surface_Release) },
{"nGetNativeCanvas", "(J)J", reinterpret_cast<void*>(Surface_GetNativeCanvas)},
{"nFlushAndSubmit" , "(J)V", reinterpret_cast<void*>(Surface_FlushAndSubmit) },

View File

@ -8,6 +8,9 @@
package org.skia.androidkit;
import android.graphics.Bitmap;
import android.os.Build;
import android.support.annotation.RequiresApi;
import org.skia.androidkit.Canvas;
public class Surface {
@ -22,10 +25,15 @@ public class Surface {
this(CreateBitmapInstance(bitmap));
}
@RequiresApi(Build.VERSION_CODES.N)
static public Surface CreateVulkan(android.view.Surface surface) {
return new Surface(nCreateVKSurface(surface));
}
static public Surface CreateGL(android.view.Surface surface) {
return new Surface(nCreateGLSurface(surface));
}
/**
* Create a Surface backed by the provided Android Surface (android.view.Surface).
* AndroidKit handles thread management. Assumes OpenGL backend.
@ -89,6 +97,7 @@ public class Surface {
private static native long nCreateBitmap(Bitmap bitmap);
private static native long nCreateThreadedSurface(android.view.Surface surface);
private static native long nCreateVKSurface(android.view.Surface surface);
private static native long nCreateGLSurface(android.view.Surface surface);
private static native void nRelease(long nativeInstance);
private static native long nGetNativeCanvas(long nativeInstance);

View File

@ -80,7 +80,7 @@ class RuntimeShaderRenderThread extends Thread {
long time_base = java.lang.System.currentTimeMillis();
Surface surface = Surface.CreateVulkan(mAndroidSurface);
Surface surface = Surface.CreateGL(mAndroidSurface);
while (mRunning) {
renderFrame(surface.getCanvas(),