| 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 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_TRUE)); | 819 GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_TRUE)); |
| 820 } | 820 } |
| 821 GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, config_alignment(dataConfig)
)); | 821 GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, config_alignment(dataConfig)
)); |
| 822 } | 822 } |
| 823 bool succeeded = true; | 823 bool succeeded = true; |
| 824 if (kNewTexture_UploadType == uploadType) { | 824 if (kNewTexture_UploadType == uploadType) { |
| 825 if (dataOrOffset && | 825 if (dataOrOffset && |
| 826 !(0 == left && 0 == top && desc.fWidth == width && desc.fHeight == h
eight)) { | 826 !(0 == left && 0 == top && desc.fWidth == width && desc.fHeight == h
eight)) { |
| 827 succeeded = false; | 827 succeeded = false; |
| 828 } else { | 828 } else { |
| 829 if (desc.fTextureStorageAllocator.fAllocateTextureStorage) { | 829 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
| 830 if (dataOrOffset) { | 830 GL_ALLOC_CALL(this->glInterface(), TexImage2D(target, 0, internalFor
mat, desc.fWidth, |
| 831 GL_CALL(TexSubImage2D(target, | 831 desc.fHeight, 0, exter
nalFormat, |
| 832 0, // level | 832 externalType, dataOrOf
fset)); |
| 833 left, top, | 833 GrGLenum error = check_alloc_error(desc, this->glInterface()); |
| 834 width, height, | 834 if (error != GR_GL_NO_ERROR) { |
| 835 externalFormat, externalType, dataOrOf
fset)); | 835 succeeded = false; |
| 836 } | 836 } |
| 837 } else {
| |
| 838 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface());
| |
| 839 GL_ALLOC_CALL(this->glInterface(), TexImage2D(
| |
| 840 target, 0, internalFormat, desc.fWidth, desc.fHeight, 0, ext
ernalFormat, | |
| 841 externalType, dataOrOffset));
| |
| 842 GrGLenum error = check_alloc_error(desc, this->glInterface()); | |
| 843 if (error != GR_GL_NO_ERROR) {
| |
| 844 succeeded = false;
| |
| 845 } | |
| 846 } | |
| 847 } | 837 } |
| 848 } else { | 838 } else { |
| 849 if (swFlipY || glFlipY) { | 839 if (swFlipY || glFlipY) { |
| 850 top = desc.fHeight - (top + height); | 840 top = desc.fHeight - (top + height); |
| 851 } | 841 } |
| 852 GL_CALL(TexSubImage2D(target, | 842 GL_CALL(TexSubImage2D(target, |
| 853 0, // level | 843 0, // level |
| 854 left, top, | 844 left, top, |
| 855 width, height, | 845 width, height, |
| 856 externalFormat, externalType, dataOrOffset)); | 846 externalFormat, externalType, dataOrOffset)); |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1105 const void* srcData, size_t rowBytes) { | 1095 const void* srcData, size_t rowBytes) { |
| 1106 // We fail if the MSAA was requested and is not available. | 1096 // We fail if the MSAA was requested and is not available. |
| 1107 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleC
nt) { | 1097 if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleC
nt) { |
| 1108 //SkDebugf("MSAA RT requested but not supported on this platform."); | 1098 //SkDebugf("MSAA RT requested but not supported on this platform."); |
| 1109 return return_null_texture(); | 1099 return return_null_texture(); |
| 1110 } | 1100 } |
| 1111 | 1101 |
| 1112 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); | 1102 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); |
| 1113 | 1103 |
| 1114 GrGLTexture::IDDesc idDesc; | 1104 GrGLTexture::IDDesc idDesc; |
| 1105 idDesc.fInfo.fID = 0; |
| 1106 GL_CALL(GenTextures(1, &idDesc.fInfo.fID)); |
| 1115 idDesc.fLifeCycle = lifeCycle; | 1107 idDesc.fLifeCycle = lifeCycle; |
| 1116 GrGLTexture::TexParams initialTexParams; | 1108 // We only support GL_TEXTURE_2D at the moment. |
| 1117 if (!this->createTextureImpl(desc, &idDesc.fInfo, renderTarget, srcData, | 1109 idDesc.fInfo.fTarget = GR_GL_TEXTURE_2D; |
| 1118 &initialTexParams, rowBytes)) { | 1110 |
| 1111 if (!idDesc.fInfo.fID) { |
| 1119 return return_null_texture(); | 1112 return return_null_texture(); |
| 1120 } | 1113 } |
| 1121 | 1114 |
| 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 |
| 1122 GrGLTexture* tex; | 1154 GrGLTexture* tex; |
| 1123 if (renderTarget) { | 1155 if (renderTarget) { |
| 1124 // unbind the texture from the texture unit before binding it to the fra
me buffer | 1156 // unbind the texture from the texture unit before binding it to the fra
me buffer |
| 1125 GL_CALL(BindTexture(idDesc.fInfo.fTarget, 0)); | 1157 GL_CALL(BindTexture(idDesc.fInfo.fTarget, 0)); |
| 1126 GrGLRenderTarget::IDDesc rtIDDesc; | 1158 GrGLRenderTarget::IDDesc rtIDDesc; |
| 1127 | 1159 |
| 1128 if (!this->createRenderTargetObjects(desc, lifeCycle, idDesc.fInfo, &rtI
DDesc)) { | 1160 if (!this->createRenderTargetObjects(desc, lifeCycle, idDesc.fInfo, &rtI
DDesc)) { |
| 1129 GL_CALL(DeleteTextures(1, &idDesc.fInfo.fID)); | 1161 GL_CALL(DeleteTextures(1, &idDesc.fInfo.fID)); |
| 1130 return return_null_texture(); | 1162 return return_null_texture(); |
| 1131 } | 1163 } |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1331 GL_CALL(DeleteRenderbuffers(1, &sbRBID)); | 1363 GL_CALL(DeleteRenderbuffers(1, &sbRBID)); |
| 1332 } | 1364 } |
| 1333 GL_CALL(DeleteTextures(1, &colorID)); | 1365 GL_CALL(DeleteTextures(1, &colorID)); |
| 1334 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, 0)); | 1366 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, 0)); |
| 1335 GL_CALL(DeleteFramebuffers(1, &fb)); | 1367 GL_CALL(DeleteFramebuffers(1, &fb)); |
| 1336 fGLContext->caps()->setStencilFormatIndexForConfig(config, firstWorkingS
tencilFormatIndex); | 1368 fGLContext->caps()->setStencilFormatIndexForConfig(config, firstWorkingS
tencilFormatIndex); |
| 1337 } | 1369 } |
| 1338 return this->glCaps().getStencilFormatIndexForConfig(config); | 1370 return this->glCaps().getStencilFormatIndexForConfig(config); |
| 1339 } | 1371 } |
| 1340 | 1372 |
| 1341 bool GrGLGpu::createTextureImpl(const GrSurfaceDesc& desc, GrGLTextureInfo* info
, | |
| 1342 bool renderTarget, const void* srcData, | |
| 1343 GrGLTexture::TexParams* initialTexParams, size_t
rowBytes) { | |
| 1344 // Some drivers like to know filter/wrap before seeing glTexImage2D. Some | |
| 1345 // drivers have a bug where an FBO won't be complete if it includes a | |
| 1346 // texture that is not mipmap complete (considering the filter in use). | |
| 1347 | |
| 1348 // we only set a subset here so invalidate first | |
| 1349 initialTexParams->invalidate(); | |
| 1350 initialTexParams->fMinFilter = GR_GL_NEAREST; | |
| 1351 initialTexParams->fMagFilter = GR_GL_NEAREST; | |
| 1352 initialTexParams->fWrapS = GR_GL_CLAMP_TO_EDGE; | |
| 1353 initialTexParams->fWrapT = GR_GL_CLAMP_TO_EDGE; | |
| 1354 | |
| 1355 if (desc.fTextureStorageAllocator.fAllocateTextureStorage) { | |
| 1356 return this->createTextureExternalAllocatorImpl(desc, info, srcData, row
Bytes); | |
| 1357 } | |
| 1358 | |
| 1359 info->fID = 0; | |
| 1360 info->fTarget = GR_GL_TEXTURE_2D; | |
| 1361 GL_CALL(GenTextures(1, &(info->fID))); | |
| 1362 | |
| 1363 if (!info->fID) { | |
| 1364 return false; | |
| 1365 } | |
| 1366 | |
| 1367 this->setScratchTextureUnit(); | |
| 1368 GL_CALL(BindTexture(info->fTarget, info->fID)); | |
| 1369 | |
| 1370 if (renderTarget && this->glCaps().textureUsageSupport()) { | |
| 1371 // provides a hint about how this texture will be used | |
| 1372 GL_CALL(TexParameteri(info->fTarget, | |
| 1373 GR_GL_TEXTURE_USAGE, | |
| 1374 GR_GL_FRAMEBUFFER_ATTACHMENT)); | |
| 1375 } | |
| 1376 | |
| 1377 GL_CALL(TexParameteri(info->fTarget, | |
| 1378 GR_GL_TEXTURE_MAG_FILTER, | |
| 1379 initialTexParams->fMagFilter)); | |
| 1380 GL_CALL(TexParameteri(info->fTarget, | |
| 1381 GR_GL_TEXTURE_MIN_FILTER, | |
| 1382 initialTexParams->fMinFilter)); | |
| 1383 GL_CALL(TexParameteri(info->fTarget, | |
| 1384 GR_GL_TEXTURE_WRAP_S, | |
| 1385 initialTexParams->fWrapS)); | |
| 1386 GL_CALL(TexParameteri(info->fTarget, | |
| 1387 GR_GL_TEXTURE_WRAP_T, | |
| 1388 initialTexParams->fWrapT)); | |
| 1389 if (!this->uploadTexData(desc, info->fTarget, kNewTexture_UploadType, 0, 0, | |
| 1390 desc.fWidth, desc.fHeight, | |
| 1391 desc.fConfig, srcData, rowBytes)) { | |
| 1392 GL_CALL(DeleteTextures(1, &(info->fID))); | |
| 1393 return false; | |
| 1394 } | |
| 1395 return true; | |
| 1396 } | |
| 1397 | |
| 1398 bool GrGLGpu::createTextureExternalAllocatorImpl( | |
| 1399 const GrSurfaceDesc& desc, GrGLTextureInfo* info, const void* srcData, s
ize_t rowBytes) { | |
| 1400 switch (desc.fTextureStorageAllocator.fAllocateTextureStorage( | |
| 1401 desc.fTextureStorageAllocator.fCtx, reinterpret_cast<GrBacke
ndObject>(info), | |
| 1402 desc.fWidth, desc.fHeight, desc.fConfig, srcData, desc.fOrig
in)) { | |
| 1403 case GrTextureStorageAllocator::Result::kSucceededAndUploaded: | |
| 1404 return true; | |
| 1405 case GrTextureStorageAllocator::Result::kFailed: | |
| 1406 return false; | |
| 1407 case GrTextureStorageAllocator::Result::kSucceededWithoutUpload: | |
| 1408 break; | |
| 1409 } | |
| 1410 | |
| 1411 if (!this->uploadTexData(desc, info->fTarget, kNewTexture_UploadType, 0, 0, | |
| 1412 desc.fWidth, desc.fHeight, | |
| 1413 desc.fConfig, srcData, rowBytes)) { | |
| 1414 desc.fTextureStorageAllocator.fDeallocateTextureStorage( | |
| 1415 desc.fTextureStorageAllocator.fCtx, reinterpret_cast<GrBackendOb
ject>(info)); | |
| 1416 return false; | |
| 1417 } | |
| 1418 return true; | |
| 1419 } | |
| 1420 | |
| 1421 GrStencilAttachment* GrGLGpu::createStencilAttachmentForRenderTarget(const GrRen
derTarget* rt, | 1373 GrStencilAttachment* GrGLGpu::createStencilAttachmentForRenderTarget(const GrRen
derTarget* rt, |
| 1422 int width, | 1374 int width, |
| 1423 int height)
{ | 1375 int height)
{ |
| 1424 // All internally created RTs are also textures. We don't create | 1376 // All internally created RTs are also textures. We don't create |
| 1425 // SBs for a client's standalone RT (that is a RT that isn't also a texture)
. | 1377 // SBs for a client's standalone RT (that is a RT that isn't also a texture)
. |
| 1426 SkASSERT(rt->asTexture()); | 1378 SkASSERT(rt->asTexture()); |
| 1427 SkASSERT(width >= rt->width()); | 1379 SkASSERT(width >= rt->width()); |
| 1428 SkASSERT(height >= rt->height()); | 1380 SkASSERT(height >= rt->height()); |
| 1429 | 1381 |
| 1430 int samples = rt->numStencilSamples(); | 1382 int samples = rt->numStencilSamples(); |
| (...skipping 2173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3604 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || | 3556 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || |
| 3605 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { | 3557 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { |
| 3606 copyParams->fFilter = GrTextureParams::kNone_FilterMode; | 3558 copyParams->fFilter = GrTextureParams::kNone_FilterMode; |
| 3607 copyParams->fWidth = texture->width(); | 3559 copyParams->fWidth = texture->width(); |
| 3608 copyParams->fHeight = texture->height(); | 3560 copyParams->fHeight = texture->height(); |
| 3609 return true; | 3561 return true; |
| 3610 } | 3562 } |
| 3611 } | 3563 } |
| 3612 return false; | 3564 return false; |
| 3613 } | 3565 } |
| OLD | NEW |