Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| (...skipping 1242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1253 unsigned target, | 1253 unsigned target, |
| 1254 int level, | 1254 int level, |
| 1255 unsigned format, | 1255 unsigned format, |
| 1256 unsigned type, | 1256 unsigned type, |
| 1257 int xoffset, | 1257 int xoffset, |
| 1258 int yoffset, | 1258 int yoffset, |
| 1259 int width, | 1259 int width, |
| 1260 int height) override; | 1260 int height) override; |
| 1261 | 1261 |
| 1262 // overridden from GLES2Decoder | 1262 // overridden from GLES2Decoder |
| 1263 bool ClearCompressedTextureLevel(Texture* texture, | |
| 1264 unsigned target, | |
| 1265 int level, | |
| 1266 unsigned format, | |
| 1267 int width, | |
| 1268 int height) override; | |
| 1269 bool IsCompressedTextureFormat(unsigned format) override; | |
| 1270 | |
| 1271 // overridden from GLES2Decoder | |
| 1263 bool ClearLevel3D(Texture* texture, | 1272 bool ClearLevel3D(Texture* texture, |
| 1264 unsigned target, | 1273 unsigned target, |
| 1265 int level, | 1274 int level, |
| 1266 unsigned format, | 1275 unsigned format, |
| 1267 unsigned type, | 1276 unsigned type, |
| 1268 int width, | 1277 int width, |
| 1269 int height, | 1278 int height, |
| 1270 int depth) override; | 1279 int depth) override; |
| 1271 | 1280 |
| 1272 // Restore all GL state that affects clearing. | 1281 // Restore all GL state that affects clearing. |
| (...skipping 9245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10518 zero.get()); | 10527 zero.get()); |
| 10519 y += tile_height; | 10528 y += tile_height; |
| 10520 } | 10529 } |
| 10521 TextureRef* bound_texture = | 10530 TextureRef* bound_texture = |
| 10522 texture_manager()->GetTextureInfoForTarget(&state_, texture->target()); | 10531 texture_manager()->GetTextureInfoForTarget(&state_, texture->target()); |
| 10523 glBindTexture(texture->target(), | 10532 glBindTexture(texture->target(), |
| 10524 bound_texture ? bound_texture->service_id() : 0); | 10533 bound_texture ? bound_texture->service_id() : 0); |
| 10525 return true; | 10534 return true; |
| 10526 } | 10535 } |
| 10527 | 10536 |
| 10537 bool GLES2DecoderImpl::ClearCompressedTextureLevel(Texture* texture, | |
| 10538 unsigned target, | |
| 10539 int level, | |
| 10540 unsigned format, | |
| 10541 int width, | |
| 10542 int height) { | |
| 10543 DCHECK(target != GL_TEXTURE_3D && target != GL_TEXTURE_2D_ARRAY); | |
| 10544 // This code path can only be called if the texture was originally | |
| 10545 // allocated via TexStorage2D. Note that TexStorage2D is exposed | |
| 10546 // internally for ES 2.0 contexts, but compressed texture support is | |
| 10547 // not part of that exposure. | |
| 10548 DCHECK(feature_info_->IsES3Enabled()); | |
| 10549 | |
| 10550 GLsizei bytes_required = 0; | |
| 10551 if (!GetCompressedTexSizeInBytes( | |
| 10552 "ClearCompressedTextureLevel", width, height, 1, format, | |
| 10553 &bytes_required)) { | |
| 10554 return false; | |
| 10555 } | |
| 10556 | |
| 10557 TRACE_EVENT1("gpu", "GLES2DecoderImpl::ClearCompressedTextureLevel", | |
| 10558 "bytes_required", bytes_required); | |
| 10559 | |
| 10560 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); | |
| 10561 std::unique_ptr<char[]> zero(new char[bytes_required]); | |
| 10562 memset(zero.get(), 0, bytes_required); | |
| 10563 glBindTexture(texture->target(), texture->service_id()); | |
| 10564 glCompressedTexSubImage2D( | |
| 10565 target, level, 0, 0, width, height, format, bytes_required, zero.get()); | |
| 10566 TextureRef* bound_texture = | |
| 10567 texture_manager()->GetTextureInfoForTarget(&state_, texture->target()); | |
| 10568 glBindTexture(texture->target(), | |
| 10569 bound_texture ? bound_texture->service_id() : 0); | |
| 10570 Buffer* bound_buffer = buffer_manager()->GetBufferInfoForTarget( | |
| 10571 &state_, GL_PIXEL_UNPACK_BUFFER); | |
| 10572 if (bound_buffer) { | |
| 10573 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); | |
|
Zhenyao Mo
2016/04/29 17:15:16
This should be bound_buffer->service_id()
Ken Russell (switch to Gerrit)
2016/05/02 20:50:55
Thank you for catching that and apologies for not
| |
| 10574 } | |
| 10575 return true; | |
| 10576 } | |
| 10577 | |
| 10578 bool GLES2DecoderImpl::IsCompressedTextureFormat(unsigned format) { | |
| 10579 return feature_info_->validators()->compressed_texture_format.IsValid( | |
| 10580 format); | |
| 10581 } | |
| 10582 | |
| 10528 bool GLES2DecoderImpl::ClearLevel3D(Texture* texture, | 10583 bool GLES2DecoderImpl::ClearLevel3D(Texture* texture, |
| 10529 unsigned target, | 10584 unsigned target, |
| 10530 int level, | 10585 int level, |
| 10531 unsigned format, | 10586 unsigned format, |
| 10532 unsigned type, | 10587 unsigned type, |
| 10533 int width, | 10588 int width, |
| 10534 int height, | 10589 int height, |
| 10535 int depth) { | 10590 int depth) { |
| 10536 DCHECK(target == GL_TEXTURE_3D || target == GL_TEXTURE_2D_ARRAY); | 10591 DCHECK(target == GL_TEXTURE_3D || target == GL_TEXTURE_2D_ARRAY); |
| 10537 DCHECK(feature_info_->IsES3Enabled()); | 10592 DCHECK(feature_info_->IsES3Enabled()); |
| (...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11734 } | 11789 } |
| 11735 | 11790 |
| 11736 if (!ValidateCompressedTexFuncData("glCompressedTexSubImage2D", | 11791 if (!ValidateCompressedTexFuncData("glCompressedTexSubImage2D", |
| 11737 width, height, 1, format, image_size) || | 11792 width, height, 1, format, image_size) || |
| 11738 !ValidateCompressedTexSubDimensions("glCompressedTexSubImage2D", | 11793 !ValidateCompressedTexSubDimensions("glCompressedTexSubImage2D", |
| 11739 target, level, xoffset, yoffset, 0, | 11794 target, level, xoffset, yoffset, 0, |
| 11740 width, height, 1, format, texture)) { | 11795 width, height, 1, format, texture)) { |
| 11741 return; | 11796 return; |
| 11742 } | 11797 } |
| 11743 | 11798 |
| 11799 if (!texture->IsLevelCleared(target, level)) { | |
| 11800 // This can only happen if the compressed texture was allocated | |
| 11801 // using TexStorage2D. | |
| 11802 DCHECK(texture->IsImmutable()); | |
| 11803 GLsizei level_width = 0, level_height = 0; | |
| 11804 bool success = texture->GetLevelSize( | |
| 11805 target, level, &level_width, &level_height, nullptr); | |
| 11806 DCHECK(success); | |
| 11807 // We can skip the clear if we're uploading the entire level. | |
| 11808 if (xoffset == 0 && yoffset == 0 && | |
| 11809 width == level_width && height == level_height) { | |
| 11810 texture_manager()->SetLevelCleared(texture_ref, target, level, true); | |
| 11811 } else { | |
| 11812 texture_manager()->ClearTextureLevel(this, texture_ref, target, level); | |
| 11813 } | |
| 11814 DCHECK(texture->IsLevelCleared(target, level)); | |
| 11815 } | |
| 11744 | 11816 |
| 11745 // Note: There is no need to deal with texture cleared tracking here | |
| 11746 // because the validation above means you can only get here if the level | |
| 11747 // is already a matching compressed format and in that case | |
| 11748 // CompressedTexImage2D already cleared the texture. | |
| 11749 glCompressedTexSubImage2D( | 11817 glCompressedTexSubImage2D( |
| 11750 target, level, xoffset, yoffset, width, height, format, image_size, data); | 11818 target, level, xoffset, yoffset, width, height, format, image_size, data); |
| 11751 | 11819 |
| 11752 // This may be a slow command. Exit command processing to allow for | 11820 // This may be a slow command. Exit command processing to allow for |
| 11753 // context preemption and GPU watchdog checks. | 11821 // context preemption and GPU watchdog checks. |
| 11754 ExitCommandProcessingEarly(); | 11822 ExitCommandProcessingEarly(); |
| 11755 } | 11823 } |
| 11756 | 11824 |
| 11757 static void Clip( | 11825 static void Clip( |
| 11758 GLint start, GLint range, GLint sourceRange, | 11826 GLint start, GLint range, GLint sourceRange, |
| (...skipping 2680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 14439 } | 14507 } |
| 14440 if (levels <= 0) { | 14508 if (levels <= 0) { |
| 14441 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "levels <= 0"); | 14509 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "levels <= 0"); |
| 14442 return; | 14510 return; |
| 14443 } | 14511 } |
| 14444 if (!validators_->texture_internal_format_storage.IsValid(internal_format)) { | 14512 if (!validators_->texture_internal_format_storage.IsValid(internal_format)) { |
| 14445 LOCAL_SET_GL_ERROR_INVALID_ENUM( | 14513 LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 14446 function_name, internal_format, "internal_format"); | 14514 function_name, internal_format, "internal_format"); |
| 14447 return; | 14515 return; |
| 14448 } | 14516 } |
| 14449 bool is_compressed_format; | 14517 bool is_compressed_format = IsCompressedTextureFormat(internal_format); |
| 14450 switch (internal_format) { | 14518 if (is_compressed_format && target == GL_TEXTURE_3D) { |
| 14451 case GL_COMPRESSED_R11_EAC: | 14519 LOCAL_SET_GL_ERROR( |
| 14452 case GL_COMPRESSED_SIGNED_R11_EAC: | 14520 GL_INVALID_OPERATION, function_name, "target invalid for format"); |
| 14453 case GL_COMPRESSED_RG11_EAC: | 14521 return; |
| 14454 case GL_COMPRESSED_SIGNED_RG11_EAC: | |
| 14455 case GL_COMPRESSED_RGB8_ETC2: | |
| 14456 case GL_COMPRESSED_SRGB8_ETC2: | |
| 14457 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: | |
| 14458 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: | |
| 14459 case GL_COMPRESSED_RGBA8_ETC2_EAC: | |
| 14460 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: | |
| 14461 is_compressed_format = true; | |
| 14462 if (target == GL_TEXTURE_3D) { | |
| 14463 LOCAL_SET_GL_ERROR( | |
| 14464 GL_INVALID_OPERATION, function_name, "target invalid for format"); | |
| 14465 return; | |
| 14466 } | |
| 14467 break; | |
| 14468 default: | |
| 14469 is_compressed_format = false; | |
| 14470 break; | |
| 14471 } | 14522 } |
| 14472 if (!texture_manager()->ValidForTarget(target, 0, width, height, depth) || | 14523 if (!texture_manager()->ValidForTarget(target, 0, width, height, depth) || |
| 14473 TextureManager::ComputeMipMapCount( | 14524 TextureManager::ComputeMipMapCount( |
| 14474 target, width, height, depth) < levels) { | 14525 target, width, height, depth) < levels) { |
| 14475 LOCAL_SET_GL_ERROR( | 14526 LOCAL_SET_GL_ERROR( |
| 14476 GL_INVALID_VALUE, function_name, "dimensions out of range"); | 14527 GL_INVALID_VALUE, function_name, "dimensions out of range"); |
| 14477 return; | 14528 return; |
| 14478 } | 14529 } |
| 14479 TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( | 14530 TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 14480 &state_, target); | 14531 &state_, target); |
| (...skipping 2013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 16494 } | 16545 } |
| 16495 | 16546 |
| 16496 // Include the auto-generated part of this file. We split this because it means | 16547 // Include the auto-generated part of this file. We split this because it means |
| 16497 // we can easily edit the non-auto generated parts right here in this file | 16548 // we can easily edit the non-auto generated parts right here in this file |
| 16498 // instead of having to edit some template or the code generator. | 16549 // instead of having to edit some template or the code generator. |
| 16499 #include "base/macros.h" | 16550 #include "base/macros.h" |
| 16500 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 16551 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 16501 | 16552 |
| 16502 } // namespace gles2 | 16553 } // namespace gles2 |
| 16503 } // namespace gpu | 16554 } // namespace gpu |
| OLD | NEW |