| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "Window_android.h" | 8 #include "Window_android.h" |
| 9 | 9 |
| 10 #include "VulkanWindowContext_android.h" | 10 #include "VulkanWindowContext_android.h" |
| 11 | 11 |
| 12 namespace sk_app { | 12 namespace sk_app { |
| 13 | 13 |
| 14 Window* Window::CreateNativeWindow(void* platformData) { | 14 Window* Window::CreateNativeWindow(void* platformData) { |
| 15 Window_android* window = new Window_android(); | 15 Window_android* window = new Window_android(); |
| 16 if (!window->init((SkiaAndroidApp*)platformData)) { | 16 if (!window->init((SkiaAndroidApp*)platformData)) { |
| 17 delete window; | 17 delete window; |
| 18 return nullptr; | 18 return nullptr; |
| 19 } | 19 } |
| 20 return window; | 20 return window; |
| 21 } | 21 } |
| 22 | 22 |
| 23 bool Window_android::init(SkiaAndroidApp* skiaAndroidApp) { | 23 bool Window_android::init(SkiaAndroidApp* skiaAndroidApp) { |
| 24 SkASSERT(skiaAndroidApp); | 24 SkASSERT(skiaAndroidApp); |
| 25 fSkiaAndroidApp = skiaAndroidApp; | 25 fSkiaAndroidApp = skiaAndroidApp; |
| 26 fSkiaAndroidApp->fWindow = this; | 26 fSkiaAndroidApp->fWindow = this; |
| 27 return true; | 27 return true; |
| 28 } | 28 } |
| 29 | 29 |
| 30 const DisplayParams& Window_android::getDisplayParams() { |
| 31 if (fWindowContext) { |
| 32 return fWindowContext->getDisplayParams(); |
| 33 } else { |
| 34 // fWindowContext doesn't exist because we haven't |
| 35 // initDisplay yet. |
| 36 return fDisplayParams; |
| 37 } |
| 38 } |
| 39 |
| 30 void Window_android::setTitle(const char* title) { | 40 void Window_android::setTitle(const char* title) { |
| 31 //todo | 41 //todo |
| 32 SkDebugf("Title: %s", title); | 42 SkDebugf("Title: %s", title); |
| 33 } | 43 } |
| 34 | 44 |
| 35 bool Window_android::attach(BackEndType attachType, const DisplayParams& params)
{ | 45 bool Window_android::attach(BackEndType attachType, const DisplayParams& params)
{ |
| 36 if (kVulkan_BackendType != attachType) { | 46 if (kVulkan_BackendType != attachType) { |
| 37 return false; | 47 return false; |
| 38 } | 48 } |
| 39 | 49 |
| 40 fDisplayParams = params; | 50 fDisplayParams = params; |
| 41 | 51 |
| 42 // We delay the creation of fTestContext until Android informs us that | 52 // We delay the creation of fTestContext until Android informs us that |
| 43 // the native window is ready to use. | 53 // the native window is ready to use. |
| 44 return true; | 54 return true; |
| 45 } | 55 } |
| 46 | 56 |
| 47 void Window_android::initDisplay(ANativeWindow* window) { | 57 void Window_android::initDisplay(ANativeWindow* window) { |
| 48 SkASSERT(window); | 58 SkASSERT(window); |
| 49 ContextPlatformData_android platformData; | 59 ContextPlatformData_android platformData; |
| 50 platformData.fNativeWindow = window; | 60 platformData.fNativeWindow = window; |
| 51 fWindowContext = VulkanWindowContext::Create((void*)&platformData, fDisplayP
arams); | 61 fWindowContext = VulkanWindowContext::Create((void*)&platformData, fDisplayP
arams); |
| 52 fNativeWindowInitialized = true; | |
| 53 } | 62 } |
| 54 | 63 |
| 55 void Window_android::onDisplayDestroyed() { | 64 void Window_android::onDisplayDestroyed() { |
| 56 fNativeWindowInitialized = false; | |
| 57 detach(); | 65 detach(); |
| 58 } | 66 } |
| 59 | 67 |
| 60 void Window_android::inval() { fSkiaAndroidApp->postMessage(Message(kContentInva
lidated)); } | 68 void Window_android::inval() { fSkiaAndroidApp->postMessage(Message(kContentInva
lidated)); } |
| 61 | 69 |
| 62 } // namespace sk_app | 70 } // namespace sk_app |
| OLD | NEW |