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 #include "GrGLGpu.h" | 8 #include "GrGLGpu.h" |
9 #include "GrGLBuffer.h" | 9 #include "GrGLBuffer.h" |
10 #include "GrGLGLSL.h" | 10 #include "GrGLGLSL.h" |
(...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
986 * @param baseWidth The width of the texture's base mipmap level | 986 * @param baseWidth The width of the texture's base mipmap level |
987 * @param baseHeight The height of the texture's base mipmap level | 987 * @param baseHeight The height of the texture's base mipmap level |
988 * @param succeeded Set to true if allocating and populating the texture co mpleted | 988 * @param succeeded Set to true if allocating and populating the texture co mpleted |
989 * without error. | 989 * without error. |
990 */ | 990 */ |
991 static bool allocate_and_populate_uncompressed_texture(const GrSurfaceDesc& desc , | 991 static bool allocate_and_populate_uncompressed_texture(const GrSurfaceDesc& desc , |
992 const GrGLInterface& inte rface, | 992 const GrGLInterface& inte rface, |
993 const GrGLCaps& caps, | 993 const GrGLCaps& caps, |
994 GrGLenum target, | 994 GrGLenum target, |
995 GrGLenum internalFormat, | 995 GrGLenum internalFormat, |
996 GrGLenum sizedInternalFor mat, | |
Brian Osman
2016/09/12 15:08:17
FWIW: Don't think we need to change allocate_and_p
bsalomon
2016/09/12 15:14:54
My only hesitation here is that calling this sized
| |
996 GrGLenum externalFormat, | 997 GrGLenum externalFormat, |
997 GrGLenum externalType, | 998 GrGLenum externalType, |
998 const SkTArray<GrMipLevel >& texels, | 999 const SkTArray<GrMipLevel >& texels, |
999 int baseWidth, int baseHe ight) { | 1000 int baseWidth, int baseHe ight) { |
1000 CLEAR_ERROR_BEFORE_ALLOC(&interface); | 1001 CLEAR_ERROR_BEFORE_ALLOC(&interface); |
1001 | 1002 |
1002 bool useTexStorage = caps.isConfigTexSupportEnabled(desc.fConfig); | 1003 bool useTexStorage = caps.isConfigTexSupportEnabled(desc.fConfig); |
1003 // We can only use TexStorage if we know we will not later change the storag e requirements. | 1004 // We can only use TexStorage if we know we will not later change the storag e requirements. |
1004 // This means if we may later want to add mipmaps, we cannot use TexStorage. | 1005 // This means if we may later want to add mipmaps, we cannot use TexStorage. |
1005 // Right now, we cannot know if we will later add mipmaps or not. | 1006 // Right now, we cannot know if we will later add mipmaps or not. |
1006 // The only time we can use TexStorage is when we already have the | 1007 // The only time we can use TexStorage is when we already have the |
1007 // mipmaps. | 1008 // mipmaps. |
1008 useTexStorage &= texels.count() > 1; | 1009 useTexStorage &= texels.count() > 1; |
1009 | 1010 |
1010 if (useTexStorage) { | 1011 if (useTexStorage) { |
1011 // We never resize or change formats of textures. | 1012 // We never resize or change formats of textures. |
1012 GL_ALLOC_CALL(&interface, | 1013 GL_ALLOC_CALL(&interface, |
1013 TexStorage2D(target, | 1014 TexStorage2D(target, |
1014 texels.count(), | 1015 texels.count(), |
1015 internalFormat, | 1016 sizedInternalFormat, |
1016 desc.fWidth, desc.fHeight)); | 1017 desc.fWidth, desc.fHeight)); |
1017 GrGLenum error = check_alloc_error(desc, &interface); | 1018 GrGLenum error = check_alloc_error(desc, &interface); |
1018 if (error != GR_GL_NO_ERROR) { | 1019 if (error != GR_GL_NO_ERROR) { |
1019 return false; | 1020 return false; |
1020 } else { | 1021 } else { |
1021 for (int currentMipLevel = 0; currentMipLevel < texels.count(); curr entMipLevel++) { | 1022 for (int currentMipLevel = 0; currentMipLevel < texels.count(); curr entMipLevel++) { |
1022 const void* currentMipData = texels[currentMipLevel].fPixels; | 1023 const void* currentMipData = texels[currentMipLevel].fPixels; |
1023 if (currentMipData == nullptr) { | 1024 if (currentMipData == nullptr) { |
1024 continue; | 1025 continue; |
1025 } | 1026 } |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1247 | 1248 |
1248 // Internal format comes from the texture desc. | 1249 // Internal format comes from the texture desc. |
1249 GrGLenum internalFormat; | 1250 GrGLenum internalFormat; |
1250 // External format and type come from the upload data. | 1251 // External format and type come from the upload data. |
1251 GrGLenum externalFormat; | 1252 GrGLenum externalFormat; |
1252 GrGLenum externalType; | 1253 GrGLenum externalType; |
1253 if (!this->glCaps().getTexImageFormats(desc.fConfig, dataConfig, &internalFo rmat, | 1254 if (!this->glCaps().getTexImageFormats(desc.fConfig, dataConfig, &internalFo rmat, |
1254 &externalFormat, &externalType)) { | 1255 &externalFormat, &externalType)) { |
1255 return false; | 1256 return false; |
1256 } | 1257 } |
1258 GrGLenum sizedInternalFormat = this->glCaps().configSizedInternalFormat(desc .fConfig); | |
1259 | |
1257 /* | 1260 /* |
1258 * Check whether to allocate a temporary buffer for flipping y or | 1261 * Check whether to allocate a temporary buffer for flipping y or |
1259 * because our srcData has extra bytes past each row. If so, we need | 1262 * because our srcData has extra bytes past each row. If so, we need |
1260 * to trim those off here, since GL ES may not let us specify | 1263 * to trim those off here, since GL ES may not let us specify |
1261 * GL_UNPACK_ROW_LENGTH. | 1264 * GL_UNPACK_ROW_LENGTH. |
1262 */ | 1265 */ |
1263 bool restoreGLRowLength = false; | 1266 bool restoreGLRowLength = false; |
1264 bool swFlipY = false; | 1267 bool swFlipY = false; |
1265 bool glFlipY = false; | 1268 bool glFlipY = false; |
1266 | 1269 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1349 } | 1352 } |
1350 GR_GL_CALL(interface, PixelStorei(GR_GL_UNPACK_ALIGNMENT, | 1353 GR_GL_CALL(interface, PixelStorei(GR_GL_UNPACK_ALIGNMENT, |
1351 config_alignment(desc.fConfig))); | 1354 config_alignment(desc.fConfig))); |
1352 } | 1355 } |
1353 | 1356 |
1354 bool succeeded = true; | 1357 bool succeeded = true; |
1355 if (kNewTexture_UploadType == uploadType && | 1358 if (kNewTexture_UploadType == uploadType && |
1356 0 == left && 0 == top && | 1359 0 == left && 0 == top && |
1357 desc.fWidth == width && desc.fHeight == height) { | 1360 desc.fWidth == width && desc.fHeight == height) { |
1358 succeeded = allocate_and_populate_uncompressed_texture(desc, *interface, caps, target, | 1361 succeeded = allocate_and_populate_uncompressed_texture(desc, *interface, caps, target, |
1359 internalFormat, e xternalFormat, | 1362 internalFormat, s izedInternalFormat, |
1360 externalType, tex elsShallowCopy, | 1363 externalFormat, e xternalType, |
1361 width, height); | 1364 texelsShallowCopy , width, height); |
1362 } else { | 1365 } else { |
1363 if (swFlipY || glFlipY) { | 1366 if (swFlipY || glFlipY) { |
1364 top = desc.fHeight - (top + height); | 1367 top = desc.fHeight - (top + height); |
1365 } | 1368 } |
1366 for (int currentMipLevel = 0; currentMipLevel < texelsShallowCopy.count( ); | 1369 for (int currentMipLevel = 0; currentMipLevel < texelsShallowCopy.count( ); |
1367 currentMipLevel++) { | 1370 currentMipLevel++) { |
1368 int twoToTheMipLevel = 1 << currentMipLevel; | 1371 int twoToTheMipLevel = 1 << currentMipLevel; |
1369 int currentWidth = SkTMax(1, width / twoToTheMipLevel); | 1372 int currentWidth = SkTMax(1, width / twoToTheMipLevel); |
1370 int currentHeight = SkTMax(1, height / twoToTheMipLevel); | 1373 int currentHeight = SkTMax(1, height / twoToTheMipLevel); |
1371 | 1374 |
(...skipping 3300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4672 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || | 4675 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || |
4673 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { | 4676 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { |
4674 copyParams->fFilter = GrTextureParams::kNone_FilterMode; | 4677 copyParams->fFilter = GrTextureParams::kNone_FilterMode; |
4675 copyParams->fWidth = texture->width(); | 4678 copyParams->fWidth = texture->width(); |
4676 copyParams->fHeight = texture->height(); | 4679 copyParams->fHeight = texture->height(); |
4677 return true; | 4680 return true; |
4678 } | 4681 } |
4679 } | 4682 } |
4680 return false; | 4683 return false; |
4681 } | 4684 } |
OLD | NEW |