| 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 #include "../GLWindowContext.h" | 9 #include "../GLWindowContext.h" |
| 10 #include "../VulkanWindowContext.h" | 10 #include "../VulkanWindowContext.h" |
| 11 #include "../RasterWindowContext.h" |
| 11 | 12 |
| 12 namespace sk_app { | 13 namespace sk_app { |
| 13 | 14 |
| 14 Window* Window::CreateNativeWindow(void* platformData) { | 15 Window* Window::CreateNativeWindow(void* platformData) { |
| 15 Window_android* window = new Window_android(); | 16 Window_android* window = new Window_android(); |
| 16 if (!window->init((SkiaAndroidApp*)platformData)) { | 17 if (!window->init((SkiaAndroidApp*)platformData)) { |
| 17 delete window; | 18 delete window; |
| 18 return nullptr; | 19 return nullptr; |
| 19 } | 20 } |
| 20 return window; | 21 return window; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 42 } | 43 } |
| 43 | 44 |
| 44 void Window_android::setUIState(const Json::Value& state) { | 45 void Window_android::setUIState(const Json::Value& state) { |
| 45 fSkiaAndroidApp->setUIState(state); | 46 fSkiaAndroidApp->setUIState(state); |
| 46 } | 47 } |
| 47 | 48 |
| 48 bool Window_android::attach(BackendType attachType, const DisplayParams& params)
{ | 49 bool Window_android::attach(BackendType attachType, const DisplayParams& params)
{ |
| 49 fBackendType = attachType; | 50 fBackendType = attachType; |
| 50 fDisplayParams = params; | 51 fDisplayParams = params; |
| 51 | 52 |
| 52 if (fNativeWindow) { | 53 // We delay the creation of fWindowContext until Android informs us that |
| 53 this->initDisplay(fNativeWindow); | |
| 54 } | |
| 55 // If fNativeWindow is not set, | |
| 56 // we delay the creation of fWindowContext until Android informs us that | |
| 57 // the native window is ready to use. | 54 // the native window is ready to use. |
| 58 // The creation will be done in initDisplay, which is initiated by kSurfaceC
reated event. | 55 // The creation will be done in initDisplay, which is initiated by kSurfaceC
reated event. |
| 59 return true; | 56 return true; |
| 60 } | 57 } |
| 61 | 58 |
| 62 void Window_android::initDisplay(ANativeWindow* window) { | 59 void Window_android::initDisplay(ANativeWindow* window) { |
| 63 SkASSERT(window); | 60 SkASSERT(window); |
| 64 fNativeWindow = window; | |
| 65 ContextPlatformData_android platformData; | 61 ContextPlatformData_android platformData; |
| 66 platformData.fNativeWindow = window; | 62 platformData.fNativeWindow = window; |
| 67 switch (fBackendType) { | 63 switch (fBackendType) { |
| 68 case kNativeGL_BackendType: | 64 case kNativeGL_BackendType: |
| 69 fWindowContext = GLWindowContext::Create((void*)&platformData, fDisp
layParams); | 65 fWindowContext = GLWindowContext::Create((void*)&platformData, fDisp
layParams); |
| 70 break; | 66 break; |
| 71 | 67 case kRaster_BackendType: |
| 68 fWindowContext = RasterWindowContext::Create((void*)&platformData, f
DisplayParams); |
| 69 break; |
| 72 case kVulkan_BackendType: | 70 case kVulkan_BackendType: |
| 73 default: | 71 default: |
| 74 fWindowContext = VulkanWindowContext::Create((void*)&platformData, f
DisplayParams); | 72 fWindowContext = VulkanWindowContext::Create((void*)&platformData, f
DisplayParams); |
| 75 break; | 73 break; |
| 76 } | 74 } |
| 77 } | 75 } |
| 78 | 76 |
| 79 void Window_android::onDisplayDestroyed() { | 77 void Window_android::onDisplayDestroyed() { |
| 80 detach(); | 78 detach(); |
| 81 fNativeWindow = nullptr; | |
| 82 } | 79 } |
| 83 | 80 |
| 84 void Window_android::onInval() { | 81 void Window_android::onInval() { |
| 85 fSkiaAndroidApp->postMessage(Message(kContentInvalidated)); | 82 fSkiaAndroidApp->postMessage(Message(kContentInvalidated)); |
| 86 } | 83 } |
| 87 | 84 |
| 88 void Window_android::paintIfNeeded() { | 85 void Window_android::paintIfNeeded() { |
| 89 if (fWindowContext) { // Check if initDisplay has already been called | 86 if (fWindowContext) { // Check if initDisplay has already been called |
| 90 onPaint(); | 87 onPaint(); |
| 91 } else { | 88 } else { |
| 92 markInvalProcessed(); | 89 markInvalProcessed(); |
| 93 } | 90 } |
| 94 } | 91 } |
| 95 | 92 |
| 96 } // namespace sk_app | 93 } // namespace sk_app |
| OLD | NEW |