| 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 |  | 
| Alec Mouri | 0f71483 | 2018-11-12 15:31:06 -0800 | [diff] [blame] | 17 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS | 
|  | 18 |  | 
| Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 19 | #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 Mouri | 05483a0 | 2018-09-10 21:03:42 +0000 | [diff] [blame] | 25 | #include <nativebase/nativebase.h> | 
| Alec Mouri | 0f71483 | 2018-11-12 15:31:06 -0800 | [diff] [blame] | 26 | #include <utils/Trace.h> | 
| Peiyong Lin | 7e219eb | 2018-12-03 05:40:42 -0800 | [diff] [blame] | 27 | #include "GLESRenderEngine.h" | 
| Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 28 |  | 
|  | 29 | namespace android { | 
|  | 30 | namespace renderengine { | 
|  | 31 | namespace gl { | 
|  | 32 |  | 
| Peiyong Lin | 7e219eb | 2018-12-03 05:40:42 -0800 | [diff] [blame] | 33 | GLFramebuffer::GLFramebuffer(const GLESRenderEngine& engine) | 
| Peiyong Lin | 46080ef | 2018-10-26 18:43:14 -0700 | [diff] [blame] | 34 | : mEGLDisplay(engine.getEGLDisplay()), mEGLImage(EGL_NO_IMAGE_KHR) { | 
| Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 35 | glGenTextures(1, &mTextureName); | 
|  | 36 | glGenFramebuffers(1, &mFramebufferName); | 
|  | 37 | } | 
|  | 38 |  | 
|  | 39 | GLFramebuffer::~GLFramebuffer() { | 
|  | 40 | glDeleteFramebuffers(1, &mFramebufferName); | 
|  | 41 | glDeleteTextures(1, &mTextureName); | 
|  | 42 | eglDestroyImageKHR(mEGLDisplay, mEGLImage); | 
|  | 43 | } | 
|  | 44 |  | 
| Peiyong Lin | fb530cf | 2018-12-15 05:07:38 +0000 | [diff] [blame] | 45 | bool GLFramebuffer::setNativeWindowBuffer(ANativeWindowBuffer* nativeBuffer, bool isProtected) { | 
| Alec Mouri | 0f71483 | 2018-11-12 15:31:06 -0800 | [diff] [blame] | 46 | ATRACE_CALL(); | 
| Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 47 | if (mEGLImage != EGL_NO_IMAGE_KHR) { | 
|  | 48 | eglDestroyImageKHR(mEGLDisplay, mEGLImage); | 
|  | 49 | mEGLImage = EGL_NO_IMAGE_KHR; | 
| Alec Mouri | 05483a0 | 2018-09-10 21:03:42 +0000 | [diff] [blame] | 50 | mBufferWidth = 0; | 
|  | 51 | mBufferHeight = 0; | 
| Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 52 | } | 
|  | 53 |  | 
|  | 54 | if (nativeBuffer) { | 
| Peiyong Lin | fb530cf | 2018-12-15 05:07:38 +0000 | [diff] [blame] | 55 | EGLint attributes[] = { | 
|  | 56 | isProtected ? EGL_PROTECTED_CONTENT_EXT : EGL_NONE, | 
|  | 57 | isProtected ? EGL_TRUE : EGL_NONE, | 
|  | 58 | EGL_NONE, | 
|  | 59 | }; | 
| Peiyong Lin | 46080ef | 2018-10-26 18:43:14 -0700 | [diff] [blame] | 60 | mEGLImage = eglCreateImageKHR(mEGLDisplay, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID, | 
| Peiyong Lin | fb530cf | 2018-12-15 05:07:38 +0000 | [diff] [blame] | 61 | nativeBuffer, attributes); | 
| Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 62 | if (mEGLImage == EGL_NO_IMAGE_KHR) { | 
|  | 63 | return false; | 
|  | 64 | } | 
| Alec Mouri | 05483a0 | 2018-09-10 21:03:42 +0000 | [diff] [blame] | 65 | mBufferWidth = nativeBuffer->width; | 
|  | 66 | mBufferHeight = nativeBuffer->height; | 
| Peiyong Lin | e5a9a7f | 2018-08-30 15:32:13 -0700 | [diff] [blame] | 67 | } | 
|  | 68 | return true; | 
|  | 69 | } | 
|  | 70 |  | 
| Peiyong Lin | 46080ef | 2018-10-26 18:43:14 -0700 | [diff] [blame] | 71 | } // namespace gl | 
|  | 72 | } // namespace renderengine | 
|  | 73 | } // namespace android |