OSDN Git Service

Properly convert the rendered layout images if alpha is needed.
authorXavier Ducrohet <xav@android.com>
Thu, 27 Jan 2011 02:09:34 +0000 (18:09 -0800)
committerXavier Ducrohet <xav@android.com>
Thu, 27 Jan 2011 02:19:11 +0000 (18:19 -0800)
The layoutlib can specify if the image is rendered as a floating
window, and needs alpha.
If it doesn't needed it we do a faster convert discarding the
alpha which will be better when playing animations in the normal
case.

Change-Id: I2dbd2d1ae9190207b51978e4a8d77cdff25f3e45

eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ImageOverlay.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PlayAnimationMenu.java
layoutlib_api/src/com/android/ide/common/rendering/api/RenderSession.java

index 7833570..0c1772b 100644 (file)
@@ -86,7 +86,7 @@ public class ImageOverlay extends Overlay implements IImageFactory {
      * @param awtImage The AWT image to be rendered as an SWT image.
      * @return The corresponding SWT image, or null.
      */
-    public synchronized Image setImage(BufferedImage awtImage) {
+    public synchronized Image setImage(BufferedImage awtImage, boolean isFloatingWindow) {
         if (awtImage != mAwtImage || awtImage == null) {
             mAwtImage = null;
 
@@ -97,11 +97,16 @@ public class ImageOverlay extends Overlay implements IImageFactory {
             if (awtImage == null) {
                 mImage = null;
             } else {
-                mImage = SwtUtils.convertToSwt(mCanvas.getDisplay(), awtImage, false, -1);
+                mImage = SwtUtils.convertToSwt(mCanvas.getDisplay(), awtImage, true, -1);
             }
         } else {
             assert awtImage instanceof SwtReadyBufferedImage;
-            mImage = ((SwtReadyBufferedImage)awtImage).getSwtImage();
+
+            if (isFloatingWindow) {
+                mImage = SwtUtils.convertToSwt(mCanvas.getDisplay(), awtImage, true, -1);
+            } else {
+                mImage = ((SwtReadyBufferedImage)awtImage).getSwtImage();
+            }
         }
 
         return mImage;
@@ -268,5 +273,4 @@ public class ImageOverlay extends Overlay implements IImageFactory {
 
         return mAwtImage;
     }
-
 }
index 8a5e198..7fbeb89 100755 (executable)
@@ -520,7 +520,7 @@ public class LayoutCanvas extends Canvas {
 
         mViewHierarchy.setSession(session, explodedNodes);
         if (mViewHierarchy.isValid() && session != null) {
-            Image image = mImageOverlay.setImage(session.getImage());
+            Image image = mImageOverlay.setImage(session.getImage(), session.isFloatingWindow());
 
             mOutlinePage.setModel(mViewHierarchy.getRoot());
 
index 7d32f78..5ccbb66 100644 (file)
@@ -164,7 +164,7 @@ public class PlayAnimationMenu extends SubmenuAction {
                                 }
 
                                 ImageOverlay imageOverlay = mCanvas.getImageOverlay();
-                                imageOverlay.setImage(s.getImage());
+                                imageOverlay.setImage(s.getImage(), s.isFloatingWindow());
                                 synchronized (this) {
                                     if (mPendingDrawing == false) {
                                         mCanvas.getDisplay().asyncExec(new Runnable() {
index 0adf6f5..5a00ebc 100644 (file)
@@ -73,6 +73,16 @@ public class RenderSession {
         return null;
     }
 
+    /**
+     * Returns true if the current session is rendered as a floating window.
+     * <p/>
+     * If true this means the alpha channel of {@link #getImage()} should be respected. If false,
+     * if can be dropped if it's more convenient/faster.
+     * @return whether the current session is rendered as a floating window.
+     */
+    public boolean isFloatingWindow() {
+        return true;
+    }
 
     /**
      * Returns a map of (XML attribute name, attribute value) containing only default attribute