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.
|
|
|
|
*/
|
2016-03-30 16:26:24 +00:00
|
|
|
#ifndef SkGLContext_DEFINED
|
|
|
|
#define SkGLContext_DEFINED
|
2010-12-21 16:26:39 +00:00
|
|
|
|
2016-03-30 16:26:24 +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
|
|
|
/**
|
2016-03-30 16:26:24 +00:00
|
|
|
* Create an offscreen opengl context with an RGBA8 / 8bit stencil FBO.
|
|
|
|
* Provides a GrGLInterface struct of function pointers for the context.
|
|
|
|
* This class is intended for Skia's testing needs and not for general
|
|
|
|
* use.
|
2010-12-23 15:00:45 +00:00
|
|
|
*/
|
2016-03-30 16:26:24 +00:00
|
|
|
class SK_API SkGLContext : public SkNoncopyable {
|
2010-12-21 16:26:39 +00:00
|
|
|
public:
|
2016-03-30 16:26:24 +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
|
|
|
|
2016-03-30 16:26:24 +00:00
|
|
|
const GrGLInterface* gl() const { return fGL.get(); }
|
2011-05-17 14:24:46 +00:00
|
|
|
|
2016-03-16 17:28:35 +00:00
|
|
|
bool fenceSyncSupport() const { return fFenceSync != nullptr; }
|
2015-06-23 20:23:44 +00:00
|
|
|
|
2016-03-30 16:26:24 +00:00
|
|
|
bool getMaxGpuFrameLag(int* maxFrameLag) const {
|
2015-06-23 20:23:44 +00:00
|
|
|
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; }
|
2016-03-30 16:26:24 +00:00
|
|
|
virtual void destroyEGLImage(GrEGLImage) const {}
|
2015-11-22 22:51:00 +00:00
|
|
|
|
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,
|
2016-03-30 16:26:24 +00:00
|
|
|
GrGLvoid* data);
|
2016-01-14 17:24:09 +00:00
|
|
|
|
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).
|
|
|
|
*/
|
2016-03-30 16:26:24 +00:00
|
|
|
virtual SkGLContext* createNew() const { return nullptr; }
|
2015-11-22 22:51:00 +00:00
|
|
|
|
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
|
|
|
/*
|
2016-03-30 16:26:24 +00:00
|
|
|
* returns the fencesync object owned by this SkGLContext
|
2016-01-28 14:26:35 +00:00
|
|
|
*/
|
2016-03-30 16:26:24 +00:00
|
|
|
SkGpuFenceSync* fenceSync() { return fFenceSync.get(); }
|
2016-01-28 14:26:35 +00:00
|
|
|
|
2011-10-19 20:43:20 +00:00
|
|
|
protected:
|
2016-03-30 16:26:24 +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.
|
|
|
|
*/
|
2016-03-30 16:26:24 +00:00
|
|
|
void init(const GrGLInterface*, SkGpuFenceSync* = NULL);
|
2015-06-23 20:23:44 +00:00
|
|
|
void teardown();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Operations that have a platform-dependent implementation.
|
|
|
|
*/
|
|
|
|
virtual void onPlatformMakeCurrent() const = 0;
|
|
|
|
virtual void onPlatformSwapBuffers() const = 0;
|
2016-03-30 16:26:24 +00:00
|
|
|
virtual GrGLFuncPtr onPlatformGetProcAddress(const char*) const = 0;
|
2015-06-23 20:23:44 +00:00
|
|
|
|
|
|
|
private:
|
2016-03-30 16:26:24 +00:00
|
|
|
enum { kMaxFrameLag = 3 };
|
2015-06-23 20:23:44 +00:00
|
|
|
|
2016-03-30 16:26:24 +00:00
|
|
|
SkAutoTDelete<SkGpuFenceSync> fFenceSync;
|
|
|
|
SkPlatformGpuFence fFrameFences[kMaxFrameLag - 1];
|
|
|
|
int fCurrentFenceIdx;
|
2015-06-23 20:23:44 +00:00
|
|
|
|
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
|
2016-03-30 16:26:24 +00:00
|
|
|
* context with which to share display lists. This should be a pointer to an SkGLContext created
|
2016-01-20 16:07:01 +00:00
|
|
|
* 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-03-30 16:26:24 +00:00
|
|
|
SK_API SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI,
|
|
|
|
SkGLContext* shareContext = nullptr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper macros for using the GL context through the GrGLInterface. Example:
|
|
|
|
* SK_GL(glCtx, GenTextures(1, &texID));
|
|
|
|
*/
|
|
|
|
#define SK_GL(ctx, X) (ctx).gl()->fFunctions.f ## X; \
|
|
|
|
SkASSERT(0 == (ctx).gl()->fFunctions.fGetError())
|
|
|
|
#define SK_GL_RET(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X; \
|
|
|
|
SkASSERT(0 == (ctx).gl()->fFunctions.fGetError())
|
|
|
|
#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
|