1 /* 2 * Copyright (C) 2017 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 #ifndef VIDEOTEX_H 17 #define VIDEOTEX_H 18 19 #include "StreamHandler.h" 20 #include "TexWrapper.h" 21 22 #include <EGL/egl.h> 23 #include <EGL/eglext.h> 24 #include <GLES2/gl2.h> 25 #include <GLES2/gl2ext.h> 26 #include <GLES3/gl3.h> 27 #include <GLES3/gl3ext.h> 28 #include <aidl/android/hardware/automotive/evs/BufferDesc.h> 29 #include <aidl/android/hardware/automotive/evs/IEvsCamera.h> 30 #include <aidl/android/hardware/automotive/evs/IEvsEnumerator.h> 31 #include <aidl/android/hardware/automotive/evs/Stream.h> 32 33 #include <system/graphics-base.h> 34 35 class VideoTex final : public TexWrapper { 36 friend VideoTex* createVideoTexture( 37 const std::shared_ptr<aidl::android::hardware::automotive::evs::IEvsEnumerator>& pEnum, 38 const char* evsCameraId, 39 std::unique_ptr<aidl::android::hardware::automotive::evs::Stream> streamCfg, 40 EGLDisplay glDisplay, bool useExternalMemory, android_pixel_format_t format); 41 42 public: 43 VideoTex() = delete; 44 virtual ~VideoTex(); 45 46 bool refresh(); // returns true if the texture contents were updated 47 48 private: 49 VideoTex(std::shared_ptr<aidl::android::hardware::automotive::evs::IEvsEnumerator> pEnum, 50 std::shared_ptr<aidl::android::hardware::automotive::evs::IEvsCamera> pCamera, 51 std::shared_ptr<StreamHandler> pStreamHandler, EGLDisplay glDisplay); 52 53 std::shared_ptr<aidl::android::hardware::automotive::evs::IEvsEnumerator> mEnumerator; 54 std::shared_ptr<aidl::android::hardware::automotive::evs::IEvsCamera> mCamera; 55 std::shared_ptr<StreamHandler> mStreamHandler; 56 aidl::android::hardware::automotive::evs::BufferDesc mImageBuffer; 57 58 EGLDisplay mDisplay; 59 EGLImageKHR mKHRimage = EGL_NO_IMAGE_KHR; 60 }; 61 62 // Creates a video texture to draw the camera preview. format is effective only 63 // when useExternalMemory is true. 64 VideoTex* createVideoTexture( 65 const std::shared_ptr<aidl::android::hardware::automotive::evs::IEvsEnumerator>& pEnum, 66 const char* deviceName, 67 std::unique_ptr<aidl::android::hardware::automotive::evs::Stream> streamCfg, 68 EGLDisplay glDisplay, bool useExternalMemory = false, 69 android_pixel_format_t format = HAL_PIXEL_FORMAT_RGBA_8888); 70 71 #endif // VIDEOTEX_H 72