Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Unified Diff: tools/viewer/sk_app/android/Window_android.cpp

Issue 1952323004: Initial commit of our new Android app to demo Skia. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Merge Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/viewer/sk_app/android/Window_android.h ('k') | tools/viewer/sk_app/android/surface_glue_android.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/viewer/sk_app/android/Window_android.cpp
diff --git a/tools/viewer/sk_app/android/Window_android.cpp b/tools/viewer/sk_app/android/Window_android.cpp
index 9def29fbf4c31fd1e0a82bb88029b42fd4493f8e..09e7ef14a7864f3169968f272680a0d01bea0da2 100644
--- a/tools/viewer/sk_app/android/Window_android.cpp
+++ b/tools/viewer/sk_app/android/Window_android.cpp
@@ -13,22 +13,17 @@ namespace sk_app {
Window* Window::CreateNativeWindow(void* platformData) {
Window_android* window = new Window_android();
- if (!window->init((android_app*)platformData)) {
+ if (!window->init((SkiaAndroidApp*)platformData)) {
delete window;
return nullptr;
}
return window;
}
-static void handle_cmd(struct android_app* app, int32_t cmd);
-static int32_t handle_input(struct android_app* app, AInputEvent* event);
-
-bool Window_android::init(android_app* app) {
- SkASSERT(app);
- mApp = app;
- mApp->userData = this;
- mApp->onAppCmd = handle_cmd;
- mApp->onInputEvent = handle_input;
+bool Window_android::init(SkiaAndroidApp* skiaAndroidApp) {
+ SkASSERT(skiaAndroidApp);
+ fSkiaAndroidApp = skiaAndroidApp;
+ fSkiaAndroidApp->fWindow = this;
return true;
}
@@ -53,131 +48,15 @@ void Window_android::initDisplay(ANativeWindow* window) {
SkASSERT(window);
ContextPlatformData_android platformData;
platformData.fNativeWindow = window;
- fWindowContext = VulkanWindowContext::Create((void*)&platformData, mSampleCount, fSRGB);
-}
-
-static void android_app_write_cmd(struct android_app* android_app, int8_t cmd) {
- if (write(android_app->msgwrite, &cmd, sizeof(cmd)) != sizeof(cmd)) {
- SkDebugf("Failure writing android_app cmd: %s\n", strerror(errno));
- }
+ fWindowContext = VulkanWindowContext::Create((void*)&platformData, fDisplayParams);
+ fNativeWindowInitialized = true;
}
-void Window_android::inval() {
- android_app_write_cmd(mApp, APP_CMD_INVAL_WINDOW);
-}
-
-void Window_android::paintIfNeeded() {
- if (mApp->window || !mContentRect.isEmpty()) {
- this->onPaint();
- }
-}
-
-/**
- * Process the next main command.
- */
-static void handle_cmd(struct android_app* app, int32_t cmd) {
- Window_android* window = (Window_android*)app->userData;
- switch (cmd) {
- case APP_CMD_INIT_WINDOW:
- // The window is being shown, get it ready.
- SkASSERT(app->window);
- window->initDisplay(app->window);
- window->paintIfNeeded();
- break;
- case APP_CMD_WINDOW_RESIZED: {
- int width = ANativeWindow_getWidth(app->window);
- int height = ANativeWindow_getHeight(app->window);
- window->onResize(width, height);
- break;
- }
- case APP_CMD_CONTENT_RECT_CHANGED:
- window->setContentRect(app->contentRect.left, app->contentRect.top,
- app->contentRect.right, app->contentRect.bottom);
- window->paintIfNeeded();
- break;
- case APP_CMD_TERM_WINDOW:
- // The window is being hidden or closed, clean it up.
- window->detach();
- break;
- case APP_CMD_INVAL_WINDOW:
- window->paintIfNeeded();
- break;
- }
-}
-
-static Window::Key get_key(int32_t keycode) {
- static const struct {
- int32_t fAndroidKey;
- Window::Key fWindowKey;
- } gPair[] = {
- { AKEYCODE_BACK, Window::kBack_Key },
- { AKEYCODE_VOLUME_UP, Window::kLeft_Key },
- { AKEYCODE_VOLUME_DOWN, Window::kRight_Key }
- };
- for (size_t i = 0; i < SK_ARRAY_COUNT(gPair); i++) {
- if (gPair[i].fAndroidKey == keycode) {
- return gPair[i].fWindowKey;
- }
- }
- return Window::kNONE_Key;
+void Window_android::onDisplayDestroyed() {
+ fNativeWindowInitialized = false;
+ detach();
}
-static Window::InputState get_action(int32_t action) {
- static const struct {
- int32_t fAndroidAction;
- Window::InputState fInputState;
- } gPair[] = {
- { AKEY_STATE_DOWN, Window::kDown_InputState },
- { AKEY_STATE_UP, Window::kUp_InputState },
- };
- for (size_t i = 0; i < SK_ARRAY_COUNT(gPair); i++) {
- if (gPair[i].fAndroidAction == action) {
- return gPair[i].fInputState;
- }
- }
- return Window::kMove_InputState;
-}
-
-static int32_t get_key_modifiers(AInputEvent* event) {
- static const struct {
- int32_t fAndroidState;
- int32_t fWindowModifier;
- } gPair[] = {
- { AMETA_SHIFT_ON, Window::kShift_ModifierKey },
- { AMETA_CTRL_ON, Window::kControl_ModifierKey },
- };
-
- int32_t metaState = AKeyEvent_getMetaState(event);
- int32_t modifiers = 0;
-
- if (AKeyEvent_getRepeatCount(event) == 0) {
- modifiers |= Window::kFirstPress_ModifierKey;
- }
-
- for (size_t i = 0; i < SK_ARRAY_COUNT(gPair); i++) {
- if (gPair[i].fAndroidState == metaState) {
- modifiers |= gPair[i].fWindowModifier;
- }
- }
- return modifiers;
-}
-
-/**
- * Process the next input event.
- */
-static int32_t handle_input(struct android_app* app, AInputEvent* event) {
- Window_android* window = (Window_android*)app->userData;
- switch(AInputEvent_getType(event)) {
- case AINPUT_EVENT_TYPE_MOTION:
- break;
- case AINPUT_EVENT_TYPE_KEY:
- Window::Key key = get_key(AKeyEvent_getKeyCode(event));
- Window::InputState state = get_action(AKeyEvent_getAction(event));
- int32_t mod = get_key_modifiers(event);
- window->onKey(key, state, mod);
- return true; // eat all key events
- }
- return 0;
-}
+void Window_android::inval() { fSkiaAndroidApp->postMessage(Message(kContentInvalidated)); }
} // namespace sk_app
« no previous file with comments | « tools/viewer/sk_app/android/Window_android.h ('k') | tools/viewer/sk_app/android/surface_glue_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698