blob: c45598cc16bcd6f763492d527297a31fe1726c40 [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
Alec Mourie7d1d4a2019-02-05 01:13:46 +000017#define ATRACE_TAG ATRACE_TAG_GRAPHICS
18
Peiyong Line5a9a7f2018-08-30 15:32:13 -070019#include "GLFramebuffer.h"
20
21#include <GLES/gl.h>
22#include <GLES/glext.h>
23#include <GLES2/gl2.h>
24#include <GLES2/gl2ext.h>
Alec Mouri05483a02018-09-10 21:03:42 +000025#include <nativebase/nativebase.h>
Alec Mourie7d1d4a2019-02-05 01:13:46 +000026#include <utils/Trace.h>
Peiyong Lin7e219eb2018-12-03 05:40:42 -080027#include "GLESRenderEngine.h"
Peiyong Line5a9a7f2018-08-30 15:32:13 -070028
29namespace android {
30namespace renderengine {
31namespace gl {
32
Alec Mourida4cf3b2019-02-12 15:33:01 -080033GLFramebuffer::GLFramebuffer(GLESRenderEngine& engine)
34 : mEngine(engine), mEGLDisplay(engine.getEGLDisplay()), mEGLImage(EGL_NO_IMAGE_KHR) {
Peiyong Line5a9a7f2018-08-30 15:32:13 -070035 glGenTextures(1, &mTextureName);
36 glGenFramebuffers(1, &mFramebufferName);
37}
38
39GLFramebuffer::~GLFramebuffer() {
40 glDeleteFramebuffers(1, &mFramebufferName);
41 glDeleteTextures(1, &mTextureName);
Peiyong Line5a9a7f2018-08-30 15:32:13 -070042}
43
Peiyong Linfb530cf2018-12-15 05:07:38 +000044bool GLFramebuffer::setNativeWindowBuffer(ANativeWindowBuffer* nativeBuffer, bool isProtected) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +000045 ATRACE_CALL();
Peiyong Line5a9a7f2018-08-30 15:32:13 -070046 if (mEGLImage != EGL_NO_IMAGE_KHR) {
Peiyong Line5a9a7f2018-08-30 15:32:13 -070047 mEGLImage = EGL_NO_IMAGE_KHR;
Alec Mouri05483a02018-09-10 21:03:42 +000048 mBufferWidth = 0;
49 mBufferHeight = 0;
Peiyong Line5a9a7f2018-08-30 15:32:13 -070050 }
51
52 if (nativeBuffer) {
Alec Mourida4cf3b2019-02-12 15:33:01 -080053 mEGLImage = mEngine.createFramebufferImageIfNeeded(nativeBuffer, isProtected);
Peiyong Line5a9a7f2018-08-30 15:32:13 -070054 if (mEGLImage == EGL_NO_IMAGE_KHR) {
55 return false;
56 }
Alec Mouri05483a02018-09-10 21:03:42 +000057 mBufferWidth = nativeBuffer->width;
58 mBufferHeight = nativeBuffer->height;
Peiyong Line5a9a7f2018-08-30 15:32:13 -070059 }
60 return true;
61}
62
Peiyong Lin46080ef2018-10-26 18:43:14 -070063} // namespace gl
64} // namespace renderengine
65} // namespace android