Chromium Code Reviews| 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 94be02c9336acc1493834c06918dad40ada2bfa7..9572e867c74e8b6b64f4e31b003f3c5f0f9207c9 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) { |
|
djsollen
2016/05/09 13:17:14
can you make this part of the window's constructor
liyuqian
2016/05/09 14:27:27
I can't (and I believe that you couldn't either so
|
| + SkASSERT(skiaAndroidApp); |
| + fSkiaAndroidApp = skiaAndroidApp; |
| + fSkiaAndroidApp->fWindow = this; |
| return true; |
| } |
| @@ -54,130 +49,20 @@ void Window_android::initDisplay(ANativeWindow* window) { |
| ContextPlatformData_android platformData; |
| platformData.fNativeWindow = window; |
| fWindowContext = VulkanWindowContext::Create((void*)&platformData, mSampleCount); |
| + fNativeWindowInitialized = true; |
| } |
| -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)); |
| - } |
| +void Window_android::onDisplayDestroyed() { |
| + fNativeWindowInitialized = false; |
| + detach(); |
| } |
| -void Window_android::inval() { |
| - android_app_write_cmd(mApp, APP_CMD_INVAL_WINDOW); |
| -} |
| +void Window_android::inval() { paintIfNeeded(); } |
|
djsollen
2016/05/09 13:17:14
you need to post a message here to return control
liyuqian
2016/05/09 14:27:27
Done.
|
| void Window_android::paintIfNeeded() { |
| - if (mApp->window || !mContentRect.isEmpty()) { |
| + if (fNativeWindowInitialized) { |
| 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; |
| -} |
| - |
| -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; |
| -} |
| - |
| } // namespace sk_app |