[RenderEngine] Make BindNativeBufferAsFramebuffer more generic.
BindNativeBufferAsFramebuffer is a helper class that manages resource of an EGL
image for screenshot capturing. However, as a public API it ties to GLES. This
patch abstracts framebuffer out as Framebuffer and uses it instead of EGL
image. As a result, we can move the most of the implementation of
bindNativeBufferAsFrameBuffer and unbindNativeBufferAsFrameBuffer to
GLFramebuffer so that it manages its own resources, and move the rest of the
implementation to GLES20RenderEngine and get rid off two virtual functions.
Minor: Clean up some coding style.
BUG: 112585051
Test: Build, flash, boot and run some display validation
Change-Id: I787625089f8959cc273d4756baa7135cb004ed2d
diff --git a/services/surfaceflinger/RenderEngine/gl/GLFramebuffer.cpp b/services/surfaceflinger/RenderEngine/gl/GLFramebuffer.cpp
new file mode 100644
index 0000000..6aca1c8
--- /dev/null
+++ b/services/surfaceflinger/RenderEngine/gl/GLFramebuffer.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "GLFramebuffer.h"
+
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+#include "GLES20RenderEngine.h"
+
+namespace android {
+namespace renderengine {
+namespace gl {
+
+GLFramebuffer::GLFramebuffer(const GLES20RenderEngine& engine)
+ : mEGLDisplay(engine.getEGLDisplay()),
+ mEGLImage(EGL_NO_IMAGE_KHR) {
+ glGenTextures(1, &mTextureName);
+ glGenFramebuffers(1, &mFramebufferName);
+}
+
+GLFramebuffer::~GLFramebuffer() {
+ glDeleteFramebuffers(1, &mFramebufferName);
+ glDeleteTextures(1, &mTextureName);
+ eglDestroyImageKHR(mEGLDisplay, mEGLImage);
+}
+
+bool GLFramebuffer::setNativeWindowBuffer(ANativeWindowBuffer* nativeBuffer) {
+ if (mEGLImage != EGL_NO_IMAGE_KHR) {
+ eglDestroyImageKHR(mEGLDisplay, mEGLImage);
+ mEGLImage = EGL_NO_IMAGE_KHR;
+ }
+
+ if (nativeBuffer) {
+ mEGLImage = eglCreateImageKHR(mEGLDisplay, EGL_NO_CONTEXT,
+ EGL_NATIVE_BUFFER_ANDROID,
+ nativeBuffer, nullptr);
+ if (mEGLImage == EGL_NO_IMAGE_KHR) {
+ return false;
+ }
+ }
+ return true;
+}
+
+} // namespace gl
+} // namespace renderengine
+} // namespace android