blob: 7a9e9e3ea22e81434a5ec4e9310596c439d5505a [file] [log] [blame]
Jamie Gennis9c183f22012-12-03 16:44:16 -08001/*
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 Stoza70982a52016-01-11 23:40:44 +000017#include <gui/GraphicBufferAlloc.h>
Jamie Gennis9c183f22012-12-03 16:44:16 -080018#include <gui/GLConsumer.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080019#include <gui/Surface.h>
Mathias Agopianb7daa0d2013-02-15 14:48:52 -080020#include <gui/SurfaceControl.h>
Jamie Gennis9c183f22012-12-03 16:44:16 -080021
22#include <EGL/egl.h>
23#include <GLES2/gl2.h>
24
25namespace android {
26
27class SurfaceComposerClient;
28class SurfaceControl;
29
30enum { MAX_SHADER_LINES = 128 };
31
32struct ShaderDesc {
33 const char* name;
34 const char* vertexShader[MAX_SHADER_LINES];
35 const char* fragmentShader[MAX_SHADER_LINES];
36};
37
38class GLHelper {
39
40public:
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
69private:
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 Stoza70982a52016-01-11 23:40:44 +000078 sp<GraphicBufferAlloc> mGraphicBufferAlloc;
79
Jamie Gennis9c183f22012-12-03 16:44:16 -080080 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