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 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 return CHECK_ALLOC_ERROR(interface); | 972 return CHECK_ALLOC_ERROR(interface); |
973 } | 973 } |
974 } | 974 } |
975 | 975 |
976 /** | 976 /** |
977 * Creates storage space for the texture and fills it with texels. | 977 * Creates storage space for the texture and fills it with texels. |
978 * | 978 * |
979 * @param desc The surface descriptor for the texture being created. | 979 * @param desc The surface descriptor for the texture being created. |
980 * @param interface The GL interface in use. | 980 * @param interface The GL interface in use. |
981 * @param caps The capabilities of the GL device. | 981 * @param caps The capabilities of the GL device. |
982 * @param internalFormat The data format used for the internal storage of the te
xture. | 982 * @param internalFormat The data format used for the internal storage of the te
xture. May be sized. |
| 983 * @param internalFormatForTexStorage The data format used for the TexStorage AP
I. Must be sized. |
983 * @param externalFormat The data format used for the external storage of the te
xture. | 984 * @param externalFormat The data format used for the external storage of the te
xture. |
984 * @param externalType The type of the data used for the external storage of t
he texture. | 985 * @param externalType The type of the data used for the external storage of t
he texture. |
985 * @param texels The texel data of the texture being created. | 986 * @param texels The texel data of the texture being created. |
986 * @param baseWidth The width of the texture's base mipmap level | 987 * @param baseWidth The width of the texture's base mipmap level |
987 * @param baseHeight The height of the texture's base mipmap level | 988 * @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 | 989 * @param succeeded Set to true if allocating and populating the texture co
mpleted |
989 * without error. | 990 * without error. |
990 */ | 991 */ |
991 static bool allocate_and_populate_uncompressed_texture(const GrSurfaceDesc& desc
, | 992 static bool allocate_and_populate_uncompressed_texture(const GrSurfaceDesc& desc
, |
992 const GrGLInterface& inte
rface, | 993 const GrGLInterface& inte
rface, |
993 const GrGLCaps& caps, | 994 const GrGLCaps& caps, |
994 GrGLenum target, | 995 GrGLenum target, |
995 GrGLenum internalFormat, | 996 GrGLenum internalFormat, |
| 997 GrGLenum internalFormatFo
rTexStorage, |
996 GrGLenum externalFormat, | 998 GrGLenum externalFormat, |
997 GrGLenum externalType, | 999 GrGLenum externalType, |
998 const SkTArray<GrMipLevel
>& texels, | 1000 const SkTArray<GrMipLevel
>& texels, |
999 int baseWidth, int baseHe
ight) { | 1001 int baseWidth, int baseHe
ight) { |
1000 CLEAR_ERROR_BEFORE_ALLOC(&interface); | 1002 CLEAR_ERROR_BEFORE_ALLOC(&interface); |
1001 | 1003 |
1002 bool useTexStorage = caps.isConfigTexSupportEnabled(desc.fConfig); | 1004 bool useTexStorage = caps.isConfigTexSupportEnabled(desc.fConfig); |
1003 // We can only use TexStorage if we know we will not later change the storag
e requirements. | 1005 // 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. | 1006 // 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. | 1007 // 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 | 1008 // The only time we can use TexStorage is when we already have the |
1007 // mipmaps. | 1009 // mipmaps. |
1008 useTexStorage &= texels.count() > 1; | 1010 useTexStorage &= texels.count() > 1; |
1009 | 1011 |
1010 if (useTexStorage) { | 1012 if (useTexStorage) { |
1011 // We never resize or change formats of textures. | 1013 // We never resize or change formats of textures. |
1012 GL_ALLOC_CALL(&interface, | 1014 GL_ALLOC_CALL(&interface, |
1013 TexStorage2D(target, | 1015 TexStorage2D(target, |
1014 texels.count(), | 1016 texels.count(), |
1015 internalFormat, | 1017 internalFormatForTexStorage, |
1016 desc.fWidth, desc.fHeight)); | 1018 desc.fWidth, desc.fHeight)); |
1017 GrGLenum error = check_alloc_error(desc, &interface); | 1019 GrGLenum error = check_alloc_error(desc, &interface); |
1018 if (error != GR_GL_NO_ERROR) { | 1020 if (error != GR_GL_NO_ERROR) { |
1019 return false; | 1021 return false; |
1020 } else { | 1022 } else { |
1021 for (int currentMipLevel = 0; currentMipLevel < texels.count(); curr
entMipLevel++) { | 1023 for (int currentMipLevel = 0; currentMipLevel < texels.count(); curr
entMipLevel++) { |
1022 const void* currentMipData = texels[currentMipLevel].fPixels; | 1024 const void* currentMipData = texels[currentMipLevel].fPixels; |
1023 if (currentMipData == nullptr) { | 1025 if (currentMipData == nullptr) { |
1024 continue; | 1026 continue; |
1025 } | 1027 } |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1247 | 1249 |
1248 // Internal format comes from the texture desc. | 1250 // Internal format comes from the texture desc. |
1249 GrGLenum internalFormat; | 1251 GrGLenum internalFormat; |
1250 // External format and type come from the upload data. | 1252 // External format and type come from the upload data. |
1251 GrGLenum externalFormat; | 1253 GrGLenum externalFormat; |
1252 GrGLenum externalType; | 1254 GrGLenum externalType; |
1253 if (!this->glCaps().getTexImageFormats(desc.fConfig, dataConfig, &internalFo
rmat, | 1255 if (!this->glCaps().getTexImageFormats(desc.fConfig, dataConfig, &internalFo
rmat, |
1254 &externalFormat, &externalType)) { | 1256 &externalFormat, &externalType)) { |
1255 return false; | 1257 return false; |
1256 } | 1258 } |
| 1259 // TexStorage requires a sized format, and internalFormat may or may not be |
| 1260 GrGLenum internalFormatForTexStorage = this->glCaps().configSizedInternalFor
mat(desc.fConfig); |
| 1261 |
1257 /* | 1262 /* |
1258 * Check whether to allocate a temporary buffer for flipping y or | 1263 * 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 | 1264 * 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 | 1265 * to trim those off here, since GL ES may not let us specify |
1261 * GL_UNPACK_ROW_LENGTH. | 1266 * GL_UNPACK_ROW_LENGTH. |
1262 */ | 1267 */ |
1263 bool restoreGLRowLength = false; | 1268 bool restoreGLRowLength = false; |
1264 bool swFlipY = false; | 1269 bool swFlipY = false; |
1265 bool glFlipY = false; | 1270 bool glFlipY = false; |
1266 | 1271 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1349 } | 1354 } |
1350 GR_GL_CALL(interface, PixelStorei(GR_GL_UNPACK_ALIGNMENT, | 1355 GR_GL_CALL(interface, PixelStorei(GR_GL_UNPACK_ALIGNMENT, |
1351 config_alignment(desc.fConfig))); | 1356 config_alignment(desc.fConfig))); |
1352 } | 1357 } |
1353 | 1358 |
1354 bool succeeded = true; | 1359 bool succeeded = true; |
1355 if (kNewTexture_UploadType == uploadType && | 1360 if (kNewTexture_UploadType == uploadType && |
1356 0 == left && 0 == top && | 1361 0 == left && 0 == top && |
1357 desc.fWidth == width && desc.fHeight == height) { | 1362 desc.fWidth == width && desc.fHeight == height) { |
1358 succeeded = allocate_and_populate_uncompressed_texture(desc, *interface,
caps, target, | 1363 succeeded = allocate_and_populate_uncompressed_texture(desc, *interface,
caps, target, |
1359 internalFormat, e
xternalFormat, | 1364 internalFormat, |
1360 externalType, tex
elsShallowCopy, | 1365 internalFormatFor
TexStorage, |
1361 width, height); | 1366 externalFormat, e
xternalType, |
| 1367 texelsShallowCopy
, width, height); |
1362 } else { | 1368 } else { |
1363 if (swFlipY || glFlipY) { | 1369 if (swFlipY || glFlipY) { |
1364 top = desc.fHeight - (top + height); | 1370 top = desc.fHeight - (top + height); |
1365 } | 1371 } |
1366 for (int currentMipLevel = 0; currentMipLevel < texelsShallowCopy.count(
); | 1372 for (int currentMipLevel = 0; currentMipLevel < texelsShallowCopy.count(
); |
1367 currentMipLevel++) { | 1373 currentMipLevel++) { |
1368 int twoToTheMipLevel = 1 << currentMipLevel; | 1374 int twoToTheMipLevel = 1 << currentMipLevel; |
1369 int currentWidth = SkTMax(1, width / twoToTheMipLevel); | 1375 int currentWidth = SkTMax(1, width / twoToTheMipLevel); |
1370 int currentHeight = SkTMax(1, height / twoToTheMipLevel); | 1376 int currentHeight = SkTMax(1, height / twoToTheMipLevel); |
1371 | 1377 |
(...skipping 3300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4672 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || | 4678 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || |
4673 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { | 4679 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { |
4674 copyParams->fFilter = GrTextureParams::kNone_FilterMode; | 4680 copyParams->fFilter = GrTextureParams::kNone_FilterMode; |
4675 copyParams->fWidth = texture->width(); | 4681 copyParams->fWidth = texture->width(); |
4676 copyParams->fHeight = texture->height(); | 4682 copyParams->fHeight = texture->height(); |
4677 return true; | 4683 return true; |
4678 } | 4684 } |
4679 } | 4685 } |
4680 return false; | 4686 return false; |
4681 } | 4687 } |
OLD | NEW |