use of java.awt.Graphics2D in project android_frameworks_base by ParanoidAndroid.
the class Bitmap_Delegate method nativeErase.
@LayoutlibDelegate
static /*package*/
void nativeErase(int nativeBitmap, int color) {
// get the delegate from the native int.
Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
if (delegate == null) {
return;
}
BufferedImage image = delegate.mImage;
Graphics2D g = image.createGraphics();
try {
g.setColor(new java.awt.Color(color, true));
g.fillRect(0, 0, image.getWidth(), image.getHeight());
} finally {
g.dispose();
}
}
use of java.awt.Graphics2D in project android_frameworks_base by ParanoidAndroid.
the class Canvas_Delegate method nativeDrawBitmapMatrix.
@LayoutlibDelegate
static /*package*/
void nativeDrawBitmapMatrix(int nCanvas, int nBitmap, int nMatrix, int nPaint) {
// get the delegate from the native int.
Canvas_Delegate canvasDelegate = sManager.getDelegate(nCanvas);
if (canvasDelegate == null) {
return;
}
// get the delegate from the native int, which can be null
Paint_Delegate paintDelegate = Paint_Delegate.getDelegate(nPaint);
// get the delegate from the native int.
Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(nBitmap);
if (bitmapDelegate == null) {
return;
}
final BufferedImage image = getImageToDraw(bitmapDelegate, paintDelegate, sBoolOut);
Matrix_Delegate matrixDelegate = Matrix_Delegate.getDelegate(nMatrix);
if (matrixDelegate == null) {
return;
}
final AffineTransform mtx = matrixDelegate.getAffineTransform();
canvasDelegate.getSnapshot().draw(new GcSnapshot.Drawable() {
@Override
public void draw(Graphics2D graphics, Paint_Delegate paint) {
if (paint != null && paint.isFilterBitmap()) {
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
}
//FIXME add support for canvas, screen and bitmap densities.
graphics.drawImage(image, mtx, null);
}
}, paintDelegate, true, /*compositeOnly*/
false);
}
use of java.awt.Graphics2D in project android_frameworks_base by ParanoidAndroid.
the class RenderDrawable method getImage.
protected BufferedImage getImage(int w, int h) {
BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics2D gc = image.createGraphics();
gc.setComposite(AlphaComposite.Src);
gc.setColor(new Color(0x00000000, true));
gc.fillRect(0, 0, w, h);
// done
gc.dispose();
return image;
}
use of java.awt.Graphics2D in project android_frameworks_base by ParanoidAndroid.
the class GcSnapshot method drawInLayer.
private void drawInLayer(Layer layer, Drawable drawable, Paint_Delegate paint, boolean compositeOnly, boolean forceSrcMode) {
Graphics2D originalGraphics = layer.getGraphics();
// get a Graphics2D object configured with the drawing parameters.
Graphics2D configuredGraphics2D = paint != null ? createCustomGraphics(originalGraphics, paint, compositeOnly, forceSrcMode) : (Graphics2D) originalGraphics.create();
try {
drawable.draw(configuredGraphics2D, paint);
layer.change();
} finally {
// dispose Graphics2D object
configuredGraphics2D.dispose();
}
}
use of java.awt.Graphics2D in project android_frameworks_base by ResurrectionRemix.
the class GcSnapshot method drawInLayer.
private void drawInLayer(Layer layer, Drawable drawable, Paint_Delegate paint, boolean compositeOnly, int forceMode) {
Graphics2D originalGraphics = layer.getGraphics();
if (paint == null) {
drawOnGraphics((Graphics2D) originalGraphics.create(), drawable, null, /*paint*/
layer);
} else {
ColorFilter_Delegate filter = paint.getColorFilter();
if (filter == null || !filter.isSupported()) {
// get a Graphics2D object configured with the drawing parameters.
Graphics2D configuredGraphics = createCustomGraphics(originalGraphics, paint, compositeOnly, forceMode);
drawOnGraphics(configuredGraphics, drawable, paint, layer);
return;
}
int x = 0;
int y = 0;
int width;
int height;
Rectangle clipBounds = originalGraphics.getClipBounds();
if (clipBounds != null) {
if (clipBounds.width == 0 || clipBounds.height == 0) {
// Clip is 0 so no need to paint anything.
return;
}
// If we have clipBounds available, use them as they will always be
// smaller than the full layer size.
x = clipBounds.x;
y = clipBounds.y;
width = clipBounds.width;
height = clipBounds.height;
} else {
width = layer.getImage().getWidth();
height = layer.getImage().getHeight();
}
// Create a temporary image to which the color filter will be applied.
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D imageBaseGraphics = (Graphics2D) image.getGraphics();
// Configure the Graphics2D object with drawing parameters and shader.
Graphics2D imageGraphics = createCustomGraphics(imageBaseGraphics, paint, compositeOnly, AlphaComposite.SRC_OVER);
// get a Graphics2D object configured with the drawing parameters, but no shader.
Graphics2D configuredGraphics = createCustomGraphics(originalGraphics, paint, true, /*compositeOnly*/
forceMode);
try {
// The main draw operation.
// We translate the operation to take into account that the rendering does not
// know about the clipping area.
imageGraphics.translate(-x, -y);
drawable.draw(imageGraphics, paint);
// Apply the color filter.
// Restore the original coordinates system and apply the filter only to the
// clipped area.
imageGraphics.translate(x, y);
filter.applyFilter(imageGraphics, width, height);
// Draw the tinted image on the main layer using as start point the clipping
// upper left coordinates.
configuredGraphics.drawImage(image, x, y, null);
layer.change();
} finally {
// dispose Graphics2D objects
imageGraphics.dispose();
imageBaseGraphics.dispose();
configuredGraphics.dispose();
}
}
}
Aggregations