Android4.2.2 Gallery2源码分析(4)——GLCanvas.java

首先申明,找到这个类是在GLRootView.java中发现的线索。这是一个接口,源码中对该接口作了详细的说明:

  1. //   
  2. // <SPAN style="COLOR: #ff6666">GLCanvas gives a convenient interface to draw using OpenGL.</SPAN>   
  3. //   
  4. // When a rectangle is specified in this interface, it means the region   
  5. // [x, x+width) * [y, y+height)   
  6. //   
  7. public interface GLCanvas {  
  8. <SPAN style="COLOR: #ff6666">    // Tells GLCanvas the size of the underlying GL surface. This should be   
  9.     // called before first drawing and when the size of GL surface is changed.   
  10.     // This is called by GLRoot and should not be called by the clients   
  11.     // who only want to draw on the GLCanvas. Both width and height must be   
  12.     // nonnegative.</SPAN>   
  13.     public void setSize(int width, int height);  
  14.   
  15.   
  16.     public void setSize(int x, int y, int width, int height);  
  17.   
  18.   
  19.     public void clearBuffer();  
  20.     public void clearBuffer(float[] argb);  
  21.   
  22.   
  23.     public void setAlpha(float alpha);  
  24.     public float getAlpha();  
  25.   
  26.   
  27.     public void multiplyAlpha(float alpha);  
  28.   
  29.   
  30.     public void translate(float x, float y, float z);  
  31.     public void translate(float x, float y);  
  32.     public void scale(float sx, float sy, float sz);  
  33.     public void rotate(float angle, float x, float y, float z);  
  34.     public void multiplyMatrix(float[] mMatrix, int offset);  
  35.   
  36.   
  37.     public void save();  
  38.   
  39.   
  40.     public void save(int saveFlags);  
  41.   
  42.     public static final int SAVE_FLAG_ALL = 0xFFFFFFFF;  
  43.     public static final int SAVE_FLAG_ALPHA = 0x01;  
  44.     public static final int SAVE_FLAG_MATRIX = 0x02;  
  45.   
  46.   
  47.     public void restore();  
  48.   
  49. <SPAN style="COLOR: #ff6666">    // Draws a line using the specified paint from (x1, y1) to (x2, y2).   
  50.     // (Both end points are included).   
  51. </SPAN>    public void drawLine(float x1, float y1, float x2, float y2, GLPaint paint);  
  52.   
  53. <SPAN style="COLOR: #ff6666">    // Draws a rectangle using the specified paint from (x1, y1) to (x2, y2).   
  54.     // (Both end points are included).</SPAN>   
  55.     public void drawRect(float x1, float y1, float x2, float y2, GLPaint paint);  
  56.   
  57.     // Fills the specified rectangle with the specified color.   
  58.     public void fillRect(float x, float y, float width, float height, int color);  
  59.   
  60. <SPAN style="COLOR: #ff6666">    // Draws a texture to the specified rectangle.</SPAN>   
  61.     public void drawTexture(  
  62.             BasicTexture texture, int x, int y, int width, int height);  
  63.     public void drawMesh(BasicTexture tex, int x, int y, int xyBuffer,  
  64.             int uvBuffer, int indexBuffer, int indexCount);  
  65.   
  66. <SPAN style="COLOR: #ff6666">    // Draws the source rectangle part of the texture to the target rectangle.</SPAN>   
  67.     public void drawTexture(BasicTexture texture, RectF source, RectF target);  
  68.   
  69.     // Draw a texture with a specified texture transform.   
  70.     public void drawTexture(BasicTexture texture, float[] mTextureTransform,  
  71.                 int x, int y, int w, int h);  
  72.   
  73. <SPAN style="COLOR: #ff6666">    // Draw two textures to the specified rectangle. The actual texture used is   
  74.     // from * (1 - ratio) + to * ratio   
  75.     // The two textures must have the same size.</SPAN>   
  76.     public void drawMixed(BasicTexture from, int toColor,  
  77.             float ratio, int x, int y, int w, int h);  
  78.   
  79.     // Draw a region of a texture and a specified color to the specified   
  80.     // rectangle. The actual color used is from * (1 - ratio) + to * ratio.   
  81.     // The region of the texture is defined by parameter "src". The target   
  82.     // rectangle is specified by parameter "target".   
  83.     public void drawMixed(BasicTexture from, int toColor,  
  84.             float ratio, RectF src, RectF target);  
  85.   
  86.     public GL11 getGLInstance();  
  87.   
  88.   
  89.     public boolean unloadTexture(BasicTexture texture);  
  90.   
  91.   
  92.     public void deleteBuffer(int bufferId);  
  93.   
  94.   
  95.     public void deleteRecycledResources();  
  96.   
  97.   
  98.     public void dumpStatisticsAndClear();  
  99.   
  100.     public void beginRenderTarget(RawTexture texture);  
  101.   
  102.     public void endRenderTarget();  
  103. }  
//
// GLCanvas gives a convenient interface to draw using OpenGL.
//
// When a rectangle is specified in this interface, it means the region
// [x, x+width) * [y, y+height)
//
public interface GLCanvas {
    // Tells GLCanvas the size of the underlying GL surface. This should be
    // called before first drawing and when the size of GL surface is changed.
    // This is called by GLRoot and should not be called by the clients
    // who only want to draw on the GLCanvas. Both width and height must be
    // nonnegative.
    public void setSize(int width, int height);


    public void setSize(int x, int y, int width, int height);


    public void clearBuffer();
    public void clearBuffer(float[] argb);


    public void setAlpha(float alpha);
    public float getAlpha();


    public void multiplyAlpha(float alpha);


    public void translate(float x, float y, float z);
    public void translate(float x, float y);
    public void scale(float sx, float sy, float sz);
    public void rotate(float angle, float x, float y, float z);
    public void multiplyMatrix(float[] mMatrix, int offset);


    public void save();


    public void save(int saveFlags);

    public static final int SAVE_FLAG_ALL = 0xFFFFFFFF;
    public static final int SAVE_FLAG_ALPHA = 0x01;
    public static final int SAVE_FLAG_MATRIX = 0x02;


    public void restore();

    // Draws a line using the specified paint from (x1, y1) to (x2, y2).
    // (Both end points are included).
    public void drawLine(float x1, float y1, float x2, float y2, GLPaint paint);

    // Draws a rectangle using the specified paint from (x1, y1) to (x2, y2).
    // (Both end points are included).
    public void drawRect(float x1, float y1, float x2, float y2, GLPaint paint);

    // Fills the specified rectangle with the specified color.
    public void fillRect(float x, float y, float width, float height, int color);

    // Draws a texture to the specified rectangle.
    public void drawTexture(
            BasicTexture texture, int x, int y, int width, int height);
    public void drawMesh(BasicTexture tex, int x, int y, int xyBuffer,
            int uvBuffer, int indexBuffer, int indexCount);

    // Draws the source rectangle part of the texture to the target rectangle.
    public void drawTexture(BasicTexture texture, RectF source, RectF target);

    // Draw a texture with a specified texture transform.
    public void drawTexture(BasicTexture texture, float[] mTextureTransform,
                int x, int y, int w, int h);

    // Draw two textures to the specified rectangle. The actual texture used is
    // from * (1 - ratio) + to * ratio
    // The two textures must have the same size.
    public void drawMixed(BasicTexture from, int toColor,
            float ratio, int x, int y, int w, int h);

    // Draw a region of a texture and a specified color to the specified
    // rectangle. The actual color used is from * (1 - ratio) + to * ratio.
    // The region of the texture is defined by parameter "src". The target
    // rectangle is specified by parameter "target".
    public void drawMixed(BasicTexture from, int toColor,
            float ratio, RectF src, RectF target);

    public GL11 getGLInstance();


    public boolean unloadTexture(BasicTexture texture);


    public void deleteBuffer(int bufferId);


    public void deleteRecycledResources();


    public void dumpStatisticsAndClear();

    public void beginRenderTarget(RawTexture texture);

    public void endRenderTarget();
}

这里留下了我觉得与最终布局形成有比较直接关系的地方的注释(完整内容可查看源码),从这些注释中,我意识到Gallery的布局之所以不同我之前所见的那些布局视图,是因为这里使用了OpenGL,并且使用了OpenGL材质渲染,那么不能根据以往的经验直接找到视图也就不足为奇了,因为OpenGL是在代码中一点一点画出来的,因此所有的布局视图都要到代码中去发现和寻找。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值