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