aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar liyuqian <liyuqian@google.com>2016-06-09 12:02:34 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-06-09 12:02:34 -0700
commit71491dc14cff017e175ae5eb555490559de67914 (patch)
tree669fb76e4382e3dac303e50c5cf666eb909ef5ab
parent804b461bc4fe3cfd959fc065c1c0b524ef96e90b (diff)
Support resize in Android Viewer App
Previously, we took out resize because Vulkan didn't support it in Android. Now Android nyc-dev builds >= 2937079 and nyc-release builds >= NRD66 supports it so we add it back. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2050613003 Review-Url: https://codereview.chromium.org/2050613003
-rw-r--r--platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerApplication.java3
-rw-r--r--tools/viewer/Viewer.cpp4
-rw-r--r--tools/viewer/sk_app/android/GLWindowContext_android.cpp16
-rw-r--r--tools/viewer/sk_app/android/GLWindowContext_android.h5
-rw-r--r--tools/viewer/sk_app/android/RasterWindowContext_android.cpp17
-rw-r--r--tools/viewer/sk_app/android/RasterWindowContext_android.h9
-rw-r--r--tools/viewer/sk_app/android/surface_glue_android.cpp1
7 files changed, 43 insertions, 12 deletions
diff --git a/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerApplication.java b/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerApplication.java
index ee1695afd1..5849724741 100644
--- a/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerApplication.java
+++ b/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerApplication.java
@@ -57,6 +57,9 @@ public class ViewerApplication extends Application {
public void setTitle(String title) {
mTitle = title; // Similar to mStateJsonStr, we have to store this.
+ if (mTitle.startsWith("Viewer: ")) { // Quick hack to shorten the title
+ mTitle = mTitle.replaceFirst("Viewer: ", "");
+ }
if (mViewerActivity != null) {
mViewerActivity.runOnUiThread(new Runnable() {
@Override
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index 7015dad458..499673572b 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -53,7 +53,11 @@ DEFINE_string2(match, m, nullptr,
"If a bench does not match any list entry,\n"
"it is skipped unless some list entry starts with ~");
DEFINE_string(skps, "skps", "Directory to read skps from.");
+#ifdef SK_BUILD_FOR_ANDROID
+DEFINE_bool(vulkan, false, "Run with Vulkan.");
+#else
DEFINE_bool(vulkan, true, "Run with Vulkan.");
+#endif
const char *kBackendTypeStrings[sk_app::Window::kBackendTypeCount] = {
" [OpenGL]",
diff --git a/tools/viewer/sk_app/android/GLWindowContext_android.cpp b/tools/viewer/sk_app/android/GLWindowContext_android.cpp
index a98b5553f8..0b3363354b 100644
--- a/tools/viewer/sk_app/android/GLWindowContext_android.cpp
+++ b/tools/viewer/sk_app/android/GLWindowContext_android.cpp
@@ -43,11 +43,17 @@ GLWindowContext_android::~GLWindowContext_android() {
}
void GLWindowContext_android::onInitializeContext(void* platformData, const DisplayParams& params) {
- ContextPlatformData_android* androidPlatformData =
- reinterpret_cast<ContextPlatformData_android*>(platformData);
+ if (platformData != nullptr) {
+ ContextPlatformData_android* androidPlatformData =
+ reinterpret_cast<ContextPlatformData_android*>(platformData);
+ fNativeWindow = androidPlatformData->fNativeWindow;
+ } else {
+ SkASSERT(fNativeWindow);
+ }
+
- fWidth = ANativeWindow_getWidth(androidPlatformData->fNativeWindow);
- fHeight = ANativeWindow_getHeight(androidPlatformData->fNativeWindow);
+ fWidth = ANativeWindow_getWidth(fNativeWindow);
+ fHeight = ANativeWindow_getHeight(fNativeWindow);
fDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
@@ -81,7 +87,7 @@ void GLWindowContext_android::onInitializeContext(void* platformData, const Disp
SkASSERT(EGL_NO_CONTEXT != fEGLContext);
fSurface = eglCreateWindowSurface(
- fDisplay, surfaceConfig, androidPlatformData->fNativeWindow, nullptr);
+ fDisplay, surfaceConfig, fNativeWindow, nullptr);
SkASSERT(EGL_NO_SURFACE != fSurface);
SkAssertResult(eglMakeCurrent(fDisplay, fSurface, fSurface, fEGLContext));
diff --git a/tools/viewer/sk_app/android/GLWindowContext_android.h b/tools/viewer/sk_app/android/GLWindowContext_android.h
index 85e65beaa2..5f4c031ed1 100644
--- a/tools/viewer/sk_app/android/GLWindowContext_android.h
+++ b/tools/viewer/sk_app/android/GLWindowContext_android.h
@@ -13,6 +13,8 @@
#include <EGL/egl.h>
+struct ANativeWindow;
+
namespace sk_app {
class GLWindowContext_android : public GLWindowContext {
@@ -32,6 +34,9 @@ private:
EGLDisplay fDisplay;
EGLContext fEGLContext;
EGLSurface fSurface;
+
+ // For setDisplayParams and resize which call onInitializeContext with null platformData
+ ANativeWindow* fNativeWindow = nullptr;
};
diff --git a/tools/viewer/sk_app/android/RasterWindowContext_android.cpp b/tools/viewer/sk_app/android/RasterWindowContext_android.cpp
index 306f291de8..3ba564635e 100644
--- a/tools/viewer/sk_app/android/RasterWindowContext_android.cpp
+++ b/tools/viewer/sk_app/android/RasterWindowContext_android.cpp
@@ -32,8 +32,12 @@ RasterWindowContext_android::RasterWindowContext_android(
fNativeWindow = androidPlatformData->fNativeWindow;
fWidth = ANativeWindow_getWidth(fNativeWindow);
fHeight = ANativeWindow_getHeight(fNativeWindow);
+ this->setBuffersGeometry();
+}
+
+void RasterWindowContext_android::setBuffersGeometry() {
int32_t format;
- switch(params.fColorType) {
+ switch(fDisplayParams.fColorType) {
case kRGBA_8888_SkColorType:
format = WINDOW_FORMAT_RGBA_8888;
break;
@@ -46,6 +50,17 @@ RasterWindowContext_android::RasterWindowContext_android(
ANativeWindow_setBuffersGeometry(fNativeWindow, fWidth, fHeight, format);
}
+void RasterWindowContext_android::setDisplayParams(const DisplayParams& params) {
+ fDisplayParams = params;
+ this->setBuffersGeometry();
+}
+
+void RasterWindowContext_android::resize(uint32_t w, uint32_t h) {
+ fWidth = w;
+ fHeight = h;
+ this->setBuffersGeometry();
+}
+
sk_sp<SkSurface> RasterWindowContext_android::getBackbufferSurface() {
if (nullptr == fBackbufferSurface) {
ANativeWindow_lock(fNativeWindow, &fBuffer, &fBounds);
diff --git a/tools/viewer/sk_app/android/RasterWindowContext_android.h b/tools/viewer/sk_app/android/RasterWindowContext_android.h
index 913b06c9dd..7bb24ba30b 100644
--- a/tools/viewer/sk_app/android/RasterWindowContext_android.h
+++ b/tools/viewer/sk_app/android/RasterWindowContext_android.h
@@ -23,15 +23,12 @@ public:
void swapBuffers() override;
bool isValid() override { return SkToBool(fNativeWindow); }
- void resize(uint32_t w, uint32_t h) override {
- SkDEBUGFAIL("Resize is currently unsupported.");
- }
- void setDisplayParams(const DisplayParams& params) override {
- SkDEBUGFAIL("setDisplayParams is currently unsupported.");
- }
+ void resize(uint32_t w, uint32_t h) override;
+ void setDisplayParams(const DisplayParams& params) override;
private:
RasterWindowContext_android(void* platformData, const DisplayParams& params);
+ void setBuffersGeometry();
sk_sp<SkSurface> fBackbufferSurface = nullptr;
ANativeWindow* fNativeWindow = nullptr;
ANativeWindow_Buffer fBuffer;
diff --git a/tools/viewer/sk_app/android/surface_glue_android.cpp b/tools/viewer/sk_app/android/surface_glue_android.cpp
index 895b0bc459..0c1ab0cca2 100644
--- a/tools/viewer/sk_app/android/surface_glue_android.cpp
+++ b/tools/viewer/sk_app/android/surface_glue_android.cpp
@@ -124,6 +124,7 @@ int SkiaAndroidApp::message_callback(int fd, int events, void* data) {
skiaAndroidApp->fNativeWindow = message.fNativeWindow;
window_android->initDisplay(skiaAndroidApp->fNativeWindow);
}
+ window_android->onResize(width, height);
window_android->setContentRect(0, 0, width, height);
window_android->paintIfNeeded();
break;