blob: 8252b6229a04b72c0b03ad1041c0d950a43b6723 [file] [log] [blame]
Zach Reizner6cbe8832015-06-26 18:25:38 -07001/*
2 * Copyright (C) 2015 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#ifndef ANDROID_GL_WORKER_H_
18#define ANDROID_GL_WORKER_H_
19
Zach Reizner6cbe8832015-06-26 18:25:38 -070020#include <memory>
21#include <vector>
22
23#define EGL_EGLEXT_PROTOTYPES
24#define GL_GLEXT_PROTOTYPES
25
26#include <EGL/egl.h>
27#include <EGL/eglext.h>
28#include <GLES2/gl2.h>
29#include <GLES2/gl2ext.h>
30
Zach Reiznerdac5d192015-07-15 18:44:37 -070031#include <ui/GraphicBuffer.h>
32
Zach Reizner6cbe8832015-06-26 18:25:38 -070033struct hwc_layer_1;
34
35namespace android {
36
37#define AUTO_GL_TYPE(name, type, zero, deleter) \
38 struct name##Deleter { \
39 typedef type pointer; \
40 \
41 void operator()(pointer p) const { \
42 if (p != zero) { \
43 deleter; \
44 } \
45 } \
46 }; \
47 typedef std::unique_ptr<type, name##Deleter> name;
48
49AUTO_GL_TYPE(AutoGLFramebuffer, GLuint, 0, glDeleteFramebuffers(1, &p))
50AUTO_GL_TYPE(AutoGLBuffer, GLuint, 0, glDeleteBuffers(1, &p))
51AUTO_GL_TYPE(AutoGLTexture, GLuint, 0, glDeleteTextures(1, &p))
52AUTO_GL_TYPE(AutoGLShader, GLint, 0, glDeleteShader(p))
53AUTO_GL_TYPE(AutoGLProgram, GLint, 0, glDeleteProgram(p))
54
55struct EGLImageDeleter {
56 typedef EGLImageKHR pointer;
57
58 EGLDisplay egl_display_;
59
60 EGLImageDeleter(EGLDisplay egl_display) : egl_display_(egl_display) {
61 }
62
63 void operator()(EGLImageKHR p) const {
64 if (p != EGL_NO_IMAGE_KHR) {
65 eglDestroyImageKHR(egl_display_, p);
66 }
67 }
68};
69typedef std::unique_ptr<EGLImageKHR, EGLImageDeleter> AutoEGLImageKHR;
70
71struct AutoEGLImageAndGLTexture {
72 AutoEGLImageKHR image;
73 AutoGLTexture texture;
74
75 AutoEGLImageAndGLTexture(EGLDisplay egl_display)
76 : image(EGL_NO_IMAGE_KHR, EGLImageDeleter(egl_display)) {
77 }
78};
79
Zach Reiznerdac5d192015-07-15 18:44:37 -070080class GLWorkerCompositor {
81 public:
82 GLWorkerCompositor();
83 ~GLWorkerCompositor();
84
85 int Init();
86
87 int Composite(hwc_layer_1 *layers, size_t num_layers,
88 sp<GraphicBuffer> framebuffer);
Zach Reizner713a6782015-07-31 15:12:44 -070089 int CompositeAndFinish(hwc_layer_1 *layers, size_t num_layers,
90 sp<GraphicBuffer> framebuffer);
Zach Reiznerdac5d192015-07-15 18:44:37 -070091
92 private:
93 EGLDisplay egl_display_;
94 EGLContext egl_ctx_;
95
96 std::vector<AutoGLProgram> blend_programs_;
97 AutoGLBuffer vertex_buffer_;
98};
Zach Reizner6cbe8832015-06-26 18:25:38 -070099}
100
101#endif