Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: src/gpu/gl/GrGLGpu.cpp

Issue 1623653002: skia: Add support for CHROMIUM_image backed textures. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Minor cleanup. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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
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
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 (!this->createTextureImpl(desc, &idDesc.fInfo, renderTarget, srcData,
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
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 return this->createTextureExternalAllocatorImpl(desc, info, srcData, row Bytes);
1363 }
1364
1365 info->fID = 0;
1366 info->fTarget = GR_GL_TEXTURE_2D;
1367 GL_CALL(GenTextures(1, &(info->fID)));
1368
1369 if (!info->fID) {
1370 return false;
1371 }
1372
1373 this->setScratchTextureUnit();
1374 GL_CALL(BindTexture(info->fTarget, info->fID));
1375
1376 if (renderTarget && this->glCaps().textureUsageSupport()) {
1377 // provides a hint about how this texture will be used
1378 GL_CALL(TexParameteri(info->fTarget,
1379 GR_GL_TEXTURE_USAGE,
1380 GR_GL_FRAMEBUFFER_ATTACHMENT));
1381 }
1382
1383 GL_CALL(TexParameteri(info->fTarget,
1384 GR_GL_TEXTURE_MAG_FILTER,
1385 initialTexParams->fMagFilter));
1386 GL_CALL(TexParameteri(info->fTarget,
1387 GR_GL_TEXTURE_MIN_FILTER,
1388 initialTexParams->fMinFilter));
1389 GL_CALL(TexParameteri(info->fTarget,
1390 GR_GL_TEXTURE_WRAP_S,
1391 initialTexParams->fWrapS));
1392 GL_CALL(TexParameteri(info->fTarget,
1393 GR_GL_TEXTURE_WRAP_T,
1394 initialTexParams->fWrapT));
1395 if (!this->uploadTexData(desc, info, kNewTexture_UploadType, 0, 0,
1396 desc.fWidth, desc.fHeight,
1397 desc.fConfig, srcData, rowBytes)) {
1398 GL_CALL(DeleteTextures(1, &(info->fID)));
1399 return false;
1400 }
1401 return true;
1402 }
1403
1404 bool GrGLGpu::createTextureExternalAllocatorImpl(
1405 const GrSurfaceDesc& desc, GrGLTextureInfo* info, const void* srcData, s ize_t rowBytes) {
1406 if (!desc.fTextureStorageAllocator->supportsPixelConfig(desc.fConfig)) {
1407 return false;
1408 }
1409 if (!desc.fTextureStorageAllocator->allocateTextureStorage(
1410 reinterpret_cast<GrBackendObject>(info), desc.fWidth, desc.fHeight)) {
1411 return false;
1412 }
1413
1414 if (!this->uploadTexData(desc, info, kNewTexture_UploadType, 0, 0,
1415 desc.fWidth, desc.fHeight,
1416 desc.fConfig, srcData, rowBytes)) {
1417 desc.fTextureStorageAllocator->deallocateTextureStorage(
1418 reinterpret_cast<GrBackendObject>(info));
1419 return false;
1420 }
1421 return true;
1422 }
1423
1373 GrStencilAttachment* GrGLGpu::createStencilAttachmentForRenderTarget(const GrRen derTarget* rt, 1424 GrStencilAttachment* GrGLGpu::createStencilAttachmentForRenderTarget(const GrRen derTarget* rt,
1374 int width, 1425 int width,
1375 int height) { 1426 int height) {
1376 // All internally created RTs are also textures. We don't create 1427 // 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) . 1428 // SBs for a client's standalone RT (that is a RT that isn't also a texture) .
1378 SkASSERT(rt->asTexture()); 1429 SkASSERT(rt->asTexture());
1379 SkASSERT(width >= rt->width()); 1430 SkASSERT(width >= rt->width());
1380 SkASSERT(height >= rt->height()); 1431 SkASSERT(height >= rt->height());
1381 1432
1382 int samples = rt->numStencilSamples(); 1433 int samples = rt->numStencilSamples();
(...skipping 2173 matching lines...) Expand 10 before | Expand all | Expand 10 after
3556 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || 3607 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() ||
3557 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { 3608 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) {
3558 copyParams->fFilter = GrTextureParams::kNone_FilterMode; 3609 copyParams->fFilter = GrTextureParams::kNone_FilterMode;
3559 copyParams->fWidth = texture->width(); 3610 copyParams->fWidth = texture->width();
3560 copyParams->fHeight = texture->height(); 3611 copyParams->fHeight = texture->height();
3561 return true; 3612 return true;
3562 } 3613 }
3563 } 3614 }
3564 return false; 3615 return false;
3565 } 3616 }
OLDNEW
« src/gpu/SkGpuDevice.h ('K') | « src/gpu/gl/GrGLGpu.h ('k') | src/gpu/gl/GrGLTexture.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698