blob: 19fdff986383e5db632935110733523b84556a39 [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
17#include <gui/GraphicBufferAlloc.h>
18#include <gui/GLConsumer.h>
19#include <gui/SurfaceTextureClient.h>
20
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
77 sp<GraphicBufferAlloc> mGraphicBufferAlloc;
78
79 EGLDisplay mDisplay;
80 EGLContext mContext;
81 EGLSurface mDummySurface;
82 sp<GLConsumer> mDummyGLConsumer;
83 EGLConfig mConfig;
84
85 sp<SurfaceComposerClient> mSurfaceComposerClient;
86
87 GLuint* mShaderPrograms;
88 const ShaderDesc* mShaderDescs;
89 size_t mNumShaders;
90
91 GLuint mDitherTexture;
92};
93
94} // namespace android