blob: 0355ad292dfb9c6385bef059803ccaab8871ae63 [file] [log] [blame]
bsalomon@google.com1744f972013-02-26 21:46:32 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef GrGLExtensions_DEFINED
9#define GrGLExtensions_DEFINED
10
bungemanbf521ff2016-02-17 13:13:44 -080011#include "../../private/SkTArray.h"
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000012#include "GrGLFunctions.h"
bsalomon@google.com1744f972013-02-26 21:46:32 +000013#include "SkString.h"
bsalomon@google.com1744f972013-02-26 21:46:32 +000014
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000015struct GrGLInterface;
Brian Osman71a18892017-08-10 10:23:25 -040016class SkJSONWriter;
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000017
bsalomon@google.com1744f972013-02-26 21:46:32 +000018/**
19 * This helper queries the current GL context for its extensions, remembers them, and can be
20 * queried. It supports both glGetString- and glGetStringi-style extension string APIs and will
bsalomonb1a32ad2015-11-16 06:48:44 -080021 * use the latter if it is available. It also will query for EGL extensions if a eglQueryString
22 * implementation is provided.
bsalomon@google.com1744f972013-02-26 21:46:32 +000023 */
commit-bot@chromium.org07143602014-02-25 02:14:57 +000024class SK_API GrGLExtensions {
bsalomon@google.com1744f972013-02-26 21:46:32 +000025public:
halcanary385fe4d2015-08-26 13:07:48 -070026 GrGLExtensions() : fInitialized(false), fStrings(new SkTArray<SkString>) {}
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000027
commit-bot@chromium.orgd8ed8512014-01-24 20:49:44 +000028 GrGLExtensions(const GrGLExtensions&);
29
30 GrGLExtensions& operator=(const GrGLExtensions&);
31
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000032 void swap(GrGLExtensions* that) {
bungemana3434d82015-09-07 12:45:52 -070033 fStrings.swap(that->fStrings);
commit-bot@chromium.orgd8ed8512014-01-24 20:49:44 +000034 SkTSwap(fInitialized, that->fInitialized);
bsalomon@google.com1744f972013-02-26 21:46:32 +000035 }
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000036
bsalomon@google.com1744f972013-02-26 21:46:32 +000037 /**
38 * We sometimes need to use this class without having yet created a GrGLInterface. This version
39 * of init expects that getString is always non-NULL while getIntegerv and getStringi are non-
40 * NULL if on desktop GL with version 3.0 or higher. Otherwise it will fail.
41 */
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000042 bool init(GrGLStandard standard,
bsalomon9f2dc272016-02-08 07:22:17 -080043 GrGLFunction<GrGLGetStringProc> getString,
44 GrGLFunction<GrGLGetStringiProc> getStringi,
45 GrGLFunction<GrGLGetIntegervProc> getIntegerv,
46 GrGLFunction<GrEGLQueryStringProc> queryString = nullptr,
bsalomona779ef12015-11-16 08:28:21 -080047 GrEGLDisplay eglDisplay = nullptr);
skia.committer@gmail.com12eea2b2013-02-27 07:10:10 +000048
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000049 bool isInitialized() const { return fInitialized; }
50
bsalomon@google.com1744f972013-02-26 21:46:32 +000051 /**
52 * Queries whether an extension is present. This will fail if init() has not been called.
53 */
commit-bot@chromium.orgd8ed8512014-01-24 20:49:44 +000054 bool has(const char[]) const;
55
56 /**
57 * Removes an extension if present. Returns true if the extension was present before the call.
58 */
59 bool remove(const char[]);
skia.committer@gmail.com12eea2b2013-02-27 07:10:10 +000060
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +000061 /**
62 * Adds an extension to list
63 */
64 void add(const char[]);
65
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000066 void reset() { fStrings->reset(); }
bsalomon@google.com1744f972013-02-26 21:46:32 +000067
Brian Osman71a18892017-08-10 10:23:25 -040068 void dumpJSON(SkJSONWriter*) const;
bsalomon@google.com00142c42013-05-02 19:42:54 +000069
bsalomon@google.com1744f972013-02-26 21:46:32 +000070private:
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000071 bool fInitialized;
bungeman6bd52842016-10-27 09:30:08 -070072 std::unique_ptr<SkTArray<SkString>> fStrings;
bsalomon@google.com1744f972013-02-26 21:46:32 +000073};
74
75#endif