use of java.awt.geom.AffineTransform in project android_frameworks_base by ResurrectionRemix.
the class GcSnapshot method doRestore.
private GcSnapshot doRestore() {
if (mPrevious != null) {
if (mLocalLayer != null) {
// prepare to blit the layers in which we have draw, in the layer beneath
// them, starting with the top one (which is the current local layer).
int i = mLayers.size() - 1;
int flags;
do {
Layer dstLayer = mLayers.get(i - 1);
restoreLayer(dstLayer);
flags = dstLayer.getFlags();
i--;
} while (i > 0 && (flags & Canvas.CLIP_TO_LAYER_SAVE_FLAG) == 0);
}
// didn't save the matrix? set the current matrix on the previous snapshot
if ((mFlags & Canvas.MATRIX_SAVE_FLAG) == 0) {
AffineTransform mtx = getTransform();
for (Layer layer : mPrevious.mLayers) {
layer.getGraphics().setTransform(mtx);
}
}
// didn't save the clip? set the current clip on the previous snapshot
if ((mFlags & Canvas.CLIP_SAVE_FLAG) == 0) {
Shape clip = getClip();
for (Layer layer : mPrevious.mLayers) {
layer.setClip(clip);
}
}
}
for (Layer layer : mLayers) {
layer.getGraphics().dispose();
}
return mPrevious;
}
use of java.awt.geom.AffineTransform in project android_frameworks_base by ResurrectionRemix.
the class Matrix_Delegate method native_invert.
@LayoutlibDelegate
static /*package*/
boolean native_invert(long native_object, long inverse) {
Matrix_Delegate d = sManager.getDelegate(native_object);
if (d == null) {
return false;
}
Matrix_Delegate inv_mtx = sManager.getDelegate(inverse);
if (inv_mtx == null) {
return false;
}
try {
AffineTransform affineTransform = d.getAffineTransform();
AffineTransform inverseTransform = affineTransform.createInverse();
inv_mtx.mValues[0] = (float) inverseTransform.getScaleX();
inv_mtx.mValues[1] = (float) inverseTransform.getShearX();
inv_mtx.mValues[2] = (float) inverseTransform.getTranslateX();
inv_mtx.mValues[3] = (float) inverseTransform.getScaleX();
inv_mtx.mValues[4] = (float) inverseTransform.getShearY();
inv_mtx.mValues[5] = (float) inverseTransform.getTranslateY();
return true;
} catch (NoninvertibleTransformException e) {
return false;
}
}
use of java.awt.geom.AffineTransform in project android_frameworks_base by ResurrectionRemix.
the class Paint_Delegate method updateFontObject.
/**
* Update the {@link Font} object from the typeface, text size and scaling
*/
@SuppressWarnings("deprecation")
private void updateFontObject() {
if (mTypeface != null) {
// Get the fonts from the TypeFace object.
List<Font> fonts = mTypeface.getFonts(mFontVariant);
if (fonts.isEmpty()) {
mFonts = Collections.emptyList();
return;
}
// create new font objects as well as FontMetrics, based on the current text size
// and skew info.
int nFonts = fonts.size();
ArrayList<FontInfo> infoList = new ArrayList<FontInfo>(nFonts);
//noinspection ForLoopReplaceableByForEach (avoid iterator instantiation)
for (int i = 0; i < nFonts; i++) {
Font font = fonts.get(i);
if (font == null) {
// If the font is null, add null to infoList. When rendering the text, if this
// null is reached, a warning will be logged.
infoList.add(null);
continue;
}
FontInfo info = new FontInfo();
info.mFont = font.deriveFont(mTextSize);
if (mTextScaleX != 1.0 || mTextSkewX != 0) {
// TODO: support skew
info.mFont = info.mFont.deriveFont(new AffineTransform(mTextScaleX, mTextSkewX, 0, 1, 0, 0));
}
// The metrics here don't have anti-aliasing set.
info.mMetrics = Toolkit.getDefaultToolkit().getFontMetrics(info.mFont);
infoList.add(info);
}
mFonts = Collections.unmodifiableList(infoList);
}
}
use of java.awt.geom.AffineTransform in project android_frameworks_base by ResurrectionRemix.
the class Canvas_Delegate method native_setMatrix.
@LayoutlibDelegate
public static void native_setMatrix(long nCanvas, long nMatrix) {
// get the delegate from the native int.
Canvas_Delegate canvasDelegate = sManager.getDelegate(nCanvas);
if (canvasDelegate == null) {
return;
}
Matrix_Delegate matrixDelegate = Matrix_Delegate.getDelegate(nMatrix);
if (matrixDelegate == null) {
return;
}
// get the current top graphics2D object.
GcSnapshot snapshot = canvasDelegate.getSnapshot();
// get the AffineTransform of the given matrix
AffineTransform matrixTx = matrixDelegate.getAffineTransform();
// give it to the graphics2D as a new matrix replacing all previous transform
snapshot.setTransform(matrixTx);
if (matrixDelegate.hasPerspective()) {
assert false;
Bridge.getLog().fidelityWarning(LayoutLog.TAG_MATRIX_AFFINE, "android.graphics.Canvas#setMatrix(android.graphics.Matrix) only " + "supports affine transformations.", null, null);
}
}
use of java.awt.geom.AffineTransform in project android_frameworks_base by ResurrectionRemix.
the class Canvas_Delegate method nativeDrawBitmapMatrix.
@LayoutlibDelegate
public static void nativeDrawBitmapMatrix(long nCanvas, Bitmap bitmap, long nMatrix, long 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(bitmap);
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);
}
Aggregations