Skip to content

Commit

Permalink
Framebuffers size reduced for #287
Browse files Browse the repository at this point in the history
  • Loading branch information
koral-- committed Sep 12, 2016
1 parent 039f3e0 commit e830cbb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
18 changes: 9 additions & 9 deletions src/main/jni/drawing.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ extern void memset32_neon(uint32_t* dst, uint32_t value, int count);

static inline void blitNormal(argb *bm, GifInfo *info, SavedImage *frame, ColorMapObject *cmap, bool drawOnlyDirtyRegion) {
unsigned char *src = info->rasterBits;
argb *dst = GET_ADDR(bm, info->stride, frame->ImageDesc.Left, frame->ImageDesc.Top);
argb *dst = drawOnlyDirtyRegion ? bm : GET_ADDR(bm, info->stride, frame->ImageDesc.Left, frame->ImageDesc.Top);

uint_fast16_t x, y = frame->ImageDesc.Height;
const int_fast16_t transpIndex = info->controlBlock[info->currentIndex].TransparentColor;
const GifWord frameWidth = frame->ImageDesc.Width;
const GifWord padding = info->stride - frameWidth;
const GifWord padding = drawOnlyDirtyRegion ? 0 : info->stride - frameWidth;
if (info->isOpaque) {
if (transpIndex == NO_TRANSPARENT_COLOR) {
for (; y > 0; y--) {
Expand Down Expand Up @@ -74,14 +74,14 @@ static void drawFrame(argb *bm, GifInfo *info, SavedImage *frame, bool drawOnlyD
// return true if area of 'target' is completely covers area of 'covered'
static bool checkIfCover(const SavedImage *target, const SavedImage *covered) {
return target->ImageDesc.Left <= covered->ImageDesc.Left
&& covered->ImageDesc.Left + covered->ImageDesc.Width
<= target->ImageDesc.Left + target->ImageDesc.Width
&& target->ImageDesc.Top <= covered->ImageDesc.Top
&& covered->ImageDesc.Top + covered->ImageDesc.Height
<= target->ImageDesc.Top + target->ImageDesc.Height;
&& covered->ImageDesc.Left + covered->ImageDesc.Width
<= target->ImageDesc.Left + target->ImageDesc.Width
&& target->ImageDesc.Top <= covered->ImageDesc.Top
&& covered->ImageDesc.Top + covered->ImageDesc.Height
<= target->ImageDesc.Top + target->ImageDesc.Height;
}

static inline void disposeFrameIfNeeded(argb *bm, GifInfo *info, bool drawOnlyDirtyRegion) {
static inline void disposeFrameIfNeeded(argb *bm, GifInfo *info, bool drawOnlyDirtyRegion) { //odo handle drawOnlyDirtyRegion
GifFileType *fGif = info->gifFilePtr;
SavedImage *cur = &fGif->SavedImages[info->currentIndex - 1];
SavedImage *next = &fGif->SavedImages[info->currentIndex];
Expand Down Expand Up @@ -128,7 +128,7 @@ void prepareCanvas(const argb *bm, GifInfo *info) {
.rgb = gifFilePtr->SColorMap->Colors[gifFilePtr->SBackGroundColor],
.alpha = 0xFF
};
MEMSET_ARGB((uint32_t *) bm, *(uint32_t * ) & bgColArgb, info->stride * gifFilePtr->SHeight);
MEMSET_ARGB((uint32_t *) bm, *(uint32_t *) &bgColArgb, info->stride * gifFilePtr->SHeight);
} else {
MEMSET_ARGB((uint32_t *) bm, 0, info->stride * gifFilePtr->SHeight);
}
Expand Down
23 changes: 16 additions & 7 deletions src/main/jni/opengl.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,18 @@ static void *slurp(void *pVoidInfo) {
GifInfo *info = pVoidInfo;
while (true) {
long renderStartTime = getRealTime();
//TODO only advance frame index if cacheAnimation is enabled and frame is cached
//TODO only advance frame index if cacheAnimation is enabled and frame is cached
DDGifSlurp(info, true, false);
TexImageDescriptor *descriptor = info->frameBufferDescriptor;
pthread_mutex_lock(&descriptor->renderMutex);
GifWord width = info->gifFilePtr->SavedImages[info->currentIndex].ImageDesc.Width;
GifWord height = info->gifFilePtr->SavedImages[info->currentIndex].ImageDesc.Height;

descriptor->frameBuffer = realloc(descriptor->frameBuffer, width * height * sizeof(argb));
if (info->currentIndex == 0) {
prepareCanvas(descriptor->frameBuffer, info);
//prepareCanvas(descriptor->frameBuffer, info); //TODO add cacheAnimation support
}
const uint_fast32_t frameDuration = getBitmap(descriptor->frameBuffer, info, false);
const uint_fast32_t frameDuration = getBitmap(descriptor->frameBuffer, info, true);
pthread_mutex_unlock(&descriptor->renderMutex);

const long long invalidationDelayMillis = calculateInvalidationDelay(info, renderStartTime, frameDuration);
Expand Down Expand Up @@ -189,21 +193,26 @@ Java_pl_droidsonroids_gif_GifInfoHandle_renderFrameGL(JNIEnv *__unused env, jcla
const GLenum target = (const GLenum) rawTarget;
GLuint *currentTextureName = descriptor->glTextureNames + info->currentIndex;
if (*currentTextureName != 0) {
glBindTexture(target, *currentTextureName);
glBindTexture(target, *currentTextureName);//TODO draw at correct position
} else {
GLuint *framebufferName = &descriptor->glFramebufferName;
if (*framebufferName == 0) {
glGenFramebuffers(1, framebufferName); //TODO delete
glGenFramebuffers(1, framebufferName); //TODO glDeleteFramebuffers
}
glGenTextures(1, currentTextureName);//TODO delete
glGenTextures(1, currentTextureName);//TODO glDeleteTextures
const GifImageDesc imageDesc = info->gifFilePtr->SavedImages[info->currentIndex].ImageDesc;
const GLsizei frameWidth = (const GLsizei) imageDesc.Width;
const GLsizei frameHeight = (const GLsizei) imageDesc.Height;
const GLsizei width = (const GLsizei) info->gifFilePtr->SWidth;
const GLsizei height = (const GLsizei) info->gifFilePtr->SHeight;

glBindTexture(target, *currentTextureName);
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(target, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, descriptor->frameBuffer);
glTexImage2D(target, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
//FIXME full size for frame 0 or clear canvas using gl API
glTexSubImage2D(target, 0, imageDesc.Left, imageDesc.Top, frameWidth, frameHeight, GL_RGBA, GL_UNSIGNED_BYTE, descriptor->frameBuffer);
glBindFramebuffer(GL_FRAMEBUFFER, *framebufferName);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, *currentTextureName, level);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
Expand Down

0 comments on commit e830cbb

Please sign in to comment.