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