Home | History | Annotate | Download | only in gl
      1 /*
      2  * Copyright 2012 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 
      9 #include "GrGLCaps.h"
     10 #include "GrGLContext.h"
     11 #include "SkTSearch.h"
     12 #include "SkTSort.h"
     13 
     14 SK_DEFINE_INST_COUNT(GrGLCaps)
     15 
     16 GrGLCaps::GrGLCaps() {
     17     this->reset();
     18 }
     19 
     20 void GrGLCaps::reset() {
     21     INHERITED::reset();
     22 
     23     fVerifiedColorConfigs.reset();
     24     fStencilFormats.reset();
     25     fStencilVerifiedColorConfigs.reset();
     26     fMSFBOType = kNone_MSFBOType;
     27     fCoverageAAType = kNone_CoverageAAType;
     28     fFBFetchType = kNone_FBFetchType;
     29     fMaxFragmentUniformVectors = 0;
     30     fMaxVertexAttributes = 0;
     31     fMaxFragmentTextureUnits = 0;
     32     fRGBA8RenderbufferSupport = false;
     33     fBGRAFormatSupport = false;
     34     fBGRAIsInternalFormat = false;
     35     fTextureSwizzleSupport = false;
     36     fUnpackRowLengthSupport = false;
     37     fUnpackFlipYSupport = false;
     38     fPackRowLengthSupport = false;
     39     fPackFlipYSupport = false;
     40     fTextureUsageSupport = false;
     41     fTexStorageSupport = false;
     42     fTextureRedSupport = false;
     43     fImagingSupport = false;
     44     fTwoFormatLimit = false;
     45     fFragCoordsConventionSupport = false;
     46     fVertexArrayObjectSupport = false;
     47     fUseNonVBOVertexAndIndexDynamicData = false;
     48     fIsCoreProfile = false;
     49     fDiscardFBSupport = false;
     50 }
     51 
     52 GrGLCaps::GrGLCaps(const GrGLCaps& caps) : GrDrawTargetCaps() {
     53     *this = caps;
     54 }
     55 
     56 GrGLCaps& GrGLCaps::operator = (const GrGLCaps& caps) {
     57     INHERITED::operator=(caps);
     58     fVerifiedColorConfigs = caps.fVerifiedColorConfigs;
     59     fStencilFormats = caps.fStencilFormats;
     60     fStencilVerifiedColorConfigs = caps.fStencilVerifiedColorConfigs;
     61     fMaxFragmentUniformVectors = caps.fMaxFragmentUniformVectors;
     62     fMaxVertexAttributes = caps.fMaxVertexAttributes;
     63     fMaxFragmentTextureUnits = caps.fMaxFragmentTextureUnits;
     64     fMSFBOType = caps.fMSFBOType;
     65     fCoverageAAType = caps.fCoverageAAType;
     66     fMSAACoverageModes = caps.fMSAACoverageModes;
     67     fFBFetchType = caps.fFBFetchType;
     68     fRGBA8RenderbufferSupport = caps.fRGBA8RenderbufferSupport;
     69     fBGRAFormatSupport = caps.fBGRAFormatSupport;
     70     fBGRAIsInternalFormat = caps.fBGRAIsInternalFormat;
     71     fTextureSwizzleSupport = caps.fTextureSwizzleSupport;
     72     fUnpackRowLengthSupport = caps.fUnpackRowLengthSupport;
     73     fUnpackFlipYSupport = caps.fUnpackFlipYSupport;
     74     fPackRowLengthSupport = caps.fPackRowLengthSupport;
     75     fPackFlipYSupport = caps.fPackFlipYSupport;
     76     fTextureUsageSupport = caps.fTextureUsageSupport;
     77     fTexStorageSupport = caps.fTexStorageSupport;
     78     fTextureRedSupport = caps.fTextureRedSupport;
     79     fImagingSupport = caps.fImagingSupport;
     80     fTwoFormatLimit = caps.fTwoFormatLimit;
     81     fFragCoordsConventionSupport = caps.fFragCoordsConventionSupport;
     82     fVertexArrayObjectSupport = caps.fVertexArrayObjectSupport;
     83     fUseNonVBOVertexAndIndexDynamicData = caps.fUseNonVBOVertexAndIndexDynamicData;
     84     fIsCoreProfile = caps.fIsCoreProfile;
     85     fDiscardFBSupport = caps.fDiscardFBSupport;
     86 
     87     return *this;
     88 }
     89 
     90 void GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
     91 
     92     this->reset();
     93     if (!ctxInfo.isInitialized()) {
     94         return;
     95     }
     96 
     97     GrGLBinding binding = ctxInfo.binding();
     98     GrGLVersion version = ctxInfo.version();
     99 
    100     /**************************************************************************
    101      * Caps specific to GrGLCaps
    102      **************************************************************************/
    103 
    104     if (kES2_GrGLBinding == binding) {
    105         GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
    106                           &fMaxFragmentUniformVectors);
    107     } else {
    108         GrAssert(kDesktop_GrGLBinding == binding);
    109         GrGLint max;
    110         GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
    111         fMaxFragmentUniformVectors = max / 4;
    112     }
    113     GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
    114     GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
    115 
    116     if (kDesktop_GrGLBinding == binding) {
    117         fRGBA8RenderbufferSupport = true;
    118     } else {
    119         fRGBA8RenderbufferSupport = ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
    120                                     ctxInfo.hasExtension("GL_ARM_rgba8");
    121     }
    122 
    123     if (kDesktop_GrGLBinding == binding) {
    124         fBGRAFormatSupport = version >= GR_GL_VER(1,2) ||
    125                              ctxInfo.hasExtension("GL_EXT_bgra");
    126     } else {
    127         if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
    128             fBGRAFormatSupport = true;
    129         } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
    130             fBGRAFormatSupport = true;
    131             fBGRAIsInternalFormat = true;
    132         }
    133         GrAssert(fBGRAFormatSupport ||
    134                  kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
    135     }
    136 
    137     if (kDesktop_GrGLBinding == binding) {
    138         fTextureSwizzleSupport = version >= GR_GL_VER(3,3) ||
    139                                  ctxInfo.hasExtension("GL_ARB_texture_swizzle");
    140     } else {
    141         fTextureSwizzleSupport = false;
    142     }
    143 
    144     if (kDesktop_GrGLBinding == binding) {
    145         fUnpackRowLengthSupport = true;
    146         fUnpackFlipYSupport = false;
    147         fPackRowLengthSupport = true;
    148         fPackFlipYSupport = false;
    149     } else {
    150         fUnpackRowLengthSupport =ctxInfo.hasExtension("GL_EXT_unpack_subimage");
    151         fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
    152         // no extension for pack row length
    153         fPackRowLengthSupport = false;
    154         fPackFlipYSupport =
    155             ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
    156     }
    157 
    158     fTextureUsageSupport = (kES2_GrGLBinding == binding) &&
    159                             ctxInfo.hasExtension("GL_ANGLE_texture_usage");
    160 
    161     // Tex storage is in desktop 4.2 and can be an extension to desktop or ES.
    162     fTexStorageSupport = (kDesktop_GrGLBinding == binding &&
    163                           version >= GR_GL_VER(4,2)) ||
    164                          ctxInfo.hasExtension("GL_ARB_texture_storage") ||
    165                          ctxInfo.hasExtension("GL_EXT_texture_storage");
    166 
    167     // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support it if
    168     // it doesn't have ARB_texture_rg extension.
    169     if (kDesktop_GrGLBinding == binding) {
    170         if (ctxInfo.isMesa()) {
    171             fTextureRedSupport = ctxInfo.hasExtension("GL_ARB_texture_rg");
    172         } else {
    173             fTextureRedSupport = version >= GR_GL_VER(3,0) ||
    174                                  ctxInfo.hasExtension("GL_ARB_texture_rg");
    175         }
    176     } else {
    177         fTextureRedSupport = ctxInfo.hasExtension("GL_EXT_texture_rg");
    178     }
    179 
    180     fImagingSupport = kDesktop_GrGLBinding == binding &&
    181                       ctxInfo.hasExtension("GL_ARB_imaging");
    182 
    183     // ES 2 only guarantees RGBA/uchar + one other format/type combo for
    184     // ReadPixels. The other format has to checked at run-time since it
    185     // can change based on which render target is bound
    186     fTwoFormatLimit = kES2_GrGLBinding == binding;
    187 
    188     // Known issue on at least some Intel platforms:
    189     // http://code.google.com/p/skia/issues/detail?id=946
    190     if (kIntel_GrGLVendor != ctxInfo.vendor()) {
    191         fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
    192                                        ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
    193     }
    194 
    195     // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
    196     // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
    197     // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
    198     // limit this decision to specific GPU families rather than basing it on the vendor alone.
    199     if (!GR_GL_MUST_USE_VBO &&
    200         (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor())) {
    201         fUseNonVBOVertexAndIndexDynamicData = true;
    202     }
    203 
    204     if (kDesktop_GrGLBinding == binding && version >= GR_GL_VER(3, 2)) {
    205         GrGLint profileMask;
    206         GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
    207         fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
    208     }
    209 
    210     fDiscardFBSupport = ctxInfo.hasExtension("GL_EXT_discard_framebuffer");
    211 
    212     if (kDesktop_GrGLBinding == binding) {
    213         fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
    214                                     ctxInfo.hasExtension("GL_ARB_vertex_array_object");
    215     } else {
    216         fVertexArrayObjectSupport = ctxInfo.hasExtension("GL_OES_vertex_array_object");
    217     }
    218 
    219     if (kES2_GrGLBinding == binding) {
    220         if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
    221             fFBFetchType = kEXT_FBFetchType;
    222         } else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
    223             fFBFetchType = kNV_FBFetchType;
    224         }
    225     }
    226 
    227     this->initFSAASupport(ctxInfo, gli);
    228     this->initStencilFormats(ctxInfo);
    229 
    230     /**************************************************************************
    231      * GrDrawTargetCaps fields
    232      **************************************************************************/
    233     GrGLint numFormats;
    234     GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
    235     if (numFormats) {
    236         SkAutoSTMalloc<10, GrGLint> formats(numFormats);
    237         GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
    238         for (int i = 0; i < numFormats; ++i) {
    239             if (formats[i] == GR_GL_PALETTE8_RGBA8) {
    240                 f8BitPaletteSupport = true;
    241                 break;
    242             }
    243         }
    244     }
    245 
    246     if (kDesktop_GrGLBinding == binding) {
    247         // we could also look for GL_ATI_separate_stencil extension or
    248         // GL_EXT_stencil_two_side but they use different function signatures
    249         // than GL2.0+ (and than each other).
    250         fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
    251         // supported on GL 1.4 and higher or by extension
    252         fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
    253                                   ctxInfo.hasExtension("GL_EXT_stencil_wrap");
    254     } else {
    255         // ES 2 has two sided stencil and stencil wrap
    256         fTwoSidedStencilSupport = true;
    257         fStencilWrapOpsSupport = true;
    258     }
    259 
    260     if (kDesktop_GrGLBinding == binding) {
    261         fBufferLockSupport = true; // we require VBO support and the desktop VBO extension includes
    262                                    // glMapBuffer.
    263     } else {
    264         fBufferLockSupport = ctxInfo.hasExtension("GL_OES_mapbuffer");
    265     }
    266 
    267     if (kDesktop_GrGLBinding == binding) {
    268         if (ctxInfo.version() >= GR_GL_VER(2,0) ||
    269             ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two")) {
    270             fNPOTTextureTileSupport = true;
    271         } else {
    272             fNPOTTextureTileSupport = false;
    273         }
    274     } else {
    275         // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
    276         fNPOTTextureTileSupport = ctxInfo.hasExtension("GL_OES_texture_npot");
    277     }
    278 
    279     fHWAALineSupport = (kDesktop_GrGLBinding == binding);
    280 
    281     GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
    282     GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
    283     // Our render targets are always created with textures as the color
    284     // attachment, hence this min:
    285     fMaxRenderTargetSize = GrMin(fMaxTextureSize, fMaxRenderTargetSize);
    286 
    287     fPathStencilingSupport = GR_GL_USE_NV_PATH_RENDERING &&
    288                              ctxInfo.hasExtension("GL_NV_path_rendering");
    289 
    290     fDstReadInShaderSupport = kNone_FBFetchType != fFBFetchType;
    291 
    292 #if 0
    293     // This has to be temporarily disabled. On Android it causes the texture
    294     // usage to become front loaded and the OS kills the process. It can
    295     // be re-enabled once the more dynamic (ref-driven) cache clearing
    296     // system is in place.
    297     fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor();
    298 #else
    299     fReuseScratchTextures = true;
    300 #endif
    301 
    302     // Enable supported shader-related caps
    303     if (kDesktop_GrGLBinding == binding) {
    304         fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3,3) ||
    305                                      ctxInfo.hasExtension("GL_ARB_blend_func_extended");
    306         fShaderDerivativeSupport = true;
    307         // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
    308         fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3,2) &&
    309                                  ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
    310     } else {
    311         fShaderDerivativeSupport = ctxInfo.hasExtension("GL_OES_standard_derivatives");
    312     }
    313 
    314     if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
    315         GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
    316     } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
    317         GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
    318     }
    319 }
    320 
    321 bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
    322                                    GrGLenum format,
    323                                    GrGLenum type) const {
    324     if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
    325         // ES 2 guarantees this format is supported
    326         return true;
    327     }
    328 
    329     if (!fTwoFormatLimit) {
    330         // not limited by ES 2's constraints
    331         return true;
    332     }
    333 
    334     GrGLint otherFormat = GR_GL_RGBA;
    335     GrGLint otherType = GR_GL_UNSIGNED_BYTE;
    336 
    337     // The other supported format/type combo supported for ReadPixels
    338     // can change based on which render target is bound
    339     GR_GL_GetIntegerv(intf,
    340                       GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
    341                       &otherFormat);
    342 
    343     GR_GL_GetIntegerv(intf,
    344                       GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
    345                       &otherType);
    346 
    347     return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
    348 }
    349 
    350 namespace {
    351 bool cov_mode_less(const GrGLCaps::MSAACoverageMode& left,
    352                    const GrGLCaps::MSAACoverageMode& right) {
    353     if (left.fCoverageSampleCnt < right.fCoverageSampleCnt) {
    354         return true;
    355     } else if (right.fCoverageSampleCnt < left.fCoverageSampleCnt) {
    356         return false;
    357     } else if (left.fColorSampleCnt < right.fColorSampleCnt) {
    358         return true;
    359     }
    360     return false;
    361 }
    362 }
    363 
    364 void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
    365 
    366     fMSFBOType = kNone_MSFBOType;
    367     if (kDesktop_GrGLBinding != ctxInfo.binding()) {
    368        if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
    369            // chrome's extension is equivalent to the EXT msaa
    370            // and fbo_blit extensions.
    371            fMSFBOType = kDesktop_EXT_MSFBOType;
    372        } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
    373            fMSFBOType = kES_Apple_MSFBOType;
    374        } else if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
    375            fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
    376        } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
    377            fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
    378        }
    379     } else {
    380         if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
    381             ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
    382             fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
    383         } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
    384                    ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
    385             fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
    386         }
    387         // TODO: We could populate fMSAACoverageModes using GetInternalformativ
    388         // on GL 4.2+. It's format-specific, though. See also
    389         // http://code.google.com/p/skia/issues/detail?id=470 about using actual
    390         // rather than requested sample counts in cache key.
    391         if (ctxInfo.hasExtension("GL_NV_framebuffer_multisample_coverage")) {
    392             fCoverageAAType = kNVDesktop_CoverageAAType;
    393             GrGLint count;
    394             GR_GL_GetIntegerv(gli,
    395                               GR_GL_MAX_MULTISAMPLE_COVERAGE_MODES,
    396                               &count);
    397             fMSAACoverageModes.setCount(count);
    398             GR_GL_GetIntegerv(gli,
    399                               GR_GL_MULTISAMPLE_COVERAGE_MODES,
    400                               (int*)&fMSAACoverageModes[0]);
    401             // The NV driver seems to return the modes already sorted but the
    402             // spec doesn't require this. So we sort.
    403             typedef SkTLessFunctionToFunctorAdaptor<MSAACoverageMode, cov_mode_less> SortFunctor;
    404             SortFunctor sortFunctor;
    405             SkTQSort<MSAACoverageMode, SortFunctor>(fMSAACoverageModes.begin(),
    406                                                     fMSAACoverageModes.end() - 1,
    407                                                     sortFunctor);
    408         }
    409     }
    410 }
    411 
    412 const GrGLCaps::MSAACoverageMode& GrGLCaps::getMSAACoverageMode(int desiredSampleCount) const {
    413     static const MSAACoverageMode kNoneMode = {0, 0};
    414     if (0 == fMSAACoverageModes.count()) {
    415         return kNoneMode;
    416     } else {
    417         GrAssert(kNone_CoverageAAType != fCoverageAAType);
    418         int max = (fMSAACoverageModes.end() - 1)->fCoverageSampleCnt;
    419         desiredSampleCount = GrMin(desiredSampleCount, max);
    420         MSAACoverageMode desiredMode = {desiredSampleCount, 0};
    421         int idx = SkTSearch<const MSAACoverageMode, cov_mode_less>(&fMSAACoverageModes[0],
    422                                                                    fMSAACoverageModes.count(),
    423                                                                    desiredMode,
    424                                                                    sizeof(MSAACoverageMode));
    425         if (idx < 0) {
    426             idx = ~idx;
    427         }
    428         GrAssert(idx >= 0 && idx < fMSAACoverageModes.count());
    429         return fMSAACoverageModes[idx];
    430     }
    431 }
    432 
    433 namespace {
    434 const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount;
    435 }
    436 
    437 void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
    438 
    439     // Build up list of legal stencil formats (though perhaps not supported on
    440     // the particular gpu/driver) from most preferred to least.
    441 
    442     // these consts are in order of most preferred to least preferred
    443     // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
    444 
    445     static const StencilFormat
    446                   // internal Format      stencil bits      total bits        packed?
    447         gS8    = {GR_GL_STENCIL_INDEX8,   8,                8,                false},
    448         gS16   = {GR_GL_STENCIL_INDEX16,  16,               16,               false},
    449         gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8,                32,               true },
    450         gS4    = {GR_GL_STENCIL_INDEX4,   4,                4,                false},
    451     //  gS     = {GR_GL_STENCIL_INDEX,    kUnknownBitCount, kUnknownBitCount, false},
    452         gDS    = {GR_GL_DEPTH_STENCIL,    kUnknownBitCount, kUnknownBitCount, true };
    453 
    454     if (kDesktop_GrGLBinding == ctxInfo.binding()) {
    455         bool supportsPackedDS =
    456             ctxInfo.version() >= GR_GL_VER(3,0) ||
    457             ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
    458             ctxInfo.hasExtension("GL_ARB_framebuffer_object");
    459 
    460         // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
    461         // require FBO support we can expect these are legal formats and don't
    462         // check. These also all support the unsized GL_STENCIL_INDEX.
    463         fStencilFormats.push_back() = gS8;
    464         fStencilFormats.push_back() = gS16;
    465         if (supportsPackedDS) {
    466             fStencilFormats.push_back() = gD24S8;
    467         }
    468         fStencilFormats.push_back() = gS4;
    469         if (supportsPackedDS) {
    470             fStencilFormats.push_back() = gDS;
    471         }
    472     } else {
    473         // ES2 has STENCIL_INDEX8 without extensions but requires extensions
    474         // for other formats.
    475         // ES doesn't support using the unsized format.
    476 
    477         fStencilFormats.push_back() = gS8;
    478         //fStencilFormats.push_back() = gS16;
    479         if (ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
    480             fStencilFormats.push_back() = gD24S8;
    481         }
    482         if (ctxInfo.hasExtension("GL_OES_stencil4")) {
    483             fStencilFormats.push_back() = gS4;
    484         }
    485     }
    486     GrAssert(0 == fStencilVerifiedColorConfigs.count());
    487     fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
    488 }
    489 
    490 void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
    491                                     GrPixelConfig config,
    492                                     const GrGLStencilBuffer::Format& format) {
    493 #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
    494     return;
    495 #endif
    496     GrAssert((unsigned)config < (unsigned)kGrPixelConfigCnt);
    497     GrAssert(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
    498     int count = fStencilFormats.count();
    499     // we expect a really small number of possible formats so linear search
    500     // should be OK
    501     GrAssert(count < 16);
    502     for (int i = 0; i < count; ++i) {
    503         if (format.fInternalFormat ==
    504             fStencilFormats[i].fInternalFormat) {
    505             fStencilVerifiedColorConfigs[i].markVerified(config);
    506             return;
    507         }
    508     }
    509     GrCrash("Why are we seeing a stencil format that "
    510             "GrGLCaps doesn't know about.");
    511 }
    512 
    513 bool GrGLCaps::isColorConfigAndStencilFormatVerified(
    514                                 GrPixelConfig config,
    515                                 const GrGLStencilBuffer::Format& format) const {
    516 #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
    517     return false;
    518 #endif
    519     GrAssert((unsigned)config < (unsigned)kGrPixelConfigCnt);
    520     int count = fStencilFormats.count();
    521     // we expect a really small number of possible formats so linear search
    522     // should be OK
    523     GrAssert(count < 16);
    524     for (int i = 0; i < count; ++i) {
    525         if (format.fInternalFormat ==
    526             fStencilFormats[i].fInternalFormat) {
    527             return fStencilVerifiedColorConfigs[i].isVerified(config);
    528         }
    529     }
    530     GrCrash("Why are we seeing a stencil format that "
    531             "GLCaps doesn't know about.");
    532     return false;
    533 }
    534 
    535 void GrGLCaps::print() const {
    536 
    537     INHERITED::print();
    538 
    539     GrPrintf("--- GL-Specific ---\n");
    540     for (int i = 0; i < fStencilFormats.count(); ++i) {
    541         GrPrintf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
    542                  i,
    543                  fStencilFormats[i].fStencilBits,
    544                  fStencilFormats[i].fTotalBits);
    545     }
    546 
    547     static const char* kMSFBOExtStr[] = {
    548         "None",
    549         "ARB",
    550         "EXT",
    551         "Apple",
    552         "IMG MS To Texture",
    553         "EXT MS To Texture",
    554     };
    555     GR_STATIC_ASSERT(0 == kNone_MSFBOType);
    556     GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
    557     GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
    558     GR_STATIC_ASSERT(3 == kES_Apple_MSFBOType);
    559     GR_STATIC_ASSERT(4 == kES_IMG_MsToTexture_MSFBOType);
    560     GR_STATIC_ASSERT(5 == kES_EXT_MsToTexture_MSFBOType);
    561     GR_STATIC_ASSERT(GR_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
    562 
    563     static const char* kFBFetchTypeStr[] = {
    564         "None",
    565         "EXT",
    566         "NV",
    567     };
    568     GR_STATIC_ASSERT(0 == kNone_FBFetchType);
    569     GR_STATIC_ASSERT(1 == kEXT_FBFetchType);
    570     GR_STATIC_ASSERT(2 == kNV_FBFetchType);
    571     GR_STATIC_ASSERT(GR_ARRAY_COUNT(kFBFetchTypeStr) == kLast_FBFetchType + 1);
    572 
    573 
    574     GrPrintf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
    575     GrPrintf("FB Fetch Type: %s\n", kFBFetchTypeStr[fFBFetchType]);
    576     GrPrintf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
    577     GrPrintf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
    578     GrPrintf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
    579     GrPrintf("BGRA support: %s\n", (fBGRAFormatSupport ? "YES": "NO"));
    580     GrPrintf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
    581     GrPrintf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
    582     GrPrintf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
    583     GrPrintf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
    584     GrPrintf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
    585     GrPrintf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
    586 
    587     GrPrintf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
    588     GrPrintf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
    589     GrPrintf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
    590     GrPrintf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
    591     GrPrintf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
    592     GrPrintf("Fragment coord conventions support: %s\n",
    593              (fFragCoordsConventionSupport ? "YES": "NO"));
    594     GrPrintf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
    595     GrPrintf("Use non-VBO for dynamic data: %s\n",
    596              (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
    597     GrPrintf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
    598     GrPrintf("Discard FrameBuffer support: %s\n", (fDiscardFBSupport ? "YES" : "NO"));
    599 }
    600