From c225f79f46e1ff13bf7a7b36efb038dd4014ad86 Mon Sep 17 00:00:00 2001 From: Icyllis Milica Date: Fri, 26 Apr 2024 18:42:57 +0800 Subject: [PATCH] Avoid re-layout on window minimized, since framebuffer is destroyed and size is 0 Deprecate Canvas.saveLayer() for future layer compositor and render tree --- .../main/java/icyllis/modernui/core/ActivityWindow.java | 7 ++++++- core/src/main/java/icyllis/modernui/graphics/Canvas.java | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/icyllis/modernui/core/ActivityWindow.java b/core/src/main/java/icyllis/modernui/core/ActivityWindow.java index 374c03501..59972f4e2 100644 --- a/core/src/main/java/icyllis/modernui/core/ActivityWindow.java +++ b/core/src/main/java/icyllis/modernui/core/ActivityWindow.java @@ -165,7 +165,12 @@ private void onFramebufferSizeCallback(long w, int width, int height) { mWidth = width; mHeight = height; if (mRoot != null) { - mRoot.mHandler.post(() -> mRoot.setFrame(mWidth, mHeight)); + mRoot.mHandler.post(() -> { + // on minimized, window size is 0 + if (mWidth != 0 && mHeight != 0) { + mRoot.setFrame(mWidth, mHeight); + } + }); } } diff --git a/core/src/main/java/icyllis/modernui/graphics/Canvas.java b/core/src/main/java/icyllis/modernui/graphics/Canvas.java index 32fcd6db3..e47515ae9 100644 --- a/core/src/main/java/icyllis/modernui/graphics/Canvas.java +++ b/core/src/main/java/icyllis/modernui/graphics/Canvas.java @@ -119,7 +119,10 @@ protected Canvas() { * @param alpha The alpha to apply to the offscreen when it is * drawn during restore() * @return value to pass to restoreToCount() to balance this call + * @deprecated this method does nothing, you should manually create a layer, or possibly manage a + * pool of layers, or use {@link icyllis.modernui.view.View#LAYER_TYPE_HARDWARE}. */ + @Deprecated public final int saveLayer(@Nullable RectF bounds, int alpha) { if (bounds == null) { // ok, it's big enough @@ -134,7 +137,10 @@ public final int saveLayer(@Nullable RectF bounds, int alpha) { * bounds' rectangle. * * @see #saveLayer(RectF, int) + * @deprecated this method does nothing, you should manually create a layer, or possibly manage a + * pool of layers, or use {@link icyllis.modernui.view.View#LAYER_TYPE_HARDWARE}. */ + @Deprecated public abstract int saveLayer(float left, float top, float right, float bottom, int alpha); /**