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