2011-07-28 14:26:00 +00:00
|
|
|
|
|
|
|
/*
|
2013-02-28 20:16:25 +00:00
|
|
|
* Copyright 2013 Google Inc.
|
2011-07-28 14:26:00 +00:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2014-10-09 12:24:15 +00:00
|
|
|
#ifndef SkGLContext_DEFINED
|
|
|
|
#define SkGLContext_DEFINED
|
2010-12-21 16:26:39 +00:00
|
|
|
|
2011-10-19 20:43:20 +00:00
|
|
|
#include "GrGLInterface.h"
|
2015-07-29 18:10:46 +00:00
|
|
|
#include "../private/SkGpuFenceSync.h"
|
2010-12-21 16:26:39 +00:00
|
|
|
|
2010-12-23 15:00:45 +00:00
|
|
|
/**
|
2011-10-19 20:43:20 +00:00
|
|
|
* Create an offscreen opengl context with an RGBA8 / 8bit stencil FBO.
|
|
|
|
* Provides a GrGLInterface struct of function pointers for the context.
|
2015-11-22 22:51:00 +00:00
|
|
|
* This class is intended for Skia's testing needs and not for general
|
|
|
|
* use.
|
2010-12-23 15:00:45 +00:00
|
|
|
*/
|
2016-01-07 07:49:30 +00:00
|
|
|
class SK_API SkGLContext : public SkNoncopyable {
|
2010-12-21 16:26:39 +00:00
|
|
|
public:
|
2016-01-07 07:49:30 +00:00
|
|
|
virtual ~SkGLContext();
|
2010-12-21 16:26:39 +00:00
|
|
|
|
2014-10-16 06:03:54 +00:00
|
|
|
bool isValid() const { return NULL != gl(); }
|
2011-08-19 17:22:05 +00:00
|
|
|
|
2014-10-16 06:03:54 +00:00
|
|
|
const GrGLInterface* gl() const { return fGL.get(); }
|
2011-05-17 14:24:46 +00:00
|
|
|
|
2015-06-23 20:23:44 +00:00
|
|
|
bool fenceSyncSupport() const { return SkToBool(fFenceSync); }
|
|
|
|
|
|
|
|
bool getMaxGpuFrameLag(int* maxFrameLag) const {
|
|
|
|
if (!fFenceSync) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*maxFrameLag = kMaxFrameLag;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void makeCurrent() const;
|
2011-10-19 20:43:20 +00:00
|
|
|
|
2015-11-22 22:51:00 +00:00
|
|
|
/** Used for testing EGLImage integration. Take a GL_TEXTURE_2D and wraps it in an EGL Image */
|
|
|
|
virtual GrEGLImage texture2DToEGLImage(GrGLuint /*texID*/) const { return 0; }
|
|
|
|
virtual void destroyEGLImage(GrEGLImage) const {}
|
|
|
|
|
2016-01-14 17:24:09 +00:00
|
|
|
/** Used for testing GL_TEXTURE_RECTANGLE integration. */
|
|
|
|
GrGLint createTextureRectangle(int width, int height, GrGLenum internalFormat,
|
|
|
|
GrGLenum externalFormat, GrGLenum externalType,
|
|
|
|
GrGLvoid* data);
|
|
|
|
|
2015-11-22 22:51:00 +00:00
|
|
|
/**
|
|
|
|
* Used for testing EGLImage integration. Takes a EGLImage and wraps it in a
|
|
|
|
* GL_TEXTURE_EXTERNAL_OES.
|
|
|
|
*/
|
|
|
|
virtual GrGLuint eglImageToExternalTexture(GrEGLImage) const { return 0; }
|
|
|
|
|
2016-01-20 21:09:12 +00:00
|
|
|
void swapBuffers();
|
|
|
|
|
2013-10-09 18:25:38 +00:00
|
|
|
/**
|
2015-06-23 20:23:44 +00:00
|
|
|
* The only purpose of this function it to provide a means of scheduling
|
2013-10-09 18:25:38 +00:00
|
|
|
* work on the GPU (since all of the subclasses create primary buffers for
|
|
|
|
* testing that are small and not meant to be rendered to the screen).
|
|
|
|
*
|
2015-06-23 20:23:44 +00:00
|
|
|
* If the platform supports fence sync (OpenGL 3.2+ or EGL_KHR_fence_sync),
|
|
|
|
* this will not swap any buffers, but rather emulate triple buffer
|
|
|
|
* synchronization using fences.
|
|
|
|
*
|
|
|
|
* Otherwise it will call the platform SwapBuffers method. This may or may
|
|
|
|
* not perform some sort of synchronization, depending on whether the
|
|
|
|
* drawing surface provided by the platform is double buffered.
|
2013-10-09 18:25:38 +00:00
|
|
|
*/
|
2016-01-20 21:09:12 +00:00
|
|
|
void waitOnSyncOrSwap();
|
2013-10-09 18:25:38 +00:00
|
|
|
|
2014-07-29 15:01:52 +00:00
|
|
|
/**
|
|
|
|
* This notifies the context that we are deliberately testing abandoning
|
|
|
|
* the context. It is useful for debugging contexts that would otherwise
|
|
|
|
* test that GPU resources are properly deleted. It also allows a debugging
|
|
|
|
* context to test that further GL calls are not made by Skia GPU code.
|
|
|
|
*/
|
|
|
|
void testAbandon();
|
|
|
|
|
2015-11-22 22:51:00 +00:00
|
|
|
/**
|
|
|
|
* Creates a new GL context of the same type and makes the returned context current
|
|
|
|
* (if not null).
|
|
|
|
*/
|
|
|
|
virtual SkGLContext* createNew() const { return nullptr; }
|
|
|
|
|
2015-06-23 20:23:44 +00:00
|
|
|
class GLFenceSync; // SkGpuFenceSync implementation that uses the OpenGL functionality.
|
|
|
|
|
2016-01-28 14:26:35 +00:00
|
|
|
/*
|
|
|
|
* returns the fencesync object owned by this SkGLContext
|
|
|
|
*/
|
|
|
|
SkGpuFenceSync* fenceSync() { return fFenceSync.get(); }
|
|
|
|
|
2011-10-19 20:43:20 +00:00
|
|
|
protected:
|
2014-10-16 06:03:54 +00:00
|
|
|
SkGLContext();
|
2011-10-19 20:43:20 +00:00
|
|
|
|
2015-06-23 20:23:44 +00:00
|
|
|
/*
|
|
|
|
* Methods that sublcasses must call from their constructors and destructors.
|
|
|
|
*/
|
|
|
|
void init(const GrGLInterface*, SkGpuFenceSync* = NULL);
|
|
|
|
void teardown();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Operations that have a platform-dependent implementation.
|
|
|
|
*/
|
|
|
|
virtual void onPlatformMakeCurrent() const = 0;
|
|
|
|
virtual void onPlatformSwapBuffers() const = 0;
|
|
|
|
virtual GrGLFuncPtr onPlatformGetProcAddress(const char*) const = 0;
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum { kMaxFrameLag = 3 };
|
|
|
|
|
|
|
|
SkAutoTDelete<SkGpuFenceSync> fFenceSync;
|
|
|
|
SkPlatformGpuFence fFrameFences[kMaxFrameLag - 1];
|
|
|
|
int fCurrentFenceIdx;
|
|
|
|
|
2014-10-16 06:03:54 +00:00
|
|
|
/** Subclass provides the gl interface object if construction was
|
|
|
|
* successful. */
|
|
|
|
SkAutoTUnref<const GrGLInterface> fGL;
|
2012-06-21 20:25:03 +00:00
|
|
|
|
2015-06-23 20:23:44 +00:00
|
|
|
friend class GLFenceSync; // For onPlatformGetProcAddress.
|
2010-12-21 16:26:39 +00:00
|
|
|
};
|
|
|
|
|
2016-01-20 16:07:01 +00:00
|
|
|
/** Creates platform-dependent GL context object. The shareContext parameter is in an optional
|
|
|
|
* context with which to share display lists. This should be a pointer to an SkGLContext created
|
|
|
|
* with SkCreatePlatformGLContext. NULL indicates that no sharing is to take place. Returns a valid
|
|
|
|
* gl context object or NULL if such can not be created.
|
|
|
|
* Note: If Skia embedder needs a custom GL context that sets up the GL interface, this function
|
|
|
|
* should be implemented by the embedder. Otherwise, the default implementation for the platform
|
|
|
|
* should be compiled in the library.
|
2014-10-09 12:24:15 +00:00
|
|
|
*/
|
2016-01-20 16:07:01 +00:00
|
|
|
SK_API SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI,
|
|
|
|
SkGLContext* shareContext = nullptr);
|
2014-10-09 12:24:15 +00:00
|
|
|
|
2011-10-19 20:43:20 +00:00
|
|
|
/**
|
2013-02-07 19:45:46 +00:00
|
|
|
* Helper macros for using the GL context through the GrGLInterface. Example:
|
2011-10-19 20:43:20 +00:00
|
|
|
* SK_GL(glCtx, GenTextures(1, &texID));
|
|
|
|
*/
|
2014-01-21 16:09:18 +00:00
|
|
|
#define SK_GL(ctx, X) (ctx).gl()->fFunctions.f ## X; \
|
2014-07-01 14:20:11 +00:00
|
|
|
SkASSERT(0 == (ctx).gl()->fFunctions.fGetError())
|
2014-01-21 16:09:18 +00:00
|
|
|
#define SK_GL_RET(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X; \
|
2014-07-01 14:20:11 +00:00
|
|
|
SkASSERT(0 == (ctx).gl()->fFunctions.fGetError())
|
2014-01-21 16:09:18 +00:00
|
|
|
#define SK_GL_NOERRCHECK(ctx, X) (ctx).gl()->fFunctions.f ## X
|
|
|
|
#define SK_GL_RET_NOERRCHECK(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X
|
2011-10-19 20:43:20 +00:00
|
|
|
|
2010-12-23 15:00:45 +00:00
|
|
|
#endif
|