blob: e12db3acbe2f3a0ab446f7133226f69e4d0ac605 [file] [log] [blame]
John Reck3b202512014-06-23 13:13:08 -07001/*
2 * Copyright (C) 2014 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#ifndef EGLMANAGER_H
17#define EGLMANAGER_H
18
19#include <cutils/compiler.h>
20#include <EGL/egl.h>
21#include <ui/GraphicBuffer.h>
22#include <utils/StrongPointer.h>
23
24namespace android {
25namespace uirenderer {
26namespace renderthread {
27
28class RenderThread;
29
30// This class contains the shared global EGL objects, such as EGLDisplay
31// and EGLConfig, which are re-used by CanvasContext
32class EglManager {
33public:
34 // Returns true on success, false on failure
35 void initialize();
36
37 bool hasEglContext();
38 void requireGlContext();
39
40 void usePBufferSurface();
41 EGLSurface createSurface(EGLNativeWindowType window);
42 void destroySurface(EGLSurface surface);
43
44 void destroy();
45
46 bool isCurrent(EGLSurface surface) { return mCurrentSurface == surface; }
47 // Returns true if the current surface changed, false if it was already current
48 bool makeCurrent(EGLSurface surface);
49 void beginFrame(EGLSurface surface, EGLint* width, EGLint* height);
John Reck2cdbc7d2014-09-17 16:06:36 -070050 bool swapBuffers(EGLSurface surface);
John Reck0e89e2b2014-10-31 14:49:06 -070051 void cancelFrame();
John Reck3b202512014-06-23 13:13:08 -070052
John Reck1125d1f2014-10-23 11:02:19 -070053 // Returns true iff the surface is now preserving buffers.
54 bool setPreserveBuffer(EGLSurface surface, bool preserve);
John Reck3b202512014-06-23 13:13:08 -070055
56 void setTextureAtlas(const sp<GraphicBuffer>& buffer, int64_t* map, size_t mapSize);
57
58private:
59 friend class RenderThread;
60
61 EglManager(RenderThread& thread);
62 // EglContext is never destroyed, method is purposely not implemented
63 ~EglManager();
64
65 void loadConfig();
66 void createContext();
67 void initAtlas();
68
69 RenderThread& mRenderThread;
70
71 EGLDisplay mEglDisplay;
72 EGLConfig mEglConfig;
73 EGLContext mEglContext;
74 EGLSurface mPBufferSurface;
75
John Reck1125d1f2014-10-23 11:02:19 -070076 const bool mAllowPreserveBuffer;
77 bool mCanSetPreserveBuffer;
John Reck3b202512014-06-23 13:13:08 -070078
79 EGLSurface mCurrentSurface;
80
81 sp<GraphicBuffer> mAtlasBuffer;
82 int64_t* mAtlasMap;
83 size_t mAtlasMapSize;
John Reck0e89e2b2014-10-31 14:49:06 -070084
85 // Whether or not we are in the middle of drawing a frame. This is used
86 // to avoid switching surfaces mid-frame if requireGlContext() is called
87 // TODO: Need to be better about surface/context management so that this isn't
88 // necessary
89 bool mInFrame;
John Reck3b202512014-06-23 13:13:08 -070090};
91
92} /* namespace renderthread */
93} /* namespace uirenderer */
94} /* namespace android */
95
96#endif /* EGLMANAGER_H */