Skip to content

Commit

Permalink
update to 10.12.0 (4710)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkaraush committed May 2, 2024
1 parent a906f12 commit d494ea8
Show file tree
Hide file tree
Showing 294 changed files with 20,511 additions and 4,451 deletions.
1 change: 1 addition & 0 deletions TMessagesProj/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dependencies {
implementation 'com.google.guava:guava:31.1-android'

implementation 'com.google.android.gms:play-services-mlkit-subject-segmentation:16.0.0-beta1'
implementation 'com.google.android.gms:play-services-mlkit-image-labeling:16.0.8'
constraints {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0") {
because("kotlin-stdlib-jdk7 is now a part of kotlin-stdlib")
Expand Down
29 changes: 27 additions & 2 deletions TMessagesProj/jni/lottie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,34 @@ JNIEXPORT jlong Java_org_telegram_ui_Components_RLottieDrawable_getFramesCount(J
delete info;
return 0;
}
long frameCount = info->animation->totalFrame();
long framesCount = info->animation->totalFrame();
delete info;
return (jlong) frameCount;
return (jlong) framesCount;
}

JNIEXPORT jdouble Java_org_telegram_ui_Components_RLottieDrawable_getDuration(JNIEnv *env, jclass clazz, jstring src, jstring json) {
auto info = new LottieInfo();
char const *srcString = env->GetStringUTFChars(src, nullptr);
info->path = srcString;
if (json != nullptr) {
char const *jsonString = env->GetStringUTFChars(json, nullptr);
if (jsonString) {
info->animation = rlottie::Animation::loadFromData(jsonString, info->path, nullptr, FitzModifier::None);
env->ReleaseStringUTFChars(json, jsonString);
}
} else {
info->animation = rlottie::Animation::loadFromFile(info->path, nullptr, FitzModifier::None);
}
if (srcString) {
env->ReleaseStringUTFChars(src, srcString);
}
if (info->animation == nullptr) {
delete info;
return 0;
}
double duration = info->animation->duration();
delete info;
return (jdouble) duration;
}

JNIEXPORT jlong Java_org_telegram_ui_Components_RLottieDrawable_createWithJson(JNIEnv *env, jclass clazz, jstring json, jstring name, jintArray data, jintArray colorReplacement) {
Expand Down
23 changes: 18 additions & 5 deletions TMessagesProj/jni/webm_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ JNIEXPORT jlong JNICALL Java_org_telegram_messenger_video_WebmEncoder_createEnco
ctx->codec_ctx->time_base = (AVRational){ 1, fps };
ctx->codec_ctx->framerate = (AVRational){ fps, 1 };
ctx->codec_ctx->bit_rate = bitrate;
ctx->codec_ctx->gop_size = 10;
ctx->codec_ctx->max_b_frames = 1;
ctx->codec_ctx->rc_min_rate = bitrate / 8;
ctx->codec_ctx->rc_max_rate = bitrate;
// ctx->codec_ctx->rc_buffer_size = 2 * bitrate;

if (ctx->fmt_ctx->oformat->flags & AVFMT_GLOBALHEADER) {
ctx->codec_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
Expand Down Expand Up @@ -185,6 +186,9 @@ JNIEXPORT jboolean JNICALL Java_org_telegram_messenger_video_WebmEncoder_writeFr
pkt.stream_index = ctx->video_stream->index;

ret = av_interleaved_write_frame(ctx->fmt_ctx, &pkt);
if (ret < 0) {
LOGE("vp9: failed to av_interleaved_write_frame %d", ret);
}
av_packet_unref(&pkt);
}

Expand All @@ -200,13 +204,16 @@ JNIEXPORT void JNICALL Java_org_telegram_messenger_video_WebmEncoder_stop(
return;
}

avcodec_send_frame(ctx->codec_ctx, NULL);
int ret;
ret = avcodec_send_frame(ctx->codec_ctx, NULL);
if (ret < 0) {
LOGE("vp9: failed to avcodec_send_frame %d", ret);
}
AVPacket pkt;
av_init_packet(&pkt);
pkt.data = NULL;
pkt.size = 0;

int ret;
while (1) {
ret = avcodec_receive_packet(ctx->codec_ctx, &pkt);
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
Expand All @@ -220,10 +227,16 @@ JNIEXPORT void JNICALL Java_org_telegram_messenger_video_WebmEncoder_stop(
pkt.stream_index = ctx->video_stream->index;

ret = av_interleaved_write_frame(ctx->fmt_ctx, &pkt);
if (ret < 0) {
LOGE("vp9: failed to av_interleaved_write_frame %d", ret);
}
av_packet_unref(&pkt);
}

av_write_trailer(ctx->fmt_ctx);
ret = av_write_trailer(ctx->fmt_ctx);
if (ret < 0) {
LOGE("vp9: failed to av_write_trailer %d", ret);
}

if (ctx->frame) {
av_frame_free(&ctx->frame);
Expand Down
Binary file modified TMessagesProj/src/main/assets/models/coin_border.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
144 changes: 62 additions & 82 deletions TMessagesProj/src/main/assets/shaders/fragment3.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -27,102 +27,82 @@ uniform float time;
uniform mat4 world;

void main() {
vec3 vLightPosition2 = vec3(-400, 40, 400);
vec3 vLightPosition3 = vec3(0, 200, 400);
vec3 vLightPosition4 = vec3(0, 0, 100);
vec3 vLightPositionNormal = vec3(100, -200, 400);

vec3 vNormalW = normalize(vec3(world * vec4(vNormal, 0.0)));
vec3 vTextureNormal = normalize(texture2D(u_NormalMap, vUV + vec2(-f_xOffset, f_xOffset)).xyz * 2.0 - 1.0);
vec3 finalNormal = normalize(vNormalW + vTextureNormal);

vec3 color = texture2D(u_Texture, vUV).xyz;
vec3 viewDirectionW = normalize(cameraPosition - modelViewVertex);

float border = 0.0;
if (modelIndex == 0) {
border = 1.0;
} else if (modelIndex == 2) {
border = texture2D(u_Texture, vUV).a;
}

float modelDiffuse = 0.1;
if (!night && modelIndex != 1) {
modelDiffuse = 0.01;
}
float diffuse = max(dot(vNormalW, viewDirectionW), (1.0 - modelDiffuse));

vec2 uv = vUV;
if (modelIndex == 2) {
uv *= 2.0;
uv = fract(uv);
if (vUV.x > .5) {
uv.x = 1.0 - uv.x;
}
}
float mixValue = clamp(distance(uv.xy, vec2(0.0)), 0.0, 1.0);
vec4 gradientColorFinal = vec4(mix(gradientColor1, gradientColor2, mixValue), 1.0);

float modelNormalSpec = normalSpec, modelSpec1 = 0.0, modelSpec2 = 0.05;
uv.x = 1.0 - uv.x;

float darken = 1. - length(modelViewVertex - vec3(30., -75., 50.)) / 200.;

if (border > 0.) {
modelNormalSpec += border;
modelSpec1 += border;
modelSpec2 += border;
float diagonal = ((uv.x + uv.y) / 2.0 - .15) / .6;
vec3 baseColor;
if (modelIndex == 0) {
baseColor = mix(
vec3(0.95686, 0.47451, 0.93725),
vec3(0.46274, 0.49411, 0.9960),
diagonal
);
} else if (modelIndex == 3) {
baseColor = mix(
vec3(0.95686, 0.47451, 0.93725),
vec3(0.46274, 0.49411, 0.9960),
diagonal
);
baseColor = mix(baseColor, vec3(1.0), .3);
} else if (modelIndex == 1) {
baseColor = mix(
vec3(0.67059, 0.25490, 0.80000),
vec3(0.39608, 0.18824, 0.98039),
diagonal
);
} else {
baseColor = mix(
vec3(0.91373, 0.62353, 0.99608),
vec3(0.67451, 0.58824, 1.00000),
clamp((uv.y - .2) / .6, 0.0, 1.0)
);

baseColor = mix(baseColor, vec3(1.0), .1 + .45 * texture2D(u_Texture, vUV).a);
if (night) {
baseColor = mix(baseColor, vec3(.0), .06);
}
}

vec3 pos = modelViewVertex / 100.0 + .5;
vec3 norm = normalize(vec3(world * vec4(vNormal, 0.0)));

vec3 angleW = normalize(viewDirectionW + vLightPosition2);
float specComp2 = max(0., dot(finalNormal, angleW));
specComp2 = pow(specComp2, max(1., 128.)) * modelSpec1;
vec3 flecksLightPos = vec3(.5, .5, .5);
vec3 flecksLightDir = normalize(flecksLightPos - pos);
vec3 flecksReflectDir = reflect(-flecksLightDir, norm);
float flecksSpec = pow(max(dot(normalize(vec3(0.0) - pos), flecksReflectDir), 0.0), 8.0);
vec3 flecksNormal = normalize(texture2D(u_NormalMap, uv * 1.3 + vec2(.02, .06) * time).xyz * 2.0 - 1.0);
float flecks = max(flecksNormal.x, flecksNormal.y) * flecksSpec;
norm += flecksSpec * flecksNormal;
norm = normalize(norm);

angleW = normalize(viewDirectionW + vLightPosition4);
float specComp3 = max(0., dot(finalNormal, angleW));
specComp3 = pow(specComp3, max(1., 30.)) * modelSpec2;
vec3 lightPos = vec3(-3., -3., 20.);
vec3 lightDir = normalize(lightPos - pos);
float diffuse = max(dot(norm, lightDir), 0.0);

angleW = normalize(viewDirectionW + vLightPositionNormal);
float normalSpecComp = max(0., dot(finalNormal, angleW));
normalSpecComp = pow(normalSpecComp, max(1., 128.)) * modelNormalSpec;
float spec = 0.0;

angleW = normalize(viewDirectionW + vLightPosition2);
float normalSpecComp2 = max(0., dot(finalNormal, angleW));
normalSpecComp2 = pow(normalSpecComp2, max(1., 128.)) * modelNormalSpec;
lightPos = vec3(-3., -3., .5);
spec += 2.0 * pow(max(dot(normalize(vec3(0.0) - pos), reflect(-normalize(lightPos - pos), norm)), 0.0), 2.0);

vec4 normalSpecFinal = vec4(normalSpecColor, 0.0) * normalSpecComp2;
vec4 specFinal = vec4(color, 0.0) * (specComp2 + specComp3);
lightPos = vec3(-3., .5, 30.);
spec += (modelIndex == 1 ? 1.5 : 0.5) * pow(max(dot(normalize(vec3(0.0) - pos), reflect(-normalize(lightPos - pos), norm)), 0.0), 32.0);

// float snap = fract((-gl_FragCoord.x / resolution.x + gl_FragCoord.y / resolution.y) / 20.0 + .2 * time) > .9 ? 1. : 0.;
// lightPos = vec3(3., .5, .5);
// spec += pow(max(dot(normalize(vec3(0.0) - pos), reflect(-normalize(lightPos - pos), norm)), 0.0), 32.0);

vec4 fragColor = gradientColorFinal + specFinal;
vec4 backgroundColor = texture2D(u_BackgroundTexture, vec2(gradientPosition.x + (gl_FragCoord.x / resolution.x) * gradientPosition.y, gradientPosition.z + (1.0 - (gl_FragCoord.y / resolution.y)) * gradientPosition.w));
vec4 color4 = mix(backgroundColor, fragColor, diffuse);
if (night) {
angleW = normalize(viewDirectionW + vLightPosition2);
float normalSpecComp = max(0., dot(finalNormal, angleW));
normalSpecComp = pow(normalSpecComp, max(1., 128.));
if (normalSpecComp > .2 && modelIndex != 0) {
color4.rgb += vec3(.5) * max(0., vTextureNormal.x) * normalSpecComp;
}
if (modelIndex == 1) {
color4.rgb *= .9;
} else {
color4.rgb += vec3(1.0) * .17;
}
} else {
if (modelIndex == 1) {
if (darken > .5) {
color4.rgb *= vec3(0.78039, 0.77254, 0.95294);
} else {
color4.rgb *= vec3(0.83921, 0.83529, 0.96862);
}
} else {
if (darken > .5) {
color4.rgb *= vec3(.945098, .94117, 1.0);
color4.rgb += vec3(.06) * border;
}
}
if (modelIndex != 0) {
spec *= .25;
}
gl_FragColor = color4 * f_alpha;

vec3 color = baseColor;
color *= .94 + .22 * diffuse;
color = mix(color, vec3(1.0), spec);
// color = mix(color, vec3(1.0), 0.35 * flecks);

gl_FragColor = vec4(color, 1.0);
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,13 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -265,9 +271,11 @@ public class AndroidUtilities {

public static final RectF rectTmp = new RectF();
public static final Rect rectTmp2 = new Rect();
public static final int[] pointTmp2 = new int[2];

public static Pattern WEB_URL = null;
public static Pattern BAD_CHARS_PATTERN = null;
public static Pattern LONG_BAD_CHARS_PATTERN = null;
public static Pattern BAD_CHARS_MESSAGE_PATTERN = null;
public static Pattern BAD_CHARS_MESSAGE_LONG_PATTERN = null;
private static Pattern singleTagPatter = null;
Expand All @@ -276,6 +284,7 @@ public class AndroidUtilities {
try {
final String GOOD_IRI_CHAR = "a-zA-Z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF";
BAD_CHARS_PATTERN = Pattern.compile("[\u2500-\u25ff]");
LONG_BAD_CHARS_PATTERN = Pattern.compile("[\u4e00-\u9fff]");
BAD_CHARS_MESSAGE_LONG_PATTERN = Pattern.compile("[\u0300-\u036f\u2066-\u2067]+");
BAD_CHARS_MESSAGE_PATTERN = Pattern.compile("[\u2066-\u2067]+");
final Pattern IP_ADDRESS = Pattern.compile(
Expand Down Expand Up @@ -565,9 +574,13 @@ public void onClick(@NonNull View view) {
}

public static CharSequence replaceArrows(CharSequence text, boolean link) {
return replaceArrows(text, link, dp(8f / 3f), 0);
}

public static CharSequence replaceArrows(CharSequence text, boolean link, float translateX, float translateY) {
ColoredImageSpan span = new ColoredImageSpan(R.drawable.msg_mini_forumarrow, DynamicDrawableSpan.ALIGN_BOTTOM);
span.setScale(.88f, .88f);
span.translate(-dp(8f / 3f), 0);
span.translate(-translateX, translateY);
span.spaceScaleX = .8f;
if (link) {
span.useLinkPaintColor = link;
Expand All @@ -581,6 +594,23 @@ public static CharSequence replaceArrows(CharSequence text, boolean link) {
rightArrow.setSpan(span, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
text = AndroidUtilities.replaceMultipleCharSequence(">", text, rightArrow);

span = new ColoredImageSpan(R.drawable.msg_mini_forumarrow, DynamicDrawableSpan.ALIGN_BOTTOM);
span.setScale(.88f, .88f);
span.translate(translateX, translateY);
span.rotate(180f);
span.spaceScaleX = .8f;
if (link) {
span.useLinkPaintColor = link;
}

// SpannableString leftArrow = new SpannableString("< ");
// leftArrow.setSpan(span, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
// text = AndroidUtilities.replaceMultipleCharSequence("< ", text, leftArrow);

SpannableString leftArrow = new SpannableString("<");
leftArrow.setSpan(span, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
text = AndroidUtilities.replaceMultipleCharSequence("<", text, leftArrow);

return text;
}

Expand Down Expand Up @@ -938,14 +968,56 @@ private static void gatherLinks(ArrayList<LinkSpec> links, Spannable s, Pattern
return true;
};

@Deprecated // use addLinksSafe
public static boolean addLinks(Spannable text, int mask) {
return addLinks(text, mask, false);
}

@Deprecated // use addLinksSafe
public static boolean addLinks(Spannable text, int mask, boolean internalOnly) {
return addLinks(text, mask, internalOnly, true);
}

public static boolean addLinksSafe(Spannable text, int mask, boolean internalOnly, boolean removeOldReplacements) {
SpannableStringBuilder newText = new SpannableStringBuilder(text);
ExecutorService executor = Executors.newSingleThreadExecutor();
Callable<Boolean> task = () -> {
try {
return addLinks(newText, mask, internalOnly, removeOldReplacements);
} catch (Exception e) {
FileLog.e(e);
return false;
}
};
boolean success = false;
Future<Boolean> future = null;
try {
future = executor.submit(task);
success = future.get(200, TimeUnit.MILLISECONDS);
} catch (TimeoutException ex) {
if (future != null) {
future.cancel(true);
}
} catch (Exception ex) {
FileLog.e(ex);
} finally {
executor.shutdownNow();
}
if (success && text != null) {
URLSpan[] oldSpans = text.getSpans(0, text.length(), URLSpan.class);
for (int i = 0; i < oldSpans.length; ++i) {
text.removeSpan(oldSpans[i]);
}
URLSpan[] newSpans = newText.getSpans(0, newText.length(), URLSpan.class);
for (int i = 0; i < newSpans.length; ++i) {
text.setSpan(newSpans[i], newText.getSpanStart(newSpans[i]), newText.getSpanEnd(newSpans[i]), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return true;
}
return false;
}

@Deprecated // use addLinksSafe
public static boolean addLinks(Spannable text, int mask, boolean internalOnly, boolean removeOldReplacements) {
if (text == null || containsUnsupportedCharacters(text.toString()) || mask == 0) {
return false;
Expand Down
Loading

1 comment on commit d494ea8

@r3pr3ss10n
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How this update was approved? Video message are unwatchable now.

Please sign in to comment.