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)14Window* 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)23bool Window_android::init(SkiaAndroidApp* skiaAndroidApp) { 24 SkASSERT(skiaAndroidApp); 25 fSkiaAndroidApp = skiaAndroidApp; 26 fSkiaAndroidApp->fWindow = this; 27 return true; 28 } 29 setTitle(const char * title)30void Window_android::setTitle(const char* title) { 31 fSkiaAndroidApp->setTitle(title); 32 } 33 setUIState(const char * state)34void Window_android::setUIState(const char* state) { 35 fSkiaAndroidApp->setUIState(state); 36 } 37 attach(BackendType attachType)38bool 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)47void Window_android::initDisplay(ANativeWindow* window) { 48 SkASSERT(window); 49 switch (fBackendType) { 50 case kNativeGL_BackendType: 51 default: 52 fWindowContext = 53 window_context_factory::MakeGLForAndroid(window, fRequestedDisplayParams); 54 break; 55 case kRaster_BackendType: 56 fWindowContext = 57 window_context_factory::MakeRasterForAndroid(window, fRequestedDisplayParams); 58 break; 59 #ifdef SK_VULKAN 60 case kVulkan_BackendType: 61 fWindowContext = 62 window_context_factory::MakeVulkanForAndroid(window, fRequestedDisplayParams); 63 break; 64 #endif 65 } 66 this->onBackendCreated(); 67 } 68 onDisplayDestroyed()69void Window_android::onDisplayDestroyed() { 70 detach(); 71 } 72 onInval()73void Window_android::onInval() { 74 fSkiaAndroidApp->postMessage(Message(kContentInvalidated)); 75 } 76 paintIfNeeded()77void Window_android::paintIfNeeded() { 78 if (fWindowContext) { // Check if initDisplay has already been called 79 onPaint(); 80 } else { 81 markInvalProcessed(); 82 } 83 } 84 85 } // namespace sk_app 86