skia2/tools/sk_app/android/Window_android.cpp
Greg Daniel 8c277bdbfe Revert "Fix crash on windows viewer when starting in vulkan."
This reverts commit fcd68167a2.

Reason for revert: going to do this a different way

Original change's description:
> Fix crash on windows viewer when starting in vulkan.
>
> setRequestedDisplayParams is called when setting up viewer before we've
> inited the Window. On windows this tries to attach the Window for a given
> backend. However, we haven't set fBackend yet. Later on we will directly
> call attach.
>
> Change-Id: I4bd6586478f2b040e5913314c4e47e92fc893a60
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/344756
> Reviewed-by: Brian Osman <brianosman@google.com>
> Commit-Queue: Greg Daniel <egdaniel@google.com>

TBR=egdaniel@google.com,brianosman@google.com

Change-Id: Ie4d33b557868e4906df9b7a3988072fdc79a19c7
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/344897
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2020-12-16 14:52:07 +00:00

90 lines
2.3 KiB
C++

/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "tools/sk_app/WindowContext.h"
#include "tools/sk_app/android/WindowContextFactory_android.h"
#include "tools/sk_app/android/Window_android.h"
namespace sk_app {
Window* Window::CreateNativeWindow(void* platformData) {
Window_android* window = new Window_android();
if (!window->init((SkiaAndroidApp*)platformData)) {
delete window;
return nullptr;
}
return window;
}
bool Window_android::init(SkiaAndroidApp* skiaAndroidApp) {
SkASSERT(skiaAndroidApp);
fSkiaAndroidApp = skiaAndroidApp;
fSkiaAndroidApp->fWindow = this;
return true;
}
void Window_android::setTitle(const char* title) {
fSkiaAndroidApp->setTitle(title);
}
void Window_android::setUIState(const char* state) {
fSkiaAndroidApp->setUIState(state);
}
bool Window_android::attach(BackendType attachType) {
fBackendType = attachType;
// We delay the creation of fWindowContext until Android informs us that
// the native window is ready to use.
// The creation will be done in initDisplay, which is initiated by kSurfaceCreated event.
return true;
}
void Window_android::initDisplay(ANativeWindow* window) {
SkASSERT(window);
switch (fBackendType) {
#ifdef SK_GL
case kNativeGL_BackendType:
default:
fWindowContext =
window_context_factory::MakeGLForAndroid(window, fRequestedDisplayParams);
break;
#else
default:
#endif
case kRaster_BackendType:
fWindowContext =
window_context_factory::MakeRasterForAndroid(window, fRequestedDisplayParams);
break;
#ifdef SK_VULKAN
case kVulkan_BackendType:
fWindowContext =
window_context_factory::MakeVulkanForAndroid(window, fRequestedDisplayParams);
break;
#endif
}
this->onBackendCreated();
}
void Window_android::onDisplayDestroyed() {
detach();
}
void Window_android::onInval() {
fSkiaAndroidApp->postMessage(Message(kContentInvalidated));
}
void Window_android::paintIfNeeded() {
if (fWindowContext) { // Check if initDisplay has already been called
onPaint();
} else {
markInvalProcessed();
}
}
} // namespace sk_app