eglSwapBuffers详解
问题来自eglSwapBuffers是否有等待,如果调用eglSwapBuffers的话,是不是会导致帧率下降?
2.7.1 BootAnimation中的调用
之所以需要了解这个api的具体实现,因为我们需要了解eglSwapBuffers是否有等待Fence。
首先看下在BootAnimation中对于这个函数的调用:
EGLBoolean res = eglSwapBuffers(mDisplay, mSurface); if (res == EGL_FALSE) break; |
故名思意,通过这个函数来实现buffer的互换,可是这个互换的buffer是怎么来的呢?
通过对代码的跟踪,可以知道,在bootanimation的readyToRun()函数中,会来创建mSurface
surface = eglCreateWindowSurface(display, config, s.get(), NULL); |
因为我们没有GPU驱动的代码,所以,我们可以从libagl中看出一点端倪。
查看这部分代码,建议将如下几部分的sourcecode导入到sourceinsight中。
l frameworks/native/opengl/libagl
l frameworks/base/cmds/bootanimation
l frameworks/core/libpixelflinger
2.7.2 eglCreateWindowSurface
在egl.cpp中,eglCreateWindowSurface就是对应函数createWindowSurface的接口封装。
surface = eglCreateWindowSurface(display, config, s.get(), NULL); EGLSurface eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config, NativeWindowType window, const EGLint *attrib_list) {
return createWindowSurface(dpy, config, window, attrib_list); } |
在介绍createWindowSurface之前,先来看看window,这个window到底是什么。
在bootanimation.cpp中有这样的一个调用逻辑:
// create the native surface sp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"), sp<Surface> s = control->getSurface(); sp<SurfaceControl> SurfaceComposerClient::createSurface( const String8& name, uint32_t w, uint32_t h, PixelFormat format, uint32_t flags) |