您的位置:首页 > 移动开发 > Android开发

android graphics related modules

2009-09-16 14:30 281 查看
frameworks/base/opengl/libs/ ==>

libEGL.SO

libGLESv1_CM.so

frameworks/base/opengl/libagl ==>

libagl.so

frameworks/base/libs/ui ==>

libui.so

external/skia/ ==>

libsgl.so

libskiagl.so

libcorecg.so

system/core/libpixelflinger ==>

libpixelflinger.so

Canvas.java中,所有的诸如drawPath之类的调用都是pass到底层的mNativeCanvas中去实现的, 而这个mNativeCanvas有两种类型: SkCanvas* 和 SkGLCanvas*。 mNativeCanvas被initRaster赋值时,得到SkCanvas*的指针; 被initGL赋值时,得到SkGLCanvas*的指针。

frameworks/base/graphics/java/android/Canvas.java

public class Canvas {
// assigned in constructors, freed in finalizer
final int mNativeCanvas;

/*  Our native canvas can be either a raster, gl, or picture canvas.
If we are raster, then mGL will be null, and mBitmap may or may not be
present (our default constructor creates a raster canvas but no
java-bitmap is). If we are a gl-based, then mBitmap will be null, and
mGL will not be null. Thus both cannot be non-null, but its possible
for both to be null.
*/
private Bitmap  mBitmap;    // if not null, mGL must be null
private GL      mGL;        // if not null, mBitmap must be null

...
/**
* Construct an empty raster canvas. Use setBitmap() to specify a bitmap to
* draw into.
*/
public Canvas() {
// 0 means no native bitmap
mNativeCanvas = initRaster(0);
}
/**
* Construct a canvas with the specified bitmap to draw into. The bitmap
* must be mutable.
*
* @param bitmap Specifies a mutable bitmap for the canvas to draw into.
*/
public Canvas(Bitmap bitmap) {
if (!bitmap.isMutable()) {
throw new IllegalStateException(
"Immutable bitmap passed to Canvas constructor");
}
throwIfRecycled(bitmap);
mNativeCanvas = initRaster(bitmap.ni());
mBitmap = bitmap;
mDensityScale = bitmap.getDensityScale();
if (mDensityScale == Bitmap.DENSITY_SCALE_UNKNOWN) mDensityScale = 1.0f;
}
/**
* Construct a canvas with the specified gl context. All drawing through
* this canvas will be redirected to OpenGL. Note: some features may not
* be supported in this mode (e.g. some GL implementations may not support
* antialiasing or certain effects like ColorMatrix or certain Xfermodes).
* However, no exception will be thrown in those cases.
*/
public Canvas(GL gl) {
mNativeCanvas = initGL();
mGL = gl;
}

/**
* Return the GL object associated with this canvas, or null if it is not
* backed by GL.
*/
public GL getGL() {
return mGL;
}
...
}


SkCanvas实现了Canvas.java中给出的所有接口,如drawPaint, drawRect, drawText,clipRegion, translate, scale。。。

android大部分的控件中,使用的canvas的底层都是用的SkCanvas, 它包含在skia库的libsgl.so, 依赖libcorecg.so(也是skia编出来的)。 而SkGLCanvas继承了SkCanvas, SkGLCanvas的constructor中会调用GLES/gl.h中定义的opengl函数。 (GLES/gl.h的路径是:frameworks/base/opengl/include/GLES/gl.h) SkGLCanvas中的其他函数则主要是对Texture的一些处理。

SkGLCanvas::SkGLCanvas() {
glEnable(GL_TEXTURE_2D);
glEnable(GL_SCISSOR_TEST);
glEnableClientState(GL_VERTEX_ARRAY);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
fViewportSize.set(0, 0);
}


SkGLCanvas自己提供了setViewport, 和freeGlCaches。也就是说, SkCanvas中不具体实现setViewport, getViewport,直接返回false; 而SkGLCanvas中是实现这两个函数的,但貌似好像也是Skia自己实现的,没有direct到opengl里面去。而像drawPaint, drawRect, drawText,clipRegion, translate, scale之类的函数接口, SkGLCanvas就是直接继承了SkCanvas里面的实现,没看出哪里会提供它自己的实现。

比较蹊跷的是,在skia中看到了SkGLDevice,继承于SkDevice, 实现了drawPaint等函数接口(通过SkGL pass到opengl中,或者假如opengl不支持的feature, 它自己实现),不过不知道哪里会被调用到。

从以下这个链接:
http://www.mail-archive.com/android-framework@googlegroups.com/msg02554.html
写到The OpenGL backend for Skia is not supported and not enabled。 那么这,是不是也解释了为什么GLSurfaceView里面,其实那些绘制都是通过handle传给Canvas的GL类型的指针来pass call to opengl的
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: