Пример #1
0
void DisplayDevice::swapBuffers(HWComposer& hwc) const {
    // We need to call eglSwapBuffers() if:
    //  (1) we don't have a hardware composer, or
    //  (2) we did GLES composition this frame, and either
    //    (a) we have framebuffer target support (not present on legacy
    //        devices, where HWComposer::commit() handles things); or
    //    (b) this is a virtual display
    if (hwc.initCheck() != NO_ERROR ||
            (hwc.hasGlesComposition(mHwcDisplayId) &&
             (hwc.supportsFramebufferTarget() || mType >= DISPLAY_VIRTUAL))) {
#ifndef MTK_DEFAULT_AOSP
        // layer swap applied for HWC 1.1 and later
        EGLBoolean success = EGL_TRUE;
        if (mLayersSwapRequired) {
            if (mType == DisplayDevice::DISPLAY_PRIMARY)
                hwc.setWaitFramebufferTarget();

            if (CC_UNLIKELY(mFlinger->sPropertiesState.mLineG3D))
                drawDebugLine();

            success = eglSwapBuffers(mDisplay, mSurface);
        }
#else
        EGLBoolean success = eglSwapBuffers(mDisplay, mSurface);
#endif
        if (!success) {
            EGLint error = eglGetError();
            if (error == EGL_CONTEXT_LOST ||
                    mType == DisplayDevice::DISPLAY_PRIMARY) {
                LOG_ALWAYS_FATAL("eglSwapBuffers(%p, %p) failed with 0x%08x",
                                 mDisplay, mSurface, error);
            } else {
                ALOGE("eglSwapBuffers(%p, %p) failed with 0x%08x",
                      mDisplay, mSurface, error);
            }
        }
    }

    status_t result = mDisplaySurface->advanceFrame();
    if (result != NO_ERROR) {
        ALOGE("[%s] failed pushing new frame to HWC: %d",
              mDisplayName.string(), result);
    }

#ifndef MTK_DEFAULT_AOSP
    // log display device FPS info for performace check
    if (true == mFps.update()) {
        ALOGI("[%s (type:%d)] fps:%f,dur:%.2f,max:%.2f,min:%.2f",
              mDisplayName.string(), mType,
              mFps.getFps(),
              mFps.getLastLogDuration() / 1e6,
              mFps.getMaxDuration() / 1e6,
              mFps.getMinDuration() / 1e6);
    }
#endif
}