blob: b1a18a96a83a6d5e247281d0c22f8edb3613f673 [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
John Reck55156372015-01-21 07:46:37 -080058 void fence();
59
John Reck3b202512014-06-23 13:13:08 -070060private:
61 friend class RenderThread;
62
63 EglManager(RenderThread& thread);
64 // EglContext is never destroyed, method is purposely not implemented
65 ~EglManager();
66
67 void loadConfig();
68 void createContext();
69 void initAtlas();
70
71 RenderThread& mRenderThread;
72
73 EGLDisplay mEglDisplay;
74 EGLConfig mEglConfig;
75 EGLContext mEglContext;
76 EGLSurface mPBufferSurface;
77
John Reck1125d1f2014-10-23 11:02:19 -070078 const bool mAllowPreserveBuffer;
79 bool mCanSetPreserveBuffer;
John Reck3b202512014-06-23 13:13:08 -070080
81 EGLSurface mCurrentSurface;
82
83 sp<GraphicBuffer> mAtlasBuffer;
84 int64_t* mAtlasMap;
85 size_t mAtlasMapSize;
John Reck0e89e2b2014-10-31 14:49:06 -070086
87 // Whether or not we are in the middle of drawing a frame. This is used
88 // to avoid switching surfaces mid-frame if requireGlContext() is called
89 // TODO: Need to be better about surface/context management so that this isn't
90 // necessary
91 bool mInFrame;
John Reck3b202512014-06-23 13:13:08 -070092};
93
94} /* namespace renderthread */
95} /* namespace uirenderer */
96} /* namespace android */
97
98#endif /* EGLMANAGER_H */