Skip to content

Commit

Permalink
Add support 16 KB page sizes for Android 15 (#847)
Browse files Browse the repository at this point in the history
Dependency versions bump
  • Loading branch information
koral-- authored Jul 10, 2024
1 parent e9ca4a1 commit 7a4ee0f
Show file tree
Hide file tree
Showing 23 changed files with 84 additions and 119 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#### SNAPSHOT
- Update NDK to 26.1.10909125
- Update Android Gradle plugin to 8.1.2
#### 1.2.29
- 2024-07-10 - [commits](https://github.com/koral--/android-gif-drawable/compare/v1.2.28...v1.2.29)
- Update NDK to 26.3.11579264
- Use Java 21 for building
- Update Android Gradle plugin to 8.5.0
- Minimum SDK version increased to 21
- Add binary compatibility check
- Add support 16 KB page sizes for Android 15, fixes [(#846)](https://github. com/koral--/android-gif-drawable/pull/846)

#### 1.2.28
- 2023-08-29 - [commits](https://github.com/koral--/android-gif-drawable/compare/v1.2.27...v1.2.28)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Bundled GIFLib via JNI is used to render frames. This way should be more efficie
Insert the following dependency to `build.gradle` file of your project.
```groovy
dependencies {
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.28'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.29'
}
```
Note that Maven central repository should be defined eg. in top-level `build.gradle` like this:
Expand Down
1 change: 1 addition & 0 deletions android-gif-drawable/src/main/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ list(APPEND LIBS
)

target_link_libraries(pl_droidsonroids_gif ${LIBS})
target_link_options(pl_droidsonroids_gif PRIVATE "-Wl,-z,max-page-size=16384")
4 changes: 3 additions & 1 deletion android-gif-drawable/src/main/c/giflib/dgif_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ DGifOpen(void *userData, InputFunc readFunc, int *Error) {
}

GifFile->Error = 0;
*Error = 0;
if (Error != NULL) {
*Error = 0;
}
/* What version of GIF? */
//Private->gif89 = (Buf[GIF_VERSION_POS] == '9');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;

Expand Down Expand Up @@ -250,13 +249,9 @@ public long getDrawableAllocationByteCount(@Nullable GifDrawable oldDrawable, @I
final int sampleSizeFactor = sampleSize * sampleSize;
final long bufferSize;
if (oldDrawable != null && !oldDrawable.mBuffer.isRecycled()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
bufferSize = oldDrawable.mBuffer.getAllocationByteCount();
} else {
bufferSize = oldDrawable.getFrameByteCount();
}
} else {
bufferSize = (mWidth * mHeight * 4) / sampleSizeFactor;
bufferSize = oldDrawable.mBuffer.getAllocationByteCount();
} else {
bufferSize = (mWidth * mHeight * 4L) / sampleSizeFactor;
}
return (mPixelsBytesCount / sampleSizeFactor) + bufferSize;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,13 +698,7 @@ public int getFrameByteCount() {
* @return possible size of the memory needed to store pixels of this object
*/
public long getAllocationByteCount() {
long byteCount = mNativeInfoHandle.getAllocationByteCount();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
byteCount += mBuffer.getAllocationByteCount();
} else {
byteCount += getFrameByteCount();
}
return byteCount;
return mNativeInfoHandle.getAllocationByteCount() + mBuffer.getAllocationByteCount();
}

/**
Expand Down Expand Up @@ -762,7 +756,7 @@ public int getPixel(@IntRange(from = 0) int x, @IntRange(from = 0) int y) {
}

@Override
protected void onBoundsChange(Rect bounds) {
protected void onBoundsChange(@NonNull Rect bounds) {
mDstRect.set(bounds);
if (mTransform != null) {
mTransform.onBoundsChange(bounds);
Expand Down Expand Up @@ -889,7 +883,7 @@ public void setTintMode(@Nullable PorterDuff.Mode tintMode) {
}

@Override
protected boolean onStateChange(int[] stateSet) {
protected boolean onStateChange(@NonNull int[] stateSet) {
if (mTint != null && mTintMode != null) {
mTintFilter = updateTintFilter(mTint, mTintMode);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Parcelable;
import androidx.annotation.RequiresApi;
import android.util.AttributeSet;
import android.widget.ImageButton;

Expand Down Expand Up @@ -65,7 +63,6 @@ public GifImageButton(Context context, AttributeSet attrs, int defStyle) {
* @param defStyleRes
* @see ImageButton#ImageButton(Context, AttributeSet, int, int)
*/
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
public GifImageButton(Context context, AttributeSet attrs, int defStyle, int defStyleRes) {
super(context, attrs, defStyle, defStyleRes);
postInit(GifViewUtils.initImageView(this, attrs, defStyle, defStyleRes));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Parcelable;
import androidx.annotation.RequiresApi;
import android.util.AttributeSet;
import android.widget.ImageView;

Expand Down Expand Up @@ -65,7 +63,6 @@ public GifImageView(Context context, AttributeSet attrs, int defStyle) {
* @param defStyleRes
* @see ImageView#ImageView(Context, AttributeSet, int, int)
*/
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
public GifImageView(Context context, AttributeSet attrs, int defStyle, int defStyleRes) {
super(context, attrs, defStyle, defStyleRes);
postInit(GifViewUtils.initImageView(this, attrs, defStyle, defStyleRes));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;

import androidx.annotation.FloatRange;
import androidx.annotation.IntRange;
import androidx.annotation.RequiresApi;

import android.system.ErrnoException;
import android.system.Os;
import android.view.Surface;
Expand All @@ -19,6 +14,9 @@
import java.io.InputStream;
import java.nio.ByteBuffer;

import androidx.annotation.FloatRange;
import androidx.annotation.IntRange;

/**
* Native library wrapper
*/
Expand Down Expand Up @@ -85,7 +83,6 @@ private static long openFileDescriptor(FileDescriptor fileDescriptor, long offse
return openNativeFileDescriptor(nativeFileDescriptor, offset);
}

@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
private static int getNativeFileDescriptor(FileDescriptor fileDescriptor, boolean closeOriginalDescriptor) throws GifIOException, ErrnoException {
try {
final int nativeFileDescriptor = createTempNativeFileDescriptor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Parcelable;
import androidx.annotation.RequiresApi;
import android.util.AttributeSet;
import android.widget.TextView;

Expand Down Expand Up @@ -70,7 +68,6 @@ public GifTextView(Context context, AttributeSet attrs, int defStyle) {
* @param defStyleRes
* @see TextView#TextView(Context, AttributeSet, int, int)
*/
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
public GifTextView(Context context, AttributeSet attrs, int defStyle, int defStyleRes) {
super(context, attrs, defStyle, defStyleRes);
init(attrs, defStyle, defStyleRes);
Expand Down Expand Up @@ -143,12 +140,8 @@ private Drawable getGifOrDefaultDrawable(int resId) {
// ignored
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return resources.getDrawable(resId, getContext().getTheme());
} else {
return resources.getDrawable(resId);
}
}
return resources.getDrawable(resId, getContext().getTheme());
}

@Override
public void setCompoundDrawablesWithIntrinsicBounds(int left, int top, int right, int bottom) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
import android.graphics.Matrix;
import android.graphics.RectF;
import android.graphics.SurfaceTexture;
import android.opengl.EGL14;
import android.opengl.GLES20;
import android.os.Build;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.TypedValue;
Expand All @@ -22,13 +19,6 @@
import androidx.annotation.FloatRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.egl.EGLSurface;

/**
* <p>{@link TextureView} which can display animated GIFs. GifTextureView can only be used in a
Expand Down Expand Up @@ -84,7 +74,6 @@ public GifTextureView(Context context, AttributeSet attrs, int defStyleAttr) {
init(attrs, defStyleAttr, 0);
}

@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
public GifTextureView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(attrs, defStyleAttr, defStyleRes);
Expand Down Expand Up @@ -142,7 +131,7 @@ public SurfaceTextureListener getSurfaceTextureListener() {
* @param surfaceTexture ignored
*/
@Override
public void setSurfaceTexture(SurfaceTexture surfaceTexture) {
public void setSurfaceTexture(@NonNull SurfaceTexture surfaceTexture) {
throw new UnsupportedOperationException("Changing SurfaceTexture is not supported");
}

Expand Down Expand Up @@ -241,7 +230,7 @@ public void run() {
}

@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
public void onSurfaceTextureAvailable(@NonNull SurfaceTexture surface, int width, int height) {
final GifTextureView gifTextureView = mGifTextureViewReference.get();
if (gifTextureView != null) {
gifTextureView.updateTextureViewSize(mGifInfoHandle);
Expand All @@ -250,20 +239,20 @@ public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int hei
}

@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
public void onSurfaceTextureSizeChanged(@NonNull SurfaceTexture surface, int width, int height) {
//no-op
}

@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
public boolean onSurfaceTextureDestroyed(@NonNull SurfaceTexture surface) {
isSurfaceValid.close();
mGifInfoHandle.postUnbindSurface();
interrupt();
return true;
}

@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
public void onSurfaceTextureUpdated(@NonNull SurfaceTexture surface) {
//no-op
}

Expand Down Expand Up @@ -479,6 +468,7 @@ public void setTransform(Matrix transform) {
* @see #setTransform(android.graphics.Matrix)
* @see #setScaleType(ScaleType)
*/
@NonNull
@Override
public Matrix getTransform(Matrix transform) {
if (transform == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.view.Surface;
import android.view.TextureView;

import androidx.annotation.NonNull;

class PlaceholderDrawingSurfaceTextureListener implements TextureView.SurfaceTextureListener {
private final GifTextureView.PlaceholderDrawListener mDrawer;

Expand All @@ -13,7 +15,7 @@ class PlaceholderDrawingSurfaceTextureListener implements TextureView.SurfaceTex
}

@Override
public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) {
public void onSurfaceTextureAvailable(@NonNull SurfaceTexture surfaceTexture, int width, int height) {
final Surface surface = new Surface(surfaceTexture);
final Canvas canvas = surface.lockCanvas(null);
mDrawer.onDrawPlaceholder(canvas);
Expand All @@ -22,17 +24,17 @@ public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width,
}

@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int width, int height) {
public void onSurfaceTextureSizeChanged(@NonNull SurfaceTexture surfaceTexture, int width, int height) {
//no-op
}

@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
public boolean onSurfaceTextureDestroyed(@NonNull SurfaceTexture surfaceTexture) {
return false;
}

@Override
public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
public void onSurfaceTextureUpdated(@NonNull SurfaceTexture surfaceTexture) {
//no-op
}
}
Loading

0 comments on commit 7a4ee0f

Please sign in to comment.