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 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 case kBorrow_GrWrapOwnership: | 477 case kBorrow_GrWrapOwnership: |
478 idDesc.fLifeCycle = GrGpuResource::kBorrowed_LifeCycle; | 478 idDesc.fLifeCycle = GrGpuResource::kBorrowed_LifeCycle; |
479 break; | 479 break; |
480 } | 480 } |
481 | 481 |
482 surfDesc.fFlags = (GrSurfaceFlags) desc.fFlags; | 482 surfDesc.fFlags = (GrSurfaceFlags) desc.fFlags; |
483 surfDesc.fWidth = desc.fWidth; | 483 surfDesc.fWidth = desc.fWidth; |
484 surfDesc.fHeight = desc.fHeight; | 484 surfDesc.fHeight = desc.fHeight; |
485 surfDesc.fConfig = desc.fConfig; | 485 surfDesc.fConfig = desc.fConfig; |
486 surfDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount()
); | 486 surfDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount()
); |
| 487 surfDesc.fTextureStorageAllocator = desc.fTextureStorageAllocator; |
487 // FIXME: this should be calling resolve_origin(), but Chrome code is curre
ntly | 488 // FIXME: this should be calling resolve_origin(), but Chrome code is curre
ntly |
488 // assuming the old behaviour, which is that backend textures are always | 489 // assuming the old behaviour, which is that backend textures are always |
489 // BottomLeft, even for non-RT's. Once Chrome is fixed, change this to: | 490 // BottomLeft, even for non-RT's. Once Chrome is fixed, change this to: |
490 // glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget); | 491 // glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget); |
491 if (kDefault_GrSurfaceOrigin == desc.fOrigin) { | 492 if (kDefault_GrSurfaceOrigin == desc.fOrigin) { |
492 surfDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; | 493 surfDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
493 } else { | 494 } else { |
494 surfDesc.fOrigin = desc.fOrigin; | 495 surfDesc.fOrigin = desc.fOrigin; |
495 } | 496 } |
496 | 497 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 this->setScratchTextureUnit(); | 643 this->setScratchTextureUnit(); |
643 GL_CALL(BindTexture(glTex->target(), glTex->textureID())); | 644 GL_CALL(BindTexture(glTex->target(), glTex->textureID())); |
644 | 645 |
645 bool success = false; | 646 bool success = false; |
646 if (GrPixelConfigIsCompressed(glTex->desc().fConfig)) { | 647 if (GrPixelConfigIsCompressed(glTex->desc().fConfig)) { |
647 // We check that config == desc.fConfig in GrGLGpu::canWriteTexturePixel
s() | 648 // We check that config == desc.fConfig in GrGLGpu::canWriteTexturePixel
s() |
648 SkASSERT(config == glTex->desc().fConfig); | 649 SkASSERT(config == glTex->desc().fConfig); |
649 success = this->uploadCompressedTexData(glTex->desc(), glTex->target(),
buffer, | 650 success = this->uploadCompressedTexData(glTex->desc(), glTex->target(),
buffer, |
650 kWrite_UploadType, left, top, wi
dth, height); | 651 kWrite_UploadType, left, top, wi
dth, height); |
651 } else { | 652 } else { |
652 success = this->uploadTexData(glTex->desc(), glTex->target(), kWrite_Upl
oadType, | 653 success = this->uploadTexData( |
653 left, top, width, height, config, buffer,
rowBytes); | 654 glTex->desc(), |
| 655 reinterpret_cast<GrGLTextureInfo*>(glTex->getTextureHandle()), |
| 656 kWrite_UploadType, left, top, width, height, config, buffer, |
| 657 rowBytes); |
654 } | 658 } |
655 | 659 |
656 if (success) { | 660 if (success) { |
657 glTex->texturePriv().dirtyMipMaps(true); | 661 glTex->texturePriv().dirtyMipMaps(true); |
658 return true; | 662 return true; |
659 } | 663 } |
660 | 664 |
661 return false; | 665 return false; |
662 } | 666 } |
663 | 667 |
(...skipping 16 matching lines...) Expand all Loading... |
680 GL_CALL(BindTexture(glTex->target(), glTex->textureID())); | 684 GL_CALL(BindTexture(glTex->target(), glTex->textureID())); |
681 | 685 |
682 SkASSERT(!buffer->isMapped()); | 686 SkASSERT(!buffer->isMapped()); |
683 GrGLTransferBuffer* glBuffer = reinterpret_cast<GrGLTransferBuffer*>(buffer)
; | 687 GrGLTransferBuffer* glBuffer = reinterpret_cast<GrGLTransferBuffer*>(buffer)
; |
684 // bind the transfer buffer | 688 // bind the transfer buffer |
685 SkASSERT(GR_GL_PIXEL_UNPACK_BUFFER == glBuffer->bufferType() || | 689 SkASSERT(GR_GL_PIXEL_UNPACK_BUFFER == glBuffer->bufferType() || |
686 GR_GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM == glBuffer->bufferType
()); | 690 GR_GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM == glBuffer->bufferType
()); |
687 GL_CALL(BindBuffer(glBuffer->bufferType(), glBuffer->bufferID())); | 691 GL_CALL(BindBuffer(glBuffer->bufferType(), glBuffer->bufferID())); |
688 | 692 |
689 bool success = false; | 693 bool success = false; |
690 success = this->uploadTexData(glTex->desc(), glTex->target(), kTransfer_Uplo
adType, | 694 success = this->uploadTexData( |
691 left, top, width, height, config, buffer, rowB
ytes); | 695 glTex->desc(), |
| 696 reinterpret_cast<GrGLTextureInfo*>(glTex->getTextureHandle()), |
| 697 kTransfer_UploadType, left, top, width, height, config, buffer, |
| 698 rowBytes); |
692 | 699 |
693 if (success) { | 700 if (success) { |
694 glTex->texturePriv().dirtyMipMaps(true); | 701 glTex->texturePriv().dirtyMipMaps(true); |
695 return true; | 702 return true; |
696 } | 703 } |
697 | 704 |
698 return false; | 705 return false; |
699 } | 706 } |
700 | 707 |
701 // For GL_[UN]PACK_ALIGNMENT. | 708 // For GL_[UN]PACK_ALIGNMENT. |
(...skipping 20 matching lines...) Expand all Loading... |
722 static inline GrGLenum check_alloc_error(const GrSurfaceDesc& desc, | 729 static inline GrGLenum check_alloc_error(const GrSurfaceDesc& desc, |
723 const GrGLInterface* interface) { | 730 const GrGLInterface* interface) { |
724 if (SkToBool(desc.fFlags & kCheckAllocation_GrSurfaceFlag)) { | 731 if (SkToBool(desc.fFlags & kCheckAllocation_GrSurfaceFlag)) { |
725 return GR_GL_GET_ERROR(interface); | 732 return GR_GL_GET_ERROR(interface); |
726 } else { | 733 } else { |
727 return CHECK_ALLOC_ERROR(interface); | 734 return CHECK_ALLOC_ERROR(interface); |
728 } | 735 } |
729 } | 736 } |
730 | 737 |
731 bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc, | 738 bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc, |
732 GrGLenum target, | 739 GrGLTextureInfo* info, |
733 UploadType uploadType, | 740 UploadType uploadType, |
734 int left, int top, int width, int height, | 741 int left, int top, int width, int height, |
735 GrPixelConfig dataConfig, | 742 GrPixelConfig dataConfig, |
736 const void* dataOrOffset, | 743 const void* dataOrOffset, |
737 size_t rowBytes) { | 744 size_t rowBytes) { |
738 SkASSERT(dataOrOffset || kNewTexture_UploadType == uploadType || | 745 SkASSERT(dataOrOffset || kNewTexture_UploadType == uploadType || |
739 kTransfer_UploadType == uploadType); | 746 kTransfer_UploadType == uploadType); |
740 | 747 |
741 // If we're uploading compressed data then we should be using uploadCompress
edTexData | 748 // If we're uploading compressed data then we should be using uploadCompress
edTexData |
742 SkASSERT(!GrPixelConfigIsCompressed(dataConfig)); | 749 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)); | 826 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_TRUE)); |
820 } | 827 } |
821 GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, config_alignment(dataConfig)
)); | 828 GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, config_alignment(dataConfig)
)); |
822 } | 829 } |
823 bool succeeded = true; | 830 bool succeeded = true; |
824 if (kNewTexture_UploadType == uploadType) { | 831 if (kNewTexture_UploadType == uploadType) { |
825 if (dataOrOffset && | 832 if (dataOrOffset && |
826 !(0 == left && 0 == top && desc.fWidth == width && desc.fHeight == h
eight)) { | 833 !(0 == left && 0 == top && desc.fWidth == width && desc.fHeight == h
eight)) { |
827 succeeded = false; | 834 succeeded = false; |
828 } else { | 835 } else { |
829 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | 836 if (desc.fTextureStorageAllocator) {
|
830 GL_ALLOC_CALL(this->glInterface(), TexImage2D(target, 0, internalFor
mat, desc.fWidth, | 837 succeeded = desc.fTextureStorageAllocator->allocateTextureStorag
e( |
831 desc.fHeight, 0, exter
nalFormat, | 838 info->fID, width, height); |
832 externalType, dataOrOf
fset)); | 839 if (succeeded && dataOrOffset) { |
833 GrGLenum error = check_alloc_error(desc, this->glInterface()); | 840 GL_CALL(TexSubImage2D(info->fTarget, |
834 if (error != GR_GL_NO_ERROR) { | 841 0, // level |
835 succeeded = false; | 842 left, top, |
836 } | 843 width, height, |
| 844 externalFormat, externalType, dataOrOf
fset)); |
| 845 } |
| 846 } else {
|
| 847 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface());
|
| 848 GL_ALLOC_CALL(this->glInterface(), TexImage2D(
|
| 849 info->fTarget, 0, internalFormat, desc.fWidth, desc.fHeight,
0, externalFormat, |
| 850 externalType, dataOrOffset));
|
| 851 GrGLenum error = check_alloc_error(desc, this->glInterface()); |
| 852 if (error != GR_GL_NO_ERROR) {
|
| 853 succeeded = false;
|
| 854 } |
| 855 } |
837 } | 856 } |
838 } else { | 857 } else { |
839 if (swFlipY || glFlipY) { | 858 if (swFlipY || glFlipY) { |
840 top = desc.fHeight - (top + height); | 859 top = desc.fHeight - (top + height); |
841 } | 860 } |
842 GL_CALL(TexSubImage2D(target, | 861 GL_CALL(TexSubImage2D(info->fTarget, |
843 0, // level | 862 0, // level |
844 left, top, | 863 left, top, |
845 width, height, | 864 width, height, |
846 externalFormat, externalType, dataOrOffset)); | 865 externalFormat, externalType, dataOrOffset)); |
847 } | 866 } |
848 | 867 |
849 if (restoreGLRowLength) { | 868 if (restoreGLRowLength) { |
850 SkASSERT(this->glCaps().unpackRowLengthSupport()); | 869 SkASSERT(this->glCaps().unpackRowLengthSupport()); |
851 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); | 870 GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); |
852 } | 871 } |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 //SkDebugf("MSAA RT requested but not supported on this platform."); | 1117 //SkDebugf("MSAA RT requested but not supported on this platform."); |
1099 return return_null_texture(); | 1118 return return_null_texture(); |
1100 } | 1119 } |
1101 | 1120 |
1102 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); | 1121 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); |
1103 | 1122 |
1104 GrGLTexture::IDDesc idDesc; | 1123 GrGLTexture::IDDesc idDesc; |
1105 idDesc.fInfo.fID = 0; | 1124 idDesc.fInfo.fID = 0; |
1106 GL_CALL(GenTextures(1, &idDesc.fInfo.fID)); | 1125 GL_CALL(GenTextures(1, &idDesc.fInfo.fID)); |
1107 idDesc.fLifeCycle = lifeCycle; | 1126 idDesc.fLifeCycle = lifeCycle; |
1108 // We only support GL_TEXTURE_2D at the moment. | 1127 |
1109 idDesc.fInfo.fTarget = GR_GL_TEXTURE_2D; | 1128 if (desc.fTextureStorageAllocator) {
|
| 1129 idDesc.fInfo.fTarget = desc.fTextureStorageAllocator->textureStorageTarg
et(); |
| 1130 } else { |
| 1131 idDesc.fInfo.fTarget = GR_GL_TEXTURE_2D; |
| 1132 } |
1110 | 1133 |
1111 if (!idDesc.fInfo.fID) { | 1134 if (!idDesc.fInfo.fID) { |
1112 return return_null_texture(); | 1135 return return_null_texture(); |
1113 } | 1136 } |
1114 | 1137 |
1115 this->setScratchTextureUnit(); | 1138 this->setScratchTextureUnit(); |
1116 GL_CALL(BindTexture(idDesc.fInfo.fTarget, idDesc.fInfo.fID)); | 1139 GL_CALL(BindTexture(idDesc.fInfo.fTarget, idDesc.fInfo.fID)); |
1117 | 1140 |
1118 if (renderTarget && this->glCaps().textureUsageSupport()) { | 1141 if (renderTarget && this->glCaps().textureUsageSupport()) { |
1119 // provides a hint about how this texture will be used | 1142 // provides a hint about how this texture will be used |
(...skipping 17 matching lines...) Expand all Loading... |
1137 initialTexParams.fMagFilter)); | 1160 initialTexParams.fMagFilter)); |
1138 GL_CALL(TexParameteri(idDesc.fInfo.fTarget, | 1161 GL_CALL(TexParameteri(idDesc.fInfo.fTarget, |
1139 GR_GL_TEXTURE_MIN_FILTER, | 1162 GR_GL_TEXTURE_MIN_FILTER, |
1140 initialTexParams.fMinFilter)); | 1163 initialTexParams.fMinFilter)); |
1141 GL_CALL(TexParameteri(idDesc.fInfo.fTarget, | 1164 GL_CALL(TexParameteri(idDesc.fInfo.fTarget, |
1142 GR_GL_TEXTURE_WRAP_S, | 1165 GR_GL_TEXTURE_WRAP_S, |
1143 initialTexParams.fWrapS)); | 1166 initialTexParams.fWrapS)); |
1144 GL_CALL(TexParameteri(idDesc.fInfo.fTarget, | 1167 GL_CALL(TexParameteri(idDesc.fInfo.fTarget, |
1145 GR_GL_TEXTURE_WRAP_T, | 1168 GR_GL_TEXTURE_WRAP_T, |
1146 initialTexParams.fWrapT)); | 1169 initialTexParams.fWrapT)); |
1147 if (!this->uploadTexData(desc, idDesc.fInfo.fTarget, kNewTexture_UploadType,
0, 0, | 1170 if (!this->uploadTexData(desc, &idDesc.fInfo, kNewTexture_UploadType, 0, 0, |
1148 desc.fWidth, desc.fHeight, | 1171 desc.fWidth, desc.fHeight, |
1149 desc.fConfig, srcData, rowBytes)) { | 1172 desc.fConfig, srcData, rowBytes)) { |
1150 GL_CALL(DeleteTextures(1, &idDesc.fInfo.fID)); | 1173 GL_CALL(DeleteTextures(1, &idDesc.fInfo.fID)); |
1151 return return_null_texture(); | 1174 return return_null_texture(); |
1152 } | 1175 } |
1153 | 1176 |
1154 GrGLTexture* tex; | 1177 GrGLTexture* tex; |
1155 if (renderTarget) { | 1178 if (renderTarget) { |
1156 // unbind the texture from the texture unit before binding it to the fra
me buffer | 1179 // unbind the texture from the texture unit before binding it to the fra
me buffer |
1157 GL_CALL(BindTexture(idDesc.fInfo.fTarget, 0)); | 1180 GL_CALL(BindTexture(idDesc.fInfo.fTarget, 0)); |
(...skipping 2398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3556 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || | 3579 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || |
3557 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { | 3580 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { |
3558 copyParams->fFilter = GrTextureParams::kNone_FilterMode; | 3581 copyParams->fFilter = GrTextureParams::kNone_FilterMode; |
3559 copyParams->fWidth = texture->width(); | 3582 copyParams->fWidth = texture->width(); |
3560 copyParams->fHeight = texture->height(); | 3583 copyParams->fHeight = texture->height(); |
3561 return true; | 3584 return true; |
3562 } | 3585 } |
3563 } | 3586 } |
3564 return false; | 3587 return false; |
3565 } | 3588 } |
OLD | NEW |