9#include <android/bitmap.h>
10#include <android/log.h>
19 , fWindowContext(
std::move(wctx))
24 fSurface = fWindowContext->getBackbufferSurface();
27void WindowSurface::release(JNIEnv*
env) {
28 fWindowContext.reset();
29 ANativeWindow_release(fWindow);
32SkCanvas* WindowSurface::getCanvas() {
39void WindowSurface::flushAndSubmit() {
41 fWindowContext->swapBuffers();
42 fSurface = fWindowContext->getBackbufferSurface();
51 fWidth = ANativeWindow_getWidth(
window);
52 fHeight = ANativeWindow_getHeight(
window);
56 message.fWindowSurface = &fWindowSurface;
60void ThreadedSurface::release(JNIEnv*
env) {
62 message.fWindowSurface = &fWindowSurface;
67SkCanvas* ThreadedSurface::getCanvas() {
72void ThreadedSurface::flushAndSubmit() {
74 message.fWindowSurface = &fWindowSurface;
81class BitmapSurface final :
public Surface {
83 BitmapSurface(JNIEnv*
env, jobject
bitmap) {
84 AndroidBitmapInfo bm_info;
85 if (AndroidBitmap_getInfo(
env,
bitmap, &bm_info) != ANDROID_BITMAP_RESULT_SUCCESS) {
93 if (AndroidBitmap_lockPixels(
env,
bitmap, &pixels) != ANDROID_BITMAP_RESULT_SUCCESS) {
109 AndroidBitmap_unlockPixels(
env, fBitmap);
111 env->DeleteGlobalRef(fBitmap);
117 return fSurface->getCanvas();
140 switch ((
flags >> ANDROID_BITMAP_FLAGS_ALPHA_SHIFT) & ANDROID_BITMAP_FLAGS_ALPHA_MASK) {
155static jlong Surface_CreateBitmap(JNIEnv*
env, jobject, jobject
bitmap) {
156 return reinterpret_cast<jlong
>(
new BitmapSurface(
env,
bitmap));
159static jlong Surface_CreateThreadedSurface(JNIEnv*
env, jobject, jobject
surface) {
163static jlong Surface_CreateVK(JNIEnv*
env, jobject, jobject jsurface) {
165 auto* win = ANativeWindow_fromSurface(
env, jsurface);
177 return reinterpret_cast<jlong
>(sk_make_sp<WindowSurface>(win, std::move(winctx)).release());
183static jlong Surface_CreateGL(JNIEnv*
env, jobject, jobject jsurface) {
185 auto* win = ANativeWindow_fromSurface(
env, jsurface);
197 return reinterpret_cast<jlong
>(sk_make_sp<WindowSurface>(win, std::move(winctx)).release());
203static void Surface_Release(JNIEnv*
env, jobject, jlong native_surface) {
210static jlong Surface_GetNativeCanvas(JNIEnv*
env, jobject, jlong native_surface) {
213 ?
reinterpret_cast<jlong
>(
surface->getCanvas())
217static void Surface_FlushAndSubmit(JNIEnv*
env, jobject, jlong native_surface) {
223static jint Surface_GetWidth(JNIEnv*
env, jobject, jlong native_surface) {
228static jint Surface_GetHeight(JNIEnv*
env, jobject, jlong native_surface) {
233static jlong Surface_MakeSnapshot(JNIEnv*
env, jobject, jlong native_surface) {
234 if (
const auto*
surface =
reinterpret_cast<Surface*
>(native_surface)) {
235 auto snapshot =
surface->makeImageSnapshot();
236 return reinterpret_cast<jlong
>(snapshot.release());
247 static const JNINativeMethod methods[] = {
248 {
"nCreateBitmap" ,
"(Landroid/graphics/Bitmap;)J",
249 reinterpret_cast<void*
>(Surface_CreateBitmap) },
250 {
"nCreateThreadedSurface" ,
"(Landroid/view/Surface;)J",
251 reinterpret_cast<void*
>(Surface_CreateThreadedSurface) },
252 {
"nCreateVKSurface" ,
"(Landroid/view/Surface;)J",
253 reinterpret_cast<void*
>(Surface_CreateVK) },
254 {
"nCreateGLSurface" ,
"(Landroid/view/Surface;)J",
255 reinterpret_cast<void*
>(Surface_CreateGL) },
256 {
"nRelease" ,
"(J)V",
reinterpret_cast<void*
>(Surface_Release) },
257 {
"nGetNativeCanvas" ,
"(J)J",
reinterpret_cast<void*
>(Surface_GetNativeCanvas)},
258 {
"nFlushAndSubmit" ,
"(J)V",
reinterpret_cast<void*
>(Surface_FlushAndSubmit) },
259 {
"nGetWidth" ,
"(J)I",
reinterpret_cast<void*
>(Surface_GetWidth) },
260 {
"nGetHeight" ,
"(J)I",
reinterpret_cast<void*
>(Surface_GetHeight) },
261 {
"nMakeImageSnapshot",
"(J)J",
reinterpret_cast<void*
>(Surface_MakeSnapshot) },
264 const auto clazz =
env->FindClass(
"org/skia/jetski/Surface");
266 ?
env->RegisterNatives(clazz, methods,
std::size(methods))
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
@ kUnknown_SkAlphaType
uninitialized
@ kOpaque_SkAlphaType
pixel is opaque
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
@ kARGB_4444_SkColorType
pixel with 4 bits for alpha, red, green, blue; in 16-bit word
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
@ kUnknown_SkColorType
uninitialized
static void SkSafeUnref(T *obj)
int register_jetski_Surface(JNIEnv *env)
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
sk_sp< SkPicture > finishRecordingAsPicture()
virtual SkCanvas * getCanvas()=0
virtual void release(JNIEnv *)=0
sk_sp< SkSurface > fSurface
virtual void flushAndSubmit()=0
ThreadedSurface(JNIEnv *env, jobject surface)
WindowSurface(ANativeWindow *win, std::unique_ptr< skwindow::WindowContext > wctx)
const EmbeddedViewParams * params
FlutterSemanticsFlag flags
uint32_t uint32_t * format
SK_API sk_sp< SkSurface > WrapPixels(const SkImageInfo &imageInfo, void *pixels, size_t rowBytes, const SkSurfaceProps *surfaceProps=nullptr)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
SK_API void FlushAndSubmit(sk_sp< SkSurface >)
std::unique_ptr< WindowContext > MakeGLForAndroid(ANativeWindow *window, const DisplayParams ¶ms)
std::unique_ptr< WindowContext > MakeVulkanForAndroid(ANativeWindow *window, const DisplayParams ¶ms)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
struct ANativeWindow ANativeWindow