2016-05-09 15:49:29 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef surface_glue_android_DEFINED
|
|
|
|
#define surface_glue_android_DEFINED
|
|
|
|
|
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
#include <android/native_window_jni.h>
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkString.h"
|
2016-05-27 15:52:52 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/sk_app/Application.h"
|
|
|
|
#include "tools/sk_app/Window.h"
|
2016-05-09 15:49:29 +00:00
|
|
|
|
|
|
|
namespace sk_app {
|
|
|
|
|
|
|
|
enum MessageType {
|
|
|
|
kUndefined,
|
|
|
|
kSurfaceCreated,
|
|
|
|
kSurfaceChanged,
|
|
|
|
kSurfaceDestroyed,
|
|
|
|
kDestroyApp,
|
2016-05-12 16:17:04 +00:00
|
|
|
kContentInvalidated,
|
2016-05-17 19:44:20 +00:00
|
|
|
kKeyPressed,
|
2016-05-27 15:52:52 +00:00
|
|
|
kTouched,
|
|
|
|
kUIStateChanged,
|
2016-05-09 15:49:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Message {
|
|
|
|
MessageType fType = kUndefined;
|
|
|
|
ANativeWindow* fNativeWindow = nullptr;
|
2016-05-17 19:44:20 +00:00
|
|
|
int fKeycode = 0;
|
|
|
|
int fTouchOwner, fTouchState;
|
|
|
|
float fTouchX, fTouchY;
|
2016-05-09 15:49:29 +00:00
|
|
|
|
2016-05-27 15:52:52 +00:00
|
|
|
SkString* stateName;
|
|
|
|
SkString* stateValue;
|
|
|
|
|
2016-05-09 15:49:29 +00:00
|
|
|
Message() {}
|
|
|
|
Message(MessageType t) : fType(t) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SkiaAndroidApp {
|
|
|
|
Application* fApp;
|
|
|
|
Window* fWindow;
|
2016-05-13 16:57:44 +00:00
|
|
|
jobject fAndroidApp;
|
2016-05-09 15:49:29 +00:00
|
|
|
|
2016-05-13 16:57:44 +00:00
|
|
|
SkiaAndroidApp(JNIEnv* env, jobject androidApp);
|
|
|
|
|
|
|
|
void postMessage(const Message& message) const;
|
|
|
|
void readMessage(Message* message) const;
|
2016-05-09 15:49:29 +00:00
|
|
|
|
2016-05-27 15:52:52 +00:00
|
|
|
// These must be called in SkiaAndroidApp's own pthread because the JNIEnv is thread sensitive
|
2016-05-13 16:57:44 +00:00
|
|
|
void setTitle(const char* title) const;
|
2017-11-21 18:18:02 +00:00
|
|
|
void setUIState(const char* state) const;
|
2016-05-17 19:44:20 +00:00
|
|
|
|
2016-05-09 15:49:29 +00:00
|
|
|
private:
|
|
|
|
pthread_t fThread;
|
2016-05-13 16:57:44 +00:00
|
|
|
ANativeWindow* fNativeWindow;
|
|
|
|
int fPipes[2]; // 0 is the read message pipe, 1 is the write message pipe
|
|
|
|
JavaVM* fJavaVM;
|
|
|
|
JNIEnv* fPThreadEnv;
|
2016-05-27 15:52:52 +00:00
|
|
|
jmethodID fSetTitleMethodID, fSetStateMethodID;
|
2016-05-13 16:57:44 +00:00
|
|
|
|
|
|
|
// This must be called in SkiaAndroidApp's own pthread because the JNIEnv is thread sensitive
|
|
|
|
~SkiaAndroidApp();
|
|
|
|
|
|
|
|
static int message_callback(int fd, int events, void* data);
|
|
|
|
static void* pthread_main(void*);
|
2016-05-09 15:49:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace sk_app
|
|
|
|
|
|
|
|
#endif
|