blob: 8881de62a94d8140aa7858b1a5a98ebf4eb02bee [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>
24
25namespace android {
26namespace uirenderer {
27namespace renderthread {
28
29class RenderThread;
30
31// This class contains the shared global EGL objects, such as EGLDisplay
32// and EGLConfig, which are re-used by CanvasContext
33class EglManager {
34public:
35 // Returns true on success, false on failure
36 void initialize();
37
38 bool hasEglContext();
John Reck3b202512014-06-23 13:13:08 -070039
John Reck3b202512014-06-23 13:13:08 -070040 EGLSurface createSurface(EGLNativeWindowType window);
41 void destroySurface(EGLSurface surface);
42
43 void destroy();
44
45 bool isCurrent(EGLSurface surface) { return mCurrentSurface == surface; }
46 // Returns true if the current surface changed, false if it was already current
47 bool makeCurrent(EGLSurface surface);
48 void beginFrame(EGLSurface surface, EGLint* width, EGLint* height);
John Reckd04794a2015-05-08 10:04:36 -070049 bool swapBuffers(EGLSurface surface, const SkRect& dirty, EGLint width, EGLint height);
John Reck3b202512014-06-23 13:13:08 -070050
John Reck1125d1f2014-10-23 11:02:19 -070051 // Returns true iff the surface is now preserving buffers.
52 bool setPreserveBuffer(EGLSurface surface, bool preserve);
John Reck3b202512014-06-23 13:13:08 -070053
54 void setTextureAtlas(const sp<GraphicBuffer>& buffer, int64_t* map, size_t mapSize);
55
John Reck55156372015-01-21 07:46:37 -080056 void fence();
57
John Reck3b202512014-06-23 13:13:08 -070058private:
59 friend class RenderThread;
60
61 EglManager(RenderThread& thread);
62 // EglContext is never destroyed, method is purposely not implemented
63 ~EglManager();
64
John Reckd7db4d72015-05-20 07:18:55 -070065 void createPBufferSurface();
John Reck3b202512014-06-23 13:13:08 -070066 void loadConfig();
67 void createContext();
68 void initAtlas();
69
70 RenderThread& mRenderThread;
71
72 EGLDisplay mEglDisplay;
73 EGLConfig mEglConfig;
74 EGLContext mEglContext;
75 EGLSurface mPBufferSurface;
76
John Reck1125d1f2014-10-23 11:02:19 -070077 const bool mAllowPreserveBuffer;
78 bool mCanSetPreserveBuffer;
John Reck3b202512014-06-23 13:13:08 -070079
80 EGLSurface mCurrentSurface;
81
82 sp<GraphicBuffer> mAtlasBuffer;
83 int64_t* mAtlasMap;
84 size_t mAtlasMapSize;
John Reck3b202512014-06-23 13:13:08 -070085};
86
87} /* namespace renderthread */
88} /* namespace uirenderer */
89} /* namespace android */
90
91#endif /* EGLMANAGER_H */