1 /* 2 * Copyright (C) 2023 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 #pragma once 18 19 #include <EGL/egl.h> 20 #include <EGL/eglext.h> 21 #include <GLES2/gl2.h> 22 #include <GLES2/gl2ext.h> 23 #include <GLES3/gl3.h> 24 #include <GLES3/gl3ext.h> 25 #include <aidl/android/frameworks/automotive/display/ICarDisplayProxy.h> 26 #include <aidl/android/hardware/automotive/evs/BufferDesc.h> 27 #include <android-base/logging.h> 28 #include <cutils/native_handle.h> 29 30 namespace aidl::android::hardware::automotive::evs::implementation { 31 32 namespace automotivedisplay = ::aidl::android::frameworks::automotive::display; 33 34 class GlWrapper { 35 public: 36 bool initialize(const std::shared_ptr<automotivedisplay::ICarDisplayProxy>& svc, 37 uint64_t displayId); 38 void shutdown(); 39 40 bool updateImageTexture( 41 buffer_handle_t handle, 42 const ::aidl::android::hardware::graphics::common::HardwareBufferDescription& 43 description); 44 void renderImageToScreen(); 45 46 void showWindow(const std::shared_ptr<automotivedisplay::ICarDisplayProxy>& svc, 47 uint64_t displayId); 48 void hideWindow(const std::shared_ptr<automotivedisplay::ICarDisplayProxy>& svc, 49 uint64_t displayId); 50 getWidth()51 unsigned getWidth() { return mWidth; }; getHeight()52 unsigned getHeight() { return mHeight; }; 53 54 private: 55 EGLDisplay mDisplay; 56 EGLSurface mSurface; 57 EGLContext mContext; 58 59 unsigned mWidth = 0; 60 unsigned mHeight = 0; 61 62 EGLImageKHR mKHRimage = EGL_NO_IMAGE_KHR; 63 64 GLuint mTextureMap = 0; 65 GLuint mShaderProgram = 0; 66 67 // Opaque handle for a native hardware buffer defined in 68 // frameworks/native/opengl/include/EGL/eglplatform.h 69 ANativeWindow* mWindow; 70 }; 71 72 } // namespace aidl::android::hardware::automotive::evs::implementation 73