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-06-02 19:16:25 +00:00
|
|
|
#include "../GLWindowContext.h"
|
|
|
|
#include "../VulkanWindowContext.h"
|
2016-06-07 21:22:37 +00:00
|
|
|
#include "../RasterWindowContext.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;
|
|
|
|
}
|
|
|
|
|
2016-05-12 16:17:04 +00:00
|
|
|
const DisplayParams& Window_android::getDisplayParams() {
|
|
|
|
if (fWindowContext) {
|
|
|
|
return fWindowContext->getDisplayParams();
|
|
|
|
} else {
|
|
|
|
// fWindowContext doesn't exist because we haven't
|
|
|
|
// initDisplay yet.
|
|
|
|
return fDisplayParams;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-21 14:59:44 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-05-27 15:52:52 +00:00
|
|
|
void Window_android::setUIState(const Json::Value& state) {
|
|
|
|
fSkiaAndroidApp->setUIState(state);
|
|
|
|
}
|
|
|
|
|
2016-05-20 13:01:06 +00:00
|
|
|
bool Window_android::attach(BackendType attachType, const DisplayParams& params) {
|
2016-06-02 19:16:25 +00:00
|
|
|
fBackendType = attachType;
|
2016-05-06 20:28:57 +00:00
|
|
|
fDisplayParams = params;
|
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);
|
|
|
|
ContextPlatformData_android platformData;
|
|
|
|
platformData.fNativeWindow = window;
|
2016-06-02 19:16:25 +00:00
|
|
|
switch (fBackendType) {
|
|
|
|
case kNativeGL_BackendType:
|
|
|
|
fWindowContext = GLWindowContext::Create((void*)&platformData, fDisplayParams);
|
|
|
|
break;
|
2016-06-07 21:22:37 +00:00
|
|
|
case kRaster_BackendType:
|
|
|
|
fWindowContext = RasterWindowContext::Create((void*)&platformData, fDisplayParams);
|
|
|
|
break;
|
2016-06-02 19:16:25 +00:00
|
|
|
case kVulkan_BackendType:
|
|
|
|
default:
|
|
|
|
fWindowContext = VulkanWindowContext::Create((void*)&platformData, fDisplayParams);
|
|
|
|
break;
|
|
|
|
}
|
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
|