blob: 6aca1c8c61e5f4aa2caf157f07bda210b9d03dfc [file] [log] [blame]
Peiyong Line5a9a7f2018-08-30 15:32:13 -07001/*
2 * Copyright 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "GLFramebuffer.h"
18
19#include <GLES/gl.h>
20#include <GLES/glext.h>
21#include <GLES2/gl2.h>
22#include <GLES2/gl2ext.h>
23#include "GLES20RenderEngine.h"
24
25namespace android {
26namespace renderengine {
27namespace gl {
28
29GLFramebuffer::GLFramebuffer(const GLES20RenderEngine& engine)
30 : mEGLDisplay(engine.getEGLDisplay()),
31 mEGLImage(EGL_NO_IMAGE_KHR) {
32 glGenTextures(1, &mTextureName);
33 glGenFramebuffers(1, &mFramebufferName);
34}
35
36GLFramebuffer::~GLFramebuffer() {
37 glDeleteFramebuffers(1, &mFramebufferName);
38 glDeleteTextures(1, &mTextureName);
39 eglDestroyImageKHR(mEGLDisplay, mEGLImage);
40}
41
42bool GLFramebuffer::setNativeWindowBuffer(ANativeWindowBuffer* nativeBuffer) {
43 if (mEGLImage != EGL_NO_IMAGE_KHR) {
44 eglDestroyImageKHR(mEGLDisplay, mEGLImage);
45 mEGLImage = EGL_NO_IMAGE_KHR;
46 }
47
48 if (nativeBuffer) {
49 mEGLImage = eglCreateImageKHR(mEGLDisplay, EGL_NO_CONTEXT,
50 EGL_NATIVE_BUFFER_ANDROID,
51 nativeBuffer, nullptr);
52 if (mEGLImage == EGL_NO_IMAGE_KHR) {
53 return false;
54 }
55 }
56 return true;
57}
58
59} // namespace gl
60} // namespace renderengine
61} // namespace android