• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
25 namespace android {
26 
27 /*
28  * Wraps EGL display, context, surface, config for a window surface.
29  *
30  * Not thread safe.
31  */
32 class EglWindow {
33 public:
EglWindow()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         {}
~EglWindow()42     ~EglWindow() { eglRelease(); }
43 
44     // Creates an EGL window for the supplied surface.
45     status_t createWindow(const sp<IGraphicBufferProducer>& surface);
46 
47     // Creates an EGL pbuffer surface.
48     status_t createPbuffer(int width, int height);
49 
50     // Return width and height values (obtained from IGBP).
getWidth()51     int getWidth() const { return mWidth; }
getHeight()52     int getHeight() const { return mHeight; }
53 
54     // Release anything we created.
release()55     void release() { eglRelease(); }
56 
57     // Make this context current.
58     status_t makeCurrent() const;
59 
60     // Sets the presentation time on the current EGL buffer.
61     void presentationTime(nsecs_t whenNsec) const;
62 
63     // Swaps the EGL buffer.
64     void swapBuffers() const;
65 
66 private:
67     EglWindow(const EglWindow&);
68     EglWindow& operator=(const EglWindow&);
69 
70     // Init display, create config and context.
71     status_t eglSetupContext(bool forPbuffer);
72     void eglRelease();
73 
74     // Basic EGL goodies.
75     EGLDisplay mEglDisplay;
76     EGLContext mEglContext;
77     EGLSurface mEglSurface;
78     EGLConfig mEglConfig;
79 
80     // Surface dimensions.
81     int mWidth;
82     int mHeight;
83 };
84 
85 }; // namespace android
86 
87 #endif /*SCREENRECORD_EGL_WINDOW_H*/
88