Skip to content

Commit

Permalink
Merge branch 'main' into feature/newstarchen-ImageScaleModes
Browse files Browse the repository at this point in the history
* main:
  Remove a  rule in lds that has no effect. (#1015)
  Update issue template.
  Fix bug when encode alpha png. (#1014)
  Replace ValueAnimator with PAGAnimator in PAGImageView (#975)
  Set the timer of PAGImageView through PAGAnimator. (#982)
  Using the correct OpenGL ES path, using RTLD_DEFAULT will link methods from non-system dynamic libraries. (#983)
  apply proguard-rules of pag in demo. (#980)
  Keep org.libpag.DisplayLink and org.libpag.PAGAnimator on Android. (#977)
  Only use GLClear when the color is opaque. (#974)
  Quick rejects based on blend mode. (#973)
  Add fault tolerance to avoid JNI crashes. (#972)
  Use tgfx::Task to release the hardware decoder in an async task. (#969)
  Fix the bug in TaskGroup where threads are frequently destroyed and recreated. (#968)
  Make Path.addArc() support adding segments of an ellipse. (#967)
  Add the getBounds method to the PAGView. (#966)
  Fix the  disk cache key generating with a PAGFile loaded from binary data. (#965)
  Make PAGAnimator holds a weak reference to the listener and remove the onAnimationFlush method. (#964)
  • Loading branch information
newstarchen committed Jun 26, 2023
2 parents 2cc6a65 + ab70f75 commit 6ec00b0
Show file tree
Hide file tree
Showing 54 changed files with 792 additions and 1,693 deletions.
31 changes: 31 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report_cn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: Bug 反馈
about: 反馈一个 Bug 帮助 PAG 改进 (中文用户专用)
title: ''
labels: ''
assignees: 'kevingpqi123'

---

<!--
请注意:目前我们使用 Issues 功能只用于记录 Bug,如果是日常使用问题请转到仓库的 Discussions 页面进行提问和交流。为了提高问题的解决效率,提问请统一按照以下模板尽可能详细地描述问题:
-->


## 【版本信息】

4.2.88

## 【平台信息】

Android 原生 | iOS 原生 | Web 浏览器 | 微信小程序 | Linux | Flutter | 其他

## 【预期的表现】
<!-- 详细描述想要实现的功能或预期的表现,推荐添加截图或视频演示问题。-->

## 【实际的情况】
<!-- 详细描述当前目标的阻塞点或实际的表现,推荐添加截图或视频演示问题。 -->

## 【Demo及附件】

<!-- 强烈推荐上传与问题关联的 PAG 素材,AE工程,或者可运行的 Demo,这样可以极大加快问题的定位解决。 -->
File renamed without changes.
11 changes: 8 additions & 3 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
blank_issues_enabled: false
contact_links:
-
about: "请通过 PAG 官方论坛进行 Bug 反馈或使用咨询(中文用户专用)"
name: 问题反馈
url: "https://bbs.pag.art"
about: "Please use PAG Discussions to ask usage questions or suggest new features (For English Speakers)"
name: Question & Feature Request
url: "https://github.com/Tencent/libpag/discussions/1017"

-
about: "请通过 PAG 论坛进行问题咨询或功能建议的相关交流(中文用户专用)"
name: 使用咨询 & 功能建议
url: "https://github.com/Tencent/libpag/discussions/1018"
27 changes: 0 additions & 27 deletions .github/ISSUE_TEMPLATE/feature_request.md

This file was deleted.

14 changes: 0 additions & 14 deletions .github/ISSUE_TEMPLATE/question.md

This file was deleted.

4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ android {
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro', project(':libpag').file('proguard-rules.pro')
}
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro', project(':libpag').file('proguard-rules.pro')
}
}

Expand Down
1 change: 0 additions & 1 deletion android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-keep class org.libpag.** {*;}
-keep class androidx.exifinterface.** {*;}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private void addPAGViewAndPlay() {
pagFile.replaceImage(0, pagImage);
}
pagView.setComposition(pagFile);
pagView.setRepeatCount(2);
pagView.setRepeatCount(0);
pagView.setOnClickListener(v -> {
if (pagView.isPlaying()) {
pagView.pause();
Expand Down
14 changes: 13 additions & 1 deletion android/libpag/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,16 @@

-keepclasseswithmembers class org.libpag.HardwareDecoder {
<methods>;
}
}

-keepclasseswithmembers class org.libpag.DisplayLink {
<methods>;
}

-keepclasseswithmembers class org.libpag.PAGAnimator {
private void onAnimationStart();
private void onAnimationEnd();
private void onAnimationCancel();
private void onAnimationRepeat();
private void onAnimationUpdate();
}
63 changes: 9 additions & 54 deletions android/libpag/src/main/java/org/libpag/HardwareDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,67 +246,22 @@ private VideoSurface getVideoSurface() {
return videoSurface;
}

private boolean released = false;

private void onRelease() {
if (released) {
return;
}
released = true;
releaseOutputBuffer();
releaseDecoder();
}

private void releaseDecoder() {
if (decoder == null) {
return;
}
releaseAsync(new Runnable() {
@Override
public void run() {
try {
decoder.stop();
} catch (Exception e) {
e.printStackTrace();
}

try {
decoder.release();
} catch (Exception e) {
e.printStackTrace();
}
decoder = null;
videoSurface.release();
}
});
}

private void releaseAsync(final Runnable runnable) {
if (runnable == null) {
return;
releaseOutputBuffer();
try {
decoder.stop();
} catch (Exception e) {
e.printStackTrace();
}
decoderThreadCount.getAndIncrement();
final HandlerThread releaseHandlerThread = new HandlerThread("libpag_GPUDecoder_release_decoder");
try {
releaseHandlerThread.start();
} catch (Exception | Error e) {
decoder.release();
} catch (Exception e) {
e.printStackTrace();
runnable.run();
return;
}
Handler releaseHandler = new Handler(releaseHandlerThread.getLooper());
releaseHandler.post(new Runnable() {
@Override
public void run() {
runnable.run();
decoderThreadCount.getAndDecrement();
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
releaseHandlerThread.quitSafely();
}
});
}
});
decoder = null;
videoSurface.release();
}
}
96 changes: 51 additions & 45 deletions android/libpag/src/main/java/org/libpag/PAGAnimator.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import org.extra.tools.LibraryLoadUtils;

import java.lang.ref.WeakReference;

/**
* PAGAnimator provides a simple timing engine for running animations.
*/
Expand All @@ -17,7 +19,7 @@ class PAGAnimator {
public interface Listener {
/**
* Notifies the start of the animation. It can be called from either the UI thread or the
* thread that calls the play() method.
* thread that calls the start() method.
*/
void onAnimationStart(PAGAnimator animator);

Expand All @@ -28,7 +30,7 @@ public interface Listener {

/**
* Notifies the cancellation of the animation. It can be called from either the UI thread or
* the thread that calls the stop() method.
* the thread that calls the cancel() method.
*/
void onAnimationCancel(PAGAnimator animator);

Expand All @@ -38,24 +40,19 @@ public interface Listener {
void onAnimationRepeat(PAGAnimator animator);

/**
* Notifies another frame of the animation has occurred. It can be called from either the UI
* thread or the thread that calls the play() method.
* Notifies another frame of the animation has occurred. It may be called from an arbitrary
* thread if the animation is running asynchronously.
*/
void onAnimationUpdate(PAGAnimator animator);

/**
* Notifies a new frame of the animation needs to be flushed. It may be called from an
* arbitrary thread if the animation is running asynchronously.
*/
void onAnimationFlush(PAGAnimator animator);
}


private Listener listener = null;
private WeakReference<Listener> weakListener = null;
private float animationScale = 1.0f;

/**
* Creates a new PAGAnimator with the specified updater.
* Creates a new PAGAnimator with the specified listener. PAGAnimator only holds a weak
* reference to the listener.
*/
public static PAGAnimator MakeFrom(Context context, Listener listener) {
if (listener == null) {
Expand All @@ -65,7 +62,7 @@ public static PAGAnimator MakeFrom(Context context, Listener listener) {
}

private PAGAnimator(Context context, Listener listener) {
this.listener = listener;
this.weakListener = new WeakReference<>(listener);
if (context != null) {
animationScale = Settings.Global.getFloat(context.getContentResolver(),
Settings.Global.ANIMATOR_DURATION_SCALE, 1.0f);
Expand Down Expand Up @@ -118,68 +115,77 @@ private PAGAnimator(Context context, Listener listener) {
public native void setProgress(double value);

/**
* Indicates whether the animation is playing.
* Indicates whether the animation is running.
*/
public native boolean isPlaying();
public native boolean isRunning();

/**
* Starts to play the animation from the current position. Calling the play() method when the
* animation is already playing has no effect. The play() method does not alter the animation's
* current position. However, if the animation previously reached its end, it will restart from
* the beginning.
* Starts the animation from the current position. Calling the start() method when the animation
* is already started has no effect. The start() method does not alter the animation's current
* position. However, if the animation previously reached its end, it will restart from the
* beginning.
*/
public void play() {
public void start() {
if (animationScale == 0.0f) {
Log.e("libpag", "PAGAnimator.play() The scale of animator duration is turned off!");
listener.onAnimationEnd(this);
Listener listener = weakListener.get();
if (listener != null) {
listener.onAnimationEnd(this);
}
return;
}
doPlay();
doStart();
}

private native void doPlay();

/**
* Cancels the animation at the current position. Calling the play() method can resume the
* animation from the last paused position.
*/
public native void pause();
private native void doStart();

/**
* Cancels the animation at the current position. Unlike pause(), stop() not only cancels the
* animation but also tries to cancel any async tasks, which may block the calling thread.
* Cancels the animation at the current position. Calling the start() method can resume the
* animation from the last canceled position.
*/
public native void stop();
public native void cancel();

/**
* Manually flush the animation to the current progress without altering its playing status. If
* the animation is already running n flushing task asynchronously, this action will not have
* any effect.
* Manually update the animation to the current progress without altering its playing status. If
* isSync is set to false, the calling thread won't be blocked. Please note that if the
* animation already has an ongoing asynchronous flushing task, this action won't have any
* effect.
*/
public native void flush();
public native void update();

private void onAnimationStart() {
listener.onAnimationStart(this);
Listener listener = weakListener.get();
if (listener != null) {
listener.onAnimationStart(this);
}
}

private void onAnimationEnd() {
listener.onAnimationEnd(this);
Listener listener = weakListener.get();
if (listener != null) {
listener.onAnimationEnd(this);
}
}

private void onAnimationCancel() {
listener.onAnimationCancel(this);
Listener listener = weakListener.get();
if (listener != null) {
listener.onAnimationCancel(this);
}
}

private void onAnimationRepeat() {
listener.onAnimationRepeat(this);
Listener listener = weakListener.get();
if (listener != null) {
listener.onAnimationRepeat(this);
}
}

private void onAnimationUpdate() {
listener.onAnimationUpdate(this);
}

private void onAnimationFlush() {
listener.onAnimationFlush(this);
Listener listener = weakListener.get();
if (listener != null) {
listener.onAnimationUpdate(this);
}
}

/**
Expand Down
Loading

0 comments on commit 6ec00b0

Please sign in to comment.