EglManager.h revision 2cdbc7d2283aae3d77b12c8fdbba8ca4bd3db5ea
1/*
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);
50    bool swapBuffers(EGLSurface surface);
51
52    bool enableDirtyRegions(EGLSurface surface);
53
54    void setTextureAtlas(const sp<GraphicBuffer>& buffer, int64_t* map, size_t mapSize);
55
56private:
57    friend class RenderThread;
58
59    EglManager(RenderThread& thread);
60    // EglContext is never destroyed, method is purposely not implemented
61    ~EglManager();
62
63    void loadConfig();
64    void createContext();
65    void initAtlas();
66
67    RenderThread& mRenderThread;
68
69    EGLDisplay mEglDisplay;
70    EGLConfig mEglConfig;
71    EGLContext mEglContext;
72    EGLSurface mPBufferSurface;
73
74    const bool mRequestDirtyRegions;
75    bool mCanSetDirtyRegions;
76
77    EGLSurface mCurrentSurface;
78
79    sp<GraphicBuffer> mAtlasBuffer;
80    int64_t* mAtlasMap;
81    size_t mAtlasMapSize;
82};
83
84} /* namespace renderthread */
85} /* namespace uirenderer */
86} /* namespace android */
87
88#endif /* EGLMANAGER_H */
89