blob: 2982c23552c9aa3cf9a8d414dd9b644741fd6279 [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
Greg Danielcd558522016-11-17 13:31:40 -050029class Frame;
John Reck3b202512014-06-23 13:13:08 -070030class 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:
sergeyv694d4992016-10-27 10:23:13 -070036 static const char* eglErrorString();
John Reck3b202512014-06-23 13:13:08 -070037 // Returns true on success, false on failure
38 void initialize();
39
40 bool hasEglContext();
John Reck3b202512014-06-23 13:13:08 -070041
Romain Guy26a2b972017-04-17 09:39:51 -070042 EGLSurface createSurface(EGLNativeWindowType window, bool wideColorGamut);
John Reck3b202512014-06-23 13:13:08 -070043 void destroySurface(EGLSurface surface);
44
45 void destroy();
46
47 bool isCurrent(EGLSurface surface) { return mCurrentSurface == surface; }
48 // Returns true if the current surface changed, false if it was already current
John Reckf2dcc2a2015-07-16 09:17:59 -070049 bool makeCurrent(EGLSurface surface, EGLint* errOut = nullptr);
John Reck149173d2015-08-10 09:52:29 -070050 Frame beginFrame(EGLSurface surface);
51 void damageFrame(const Frame& frame, const SkRect& dirty);
John Reckc96955d2016-02-26 14:56:44 -080052 // If this returns true it is mandatory that swapBuffers is called
53 // if damageFrame is called without subsequent calls to damageFrame().
54 // See EGL_KHR_partial_update for more information
55 bool damageRequiresSwap();
John Reck149173d2015-08-10 09:52:29 -070056 bool swapBuffers(const Frame& frame, const SkRect& screenDirty);
John Reck3b202512014-06-23 13:13:08 -070057
John Reck1125d1f2014-10-23 11:02:19 -070058 // Returns true iff the surface is now preserving buffers.
59 bool setPreserveBuffer(EGLSurface surface, bool preserve);
John Reck3b202512014-06-23 13:13:08 -070060
John Reck55156372015-01-21 07:46:37 -080061 void fence();
62
John Reck3b202512014-06-23 13:13:08 -070063private:
64 friend class RenderThread;
Chih-Hung Hsieh49796452016-08-10 14:08:35 -070065 explicit EglManager(RenderThread& thread);
John Reck3b202512014-06-23 13:13:08 -070066 // EglContext is never destroyed, method is purposely not implemented
67 ~EglManager();
68
John Reck149173d2015-08-10 09:52:29 -070069 void initExtensions();
John Reckd7db4d72015-05-20 07:18:55 -070070 void createPBufferSurface();
Romain Guy26a2b972017-04-17 09:39:51 -070071 void loadConfigs();
John Reck3b202512014-06-23 13:13:08 -070072 void createContext();
John Reck149173d2015-08-10 09:52:29 -070073 EGLint queryBufferAge(EGLSurface surface);
Season Li13d1b4a2015-07-29 17:16:19 -070074
John Reck3b202512014-06-23 13:13:08 -070075 RenderThread& mRenderThread;
76
77 EGLDisplay mEglDisplay;
78 EGLConfig mEglConfig;
Romain Guy26a2b972017-04-17 09:39:51 -070079 EGLConfig mEglConfigWideGamut;
John Reck3b202512014-06-23 13:13:08 -070080 EGLContext mEglContext;
81 EGLSurface mPBufferSurface;
82
John Reck3b202512014-06-23 13:13:08 -070083 EGLSurface mCurrentSurface;
84
John Reck149173d2015-08-10 09:52:29 -070085 enum class SwapBehavior {
86 Discard,
87 Preserved,
88 BufferAge,
89 };
90 SwapBehavior mSwapBehavior = SwapBehavior::Discard;
John Reck3b202512014-06-23 13:13:08 -070091};
92
93} /* namespace renderthread */
94} /* namespace uirenderer */
95} /* namespace android */
96
97#endif /* EGLMANAGER_H */