blob: 57456c2f51ad98ca91c396de3b88754eef38ca5c [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
robertphillips@google.com6177e692013-02-28 20:16:25 +00003 * Copyright 2013 Google Inc.
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
kkinnunen9e61bb72014-10-09 05:24:15 -07008#ifndef SkGLContext_DEFINED
9#define SkGLContext_DEFINED
reed@google.comc31ce102010-12-21 16:26:39 +000010
bsalomon@google.com373a6632011-10-19 20:43:20 +000011#include "GrGLInterface.h"
reed@google.comc31ce102010-12-21 16:26:39 +000012
reed@google.com873cb1e2010-12-23 15:00:45 +000013/**
bsalomon@google.com373a6632011-10-19 20:43:20 +000014 * Create an offscreen opengl context with an RGBA8 / 8bit stencil FBO.
15 * Provides a GrGLInterface struct of function pointers for the context.
reed@google.com873cb1e2010-12-23 15:00:45 +000016 */
bsalomon@google.com373a6632011-10-19 20:43:20 +000017
kkinnunen9e61bb72014-10-09 05:24:15 -070018class SK_API SkGLContext : public SkRefCnt {
reed@google.comc31ce102010-12-21 16:26:39 +000019public:
kkinnunen9e61bb72014-10-09 05:24:15 -070020 SK_DECLARE_INST_COUNT(SkGLContext)
robertphillips@google.com15e9d3e2012-06-21 20:25:03 +000021
mtklein72c9faa2015-01-09 10:06:39 -080022 ~SkGLContext() SK_OVERRIDE;
reed@google.comc31ce102010-12-21 16:26:39 +000023
kkinnunen30bc88c2014-10-15 23:03:54 -070024 bool isValid() const { return NULL != gl(); }
reed@google.comc31ce102010-12-21 16:26:39 +000025
kkinnunen30bc88c2014-10-15 23:03:54 -070026 const GrGLInterface* gl() const { return fGL.get(); }
bungeman@google.com16bab872011-05-17 14:24:46 +000027
bsalomon@google.com373a6632011-10-19 20:43:20 +000028 virtual void makeCurrent() const = 0;
29
djsollen@google.comc9542ca2013-10-09 18:25:38 +000030 /**
31 * The primary purpose of this function it to provide a means of scheduling
32 * work on the GPU (since all of the subclasses create primary buffers for
33 * testing that are small and not meant to be rendered to the screen).
34 *
35 * If the drawing surface provided by the platform is double buffered this
36 * call will cause the platform to swap which buffer is currently being
37 * targeted. If the current surface does not include a back buffer, this
38 * call has no effect.
39 */
40 virtual void swapBuffers() const = 0;
41
bsalomon944bcf02014-07-29 08:01:52 -070042 /**
43 * This notifies the context that we are deliberately testing abandoning
44 * the context. It is useful for debugging contexts that would otherwise
45 * test that GPU resources are properly deleted. It also allows a debugging
46 * context to test that further GL calls are not made by Skia GPU code.
47 */
48 void testAbandon();
49
bsalomon@google.com373a6632011-10-19 20:43:20 +000050protected:
kkinnunen30bc88c2014-10-15 23:03:54 -070051 SkGLContext();
bsalomon@google.com373a6632011-10-19 20:43:20 +000052
kkinnunen30bc88c2014-10-15 23:03:54 -070053 /** Subclass provides the gl interface object if construction was
54 * successful. */
55 SkAutoTUnref<const GrGLInterface> fGL;
robertphillips@google.com15e9d3e2012-06-21 20:25:03 +000056
57 typedef SkRefCnt INHERITED;
reed@google.comc31ce102010-12-21 16:26:39 +000058};
59
kkinnunen9e61bb72014-10-09 05:24:15 -070060/** Creates platform-dependent GL context object
kkinnunen30bc88c2014-10-15 23:03:54 -070061 * Returns a valid gl context object or NULL if such can not be created.
kkinnunen9e61bb72014-10-09 05:24:15 -070062 * Note: If Skia embedder needs a custom GL context that sets up the GL
63 * interface, this function should be implemented by the embedder.
64 * Otherwise, the default implementation for the platform should be compiled in
65 * the library.
66 */
kkinnunen30bc88c2014-10-15 23:03:54 -070067SK_API SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI);
kkinnunen9e61bb72014-10-09 05:24:15 -070068
bsalomon@google.com373a6632011-10-19 20:43:20 +000069/**
robertphillips@google.comfe1b5362013-02-07 19:45:46 +000070 * Helper macros for using the GL context through the GrGLInterface. Example:
bsalomon@google.com373a6632011-10-19 20:43:20 +000071 * SK_GL(glCtx, GenTextures(1, &texID));
72 */
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +000073#define SK_GL(ctx, X) (ctx).gl()->fFunctions.f ## X; \
bsalomon9245b7e2014-07-01 07:20:11 -070074 SkASSERT(0 == (ctx).gl()->fFunctions.fGetError())
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +000075#define SK_GL_RET(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X; \
bsalomon9245b7e2014-07-01 07:20:11 -070076 SkASSERT(0 == (ctx).gl()->fFunctions.fGetError())
commit-bot@chromium.orgc72425a2014-01-21 16:09:18 +000077#define SK_GL_NOERRCHECK(ctx, X) (ctx).gl()->fFunctions.f ## X
78#define SK_GL_RET_NOERRCHECK(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X
bsalomon@google.com373a6632011-10-19 20:43:20 +000079
reed@google.com873cb1e2010-12-23 15:00:45 +000080#endif