正在查看: Plus 12 v10.13.1.1 应用的 BlurringShader.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Plus 12 v10.13.1.1 应用的 BlurringShader.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package org.telegram.ui.Components;
import android.animation.ValueAnimator;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.graphics.RenderNode;
import android.graphics.Shader;
import android.graphics.drawable.Drawable;
import android.opengl.GLES20;
import android.text.TextUtils;
import android.view.View;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.util.ArrayList;
import java.util.Iterator;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLContext;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.BuildConfig;
import org.telegram.messenger.DispatchQueue;
import org.telegram.messenger.ImageReceiver;
import org.telegram.messenger.LiteMode;
import org.telegram.messenger.R;
import org.telegram.messenger.Utilities;
import org.telegram.ui.Components.BlurringShader;
import org.telegram.ui.Components.Paint.Shader;
public class BlurringShader {
public Bitmap bitmap;
public boolean bitmapAvailable;
public final Object bitmapLock;
public ByteBuffer buffer;
public BlurManager currentManager;
public final int[] framebuffer;
public int gradientBottom;
public int gradientTop;
public int height;
public final Matrix iMatrix;
public final Runnable invalidateViews;
public final float[] m3x3;
public final float[] matrix;
public final Object matrixLock;
public FloatBuffer padPosBuffer;
public int padding;
public FloatBuffer posBuffer;
public Program[] program;
public boolean setupTransform;
public final int[] texture;
public FloatBuffer uvBuffer;
public int width;
public BlurringShader() {
this(null);
}
public BlurringShader(FilterGLThread parent) {
this.width = 1;
this.height = 1;
this.padding = 0;
this.program = new Program[2];
this.m3x3 = new float[9];
this.matrix = new float[16];
this.matrixLock = new Object();
this.bitmapLock = new Object();
this.framebuffer = new int[3];
this.texture = new int[3];
this.invalidateViews = new Runnable() {
@Override
public final void run() {
BlurringShader.this.lambda$new$0();
}
};
this.iMatrix = new Matrix();
}
public static class Program {
public int flipyHandle;
public int gl;
public int gradientBottomHandle;
public int gradientTopHandle;
public int hasVideoMatrixHandle;
public int matrixHandle;
public int posHandle;
public int stepHandle;
public int szHandle;
public int texHandle;
public int texSzHandle;
public int uvHandle;
public int videoMatrixHandle;
public Program(int gl) {
this.gl = gl;
this.posHandle = GLES20.glGetAttribLocation(gl, "p");
this.uvHandle = GLES20.glGetAttribLocation(gl, "inputuv");
this.matrixHandle = GLES20.glGetUniformLocation(gl, "matrix");
this.texHandle = GLES20.glGetUniformLocation(gl, "tex");
this.szHandle = GLES20.glGetUniformLocation(gl, "sz");
this.texSzHandle = GLES20.glGetUniformLocation(gl, "texSz");
this.gradientTopHandle = GLES20.glGetUniformLocation(gl, "gtop");
this.gradientBottomHandle = GLES20.glGetUniformLocation(gl, "gbottom");
this.stepHandle = GLES20.glGetUniformLocation(gl, "step");
this.videoMatrixHandle = GLES20.glGetUniformLocation(gl, "videoMatrix");
this.hasVideoMatrixHandle = GLES20.glGetUniformLocation(gl, "hasVideoMatrix");
this.flipyHandle = GLES20.glGetUniformLocation(gl, "flipy");
}
}
public boolean setup(float aspectRatio, boolean needsUiBitmap, int padding) {
this.width = (int) Math.round(Math.sqrt(aspectRatio * 324.0f));
this.height = (int) Math.round(Math.sqrt(324.0f / aspectRatio));
this.padding = padding;
if (!this.setupTransform) {
updateTransform(new Matrix(), 1, 1);
}
float[] fArr = {-1.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f};
ByteBuffer allocateDirect = ByteBuffer.allocateDirect(32);
allocateDirect.order(ByteOrder.nativeOrder());
FloatBuffer asFloatBuffer = allocateDirect.asFloatBuffer();
this.posBuffer = asFloatBuffer;
asFloatBuffer.put(fArr);
this.posBuffer.position(0);
for (int i = 0; i < 4; i++) {
int i2 = i * 2;
fArr[i2] = fArr[i2] * ((r10 - padding) / this.width);
int i3 = i2 + 1;
fArr[i3] = fArr[i3] * ((r10 - padding) / this.height);
}
ByteBuffer allocateDirect2 = ByteBuffer.allocateDirect(32);
allocateDirect2.order(ByteOrder.nativeOrder());
FloatBuffer asFloatBuffer2 = allocateDirect2.asFloatBuffer();
this.padPosBuffer = asFloatBuffer2;
asFloatBuffer2.put(fArr);
this.padPosBuffer.position(0);
ByteBuffer allocateDirect3 = ByteBuffer.allocateDirect(32);
allocateDirect3.order(ByteOrder.nativeOrder());
FloatBuffer asFloatBuffer3 = allocateDirect3.asFloatBuffer();
this.uvBuffer = asFloatBuffer3;
asFloatBuffer3.put(new float[]{0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f});
this.uvBuffer.position(0);
String readRes = RLottieDrawable.readRes(null, R.raw.blur_vrt);
String readRes2 = RLottieDrawable.readRes(null, R.raw.blur_frg);
if (readRes == null || readRes2 == null) {
return false;
}
for (int i4 = 0; i4 < 2; i4++) {
if (i4 == 1) {
readRes2 = "#extension GL_OES_EGL_image_external : require\n" + readRes2.replace("sampler2D tex", "samplerExternalOES tex");
}
int loadShader = FilterShaders.loadShader(35633, readRes);
int loadShader2 = FilterShaders.loadShader(35632, readRes2);
if (loadShader == 0 || loadShader2 == 0) {
return false;
}
int glCreateProgram = GLES20.glCreateProgram();
GLES20.glAttachShader(glCreateProgram, loadShader);
GLES20.glAttachShader(glCreateProgram, loadShader2);
GLES20.glBindAttribLocation(glCreateProgram, 0, "p");
GLES20.glBindAttribLocation(glCreateProgram, 1, "inputuv");
GLES20.glLinkProgram(glCreateProgram);
int[] iArr = new int[1];
GLES20.glGetProgramiv(glCreateProgram, 35714, iArr, 0);
if (iArr[0] == 0) {
GLES20.glDeleteProgram(glCreateProgram);
return false;
}
this.program[i4] = new Program(glCreateProgram);
}
GLES20.glGenFramebuffers(3, this.framebuffer, 0);
GLES20.glGenTextures(3, this.texture, 0);
int i5 = 0;
while (i5 < 3) {
GLES20.glBindTexture(3553, this.texture[i5]);
GLES20.glTexImage2D(3553, 0, 6408, this.width + (i5 == 2 ? padding * 2 : 0), this.height + (i5 == 2 ? padding * 2 : 0), 0, 6408, 5121, null);
GLES20.glTexParameteri(3553, 10242, 33071);
GLES20.glTexParameteri(3553, 10243, 33071);
GLES20.glTexParameteri(3553, 10241, 9729);
GLES20.glTexParameteri(3553, 10240, 9729);
GLES20.glBindFramebuffer(36160, this.framebuffer[i5]);
GLES20.glFramebufferTexture2D(36160, 36064, 3553, this.texture[i5], 0);
if (GLES20.glCheckFramebufferStatus(36160) != 36053) {
return false;
}
i5++;
}
GLES20.glBindFramebuffer(36160, 0);
if (needsUiBitmap) {
int i6 = padding * 2;
this.bitmap = Bitmap.createBitmap(this.width + i6, this.height + i6, Bitmap.Config.ARGB_8888);
this.buffer = ByteBuffer.allocateDirect((this.width + i6) * (i6 + this.height) * 4);
}
return true;
}
public void draw(float[] oesMatrix, int texture, int textureWidth, int textureHeight) {
char c = oesMatrix != null ? (char) 1 : (char) 0;
Program program = this.program[c];
if (program == null) {
return;
}
GLES20.glBindFramebuffer(36160, this.framebuffer[0]);
GLES20.glViewport(0, 0, this.width, this.height);
GLES20.glClear(LiteMode.FLAG_ANIMATED_EMOJI_KEYBOARD_NOT_PREMIUM);
GLES20.glUseProgram(program.gl);
GLES20.glUniform1i(program.texHandle, 0);
GLES20.glActiveTexture(33984);
if (c != 0) {
GLES20.glBindTexture(36197, texture);
} else {
GLES20.glBindTexture(3553, texture);
}
GLES20.glEnableVertexAttribArray(program.uvHandle);
GLES20.glVertexAttribPointer(program.uvHandle, 2, 5126, false, 8, (Buffer) this.uvBuffer);
GLES20.glEnableVertexAttribArray(program.posHandle);
GLES20.glVertexAttribPointer(program.posHandle, 2, 5126, false, 8, (Buffer) this.posBuffer);
GLES20.glUniform2f(program.szHandle, this.width, this.height);
float f = textureWidth;
float f2 = textureHeight;
GLES20.glUniform2f(program.texSzHandle, f, f2);
GLES20.glUniform1i(program.stepHandle, 0);
GLES20.glUniform1f(program.flipyHandle, c != 0 ? 1.0f : 0.0f);
if (c != 0) {
GLES20.glUniformMatrix4fv(program.videoMatrixHandle, 1, false, oesMatrix, 0);
}
GLES20.glUniform1f(program.hasVideoMatrixHandle, c == 0 ? 0.0f : 1.0f);
Shader.SetColorUniform(program.gradientTopHandle, this.gradientTop);
Shader.SetColorUniform(program.gradientBottomHandle, this.gradientBottom);
synchronized (this.matrixLock) {
GLES20.glUniformMatrix4fv(program.matrixHandle, 1, false, this.matrix, 0);
}
GLES20.glDrawArrays(5, 0, 4);
if (c != 0) {
program = this.program[0];
if (program == null) {
return;
}
GLES20.glUseProgram(program.gl);
GLES20.glEnableVertexAttribArray(program.uvHandle);
GLES20.glVertexAttribPointer(program.uvHandle, 2, 5126, false, 8, (Buffer) this.uvBuffer);
GLES20.glEnableVertexAttribArray(program.posHandle);
GLES20.glVertexAttribPointer(program.posHandle, 2, 5126, false, 8, (Buffer) this.posBuffer);
GLES20.glUniform2f(program.szHandle, this.width, this.height);
GLES20.glUniform2f(program.texSzHandle, f, f2);
GLES20.glUniform1i(program.stepHandle, 0);
Shader.SetColorUniform(program.gradientTopHandle, this.gradientTop);
Shader.SetColorUniform(program.gradientBottomHandle, this.gradientBottom);
GLES20.glUniform1f(program.flipyHandle, 0.0f);
synchronized (this.matrixLock) {
GLES20.glUniformMatrix4fv(program.matrixHandle, 1, false, this.matrix, 0);
}
}
GLES20.glBindFramebuffer(36160, this.framebuffer[1]);
GLES20.glUniform1i(program.stepHandle, 1);
GLES20.glUniform1i(program.texHandle, 0);
GLES20.glActiveTexture(33984);
GLES20.glBindTexture(3553, this.texture[0]);
GLES20.glDrawArrays(5, 0, 4);
GLES20.glBindFramebuffer(36160, this.framebuffer[2]);
int i = this.width;
int i2 = this.padding;
GLES20.glViewport(0, 0, i + (i2 * 2), this.height + (i2 * 2));
GLES20.glClear(LiteMode.FLAG_ANIMATED_EMOJI_KEYBOARD_NOT_PREMIUM);
GLES20.glEnableVertexAttribArray(program.posHandle);
GLES20.glVertexAttribPointer(program.posHandle, 2, 5126, false, 8, (Buffer) this.padPosBuffer);
GLES20.glUniform1i(program.stepHandle, 2);
GLES20.glUniform1i(program.texHandle, 0);
GLES20.glActiveTexture(33984);
GLES20.glBindTexture(3553, this.texture[1]);
BlurManager blurManager = this.currentManager;
Object textureLock = blurManager != null ? blurManager.getTextureLock() : null;
if (textureLock != null) {
synchronized (textureLock) {
GLES20.glDrawArrays(5, 0, 4);
}
} else {
GLES20.glDrawArrays(5, 0, 4);
}
ByteBuffer byteBuffer = this.buffer;
if (byteBuffer != null) {
byteBuffer.rewind();
int i3 = this.width;
int i4 = this.padding;
GLES20.glReadPixels(0, 0, i3 + (i4 * 2), this.height + (i4 * 2), 6408, 5121, this.buffer);
synchronized (this.bitmapLock) {
this.bitmap.copyPixelsFromBuffer(this.buffer);
this.bitmapAvailable = true;
}
GLES20.glBindFramebuffer(36160, 0);
}
AndroidUtilities.cancelRunOnUIThread(this.invalidateViews);
AndroidUtilities.runOnUIThread(this.invalidateViews);
}
public int getTexture() {
return this.texture[2];
}
public Bitmap getBitmap() {
synchronized (this.bitmapLock) {
if (!this.bitmapAvailable) {
return null;
}
return this.bitmap;
}
}
public void resetBitmap() {
synchronized (this.bitmapLock) {
this.bitmapAvailable = false;
}
}
public void updateGradient(int top, int bottom) {
this.gradientTop = top;
this.gradientBottom = bottom;
}
public void setBlurManager(BlurManager manager) {
BlurManager blurManager = this.currentManager;
if (blurManager != null) {
blurManager.setShader(null);
}
this.currentManager = manager;
if (manager != null) {
manager.setShader(this);
}
}
public void lambda$new$0() {
BlurManager blurManager = this.currentManager;
if (blurManager != null) {
blurManager.invalidate();
}
}
public void updateTransform(Matrix matrix, int w, int h) {
matrix.invert(this.iMatrix);
float f = w;
float f2 = h;
this.iMatrix.preScale(f, f2);
this.iMatrix.postScale(1.0f / f, 1.0f / f2);
updateTransform(this.iMatrix);
}
public void updateTransform(Matrix matrix) {
this.setupTransform = true;
matrix.getValues(this.m3x3);
synchronized (this.matrixLock) {
float[] fArr = this.matrix;
float[] fArr2 = this.m3x3;
fArr[0] = fArr2[0];
fArr[1] = fArr2[3];
fArr[2] = 0.0f;
fArr[3] = fArr2[6];
fArr[4] = fArr2[1];
fArr[5] = fArr2[4];
fArr[6] = 0.0f;
fArr[7] = fArr2[7];
fArr[8] = 0.0f;
fArr[9] = 0.0f;
fArr[10] = 1.0f;
fArr[11] = 0.0f;
fArr[12] = fArr2[2];
fArr[13] = fArr2[5];
fArr[14] = 0.0f;
fArr[15] = fArr2[8];
}
}
public static class BlurManager {
public EGLContext context;
public BlurringShader currentShader;
public Bitmap fallbackBitmap;
public int padding;
public final View view;
public final ArrayList<View> parents = new ArrayList<>();
public final ArrayList<StoryBlurDrawer> holders = new ArrayList<>();
public final ArrayList<Runnable> invalidateHolders = new ArrayList<>();
public final Object contextLock = new Object();
public final Object textureLock = new Object();
public final ThumbBlurer thumbBlurer = new ThumbBlurer(0, new Runnable() {
@Override
public final void run() {
BlurringShader.BlurManager.this.invalidateFallbackBlur();
}
});
public int i = 0;
public BlurManager(View parentView) {
this.view = parentView;
if (parentView.isAttachedToWindow()) {
updateParents();
}
parentView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
@Override
public void onViewAttachedToWindow(View v) {
BlurManager.this.updateParents();
}
@Override
public void onViewDetachedFromWindow(View v) {
BlurManager.this.parents.clear();
}
});
}
public EGLContext getParentContext() {
synchronized (this.contextLock) {
EGLContext eGLContext = this.context;
if (eGLContext != null) {
return eGLContext;
}
return EGL10.EGL_NO_CONTEXT;
}
}
public void acquiredContext(EGLContext newContext) {
synchronized (this.contextLock) {
if (this.context == null) {
this.context = newContext;
}
}
}
public void destroyedContext(EGLContext oldContext) {
synchronized (this.contextLock) {
if (this.context == oldContext) {
this.context = null;
}
}
}
public Object getTextureLock() {
return this.textureLock;
}
public int getTexture() {
BlurringShader blurringShader = this.currentShader;
if (blurringShader != null) {
return blurringShader.getTexture();
}
return -1;
}
public final void updateParents() {
this.parents.clear();
for (View view = this.view; view != null; view = (View) view.getParent()) {
this.parents.add(0, view);
if (!(view.getParent() instanceof View)) {
return;
}
}
}
public void setShader(BlurringShader shader) {
if (this.currentShader == shader) {
return;
}
this.currentShader = shader;
if (shader != null) {
invalidate();
}
}
public void invalidate() {
Iterator<StoryBlurDrawer> it = this.holders.iterator();
while (it.hasNext()) {
it.next().view.invalidate();
}
Iterator<Runnable> it2 = this.invalidateHolders.iterator();
while (it2.hasNext()) {
it2.next().run();
}
}
public void attach(StoryBlurDrawer holder) {
this.holders.add(holder);
}
public void detach(StoryBlurDrawer holder) {
this.holders.remove(holder);
if (this.invalidateHolders.isEmpty() && this.holders.isEmpty()) {
this.thumbBlurer.destroy();
}
}
public void attach(Runnable invalidate) {
this.invalidateHolders.add(invalidate);
}
public void detach(Runnable invalidate) {
this.invalidateHolders.remove(invalidate);
if (this.invalidateHolders.isEmpty() && this.holders.isEmpty()) {
this.thumbBlurer.destroy();
}
}
public Bitmap getBitmap() {
BlurringShader blurringShader = this.currentShader;
if (blurringShader == null) {
return this.fallbackBitmap;
}
Bitmap bitmap = blurringShader.getBitmap();
return bitmap == null ? this.fallbackBitmap : bitmap;
}
public final void invalidateFallbackBlur() {
this.fallbackBitmap = this.thumbBlurer.thumbBitmap;
invalidate();
}
public void setFallbackBlur(Bitmap bitmap, int orientation) {
setFallbackBlur(bitmap, orientation, false);
}
public void setFallbackBlur(Bitmap bitmap, int orientation, boolean recycleAfter) {
ThumbBlurer thumbBlurer = this.thumbBlurer;
StringBuilder sb = new StringBuilder();
sb.append(BuildConfig.APP_CENTER_HASH);
int i = this.i;
this.i = i + 1;
sb.append(i);
this.fallbackBitmap = thumbBlurer.getBitmap(bitmap, sb.toString(), orientation, 0, recycleAfter);
}
public void resetBitmap() {
BlurringShader blurringShader = this.currentShader;
if (blurringShader != null) {
blurringShader.resetBitmap();
}
}
}
public static class ThumbBlurer {
public final Paint clearPaint;
public Runnable generate;
public final Runnable invalidate;
public final int padding;
public Bitmap thumbBitmap;
public String thumbKey;
public ThumbBlurer(int padding, Runnable invalidate) {
Paint paint = new Paint(1);
this.clearPaint = paint;
this.padding = padding;
this.invalidate = invalidate;
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
}
public void destroy() {
this.thumbKey = null;
if (this.generate != null) {
Utilities.globalQueue.cancelRunnable(this.generate);
}
Bitmap bitmap = this.thumbBitmap;
if (bitmap != null && !bitmap.isRecycled()) {
this.thumbBitmap.recycle();
}
this.thumbBitmap = null;
}
public Bitmap getBitmap(final Bitmap bitmap, final String key, final int orientation, final int invert, final boolean recycleAfter) {
if (bitmap == null || bitmap.isRecycled()) {
return null;
}
if (TextUtils.equals(this.thumbKey, key)) {
Bitmap bitmap2 = this.thumbBitmap;
if (bitmap2 != null) {
return bitmap2;
}
if (this.generate != null) {
return null;
}
}
if (this.generate != null) {
Utilities.globalQueue.cancelRunnable(this.generate);
}
this.thumbKey = key;
DispatchQueue dispatchQueue = Utilities.globalQueue;
Runnable runnable = new Runnable() {
@Override
public final void run() {
BlurringShader.ThumbBlurer.this.lambda$getBitmap$1(bitmap, orientation, invert, key, recycleAfter);
}
};
this.generate = runnable;
dispatchQueue.postRunnable(runnable);
return this.thumbBitmap;
}
public void lambda$getBitmap$1(final Bitmap bitmap, int i, int i2, final String str, final boolean z) {
int i3;
int i4;
if (bitmap == null || bitmap.isRecycled()) {
return;
}
float width = bitmap.getWidth() / bitmap.getHeight();
int round = (int) Math.round(Math.sqrt(width * 324.0f));
int round2 = (int) Math.round(Math.sqrt(324.0f / width));
if (i == 90 || i == 270) {
i3 = round2;
i4 = round;
} else {
i4 = round2;
i3 = round;
}
int i5 = this.padding;
final Bitmap createBitmap = Bitmap.createBitmap((i5 * 2) + i3, (i5 * 2) + i4, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(createBitmap);
android.graphics.Rect rect = new android.graphics.Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
int i6 = this.padding;
android.graphics.Rect rect2 = new android.graphics.Rect(i6, i6, i6 + round, i6 + round2);
int i7 = this.padding;
canvas.translate(i7 + (i3 / 2.0f), i7 + (i4 / 2.0f));
if (i2 == 1) {
canvas.scale(-1.0f, 1.0f);
} else if (i2 == 2) {
canvas.scale(1.0f, -1.0f);
}
canvas.rotate(i);
int i8 = this.padding;
canvas.translate((-i8) - (round / 2.0f), (-i8) - (round2 / 2.0f));
canvas.drawBitmap(bitmap, rect, rect2, (Paint) null);
Utilities.stackBlurBitmap(createBitmap, 6);
int i9 = this.padding;
if (i9 > 0) {
canvas.drawRect(0.0f, 0.0f, round + i9, i9, this.clearPaint);
int i10 = this.padding;
canvas.drawRect(0.0f, i10, i10, i10 + round2, this.clearPaint);
canvas.drawRect(r0 + round, this.padding, r0 + round + r0, r0 + round2, this.clearPaint);
int i11 = this.padding;
canvas.drawRect(0.0f, i11 + round2, round + i11 + i11, round2 + i11 + i11, this.clearPaint);
}
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
BlurringShader.ThumbBlurer.this.lambda$getBitmap$0(str, createBitmap, z, bitmap);
}
});
}
public void lambda$getBitmap$0(String str, Bitmap bitmap, boolean z, Bitmap bitmap2) {
if (TextUtils.equals(this.thumbKey, str)) {
this.generate = null;
Bitmap bitmap3 = this.thumbBitmap;
if (bitmap3 != null) {
bitmap3.recycle();
}
this.thumbBitmap = bitmap;
Runnable runnable = this.invalidate;
if (runnable != null) {
runnable.run();
}
} else {
bitmap.recycle();
}
if (z) {
bitmap2.recycle();
}
}
public Bitmap getBitmap(ImageReceiver imageReceiver) {
if (imageReceiver == null) {
return null;
}
return getBitmap(imageReceiver.getBitmap(), imageReceiver.getImageKey(), imageReceiver.getOrientation(), imageReceiver.getInvert(), false);
}
public Bitmap getBitmap(ImageReceiver.BitmapHolder bitmapHolder) {
if (bitmapHolder == null) {
return null;
}
return getBitmap(bitmapHolder.bitmap, bitmapHolder.getKey(), bitmapHolder.orientation, 0, false);
}
}
public static class StoryBlurDrawer {
public boolean animateBitmapChange;
public BitmapShader bitmapShader;
public RectF bounds;
public final ColorMatrix colorMatrix;
public ValueAnimator crossfadeAnimator;
public boolean customOffset;
public float customOffsetX;
public float customOffsetY;
public Bitmap lastBitmap;
public final BlurManager manager;
public final Matrix matrix;
public Paint oldPaint;
public float oldPaintAlpha;
public boolean oldPaintSet;
public Paint paint;
public RenderNode renderNode;
public Paint[] tempPaints;
public final View view;
public boolean wasDark;
public StoryBlurDrawer(BlurManager manager, View view, int type) {
this(manager, view, type, false);
}
public StoryBlurDrawer(final BlurManager manager, View view, int type, boolean animateBitmapChange) {
this.oldPaint = new Paint(3);
this.paint = new Paint(3);
this.matrix = new Matrix();
this.bounds = new RectF();
this.wasDark = false;
this.manager = manager;
this.view = view;
this.animateBitmapChange = animateBitmapChange;
ColorMatrix colorMatrix = new ColorMatrix();
this.colorMatrix = colorMatrix;
if (type == 0) {
AndroidUtilities.adjustSaturationColorMatrix(colorMatrix, 0.45f);
} else if (type == 5) {
this.paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
this.oldPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
AndroidUtilities.adjustSaturationColorMatrix(colorMatrix, 0.3f);
} else if (type == 2) {
this.paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
this.oldPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
AndroidUtilities.adjustBrightnessColorMatrix(colorMatrix, 0.4f);
AndroidUtilities.adjustSaturationColorMatrix(colorMatrix, 0.3f);
} else if (type == 1) {
AndroidUtilities.adjustSaturationColorMatrix(colorMatrix, 0.35f);
AndroidUtilities.adjustBrightnessColorMatrix(colorMatrix, 0.7f);
AndroidUtilities.multiplyBrightnessColorMatrix(colorMatrix, 1.5f);
} else if (type == 3) {
AndroidUtilities.adjustSaturationColorMatrix(colorMatrix, 0.5f);
} else if (type == 4) {
AndroidUtilities.adjustSaturationColorMatrix(colorMatrix, 0.6f);
AndroidUtilities.adjustBrightnessColorMatrix(colorMatrix, 0.3f);
AndroidUtilities.multiplyBrightnessColorMatrix(colorMatrix, 1.2f);
} else if (type == 6) {
AndroidUtilities.adjustSaturationColorMatrix(colorMatrix, 0.4f);
AndroidUtilities.multiplyBrightnessColorMatrix(colorMatrix, 0.35f);
} else if (type == 7) {
AndroidUtilities.adjustSaturationColorMatrix(colorMatrix, 0.5f);
AndroidUtilities.multiplyBrightnessColorMatrix(colorMatrix, 0.95f);
} else if (type == 8) {
AndroidUtilities.adjustBrightnessColorMatrix(colorMatrix, -0.15f);
AndroidUtilities.adjustSaturationColorMatrix(colorMatrix, 0.47f);
} else if (type == 9) {
this.paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
this.oldPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
AndroidUtilities.adjustBrightnessColorMatrix(colorMatrix, 0.4f);
AndroidUtilities.adjustSaturationColorMatrix(colorMatrix, 0.45f);
} else if (type == 10) {
colorMatrix.setSaturation(1.6f);
AndroidUtilities.multiplyBrightnessColorMatrix(colorMatrix, this.wasDark ? 0.97f : 0.92f);
AndroidUtilities.adjustBrightnessColorMatrix(colorMatrix, this.wasDark ? 0.12f : -0.06f);
}
this.paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
this.oldPaint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
if (view.isAttachedToWindow() && manager != null) {
manager.attach(this);
}
view.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
@Override
public void onViewAttachedToWindow(View v) {
BlurManager blurManager = manager;
if (blurManager != null) {
blurManager.attach(StoryBlurDrawer.this);
}
}
@Override
public void onViewDetachedFromWindow(View v) {
BlurManager blurManager = manager;
if (blurManager != null) {
blurManager.detach(StoryBlurDrawer.this);
}
StoryBlurDrawer.this.recycle();
}
});
}
public final void updateBounds() {
Bitmap bitmap = this.manager.getBitmap();
if (bitmap == null) {
return;
}
if (this.bitmapShader == null || this.lastBitmap != bitmap) {
this.lastBitmap = bitmap;
Shader.TileMode tileMode = Shader.TileMode.CLAMP;
BitmapShader bitmapShader = new BitmapShader(bitmap, tileMode, tileMode);
this.bitmapShader = bitmapShader;
this.paint.setShader(bitmapShader);
}
float width = this.bounds.width() / this.lastBitmap.getWidth();
float height = this.bounds.height() / this.lastBitmap.getHeight();
this.matrix.reset();
Matrix matrix = this.matrix;
RectF rectF = this.bounds;
matrix.postTranslate(rectF.left, rectF.top);
this.matrix.preScale(width, height);
this.bitmapShader.setLocalMatrix(this.matrix);
}
public void setBounds(float left, float top, float right, float bottom) {
RectF rectF = AndroidUtilities.rectTmp;
rectF.set(left, top, right, bottom);
setBounds(rectF);
}
public void setBounds(RectF bounds) {
RectF rectF = this.bounds;
if (rectF.top == bounds.top && rectF.bottom == bounds.bottom && rectF.left == bounds.left && rectF.right == bounds.right) {
return;
}
rectF.set(bounds);
updateBounds();
}
public Paint getPaint(float alpha) {
return getPaint(alpha, 0.0f, 0.0f);
}
public Paint getPaint(float alpha, float tx, float ty) {
Bitmap bitmap;
Bitmap bitmap2;
BlurManager blurManager = this.manager;
if (blurManager == null || (bitmap = blurManager.getBitmap()) == null) {
return null;
}
BitmapShader bitmapShader = this.bitmapShader;
if (bitmapShader == null || this.lastBitmap != bitmap) {
if (this.animateBitmapChange && bitmapShader != null && (bitmap2 = this.lastBitmap) != null && !bitmap2.isRecycled() && !bitmap.isRecycled()) {
Paint paint = this.paint;
this.paint = this.oldPaint;
this.oldPaint = paint;
this.oldPaintSet = true;
animateOldPaint();
}
this.lastBitmap = bitmap;
Shader.TileMode tileMode = Shader.TileMode.CLAMP;
BitmapShader bitmapShader2 = new BitmapShader(bitmap, tileMode, tileMode);
this.bitmapShader = bitmapShader2;
this.paint.setShader(bitmapShader2);
}
if (!setupMatrix(bitmap.getWidth(), bitmap.getHeight())) {
return null;
}
this.matrix.postTranslate(-tx, -ty);
this.bitmapShader.setLocalMatrix(this.matrix);
this.paint.setAlpha((int) (alpha * 255.0f));
return this.paint;
}
public Paint[] getPaints(float alpha, float tx, float ty) {
Paint paint = getPaint(alpha, tx, ty);
boolean z = this.oldPaintSet;
Paint paint2 = z ? this.oldPaint : null;
if (paint != null && z) {
paint.setAlpha((int) ((1.0f - this.oldPaintAlpha) * 255.0f * alpha));
}
if (paint2 != null) {
paint2.setAlpha((int) (alpha * 255.0f));
}
if (this.tempPaints == null) {
this.tempPaints = new Paint[2];
}
Paint[] paintArr = this.tempPaints;
paintArr[0] = paint2;
paintArr[1] = paint;
return paintArr;
}
public final void animateOldPaint() {
ValueAnimator valueAnimator = this.crossfadeAnimator;
if (valueAnimator != null) {
valueAnimator.cancel();
this.crossfadeAnimator = null;
}
this.oldPaintAlpha = 1.0f;
ValueAnimator ofFloat = ValueAnimator.ofFloat(1.0f, 0.0f);
this.crossfadeAnimator = ofFloat;
ofFloat.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public final void onAnimationUpdate(ValueAnimator valueAnimator2) {
BlurringShader.StoryBlurDrawer.this.lambda$animateOldPaint$0(valueAnimator2);
}
});
this.crossfadeAnimator.start();
}
public void lambda$animateOldPaint$0(ValueAnimator valueAnimator) {
this.oldPaintAlpha = ((Float) valueAnimator.getAnimatedValue()).floatValue();
this.view.invalidate();
}
public final void recycle() {
this.lastBitmap = null;
Paint paint = this.paint;
this.bitmapShader = null;
paint.setShader(null);
}
public final boolean setupMatrix(int bitmapWidth, int bitmapHeight) {
BlurManager blurManager;
this.matrix.reset();
if (this.customOffset) {
this.matrix.postTranslate(-this.customOffsetX, -this.customOffsetY);
} else {
View view = this.view;
do {
this.matrix.preScale(1.0f / view.getScaleX(), 1.0f / view.getScaleY(), view.getPivotX(), view.getPivotY());
this.matrix.preRotate(-view.getRotation(), view.getPivotX(), view.getPivotY());
this.matrix.preTranslate(-view.getX(), -view.getY());
if (!(view.getParent() instanceof View) || (view = (View) view.getParent()) == null || (blurManager = this.manager) == null) {
break;
}
} while (!blurManager.parents.contains(view));
BlurManager blurManager2 = this.manager;
if (blurManager2 != null && blurManager2.view != view) {
int indexOf = this.manager.parents.indexOf(view) + 1;
while (indexOf >= 0 && indexOf < this.manager.parents.size()) {
View view2 = (View) this.manager.parents.get(indexOf);
if (view2 != null) {
this.matrix.postTranslate(view2.getX(), view2.getY());
this.matrix.postScale(1.0f / view2.getScaleX(), 1.0f / view2.getScaleY(), view2.getPivotX(), view2.getPivotY());
this.matrix.postRotate(view2.getRotation(), view2.getPivotX(), view2.getPivotY());
indexOf++;
}
}
}
}
BlurManager blurManager3 = this.manager;
if (blurManager3 != null && blurManager3.view != null) {
this.matrix.preScale(this.manager.view.getWidth() / bitmapWidth, this.manager.view.getHeight() / bitmapHeight);
}
return true;
}
public Drawable makeDrawable(final float offsetX, final float offsetY, final Drawable base, final float r) {
return new Drawable() {
public float alpha = 1.0f;
public final Paint dimPaint = new Paint(1);
@Override
public int getOpacity() {
return -2;
}
@Override
public void setColorFilter(ColorFilter colorFilter) {
}
public final Paint getPaint() {
Bitmap bitmap;
if (StoryBlurDrawer.this.manager == null || (bitmap = StoryBlurDrawer.this.manager.getBitmap()) == null) {
return null;
}
if (StoryBlurDrawer.this.bitmapShader == null || StoryBlurDrawer.this.lastBitmap != bitmap) {
StoryBlurDrawer storyBlurDrawer = StoryBlurDrawer.this;
StoryBlurDrawer.this.lastBitmap = bitmap;
Shader.TileMode tileMode = Shader.TileMode.CLAMP;
storyBlurDrawer.bitmapShader = new BitmapShader(bitmap, tileMode, tileMode);
StoryBlurDrawer storyBlurDrawer2 = StoryBlurDrawer.this;
storyBlurDrawer2.paint.setShader(storyBlurDrawer2.bitmapShader);
}
StoryBlurDrawer.this.matrix.reset();
StoryBlurDrawer.this.matrix.postTranslate((-StoryBlurDrawer.this.customOffsetX) - offsetX, (-StoryBlurDrawer.this.customOffsetY) - offsetY);
if (StoryBlurDrawer.this.manager.view != null) {
StoryBlurDrawer.this.matrix.preScale(StoryBlurDrawer.this.manager.view.getWidth() / bitmap.getWidth(), StoryBlurDrawer.this.manager.view.getHeight() / bitmap.getHeight());
}
StoryBlurDrawer.this.bitmapShader.setLocalMatrix(StoryBlurDrawer.this.matrix);
StoryBlurDrawer.this.paint.setAlpha((int) (this.alpha * 255.0f));
return StoryBlurDrawer.this.paint;
}
@Override
public void draw(Canvas canvas) {
Paint paint = getPaint();
android.graphics.Rect bounds = getBounds();
if (paint != null) {
if (base != null) {
canvas.saveLayerAlpha(bounds.left, bounds.top, bounds.right, bounds.bottom, 255, 31);
base.setBounds(bounds);
base.draw(canvas);
canvas.drawRect(bounds, paint);
canvas.restore();
getPadding(AndroidUtilities.rectTmp2);
RectF rectF = AndroidUtilities.rectTmp;
rectF.set(bounds.left + r0.left, bounds.top + r0.top, bounds.right - r0.right, bounds.bottom - r0.bottom);
this.dimPaint.setColor(1711276032);
float f = r;
canvas.drawRoundRect(rectF, f, f, this.dimPaint);
return;
}
if (r > 0.0f) {
RectF rectF2 = AndroidUtilities.rectTmp;
rectF2.set(bounds);
float f2 = r;
canvas.drawRoundRect(rectF2, f2, f2, paint);
} else {
canvas.drawRect(bounds, paint);
}
this.dimPaint.setColor(1711276032);
if (r > 0.0f) {
RectF rectF3 = AndroidUtilities.rectTmp;
rectF3.set(bounds);
float f3 = r;
canvas.drawRoundRect(rectF3, f3, f3, this.dimPaint);
return;
}
canvas.drawRect(bounds, this.dimPaint);
return;
}
Drawable drawable = base;
if (drawable != null) {
drawable.setBounds(bounds);
base.draw(canvas);
return;
}
this.dimPaint.setColor(-14145495);
if (r > 0.0f) {
RectF rectF4 = AndroidUtilities.rectTmp;
rectF4.set(bounds);
float f4 = r;
canvas.drawRoundRect(rectF4, f4, f4, this.dimPaint);
return;
}
canvas.drawRect(bounds, this.dimPaint);
}
@Override
public void setAlpha(int alpha) {
this.alpha = alpha / 255.0f;
}
@Override
public boolean getPadding(android.graphics.Rect padding) {
Drawable drawable = base;
if (drawable != null) {
return drawable.getPadding(padding);
}
padding.set(0, 0, 0, 0);
return true;
}
};
}
}
}