Skip to content

Commit d494ea8

Browse files
committed
update to 10.12.0 (4710)
1 parent a906f12 commit d494ea8

File tree

294 files changed

+20511
-4451
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

294 files changed

+20511
-4451
lines changed

TMessagesProj/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ dependencies {
4848
implementation 'com.google.guava:guava:31.1-android'
4949

5050
implementation 'com.google.android.gms:play-services-mlkit-subject-segmentation:16.0.0-beta1'
51+
implementation 'com.google.android.gms:play-services-mlkit-image-labeling:16.0.8'
5152
constraints {
5253
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0") {
5354
because("kotlin-stdlib-jdk7 is now a part of kotlin-stdlib")

TMessagesProj/jni/lottie.cpp

+27-2
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,34 @@ JNIEXPORT jlong Java_org_telegram_ui_Components_RLottieDrawable_getFramesCount(J
182182
delete info;
183183
return 0;
184184
}
185-
long frameCount = info->animation->totalFrame();
185+
long framesCount = info->animation->totalFrame();
186186
delete info;
187-
return (jlong) frameCount;
187+
return (jlong) framesCount;
188+
}
189+
190+
JNIEXPORT jdouble Java_org_telegram_ui_Components_RLottieDrawable_getDuration(JNIEnv *env, jclass clazz, jstring src, jstring json) {
191+
auto info = new LottieInfo();
192+
char const *srcString = env->GetStringUTFChars(src, nullptr);
193+
info->path = srcString;
194+
if (json != nullptr) {
195+
char const *jsonString = env->GetStringUTFChars(json, nullptr);
196+
if (jsonString) {
197+
info->animation = rlottie::Animation::loadFromData(jsonString, info->path, nullptr, FitzModifier::None);
198+
env->ReleaseStringUTFChars(json, jsonString);
199+
}
200+
} else {
201+
info->animation = rlottie::Animation::loadFromFile(info->path, nullptr, FitzModifier::None);
202+
}
203+
if (srcString) {
204+
env->ReleaseStringUTFChars(src, srcString);
205+
}
206+
if (info->animation == nullptr) {
207+
delete info;
208+
return 0;
209+
}
210+
double duration = info->animation->duration();
211+
delete info;
212+
return (jdouble) duration;
188213
}
189214

190215
JNIEXPORT jlong Java_org_telegram_ui_Components_RLottieDrawable_createWithJson(JNIEnv *env, jclass clazz, jstring json, jstring name, jintArray data, jintArray colorReplacement) {

TMessagesProj/jni/webm_encoder.c

+18-5
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ JNIEXPORT jlong JNICALL Java_org_telegram_messenger_video_WebmEncoder_createEnco
7070
ctx->codec_ctx->time_base = (AVRational){ 1, fps };
7171
ctx->codec_ctx->framerate = (AVRational){ fps, 1 };
7272
ctx->codec_ctx->bit_rate = bitrate;
73-
ctx->codec_ctx->gop_size = 10;
74-
ctx->codec_ctx->max_b_frames = 1;
73+
ctx->codec_ctx->rc_min_rate = bitrate / 8;
74+
ctx->codec_ctx->rc_max_rate = bitrate;
75+
// ctx->codec_ctx->rc_buffer_size = 2 * bitrate;
7576

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

187188
ret = av_interleaved_write_frame(ctx->fmt_ctx, &pkt);
189+
if (ret < 0) {
190+
LOGE("vp9: failed to av_interleaved_write_frame %d", ret);
191+
}
188192
av_packet_unref(&pkt);
189193
}
190194

@@ -200,13 +204,16 @@ JNIEXPORT void JNICALL Java_org_telegram_messenger_video_WebmEncoder_stop(
200204
return;
201205
}
202206

203-
avcodec_send_frame(ctx->codec_ctx, NULL);
207+
int ret;
208+
ret = avcodec_send_frame(ctx->codec_ctx, NULL);
209+
if (ret < 0) {
210+
LOGE("vp9: failed to avcodec_send_frame %d", ret);
211+
}
204212
AVPacket pkt;
205213
av_init_packet(&pkt);
206214
pkt.data = NULL;
207215
pkt.size = 0;
208216

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

222229
ret = av_interleaved_write_frame(ctx->fmt_ctx, &pkt);
230+
if (ret < 0) {
231+
LOGE("vp9: failed to av_interleaved_write_frame %d", ret);
232+
}
223233
av_packet_unref(&pkt);
224234
}
225235

226-
av_write_trailer(ctx->fmt_ctx);
236+
ret = av_write_trailer(ctx->fmt_ctx);
237+
if (ret < 0) {
238+
LOGE("vp9: failed to av_write_trailer %d", ret);
239+
}
227240

228241
if (ctx->frame) {
229242
av_frame_free(&ctx->frame);
-137 Bytes
Loading
Binary file not shown.

TMessagesProj/src/main/assets/shaders/fragment3.glsl

+62-82
Original file line numberDiff line numberDiff line change
@@ -27,102 +27,82 @@ uniform float time;
2727
uniform mat4 world;
2828

2929
void main() {
30-
vec3 vLightPosition2 = vec3(-400, 40, 400);
31-
vec3 vLightPosition3 = vec3(0, 200, 400);
32-
vec3 vLightPosition4 = vec3(0, 0, 100);
33-
vec3 vLightPositionNormal = vec3(100, -200, 400);
34-
35-
vec3 vNormalW = normalize(vec3(world * vec4(vNormal, 0.0)));
36-
vec3 vTextureNormal = normalize(texture2D(u_NormalMap, vUV + vec2(-f_xOffset, f_xOffset)).xyz * 2.0 - 1.0);
37-
vec3 finalNormal = normalize(vNormalW + vTextureNormal);
38-
39-
vec3 color = texture2D(u_Texture, vUV).xyz;
40-
vec3 viewDirectionW = normalize(cameraPosition - modelViewVertex);
41-
42-
float border = 0.0;
43-
if (modelIndex == 0) {
44-
border = 1.0;
45-
} else if (modelIndex == 2) {
46-
border = texture2D(u_Texture, vUV).a;
47-
}
48-
49-
float modelDiffuse = 0.1;
50-
if (!night && modelIndex != 1) {
51-
modelDiffuse = 0.01;
52-
}
53-
float diffuse = max(dot(vNormalW, viewDirectionW), (1.0 - modelDiffuse));
54-
5530
vec2 uv = vUV;
5631
if (modelIndex == 2) {
5732
uv *= 2.0;
5833
uv = fract(uv);
59-
if (vUV.x > .5) {
60-
uv.x = 1.0 - uv.x;
61-
}
6234
}
63-
float mixValue = clamp(distance(uv.xy, vec2(0.0)), 0.0, 1.0);
64-
vec4 gradientColorFinal = vec4(mix(gradientColor1, gradientColor2, mixValue), 1.0);
65-
66-
float modelNormalSpec = normalSpec, modelSpec1 = 0.0, modelSpec2 = 0.05;
35+
uv.x = 1.0 - uv.x;
6736

68-
float darken = 1. - length(modelViewVertex - vec3(30., -75., 50.)) / 200.;
69-
70-
if (border > 0.) {
71-
modelNormalSpec += border;
72-
modelSpec1 += border;
73-
modelSpec2 += border;
37+
float diagonal = ((uv.x + uv.y) / 2.0 - .15) / .6;
38+
vec3 baseColor;
39+
if (modelIndex == 0) {
40+
baseColor = mix(
41+
vec3(0.95686, 0.47451, 0.93725),
42+
vec3(0.46274, 0.49411, 0.9960),
43+
diagonal
44+
);
45+
} else if (modelIndex == 3) {
46+
baseColor = mix(
47+
vec3(0.95686, 0.47451, 0.93725),
48+
vec3(0.46274, 0.49411, 0.9960),
49+
diagonal
50+
);
51+
baseColor = mix(baseColor, vec3(1.0), .3);
52+
} else if (modelIndex == 1) {
53+
baseColor = mix(
54+
vec3(0.67059, 0.25490, 0.80000),
55+
vec3(0.39608, 0.18824, 0.98039),
56+
diagonal
57+
);
58+
} else {
59+
baseColor = mix(
60+
vec3(0.91373, 0.62353, 0.99608),
61+
vec3(0.67451, 0.58824, 1.00000),
62+
clamp((uv.y - .2) / .6, 0.0, 1.0)
63+
);
64+
65+
baseColor = mix(baseColor, vec3(1.0), .1 + .45 * texture2D(u_Texture, vUV).a);
66+
if (night) {
67+
baseColor = mix(baseColor, vec3(.0), .06);
68+
}
7469
}
7570

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

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

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

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

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

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

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

98-
vec4 fragColor = gradientColorFinal + specFinal;
99-
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));
100-
vec4 color4 = mix(backgroundColor, fragColor, diffuse);
101-
if (night) {
102-
angleW = normalize(viewDirectionW + vLightPosition2);
103-
float normalSpecComp = max(0., dot(finalNormal, angleW));
104-
normalSpecComp = pow(normalSpecComp, max(1., 128.));
105-
if (normalSpecComp > .2 && modelIndex != 0) {
106-
color4.rgb += vec3(.5) * max(0., vTextureNormal.x) * normalSpecComp;
107-
}
108-
if (modelIndex == 1) {
109-
color4.rgb *= .9;
110-
} else {
111-
color4.rgb += vec3(1.0) * .17;
112-
}
113-
} else {
114-
if (modelIndex == 1) {
115-
if (darken > .5) {
116-
color4.rgb *= vec3(0.78039, 0.77254, 0.95294);
117-
} else {
118-
color4.rgb *= vec3(0.83921, 0.83529, 0.96862);
119-
}
120-
} else {
121-
if (darken > .5) {
122-
color4.rgb *= vec3(.945098, .94117, 1.0);
123-
color4.rgb += vec3(.06) * border;
124-
}
125-
}
98+
if (modelIndex != 0) {
99+
spec *= .25;
126100
}
127-
gl_FragColor = color4 * f_alpha;
101+
102+
vec3 color = baseColor;
103+
color *= .94 + .22 * diffuse;
104+
color = mix(color, vec3(1.0), spec);
105+
// color = mix(color, vec3(1.0), 0.35 * flecks);
106+
107+
gl_FragColor = vec4(color, 1.0);
128108
}

TMessagesProj/src/main/java/org/telegram/messenger/AndroidUtilities.java

+73-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,13 @@
207207
import java.util.List;
208208
import java.util.Locale;
209209
import java.util.Map;
210+
import java.util.concurrent.Callable;
210211
import java.util.concurrent.CountDownLatch;
212+
import java.util.concurrent.ExecutorService;
213+
import java.util.concurrent.Executors;
214+
import java.util.concurrent.Future;
215+
import java.util.concurrent.TimeUnit;
216+
import java.util.concurrent.TimeoutException;
211217
import java.util.concurrent.atomic.AtomicBoolean;
212218
import java.util.concurrent.atomic.AtomicReference;
213219
import java.util.regex.Matcher;
@@ -265,9 +271,11 @@ public class AndroidUtilities {
265271

266272
public static final RectF rectTmp = new RectF();
267273
public static final Rect rectTmp2 = new Rect();
274+
public static final int[] pointTmp2 = new int[2];
268275

269276
public static Pattern WEB_URL = null;
270277
public static Pattern BAD_CHARS_PATTERN = null;
278+
public static Pattern LONG_BAD_CHARS_PATTERN = null;
271279
public static Pattern BAD_CHARS_MESSAGE_PATTERN = null;
272280
public static Pattern BAD_CHARS_MESSAGE_LONG_PATTERN = null;
273281
private static Pattern singleTagPatter = null;
@@ -276,6 +284,7 @@ public class AndroidUtilities {
276284
try {
277285
final String GOOD_IRI_CHAR = "a-zA-Z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF";
278286
BAD_CHARS_PATTERN = Pattern.compile("[\u2500-\u25ff]");
287+
LONG_BAD_CHARS_PATTERN = Pattern.compile("[\u4e00-\u9fff]");
279288
BAD_CHARS_MESSAGE_LONG_PATTERN = Pattern.compile("[\u0300-\u036f\u2066-\u2067]+");
280289
BAD_CHARS_MESSAGE_PATTERN = Pattern.compile("[\u2066-\u2067]+");
281290
final Pattern IP_ADDRESS = Pattern.compile(
@@ -565,9 +574,13 @@ public void onClick(@NonNull View view) {
565574
}
566575

567576
public static CharSequence replaceArrows(CharSequence text, boolean link) {
577+
return replaceArrows(text, link, dp(8f / 3f), 0);
578+
}
579+
580+
public static CharSequence replaceArrows(CharSequence text, boolean link, float translateX, float translateY) {
568581
ColoredImageSpan span = new ColoredImageSpan(R.drawable.msg_mini_forumarrow, DynamicDrawableSpan.ALIGN_BOTTOM);
569582
span.setScale(.88f, .88f);
570-
span.translate(-dp(8f / 3f), 0);
583+
span.translate(-translateX, translateY);
571584
span.spaceScaleX = .8f;
572585
if (link) {
573586
span.useLinkPaintColor = link;
@@ -581,6 +594,23 @@ public static CharSequence replaceArrows(CharSequence text, boolean link) {
581594
rightArrow.setSpan(span, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
582595
text = AndroidUtilities.replaceMultipleCharSequence(">", text, rightArrow);
583596

597+
span = new ColoredImageSpan(R.drawable.msg_mini_forumarrow, DynamicDrawableSpan.ALIGN_BOTTOM);
598+
span.setScale(.88f, .88f);
599+
span.translate(translateX, translateY);
600+
span.rotate(180f);
601+
span.spaceScaleX = .8f;
602+
if (link) {
603+
span.useLinkPaintColor = link;
604+
}
605+
606+
// SpannableString leftArrow = new SpannableString("< ");
607+
// leftArrow.setSpan(span, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
608+
// text = AndroidUtilities.replaceMultipleCharSequence("< ", text, leftArrow);
609+
610+
SpannableString leftArrow = new SpannableString("<");
611+
leftArrow.setSpan(span, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
612+
text = AndroidUtilities.replaceMultipleCharSequence("<", text, leftArrow);
613+
584614
return text;
585615
}
586616

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

971+
@Deprecated // use addLinksSafe
941972
public static boolean addLinks(Spannable text, int mask) {
942973
return addLinks(text, mask, false);
943974
}
944975

976+
@Deprecated // use addLinksSafe
945977
public static boolean addLinks(Spannable text, int mask, boolean internalOnly) {
946978
return addLinks(text, mask, internalOnly, true);
947979
}
948980

981+
public static boolean addLinksSafe(Spannable text, int mask, boolean internalOnly, boolean removeOldReplacements) {
982+
SpannableStringBuilder newText = new SpannableStringBuilder(text);
983+
ExecutorService executor = Executors.newSingleThreadExecutor();
984+
Callable<Boolean> task = () -> {
985+
try {
986+
return addLinks(newText, mask, internalOnly, removeOldReplacements);
987+
} catch (Exception e) {
988+
FileLog.e(e);
989+
return false;
990+
}
991+
};
992+
boolean success = false;
993+
Future<Boolean> future = null;
994+
try {
995+
future = executor.submit(task);
996+
success = future.get(200, TimeUnit.MILLISECONDS);
997+
} catch (TimeoutException ex) {
998+
if (future != null) {
999+
future.cancel(true);
1000+
}
1001+
} catch (Exception ex) {
1002+
FileLog.e(ex);
1003+
} finally {
1004+
executor.shutdownNow();
1005+
}
1006+
if (success && text != null) {
1007+
URLSpan[] oldSpans = text.getSpans(0, text.length(), URLSpan.class);
1008+
for (int i = 0; i < oldSpans.length; ++i) {
1009+
text.removeSpan(oldSpans[i]);
1010+
}
1011+
URLSpan[] newSpans = newText.getSpans(0, newText.length(), URLSpan.class);
1012+
for (int i = 0; i < newSpans.length; ++i) {
1013+
text.setSpan(newSpans[i], newText.getSpanStart(newSpans[i]), newText.getSpanEnd(newSpans[i]), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
1014+
}
1015+
return true;
1016+
}
1017+
return false;
1018+
}
1019+
1020+
@Deprecated // use addLinksSafe
9491021
public static boolean addLinks(Spannable text, int mask, boolean internalOnly, boolean removeOldReplacements) {
9501022
if (text == null || containsUnsupportedCharacters(text.toString()) || mask == 0) {
9511023
return false;

0 commit comments

Comments
 (0)