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,
EGLNativeWindowType window,
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,
......
......@@ -11,10 +11,14 @@
#include "libANGLE/renderer/gl/SurfaceGL.h"
struct _CGLContextObject;
typedef _CGLContextObject *CGLContextObj;
@class CALayer;
struct __IOSurface;
typedef __IOSurface *IOSurfaceRef;
@class SwapLayer;
namespace rx
{
......@@ -24,12 +28,36 @@ class FunctionsGL;
class StateManagerGL;
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
{
public:
WindowSurfaceCGL(RendererGL *renderer, CALayer *layer, const FunctionsGL *functions);
WindowSurfaceCGL(RendererGL *renderer,
CALayer *layer,
const FunctionsGL *functions,
CGLContextObj context);
~WindowSurfaceCGL() override;
egl::Error initialize() override;
......@@ -51,27 +79,16 @@ class WindowSurfaceCGL : public SurfaceGL
FramebufferImpl *createDefaultFramebuffer(const gl::Framebuffer::Data &data) override;
private:
struct Surface
{
IOSurfaceRef ioSurface;
GLuint texture;
uint64_t lastPresentNanos;
};
void freeSurfaceData(Surface *surface);
egl::Error initializeSurfaceData(Surface *surface, int width, int height);
SwapLayer *mSwapLayer;
SharedSwapState mSwapState;
uint64_t mCurrentSwapId;
CALayer *mLayer;
CGLContextObj mContext;
const FunctionsGL *mFunctions;
StateManagerGL *mStateManager;
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 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