OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 | 8 |
9 #include "GrGLCaps.h" | 9 #include "GrGLCaps.h" |
10 #include "GrGLContext.h" | 10 #include "GrGLContext.h" |
11 #include "SkTSearch.h" | 11 #include "SkTSearch.h" |
12 #include "SkTSort.h" | 12 #include "SkTSort.h" |
13 | 13 |
14 SK_DEFINE_INST_COUNT(GrGLCaps) | 14 SK_DEFINE_INST_COUNT(GrGLCaps) |
15 | 15 |
16 GrGLCaps::GrGLCaps() { | 16 GrGLCaps::GrGLCaps() { |
17 this->reset(); | 17 this->reset(); |
18 } | 18 } |
19 | 19 |
20 void GrGLCaps::reset() { | 20 void GrGLCaps::reset() { |
21 INHERITED::reset(); | 21 INHERITED::reset(); |
22 | 22 |
23 fVerifiedColorConfigs.reset(); | 23 fVerifiedColorConfigs.reset(); |
24 fStencilFormats.reset(); | 24 fStencilFormats.reset(); |
25 fStencilVerifiedColorConfigs.reset(); | 25 fStencilVerifiedColorConfigs.reset(); |
26 fMSFBOType = kNone_MSFBOType; | 26 fMSFBOType = kNone_MSFBOType; |
27 fCoverageAAType = kNone_CoverageAAType; | |
28 fFBFetchType = kNone_FBFetchType; | 27 fFBFetchType = kNone_FBFetchType; |
29 fMaxFragmentUniformVectors = 0; | 28 fMaxFragmentUniformVectors = 0; |
30 fMaxVertexAttributes = 0; | 29 fMaxVertexAttributes = 0; |
31 fMaxFragmentTextureUnits = 0; | 30 fMaxFragmentTextureUnits = 0; |
32 fMaxFixedFunctionTextureCoords = 0; | 31 fMaxFixedFunctionTextureCoords = 0; |
33 fRGBA8RenderbufferSupport = false; | 32 fRGBA8RenderbufferSupport = false; |
34 fBGRAFormatSupport = false; | 33 fBGRAFormatSupport = false; |
35 fBGRAIsInternalFormat = false; | 34 fBGRAIsInternalFormat = false; |
36 fTextureSwizzleSupport = false; | 35 fTextureSwizzleSupport = false; |
37 fUnpackRowLengthSupport = false; | 36 fUnpackRowLengthSupport = false; |
(...skipping 20 matching lines...) Expand all Loading... |
58 GrGLCaps& GrGLCaps::operator = (const GrGLCaps& caps) { | 57 GrGLCaps& GrGLCaps::operator = (const GrGLCaps& caps) { |
59 INHERITED::operator=(caps); | 58 INHERITED::operator=(caps); |
60 fVerifiedColorConfigs = caps.fVerifiedColorConfigs; | 59 fVerifiedColorConfigs = caps.fVerifiedColorConfigs; |
61 fStencilFormats = caps.fStencilFormats; | 60 fStencilFormats = caps.fStencilFormats; |
62 fStencilVerifiedColorConfigs = caps.fStencilVerifiedColorConfigs; | 61 fStencilVerifiedColorConfigs = caps.fStencilVerifiedColorConfigs; |
63 fMaxFragmentUniformVectors = caps.fMaxFragmentUniformVectors; | 62 fMaxFragmentUniformVectors = caps.fMaxFragmentUniformVectors; |
64 fMaxVertexAttributes = caps.fMaxVertexAttributes; | 63 fMaxVertexAttributes = caps.fMaxVertexAttributes; |
65 fMaxFragmentTextureUnits = caps.fMaxFragmentTextureUnits; | 64 fMaxFragmentTextureUnits = caps.fMaxFragmentTextureUnits; |
66 fMaxFixedFunctionTextureCoords = caps.fMaxFixedFunctionTextureCoords; | 65 fMaxFixedFunctionTextureCoords = caps.fMaxFixedFunctionTextureCoords; |
67 fMSFBOType = caps.fMSFBOType; | 66 fMSFBOType = caps.fMSFBOType; |
68 fCoverageAAType = caps.fCoverageAAType; | |
69 fMSAACoverageModes = caps.fMSAACoverageModes; | |
70 fFBFetchType = caps.fFBFetchType; | 67 fFBFetchType = caps.fFBFetchType; |
71 fRGBA8RenderbufferSupport = caps.fRGBA8RenderbufferSupport; | 68 fRGBA8RenderbufferSupport = caps.fRGBA8RenderbufferSupport; |
72 fBGRAFormatSupport = caps.fBGRAFormatSupport; | 69 fBGRAFormatSupport = caps.fBGRAFormatSupport; |
73 fBGRAIsInternalFormat = caps.fBGRAIsInternalFormat; | 70 fBGRAIsInternalFormat = caps.fBGRAIsInternalFormat; |
74 fTextureSwizzleSupport = caps.fTextureSwizzleSupport; | 71 fTextureSwizzleSupport = caps.fTextureSwizzleSupport; |
75 fUnpackRowLengthSupport = caps.fUnpackRowLengthSupport; | 72 fUnpackRowLengthSupport = caps.fUnpackRowLengthSupport; |
76 fUnpackFlipYSupport = caps.fUnpackFlipYSupport; | 73 fUnpackFlipYSupport = caps.fUnpackFlipYSupport; |
77 fPackRowLengthSupport = caps.fPackRowLengthSupport; | 74 fPackRowLengthSupport = caps.fPackRowLengthSupport; |
78 fPackFlipYSupport = caps.fPackFlipYSupport; | 75 fPackFlipYSupport = caps.fPackFlipYSupport; |
79 fTextureUsageSupport = caps.fTextureUsageSupport; | 76 fTextureUsageSupport = caps.fTextureUsageSupport; |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, | 358 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, |
362 &otherFormat); | 359 &otherFormat); |
363 | 360 |
364 GR_GL_GetIntegerv(intf, | 361 GR_GL_GetIntegerv(intf, |
365 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, | 362 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, |
366 &otherType); | 363 &otherType); |
367 | 364 |
368 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type; | 365 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type; |
369 } | 366 } |
370 | 367 |
371 namespace { | |
372 bool cov_mode_less(const GrGLCaps::MSAACoverageMode& left, | |
373 const GrGLCaps::MSAACoverageMode& right) { | |
374 if (left.fCoverageSampleCnt < right.fCoverageSampleCnt) { | |
375 return true; | |
376 } else if (right.fCoverageSampleCnt < left.fCoverageSampleCnt) { | |
377 return false; | |
378 } else if (left.fColorSampleCnt < right.fColorSampleCnt) { | |
379 return true; | |
380 } | |
381 return false; | |
382 } | |
383 } | |
384 | |
385 void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterfa
ce* gli) { | 368 void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterfa
ce* gli) { |
386 | 369 |
387 fMSFBOType = kNone_MSFBOType; | 370 fMSFBOType = kNone_MSFBOType; |
388 if (kDesktop_GrGLBinding != ctxInfo.binding()) { | 371 if (kDesktop_GrGLBinding != ctxInfo.binding()) { |
389 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed | 372 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed |
390 // ES3 driver bugs on at least one device with a tiled GPU (N10). | 373 // ES3 driver bugs on at least one device with a tiled GPU (N10). |
391 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) { | 374 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) { |
392 fMSFBOType = kES_EXT_MsToTexture_MSFBOType; | 375 fMSFBOType = kES_EXT_MsToTexture_MSFBOType; |
393 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")
) { | 376 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")
) { |
394 fMSFBOType = kES_IMG_MsToTexture_MSFBOType; | 377 fMSFBOType = kES_IMG_MsToTexture_MSFBOType; |
395 } else if (!GR_GL_IGNORE_ES3_MSAA && ctxInfo.version() >= GR_GL_VER(3,0)
) { | 378 } else if (!GR_GL_IGNORE_ES3_MSAA && ctxInfo.version() >= GR_GL_VER(3,0)
) { |
396 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType; | 379 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType; |
397 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample"))
{ | 380 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample"))
{ |
398 // chrome's extension is equivalent to the EXT msaa | 381 // chrome's extension is equivalent to the EXT msaa |
399 // and fbo_blit extensions. | 382 // and fbo_blit extensions. |
400 fMSFBOType = kDesktop_EXT_MSFBOType; | 383 fMSFBOType = kDesktop_EXT_MSFBOType; |
401 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) { | 384 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) { |
402 fMSFBOType = kES_Apple_MSFBOType; | 385 fMSFBOType = kES_Apple_MSFBOType; |
403 } | 386 } |
404 } else { | 387 } else { |
405 if ((ctxInfo.version() >= GR_GL_VER(3,0)) || | 388 if ((ctxInfo.version() >= GR_GL_VER(3,0)) || |
406 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) { | 389 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) { |
407 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType; | 390 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType; |
408 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") && | 391 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") && |
409 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) { | 392 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) { |
410 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType; | 393 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType; |
411 } | 394 } |
412 // TODO: We could populate fMSAACoverageModes using GetInternalformativ | |
413 // on GL 4.2+. It's format-specific, though. See also | |
414 // http://code.google.com/p/skia/issues/detail?id=470 about using actual | |
415 // rather than requested sample counts in cache key. | |
416 if (ctxInfo.hasExtension("GL_NV_framebuffer_multisample_coverage")) { | |
417 fCoverageAAType = kNVDesktop_CoverageAAType; | |
418 GrGLint count; | |
419 GR_GL_GetIntegerv(gli, | |
420 GR_GL_MAX_MULTISAMPLE_COVERAGE_MODES, | |
421 &count); | |
422 fMSAACoverageModes.setCount(count); | |
423 GR_GL_GetIntegerv(gli, | |
424 GR_GL_MULTISAMPLE_COVERAGE_MODES, | |
425 (int*)&fMSAACoverageModes[0]); | |
426 // The NV driver seems to return the modes already sorted but the | |
427 // spec doesn't require this. So we sort. | |
428 typedef SkTLessFunctionToFunctorAdaptor<MSAACoverageMode, cov_mode_l
ess> SortFunctor; | |
429 SortFunctor sortFunctor; | |
430 SkTQSort<MSAACoverageMode, SortFunctor>(fMSAACoverageModes.begin(), | |
431 fMSAACoverageModes.end() - 1
, | |
432 sortFunctor); | |
433 } | |
434 } | 395 } |
435 } | 396 } |
436 | 397 |
437 const GrGLCaps::MSAACoverageMode& GrGLCaps::getMSAACoverageMode(int desiredSampl
eCount) const { | |
438 static const MSAACoverageMode kNoneMode = {0, 0}; | |
439 if (0 == fMSAACoverageModes.count()) { | |
440 return kNoneMode; | |
441 } else { | |
442 SkASSERT(kNone_CoverageAAType != fCoverageAAType); | |
443 int max = (fMSAACoverageModes.end() - 1)->fCoverageSampleCnt; | |
444 desiredSampleCount = GrMin(desiredSampleCount, max); | |
445 MSAACoverageMode desiredMode = {desiredSampleCount, 0}; | |
446 int idx = SkTSearch<const MSAACoverageMode, cov_mode_less>(&fMSAACoverag
eModes[0], | |
447 fMSAACoverage
Modes.count(), | |
448 desiredMode, | |
449 sizeof(MSAACo
verageMode)); | |
450 if (idx < 0) { | |
451 idx = ~idx; | |
452 } | |
453 SkASSERT(idx >= 0 && idx < fMSAACoverageModes.count()); | |
454 return fMSAACoverageModes[idx]; | |
455 } | |
456 } | |
457 | |
458 namespace { | 398 namespace { |
459 const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount; | 399 const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount; |
460 } | 400 } |
461 | 401 |
462 void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) { | 402 void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) { |
463 | 403 |
464 // Build up list of legal stencil formats (though perhaps not supported on | 404 // Build up list of legal stencil formats (though perhaps not supported on |
465 // the particular gpu/driver) from most preferred to least. | 405 // the particular gpu/driver) from most preferred to least. |
466 | 406 |
467 // these consts are in order of most preferred to least preferred | 407 // these consts are in order of most preferred to least preferred |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 GrPrintf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO")); | 562 GrPrintf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO")); |
623 GrPrintf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO")); | 563 GrPrintf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO")); |
624 GrPrintf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO")); | 564 GrPrintf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO")); |
625 GrPrintf("Fragment coord conventions support: %s\n", | 565 GrPrintf("Fragment coord conventions support: %s\n", |
626 (fFragCoordsConventionSupport ? "YES": "NO")); | 566 (fFragCoordsConventionSupport ? "YES": "NO")); |
627 GrPrintf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "
YES": "NO")); | 567 GrPrintf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "
YES": "NO")); |
628 GrPrintf("Use non-VBO for dynamic data: %s\n", | 568 GrPrintf("Use non-VBO for dynamic data: %s\n", |
629 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO")); | 569 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO")); |
630 GrPrintf("Discard FrameBuffer support: %s\n", (fDiscardFBSupport ? "YES" : "
NO")); | 570 GrPrintf("Discard FrameBuffer support: %s\n", (fDiscardFBSupport ? "YES" : "
NO")); |
631 } | 571 } |
OLD | NEW |