SpriteMethodTest 1.0
Author: Chris Pruett
INTRODUCTION
SpriteMethodTest is a simple application for comparing the relative speeds of
various 2D drawing methods on Android. The current version can test drawing
with the CPU-based Canvas system, or via three different OpenGL ES rendering
methods.
The goal of this program is to provide an example of how to architect an
efficient 2D rendering pipeline with the Android SDK, and to show the
relative merits of each rendering method. It is not an absolute benchmark and
should not be used as such. However, it should give you a good idea of how to
go about making a fast 2D program.
RENDERING METHODS
There are four basic methods that SpriteMethodTest can test.
1) Canvas. This test draws sprites using Bitmap objects onto a Canvas surface.
This is an entirely CPU-driven operation. It is also the simplest to code.
2) OpenGL ES flavors:
2a) Basic Vert Quads. This is a test of drawing sprites on a plane using
basic vertex quads and orthographic projection. This test requires only the
baseline OpenGL ES 1.0, which is guaranteed to be supported on all Android
devices.
2b) Draw Texture Extension. This test uses the GL_OES_draw_texture extension
to draw sprites on the screen without any sort of projection or vertex buffers
involved. Note that this functionality is not guaranteed to be supported on
all Android devices, and application authors who use it should check the
contents of glGetString(GL_EXTENSIONS) before using it. This extension is
currently supported by the T-Mobile G1.
2c) VBO Extension. This test is fundamentally the same as 2a except that the
vertex arrays describing the sprites are stored in vertex buffer objects,
which means that they reside in the GPU's memory rather than in main memory.
As with 2b, this functionality is supported on the G1 but is not guaranteed
to be supported on other devices; the extension string must be checked at
runtime before you use it.
INTERPRETING RESULTS
After a test is run, a dialog containing some basic timing results will be
displayed. This dialog contains four numbers:
- Frame Time. This is the time (in ms and frames per second) that each frame
took, on average, to draw from beginning to end. This is the most valuable
part of the result.
- Draw Time. This is the time that was spent, on average, making draw calls
against the OpenGL ES or Canvas API. Under Canvas this is mostly just the
time that Bitmap.drawCanvas() required. Under OpenGL ES, this time is the time
it took to issue all GL commands for a single frame.
- Page Flip Time. This is a slightly misleading statistic. It tracks the
amount of time that the rendering thread spent waiting for the commands
issued during Draw to actually appear on the screen. Under the Canvas test
this time is defined by the time spent in lockCanvas() and
unlockCanvasAndPost(). Under Open GL ES this is the time spent in
eglSwapBuffers(). This statistic is important because it shows how long
your rendering thread may block while waiting for the previous frame to
complete. If this value is significant, you might want to move some
non-rendering code into another thread.
- Sim Time. This is the time spent running the "simulation" step--the code
that moves the robot sprites around on the screen. If you uncheck the
"animate" option, this time will always be zero.
DESIGN NOTES
All of the tests follow the same basic pattern: an activity to run the test
starts up and spawns a separate thread to draw to the activity's surface. This
thread acquires a surface holder object and then draws into it as fast as
it can. This pattern is based on the SpriteText example from the API Demos
sample, but it has been modified to work with both Canvas and OpenGL ES.
FURTHER OPTIMIZATIONS
This is not an absolutely optimal 2D drawing implementation, but it's fairly
simple and produces good results. Other things that could be done to improve
performance include better management of image and canvas bitmaps (or, in the
OpenGL ES case, texture compression is an option on the G1). The canvas is
redrawn from scratch every frame, which probably isn't necessary; a
dirty rectangle-based system might improve results. There are other OpenGL ES
extensions that might be applicable (such as point sprites). The simulation
code could easily be moved into another thread so that it can run while the
rendering thread blocks on page flip. And fixed point math could produce an
edge over floating point math, especially when there are a large number of
sprites on the screen.
TAKEAWAY
Here are some general observations about writing efficient 2D (and 3D) rendering
systems on Android.
- Canvas is super easy to use but has a low upper bound for performance.
Though not tested in this example, rotation and scaling sprites using Canvas
is probably very expensive. Still, for a Tetris or color matching game, or
even a top-down RPG that does not require 60fps, Canvas may be enough.
- OpenGL ES is the way to go for 2D applications that need to maintain a high
frame rate. It's also the way to go if scaling or rotation are required, as
these features are almost free.
- OpenGL ES extensions, in particular the Draw Texture extension, can produce
very good results on the G1. However, not all devices are guaranteed to have
these extensions, so your code should be built to handle differing rendering
systems. Hopefully this code shows how the same rendering pipeline and
simulation code can be used with a variety of different rendering methods.
- When drawing static vertex arrays (whether for 2D or 3D) on the G1, the
vertex buffer object extension is a big win. You should use it.
- JNI call overhead is something to think about with OpenGL ES. Each GL call
will have to jump through JNI to get to the actual C++ implementation, and
after a while that overhead may add up. You might want to test drawing
methods that are slower on their own but result in fewer total GL calls;
for example, a tile-based game might be faster when rendered as a vertex grid
(using the VBO extension) than as individual draw texture calls for each tile.
This sample suggests that the draw texture extension is the fastest way to
draw 2D sprites on the G1, but each draw call also requires at least one GL
call, so in the case of a grid a vertex array might actually be faster.
- One thing that this test does implicitly is avoid all allocation at runtime
once the test has begun. It invokes the GC before the test starts and then
makes sure not to allocate memory explicitly (Java often allocates memory
under the hood) so that the GC will not interfere with the test. On the G1
the GC takes between 100ms and 300ms to run, so for performance applications
you *really* want to avoid allocating memory outside of safe pause states.
没有合适的资源?快使用搜索试试~ 我知道了~
yuv to rgb color convert
3星 · 超过75%的资源 需积分: 9 17 下载量 140 浏览量
2012-11-25
09:31:19
上传
评论 1
收藏 1.66MB GZ 举报
温馨提示
共1800个文件
java:687个
svn-base:562个
xml:140个
video development about color convert yuv to rgb
资源推荐
资源详情
资源评论
收起资源包目录
yuv to rgb color convert (1800个子文件)
all-wcprops 12KB
all-wcprops 12KB
all-wcprops 7KB
all-wcprops 7KB
all-wcprops 3KB
all-wcprops 3KB
all-wcprops 3KB
all-wcprops 3KB
all-wcprops 3KB
all-wcprops 3KB
all-wcprops 3KB
all-wcprops 3KB
all-wcprops 2KB
all-wcprops 2KB
all-wcprops 2KB
all-wcprops 2KB
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 798B
all-wcprops 798B
all-wcprops 775B
all-wcprops 775B
all-wcprops 752B
all-wcprops 752B
all-wcprops 641B
all-wcprops 641B
all-wcprops 616B
all-wcprops 616B
all-wcprops 487B
all-wcprops 450B
all-wcprops 450B
all-wcprops 393B
all-wcprops 393B
all-wcprops 323B
all-wcprops 311B
all-wcprops 311B
all-wcprops 309B
all-wcprops 309B
all-wcprops 307B
all-wcprops 305B
all-wcprops 303B
all-wcprops 303B
all-wcprops 285B
all-wcprops 285B
all-wcprops 270B
all-wcprops 264B
all-wcprops 264B
all-wcprops 256B
all-wcprops 256B
all-wcprops 133B
all-wcprops 133B
all-wcprops 119B
all-wcprops 119B
all-wcprops 113B
all-wcprops 113B
all-wcprops 111B
all-wcprops 111B
all-wcprops 103B
all-wcprops 103B
all-wcprops 102B
all-wcprops 102B
all-wcprops 92B
yuv2rgb16tab.c 16KB
yuv420rgb565c.c 15KB
yuv444rgb565c.c 14KB
yuv422rgb565c.c 14KB
yuv420rgb888c.c 6KB
yuv420rgb8888c.c 6KB
yuv444rgb8888c.c 6KB
yuv444rgb888c.c 6KB
yuv422rgb8888c.c 5KB
yuv422rgb888c.c 5KB
mmaptest.c 3KB
test.c 2KB
mmaptest1.c 2KB
test.c 2KB
hello-jni.c 1KB
proguard.cfg 1KB
proguard.cfg 1KB
proguard.cfg 1KB
proguard.cfg 1KB
proguard.cfg 1KB
proguard.cfg 1KB
proguard.cfg 1KB
proguard.cfg 1KB
proguard.cfg 1KB
proguard.cfg 1KB
proguard.cfg 1KB
proguard.cfg 1KB
proguard.cfg 1KB
proguard.cfg 1KB
proguard.cfg 1KB
proguard.cfg 1KB
proguard.cfg 1KB
共 1800 条
- 1
- 2
- 3
- 4
- 5
- 6
- 18
资源评论
- chen7yang2014-10-07想看看,也许有用。。。
fanbird2008
- 粉丝: 209
- 资源: 249
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功