void EglManager::beginFrame(EGLSurface surface, EGLint* width, EGLint* height) { LOG_ALWAYS_FATAL_IF(surface == EGL_NO_SURFACE, "Tried to beginFrame on EGL_NO_SURFACE!"); makeCurrent(surface); if (width) { TIME_LOG("eglQuerySurface", eglQuerySurface(mEglDisplay, surface, EGL_WIDTH, width)); } if (height) { TIME_LOG("eglQuerySurface", eglQuerySurface(mEglDisplay, surface, EGL_HEIGHT, height)); } /// M: use basic because driver has added systrace for it nsecs_t duration; TIME_LOG_BASIC("eglBeginFrame", eglBeginFrame(mEglDisplay, surface), duration); }
void EglManager::createContext() { EGLint attribs[] = { EGL_CONTEXT_CLIENT_VERSION, GLES_VERSION, EGL_NONE }; TIME_LOG("eglCreateContext", mEglContext = eglCreateContext(mEglDisplay, mEglConfig, EGL_NO_CONTEXT, attribs)); LOG_ALWAYS_FATAL_IF(mEglContext == EGL_NO_CONTEXT, "Failed to create context, error = %s", egl_error_str()); EGL_LOGD("Created EGL context (%p)", mEglContext); }
void FboCache::clear() { for (size_t i = 0; i < mCache.size(); i++) { const GLuint fbo = mCache.itemAt(i); TIME_LOG("glDeleteFramebuffers", glDeleteFramebuffers(1, &fbo)); } mCache.clear(); }
EGLSurface EglManager::createSurface(EGLNativeWindowType window) { initialize(); EGLSurface surface; TIME_LOG("eglCreateWindowSurface", surface = eglCreateWindowSurface(mEglDisplay, mEglConfig, window, NULL)); LOG_ALWAYS_FATAL_IF(surface == EGL_NO_SURFACE, "Failed to create EGLSurface for window %p, eglErr = %s", (void*) window, egl_error_str()); return surface; }
bool EglManager::makeCurrent(EGLSurface surface) { if (isCurrent(surface)) return false; if (surface == EGL_NO_SURFACE) { // If we are setting EGL_NO_SURFACE we don't care about any of the potential // return errors, which would only happen if mEglDisplay had already been // destroyed in which case the current context is already NO_CONTEXT TIME_LOG("eglMakeCurrent", eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)); } else { EGLBoolean success; TIME_LOG("eglMakeCurrent", success = eglMakeCurrent(mEglDisplay, surface, surface, mEglContext)); if (!success) { LOG_ALWAYS_FATAL("Failed to make current on surface %p, error=%s", (void*)surface, egl_error_str()); } } mCurrentSurface = surface; return true; }
void EglManager::destroySurface(EGLSurface surface) { if (isCurrent(surface)) { makeCurrent(EGL_NO_SURFACE); } EGLBoolean success; TIME_LOG("eglDestroySurface", success = eglDestroySurface(mEglDisplay, surface)); if (!success) { ALOGW("Failed to destroy surface %p, error=%s", (void*)surface, egl_error_str()); } }
void EglManager::usePBufferSurface() { LOG_ALWAYS_FATAL_IF(mEglDisplay == EGL_NO_DISPLAY, "usePBufferSurface() called on uninitialized GlobalContext!"); if (mPBufferSurface == EGL_NO_SURFACE) { EGLint attribs[] = { EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE }; TIME_LOG("eglCreatePbufferSurface", mPBufferSurface = eglCreatePbufferSurface(mEglDisplay, mEglConfig, attribs)); } makeCurrent(mPBufferSurface); }
void PatchCache::clear() { clearCache(); if (mMeshBuffer) { Caches::getInstance().unbindMeshBuffer(); TIME_LOG("glDeleteBuffers", glDeleteBuffers(1, &mMeshBuffer)); mMeshBuffer = 0; mSize = 0; } /// M: [ALPS01877772] Clear operation will need to update generation id as well because the status has changed. mGenerationId++; }
void EglManager::destroy() { if (mEglDisplay == EGL_NO_DISPLAY) return; usePBufferSurface(); if (Caches::hasInstance()) { Caches::getInstance().terminate(); } mRenderThread.renderState().onGLContextDestroyed(); TIME_LOG("eglDestroyContext", eglDestroyContext(mEglDisplay, mEglContext)); EGL_LOGD("Destroyed EGL context (%p)", mEglContext); TIME_LOG("eglDestroySurface", eglDestroySurface(mEglDisplay, mPBufferSurface)); TIME_LOG("eglMakeCurrent", eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)); TIME_LOG("eglTerminate", eglTerminate(mEglDisplay)); EGL_LOGD("Terminated EGL display (%p)", mEglDisplay); TIME_LOG("eglReleaseThread", eglReleaseThread()); mEglDisplay = EGL_NO_DISPLAY; mEglContext = EGL_NO_CONTEXT; mPBufferSurface = EGL_NO_SURFACE; mCurrentSurface = EGL_NO_SURFACE; }
bool EglManager::enableDirtyRegions(EGLSurface surface) { if (!mRequestDirtyRegions) return false; if (mCanSetDirtyRegions) { EGLBoolean success; TIME_LOG("eglSurfaceAttrib", success = eglSurfaceAttrib(mEglDisplay, surface, EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED)); if (!success) { ALOGW("Failed to set EGL_SWAP_BEHAVIOR on surface %p, error=%s", (void*) surface, egl_error_str()); return false; } return true; } // Perhaps it is already enabled? EGLint value; EGLBoolean success; TIME_LOG("eglQuerySurface", success = eglQuerySurface(mEglDisplay, surface, EGL_SWAP_BEHAVIOR, &value)); if (!success) { ALOGW("Failed to query EGL_SWAP_BEHAVIOR on surface %p, error=%p", (void*) surface, egl_error_str()); return false; } return value == EGL_BUFFER_PRESERVED; }
bool FboCache::put(GLuint fbo) { // Detach the texture from the FBO GLuint previousFbo; glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint*) &previousFbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, previousFbo); if (mCache.size() < mMaxSize) { mCache.add(fbo); return true; } TIME_LOG("glDeleteFramebuffers", glDeleteFramebuffers(1, &fbo)); return false; }