EglWindow.h revision aaa3f358410701710e31f31de62f0b4521989661
1/*
2 * Copyright 2013 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 SCREENRECORD_EGL_WINDOW_H
18#define SCREENRECORD_EGL_WINDOW_H
19
20#include <gui/BufferQueue.h>
21#include <utils/Errors.h>
22
23#include <EGL/egl.h>
24
25namespace android {
26
27/*
28 * Wraps EGL display, context, surface, config for a window surface.
29 *
30 * Not thread safe.
31 */
32class EglWindow {
33public:
34    EglWindow() :
35        mEglDisplay(EGL_NO_DISPLAY),
36        mEglContext(EGL_NO_CONTEXT),
37        mEglSurface(EGL_NO_SURFACE),
38        mEglConfig(NULL),
39        mWidth(0),
40        mHeight(0)
41        {}
42    ~EglWindow() { eglRelease(); }
43
44    // Creates an EGL window for the supplied surface.
45    status_t createWindow(const sp<IGraphicBufferProducer>& surface);
46
47    // Return width and height values (obtained from IGBP).
48    int getWidth() const { return mWidth; }
49    int getHeight() const { return mHeight; }
50
51    // Release anything we created.
52    void release() { eglRelease(); }
53
54    // Make this context current.
55    status_t makeCurrent() const;
56
57    // Sets the presentation time on the current EGL buffer.
58    void presentationTime(nsecs_t whenNsec) const;
59
60    // Swaps the EGL buffer.
61    void swapBuffers() const;
62
63private:
64    EglWindow(const EglWindow&);
65    EglWindow& operator=(const EglWindow&);
66
67    // Init display, create config and context.
68    status_t eglSetupContext();
69    void eglRelease();
70
71    // Basic EGL goodies.
72    EGLDisplay mEglDisplay;
73    EGLContext mEglContext;
74    EGLSurface mEglSurface;
75    EGLConfig mEglConfig;
76
77    // Surface dimensions.
78    int mWidth;
79    int mHeight;
80};
81
82}; // namespace android
83
84#endif /*SCREENRECORD_EGL_WINDOW_H*/
85