From 26e32ea559da98dcdebaefb74d4f3c1a5ce705c3 Mon Sep 17 00:00:00 2001 From: Deepanshu Gupta Date: Thu, 10 Jul 2014 13:57:52 -0700 Subject: [PATCH] Update delegates Change-Id: Icd93c31b4e8c8ee5ea242fb8295578937f48ff2a --- .../android/content/res/BridgeTypedArray.java | 9 +++ .../src/android/graphics/Bitmap_Delegate.java | 34 ++++++++--- .../android/graphics/Typeface_Delegate.java | 56 +------------------ 3 files changed, 37 insertions(+), 62 deletions(-) diff --git a/tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java b/tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java index 105803e5ef707..f939678af85f2 100644 --- a/tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java +++ b/tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java @@ -828,9 +828,18 @@ public final class BridgeTypedArray extends TypedArray { @Override public int[] extractThemeAttrs() { + // The drawables are always inflated with a Theme and we don't care about caching. So, + // just return. return null; } + @Override + public int getChangingConfigurations() { + // We don't care about caching. Any change in configuration is a fresh render. So, + // just return. + return 0; + } + /** * Retrieve the raw TypedValue for the attribute at index. * diff --git a/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java index bd88ae2378b9d..f4282ad423c20 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java @@ -53,6 +53,7 @@ import javax.imageio.ImageIO; */ public final class Bitmap_Delegate { + public enum BitmapCreateFlags { PREMULTIPLIED, MUTABLE } @@ -68,6 +69,7 @@ public final class Bitmap_Delegate { private BufferedImage mImage; private boolean mHasAlpha = true; private boolean mHasMipMap = false; // TODO: check the default. + private boolean mIsPremultiplied = true; private int mGenerationId = 0; @@ -393,21 +395,19 @@ public final class Bitmap_Delegate { } @LayoutlibDelegate - /*package*/ static int nativeGetPixel(long nativeBitmap, int x, int y, - boolean isPremultiplied) { + /*package*/ static int nativeGetPixel(long nativeBitmap, int x, int y) { // get the delegate from the native int. Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); if (delegate == null) { return 0; } - // TODO: Support isPremultiplied. return delegate.mImage.getRGB(x, y); } @LayoutlibDelegate /*package*/ static void nativeGetPixels(long nativeBitmap, int[] pixels, int offset, - int stride, int x, int y, int width, int height, boolean isPremultiplied) { + int stride, int x, int y, int width, int height) { Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); if (delegate == null) { return; @@ -418,8 +418,7 @@ public final class Bitmap_Delegate { @LayoutlibDelegate - /*package*/ static void nativeSetPixel(long nativeBitmap, int x, int y, int color, - boolean isPremultiplied) { + /*package*/ static void nativeSetPixel(long nativeBitmap, int x, int y, int color) { Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); if (delegate == null) { return; @@ -430,7 +429,7 @@ public final class Bitmap_Delegate { @LayoutlibDelegate /*package*/ static void nativeSetPixels(long nativeBitmap, int[] colors, int offset, - int stride, int x, int y, int width, int height, boolean isPremultiplied) { + int stride, int x, int y, int width, int height) { Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); if (delegate == null) { return; @@ -518,7 +517,26 @@ public final class Bitmap_Delegate { } @LayoutlibDelegate - /*package*/ static void nativeSetAlphaAndPremultiplied(long nativeBitmap, boolean hasAlpha, + /*package*/ static boolean nativeIsPremultiplied(long nativeBitmap) { + // get the delegate from the native int. + Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); + return delegate != null && delegate.mIsPremultiplied; + + } + + @LayoutlibDelegate + /*package*/ static void nativeSetPremultiplied(long nativeBitmap, boolean isPremul) { + // get the delegate from the native int. + Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); + if (delegate == null) { + return; + } + + delegate.mIsPremultiplied = isPremul; + } + + @LayoutlibDelegate + /*package*/ static void nativeSetHasAlpha(long nativeBitmap, boolean hasAlpha, boolean isPremul) { // get the delegate from the native int. Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); diff --git a/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java index 887e8f69b71ac..f044def64697a 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java @@ -17,19 +17,14 @@ package android.graphics; import com.android.annotations.NonNull; -import com.android.annotations.Nullable; -import com.android.ide.common.rendering.api.LayoutLog; -import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.impl.DelegateManager; import com.android.tools.layoutlib.annotations.LayoutlibDelegate; -import android.content.res.AssetManager; import android.graphics.FontFamily_Delegate.FontVariant; import java.awt.Font; import java.io.File; import java.util.ArrayList; -import java.util.Collections; import java.util.List; /** @@ -58,10 +53,8 @@ public final class Typeface_Delegate { // ---- delegate data ---- - @Nullable + @NonNull private final FontFamily_Delegate[] mFontFamilies; // the reference to FontFamily_Delegate. - @Nullable - private final Font mFont; /** @see FontFamily_Delegate.FontInfo#mStyle */ private final int mStyle; @@ -87,11 +80,6 @@ public final class Typeface_Delegate { @NonNull public List getFonts(FontVariant variant) { assert variant != FontVariant.NONE; - if (mFontFamilies == null) { - // We don't care about the variant here, since the Typeface was created with a single - // Font File. So, we simply return that Font. - return getFontAsList(); - } List fonts = new ArrayList(mFontFamilies.length); for (int i = 0; i < mFontFamilies.length; i++) { FontFamily_Delegate ffd = mFontFamilies[i]; @@ -127,14 +115,6 @@ public final class Typeface_Delegate { // ---- native methods ---- - @LayoutlibDelegate - /*package*/ static synchronized long nativeCreate(String familyName, int style) { - Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, - "Could not find font with family \"" + familyName + "\".", - null /*throwable*/, null /*data*/); - return 0; - } - @LayoutlibDelegate /*package*/ static synchronized long nativeCreateFromTypeface(long native_instance, int style) { Typeface_Delegate delegate = sManager.getDelegate(native_instance); @@ -148,24 +128,6 @@ public final class Typeface_Delegate { return sManager.addNewDelegate(new Typeface_Delegate(delegate.mFontFamilies, style)); } - @LayoutlibDelegate - /*package*/ static synchronized long nativeCreateFromAsset(AssetManager mgr, String path) { - Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, - "Typeface.createFromAsset() is not supported.", null /*throwable*/, null /*data*/); - return 0; - } - - @LayoutlibDelegate - /*package*/ static synchronized long nativeCreateFromFile(String path) { - if (!path.startsWith(SYSTEM_FONTS)) { - Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, - "Typeface.createFromFile() can only work with platform fonts located in " + - SYSTEM_FONTS, null, null); - return 0; - } - return sManager.addNewDelegate(new Typeface_Delegate(path)); - } - @LayoutlibDelegate /*package*/ static synchronized long nativeCreateFromArray(long[] familyArray) { FontFamily_Delegate[] fontFamilies = new FontFamily_Delegate[familyArray.length]; @@ -203,22 +165,8 @@ public final class Typeface_Delegate { // ---- Private delegate/helper methods ---- - private Typeface_Delegate(FontFamily_Delegate[] fontFamilies, int style) { + private Typeface_Delegate(@NonNull FontFamily_Delegate[] fontFamilies, int style) { mFontFamilies = fontFamilies; - mFont = null; mStyle = style; } - - private Typeface_Delegate(String path) { - mFont = FontFamily_Delegate.loadFont(path); - mFontFamilies = null; - mStyle = FontFamily_Delegate.getFontStyle(path); - } - - private List getFontAsList() { - if (mFont != null) { - return Collections.singletonList(mFont); - } - return Collections.emptyList(); - } }