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"
|
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.
|
2010-12-23 15:00:45 +00:00
|
|
|
*/
|
2011-10-19 20:43:20 +00:00
|
|
|
|
2014-10-09 12:24:15 +00:00
|
|
|
class SK_API SkGLContext : public SkRefCnt {
|
2010-12-21 16:26:39 +00:00
|
|
|
public:
|
2014-10-09 12:24:15 +00:00
|
|
|
SK_DECLARE_INST_COUNT(SkGLContext)
|
2012-06-21 20:25:03 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
~SkGLContext() override;
|
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
|
|
|
|
2011-10-19 20:43:20 +00:00
|
|
|
virtual void makeCurrent() const = 0;
|
|
|
|
|
2013-10-09 18:25:38 +00:00
|
|
|
/**
|
|
|
|
* The primary purpose of this function it to provide a means of scheduling
|
|
|
|
* 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).
|
|
|
|
*
|
|
|
|
* If the drawing surface provided by the platform is double buffered this
|
|
|
|
* call will cause the platform to swap which buffer is currently being
|
|
|
|
* targeted. If the current surface does not include a back buffer, this
|
|
|
|
* call has no effect.
|
|
|
|
*/
|
|
|
|
virtual void swapBuffers() const = 0;
|
|
|
|
|
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();
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
typedef SkRefCnt INHERITED;
|
2010-12-21 16:26:39 +00:00
|
|
|
};
|
|
|
|
|
2014-10-09 12:24:15 +00:00
|
|
|
/** Creates platform-dependent GL context object
|
2014-10-16 06:03:54 +00:00
|
|
|
* Returns a valid gl context object or NULL if such can not be created.
|
2014-10-09 12:24:15 +00:00
|
|
|
* 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-16 06:03:54 +00:00
|
|
|
SK_API SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI);
|
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
|