mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-03 09:26:51 +00:00
First pass at using hardware bitmaps
Bug: 35428783 Change-Id: Ife67b85f6e7e268826597ed9bccd9659841f67de
This commit is contained in:
@@ -50,49 +50,38 @@ public class ShadowGenerator {
|
||||
|
||||
private final int mIconSize;
|
||||
|
||||
private final Canvas mCanvas;
|
||||
private final Paint mBlurPaint;
|
||||
private final Paint mDrawPaint;
|
||||
private final BlurMaskFilter mDefaultBlurMaskFilter;
|
||||
|
||||
private ShadowGenerator(Context context) {
|
||||
mIconSize = LauncherAppState.getIDP(context).iconBitmapSize;
|
||||
mCanvas = new Canvas();
|
||||
mBlurPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
|
||||
mDrawPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
|
||||
mDefaultBlurMaskFilter = new BlurMaskFilter(mIconSize * BLUR_FACTOR, Blur.NORMAL);
|
||||
}
|
||||
|
||||
public synchronized Bitmap recreateIcon(Bitmap icon) {
|
||||
return recreateIcon(icon, true, mDefaultBlurMaskFilter, AMBIENT_SHADOW_ALPHA,
|
||||
KEY_SHADOW_ALPHA);
|
||||
public synchronized void recreateIcon(Bitmap icon, Canvas out) {
|
||||
recreateIcon(icon, mDefaultBlurMaskFilter, AMBIENT_SHADOW_ALPHA, KEY_SHADOW_ALPHA, out);
|
||||
}
|
||||
|
||||
public synchronized Bitmap recreateIcon(Bitmap icon, boolean resize,
|
||||
BlurMaskFilter blurMaskFilter, int ambientAlpha, int keyAlpha) {
|
||||
int width = resize ? mIconSize : icon.getWidth();
|
||||
int height = resize ? mIconSize : icon.getHeight();
|
||||
public synchronized void recreateIcon(Bitmap icon, BlurMaskFilter blurMaskFilter,
|
||||
int ambientAlpha, int keyAlpha, Canvas out) {
|
||||
int[] offset = new int[2];
|
||||
|
||||
mBlurPaint.setMaskFilter(blurMaskFilter);
|
||||
Bitmap shadow = icon.extractAlpha(mBlurPaint, offset);
|
||||
Bitmap result = Bitmap.createBitmap(width, height, Config.ARGB_8888);
|
||||
mCanvas.setBitmap(result);
|
||||
|
||||
// Draw ambient shadow
|
||||
mDrawPaint.setAlpha(ambientAlpha);
|
||||
mCanvas.drawBitmap(shadow, offset[0], offset[1], mDrawPaint);
|
||||
out.drawBitmap(shadow, offset[0], offset[1], mDrawPaint);
|
||||
|
||||
// Draw key shadow
|
||||
mDrawPaint.setAlpha(keyAlpha);
|
||||
mCanvas.drawBitmap(shadow, offset[0], offset[1] + KEY_SHADOW_DISTANCE * mIconSize, mDrawPaint);
|
||||
out.drawBitmap(shadow, offset[0], offset[1] + KEY_SHADOW_DISTANCE * mIconSize, mDrawPaint);
|
||||
|
||||
// Draw the icon
|
||||
mDrawPaint.setAlpha(255);
|
||||
mCanvas.drawBitmap(icon, 0, 0, mDrawPaint);
|
||||
|
||||
mCanvas.setBitmap(null);
|
||||
return result;
|
||||
out.drawBitmap(icon, 0, 0, mDrawPaint);
|
||||
}
|
||||
|
||||
public static ShadowGenerator getInstance(Context context) {
|
||||
|
||||
Reference in New Issue
Block a user