Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
a128f6fb
G
glide
项目概览
沉迷打码的小凳子
/
glide
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
glide
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a128f6fb
编写于
9月 28, 2014
作者:
S
Sam Judd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Don't loop through GIFs containing a single frame.
上级
4185efc3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
76 addition
and
37 deletion
+76
-37
library/src/androidTest/java/com/bumptech/glide/load/resource/gif/GifDrawableTest.java
...com/bumptech/glide/load/resource/gif/GifDrawableTest.java
+72
-36
library/src/main/java/com/bumptech/glide/load/resource/gif/GifDrawable.java
...ava/com/bumptech/glide/load/resource/gif/GifDrawable.java
+4
-1
未找到文件。
library/src/androidTest/java/com/bumptech/glide/load/resource/gif/GifDrawableTest.java
浏览文件 @
a128f6fb
...
...
@@ -5,14 +5,12 @@ import android.graphics.Canvas;
import
android.graphics.Paint
;
import
android.graphics.PixelFormat
;
import
android.graphics.drawable.Drawable
;
import
com.bumptech.glide.gifdecoder.GifDecoder
;
import
com.bumptech.glide.gifdecoder.GifHeader
;
import
com.bumptech.glide.load.Transformation
;
import
com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
;
import
com.bumptech.glide.load.resource.drawable.GlideDrawable
;
import
com.bumptech.glide.tests.GlideShadowLooper
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
...
...
@@ -107,6 +105,24 @@ public class GifDrawableTest {
verify
(
frameManager
,
never
()).
getNextFrame
(
any
(
GifFrameManager
.
FrameCallback
.
class
));
}
@Test
public
void
testDoesNotRequestNextFrameOnStartIfHasSingleFrame
()
{
when
(
gifDecoder
.
getFrameCount
()).
thenReturn
(
1
);
drawable
.
setVisible
(
true
,
false
);
drawable
.
start
();
verify
(
frameManager
,
never
()).
getNextFrame
(
any
(
GifFrameManager
.
FrameCallback
.
class
));
}
@Test
public
void
testInvalidatesSelfOnStartIfHasSingleFrame
()
{
when
(
gifDecoder
.
getFrameCount
()).
thenReturn
(
1
);
drawable
.
setVisible
(
true
,
false
);
drawable
.
start
();
verify
(
cb
).
invalidateDrawable
(
eq
(
drawable
));
}
@Test
public
void
testShouldInvalidateSelfOnRun
()
{
drawable
.
setVisible
(
true
,
true
);
...
...
@@ -300,56 +316,63 @@ public class GifDrawableTest {
@Test
public
void
testLoopsASingleTimeIfLoopCountIsSetToOne
()
{
when
(
gifDecoder
.
getFrameCount
()).
thenReturn
(
1
);
drawable
.
setLoopCount
(
1
);
final
int
loopCount
=
1
;
final
int
frameCount
=
2
;
when
(
gifDecoder
.
getFrameCount
()).
thenReturn
(
frameCount
);
drawable
.
setLoopCount
(
loopCount
);
drawable
.
setVisible
(
true
,
true
);
drawable
.
start
();
drawable
.
onFrameRead
(
getBitmap
(),
0
);
verify
(
frameManager
,
times
(
1
)).
getNextFrame
(
eq
(
drawable
));
runLoops
(
loopCount
,
frameCount
);
verify
(
frameManager
,
times
(
loopCount
*
frameCount
)).
getNextFrame
(
eq
(
drawable
));
assertFalse
(
drawable
.
isRunning
());
}
@Test
public
void
testLoopsForeverIfLoopCountIsSetToLoopForever
()
{
when
(
gifDecoder
.
getFrameCount
()).
thenReturn
(
1
);
final
int
loopCount
=
40
;
final
int
frameCount
=
2
;
when
(
gifDecoder
.
getFrameCount
()).
thenReturn
(
frameCount
);
drawable
.
setLoopCount
(
GifDrawable
.
LOOP_FOREVER
);
drawable
.
setVisible
(
true
,
true
);
drawable
.
start
();
int
loops
=
40
;
for
(
int
i
=
0
;
i
<
40
;
i
++)
{
drawable
.
onFrameRead
(
getBitmap
(),
0
);
}
runLoops
(
loopCount
,
frameCount
);
verify
(
frameManager
,
times
(
loops
+
1
)).
getNextFrame
(
eq
(
drawable
));
verify
(
frameManager
,
times
(
(
loopCount
*
frameCount
)
+
1
)).
getNextFrame
(
eq
(
drawable
));
}
@Test
public
void
testLoopsOnceIfLoopCountIsSetToOneWithThreeFrames
()
{
when
(
gifDecoder
.
getFrameCount
()).
thenReturn
(
3
);
drawable
.
setLoopCount
(
1
);
final
int
loopCount
=
1
;
final
int
frameCount
=
3
;
when
(
gifDecoder
.
getFrameCount
()).
thenReturn
(
frameCount
);
drawable
.
setLoopCount
(
loopCount
);
drawable
.
setVisible
(
true
,
true
);
drawable
.
start
();
drawable
.
onFrameRead
(
getBitmap
(),
0
);
drawable
.
onFrameRead
(
getBitmap
(),
1
);
drawable
.
onFrameRead
(
getBitmap
(),
2
);
verify
(
frameManager
,
times
(
3
)).
getNextFrame
(
eq
(
drawable
));
runLoops
(
loopCount
,
frameCount
);
verify
(
frameManager
,
times
(
frameCount
*
loopCount
)).
getNextFrame
(
eq
(
drawable
));
assertFalse
(
drawable
.
isRunning
());
}
@Test
public
void
testLoopsThreeTimesIfLoopCountIsSetToThree
()
{
when
(
gifDecoder
.
getFrameCount
()).
thenReturn
(
1
);
drawable
.
setLoopCount
(
3
);
final
int
loopCount
=
3
;
final
int
frameCount
=
2
;
when
(
gifDecoder
.
getFrameCount
()).
thenReturn
(
frameCount
);
drawable
.
setLoopCount
(
loopCount
);
drawable
.
setVisible
(
true
,
true
);
drawable
.
start
();
drawable
.
onFrameRead
(
getBitmap
(),
0
);
drawable
.
onFrameRead
(
getBitmap
(),
0
);
drawable
.
onFrameRead
(
getBitmap
(),
0
);
verify
(
frameManager
,
times
(
3
)).
getNextFrame
(
eq
(
drawable
));
runLoops
(
loopCount
,
frameCount
);
verify
(
frameManager
,
times
(
loopCount
*
frameCount
)).
getNextFrame
(
eq
(
drawable
));
assertFalse
(
drawable
.
isRunning
());
}
...
...
@@ -374,20 +397,25 @@ public class GifDrawableTest {
@Test
public
void
testChangingTheLoopCountAfterHittingTheMaxLoopCount
()
{
when
(
gifDecoder
.
getFrameCount
()).
thenReturn
(
1
);
drawable
.
setLoopCount
(
1
);
final
int
initialLoopCount
=
1
;
final
int
frameCount
=
2
;
when
(
gifDecoder
.
getFrameCount
()).
thenReturn
(
frameCount
);
drawable
.
setLoopCount
(
initialLoopCount
);
drawable
.
setVisible
(
true
,
true
);
drawable
.
start
();
drawable
.
onFrameRead
(
getBitmap
(),
0
);
runLoops
(
initialLoopCount
,
frameCount
);
drawable
.
setLoopCount
(
2
);
final
int
newLoopCount
=
2
;
drawable
.
setLoopCount
(
newLoopCount
);
drawable
.
start
();
drawable
.
onFrameRead
(
getBitmap
(),
0
);
drawable
.
onFrameRead
(
getBitmap
(),
0
);
runLoops
(
newLoopCount
,
frameCount
);
verify
(
frameManager
,
times
(
3
)).
getNextFrame
(
eq
(
drawable
));
int
expectedFrames
=
(
initialLoopCount
+
newLoopCount
)
*
frameCount
;
verify
(
frameManager
,
times
(
expectedFrames
)).
getNextFrame
(
eq
(
drawable
));
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
...
...
@@ -397,18 +425,26 @@ public class GifDrawableTest {
@Test
public
void
testUsesDecoderNetscapeLoopCountIfLoopCountIsLoopIntrinsic
()
{
when
(
gifDecoder
.
getLoopCount
()).
thenReturn
(
2
);
when
(
gifDecoder
.
getFrameCount
()).
thenReturn
(
1
);
final
int
frameCount
=
3
;
final
int
loopCount
=
2
;
when
(
gifDecoder
.
getLoopCount
()).
thenReturn
(
loopCount
);
when
(
gifDecoder
.
getFrameCount
()).
thenReturn
(
frameCount
);
drawable
.
setLoopCount
(
GlideDrawable
.
LOOP_INTRINSIC
);
drawable
.
setVisible
(
true
,
true
);
drawable
.
start
();
drawable
.
onFrameRead
(
getBitmap
(),
0
);
drawable
.
onFrameRead
(
getBitmap
(),
0
);
runLoops
(
loopCount
,
frameCount
);
verify
(
frameManager
,
times
(
2
)).
getNextFrame
(
eq
(
drawable
));
verify
(
frameManager
,
times
(
frameCount
*
loopCount
)).
getNextFrame
(
eq
(
drawable
));
}
private
void
runLoops
(
int
loopCount
,
int
frameCount
)
{
for
(
int
loop
=
0
;
loop
<
loopCount
;
loop
++)
{
for
(
int
frame
=
0
;
frame
<
frameCount
;
frame
++)
{
drawable
.
onFrameRead
(
getBitmap
(),
frame
);
}
}
}
private
static
Bitmap
getBitmap
()
{
return
Bitmap
.
createBitmap
(
100
,
100
,
Bitmap
.
Config
.
ARGB_8888
);
...
...
library/src/main/java/com/bumptech/glide/load/resource/gif/GifDrawable.java
浏览文件 @
a128f6fb
...
...
@@ -126,7 +126,10 @@ public class GifDrawable extends GlideDrawable implements GifFrameManager.FrameC
}
private
void
startRunning
()
{
if
(!
isRunning
)
{
// If we have only a single frame, we don't want to decode it endlessly.
if
(
decoder
.
getFrameCount
()
==
1
)
{
invalidateSelf
();
}
else
if
(!
isRunning
)
{
isRunning
=
true
;
frameManager
.
getNextFrame
(
this
);
invalidateSelf
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录