您的位置:华清远见教育科技集团 >> 新闻动态 >> Android资料 >> Android LayerBuffer模式的layer渲染  
 
Android LayerBuffer模式的layer渲染
分享到:

“LayerBuffer”模式的Layer主要应用于多媒体应用,如照相机预览和视频回放的渲染中,根据渲染方式的不同,“LayerBuffer”模式的Layer分为普通缓冲和OverLay两种模式。“LayerBuffer”模式的Layer的渲染过程如下:

代码:“LayerBuffer”模式的Layer的渲染过程

void LayerBuffer::BufferSource::onDraw(const Region& clip) const
    {
    sp ourBuffer(getBuffer());
    if (UNLIKELY(ourBuffer==0)) {
        mLayer.clearWithOpenGL(clip);     //清空渲染区域
        return;
        }
    status_t err=NO_ERROR;
    NativeBuffer src(ourBuffer->getBuffer());
    const Rect transformedBounds(mLayer.getTransformedBounds());
    if (UNLIKELY(mTexture.name==-1LU)) {
        mTexture.name=mLayer.createTexture();
        }
    #if defined(EGL_ANDROID_image_native_buffer)
    if (mLayer.mFlags & DisplayHardware::DIRECT_TEXTURE) {
    copybit_device_t* copybit=mLayer.mBlitEngine;
    if (copybit) {
        err=initTempBuffer();
        if (err==NO_ERROR) {
            const NativeBuffer& dst(mTempBuffer);
            region_iterator clip(Region(Rect(dst.crop.r, dst.crop.b)));
          copybit->set_parameter(copybit, COPYBIT_TRANSFORM, 0);
          copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, 0xFF);
          copybit->set_parameter(copybit, COPYBIT_DITHER, COPYBIT_ENABLE);
          err=copybit->stretch(copybit,&dst.img, &src.img,&dst.crop, &src.crop, &clip);
          }
        } else {
          err=INVALID_OPERATION;
        }
    }
    #endif
    else {
        err=INVALID_OPERATION;
         }
    if (err !=NO_ERROR){
    GGLSurface t;
    t.version=sizeof(GGLSurface);
    t.width=src.crop.r;
    t.height=src.crop.b;
    t.stride=src.img.w;
    t.vstride=src.img.h;
    t.format=src.img.format;
    t.data=(GGLubyte*)src.img.base;
    const Region dirty(Rect(t.width, t.height));
    mLayer.loadTexture(&mTexture, dirty, t);    //加载纹理
        }
    mTexture.transform=mBufferHeap.transform;
    mLayer.drawWithOpenGL(clip, mTexture); //OpenGL渲染
    }

“LayerBlur”和“LayerDim”模式的Layer均为利用OpenGL进行渲染的特殊Layer,“LayerBlur”模式的Layer呈现一种模糊的特效;“LayerDim”模式的Layer呈现一种暗淡的特效,这里就不再多做介绍了。

在默认情况下,系统多可以创建31个Layer,4个缓冲。

 更多相关文章

·Android应用程序之WebApp开发实战
·从开发到盈利--安卓程序商业化之路
·Android Layer纹理重载的实现
·Android Surface Flinger 服务器概述
·Android 属性动画开发源码