blob: bb5d24b0557f9ded1214d897e538c4df67b9153d [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>
John Reckd04794a2015-05-08 10:04:36 -070021#include <SkRect.h>
John Reck3b202512014-06-23 13:13:08 -070022#include <ui/GraphicBuffer.h>
23#include <utils/StrongPointer.h>
Season Li13d1b4a2015-07-29 17:16:19 -070024#include <set>
John Reck3b202512014-06-23 13:13:08 -070025
26namespace android {
27namespace uirenderer {
28namespace renderthread {
29
30class RenderThread;
31
32// This class contains the shared global EGL objects, such as EGLDisplay
33// and EGLConfig, which are re-used by CanvasContext
34class EglManager {
35public:
36 // Returns true on success, false on failure
37 void initialize();
38
39 bool hasEglContext();
John Reck3b202512014-06-23 13:13:08 -070040
Season Li13d1b4a2015-07-29 17:16:19 -070041 bool hasEglExtension(const char* extension) const;
42
John Reck3b202512014-06-23 13:13:08 -070043 EGLSurface createSurface(EGLNativeWindowType window);
44 void destroySurface(EGLSurface surface);
45
46 void destroy();
47
48 bool isCurrent(EGLSurface surface) { return mCurrentSurface == surface; }
49 // Returns true if the current surface changed, false if it was already current
John Reckf2dcc2a2015-07-16 09:17:59 -070050 bool makeCurrent(EGLSurface surface, EGLint* errOut = nullptr);
Season Li13d1b4a2015-07-29 17:16:19 -070051 void beginFrame(EGLSurface surface, EGLint* width, EGLint* height, EGLint* framebufferAge);
John Reckd04794a2015-05-08 10:04:36 -070052 bool swapBuffers(EGLSurface surface, const SkRect& dirty, EGLint width, EGLint height);
John Reck3b202512014-06-23 13:13:08 -070053
John Reck1125d1f2014-10-23 11:02:19 -070054 // Returns true iff the surface is now preserving buffers.
55 bool setPreserveBuffer(EGLSurface surface, bool preserve);
John Reck3b202512014-06-23 13:13:08 -070056
Season Li13d1b4a2015-07-29 17:16:19 -070057 bool useBufferAgeExt();
58
John Reck3b202512014-06-23 13:13:08 -070059 void setTextureAtlas(const sp<GraphicBuffer>& buffer, int64_t* map, size_t mapSize);
60
John Reck55156372015-01-21 07:46:37 -080061 void fence();
62
John Reck3b202512014-06-23 13:13:08 -070063private:
64 friend class RenderThread;
65
66 EglManager(RenderThread& thread);
67 // EglContext is never destroyed, method is purposely not implemented
68 ~EglManager();
69
John Reckd7db4d72015-05-20 07:18:55 -070070 void createPBufferSurface();
Season Li13d1b4a2015-07-29 17:16:19 -070071 void loadConfig(bool useBufferAgeExt);
John Reck3b202512014-06-23 13:13:08 -070072 void createContext();
73 void initAtlas();
74
Season Li13d1b4a2015-07-29 17:16:19 -070075 void findExtensions(const char* extensions, std::set<std::string>& list) const;
76
John Reck3b202512014-06-23 13:13:08 -070077 RenderThread& mRenderThread;
78
79 EGLDisplay mEglDisplay;
80 EGLConfig mEglConfig;
81 EGLContext mEglContext;
82 EGLSurface mPBufferSurface;
83
John Reck1125d1f2014-10-23 11:02:19 -070084 const bool mAllowPreserveBuffer;
85 bool mCanSetPreserveBuffer;
John Reck3b202512014-06-23 13:13:08 -070086
Season Li13d1b4a2015-07-29 17:16:19 -070087 bool mHasBufferAgeExt;
88
John Reck3b202512014-06-23 13:13:08 -070089 EGLSurface mCurrentSurface;
90
91 sp<GraphicBuffer> mAtlasBuffer;
92 int64_t* mAtlasMap;
93 size_t mAtlasMapSize;
Season Li13d1b4a2015-07-29 17:16:19 -070094
95 std::set<std::string> mEglExtensionList;
John Reck3b202512014-06-23 13:13:08 -070096};
97
98} /* namespace renderthread */
99} /* namespace uirenderer */
100} /* namespace android */
101
102#endif /* EGLMANAGER_H */