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/texture_manager.h" | 5 #include "gpu/command_buffer/service/texture_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 796 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 796 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
| 797 DCHECK_LT(static_cast<size_t>(face_index), face_infos_.size()); | 797 DCHECK_LT(static_cast<size_t>(face_index), face_infos_.size()); |
| 798 DCHECK_LT(static_cast<size_t>(level), | 798 DCHECK_LT(static_cast<size_t>(level), |
| 799 face_infos_[face_index].level_infos.size()); | 799 face_infos_[face_index].level_infos.size()); |
| 800 Texture::LevelInfo& info = face_infos_[face_index].level_infos[level]; | 800 Texture::LevelInfo& info = face_infos_[face_index].level_infos[level]; |
| 801 UpdateMipCleared(&info, info.width, info.height, | 801 UpdateMipCleared(&info, info.width, info.height, |
| 802 cleared ? gfx::Rect(info.width, info.height) : gfx::Rect()); | 802 cleared ? gfx::Rect(info.width, info.height) : gfx::Rect()); |
| 803 UpdateCleared(); | 803 UpdateCleared(); |
| 804 } | 804 } |
| 805 | 805 |
| 806 void Texture::SetLevelCleared(GLenum target, | |
| 807 GLint level, | |
| 808 GLenum attachment, | |
| 809 bool cleared) { | |
| 810 DCHECK_GE(level, 0); | |
| 811 // Only take effect when the format is DEPTH_STENCIL | |
| 812 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | |
| 813 DCHECK_LT(static_cast<size_t>(face_index), face_infos_.size()); | |
| 814 DCHECK_LT(static_cast<size_t>(level), | |
| 815 face_infos_[face_index].level_infos.size()); | |
| 816 Texture::LevelInfo& info = face_infos_[face_index].level_infos[level]; | |
| 817 if (info.format != GL_DEPTH_STENCIL) | |
|
qiankun
2016/07/14 06:48:21
Will this be true in any conditions? I think only
| |
| 818 return; | |
| 819 // cleared_ is true only when both depth and stencil part are cleared. | |
| 820 if (attachment == GL_DEPTH_ATTACHMENT) { | |
| 821 if (cleared == stencil_cleared_) { | |
| 822 // SetLevelCleared(target, level, cleared); | |
|
qiankun
2016/07/14 06:48:22
remove unused code.
| |
| 823 UpdateMipCleared(&info, info.width, info.height, | |
| 824 cleared ? gfx::Rect(info.width, info.height) : | |
| 825 gfx::Rect()); | |
| 826 UpdateCleared(); | |
| 827 } else { | |
| 828 // SetLevelCleared(target, level, false); | |
| 829 UpdateMipCleared(&info, info.width, info.height, gfx::Rect()); | |
| 830 UpdateCleared(); | |
| 831 depth_cleared_ = cleared; | |
| 832 stencil_cleared_ = !cleared; | |
|
qiankun
2016/07/14 06:48:21
Should depth_cleared_ be updated in if branch?
ste
| |
| 833 } | |
| 834 } | |
| 835 else if (attachment == GL_STENCIL_ATTACHMENT) { | |
| 836 if (cleared == depth_cleared_) { | |
| 837 // SetLevelCleared(target, level, cleared); | |
| 838 UpdateMipCleared(&info, info.width, info.height, | |
| 839 cleared ? gfx::Rect(info.width, info.height) : | |
| 840 gfx::Rect()); | |
| 841 UpdateCleared(); | |
| 842 } else { | |
| 843 // SetLevelCleared(target, level, false); | |
| 844 UpdateMipCleared(&info, info.width, info.height, gfx::Rect()); | |
| 845 UpdateCleared(); | |
| 846 stencil_cleared_ = cleared; | |
| 847 depth_cleared_ = !cleared; | |
|
qiankun
2016/07/14 06:48:22
Same here.
| |
| 848 } | |
| 849 } | |
| 850 } | |
| 851 | |
| 806 void Texture::UpdateCleared() { | 852 void Texture::UpdateCleared() { |
| 807 if (face_infos_.empty()) { | 853 if (face_infos_.empty()) { |
| 808 return; | 854 return; |
| 809 } | 855 } |
| 810 | 856 |
| 811 const bool cleared = (num_uncleared_mips_ == 0); | 857 const bool cleared = (num_uncleared_mips_ == 0); |
| 812 | 858 |
| 813 // If texture is uncleared and is attached to a framebuffer, | 859 // If texture is uncleared and is attached to a framebuffer, |
| 814 // that framebuffer must be marked possibly incomplete. | 860 // that framebuffer must be marked possibly incomplete. |
| 815 if (!cleared && IsAttachedToFramebuffer()) { | 861 if (!cleared && IsAttachedToFramebuffer()) { |
| 816 IncAllFramebufferStateChangeCount(); | 862 IncAllFramebufferStateChangeCount(); |
| 817 } | 863 } |
| 818 | 864 |
| 819 UpdateSafeToRenderFrom(cleared); | 865 UpdateSafeToRenderFrom(cleared); |
| 820 } | 866 } |
| 821 | 867 |
| 822 void Texture::UpdateSafeToRenderFrom(bool cleared) { | 868 void Texture::UpdateSafeToRenderFrom(bool cleared) { |
| 823 if (cleared_ == cleared) | 869 if (cleared_ == cleared) |
| 824 return; | 870 return; |
| 825 cleared_ = cleared; | 871 cleared_ = cleared; |
| 826 int delta = cleared ? -1 : +1; | 872 int delta = cleared ? -1 : +1; |
| 827 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) | 873 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) |
| 828 (*it)->manager()->UpdateSafeToRenderFrom(delta); | 874 (*it)->manager()->UpdateSafeToRenderFrom(delta); |
| 875 | |
| 876 depth_cleared_ = cleared; | |
| 877 stencil_cleared_ = cleared; | |
| 829 } | 878 } |
| 830 | 879 |
| 831 void Texture::UpdateMipCleared(LevelInfo* info, | 880 void Texture::UpdateMipCleared(LevelInfo* info, |
| 832 GLsizei width, | 881 GLsizei width, |
| 833 GLsizei height, | 882 GLsizei height, |
| 834 const gfx::Rect& cleared_rect) { | 883 const gfx::Rect& cleared_rect) { |
| 835 bool was_cleared = info->cleared_rect == gfx::Rect(info->width, info->height); | 884 bool was_cleared = info->cleared_rect == gfx::Rect(info->width, info->height); |
| 836 info->width = width; | 885 info->width = width; |
| 837 info->height = height; | 886 info->height = height; |
| 838 info->cleared_rect = cleared_rect; | 887 info->cleared_rect = cleared_rect; |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1396 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 1445 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
| 1397 if (face_index >= face_infos_.size() || | 1446 if (face_index >= face_infos_.size() || |
| 1398 level < 0 || | 1447 level < 0 || |
| 1399 level >= static_cast<GLint>(face_infos_[face_index].level_infos.size())) { | 1448 level >= static_cast<GLint>(face_infos_[face_index].level_infos.size())) { |
| 1400 return true; | 1449 return true; |
| 1401 } | 1450 } |
| 1402 const Texture::LevelInfo& info = face_infos_[face_index].level_infos[level]; | 1451 const Texture::LevelInfo& info = face_infos_[face_index].level_infos[level]; |
| 1403 return info.cleared_rect == gfx::Rect(info.width, info.height); | 1452 return info.cleared_rect == gfx::Rect(info.width, info.height); |
| 1404 } | 1453 } |
| 1405 | 1454 |
| 1455 bool Texture::IsLevelCleared(GLenum target, | |
| 1456 GLint level, | |
| 1457 GLenum attachment) const { | |
|
qiankun
2016/07/14 06:48:21
ASSERT(attachment == GL_DEPTH_ATTACHMENT || attach
| |
| 1458 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | |
| 1459 if (face_index >= face_infos_.size() || | |
| 1460 level < 0 || | |
| 1461 level >= static_cast<GLint>(face_infos_[face_index].level_infos.size())) { | |
| 1462 return true; | |
| 1463 } | |
| 1464 const Texture::LevelInfo& info = face_infos_[face_index].level_infos[level]; | |
| 1465 if (info.format != GL_DEPTH_STENCIL) | |
| 1466 return info.cleared_rect == gfx::Rect(info.width, info.height); | |
| 1467 if (attachment == GL_DEPTH_ATTACHMENT) | |
| 1468 return depth_cleared_; | |
| 1469 else if (attachment == GL_STENCIL_ATTACHMENT) | |
| 1470 return stencil_cleared_; | |
| 1471 // Should not be reached | |
| 1472 return info.cleared_rect == gfx::Rect(info.width, info.height); | |
|
qiankun
2016/07/14 06:48:21
change to return attachment == GL_DEPTH_ATTACHMEN
| |
| 1473 } | |
| 1474 | |
| 1406 bool Texture::IsLevelPartiallyCleared(GLenum target, GLint level) const { | 1475 bool Texture::IsLevelPartiallyCleared(GLenum target, GLint level) const { |
| 1407 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 1476 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
| 1408 if (face_index >= face_infos_.size() || | 1477 if (face_index >= face_infos_.size() || |
| 1409 level < 0 || | 1478 level < 0 || |
| 1410 level >= static_cast<GLint>(face_infos_[face_index].level_infos.size())) { | 1479 level >= static_cast<GLint>(face_infos_[face_index].level_infos.size())) { |
| 1411 return false; | 1480 return false; |
| 1412 } | 1481 } |
| 1413 const Texture::LevelInfo& info = face_infos_[face_index].level_infos[level]; | 1482 const Texture::LevelInfo& info = face_infos_[face_index].level_infos[level]; |
| 1414 return (info.cleared_rect != gfx::Rect(info.width, info.height) && | 1483 return (info.cleared_rect != gfx::Rect(info.width, info.height) && |
| 1415 info.cleared_rect != gfx::Rect()); | 1484 info.cleared_rect != gfx::Rect()); |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1900 } | 1969 } |
| 1901 | 1970 |
| 1902 void TextureManager::SetLevelCleared(TextureRef* ref, | 1971 void TextureManager::SetLevelCleared(TextureRef* ref, |
| 1903 GLenum target, | 1972 GLenum target, |
| 1904 GLint level, | 1973 GLint level, |
| 1905 bool cleared) { | 1974 bool cleared) { |
| 1906 DCHECK(ref); | 1975 DCHECK(ref); |
| 1907 ref->texture()->SetLevelCleared(target, level, cleared); | 1976 ref->texture()->SetLevelCleared(target, level, cleared); |
| 1908 } | 1977 } |
| 1909 | 1978 |
| 1979 void TextureManager::SetLevelCleared(TextureRef* ref, | |
| 1980 GLenum target, | |
| 1981 GLint level, | |
| 1982 GLenum attachment, | |
| 1983 bool cleared) { | |
| 1984 DCHECK(ref); | |
| 1985 ref->texture()->SetLevelCleared(target, level, attachment, cleared); | |
| 1986 } | |
| 1987 | |
| 1910 bool TextureManager::ClearRenderableLevels( | 1988 bool TextureManager::ClearRenderableLevels( |
| 1911 GLES2Decoder* decoder, TextureRef* ref) { | 1989 GLES2Decoder* decoder, TextureRef* ref) { |
| 1912 DCHECK(ref); | 1990 DCHECK(ref); |
| 1913 return ref->texture()->ClearRenderableLevels(decoder); | 1991 return ref->texture()->ClearRenderableLevels(decoder); |
| 1914 } | 1992 } |
| 1915 | 1993 |
| 1916 bool TextureManager::ClearTextureLevel( | 1994 bool TextureManager::ClearTextureLevel( |
| 1917 GLES2Decoder* decoder, TextureRef* ref, | 1995 GLES2Decoder* decoder, TextureRef* ref, |
| 1918 GLenum target, GLint level) { | 1996 GLenum target, GLint level) { |
| 1919 DCHECK(ref); | 1997 DCHECK(ref); |
| (...skipping 1444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3364 uint32_t TextureManager::GetServiceIdGeneration() const { | 3442 uint32_t TextureManager::GetServiceIdGeneration() const { |
| 3365 return current_service_id_generation_; | 3443 return current_service_id_generation_; |
| 3366 } | 3444 } |
| 3367 | 3445 |
| 3368 void TextureManager::IncrementServiceIdGeneration() { | 3446 void TextureManager::IncrementServiceIdGeneration() { |
| 3369 current_service_id_generation_++; | 3447 current_service_id_generation_++; |
| 3370 } | 3448 } |
| 3371 | 3449 |
| 3372 } // namespace gles2 | 3450 } // namespace gles2 |
| 3373 } // namespace gpu | 3451 } // namespace gpu |
| OLD | NEW |