“LayerBuffer”模式的Layer主要應(yīng)用于多媒體應(yīng)用,如照相機(jī)預(yù)覽和視頻回放的渲染中,根據(jù)渲染方式的不同,“LayerBuffer”模式的Layer分為普通緩沖和OverLay兩種模式!癓ayerBuffer”模式的Layer的渲染過程如下:
代碼:“LayerBuffer”模式的Layer的渲染過程
void LayerBuffer::BufferSource::onDraw(const Region& clip) const
{
sp ourBuffer(getBuffer());
if (UNLIKELY(ourBuffer==0)) {
mLayer.clearWithOpenGL(clip); //清空渲染區(qū)域
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進(jìn)行渲染的特殊Layer,“LayerBlur”模式的Layer呈現(xiàn)一種模糊的特效;“LayerDim”模式的Layer呈現(xiàn)一種暗淡的特效,這里就不再多做介紹了。
在默認(rèn)情況下,系統(tǒng)多可以創(chuàng)建31個(gè)Layer,4個(gè)緩沖。