Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 1 | /* |
| 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 Mouri | 05483a0 | 2018-09-10 21:03:42 +0000 | [diff] [blame^] | 23 | #include <nativebase/nativebase.h> |
Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 24 | #include "GLES20RenderEngine.h" |
| 25 | |
| 26 | namespace android { |
| 27 | namespace renderengine { |
| 28 | namespace gl { |
| 29 | |
| 30 | GLFramebuffer::GLFramebuffer(const GLES20RenderEngine& engine) |
| 31 | : mEGLDisplay(engine.getEGLDisplay()), |
| 32 | mEGLImage(EGL_NO_IMAGE_KHR) { |
| 33 | glGenTextures(1, &mTextureName); |
| 34 | glGenFramebuffers(1, &mFramebufferName); |
| 35 | } |
| 36 | |
| 37 | GLFramebuffer::~GLFramebuffer() { |
| 38 | glDeleteFramebuffers(1, &mFramebufferName); |
| 39 | glDeleteTextures(1, &mTextureName); |
| 40 | eglDestroyImageKHR(mEGLDisplay, mEGLImage); |
| 41 | } |
| 42 | |
| 43 | bool GLFramebuffer::setNativeWindowBuffer(ANativeWindowBuffer* nativeBuffer) { |
| 44 | if (mEGLImage != EGL_NO_IMAGE_KHR) { |
| 45 | eglDestroyImageKHR(mEGLDisplay, mEGLImage); |
| 46 | mEGLImage = EGL_NO_IMAGE_KHR; |
Alec Mouri | 05483a0 | 2018-09-10 21:03:42 +0000 | [diff] [blame^] | 47 | mBufferWidth = 0; |
| 48 | mBufferHeight = 0; |
Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 49 | } |
| 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 Mouri | 05483a0 | 2018-09-10 21:03:42 +0000 | [diff] [blame^] | 58 | mBufferWidth = nativeBuffer->width; |
| 59 | mBufferHeight = nativeBuffer->height; |
Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 60 | } |
| 61 | return true; |
| 62 | } |
| 63 | |
| 64 | } // namespace gl |
| 65 | } // namespace renderengine |
| 66 | } // namespace android |