1 // Copyright (C) 2022 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #include <cstdint> 18 #include <memory> 19 20 #include <EGL/egl.h> 21 #include <EGL/eglext.h> 22 #include <GLES2/gl2.h> 23 #include <GLES2/gl2ext.h> 24 25 #include "ContextHelper.h" 26 #include "DisplaySurface.h" 27 #include "render-utils/render_api_platform_types.h" 28 29 namespace gfxstream { 30 namespace gl { 31 32 class DisplaySurfaceGl : public gfxstream::DisplaySurfaceImpl { 33 public: 34 static std::unique_ptr<DisplaySurfaceGl> createPbufferSurface(EGLDisplay display, 35 EGLConfig config, 36 EGLContext shareContext, 37 const EGLint* contextAttribs, 38 EGLint width, 39 EGLint height); 40 41 static std::unique_ptr<DisplaySurfaceGl> createWindowSurface(EGLDisplay display, 42 EGLConfig config, 43 EGLContext shareContext, 44 const GLint* contextAttribs, 45 FBNativeWindowType window); 46 47 ~DisplaySurfaceGl(); 48 getContextHelper()49 ContextHelper* getContextHelper() const { return mContextHelper.get(); } 50 getContextForShareContext()51 EGLContext getContextForShareContext() const { return mContext; } 52 getSurface()53 EGLSurface getSurface() const { return mSurface; } 54 55 bool bindContext() const; 56 57 private: 58 friend class DisplayGl; 59 60 DisplaySurfaceGl(EGLDisplay display, 61 EGLSurface surface, 62 EGLContext context); 63 64 EGLDisplay mDisplay = EGL_NO_DISPLAY; 65 EGLSurface mSurface = EGL_NO_SURFACE; 66 EGLContext mContext = EGL_NO_CONTEXT; 67 68 std::unique_ptr<ContextHelper> mContextHelper; 69 }; 70 71 } // namespace gl 72 } // namespace gfxstream 73