1 // 2 // Copyright 2017 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 7 // PBufferSurfaceCGL.h: an implementation of PBuffers created from IOSurfaces using 8 // EGL_ANGLE_iosurface_client_buffer 9 10 #ifndef LIBANGLE_RENDERER_GL_CGL_IOSURFACESURFACECGL_H_ 11 #define LIBANGLE_RENDERER_GL_CGL_IOSURFACESURFACECGL_H_ 12 13 #include "libANGLE/renderer/gl/SurfaceGL.h" 14 #include "libANGLE/renderer/gl/cgl/DisplayCGL.h" 15 16 struct __IOSurface; 17 typedef __IOSurface *IOSurfaceRef; 18 19 namespace egl 20 { 21 class AttributeMap; 22 } // namespace egl 23 24 namespace rx 25 { 26 27 class DisplayCGL; 28 class FunctionsGL; 29 class StateManagerGL; 30 31 class IOSurfaceSurfaceCGL : public SurfaceGL 32 { 33 public: 34 IOSurfaceSurfaceCGL(const egl::SurfaceState &state, 35 RendererGL *renderer, 36 CGLContextObj cglContext, 37 EGLClientBuffer buffer, 38 const egl::AttributeMap &attribs); 39 ~IOSurfaceSurfaceCGL() override; 40 41 egl::Error initialize(const egl::Display *display) override; 42 egl::Error makeCurrent(const gl::Context *context) override; 43 egl::Error unMakeCurrent(const gl::Context *context) override; 44 45 egl::Error swap(const gl::Context *context) override; 46 egl::Error postSubBuffer(const gl::Context *context, 47 EGLint x, 48 EGLint y, 49 EGLint width, 50 EGLint height) override; 51 egl::Error querySurfacePointerANGLE(EGLint attribute, void **value) override; 52 egl::Error bindTexImage(const gl::Context *context, 53 gl::Texture *texture, 54 EGLint buffer) override; 55 egl::Error releaseTexImage(const gl::Context *context, EGLint buffer) override; 56 void setSwapInterval(const egl::Display *display, EGLint interval) override; 57 58 EGLint getWidth() const override; 59 EGLint getHeight() const override; 60 61 EGLint isPostSubBufferSupported() const override; 62 EGLint getSwapBehavior() const override; 63 64 static bool validateAttributes(EGLClientBuffer buffer, const egl::AttributeMap &attribs); 65 66 bool hasEmulatedAlphaChannel() const override; 67 68 egl::Error attachToFramebuffer(const gl::Context *context, 69 gl::Framebuffer *framebuffer) override; 70 egl::Error detachFromFramebuffer(const gl::Context *context, 71 gl::Framebuffer *framebuffer) override; 72 73 private: 74 angle::Result initializeAlphaChannel(const gl::Context *context, GLuint texture); 75 76 // TODO(geofflang): Don't store these, they are potentially specific to a single GL context. 77 // http://anglebug.com/40096492 78 const FunctionsGL *mFunctions; 79 StateManagerGL *mStateManager; 80 81 CGLContextObj mCGLContext; 82 IOSurfaceRef mIOSurface; 83 int mWidth; 84 int mHeight; 85 int mPlane; 86 int mFormatIndex; 87 88 bool mAlphaInitialized; 89 90 GLuint mTextureID; 91 GLuint mFramebufferID; 92 }; 93 94 } // namespace rx 95 96 #endif // LIBANGLE_RENDERER_GL_CGL_IOSURFACESURFACECGL_H_ 97