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 "GrGLGpu.h" | 9 #include "GrGLGpu.h" |
10 #include "GrGLGLSL.h" | 10 #include "GrGLGLSL.h" |
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
642 this->setScratchTextureUnit(); | 642 this->setScratchTextureUnit(); |
643 GL_CALL(BindTexture(glTex->target(), glTex->textureID())); | 643 GL_CALL(BindTexture(glTex->target(), glTex->textureID())); |
644 | 644 |
645 bool success = false; | 645 bool success = false; |
646 if (GrPixelConfigIsCompressed(glTex->desc().fConfig)) { | 646 if (GrPixelConfigIsCompressed(glTex->desc().fConfig)) { |
647 // We check that config == desc.fConfig in GrGLGpu::canWriteTexturePixel s() | 647 // We check that config == desc.fConfig in GrGLGpu::canWriteTexturePixel s() |
648 SkASSERT(config == glTex->desc().fConfig); | 648 SkASSERT(config == glTex->desc().fConfig); |
649 success = this->uploadCompressedTexData(glTex->desc(), glTex->target(), buffer, | 649 success = this->uploadCompressedTexData(glTex->desc(), glTex->target(), buffer, |
650 kWrite_UploadType, left, top, wi dth, height); | 650 kWrite_UploadType, left, top, wi dth, height); |
651 } else { | 651 } else { |
652 success = this->uploadTexData(glTex->desc(), glTex->target(), kWrite_Upl oadType, | 652 success = this->uploadTexData( |
653 left, top, width, height, config, buffer, rowBytes); | 653 glTex->desc(), |
654 reinterpret_cast<GrGLTextureInfo*>(glTex->getTextureHandle()), | |
655 kWrite_UploadType, left, top, width, height, config, buffer, | |
656 rowBytes); | |
654 } | 657 } |
655 | 658 |
656 if (success) { | 659 if (success) { |
657 glTex->texturePriv().dirtyMipMaps(true); | 660 glTex->texturePriv().dirtyMipMaps(true); |
658 return true; | 661 return true; |
659 } | 662 } |
660 | 663 |
661 return false; | 664 return false; |
662 } | 665 } |
663 | 666 |
(...skipping 16 matching lines...) Expand all Loading... | |
680 GL_CALL(BindTexture(glTex->target(), glTex->textureID())); | 683 GL_CALL(BindTexture(glTex->target(), glTex->textureID())); |
681 | 684 |
682 SkASSERT(!buffer->isMapped()); | 685 SkASSERT(!buffer->isMapped()); |
683 GrGLTransferBuffer* glBuffer = reinterpret_cast<GrGLTransferBuffer*>(buffer) ; | 686 GrGLTransferBuffer* glBuffer = reinterpret_cast<GrGLTransferBuffer*>(buffer) ; |
684 // bind the transfer buffer | 687 // bind the transfer buffer |
685 SkASSERT(GR_GL_PIXEL_UNPACK_BUFFER == glBuffer->bufferType() || | 688 SkASSERT(GR_GL_PIXEL_UNPACK_BUFFER == glBuffer->bufferType() || |
686 GR_GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM == glBuffer->bufferType ()); | 689 GR_GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM == glBuffer->bufferType ()); |
687 GL_CALL(BindBuffer(glBuffer->bufferType(), glBuffer->bufferID())); | 690 GL_CALL(BindBuffer(glBuffer->bufferType(), glBuffer->bufferID())); |
688 | 691 |
689 bool success = false; | 692 bool success = false; |
690 success = this->uploadTexData(glTex->desc(), glTex->target(), kTransfer_Uplo adType, | 693 success = this->uploadTexData( |
691 left, top, width, height, config, buffer, rowB ytes); | 694 glTex->desc(), |
695 reinterpret_cast<GrGLTextureInfo*>(glTex->getTextureHandle()), | |
696 kTransfer_UploadType, left, top, width, height, config, buffer, | |
697 rowBytes); | |
692 | 698 |
693 if (success) { | 699 if (success) { |
694 glTex->texturePriv().dirtyMipMaps(true); | 700 glTex->texturePriv().dirtyMipMaps(true); |
695 return true; | 701 return true; |
696 } | 702 } |
697 | 703 |
698 return false; | 704 return false; |
699 } | 705 } |
700 | 706 |
701 // For GL_[UN]PACK_ALIGNMENT. | 707 // For GL_[UN]PACK_ALIGNMENT. |
(...skipping 20 matching lines...) Expand all Loading... | |
722 static inline GrGLenum check_alloc_error(const GrSurfaceDesc& desc, | 728 static inline GrGLenum check_alloc_error(const GrSurfaceDesc& desc, |
723 const GrGLInterface* interface) { | 729 const GrGLInterface* interface) { |
724 if (SkToBool(desc.fFlags & kCheckAllocation_GrSurfaceFlag)) { | 730 if (SkToBool(desc.fFlags & kCheckAllocation_GrSurfaceFlag)) { |
725 return GR_GL_GET_ERROR(interface); | 731 return GR_GL_GET_ERROR(interface); |
726 } else { | 732 } else { |
727 return CHECK_ALLOC_ERROR(interface); | 733 return CHECK_ALLOC_ERROR(interface); |
728 } | 734 } |
729 } | 735 } |
730 | 736 |
731 bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc, | 737 bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc, |
732 GrGLenum target, | 738 GrGLTextureInfo* info, |
733 UploadType uploadType, | 739 UploadType uploadType, |
734 int left, int top, int width, int height, | 740 int left, int top, int width, int height, |
735 GrPixelConfig dataConfig, | 741 GrPixelConfig dataConfig, |
736 const void* dataOrOffset, | 742 const void* dataOrOffset, |
737 size_t rowBytes) { | 743 size_t rowBytes) { |
738 SkASSERT(dataOrOffset || kNewTexture_UploadType == uploadType || | 744 SkASSERT(dataOrOffset || kNewTexture_UploadType == uploadType || |
739 kTransfer_UploadType == uploadType); | 745 kTransfer_UploadType == uploadType); |
740 | 746 |
741 // If we're uploading compressed data then we should be using uploadCompress edTexData | 747 // If we're uploading compressed data then we should be using uploadCompress edTexData |
742 SkASSERT(!GrPixelConfigIsCompressed(dataConfig)); | 748 SkASSERT(!GrPixelConfigIsCompressed(dataConfig)); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
819 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_TRUE)); | 825 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_TRUE)); |
820 } | 826 } |
821 GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, config_alignment(dataConfig) )); | 827 GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, config_alignment(dataConfig) )); |
822 } | 828 } |
823 bool succeeded = true; | 829 bool succeeded = true; |
824 if (kNewTexture_UploadType == uploadType) { | 830 if (kNewTexture_UploadType == uploadType) { |
825 if (dataOrOffset && | 831 if (dataOrOffset && |
826 !(0 == left && 0 == top && desc.fWidth == width && desc.fHeight == h eight)) { | 832 !(0 == left && 0 == top && desc.fWidth == width && desc.fHeight == h eight)) { |
827 succeeded = false; | 833 succeeded = false; |
828 } else { | 834 } else { |
829 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | 835 if (desc.fTextureStorageAllocator) { |
830 GL_ALLOC_CALL(this->glInterface(), TexImage2D(target, 0, internalFor mat, desc.fWidth, | 836 if (dataOrOffset) { |
831 desc.fHeight, 0, exter nalFormat, | 837 GL_CALL(TexSubImage2D(info->fTarget, |
832 externalType, dataOrOf fset)); | 838 0, // level |
833 GrGLenum error = check_alloc_error(desc, this->glInterface()); | 839 left, top, |
834 if (error != GR_GL_NO_ERROR) { | 840 width, height, |
835 succeeded = false; | 841 externalFormat, externalType, dataOrOf fset)); |
836 } | 842 } |
843 } else { | |
844 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | |
845 GL_ALLOC_CALL(this->glInterface(), TexImage2D( | |
846 info->fTarget, 0, internalFormat, desc.fWidth, desc.fHeight, 0, externalFormat, | |
847 externalType, dataOrOffset)); | |
848 GrGLenum error = check_alloc_error(desc, this->glInterface()); | |
849 if (error != GR_GL_NO_ERROR) { | |
850 succeeded = false; | |
851 } | |
852 } | |
837 } | 853 } |
838 } else { | 854 } else { |
839 if (swFlipY || glFlipY) { | 855 if (swFlipY || glFlipY) { |
840 top = desc.fHeight - (top + height); | 856 top = desc.fHeight - (top + height); |
841 } | 857 } |
842 GL_CALL(TexSubImage2D(target, | 858 GL_CALL(TexSubImage2D(info->fTarget, |
843 0, // level | 859 0, // level |
844 left, top, | 860 left, top, |
845 width, height, | 861 width, height, |
846 externalFormat, externalType, dataOrOffset)); | 862 externalFormat, externalType, dataOrOffset)); |
847 } | 863 } |
848 | 864 |
849 if (restoreGLRowLength) { | 865 if (restoreGLRowLength) { |
850 SkASSERT(this->glCaps().unpackRowLengthSupport()); | 866 SkASSERT(this->glCaps().unpackRowLengthSupport()); |
851 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); | 867 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); |
852 } | 868 } |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1095 const void* srcData, size_t rowBytes) { | 1111 const void* srcData, size_t rowBytes) { |
1096 // We fail if the MSAA was requested and is not available. | 1112 // We fail if the MSAA was requested and is not available. |
1097 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleC nt) { | 1113 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleC nt) { |
1098 //SkDebugf("MSAA RT requested but not supported on this platform."); | 1114 //SkDebugf("MSAA RT requested but not supported on this platform."); |
1099 return return_null_texture(); | 1115 return return_null_texture(); |
1100 } | 1116 } |
1101 | 1117 |
1102 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); | 1118 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); |
1103 | 1119 |
1104 GrGLTexture::IDDesc idDesc; | 1120 GrGLTexture::IDDesc idDesc; |
1105 idDesc.fInfo.fID = 0; | |
1106 GL_CALL(GenTextures(1, &idDesc.fInfo.fID)); | |
1107 idDesc.fLifeCycle = lifeCycle; | 1121 idDesc.fLifeCycle = lifeCycle; |
1108 // We only support GL_TEXTURE_2D at the moment. | 1122 GrGLTexture::TexParams initialTexParams; |
1109 idDesc.fInfo.fTarget = GR_GL_TEXTURE_2D; | 1123 if (!createTextureImpl(desc, &idDesc.fInfo, renderTarget, srcData, |
bsalomon
2016/01/26 22:20:54
nit, we prefix method calls with "this->"
erikchen
2016/01/27 21:55:15
Done.
| |
1110 | 1124 &initialTexParams, rowBytes)) { |
1111 if (!idDesc.fInfo.fID) { | |
1112 return return_null_texture(); | 1125 return return_null_texture(); |
1113 } | 1126 } |
1114 | 1127 |
1115 this->setScratchTextureUnit(); | |
1116 GL_CALL(BindTexture(idDesc.fInfo.fTarget, idDesc.fInfo.fID)); | |
1117 | |
1118 if (renderTarget && this->glCaps().textureUsageSupport()) { | |
1119 // provides a hint about how this texture will be used | |
1120 GL_CALL(TexParameteri(idDesc.fInfo.fTarget, | |
1121 GR_GL_TEXTURE_USAGE, | |
1122 GR_GL_FRAMEBUFFER_ATTACHMENT)); | |
1123 } | |
1124 | |
1125 // Some drivers like to know filter/wrap before seeing glTexImage2D. Some | |
1126 // drivers have a bug where an FBO won't be complete if it includes a | |
1127 // texture that is not mipmap complete (considering the filter in use). | |
1128 GrGLTexture::TexParams initialTexParams; | |
1129 // we only set a subset here so invalidate first | |
1130 initialTexParams.invalidate(); | |
1131 initialTexParams.fMinFilter = GR_GL_NEAREST; | |
1132 initialTexParams.fMagFilter = GR_GL_NEAREST; | |
1133 initialTexParams.fWrapS = GR_GL_CLAMP_TO_EDGE; | |
1134 initialTexParams.fWrapT = GR_GL_CLAMP_TO_EDGE; | |
1135 GL_CALL(TexParameteri(idDesc.fInfo.fTarget, | |
1136 GR_GL_TEXTURE_MAG_FILTER, | |
1137 initialTexParams.fMagFilter)); | |
1138 GL_CALL(TexParameteri(idDesc.fInfo.fTarget, | |
1139 GR_GL_TEXTURE_MIN_FILTER, | |
1140 initialTexParams.fMinFilter)); | |
1141 GL_CALL(TexParameteri(idDesc.fInfo.fTarget, | |
1142 GR_GL_TEXTURE_WRAP_S, | |
1143 initialTexParams.fWrapS)); | |
1144 GL_CALL(TexParameteri(idDesc.fInfo.fTarget, | |
1145 GR_GL_TEXTURE_WRAP_T, | |
1146 initialTexParams.fWrapT)); | |
1147 if (!this->uploadTexData(desc, idDesc.fInfo.fTarget, kNewTexture_UploadType, 0, 0, | |
1148 desc.fWidth, desc.fHeight, | |
1149 desc.fConfig, srcData, rowBytes)) { | |
1150 GL_CALL(DeleteTextures(1, &idDesc.fInfo.fID)); | |
1151 return return_null_texture(); | |
1152 } | |
1153 | |
1154 GrGLTexture* tex; | 1128 GrGLTexture* tex; |
1155 if (renderTarget) { | 1129 if (renderTarget) { |
1156 // unbind the texture from the texture unit before binding it to the fra me buffer | 1130 // unbind the texture from the texture unit before binding it to the fra me buffer |
1157 GL_CALL(BindTexture(idDesc.fInfo.fTarget, 0)); | 1131 GL_CALL(BindTexture(idDesc.fInfo.fTarget, 0)); |
1158 GrGLRenderTarget::IDDesc rtIDDesc; | 1132 GrGLRenderTarget::IDDesc rtIDDesc; |
1159 | 1133 |
1160 if (!this->createRenderTargetObjects(desc, lifeCycle, idDesc.fInfo, &rtI DDesc)) { | 1134 if (!this->createRenderTargetObjects(desc, lifeCycle, idDesc.fInfo, &rtI DDesc)) { |
1161 GL_CALL(DeleteTextures(1, &idDesc.fInfo.fID)); | 1135 GL_CALL(DeleteTextures(1, &idDesc.fInfo.fID)); |
1162 return return_null_texture(); | 1136 return return_null_texture(); |
1163 } | 1137 } |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1363 GL_CALL(DeleteRenderbuffers(1, &sbRBID)); | 1337 GL_CALL(DeleteRenderbuffers(1, &sbRBID)); |
1364 } | 1338 } |
1365 GL_CALL(DeleteTextures(1, &colorID)); | 1339 GL_CALL(DeleteTextures(1, &colorID)); |
1366 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, 0)); | 1340 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, 0)); |
1367 GL_CALL(DeleteFramebuffers(1, &fb)); | 1341 GL_CALL(DeleteFramebuffers(1, &fb)); |
1368 fGLContext->caps()->setStencilFormatIndexForConfig(config, firstWorkingS tencilFormatIndex); | 1342 fGLContext->caps()->setStencilFormatIndexForConfig(config, firstWorkingS tencilFormatIndex); |
1369 } | 1343 } |
1370 return this->glCaps().getStencilFormatIndexForConfig(config); | 1344 return this->glCaps().getStencilFormatIndexForConfig(config); |
1371 } | 1345 } |
1372 | 1346 |
1347 bool GrGLGpu::createTextureImpl(const GrSurfaceDesc& desc, GrGLTextureInfo* info , | |
1348 bool renderTarget, const void* srcData, | |
1349 GrGLTexture::TexParams* initialTexParams, size_t rowBytes) { | |
1350 // Some drivers like to know filter/wrap before seeing glTexImage2D. Some | |
1351 // drivers have a bug where an FBO won't be complete if it includes a | |
1352 // texture that is not mipmap complete (considering the filter in use). | |
1353 | |
1354 // we only set a subset here so invalidate first | |
1355 initialTexParams->invalidate(); | |
1356 initialTexParams->fMinFilter = GR_GL_NEAREST; | |
1357 initialTexParams->fMagFilter = GR_GL_NEAREST; | |
1358 initialTexParams->fWrapS = GR_GL_CLAMP_TO_EDGE; | |
1359 initialTexParams->fWrapT = GR_GL_CLAMP_TO_EDGE; | |
1360 | |
1361 if (desc.fTextureStorageAllocator) { | |
1362 if (!desc.fTextureStorageAllocator->allocateTextureStorage( | |
1363 reinterpret_cast<GrBackendObject>(info), desc.fWidth, desc.fHeig ht)) { | |
1364 return false; | |
1365 } | |
1366 | |
1367 if (!this->uploadTexData(desc, info, kNewTexture_UploadType, 0, 0, | |
1368 desc.fWidth, desc.fHeight, | |
1369 desc.fConfig, srcData, rowBytes)) { | |
1370 desc.fTextureStorageAllocator->deallocateTextureStorage( | |
1371 reinterpret_cast<GrBackendObject>(info)); | |
1372 return false; | |
1373 } | |
1374 return true; | |
1375 } | |
1376 | |
1377 info->fID = 0; | |
1378 info->fTarget = GR_GL_TEXTURE_2D; | |
1379 GL_CALL(GenTextures(1, &(info->fID))); | |
1380 | |
1381 if (!info->fID) { | |
1382 return false; | |
1383 } | |
1384 | |
1385 this->setScratchTextureUnit(); | |
1386 GL_CALL(BindTexture(info->fTarget, info->fID)); | |
1387 | |
1388 if (renderTarget && this->glCaps().textureUsageSupport()) { | |
1389 // provides a hint about how this texture will be used | |
1390 GL_CALL(TexParameteri(info->fTarget, | |
1391 GR_GL_TEXTURE_USAGE, | |
1392 GR_GL_FRAMEBUFFER_ATTACHMENT)); | |
1393 } | |
1394 | |
1395 GL_CALL(TexParameteri(info->fTarget, | |
1396 GR_GL_TEXTURE_MAG_FILTER, | |
1397 initialTexParams->fMagFilter)); | |
1398 GL_CALL(TexParameteri(info->fTarget, | |
1399 GR_GL_TEXTURE_MIN_FILTER, | |
1400 initialTexParams->fMinFilter)); | |
1401 GL_CALL(TexParameteri(info->fTarget, | |
1402 GR_GL_TEXTURE_WRAP_S, | |
1403 initialTexParams->fWrapS)); | |
1404 GL_CALL(TexParameteri(info->fTarget, | |
1405 GR_GL_TEXTURE_WRAP_T, | |
1406 initialTexParams->fWrapT)); | |
1407 if (!this->uploadTexData(desc, info, kNewTexture_UploadType, 0, 0, | |
1408 desc.fWidth, desc.fHeight, | |
1409 desc.fConfig, srcData, rowBytes)) { | |
1410 GL_CALL(DeleteTextures(1, &(info->fID))); | |
1411 return false; | |
1412 } | |
1413 return true; | |
1414 } | |
1415 | |
1373 GrStencilAttachment* GrGLGpu::createStencilAttachmentForRenderTarget(const GrRen derTarget* rt, | 1416 GrStencilAttachment* GrGLGpu::createStencilAttachmentForRenderTarget(const GrRen derTarget* rt, |
1374 int width, | 1417 int width, |
1375 int height) { | 1418 int height) { |
1376 // All internally created RTs are also textures. We don't create | 1419 // All internally created RTs are also textures. We don't create |
1377 // SBs for a client's standalone RT (that is a RT that isn't also a texture) . | 1420 // SBs for a client's standalone RT (that is a RT that isn't also a texture) . |
1378 SkASSERT(rt->asTexture()); | 1421 SkASSERT(rt->asTexture()); |
1379 SkASSERT(width >= rt->width()); | 1422 SkASSERT(width >= rt->width()); |
1380 SkASSERT(height >= rt->height()); | 1423 SkASSERT(height >= rt->height()); |
1381 | 1424 |
1382 int samples = rt->numStencilSamples(); | 1425 int samples = rt->numStencilSamples(); |
(...skipping 2173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3556 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || | 3599 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || |
3557 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { | 3600 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { |
3558 copyParams->fFilter = GrTextureParams::kNone_FilterMode; | 3601 copyParams->fFilter = GrTextureParams::kNone_FilterMode; |
3559 copyParams->fWidth = texture->width(); | 3602 copyParams->fWidth = texture->width(); |
3560 copyParams->fHeight = texture->height(); | 3603 copyParams->fHeight = texture->height(); |
3561 return true; | 3604 return true; |
3562 } | 3605 } |
3563 } | 3606 } |
3564 return false; | 3607 return false; |
3565 } | 3608 } |
OLD | NEW |