9#include <android/bitmap.h>
10#include <android/log.h>
19 , fWindowContext(
std::move(wctx))
24 fSurface = fWindowContext->getBackbufferSurface();
28 fWindowContext.reset();
29 ANativeWindow_release(fWindow);
41 fWindowContext->swapBuffers();
42 fSurface = fWindowContext->getBackbufferSurface();
51 fWidth = ANativeWindow_getWidth(
window);
52 fHeight = ANativeWindow_getHeight(
window);
56 message.fWindowSurface = &fWindowSurface;
62 message.fWindowSurface = &fWindowSurface;
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);
192 auto winctx = skwindow::MakeGLForAndroid(win,
params);
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
SkCanvas * getCanvas() override
void release(JNIEnv *env) override
void flushAndSubmit() override
ThreadedSurface(JNIEnv *env, jobject surface)
void release(JNIEnv *env) override
void flushAndSubmit() override
WindowSurface(ANativeWindow *win, std::unique_ptr< skwindow::WindowContext > wctx)
SkCanvas * getCanvas() override
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)
SK_API void FlushAndSubmit(sk_sp< SkSurface >)
std::unique_ptr< WindowContext > MakeVulkanForAndroid(ANativeWindow *window, const DisplayParams ¶ms)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
struct ANativeWindow ANativeWindow