Skip to content

Commit

Permalink
#173 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
koral-- committed Jun 11, 2015
1 parent 5edbb89 commit 66116f9
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 28 deletions.
3 changes: 3 additions & 0 deletions src/main/java/pl/droidsonroids/gif/GifTextureView.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public class GifTextureView extends TextureView {
static {
System.loadLibrary("pl_droidsonroids_gif_surface");
}

private ScaleType mScaleType = ScaleType.FIT_CENTER;
private final Matrix mTransform = new Matrix();
Expand Down
11 changes: 7 additions & 4 deletions src/main/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE := pl_droidsonroids_gif
LOCAL_CFLAGS := -Ofast -DDEBUG
LOCAL_CFLAGS := -Ofast
#-DDEBUG
LOCAL_LDLIBS := \
-ljnigraphics \
-llog \
Expand All @@ -16,6 +17,7 @@ LOCAL_SRC_FILES := \
open_close.c \
decoding.c \
exception.c \
surface_common.c \
time.c \
control.c \
memset.arm.S \
Expand All @@ -28,12 +30,13 @@ include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)

LOCAL_MODULE := pl_droidsonroids_gif_surface
LOCAL_CFLAGS := -Ofast -DDEBUG
LOCAL_CFLAGS := -Ofast
#-DDEBUG
LOCAL_LDLIBS := \
-landroid \
-llog \
-landroid

LOCAL_SRC_FILES := \
surface.c \

LOCAL_SHARED_LIBRARIES := pl_droidsonroids_gif
include $(BUILD_SHARED_LIBRARY)
4 changes: 2 additions & 2 deletions src/main/jni/Application.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
APP_ABI := all
APP_PLATFORM := android-21
APP_OPTIM := debug
APP_OPTIM := release

#NDK_TOOLCHAIN_VERSION := clang
NDK_TOOLCHAIN_VERSION := clang
2 changes: 1 addition & 1 deletion src/main/jni/drawing.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static inline void disposeFrameIfNeeded(argb *bm, GifInfo *info) {
memcpy(backup, bm, info->stride * fGif->SHeight * sizeof(argb));
}

inline void prepareCanvas(argb *bm, GifInfo *info) {
void prepareCanvas(argb *bm, GifInfo *info) {
if (info->gifFilePtr->SColorMap && info->controlBlock->TransparentColor == NO_TRANSPARENT_COLOR) {
argb bgColArgb;
bgColArgb.rgb = info->gifFilePtr->SColorMap->Colors[info->gifFilePtr->SBackGroundColor];
Expand Down
4 changes: 2 additions & 2 deletions src/main/jni/gif.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ inline JNIEnv *getEnv() {
return NULL;
}

inline void DetachCurrentThread() {
void DetachCurrentThread() {
(*g_jvm)->DetachCurrentThread(g_jvm);
}

Expand Down Expand Up @@ -395,6 +395,6 @@ __unused JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *__unused vm, void *__unused
GifFreeMapObject(defaultCmap);
}

inline ColorMapObject *getDefColorMap() {
ColorMapObject *getDefColorMap() {
return defaultCmap;
}
17 changes: 12 additions & 5 deletions src/main/jni/gif.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef _GIF
#define _GIF

#include <unistd.h>
#include <jni.h>
#include <android/native_window_jni.h>
Expand All @@ -19,6 +22,8 @@
#include <errno.h>
#include "giflib/gif_lib.h"

#define THROW_ON_NONZERO_RESULT(fun, message) if (fun !=0) throwException(env, ILLEGAL_STATE_EXCEPTION_ERRNO, message)

#ifdef DEBUG
#include <android/log.h>
#define LOG_TAG "libgif"
Expand Down Expand Up @@ -134,14 +139,14 @@ typedef struct {
jlong sourceLength;
} GifSourceDescriptor;

inline void DetachCurrentThread();
void DetachCurrentThread();

inline ColorMapObject* getDefColorMap();
ColorMapObject* getDefColorMap();

/**
* @return the real time, in ms
*/
inline long getRealTime();
long getRealTime();

/**
* Frees dynamically allocated memory
Expand Down Expand Up @@ -202,8 +207,10 @@ jint restoreSavedState(GifInfo *info, JNIEnv *env, jlongArray state, void *pixel

void releaseSurfaceDescriptor(SurfaceDescriptor *surfaceDescriptor, JNIEnv *pConst);

inline void prepareCanvas(argb *bm, GifInfo *info);
void prepareCanvas(argb *bm, GifInfo *info);

void drawNextBitmap(argb *bm, GifInfo *info);

uint_fast32_t getFrameDuration(GifInfo *info);
uint_fast32_t getFrameDuration(GifInfo *info);

#endif
13 changes: 0 additions & 13 deletions src/main/jni/surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
typedef uint64_t POLL_TYPE;
#define POLL_TYPE_SIZE sizeof(POLL_TYPE)

#define THROW_ON_NONZERO_RESULT(fun, message) if (fun !=0) throwException(env, ILLEGAL_STATE_EXCEPTION_ERRNO, message)
#define THROW_AND_BREAK_ON_NONZERO_RESULT(fun, message) if (fun !=0) {throwException(env, ILLEGAL_STATE_EXCEPTION_ERRNO, message); break;}

static void *slurp(void *pVoidInfo) {
Expand Down Expand Up @@ -49,18 +48,6 @@ static inline bool initSurfaceDescriptor(SurfaceDescriptor *surfaceDescriptor, J
return true;
}

void releaseSurfaceDescriptor(SurfaceDescriptor *surfaceDescriptor, JNIEnv *env) {
if (surfaceDescriptor == NULL)
return;
free(surfaceDescriptor->surfaceBackupPtr);
surfaceDescriptor->surfaceBackupPtr = NULL;
THROW_ON_NONZERO_RESULT(close(surfaceDescriptor->eventPollFd.fd), "eventfd close failed");
THROW_ON_NONZERO_RESULT(pthread_mutex_destroy(&surfaceDescriptor->slurpMutex), "slurp mutex destroy failed");
THROW_ON_NONZERO_RESULT(pthread_mutex_destroy(&surfaceDescriptor->renderMutex), "render mutex destroy failed");
THROW_ON_NONZERO_RESULT(pthread_cond_destroy(&surfaceDescriptor->slurpCond), "slurp cond destroy failed");
THROW_ON_NONZERO_RESULT(pthread_cond_destroy(&surfaceDescriptor->renderCond), "render cond destroy failed");
}

__unused JNIEXPORT void JNICALL
Java_pl_droidsonroids_gif_GifInfoHandle_bindSurface(JNIEnv *env, jclass __unused handleClass, jlong gifInfo,
jobject jsurface, jlongArray savedState, jboolean isOpaque) {
Expand Down
13 changes: 13 additions & 0 deletions src/main/jni/surface_common.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "gif.h"

void releaseSurfaceDescriptor(SurfaceDescriptor *surfaceDescriptor, JNIEnv *env) {
if (surfaceDescriptor == NULL)
return;
free(surfaceDescriptor->surfaceBackupPtr);
surfaceDescriptor->surfaceBackupPtr = NULL;
THROW_ON_NONZERO_RESULT(close(surfaceDescriptor->eventPollFd.fd), "eventfd close failed");
THROW_ON_NONZERO_RESULT(pthread_mutex_destroy(&surfaceDescriptor->slurpMutex), "slurp mutex destroy failed");
THROW_ON_NONZERO_RESULT(pthread_mutex_destroy(&surfaceDescriptor->renderMutex), "render mutex destroy failed");
THROW_ON_NONZERO_RESULT(pthread_cond_destroy(&surfaceDescriptor->slurpCond), "slurp cond destroy failed");
THROW_ON_NONZERO_RESULT(pthread_cond_destroy(&surfaceDescriptor->renderCond), "render cond destroy failed");
}
2 changes: 1 addition & 1 deletion src/main/jni/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ long calculateInvalidationDelay(GifInfo *info, long renderStartTime, uint_fast32
return -1;
}

inline long getRealTime() {
long getRealTime() {
struct timespec ts; //result not checked since CLOCK_MONOTONIC_RAW availability is checked in JNI_ONLoad
clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
return ts.tv_sec * 1000L + ts.tv_nsec / 1000000L;
Expand Down

0 comments on commit 66116f9

Please sign in to comment.