GrGLCaps.h revision d7a2c1f5fd710581d6233de5c202d3f2627948e0
1f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com/*
2f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com * Copyright 2012 Google Inc.
3f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com *
4f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com * Use of this source code is governed by a BSD-style license that can be
5f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com * found in the LICENSE file.
6f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com */
7f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
8f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
9f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com#ifndef GrGLCaps_DEFINED
10f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com#define GrGLCaps_DEFINED
11f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
12eb1cb5c5b50febad115d859faca91d2d6af3fff2bsalomon#include "GrCaps.h"
13cba99b88fd5fb39def7a094dc32c0745c7a1cfeajvanverth#include "glsl/GrGLSL.h"
148dc7c3a839b38b73af34cc2674a06f49eb1ce527egdaniel#include "GrGLStencilAttachment.h"
15e4b231428e8c14cbc82d20cfb12eb08fc45f8df6piotaixr#include "SkChecksum.h"
162aa1f7e6799501974532d35c1f6c3a0447121b95mtklein#include "SkTHash.h"
17a2d71482db8b6d752a51c96da74768d7dfc27932robertphillips@google.com#include "SkTArray.h"
18f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
19f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.comclass GrGLContextInfo;
20e9c0fc616d2a1632c285885b9b656b68ca8d4f24jvanverthclass GrGLSLCaps;
21f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
22f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com/**
23f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com * Stores some capabilities of a GL context. Most are determined by the GL
24f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com * version and the extensions string. It also tracks formats that have passed
25f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com * the FBO completeness test.
26f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com */
274b91f768b348aa1cebeb54f3ff9331938734c242bsalomonclass GrGLCaps : public GrCaps {
28f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.compublic:
298dc7c3a839b38b73af34cc2674a06f49eb1ce527egdaniel    typedef GrGLStencilAttachment::Format StencilFormat;
30f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
31f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    /**
32f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com     * The type of MSAA for FBOs supported. Different extensions have different
33f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com     * semantics of how / when a resolve is performed.
34f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com     */
35f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    enum MSFBOType {
36f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com        /**
37f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com         * no support for MSAA FBOs
38f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com         */
39fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com        kNone_MSFBOType = 0,
40f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com        /**
416fc1b4998917791a73bf54428513940fe77dc058skia.committer@gmail.com         * GL3.0-style MSAA FBO (GL_ARB_framebuffer_object).
42f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com         */
43347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com        kDesktop_ARB_MSFBOType,
44f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com        /**
45f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com         * earlier GL_EXT_framebuffer* extensions
46f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com         */
47347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com        kDesktop_EXT_MSFBOType,
48f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com        /**
49a8e5a06f69b7e0cb17a4b3203f0a7a1d52aa73eccommit-bot@chromium.org         * Similar to kDesktop_ARB but with additional restrictions on glBlitFramebuffer.
50a8e5a06f69b7e0cb17a4b3203f0a7a1d52aa73eccommit-bot@chromium.org         */
51a8e5a06f69b7e0cb17a4b3203f0a7a1d52aa73eccommit-bot@chromium.org        kES_3_0_MSFBOType,
52a8e5a06f69b7e0cb17a4b3203f0a7a1d52aa73eccommit-bot@chromium.org        /**
53f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com         * GL_APPLE_framebuffer_multisample ES extension
54f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com         */
55347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com        kES_Apple_MSFBOType,
56f3a60c09b975f50bbd14215df10effffd2fd46e8bsalomon@google.com        /**
57347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com         * GL_IMG_multisampled_render_to_texture. This variation does not have MSAA renderbuffers.
58347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com         * Instead the texture is multisampled when bound to the FBO and then resolved automatically
59347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com         * when read. It also defines an alternate value for GL_MAX_SAMPLES (which we call
60347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com         * GR_GL_MAX_SAMPLES_IMG).
61f3a60c09b975f50bbd14215df10effffd2fd46e8bsalomon@google.com         */
62347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com        kES_IMG_MsToTexture_MSFBOType,
63347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com        /**
64347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com         * GL_EXT_multisampled_render_to_texture. Same as the IMG one above but uses the standard
65347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com         * GL_MAX_SAMPLES value.
66347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com         */
67347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com        kES_EXT_MsToTexture_MSFBOType,
68dded69693dd3779f081326cde24c3954505b129dvbuzinov        /**
69dded69693dd3779f081326cde24c3954505b129dvbuzinov         * GL_NV_framebuffer_mixed_samples.
70dded69693dd3779f081326cde24c3954505b129dvbuzinov         */
71dded69693dd3779f081326cde24c3954505b129dvbuzinov        kMixedSamples_MSFBOType,
726b0cf0273fdffbbdf69235b57b5b5a311e7f1ca6bsalomon@google.com
73dded69693dd3779f081326cde24c3954505b129dvbuzinov        kLast_MSFBOType = kMixedSamples_MSFBOType
746b0cf0273fdffbbdf69235b57b5b5a311e7f1ca6bsalomon@google.com    };
756b0cf0273fdffbbdf69235b57b5b5a311e7f1ca6bsalomon@google.com
7652ffbf6be05eb30671529ec86268967fb85c9810commit-bot@chromium.org    enum InvalidateFBType {
7752ffbf6be05eb30671529ec86268967fb85c9810commit-bot@chromium.org        kNone_InvalidateFBType,
7852ffbf6be05eb30671529ec86268967fb85c9810commit-bot@chromium.org        kDiscard_InvalidateFBType,       //<! glDiscardFramebuffer()
7952ffbf6be05eb30671529ec86268967fb85c9810commit-bot@chromium.org        kInvalidate_InvalidateFBType,     //<! glInvalidateFramebuffer()
8052ffbf6be05eb30671529ec86268967fb85c9810commit-bot@chromium.org
8152ffbf6be05eb30671529ec86268967fb85c9810commit-bot@chromium.org        kLast_InvalidateFBType = kInvalidate_InvalidateFBType
82f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    };
83f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
84160b478eed1dd4924a86a87fd60c91139e08ff71commit-bot@chromium.org    enum MapBufferType {
85160b478eed1dd4924a86a87fd60c91139e08ff71commit-bot@chromium.org        kNone_MapBufferType,
86160b478eed1dd4924a86a87fd60c91139e08ff71commit-bot@chromium.org        kMapBuffer_MapBufferType,         // glMapBuffer()
87160b478eed1dd4924a86a87fd60c91139e08ff71commit-bot@chromium.org        kMapBufferRange_MapBufferType,    // glMapBufferRange()
88160b478eed1dd4924a86a87fd60c91139e08ff71commit-bot@chromium.org        kChromium_MapBufferType,          // GL_CHROMIUM_map_sub
89160b478eed1dd4924a86a87fd60c91139e08ff71commit-bot@chromium.org
90160b478eed1dd4924a86a87fd60c91139e08ff71commit-bot@chromium.org        kLast_MapBufferType = kChromium_MapBufferType,
91160b478eed1dd4924a86a87fd60c91139e08ff71commit-bot@chromium.org    };
92160b478eed1dd4924a86a87fd60c91139e08ff71commit-bot@chromium.org
93d7a2c1f5fd710581d6233de5c202d3f2627948e0jvanverth    enum TransferBufferType {
94d7a2c1f5fd710581d6233de5c202d3f2627948e0jvanverth        kNone_TransferBufferType,
95d7a2c1f5fd710581d6233de5c202d3f2627948e0jvanverth        kPBO_TransferBufferType,          // ARB_pixel_buffer_object
96d7a2c1f5fd710581d6233de5c202d3f2627948e0jvanverth        kChromium_TransferBufferType,     // CHROMIUM_pixel_transfer_buffer_object
97d7a2c1f5fd710581d6233de5c202d3f2627948e0jvanverth
98d7a2c1f5fd710581d6233de5c202d3f2627948e0jvanverth        kLast_TransferBufferType = kChromium_TransferBufferType,
99d7a2c1f5fd710581d6233de5c202d3f2627948e0jvanverth    };
100d7a2c1f5fd710581d6233de5c202d3f2627948e0jvanverth
101f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    /**
102f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com     * Initializes the GrGLCaps to the set of features supported in the current
103f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com     * OpenGL context accessible via ctxInfo.
104f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com     */
105682c269a1511200322916af83053e26004c0ec40bsalomon    GrGLCaps(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo,
106682c269a1511200322916af83053e26004c0ec40bsalomon             const GrGLInterface* glInterface);
107f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
108f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    /**
109f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com     * Call to note that a color config has been verified as a valid color
110f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com     * attachment. This may save future calls to glCheckFramebufferStatus
111f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com     * using isConfigVerifiedColorAttachment().
112f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com     */
113f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    void markConfigAsValidColorAttachment(GrPixelConfig config) {
114f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com        fVerifiedColorConfigs.markVerified(config);
115f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    }
116f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
117f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    /**
118f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com     * Call to check whether a config has been verified as a valid color
119f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com     * attachment.
120f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com     */
121f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    bool isConfigVerifiedColorAttachment(GrPixelConfig config) const {
122f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com        return fVerifiedColorConfigs.isVerified(config);
123f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    }
124f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
125f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    /**
126f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com     * Reports the type of MSAA FBO support.
127f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com     */
128f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    MSFBOType msFBOType() const { return fMSFBOType; }
129f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
130f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    /**
131347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com     * Does the supported MSAA FBO extension have MSAA renderbuffers?
132347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com     */
133347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com    bool usesMSAARenderBuffers() const {
134347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com        return kNone_MSFBOType != fMSFBOType &&
135347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com               kES_IMG_MsToTexture_MSFBOType != fMSFBOType &&
136dded69693dd3779f081326cde24c3954505b129dvbuzinov               kES_EXT_MsToTexture_MSFBOType != fMSFBOType &&
137dded69693dd3779f081326cde24c3954505b129dvbuzinov               kMixedSamples_MSFBOType != fMSFBOType;
138347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com    }
139347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com
140347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com    /**
141347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com     * Is the MSAA FBO extension one where the texture is multisampled when bound to an FBO and
142347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com     * then implicitly resolved when read.
143347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com     */
144347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com    bool usesImplicitMSAAResolve() const {
145347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com        return kES_IMG_MsToTexture_MSFBOType == fMSFBOType ||
146347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com               kES_EXT_MsToTexture_MSFBOType == fMSFBOType;
147347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com    }
148347c382d580cd1bc223e11a355b6a1c65d206e34bsalomon@google.com
14952ffbf6be05eb30671529ec86268967fb85c9810commit-bot@chromium.org    InvalidateFBType invalidateFBType() const { return fInvalidateFBType; }
15052ffbf6be05eb30671529ec86268967fb85c9810commit-bot@chromium.org
151160b478eed1dd4924a86a87fd60c91139e08ff71commit-bot@chromium.org    /// What type of buffer mapping is supported?
152160b478eed1dd4924a86a87fd60c91139e08ff71commit-bot@chromium.org    MapBufferType mapBufferType() const { return fMapBufferType; }
153f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
154d7a2c1f5fd710581d6233de5c202d3f2627948e0jvanverth    /// What type of transfer buffer is supported?
155d7a2c1f5fd710581d6233de5c202d3f2627948e0jvanverth    TransferBufferType transferBufferType() const { return fTransferBufferType; }
156d7a2c1f5fd710581d6233de5c202d3f2627948e0jvanverth
157f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    /**
158f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com     * Gets an array of legal stencil formats. These formats are not guaranteed
159f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com     * to be supported by the driver but are legal GLenum names given the GL
160f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com     * version and extensions supported.
161f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com     */
162f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    const SkTArray<StencilFormat, true>& stencilFormats() const {
163f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com        return fStencilFormats;
164f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    }
165f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
166f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    /// The maximum number of fragment uniform vectors (GLES has min. 16).
167f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    int maxFragmentUniformVectors() const { return fMaxFragmentUniformVectors; }
168f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
169a15f7e5b96ee3d71fdbcb4f9cf02f6a09b4b11accommit-bot@chromium.org    /// maximum number of attribute values per vertex
17060da4176425c74cf112d7e116f54a530a82d0d68bsalomon@google.com    int maxVertexAttributes() const { return fMaxVertexAttributes; }
17160da4176425c74cf112d7e116f54a530a82d0d68bsalomon@google.com
172a15f7e5b96ee3d71fdbcb4f9cf02f6a09b4b11accommit-bot@chromium.org    /// maximum number of texture units accessible in the fragment shader.
173a15f7e5b96ee3d71fdbcb4f9cf02f6a09b4b11accommit-bot@chromium.org    int maxFragmentTextureUnits() const { return fMaxFragmentTextureUnits; }
174a15f7e5b96ee3d71fdbcb4f9cf02f6a09b4b11accommit-bot@chromium.org
175f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    /// ES requires an extension to support RGBA8 in RenderBufferStorage
176f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    bool rgba8RenderbufferSupport() const { return fRGBA8RenderbufferSupport; }
177f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
178f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    /**
179f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com     * Depending on the ES extensions present the BGRA external format may
180f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com     * correspond either a BGRA or RGBA internalFormat. On desktop GL it is
181f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com     * RGBA.
182f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com     */
183f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    bool bgraIsInternalFormat() const { return fBGRAIsInternalFormat; }
184f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
185f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    /// Is there support for GL_UNPACK_ROW_LENGTH
186f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    bool unpackRowLengthSupport() const { return fUnpackRowLengthSupport; }
187f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
188f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    /// Is there support for GL_UNPACK_FLIP_Y
189f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    bool unpackFlipYSupport() const { return fUnpackFlipYSupport; }
190f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
191f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    /// Is there support for GL_PACK_ROW_LENGTH
192f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    bool packRowLengthSupport() const { return fPackRowLengthSupport; }
193f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
194f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    /// Is there support for GL_PACK_REVERSE_ROW_ORDER
195f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    bool packFlipYSupport() const { return fPackFlipYSupport; }
196f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
197f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    /// Is there support for texture parameter GL_TEXTURE_USAGE
198f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    bool textureUsageSupport() const { return fTextureUsageSupport; }
199f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
200f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    /// Is there support for glTexStorage
201f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    bool texStorageSupport() const { return fTexStorageSupport; }
202f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
203443e5a52b7e85070c26a068cd3b0aad126502395robertphillips@google.com    /// Is there support for GL_RED and GL_R8
204443e5a52b7e85070c26a068cd3b0aad126502395robertphillips@google.com    bool textureRedSupport() const { return fTextureRedSupport; }
205443e5a52b7e85070c26a068cd3b0aad126502395robertphillips@google.com
206e76b7ccb860b7ffcd86a42af8eecfe30f96493fabsalomon@google.com    /// Is GL_ARB_IMAGING supported
207e76b7ccb860b7ffcd86a42af8eecfe30f96493fabsalomon@google.com    bool imagingSupport() const { return fImagingSupport; }
208e76b7ccb860b7ffcd86a42af8eecfe30f96493fabsalomon@google.com
20907631cf14e22e772f901baf68545ee48c3d1e014bsalomon@google.com    /// Is there support for Vertex Array Objects?
21007631cf14e22e772f901baf68545ee48c3d1e014bsalomon@google.com    bool vertexArrayObjectSupport() const { return fVertexArrayObjectSupport; }
21107631cf14e22e772f901baf68545ee48c3d1e014bsalomon@google.com
212626e1ffe84c24a969dc56ca70ab2e950bf5034c4cdalton    /// Is there support for glDraw*Instanced and glVertexAttribDivisor?
213626e1ffe84c24a969dc56ca70ab2e950bf5034c4cdalton    bool instancedDrawingSupport() const { return fInstancedDrawingSupport; }
214626e1ffe84c24a969dc56ca70ab2e950bf5034c4cdalton
215626e1ffe84c24a969dc56ca70ab2e950bf5034c4cdalton    /// Is there support for GL_EXT_direct_state_access?
216626e1ffe84c24a969dc56ca70ab2e950bf5034c4cdalton    bool directStateAccessSupport() const { return fDirectStateAccessSupport; }
217626e1ffe84c24a969dc56ca70ab2e950bf5034c4cdalton
218626e1ffe84c24a969dc56ca70ab2e950bf5034c4cdalton    /// Is there support for GL_KHR_debug?
219626e1ffe84c24a969dc56ca70ab2e950bf5034c4cdalton    bool debugSupport() const { return fDebugSupport; }
220626e1ffe84c24a969dc56ca70ab2e950bf5034c4cdalton
2213f801cbb67895fa9fa29498aa017a7666960a627jvanverth    /// Is there support for ES2 compatability?
2223f801cbb67895fa9fa29498aa017a7666960a627jvanverth    bool ES2CompatibilitySupport() const { return fES2CompatibilitySupport; }
2233f801cbb67895fa9fa29498aa017a7666960a627jvanverth
224d472792a72c0c433a205d42a73e0b77d65f8d76fcdalton    /// Can we call glDisable(GL_MULTISAMPLE)?
225d472792a72c0c433a205d42a73e0b77d65f8d76fcdalton    bool multisampleDisableSupport() const {
226d472792a72c0c433a205d42a73e0b77d65f8d76fcdalton        return fMultisampleDisableSupport;
227d472792a72c0c433a205d42a73e0b77d65f8d76fcdalton    }
228d472792a72c0c433a205d42a73e0b77d65f8d76fcdalton
22907631cf14e22e772f901baf68545ee48c3d1e014bsalomon@google.com    /// Use indices or vertices in CPU arrays rather than VBOs for dynamic content.
23096966a5a1ffc2f03eef1b5523308299aa4195f50bsalomon@google.com    bool useNonVBOVertexAndIndexDynamicData() const {
23196966a5a1ffc2f03eef1b5523308299aa4195f50bsalomon@google.com        return fUseNonVBOVertexAndIndexDynamicData;
23296966a5a1ffc2f03eef1b5523308299aa4195f50bsalomon@google.com    }
23396966a5a1ffc2f03eef1b5523308299aa4195f50bsalomon@google.com
23407631cf14e22e772f901baf68545ee48c3d1e014bsalomon@google.com    /// Does ReadPixels support the provided format/type combo?
2351d89c93b2a61a9679f444b19b6fce4325ae7df65robertphillips@google.com    bool readPixelsSupported(const GrGLInterface* intf,
236fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com                             GrGLenum format,
237e4b231428e8c14cbc82d20cfb12eb08fc45f8df6piotaixr                             GrGLenum type,
238e4b231428e8c14cbc82d20cfb12eb08fc45f8df6piotaixr                             GrGLenum currFboFormat) const;
239631cdcb4a6b926b6447f328b81911a4499fb3698skia.committer@gmail.com
2402b1b8c083b969a2a798b03d1754a3fc99ea054dfbsalomon@google.com    bool isCoreProfile() const { return fIsCoreProfile; }
2411d89c93b2a61a9679f444b19b6fce4325ae7df65robertphillips@google.com
242c1f56b518218d1caa65d6b7101bebf0d28c02a92joshualitt    bool bindFragDataLocationSupport() const { return fBindFragDataLocationSupport; }
243c1f56b518218d1caa65d6b7101bebf0d28c02a92joshualitt
2447bdd70ab9162980f3173c98c48234f9f345665a3joshualitt    bool bindUniformLocationSupport() const { return fBindUniformLocationSupport; }
2457bdd70ab9162980f3173c98c48234f9f345665a3joshualitt
2467ea33f5e1ae9eb1fb1e7377d6edf6acdcf71d103bsalomon    /// Are textures with GL_TEXTURE_EXTERNAL_OES type supported.
2477ea33f5e1ae9eb1fb1e7377d6edf6acdcf71d103bsalomon    bool externalTextureSupport() const { return fExternalTextureSupport; }
2487ea33f5e1ae9eb1fb1e7377d6edf6acdcf71d103bsalomon
249160b478eed1dd4924a86a87fd60c91139e08ff71commit-bot@chromium.org    /**
25016921ec30a81976129d507b1148c93a322e61a4fbsalomon     * Is there support for enabling/disabling sRGB writes for sRGB-capable color attachments?
25116921ec30a81976129d507b1148c93a322e61a4fbsalomon     * If false this does not mean sRGB is not supported but rather that if it is supported
25216921ec30a81976129d507b1148c93a322e61a4fbsalomon     * it cannot be turned off for configs that support it.
25316921ec30a81976129d507b1148c93a322e61a4fbsalomon     */
25416921ec30a81976129d507b1148c93a322e61a4fbsalomon    bool srgbWriteControl() const { return fSRGBWriteControl; }
25516921ec30a81976129d507b1148c93a322e61a4fbsalomon
25616921ec30a81976129d507b1148c93a322e61a4fbsalomon    /**
257160b478eed1dd4924a86a87fd60c91139e08ff71commit-bot@chromium.org     * Returns a string containing the caps info.
258160b478eed1dd4924a86a87fd60c91139e08ff71commit-bot@chromium.org     */
25936352bf5e38f45a70ee4f4fc132a38048d38206dmtklein    SkString dump() const override;
260beb8b3a4da83ce30e313e72ae0e444870acecb7ecommit-bot@chromium.org
2616e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org    /**
2626e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org     * LATC can appear under one of three possible names. In order to know
2636e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org     * which GL internal format to use, we need to keep track of which name
2646e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org     * we found LATC under. The default is LATC.
2656e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org     */
2666e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org    enum LATCAlias {
2676e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org        kLATC_LATCAlias,
2686e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org        kRGTC_LATCAlias,
2696e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org        k3DC_LATCAlias
2706e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org    };
2716e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org
2726e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org    LATCAlias latcAlias() const { return fLATCAlias; }
2736e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org
27488c7b988ba7792e51e741567426069cd9cc852ddbsalomon    bool rgba8888PixelsOpsAreSlow() const { return fRGBA8888PixelsOpsAreSlow; }
27588c7b988ba7792e51e741567426069cd9cc852ddbsalomon    bool partialFBOReadIsSlow() const { return fPartialFBOReadIsSlow; }
27688c7b988ba7792e51e741567426069cd9cc852ddbsalomon
277f529439fea003851d986a0573a7e0465754b2a48egdaniel    const GrGLSLCaps* glslCaps() const { return reinterpret_cast<GrGLSLCaps*>(fShaderCaps.get()); }
278e9c0fc616d2a1632c285885b9b656b68ca8d4f24jvanverth
279f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.comprivate:
2804cd6713af1c699b79e04b590109768300faee531cdalton    void init(const GrContextOptions&, const GrGLContextInfo&, const GrGLInterface*);
28105ded891272772d43acc16345b2f90a4560df090egdaniel    void initGLSL(const GrGLContextInfo&);
282cfe62e30848eadead4358b0385e57723779b762bkkinnunen    bool hasPathRenderingSupport(const GrGLContextInfo&, const GrGLInterface*);
283424cc26add7ed491c6941d0c0c3a0e6d83190307bsalomon
284b7e7d5748d74c7482436b33733d7770484bb62e3egdaniel    void onApplyOptionsOverrides(const GrContextOptions& options) override;
285b7e7d5748d74c7482436b33733d7770484bb62e3egdaniel
286f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    /**
287f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com     * Maintains a bit per GrPixelConfig. It is used to avoid redundantly
288f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com     * performing glCheckFrameBufferStatus for the same config.
289f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com     */
290f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    struct VerifiedColorConfigs {
291f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com        VerifiedColorConfigs() {
292f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com            this->reset();
293f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com        }
294f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
295f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com        void reset() {
296f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com            for (int i = 0; i < kNumUints; ++i) {
297f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com                fVerifiedColorConfigs[i] = 0;
298f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com            }
299f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com        }
300f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
301b8eb2e89edf914caf5479baeffcb670d3e93f496bsalomon@google.com        static const int kNumUints = (kGrPixelConfigCnt  + 31) / 32;
302f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com        uint32_t fVerifiedColorConfigs[kNumUints];
303f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
304f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com        void markVerified(GrPixelConfig config) {
305f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
306f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com                return;
307f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com#endif
308f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com            int u32Idx = config / 32;
309f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com            int bitIdx = config % 32;
310f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com            fVerifiedColorConfigs[u32Idx] |= 1 << bitIdx;
311f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com        }
312f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
313f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com        bool isVerified(GrPixelConfig config) const {
314f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
315f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com            return false;
316f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com#endif
317f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com            int u32Idx = config / 32;
318f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com            int bitIdx = config % 32;
319f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com            return SkToBool(fVerifiedColorConfigs[u32Idx] & (1 << bitIdx));
320f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com        }
321f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    };
322f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
3237388051d745590d7759e7ed49c233caec6bea0f7commit-bot@chromium.org    void initFSAASupport(const GrGLContextInfo&, const GrGLInterface*);
3241dd0542ca37cf1b4a2ab0ea41f8009ded097fd47cdalton    void initBlendEqationSupport(const GrGLContextInfo&);
3257388051d745590d7759e7ed49c233caec6bea0f7commit-bot@chromium.org    void initStencilFormats(const GrGLContextInfo&);
3266b7938f9cb250086a7c6325cf31576f894ca4a1bcommit-bot@chromium.org    // This must be called after initFSAASupport().
32716921ec30a81976129d507b1148c93a322e61a4fbsalomon    void initConfigRenderableTable(const GrGLContextInfo&, bool srgbSupport);
32816921ec30a81976129d507b1148c93a322e61a4fbsalomon    void initConfigTexturableTable(const GrGLContextInfo&, const GrGLInterface*, bool srgbSupport);
32942dc8136914ee0777bb9110a5e04a75016687c0dcommit-bot@chromium.org
33017168df7798d0d12684f18df0556dc19e65b32e6bsalomon    bool doReadPixelsSupported(const GrGLInterface* intf, GrGLenum format, GrGLenum type) const;
331e4b231428e8c14cbc82d20cfb12eb08fc45f8df6piotaixr
332cba99b88fd5fb39def7a094dc32c0745c7a1cfeajvanverth    void initShaderPrecisionTable(const GrGLContextInfo& ctxInfo,
333cba99b88fd5fb39def7a094dc32c0745c7a1cfeajvanverth                                  const GrGLInterface* intf,
334cba99b88fd5fb39def7a094dc32c0745c7a1cfeajvanverth                                  GrGLSLCaps* glslCaps);
335cba99b88fd5fb39def7a094dc32c0745c7a1cfeajvanverth
336b7e7d5748d74c7482436b33733d7770484bb62e3egdaniel    void initConfigSwizzleTable(const GrGLContextInfo& ctxInfo, GrGLSLCaps* glslCaps);
337b7e7d5748d74c7482436b33733d7770484bb62e3egdaniel
338f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    // tracks configs that have been verified to pass the FBO completeness when
339f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    // used as a color attachment
340f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    VerifiedColorConfigs fVerifiedColorConfigs;
341f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
342f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    SkTArray<StencilFormat, true> fStencilFormats;
343f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
344f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    int fMaxFragmentUniformVectors;
34560da4176425c74cf112d7e116f54a530a82d0d68bsalomon@google.com    int fMaxVertexAttributes;
346a15f7e5b96ee3d71fdbcb4f9cf02f6a09b4b11accommit-bot@chromium.org    int fMaxFragmentTextureUnits;
34760da4176425c74cf112d7e116f54a530a82d0d68bsalomon@google.com
34852ffbf6be05eb30671529ec86268967fb85c9810commit-bot@chromium.org    MSFBOType           fMSFBOType;
34952ffbf6be05eb30671529ec86268967fb85c9810commit-bot@chromium.org    InvalidateFBType    fInvalidateFBType;
350160b478eed1dd4924a86a87fd60c91139e08ff71commit-bot@chromium.org    MapBufferType       fMapBufferType;
351d7a2c1f5fd710581d6233de5c202d3f2627948e0jvanverth    TransferBufferType  fTransferBufferType;
3526e7ddaae0a077a777b8b8872ec27f8faab275536commit-bot@chromium.org    LATCAlias           fLATCAlias;
3536b0cf0273fdffbbdf69235b57b5b5a311e7f1ca6bsalomon@google.com
354f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    bool fRGBA8RenderbufferSupport : 1;
355f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    bool fBGRAIsInternalFormat : 1;
356f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    bool fUnpackRowLengthSupport : 1;
357f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    bool fUnpackFlipYSupport : 1;
358f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    bool fPackRowLengthSupport : 1;
359f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    bool fPackFlipYSupport : 1;
360f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    bool fTextureUsageSupport : 1;
361f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com    bool fTexStorageSupport : 1;
362443e5a52b7e85070c26a068cd3b0aad126502395robertphillips@google.com    bool fTextureRedSupport : 1;
363e76b7ccb860b7ffcd86a42af8eecfe30f96493fabsalomon@google.com    bool fImagingSupport  : 1;
3641d89c93b2a61a9679f444b19b6fce4325ae7df65robertphillips@google.com    bool fTwoFormatLimit : 1;
36507631cf14e22e772f901baf68545ee48c3d1e014bsalomon@google.com    bool fVertexArrayObjectSupport : 1;
366626e1ffe84c24a969dc56ca70ab2e950bf5034c4cdalton    bool fInstancedDrawingSupport : 1;
367626e1ffe84c24a969dc56ca70ab2e950bf5034c4cdalton    bool fDirectStateAccessSupport : 1;
368626e1ffe84c24a969dc56ca70ab2e950bf5034c4cdalton    bool fDebugSupport : 1;
3693f801cbb67895fa9fa29498aa017a7666960a627jvanverth    bool fES2CompatibilitySupport : 1;
370d472792a72c0c433a205d42a73e0b77d65f8d76fcdalton    bool fMultisampleDisableSupport : 1;
37196966a5a1ffc2f03eef1b5523308299aa4195f50bsalomon@google.com    bool fUseNonVBOVertexAndIndexDynamicData : 1;
3722b1b8c083b969a2a798b03d1754a3fc99ea054dfbsalomon@google.com    bool fIsCoreProfile : 1;
373c1f56b518218d1caa65d6b7101bebf0d28c02a92joshualitt    bool fBindFragDataLocationSupport : 1;
37416921ec30a81976129d507b1148c93a322e61a4fbsalomon    bool fSRGBWriteControl : 1;
37588c7b988ba7792e51e741567426069cd9cc852ddbsalomon    bool fRGBA8888PixelsOpsAreSlow : 1;
37688c7b988ba7792e51e741567426069cd9cc852ddbsalomon    bool fPartialFBOReadIsSlow : 1;
3777bdd70ab9162980f3173c98c48234f9f345665a3joshualitt    bool fBindUniformLocationSupport : 1;
3787ea33f5e1ae9eb1fb1e7377d6edf6acdcf71d103bsalomon    bool fExternalTextureSupport : 1;
3795816233d237e5c214f14f1c92eda4a87c898ea11joshualitt
3802aa1f7e6799501974532d35c1f6c3a0447121b95mtklein    struct ReadPixelsSupportedFormat {
3812aa1f7e6799501974532d35c1f6c3a0447121b95mtklein        GrGLenum fFormat;
3822aa1f7e6799501974532d35c1f6c3a0447121b95mtklein        GrGLenum fType;
3832aa1f7e6799501974532d35c1f6c3a0447121b95mtklein        GrGLenum fFboFormat;
384e4b231428e8c14cbc82d20cfb12eb08fc45f8df6piotaixr
3852aa1f7e6799501974532d35c1f6c3a0447121b95mtklein        bool operator==(const ReadPixelsSupportedFormat& rhs) const {
3862aa1f7e6799501974532d35c1f6c3a0447121b95mtklein            return fFormat    == rhs.fFormat
3872aa1f7e6799501974532d35c1f6c3a0447121b95mtklein                && fType      == rhs.fType
3882aa1f7e6799501974532d35c1f6c3a0447121b95mtklein                && fFboFormat == rhs.fFboFormat;
389e4b231428e8c14cbc82d20cfb12eb08fc45f8df6piotaixr        }
390e4b231428e8c14cbc82d20cfb12eb08fc45f8df6piotaixr    };
39102f46cf878535fb79317d15ebed66dfa3f2cd772mtklein    mutable SkTHashMap<ReadPixelsSupportedFormat, bool> fReadPixelsSupportedCache;
392e4b231428e8c14cbc82d20cfb12eb08fc45f8df6piotaixr
3934b91f768b348aa1cebeb54f3ff9331938734c242bsalomon    typedef GrCaps INHERITED;
394f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com};
395f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com
396f7fa806d84abf1cba47bfa8679e875a75d76599ebsalomon@google.com#endif
397