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 
17 #ifndef CAR_EVS_APP_RENDERBASE_H
18 #define CAR_EVS_APP_RENDERBASE_H
19 
20 #include <EGL/egl.h>
21 #include <EGL/eglext.h>
22 #include <GLES2/gl2.h>
23 #include <GLES2/gl2ext.h>
24 #include <GLES3/gl3.h>
25 #include <GLES3/gl3ext.h>
26 #include <android/hardware/automotive/evs/1.0/IEvsEnumerator.h>
27 
28 #include <BaseRenderCallback.h>
29 
30 namespace android {
31 namespace automotive {
32 namespace evs {
33 namespace support {
34 
35 using ::android::hardware::automotive::evs::V1_0::BufferDesc;
36 
37 /*
38  * Abstract base class for the workhorse classes that handle the user interaction and display for
39  * each mode of the EVS application.
40  */
41 class RenderBase {
42 public:
~RenderBase()43     virtual ~RenderBase() {};
44 
45     virtual bool activate() = 0;
46     virtual void deactivate() = 0;
47 
48     virtual bool drawFrame(const BufferDesc& tgtBuffer, const BufferDesc& imageBuffer) = 0;
49 
50 protected:
51     static bool prepareGL();
52 
53     static bool attachRenderTarget(const BufferDesc& tgtBuffer);
54     static void detachRenderTarget();
55 
56     // OpenGL state shared among all renderers
57     static EGLDisplay sDisplay;
58     static EGLContext sContext;
59     static EGLSurface sMockSurface;
60     static GLuint sFrameBuffer;
61     static GLuint sColorBuffer;
62     static GLuint sDepthBuffer;
63 
64     static EGLImageKHR sKHRimage;
65 
66     static unsigned sWidth;
67     static unsigned sHeight;
68     static float sAspectRatio;
69 };
70 
71 }  // namespace support
72 }  // namespace evs
73 }  // namespace automotive
74 }  // namespace android
75 
76 #endif  // CAR_EVS_APP_RENDERBASE_H
77