OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "GrGpuGL.h" | 9 #include "GrGpuGL.h" |
10 #include "GrGLStencilBuffer.h" | 10 #include "GrGLStencilBuffer.h" |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
419 | 419 |
420 GrGLTexture* texture = NULL; | 420 GrGLTexture* texture = NULL; |
421 if (renderTarget) { | 421 if (renderTarget) { |
422 GrGLRenderTarget::Desc glRTDesc; | 422 GrGLRenderTarget::Desc glRTDesc; |
423 glRTDesc.fRTFBOID = 0; | 423 glRTDesc.fRTFBOID = 0; |
424 glRTDesc.fTexFBOID = 0; | 424 glRTDesc.fTexFBOID = 0; |
425 glRTDesc.fMSColorRenderbufferID = 0; | 425 glRTDesc.fMSColorRenderbufferID = 0; |
426 glRTDesc.fConfig = desc.fConfig; | 426 glRTDesc.fConfig = desc.fConfig; |
427 glRTDesc.fSampleCnt = desc.fSampleCnt; | 427 glRTDesc.fSampleCnt = desc.fSampleCnt; |
428 glRTDesc.fOrigin = glTexDesc.fOrigin; | 428 glRTDesc.fOrigin = glTexDesc.fOrigin; |
429 glRTDesc.fCheckAllocation = false; | |
429 if (!this->createRenderTargetObjects(glTexDesc.fWidth, | 430 if (!this->createRenderTargetObjects(glTexDesc.fWidth, |
430 glTexDesc.fHeight, | 431 glTexDesc.fHeight, |
431 glTexDesc.fTextureID, | 432 glTexDesc.fTextureID, |
432 &glRTDesc)) { | 433 &glRTDesc)) { |
433 return NULL; | 434 return NULL; |
434 } | 435 } |
435 texture = SkNEW_ARGS(GrGLTexture, (this, glTexDesc, glRTDesc)); | 436 texture = SkNEW_ARGS(GrGLTexture, (this, glTexDesc, glRTDesc)); |
436 } else { | 437 } else { |
437 texture = SkNEW_ARGS(GrGLTexture, (this, glTexDesc)); | 438 texture = SkNEW_ARGS(GrGLTexture, (this, glTexDesc)); |
438 } | 439 } |
439 if (NULL == texture) { | 440 if (NULL == texture) { |
440 return NULL; | 441 return NULL; |
441 } | 442 } |
442 | 443 |
443 return texture; | 444 return texture; |
444 } | 445 } |
445 | 446 |
446 GrRenderTarget* GrGpuGL::onWrapBackendRenderTarget(const GrBackendRenderTargetDe sc& desc) { | 447 GrRenderTarget* GrGpuGL::onWrapBackendRenderTarget(const GrBackendRenderTargetDe sc& desc) { |
447 GrGLRenderTarget::Desc glDesc; | 448 GrGLRenderTarget::Desc glDesc; |
448 glDesc.fConfig = desc.fConfig; | 449 glDesc.fConfig = desc.fConfig; |
449 glDesc.fRTFBOID = static_cast<GrGLuint>(desc.fRenderTargetHandle); | 450 glDesc.fRTFBOID = static_cast<GrGLuint>(desc.fRenderTargetHandle); |
450 glDesc.fMSColorRenderbufferID = 0; | 451 glDesc.fMSColorRenderbufferID = 0; |
451 glDesc.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID; | 452 glDesc.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID; |
452 glDesc.fSampleCnt = desc.fSampleCnt; | 453 glDesc.fSampleCnt = desc.fSampleCnt; |
453 glDesc.fIsWrapped = true; | 454 glDesc.fIsWrapped = true; |
455 glDesc.fCheckAllocation = false; | |
454 | 456 |
455 glDesc.fOrigin = resolve_origin(desc.fOrigin, true); | 457 glDesc.fOrigin = resolve_origin(desc.fOrigin, true); |
456 GrGLIRect viewport; | 458 GrGLIRect viewport; |
457 viewport.fLeft = 0; | 459 viewport.fLeft = 0; |
458 viewport.fBottom = 0; | 460 viewport.fBottom = 0; |
459 viewport.fWidth = desc.fWidth; | 461 viewport.fWidth = desc.fWidth; |
460 viewport.fHeight = desc.fHeight; | 462 viewport.fHeight = desc.fHeight; |
461 | 463 |
462 GrRenderTarget* tgt = SkNEW_ARGS(GrGLRenderTarget, | 464 GrRenderTarget* tgt = SkNEW_ARGS(GrGLRenderTarget, |
463 (this, glDesc, viewport)); | 465 (this, glDesc, viewport)); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
528 } | 530 } |
529 *data = reinterpret_cast<const void*>(reinterpret_cast<intptr_t>(*data) + | 531 *data = reinterpret_cast<const void*>(reinterpret_cast<intptr_t>(*data) + |
530 (subRect.fTop - *top) * *rowBytes + (subRect.fLeft - *left) * bpp); | 532 (subRect.fTop - *top) * *rowBytes + (subRect.fLeft - *left) * bpp); |
531 | 533 |
532 *left = subRect.fLeft; | 534 *left = subRect.fLeft; |
533 *top = subRect.fTop; | 535 *top = subRect.fTop; |
534 *width = subRect.width(); | 536 *width = subRect.width(); |
535 *height = subRect.height(); | 537 *height = subRect.height(); |
536 return true; | 538 return true; |
537 } | 539 } |
540 | |
541 GrGLenum checkAllocError(const GrTextureDesc& desc, const GrGLInterface* interfa ce) { | |
bsalomon
2013/06/10 13:21:47
could you namespace {} and_rename_this_to_this_sty
Stephen White
2013/06/10 13:53:14
It already is.
| |
542 if (0 != (desc.fFlags & kCheckAllocation_GrTextureFlagBit)) { | |
543 return GR_GL_GET_ERROR(interface); | |
544 } else { | |
545 return CHECK_ALLOC_ERROR(interface); | |
546 } | |
547 } | |
548 | |
538 } | 549 } |
539 | 550 |
540 bool GrGpuGL::uploadTexData(const GrGLTexture::Desc& desc, | 551 bool GrGpuGL::uploadTexData(const GrGLTexture::Desc& desc, |
541 bool isNewTexture, | 552 bool isNewTexture, |
542 int left, int top, int width, int height, | 553 int left, int top, int width, int height, |
543 GrPixelConfig dataConfig, | 554 GrPixelConfig dataConfig, |
544 const void* data, | 555 const void* data, |
545 size_t rowBytes) { | 556 size_t rowBytes) { |
546 GrAssert(NULL != data || isNewTexture); | 557 GrAssert(NULL != data || isNewTexture); |
547 | 558 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
663 GL_ALLOC_CALL(this->glInterface(), | 674 GL_ALLOC_CALL(this->glInterface(), |
664 TexImage2D(GR_GL_TEXTURE_2D, | 675 TexImage2D(GR_GL_TEXTURE_2D, |
665 0, // level | 676 0, // level |
666 internalFormat, | 677 internalFormat, |
667 desc.fWidth, desc.fHeight, | 678 desc.fWidth, desc.fHeight, |
668 0, // border | 679 0, // border |
669 externalFormat, externalType, | 680 externalFormat, externalType, |
670 data)); | 681 data)); |
671 } | 682 } |
672 } | 683 } |
673 GrGLenum error = CHECK_ALLOC_ERROR(this->glInterface()); | 684 GrGLenum error = checkAllocError(desc, this->glInterface()); |
674 if (error != GR_GL_NO_ERROR) { | 685 if (error != GR_GL_NO_ERROR) { |
675 succeeded = false; | 686 succeeded = false; |
676 } else { | 687 } else { |
677 // if we have data and we used TexStorage to create the texture, we | 688 // if we have data and we used TexStorage to create the texture, we |
678 // now upload with TexSubImage. | 689 // now upload with TexSubImage. |
679 if (NULL != data && useTexStorage) { | 690 if (NULL != data && useTexStorage) { |
680 GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, | 691 GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, |
681 0, // level | 692 0, // level |
682 left, top, | 693 left, top, |
683 width, height, | 694 width, height, |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
791 desc->fSampleCnt, | 802 desc->fSampleCnt, |
792 msColorFormat, | 803 msColorFormat, |
793 width, height)) { | 804 width, height)) { |
794 goto FAILED; | 805 goto FAILED; |
795 } | 806 } |
796 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fRTFBOID)); | 807 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fRTFBOID)); |
797 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | 808 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
798 GR_GL_COLOR_ATTACHMENT0, | 809 GR_GL_COLOR_ATTACHMENT0, |
799 GR_GL_RENDERBUFFER, | 810 GR_GL_RENDERBUFFER, |
800 desc->fMSColorRenderbufferID)); | 811 desc->fMSColorRenderbufferID)); |
801 if (!this->glCaps().isConfigVerifiedColorAttachment(desc->fConfig)) { | 812 if (desc->fCheckAllocation || !this->glCaps().isConfigVerifiedColorAttac hment(desc->fConfig)) { |
bsalomon
2013/06/10 13:21:47
can you wrap this if and the next one?
Stephen White
2013/06/10 13:53:14
Done.
| |
802 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); | 813 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
803 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { | 814 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
804 goto FAILED; | 815 goto FAILED; |
805 } | 816 } |
806 fGLContext.info().caps()->markConfigAsValidColorAttachment(desc->fCo nfig); | 817 fGLContext.info().caps()->markConfigAsValidColorAttachment(desc->fCo nfig); |
807 } | 818 } |
808 } | 819 } |
809 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fTexFBOID)); | 820 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fTexFBOID)); |
810 | 821 |
811 if (this->glCaps().usesImplicitMSAAResolve() && desc->fSampleCnt > 0) { | 822 if (this->glCaps().usesImplicitMSAAResolve() && desc->fSampleCnt > 0) { |
812 GL_CALL(FramebufferTexture2DMultisample(GR_GL_FRAMEBUFFER, | 823 GL_CALL(FramebufferTexture2DMultisample(GR_GL_FRAMEBUFFER, |
813 GR_GL_COLOR_ATTACHMENT0, | 824 GR_GL_COLOR_ATTACHMENT0, |
814 GR_GL_TEXTURE_2D, | 825 GR_GL_TEXTURE_2D, |
815 texID, 0, desc->fSampleCnt)); | 826 texID, 0, desc->fSampleCnt)); |
816 } else { | 827 } else { |
817 GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, | 828 GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, |
818 GR_GL_COLOR_ATTACHMENT0, | 829 GR_GL_COLOR_ATTACHMENT0, |
819 GR_GL_TEXTURE_2D, | 830 GR_GL_TEXTURE_2D, |
820 texID, 0)); | 831 texID, 0)); |
821 } | 832 } |
822 if (!this->glCaps().isConfigVerifiedColorAttachment(desc->fConfig)) { | 833 if (desc->fCheckAllocation || !this->glCaps().isConfigVerifiedColorAttachmen t(desc->fConfig)) { |
823 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); | 834 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
824 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { | 835 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
825 goto FAILED; | 836 goto FAILED; |
826 } | 837 } |
827 fGLContext.info().caps()->markConfigAsValidColorAttachment(desc->fConfig ); | 838 fGLContext.info().caps()->markConfigAsValidColorAttachment(desc->fConfig ); |
828 } | 839 } |
829 | 840 |
830 return true; | 841 return true; |
831 | 842 |
832 FAILED: | 843 FAILED: |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
875 glTexDesc.fWidth = desc.fWidth; | 886 glTexDesc.fWidth = desc.fWidth; |
876 glTexDesc.fHeight = desc.fHeight; | 887 glTexDesc.fHeight = desc.fHeight; |
877 glTexDesc.fConfig = desc.fConfig; | 888 glTexDesc.fConfig = desc.fConfig; |
878 glTexDesc.fIsWrapped = false; | 889 glTexDesc.fIsWrapped = false; |
879 | 890 |
880 glRTDesc.fMSColorRenderbufferID = 0; | 891 glRTDesc.fMSColorRenderbufferID = 0; |
881 glRTDesc.fRTFBOID = 0; | 892 glRTDesc.fRTFBOID = 0; |
882 glRTDesc.fTexFBOID = 0; | 893 glRTDesc.fTexFBOID = 0; |
883 glRTDesc.fIsWrapped = false; | 894 glRTDesc.fIsWrapped = false; |
884 glRTDesc.fConfig = glTexDesc.fConfig; | 895 glRTDesc.fConfig = glTexDesc.fConfig; |
896 glRTDesc.fCheckAllocation = 0 != (desc.fFlags & kCheckAllocation_GrTextureFl agBit); | |
bsalomon
2013/06/10 13:21:47
SkToBool(desc.fFlags & ...)
Stephen White
2013/06/10 13:53:14
Done. Want me to do the line below? :)
bsalomon
2013/06/10 14:04:42
Yes, please! Much of the GPU code doesn't use SkTo
Stephen White
2013/06/10 14:54:39
Done (here and two other places in this file).
| |
885 | 897 |
886 bool renderTarget = 0 != (desc.fFlags & kRenderTarget_GrTextureFlagBit); | 898 bool renderTarget = 0 != (desc.fFlags & kRenderTarget_GrTextureFlagBit); |
887 | 899 |
888 glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget); | 900 glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget); |
889 glRTDesc.fOrigin = glTexDesc.fOrigin; | 901 glRTDesc.fOrigin = glTexDesc.fOrigin; |
890 | 902 |
891 glRTDesc.fSampleCnt = glTexDesc.fSampleCnt; | 903 glRTDesc.fSampleCnt = glTexDesc.fSampleCnt; |
892 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && | 904 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && |
893 desc.fSampleCnt) { | 905 desc.fSampleCnt) { |
894 //GrPrintf("MSAA RT requested but not supported on this platform."); | 906 //GrPrintf("MSAA RT requested but not supported on this platform."); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1032 created = renderbuffer_storage_msaa(fGLContext, | 1044 created = renderbuffer_storage_msaa(fGLContext, |
1033 samples, | 1045 samples, |
1034 sFmt.fInternalFormat, | 1046 sFmt.fInternalFormat, |
1035 width, height); | 1047 width, height); |
1036 } else { | 1048 } else { |
1037 GL_ALLOC_CALL(this->glInterface(), | 1049 GL_ALLOC_CALL(this->glInterface(), |
1038 RenderbufferStorage(GR_GL_RENDERBUFFER, | 1050 RenderbufferStorage(GR_GL_RENDERBUFFER, |
1039 sFmt.fInternalFormat, | 1051 sFmt.fInternalFormat, |
1040 width, height)); | 1052 width, height)); |
1041 created = | 1053 created = |
1042 (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(this->glInterface())); | 1054 (GR_GL_NO_ERROR == checkAllocError(rt->desc(), this->glInterface ())); |
1043 } | 1055 } |
1044 if (created) { | 1056 if (created) { |
1045 // After sized formats we attempt an unsized format and take | 1057 // After sized formats we attempt an unsized format and take |
1046 // whatever sizes GL gives us. In that case we query for the size. | 1058 // whatever sizes GL gives us. In that case we query for the size. |
1047 GrGLStencilBuffer::Format format = sFmt; | 1059 GrGLStencilBuffer::Format format = sFmt; |
1048 get_stencil_rb_sizes(this->glInterface(), &format); | 1060 get_stencil_rb_sizes(this->glInterface(), &format); |
1049 static const bool kIsWrapped = false; | 1061 static const bool kIsWrapped = false; |
1050 SkAutoTUnref<GrStencilBuffer> sb(SkNEW_ARGS(GrGLStencilBuffer, | 1062 SkAutoTUnref<GrStencilBuffer> sb(SkNEW_ARGS(GrGLStencilBuffer, |
1051 (this, kIsWrapped, sbID, width , height, | 1063 (this, kIsWrapped, sbID, width , height, |
1052 samples, format))); | 1064 samples, format))); |
(...skipping 1428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2481 this->setVertexArrayID(gpu, 0); | 2493 this->setVertexArrayID(gpu, 0); |
2482 } | 2494 } |
2483 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2495 int attrCount = gpu->glCaps().maxVertexAttributes(); |
2484 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 2496 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
2485 fDefaultVertexArrayAttribState.resize(attrCount); | 2497 fDefaultVertexArrayAttribState.resize(attrCount); |
2486 } | 2498 } |
2487 attribState = &fDefaultVertexArrayAttribState; | 2499 attribState = &fDefaultVertexArrayAttribState; |
2488 } | 2500 } |
2489 return attribState; | 2501 return attribState; |
2490 } | 2502 } |
OLD | NEW |