blob: d09463a9b80ede5efee630ba7d6937b63d47dc01 [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
Jamie Gennis9c183f22012-12-03 16:44:16 -080017#include <gui/GLConsumer.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080018#include <gui/Surface.h>
Mathias Agopianb7daa0d2013-02-15 14:48:52 -080019#include <gui/SurfaceControl.h>
Jamie Gennis9c183f22012-12-03 16:44:16 -080020
21#include <EGL/egl.h>
22#include <GLES2/gl2.h>
23
24namespace android {
25
26class SurfaceComposerClient;
27class SurfaceControl;
28
29enum { MAX_SHADER_LINES = 128 };
30
31struct ShaderDesc {
32 const char* name;
33 const char* vertexShader[MAX_SHADER_LINES];
34 const char* fragmentShader[MAX_SHADER_LINES];
35};
36
37class GLHelper {
38
39public:
40
41 enum { DITHER_KERNEL_SIZE = 4 };
42
43 GLHelper();
44
45 ~GLHelper();
46
47 bool setUp(const ShaderDesc* shaderDescs, size_t numShaders);
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
68private:
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 Gennis9c183f22012-12-03 16:44:16 -080077 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;
90};
91
92} // namespace android