Commit 40eefabd by Corentin Wallez

Rewrite WindowSurfaceCGL to use CAOpenGLLayer

It used to render to IOSurfaces and use setContents to directly give them to the OSX compositor. This was worth the complexity only because Chrome going to use that code path. This is no longer the case. Instead we replace the implementation with one based on CAOpenGLLayer, that basically gets a "draw" callback every frame. The complexity comes from the fact that this callback is called from another thread, with another CGL context. BUG=angleproject:1233 Change-Id: I1878d0071d057e043e0bb9043d9849f50e00d023 Reviewed-on: https://chromium-review.googlesource.com/314031Reviewed-by: 's avatarccameron chromium <ccameron@chromium.org> Tryjob-Request: Corentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Tested-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent dd5c5b79
...@@ -113,7 +113,7 @@ SurfaceImpl *DisplayCGL::createWindowSurface(const egl::Config *configuration, ...@@ -113,7 +113,7 @@ SurfaceImpl *DisplayCGL::createWindowSurface(const egl::Config *configuration,
EGLNativeWindowType window, EGLNativeWindowType window,
const egl::AttributeMap &attribs) const egl::AttributeMap &attribs)
{ {
return new WindowSurfaceCGL(this->getRenderer(), window, mFunctions); return new WindowSurfaceCGL(this->getRenderer(), window, mFunctions, mContext);
} }
SurfaceImpl *DisplayCGL::createPbufferSurface(const egl::Config *configuration, SurfaceImpl *DisplayCGL::createPbufferSurface(const egl::Config *configuration,
......
...@@ -11,10 +11,14 @@ ...@@ -11,10 +11,14 @@
#include "libANGLE/renderer/gl/SurfaceGL.h" #include "libANGLE/renderer/gl/SurfaceGL.h"
struct _CGLContextObject;
typedef _CGLContextObject *CGLContextObj;
@class CALayer; @class CALayer;
struct __IOSurface; struct __IOSurface;
typedef __IOSurface *IOSurfaceRef; typedef __IOSurface *IOSurfaceRef;
@class SwapLayer;
namespace rx namespace rx
{ {
...@@ -24,12 +28,36 @@ class FunctionsGL; ...@@ -24,12 +28,36 @@ class FunctionsGL;
class StateManagerGL; class StateManagerGL;
struct WorkaroundsGL; struct WorkaroundsGL;
class DisplayLink; struct SharedSwapState
{
struct SwapTexture
{
GLuint texture;
unsigned int width;
unsigned int height;
uint64_t swapId;
};
SwapTexture textures[3];
// This code path is not going to be used by Chrome so we take the liberty
// to use pthreads directly instead of using mutexes and condition variables
// via the Platform API.
pthread_mutex_t mutex;
// The following members should be accessed only when holding the mutex
// (or doing construction / destruction)
SwapTexture *beingRendered;
SwapTexture *lastRendered;
SwapTexture *beingPresented;
};
class WindowSurfaceCGL : public SurfaceGL class WindowSurfaceCGL : public SurfaceGL
{ {
public: public:
WindowSurfaceCGL(RendererGL *renderer, CALayer *layer, const FunctionsGL *functions); WindowSurfaceCGL(RendererGL *renderer,
CALayer *layer,
const FunctionsGL *functions,
CGLContextObj context);
~WindowSurfaceCGL() override; ~WindowSurfaceCGL() override;
egl::Error initialize() override; egl::Error initialize() override;
...@@ -51,27 +79,16 @@ class WindowSurfaceCGL : public SurfaceGL ...@@ -51,27 +79,16 @@ class WindowSurfaceCGL : public SurfaceGL
FramebufferImpl *createDefaultFramebuffer(const gl::Framebuffer::Data &data) override; FramebufferImpl *createDefaultFramebuffer(const gl::Framebuffer::Data &data) override;
private: private:
struct Surface SwapLayer *mSwapLayer;
{ SharedSwapState mSwapState;
IOSurfaceRef ioSurface; uint64_t mCurrentSwapId;
GLuint texture;
uint64_t lastPresentNanos;
};
void freeSurfaceData(Surface *surface);
egl::Error initializeSurfaceData(Surface *surface, int width, int height);
CALayer *mLayer; CALayer *mLayer;
CGLContextObj mContext;
const FunctionsGL *mFunctions; const FunctionsGL *mFunctions;
StateManagerGL *mStateManager; StateManagerGL *mStateManager;
const WorkaroundsGL &mWorkarounds; const WorkaroundsGL &mWorkarounds;
DisplayLink *mDisplayLink;
// CGL doesn't have a default framebuffer, we instead render to an IOSurface
// that will be set as the content of the CALayer which is our native window.
// We use two IOSurfaces to do double buffering.
Surface mSurfaces[2];
int mCurrentSurface;
GLuint mFramebuffer; GLuint mFramebuffer;
GLuint mDSRenderbuffer; GLuint mDSRenderbuffer;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment