android graphics related modules(转载)

原文地址:http://blog.csdn.net/hwizhao/archive/2009/09/16/4558477.aspx

 

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

  1. public   class  Canvas {  
  2.     // assigned in constructors, freed in finalizer   
  3.     final   int  mNativeCanvas;  
  4.       
  5.     /*  Our native canvas can be either a raster, gl, or picture canvas.  
  6.         If we are raster, then mGL will be null, and mBitmap may or may not be  
  7.         present (our default constructor creates a raster canvas but no  
  8.         java-bitmap is). If we are a gl-based, then mBitmap will be null, and  
  9.         mGL will not be null. Thus both cannot be non-null, but its possible  
  10.         for both to be null.  
  11.     */   
  12.     private  Bitmap  mBitmap;     // if not null, mGL must be null   
  13.     private  GL      mGL;         // if not null, mBitmap must be null   
  14.       
  15. ...  
  16.     /**  
  17.      * Construct an empty raster canvas. Use setBitmap() to specify a bitmap to  
  18.      * draw into.  
  19.      */   
  20.     public  Canvas() {  
  21.         // 0 means no native bitmap   
  22.         mNativeCanvas = initRaster(0 );  
  23.     }  
  24.     /**  
  25.      * Construct a canvas with the specified bitmap to draw into. The bitmap  
  26.      * must be mutable.  
  27.      *  
  28.      * @param bitmap Specifies a mutable bitmap for the canvas to draw into.  
  29.      */   
  30.     public  Canvas(Bitmap bitmap) {  
  31.         if  (!bitmap.isMutable()) {  
  32.             throw   new  IllegalStateException(  
  33.                             "Immutable bitmap passed to Canvas constructor" );  
  34.         }  
  35.         throwIfRecycled(bitmap);  
  36.         mNativeCanvas = initRaster(bitmap.ni());  
  37.         mBitmap = bitmap;  
  38.         mDensityScale = bitmap.getDensityScale();  
  39.         if  (mDensityScale == Bitmap.DENSITY_SCALE_UNKNOWN) mDensityScale =  1 .0f;  
  40.     }  
  41.    /**  
  42.      * Construct a canvas with the specified gl context. All drawing through  
  43.      * this canvas will be redirected to OpenGL. Note: some features may not  
  44.      * be supported in this mode (e.g. some GL implementations may not support  
  45.      * antialiasing or certain effects like ColorMatrix or certain Xfermodes).  
  46.      * However, no exception will be thrown in those cases.  
  47.      */   
  48.     public  Canvas(GL gl) {  
  49.         mNativeCanvas = initGL();  
  50.         mGL = gl;  
  51.     }  
  52.       
  53.     /**  
  54.      * Return the GL object associated with this canvas, or null if it is not  
  55.      * backed by GL.  
  56.      */   
  57.     public  GL getGL() {  
  58.         return  mGL;  
  59.     }  
  60.  ...  
  61. }  

 

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的一些处理。

  1. SkGLCanvas::SkGLCanvas() {  
  2.     glEnable(GL_TEXTURE_2D);  
  3.     glEnable(GL_SCISSOR_TEST);  
  4.     glEnableClientState(GL_VERTEX_ARRAY);  
  5.     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);  
  6.     fViewportSize.set(0, 0);  
  7. }  

 

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的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值