blob: 83d2bdeb9d97a2f7d14309cd26d43da36eb3fd6e [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>
Alec Mouri05483a02018-09-10 21:03:42 +000023#include <nativebase/nativebase.h>
Peiyong Line5a9a7f2018-08-30 15:32:13 -070024#include "GLES20RenderEngine.h"
25
26namespace android {
27namespace renderengine {
28namespace gl {
29
30GLFramebuffer::GLFramebuffer(const GLES20RenderEngine& engine)
31 : mEGLDisplay(engine.getEGLDisplay()),
32 mEGLImage(EGL_NO_IMAGE_KHR) {
33 glGenTextures(1, &mTextureName);
34 glGenFramebuffers(1, &mFramebufferName);
35}
36
37GLFramebuffer::~GLFramebuffer() {
38 glDeleteFramebuffers(1, &mFramebufferName);
39 glDeleteTextures(1, &mTextureName);
40 eglDestroyImageKHR(mEGLDisplay, mEGLImage);
41}
42
43bool GLFramebuffer::setNativeWindowBuffer(ANativeWindowBuffer* nativeBuffer) {
44 if (mEGLImage != EGL_NO_IMAGE_KHR) {
45 eglDestroyImageKHR(mEGLDisplay, mEGLImage);
46 mEGLImage = EGL_NO_IMAGE_KHR;
Alec Mouri05483a02018-09-10 21:03:42 +000047 mBufferWidth = 0;
48 mBufferHeight = 0;
Peiyong Line5a9a7f2018-08-30 15:32:13 -070049 }
50
51 if (nativeBuffer) {
52 mEGLImage = eglCreateImageKHR(mEGLDisplay, EGL_NO_CONTEXT,
53 EGL_NATIVE_BUFFER_ANDROID,
54 nativeBuffer, nullptr);
55 if (mEGLImage == EGL_NO_IMAGE_KHR) {
56 return false;
57 }
Alec Mouri05483a02018-09-10 21:03:42 +000058 mBufferWidth = nativeBuffer->width;
59 mBufferHeight = nativeBuffer->height;
Peiyong Line5a9a7f2018-08-30 15:32:13 -070060 }
61 return true;
62}
63
64} // namespace gl
65} // namespace renderengine
66} // namespace android