• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7 
8 #include "tools/sk_app/WindowContext.h"
9 #include "tools/sk_app/android/WindowContextFactory_android.h"
10 #include "tools/sk_app/android/Window_android.h"
11 
12 namespace sk_app {
13 
CreateNativeWindow(void * platformData)14 Window* Window::CreateNativeWindow(void* platformData) {
15     Window_android* window = new Window_android();
16     if (!window->init((SkiaAndroidApp*)platformData)) {
17         delete window;
18         return nullptr;
19     }
20     return window;
21 }
22 
init(SkiaAndroidApp * skiaAndroidApp)23 bool Window_android::init(SkiaAndroidApp* skiaAndroidApp) {
24     SkASSERT(skiaAndroidApp);
25     fSkiaAndroidApp = skiaAndroidApp;
26     fSkiaAndroidApp->fWindow = this;
27     return true;
28 }
29 
setTitle(const char * title)30 void Window_android::setTitle(const char* title) {
31     fSkiaAndroidApp->setTitle(title);
32 }
33 
setUIState(const char * state)34 void Window_android::setUIState(const char* state) {
35     fSkiaAndroidApp->setUIState(state);
36 }
37 
attach(BackendType attachType)38 bool Window_android::attach(BackendType attachType) {
39     fBackendType = attachType;
40 
41     // We delay the creation of fWindowContext until Android informs us that
42     // the native window is ready to use.
43     // The creation will be done in initDisplay, which is initiated by kSurfaceCreated event.
44     return true;
45 }
46 
initDisplay(ANativeWindow * window)47 void Window_android::initDisplay(ANativeWindow* window) {
48     SkASSERT(window);
49     switch (fBackendType) {
50 #ifdef SK_GL
51         case kNativeGL_BackendType:
52         default:
53             fWindowContext =
54                     window_context_factory::MakeGLForAndroid(window, fRequestedDisplayParams);
55             break;
56 #else
57         default:
58 #endif
59         case kRaster_BackendType:
60             fWindowContext =
61                     window_context_factory::MakeRasterForAndroid(window, fRequestedDisplayParams);
62             break;
63 #ifdef SK_VULKAN
64         case kVulkan_BackendType:
65             fWindowContext =
66                     window_context_factory::MakeVulkanForAndroid(window, fRequestedDisplayParams);
67             break;
68 #endif
69     }
70     this->onBackendCreated();
71 }
72 
onDisplayDestroyed()73 void Window_android::onDisplayDestroyed() {
74     detach();
75 }
76 
onInval()77 void Window_android::onInval() {
78     fSkiaAndroidApp->postMessage(Message(kContentInvalidated));
79 }
80 
paintIfNeeded()81 void Window_android::paintIfNeeded() {
82     if (fWindowContext) { // Check if initDisplay has already been called
83         onPaint();
84     } else {
85         markInvalProcessed();
86     }
87 }
88 
89 }   // namespace sk_app
90