Jamie Gennis | 9c183f2 | 2012-12-03 16:44:16 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | |
Jamie Gennis | 9c183f2 | 2012-12-03 16:44:16 -0800 | [diff] [blame] | 17 | #include <gui/GLConsumer.h> |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 18 | #include <gui/Surface.h> |
Mathias Agopian | b7daa0d | 2013-02-15 14:48:52 -0800 | [diff] [blame] | 19 | #include <gui/SurfaceControl.h> |
Jamie Gennis | 9c183f2 | 2012-12-03 16:44:16 -0800 | [diff] [blame] | 20 | |
| 21 | #include <EGL/egl.h> |
| 22 | #include <GLES2/gl2.h> |
| 23 | |
| 24 | namespace android { |
| 25 | |
| 26 | class SurfaceComposerClient; |
| 27 | class SurfaceControl; |
| 28 | |
| 29 | enum { MAX_SHADER_LINES = 128 }; |
| 30 | |
| 31 | struct ShaderDesc { |
| 32 | const char* name; |
| 33 | const char* vertexShader[MAX_SHADER_LINES]; |
| 34 | const char* fragmentShader[MAX_SHADER_LINES]; |
| 35 | }; |
| 36 | |
| 37 | class GLHelper { |
| 38 | |
| 39 | public: |
| 40 | |
| 41 | enum { DITHER_KERNEL_SIZE = 4 }; |
| 42 | |
| 43 | GLHelper(); |
| 44 | |
| 45 | ~GLHelper(); |
| 46 | |
Huihong Luo | 31b5ac2 | 2022-08-15 20:38:10 -0700 | [diff] [blame] | 47 | bool setUp(const sp<IBinder>& displayToken, const ShaderDesc* shaderDescs, size_t numShaders); |
Jamie Gennis | 9c183f2 | 2012-12-03 16:44:16 -0800 | [diff] [blame] | 48 | |
| 49 | void tearDown(); |
| 50 | |
| 51 | bool makeCurrent(EGLSurface surface); |
| 52 | |
| 53 | bool createSurfaceTexture(uint32_t w, uint32_t h, |
| 54 | sp<GLConsumer>* surfaceTexture, EGLSurface* surface, |
| 55 | GLuint* name); |
| 56 | |
| 57 | bool createWindowSurface(uint32_t w, uint32_t h, |
| 58 | sp<SurfaceControl>* surfaceControl, EGLSurface* surface); |
| 59 | |
| 60 | void destroySurface(EGLSurface* surface); |
| 61 | |
| 62 | bool swapBuffers(EGLSurface surface); |
| 63 | |
| 64 | bool getShaderProgram(const char* name, GLuint* outPgm); |
| 65 | |
| 66 | bool getDitherTexture(GLuint* outTexName); |
| 67 | |
| 68 | private: |
| 69 | |
| 70 | bool createNamedSurfaceTexture(GLuint name, uint32_t w, uint32_t h, |
| 71 | sp<GLConsumer>* surfaceTexture, EGLSurface* surface); |
| 72 | |
| 73 | bool computeWindowScale(uint32_t w, uint32_t h, float* scale); |
| 74 | |
| 75 | bool setUpShaders(const ShaderDesc* shaderDescs, size_t numShaders); |
| 76 | |
Jamie Gennis | 9c183f2 | 2012-12-03 16:44:16 -0800 | [diff] [blame] | 77 | EGLDisplay mDisplay; |
| 78 | EGLContext mContext; |
| 79 | EGLSurface mDummySurface; |
| 80 | sp<GLConsumer> mDummyGLConsumer; |
| 81 | EGLConfig mConfig; |
| 82 | |
| 83 | sp<SurfaceComposerClient> mSurfaceComposerClient; |
| 84 | |
| 85 | GLuint* mShaderPrograms; |
| 86 | const ShaderDesc* mShaderDescs; |
| 87 | size_t mNumShaders; |
| 88 | |
| 89 | GLuint mDitherTexture; |
Huihong Luo | 31b5ac2 | 2022-08-15 20:38:10 -0700 | [diff] [blame] | 90 | |
| 91 | sp<IBinder> mDisplayToken; |
Jamie Gennis | 9c183f2 | 2012-12-03 16:44:16 -0800 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | } // namespace android |