Loading tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java +101 −25 Original line number Diff line number Diff line Loading @@ -458,8 +458,28 @@ public class Canvas_Delegate { /*package*/ static void native_drawARGB(int nativeCanvas, int a, int r, int g, int b) { // FIXME throw new UnsupportedOperationException(); // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas); if (canvasDelegate == null) { assert false; return; } // get a new graphics context. Graphics2D graphics = (Graphics2D)canvasDelegate.getGraphics2d().create(); try { // reset its transform just in case graphics.setTransform(new AffineTransform()); // set the color graphics.setColor(new Color(r, g, b, a)); graphics.fillRect(0, 0, canvasDelegate.mBufferedImage.getWidth(), canvasDelegate.mBufferedImage.getHeight()); } finally { // dispose Graphics2D object graphics.dispose(); } } /*package*/ static void native_drawColor(int nativeCanvas, int color) { Loading Loading @@ -676,18 +696,20 @@ public class Canvas_Delegate { return; } Graphics2D g = canvasDelegate.getGraphics2d(); g = (Graphics2D)g.create(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Graphics2D g = (Graphics2D) canvasDelegate.getGraphics2d().create(); try { if (paintDelegate.isAntiAliased()) { g.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } // set the color. because this only handles RGB, the alpha channel is handled // as a composite. g.setColor(new Color(paintDelegate.getColor())); int alpha = paintDelegate.getAlpha(); float falpha = alpha / 255.f; g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, falpha)); setModeInGraphics(g, PorterDuff.Mode.SRC_OVER, falpha); // Paint.TextAlign indicates how the text is positioned relative to X. // LEFT is the default and there's nothing to do. Loading @@ -701,7 +723,7 @@ public class Canvas_Delegate { } List<FontInfo> fonts = paintDelegate.getFonts(); try { if (fonts.size() > 0) { FontInfo mainFont = fonts.get(0); int i = index; Loading Loading @@ -873,6 +895,11 @@ public class Canvas_Delegate { Graphics2D g = getGraphics2d(); g = (Graphics2D)g.create(); if (paint.isAntiAliased()) { g.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } // configure it g.setColor(new Color(paint.getColor())); int alpha = paint.getAlpha(); Loading Loading @@ -932,6 +959,55 @@ public class Canvas_Delegate { return g; } private static void setModeInGraphics(Graphics2D g, PorterDuff.Mode mode, float falpha) { switch (mode) { case CLEAR: g.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, falpha)); break; case DARKEN: break; case DST: g.setComposite(AlphaComposite.getInstance(AlphaComposite.DST, falpha)); break; case DST_ATOP: g.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_ATOP, falpha)); break; case DST_IN: g.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_IN, falpha)); break; case DST_OUT: g.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_OUT, falpha)); break; case DST_OVER: g.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_OVER, falpha)); break; case LIGHTEN: break; case MULTIPLY: break; case SCREEN: break; case SRC: g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, falpha)); break; case SRC_ATOP: g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, falpha)); break; case SRC_IN: g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_IN, falpha)); break; case SRC_OUT: g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OUT, falpha)); break; case SRC_OVER: g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, falpha)); break; case XOR: g.setComposite(AlphaComposite.getInstance(AlphaComposite.XOR, falpha)); break; } } private static void drawBitmap( int nativeCanvas, Loading tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java +60 −11 Original line number Diff line number Diff line Loading @@ -77,6 +77,12 @@ public class Paint_Delegate { private float mTextScaleX; private float mTextSkewX; private int mXfermode; private int mColorFilter; private int mShader; private int mPathEffect; private int mMaskFilter; // ---- Public Helper methods ---- Loading @@ -92,6 +98,10 @@ public class Paint_Delegate { return mFonts; } public boolean isAntiAliased() { return (mFlags & Paint.ANTI_ALIAS_FLAG) != 0; } public boolean isFilterBitmap() { return (mFlags & Paint.FILTER_BITMAP_FLAG) != 0; } Loading Loading @@ -574,28 +584,58 @@ public class Paint_Delegate { } /*package*/ static int native_setShader(int native_object, int shader) { // FIXME throw new UnsupportedOperationException(); // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { assert false; return shader; } return delegate.mShader = shader; } /*package*/ static int native_setColorFilter(int native_object, int filter) { // FIXME throw new UnsupportedOperationException(); // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { assert false; return filter; } return delegate.mColorFilter = filter; } /*package*/ static int native_setXfermode(int native_object, int xfermode) { // FIXME throw new UnsupportedOperationException(); // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { assert false; return xfermode; } return delegate.mXfermode = xfermode; } /*package*/ static int native_setPathEffect(int native_object, int effect) { // FIXME throw new UnsupportedOperationException(); // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { assert false; return effect; } return delegate.mPathEffect = effect; } /*package*/ static int native_setMaskFilter(int native_object, int maskfilter) { // FIXME throw new UnsupportedOperationException(); // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { assert false; return maskfilter; } return delegate.mMaskFilter = maskfilter; } /*package*/ static int native_setTypeface(int native_object, int typeface) { Loading Loading @@ -778,6 +818,11 @@ public class Paint_Delegate { mTextSize = paint.mTextSize; mTextScaleX = paint.mTextScaleX; mTextSkewX = paint.mTextSkewX; mXfermode = paint.mXfermode; mColorFilter = paint.mColorFilter; mShader = paint.mShader; mPathEffect = paint.mPathEffect; mMaskFilter = paint.mMaskFilter; } private void reset() { Loading @@ -793,6 +838,11 @@ public class Paint_Delegate { mTextSize = 20.f; mTextScaleX = 1.f; mTextSkewX = 0.f; mXfermode = 0; mColorFilter = 0; mShader = 0; mPathEffect = 0; mMaskFilter = 0; } /** Loading Loading @@ -877,7 +927,6 @@ public class Paint_Delegate { } private static void setFlag(Paint thisPaint, int flagMask, boolean flagValue) { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); Loading Loading
tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java +101 −25 Original line number Diff line number Diff line Loading @@ -458,8 +458,28 @@ public class Canvas_Delegate { /*package*/ static void native_drawARGB(int nativeCanvas, int a, int r, int g, int b) { // FIXME throw new UnsupportedOperationException(); // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas); if (canvasDelegate == null) { assert false; return; } // get a new graphics context. Graphics2D graphics = (Graphics2D)canvasDelegate.getGraphics2d().create(); try { // reset its transform just in case graphics.setTransform(new AffineTransform()); // set the color graphics.setColor(new Color(r, g, b, a)); graphics.fillRect(0, 0, canvasDelegate.mBufferedImage.getWidth(), canvasDelegate.mBufferedImage.getHeight()); } finally { // dispose Graphics2D object graphics.dispose(); } } /*package*/ static void native_drawColor(int nativeCanvas, int color) { Loading Loading @@ -676,18 +696,20 @@ public class Canvas_Delegate { return; } Graphics2D g = canvasDelegate.getGraphics2d(); g = (Graphics2D)g.create(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Graphics2D g = (Graphics2D) canvasDelegate.getGraphics2d().create(); try { if (paintDelegate.isAntiAliased()) { g.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } // set the color. because this only handles RGB, the alpha channel is handled // as a composite. g.setColor(new Color(paintDelegate.getColor())); int alpha = paintDelegate.getAlpha(); float falpha = alpha / 255.f; g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, falpha)); setModeInGraphics(g, PorterDuff.Mode.SRC_OVER, falpha); // Paint.TextAlign indicates how the text is positioned relative to X. // LEFT is the default and there's nothing to do. Loading @@ -701,7 +723,7 @@ public class Canvas_Delegate { } List<FontInfo> fonts = paintDelegate.getFonts(); try { if (fonts.size() > 0) { FontInfo mainFont = fonts.get(0); int i = index; Loading Loading @@ -873,6 +895,11 @@ public class Canvas_Delegate { Graphics2D g = getGraphics2d(); g = (Graphics2D)g.create(); if (paint.isAntiAliased()) { g.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } // configure it g.setColor(new Color(paint.getColor())); int alpha = paint.getAlpha(); Loading Loading @@ -932,6 +959,55 @@ public class Canvas_Delegate { return g; } private static void setModeInGraphics(Graphics2D g, PorterDuff.Mode mode, float falpha) { switch (mode) { case CLEAR: g.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, falpha)); break; case DARKEN: break; case DST: g.setComposite(AlphaComposite.getInstance(AlphaComposite.DST, falpha)); break; case DST_ATOP: g.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_ATOP, falpha)); break; case DST_IN: g.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_IN, falpha)); break; case DST_OUT: g.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_OUT, falpha)); break; case DST_OVER: g.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_OVER, falpha)); break; case LIGHTEN: break; case MULTIPLY: break; case SCREEN: break; case SRC: g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, falpha)); break; case SRC_ATOP: g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, falpha)); break; case SRC_IN: g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_IN, falpha)); break; case SRC_OUT: g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OUT, falpha)); break; case SRC_OVER: g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, falpha)); break; case XOR: g.setComposite(AlphaComposite.getInstance(AlphaComposite.XOR, falpha)); break; } } private static void drawBitmap( int nativeCanvas, Loading
tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java +60 −11 Original line number Diff line number Diff line Loading @@ -77,6 +77,12 @@ public class Paint_Delegate { private float mTextScaleX; private float mTextSkewX; private int mXfermode; private int mColorFilter; private int mShader; private int mPathEffect; private int mMaskFilter; // ---- Public Helper methods ---- Loading @@ -92,6 +98,10 @@ public class Paint_Delegate { return mFonts; } public boolean isAntiAliased() { return (mFlags & Paint.ANTI_ALIAS_FLAG) != 0; } public boolean isFilterBitmap() { return (mFlags & Paint.FILTER_BITMAP_FLAG) != 0; } Loading Loading @@ -574,28 +584,58 @@ public class Paint_Delegate { } /*package*/ static int native_setShader(int native_object, int shader) { // FIXME throw new UnsupportedOperationException(); // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { assert false; return shader; } return delegate.mShader = shader; } /*package*/ static int native_setColorFilter(int native_object, int filter) { // FIXME throw new UnsupportedOperationException(); // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { assert false; return filter; } return delegate.mColorFilter = filter; } /*package*/ static int native_setXfermode(int native_object, int xfermode) { // FIXME throw new UnsupportedOperationException(); // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { assert false; return xfermode; } return delegate.mXfermode = xfermode; } /*package*/ static int native_setPathEffect(int native_object, int effect) { // FIXME throw new UnsupportedOperationException(); // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { assert false; return effect; } return delegate.mPathEffect = effect; } /*package*/ static int native_setMaskFilter(int native_object, int maskfilter) { // FIXME throw new UnsupportedOperationException(); // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { assert false; return maskfilter; } return delegate.mMaskFilter = maskfilter; } /*package*/ static int native_setTypeface(int native_object, int typeface) { Loading Loading @@ -778,6 +818,11 @@ public class Paint_Delegate { mTextSize = paint.mTextSize; mTextScaleX = paint.mTextScaleX; mTextSkewX = paint.mTextSkewX; mXfermode = paint.mXfermode; mColorFilter = paint.mColorFilter; mShader = paint.mShader; mPathEffect = paint.mPathEffect; mMaskFilter = paint.mMaskFilter; } private void reset() { Loading @@ -793,6 +838,11 @@ public class Paint_Delegate { mTextSize = 20.f; mTextScaleX = 1.f; mTextSkewX = 0.f; mXfermode = 0; mColorFilter = 0; mShader = 0; mPathEffect = 0; mMaskFilter = 0; } /** Loading Loading @@ -877,7 +927,6 @@ public class Paint_Delegate { } private static void setFlag(Paint thisPaint, int flagMask, boolean flagValue) { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); Loading