爲了提高刷屏效率,研究了下直接在HAL層刷屏的方法。另外一個好處是這樣的能夠支持使用YUV 數據直接刷屏。(依賴系統支持)
1:使用surfaceview,並按你要求設置surface的格式和顏色格式
holder.setFormat,holder.setType,注在Android2.0以後,貌似這個方法只支持565了,也沒有細看源代碼,不知道爲什麼。
2:在surfaceCreated函數裏面,得到surface 對象,並通過JNI 傳到HAL層
3:JNI 初始化的時候,得到android/view/Surface裏面的一個field: mSurface
4:在JNI 函數裏面,mSurface的對應的c指針
sp<Surface> mysurface = (Surface *)env->GetIntField(surface, s_fields.surface);
5:這樣就可以使用了這個mysurface了。
if(mysurface->isValid())
{
//log_to_file("display");
Surface::SurfaceInfo info;
/* get data */
MByte *pSrc;
MByte* pDisplay;
status_t err = mysurface->lock(&info, true);
if(err == 0)
{
int width = info.w;
int height = info.h;
int s = info.s;
pDisplay = (MByte*)info.bits;
// Do something...
mysurface->unlockAndPost();
LOGE("width %d height %d info.bits %d info.s %d", width,height, (int)info.bits, info.s);
}else
LOGE("mysurface->lock error, return %d########", err);
}
else
LOGE("mysurface->isValid error########");
6: 注意,需要include Surface.h IMemory.h 並link 相應庫
using namespace android; 也是必須的。