summaryrefslogtreecommitdiffstats
path: root/tools/layoutlib/bridge
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2011-01-26 16:33:07 -0800
committerXavier Ducrohet <xav@android.com>2011-01-26 16:34:53 -0800
commit5a82d8c58bf91c357c37a82b9f5e5c26f676d847 (patch)
tree34486ebd0aabece45c26801fe11600cd9934dfcd /tools/layoutlib/bridge
parentf6926a63dfdc114789a6acc06396ca826eb64418 (diff)
downloadframeworks_base-5a82d8c58bf91c357c37a82b9f5e5c26f676d847.zip
frameworks_base-5a82d8c58bf91c357c37a82b9f5e5c26f676d847.tar.gz
frameworks_base-5a82d8c58bf91c357c37a82b9f5e5c26f676d847.tar.bz2
LayoutLib: properly erase the bitmap when rendering a new session.
This fix the issue where going from a full theme to a dialog theme would show the dialog on top of the previous rendering. Change-Id: Ib52b9719f44b04969423547b9de8d039f90b6f46
Diffstat (limited to 'tools/layoutlib/bridge')
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java2
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java2
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/AnimationThread.java2
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java28
4 files changed, 26 insertions, 8 deletions
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
index 0c3aef4..bd52dc2 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
@@ -304,7 +304,7 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
if (lastResult.isSuccess()) {
lastResult = scene.inflate();
if (lastResult.isSuccess()) {
- lastResult = scene.render();
+ lastResult = scene.render(true /*freshRender*/);
}
}
} finally {
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java
index 3bc0202..963dc4d 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java
@@ -108,7 +108,7 @@ public class BridgeRenderSession extends RenderSession {
Bridge.prepareThread();
mLastResult = mSession.acquire(timeout);
if (mLastResult.isSuccess()) {
- mLastResult = mSession.render();
+ mLastResult = mSession.render(false /*freshRender*/);
}
} finally {
mSession.release();
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/AnimationThread.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/AnimationThread.java
index 2bd7cc7..4c18656 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/AnimationThread.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/AnimationThread.java
@@ -146,7 +146,7 @@ public abstract class AnimationThread extends Thread {
}
bundle.mTarget.handleMessage(bundle.mMessage);
- if (mSession.render().isSuccess()) {
+ if (mSession.render(false /*freshRender*/).isSuccess()) {
mListener.onNewFrame(session);
}
} finally {
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
index d7b7009..6224047 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
@@ -72,6 +72,7 @@ import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TabHost.TabSpec;
+import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
@@ -385,13 +386,17 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
* <p>
* {@link #acquire(long)} must have been called before this.
*
+ * @param freshRender whether the render is a new one and should erase the existing bitmap (in
+ * the case where bitmaps are reused). This is typically needed when not playing
+ * animations.)
+ *
* @throws IllegalStateException if the current context is different than the one owned by
* the scene, or if {@link #acquire(long)} was not called.
*
* @see SceneParams#getRenderingMode()
* @see LayoutScene#render(long)
*/
- public Result render() {
+ public Result render(boolean freshRender) {
checkLock();
try {
@@ -450,6 +455,7 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
// draw the views
// create the BufferedImage into which the layout will be rendered.
+ boolean newImage = false;
if (newRenderSize || mCanvas == null) {
if (mParams.getImageFactory() != null) {
mImage = mParams.getImageFactory().getImage(mMeasuredScreenWidth,
@@ -457,11 +463,15 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
} else {
mImage = new BufferedImage(mMeasuredScreenWidth,
mMeasuredScreenHeight - mScreenOffset, BufferedImage.TYPE_INT_ARGB);
+ newImage = true;
}
if (mParams.isBgColorOverridden()) {
+ // since we override the content, it's the same as if it was a new image.
+ newImage = true;
Graphics2D gc = mImage.createGraphics();
gc.setColor(new Color(mParams.getOverrideBgColor(), true));
+ gc.setComposite(AlphaComposite.Src);
gc.fillRect(0, 0, mMeasuredScreenWidth, mMeasuredScreenHeight - mScreenOffset);
gc.dispose();
}
@@ -476,6 +486,14 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
mCanvas.setDensity(mParams.getDensity());
}
+ if (freshRender && newImage == false) {
+ Graphics2D gc = mImage.createGraphics();
+ gc.setColor(new Color(0x00000000, true));
+ gc.setComposite(AlphaComposite.Src);
+ gc.fillRect(0, 0, mMeasuredScreenWidth, mMeasuredScreenHeight - mScreenOffset);
+ gc.dispose();
+ }
+
mViewRoot.draw(mCanvas);
mViewInfoList = visitAllChildren((ViewGroup)mViewRoot, mContext);
@@ -600,7 +618,7 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
return result;
}
- result = render();
+ result = render(false /*freshRender*/);
if (result.isSuccess()) {
result = result.getCopyWithData(child);
}
@@ -678,7 +696,7 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
}
try {
- result = render();
+ result = render(false /*freshRender*/);
if (result.isSuccess()) {
listener.onNewFrame(RenderSessionImpl.this.getSession());
}
@@ -734,7 +752,7 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
return result;
}
- result = render();
+ result = render(false /*freshRender*/);
if (layoutParams != null && result.isSuccess()) {
result = result.getCopyWithData(layoutParams);
}
@@ -866,7 +884,7 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
return result;
}
- return render();
+ return render(false /*freshRender*/);
}
/**