2016-04-21 14:59:44 +00:00
|
|
|
/*
|
|
|
|
* 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 "Window_android.h"
|
2016-07-26 19:02:50 +00:00
|
|
|
#include "WindowContextFactory_android.h"
|
|
|
|
#include "../WindowContext.h"
|
2016-04-21 14:59:44 +00:00
|
|
|
|
2016-05-04 20:49:13 +00:00
|
|
|
namespace sk_app {
|
|
|
|
|
2016-04-21 14:59:44 +00:00
|
|
|
Window* Window::CreateNativeWindow(void* platformData) {
|
|
|
|
Window_android* window = new Window_android();
|
2016-05-09 15:49:29 +00:00
|
|
|
if (!window->init((SkiaAndroidApp*)platformData)) {
|
2016-04-21 14:59:44 +00:00
|
|
|
delete window;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2016-05-09 15:49:29 +00:00
|
|
|
bool Window_android::init(SkiaAndroidApp* skiaAndroidApp) {
|
|
|
|
SkASSERT(skiaAndroidApp);
|
|
|
|
fSkiaAndroidApp = skiaAndroidApp;
|
|
|
|
fSkiaAndroidApp->fWindow = this;
|
2016-04-21 14:59:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window_android::setTitle(const char* title) {
|
2016-05-13 16:57:44 +00:00
|
|
|
fSkiaAndroidApp->setTitle(title);
|
2016-04-21 14:59:44 +00:00
|
|
|
}
|
|
|
|
|
2017-11-21 18:18:02 +00:00
|
|
|
void Window_android::setUIState(const char* state) {
|
2016-05-27 15:52:52 +00:00
|
|
|
fSkiaAndroidApp->setUIState(state);
|
|
|
|
}
|
|
|
|
|
2017-02-24 23:04:47 +00:00
|
|
|
bool Window_android::attach(BackendType attachType) {
|
2016-06-02 19:16:25 +00:00
|
|
|
fBackendType = attachType;
|
2016-04-21 14:59:44 +00:00
|
|
|
|
2016-06-07 21:22:37 +00:00
|
|
|
// We delay the creation of fWindowContext until Android informs us that
|
2016-04-21 14:59:44 +00:00
|
|
|
// the native window is ready to use.
|
2016-06-02 19:16:25 +00:00
|
|
|
// The creation will be done in initDisplay, which is initiated by kSurfaceCreated event.
|
2016-04-21 14:59:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window_android::initDisplay(ANativeWindow* window) {
|
|
|
|
SkASSERT(window);
|
2016-06-02 19:16:25 +00:00
|
|
|
switch (fBackendType) {
|
|
|
|
case kNativeGL_BackendType:
|
2016-06-17 16:29:14 +00:00
|
|
|
default:
|
2017-02-24 23:04:47 +00:00
|
|
|
fWindowContext = window_context_factory::NewGLForAndroid(window,
|
|
|
|
fRequestedDisplayParams);
|
2016-06-02 19:16:25 +00:00
|
|
|
break;
|
2016-06-07 21:22:37 +00:00
|
|
|
case kRaster_BackendType:
|
2017-02-24 23:04:47 +00:00
|
|
|
fWindowContext = window_context_factory::NewRasterForAndroid(window,
|
|
|
|
fRequestedDisplayParams);
|
2016-06-07 21:22:37 +00:00
|
|
|
break;
|
2016-06-17 16:29:14 +00:00
|
|
|
#ifdef SK_VULKAN
|
2016-06-02 19:16:25 +00:00
|
|
|
case kVulkan_BackendType:
|
2017-02-24 23:04:47 +00:00
|
|
|
fWindowContext = window_context_factory::NewVulkanForAndroid(window,
|
|
|
|
fRequestedDisplayParams);
|
2016-06-02 19:16:25 +00:00
|
|
|
break;
|
2016-06-17 16:29:14 +00:00
|
|
|
#endif
|
2016-06-02 19:16:25 +00:00
|
|
|
}
|
2017-02-24 20:22:53 +00:00
|
|
|
this->onBackendCreated();
|
2016-04-21 14:59:44 +00:00
|
|
|
}
|
|
|
|
|
2016-05-09 15:49:29 +00:00
|
|
|
void Window_android::onDisplayDestroyed() {
|
|
|
|
detach();
|
2016-04-21 14:59:44 +00:00
|
|
|
}
|
|
|
|
|
2016-05-23 17:52:34 +00:00
|
|
|
void Window_android::onInval() {
|
|
|
|
fSkiaAndroidApp->postMessage(Message(kContentInvalidated));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window_android::paintIfNeeded() {
|
|
|
|
if (fWindowContext) { // Check if initDisplay has already been called
|
|
|
|
onPaint();
|
|
|
|
} else {
|
|
|
|
markInvalProcessed();
|
|
|
|
}
|
2016-05-17 19:44:20 +00:00
|
|
|
}
|
2016-05-04 20:49:13 +00:00
|
|
|
|
|
|
|
} // namespace sk_app
|