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 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 | 399 |
400 GrGLTexture::Desc glTexDesc; | 400 GrGLTexture::Desc glTexDesc; |
401 // next line relies on GrBackendTextureDesc's flags matching GrTexture's | 401 // next line relies on GrBackendTextureDesc's flags matching GrTexture's |
402 glTexDesc.fFlags = (GrTextureFlags) desc.fFlags; | 402 glTexDesc.fFlags = (GrTextureFlags) desc.fFlags; |
403 glTexDesc.fWidth = desc.fWidth; | 403 glTexDesc.fWidth = desc.fWidth; |
404 glTexDesc.fHeight = desc.fHeight; | 404 glTexDesc.fHeight = desc.fHeight; |
405 glTexDesc.fConfig = desc.fConfig; | 405 glTexDesc.fConfig = desc.fConfig; |
406 glTexDesc.fSampleCnt = desc.fSampleCnt; | 406 glTexDesc.fSampleCnt = desc.fSampleCnt; |
407 glTexDesc.fTextureID = static_cast<GrGLuint>(desc.fTextureHandle); | 407 glTexDesc.fTextureID = static_cast<GrGLuint>(desc.fTextureHandle); |
408 glTexDesc.fIsWrapped = true; | 408 glTexDesc.fIsWrapped = true; |
409 bool renderTarget = 0 != (desc.fFlags & kRenderTarget_GrBackendTextureFlag); | 409 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFla
g); |
410 // FIXME: this should be calling resolve_origin(), but Chrome code is curre
ntly | 410 // FIXME: this should be calling resolve_origin(), but Chrome code is curre
ntly |
411 // assuming the old behaviour, which is that backend textures are always | 411 // assuming the old behaviour, which is that backend textures are always |
412 // BottomLeft, even for non-RT's. Once Chrome is fixed, change this to: | 412 // BottomLeft, even for non-RT's. Once Chrome is fixed, change this to: |
413 // glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget); | 413 // glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget); |
414 if (kDefault_GrSurfaceOrigin == desc.fOrigin) { | 414 if (kDefault_GrSurfaceOrigin == desc.fOrigin) { |
415 glTexDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; | 415 glTexDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
416 } else { | 416 } else { |
417 glTexDesc.fOrigin = desc.fOrigin; | 417 glTexDesc.fOrigin = desc.fOrigin; |
418 } | 418 } |
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 check_alloc_error(const GrTextureDesc& desc, const GrGLInterface* inter
face) { |
| 542 if (SkToBool(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 = check_alloc_error(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 || |
| 813 !this->glCaps().isConfigVerifiedColorAttachment(desc->fConfig)) { |
802 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); | 814 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
803 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { | 815 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
804 goto FAILED; | 816 goto FAILED; |
805 } | 817 } |
806 fGLContext.info().caps()->markConfigAsValidColorAttachment(desc->fCo
nfig); | 818 fGLContext.info().caps()->markConfigAsValidColorAttachment(desc->fCo
nfig); |
807 } | 819 } |
808 } | 820 } |
809 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fTexFBOID)); | 821 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fTexFBOID)); |
810 | 822 |
811 if (this->glCaps().usesImplicitMSAAResolve() && desc->fSampleCnt > 0) { | 823 if (this->glCaps().usesImplicitMSAAResolve() && desc->fSampleCnt > 0) { |
812 GL_CALL(FramebufferTexture2DMultisample(GR_GL_FRAMEBUFFER, | 824 GL_CALL(FramebufferTexture2DMultisample(GR_GL_FRAMEBUFFER, |
813 GR_GL_COLOR_ATTACHMENT0, | 825 GR_GL_COLOR_ATTACHMENT0, |
814 GR_GL_TEXTURE_2D, | 826 GR_GL_TEXTURE_2D, |
815 texID, 0, desc->fSampleCnt)); | 827 texID, 0, desc->fSampleCnt)); |
816 } else { | 828 } else { |
817 GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, | 829 GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, |
818 GR_GL_COLOR_ATTACHMENT0, | 830 GR_GL_COLOR_ATTACHMENT0, |
819 GR_GL_TEXTURE_2D, | 831 GR_GL_TEXTURE_2D, |
820 texID, 0)); | 832 texID, 0)); |
821 } | 833 } |
822 if (!this->glCaps().isConfigVerifiedColorAttachment(desc->fConfig)) { | 834 if (desc->fCheckAllocation || |
| 835 !this->glCaps().isConfigVerifiedColorAttachment(desc->fConfig)) { |
823 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); | 836 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
824 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { | 837 if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
825 goto FAILED; | 838 goto FAILED; |
826 } | 839 } |
827 fGLContext.info().caps()->markConfigAsValidColorAttachment(desc->fConfig
); | 840 fGLContext.info().caps()->markConfigAsValidColorAttachment(desc->fConfig
); |
828 } | 841 } |
829 | 842 |
830 return true; | 843 return true; |
831 | 844 |
832 FAILED: | 845 FAILED: |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 glTexDesc.fWidth = desc.fWidth; | 888 glTexDesc.fWidth = desc.fWidth; |
876 glTexDesc.fHeight = desc.fHeight; | 889 glTexDesc.fHeight = desc.fHeight; |
877 glTexDesc.fConfig = desc.fConfig; | 890 glTexDesc.fConfig = desc.fConfig; |
878 glTexDesc.fIsWrapped = false; | 891 glTexDesc.fIsWrapped = false; |
879 | 892 |
880 glRTDesc.fMSColorRenderbufferID = 0; | 893 glRTDesc.fMSColorRenderbufferID = 0; |
881 glRTDesc.fRTFBOID = 0; | 894 glRTDesc.fRTFBOID = 0; |
882 glRTDesc.fTexFBOID = 0; | 895 glRTDesc.fTexFBOID = 0; |
883 glRTDesc.fIsWrapped = false; | 896 glRTDesc.fIsWrapped = false; |
884 glRTDesc.fConfig = glTexDesc.fConfig; | 897 glRTDesc.fConfig = glTexDesc.fConfig; |
| 898 glRTDesc.fCheckAllocation = SkToBool(desc.fFlags & kCheckAllocation_GrTextur
eFlagBit); |
885 | 899 |
886 bool renderTarget = 0 != (desc.fFlags & kRenderTarget_GrTextureFlagBit); | 900 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrTextureFlagBit); |
887 | 901 |
888 glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget); | 902 glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget); |
889 glRTDesc.fOrigin = glTexDesc.fOrigin; | 903 glRTDesc.fOrigin = glTexDesc.fOrigin; |
890 | 904 |
891 glRTDesc.fSampleCnt = glTexDesc.fSampleCnt; | 905 glRTDesc.fSampleCnt = glTexDesc.fSampleCnt; |
892 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && | 906 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && |
893 desc.fSampleCnt) { | 907 desc.fSampleCnt) { |
894 //GrPrintf("MSAA RT requested but not supported on this platform."); | 908 //GrPrintf("MSAA RT requested but not supported on this platform."); |
895 return return_null_texture(); | 909 return return_null_texture(); |
896 } | 910 } |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 created = renderbuffer_storage_msaa(fGLContext, | 1046 created = renderbuffer_storage_msaa(fGLContext, |
1033 samples, | 1047 samples, |
1034 sFmt.fInternalFormat, | 1048 sFmt.fInternalFormat, |
1035 width, height); | 1049 width, height); |
1036 } else { | 1050 } else { |
1037 GL_ALLOC_CALL(this->glInterface(), | 1051 GL_ALLOC_CALL(this->glInterface(), |
1038 RenderbufferStorage(GR_GL_RENDERBUFFER, | 1052 RenderbufferStorage(GR_GL_RENDERBUFFER, |
1039 sFmt.fInternalFormat, | 1053 sFmt.fInternalFormat, |
1040 width, height)); | 1054 width, height)); |
1041 created = | 1055 created = |
1042 (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(this->glInterface())); | 1056 (GR_GL_NO_ERROR == check_alloc_error(rt->desc(), this->glInterfa
ce())); |
1043 } | 1057 } |
1044 if (created) { | 1058 if (created) { |
1045 // After sized formats we attempt an unsized format and take | 1059 // After sized formats we attempt an unsized format and take |
1046 // whatever sizes GL gives us. In that case we query for the size. | 1060 // whatever sizes GL gives us. In that case we query for the size. |
1047 GrGLStencilBuffer::Format format = sFmt; | 1061 GrGLStencilBuffer::Format format = sFmt; |
1048 get_stencil_rb_sizes(this->glInterface(), &format); | 1062 get_stencil_rb_sizes(this->glInterface(), &format); |
1049 static const bool kIsWrapped = false; | 1063 static const bool kIsWrapped = false; |
1050 SkAutoTUnref<GrStencilBuffer> sb(SkNEW_ARGS(GrGLStencilBuffer, | 1064 SkAutoTUnref<GrStencilBuffer> sb(SkNEW_ARGS(GrGLStencilBuffer, |
1051 (this, kIsWrapped, sbID, width
, height, | 1065 (this, kIsWrapped, sbID, width
, height, |
1052 samples, format))); | 1066 samples, format))); |
(...skipping 1428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2481 this->setVertexArrayID(gpu, 0); | 2495 this->setVertexArrayID(gpu, 0); |
2482 } | 2496 } |
2483 int attrCount = gpu->glCaps().maxVertexAttributes(); | 2497 int attrCount = gpu->glCaps().maxVertexAttributes(); |
2484 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 2498 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
2485 fDefaultVertexArrayAttribState.resize(attrCount); | 2499 fDefaultVertexArrayAttribState.resize(attrCount); |
2486 } | 2500 } |
2487 attribState = &fDefaultVertexArrayAttribState; | 2501 attribState = &fDefaultVertexArrayAttribState; |
2488 } | 2502 } |
2489 return attribState; | 2503 return attribState; |
2490 } | 2504 } |
OLD | NEW |