1/*
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
11#include "../../private/SkTArray.h"
12#include "GrGLFunctions.h"
13#include "SkString.h"
14
15struct GrGLInterface;
16class SkJSONWriter;
17
18/**
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
21 * use the latter if it is available. It also will query for EGL extensions if a eglQueryString
22 * implementation is provided.
23 */
24class SK_API GrGLExtensions {
25public:
26    GrGLExtensions() : fInitialized(false), fStrings(new SkTArray<SkString>) {}
27
28    GrGLExtensions(const GrGLExtensions&);
29
30    GrGLExtensions& operator=(const GrGLExtensions&);
31
32    void swap(GrGLExtensions* that) {
33        fStrings.swap(that->fStrings);
34        SkTSwap(fInitialized, that->fInitialized);
35    }
36
37    /**
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     */
42    bool init(GrGLStandard standard,
43              GrGLFunction<GrGLGetStringProc> getString,
44              GrGLFunction<GrGLGetStringiProc> getStringi,
45              GrGLFunction<GrGLGetIntegervProc> getIntegerv,
46              GrGLFunction<GrEGLQueryStringProc> queryString = nullptr,
47              GrEGLDisplay eglDisplay = nullptr);
48
49    bool isInitialized() const { return fInitialized; }
50
51    /**
52     * Queries whether an extension is present. This will fail if init() has not been called.
53     */
54    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[]);
60
61    /**
62     * Adds an extension to list
63     */
64    void add(const char[]);
65
66    void reset() { fStrings->reset(); }
67
68    void dumpJSON(SkJSONWriter*) const;
69
70private:
71    bool                                fInitialized;
72    std::unique_ptr<SkTArray<SkString>> fStrings;
73};
74
75#endif
76