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 #include "base/bits.h" | 6 #include "base/bits.h" |
7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
8 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 8 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
9 #include "gpu/command_buffer/service/feature_info.h" | 9 #include "gpu/command_buffer/service/feature_info.h" |
10 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 10 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 return GL_TEXTURE_CUBE_MAP_POSITIVE_Z; | 53 return GL_TEXTURE_CUBE_MAP_POSITIVE_Z; |
54 case 5: | 54 case 5: |
55 return GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; | 55 return GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; |
56 default: | 56 default: |
57 NOTREACHED(); | 57 NOTREACHED(); |
58 return 0; | 58 return 0; |
59 } | 59 } |
60 } | 60 } |
61 | 61 |
62 TextureManager::~TextureManager() { | 62 TextureManager::~TextureManager() { |
63 DCHECK(texture_infos_.empty()); | 63 DCHECK(textures_.empty()); |
64 | 64 |
65 // If this triggers, that means something is keeping a reference to | 65 // If this triggers, that means something is keeping a reference to |
66 // a Texture belonging to this. | 66 // a Texture belonging to this. |
67 CHECK_EQ(texture_info_count_, 0u); | 67 CHECK_EQ(texture_count_, 0u); |
68 | 68 |
69 DCHECK_EQ(0, num_unrenderable_textures_); | 69 DCHECK_EQ(0, num_unrenderable_textures_); |
70 DCHECK_EQ(0, num_unsafe_textures_); | 70 DCHECK_EQ(0, num_unsafe_textures_); |
71 DCHECK_EQ(0, num_uncleared_mips_); | 71 DCHECK_EQ(0, num_uncleared_mips_); |
72 } | 72 } |
73 | 73 |
74 void TextureManager::Destroy(bool have_context) { | 74 void TextureManager::Destroy(bool have_context) { |
75 have_context_ = have_context; | 75 have_context_ = have_context; |
76 texture_infos_.clear(); | 76 textures_.clear(); |
77 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { | 77 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { |
78 default_textures_[ii] = NULL; | 78 default_textures_[ii] = NULL; |
79 } | 79 } |
80 | 80 |
81 if (have_context) { | 81 if (have_context) { |
82 glDeleteTextures(arraysize(black_texture_ids_), black_texture_ids_); | 82 glDeleteTextures(arraysize(black_texture_ids_), black_texture_ids_); |
83 } | 83 } |
84 | 84 |
85 DCHECK_EQ(0u, memory_tracker_managed_->GetMemRepresented()); | 85 DCHECK_EQ(0u, memory_tracker_managed_->GetMemRepresented()); |
86 DCHECK_EQ(0u, memory_tracker_unmanaged_->GetMemRepresented()); | 86 DCHECK_EQ(0u, memory_tracker_unmanaged_->GetMemRepresented()); |
87 } | 87 } |
88 | 88 |
89 Texture::Texture(TextureManager* manager, | 89 Texture::Texture(TextureManager* manager, GLuint service_id) |
90 GLuint service_id) | |
91 : manager_(manager), | 90 : manager_(manager), |
92 service_id_(service_id), | 91 service_id_(service_id), |
93 deleted_(false), | 92 deleted_(false), |
94 cleared_(true), | 93 cleared_(true), |
95 num_uncleared_mips_(0), | 94 num_uncleared_mips_(0), |
96 target_(0), | 95 target_(0), |
97 min_filter_(GL_NEAREST_MIPMAP_LINEAR), | 96 min_filter_(GL_NEAREST_MIPMAP_LINEAR), |
98 mag_filter_(GL_LINEAR), | 97 mag_filter_(GL_LINEAR), |
99 wrap_s_(GL_REPEAT), | 98 wrap_s_(GL_REPEAT), |
100 wrap_t_(GL_REPEAT), | 99 wrap_t_(GL_REPEAT), |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 border(rhs.border), | 151 border(rhs.border), |
153 format(rhs.format), | 152 format(rhs.format), |
154 type(rhs.type), | 153 type(rhs.type), |
155 image(rhs.image), | 154 image(rhs.image), |
156 estimated_size(rhs.estimated_size) { | 155 estimated_size(rhs.estimated_size) { |
157 } | 156 } |
158 | 157 |
159 Texture::LevelInfo::~LevelInfo() { | 158 Texture::LevelInfo::~LevelInfo() { |
160 } | 159 } |
161 | 160 |
162 bool Texture::CanRender( | 161 bool Texture::CanRender(const FeatureInfo* feature_info) const { |
163 const FeatureInfo* feature_info) const { | |
164 if (target_ == 0) { | 162 if (target_ == 0) { |
165 return false; | 163 return false; |
166 } | 164 } |
167 bool needs_mips = NeedsMips(); | 165 bool needs_mips = NeedsMips(); |
168 if ((npot() && !feature_info->feature_flags().npot_ok) || | 166 if ((npot() && !feature_info->feature_flags().npot_ok) || |
169 (target_ == GL_TEXTURE_RECTANGLE_ARB)) { | 167 (target_ == GL_TEXTURE_RECTANGLE_ARB)) { |
170 return !needs_mips && | 168 return !needs_mips && |
171 wrap_s_ == GL_CLAMP_TO_EDGE && | 169 wrap_s_ == GL_CLAMP_TO_EDGE && |
172 wrap_t_ == GL_CLAMP_TO_EDGE; | 170 wrap_t_ == GL_CLAMP_TO_EDGE; |
173 } | 171 } |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 max_cube_map_texture_size_(max_cube_map_texture_size), | 708 max_cube_map_texture_size_(max_cube_map_texture_size), |
711 max_levels_(ComputeMipMapCount(max_texture_size, | 709 max_levels_(ComputeMipMapCount(max_texture_size, |
712 max_texture_size, | 710 max_texture_size, |
713 max_texture_size)), | 711 max_texture_size)), |
714 max_cube_map_levels_(ComputeMipMapCount(max_cube_map_texture_size, | 712 max_cube_map_levels_(ComputeMipMapCount(max_cube_map_texture_size, |
715 max_cube_map_texture_size, | 713 max_cube_map_texture_size, |
716 max_cube_map_texture_size)), | 714 max_cube_map_texture_size)), |
717 num_unrenderable_textures_(0), | 715 num_unrenderable_textures_(0), |
718 num_unsafe_textures_(0), | 716 num_unsafe_textures_(0), |
719 num_uncleared_mips_(0), | 717 num_uncleared_mips_(0), |
720 texture_info_count_(0), | 718 texture_count_(0), |
721 have_context_(true) { | 719 have_context_(true) { |
722 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { | 720 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { |
723 black_texture_ids_[ii] = 0; | 721 black_texture_ids_[ii] = 0; |
724 } | 722 } |
725 } | 723 } |
726 | 724 |
727 bool TextureManager::Initialize() { | 725 bool TextureManager::Initialize() { |
728 // TODO(gman): The default textures have to be real textures, not the 0 | 726 // TODO(gman): The default textures have to be real textures, not the 0 |
729 // texture because we simulate non shared resources on top of shared | 727 // texture because we simulate non shared resources on top of shared |
730 // resources and all contexts that share resource share the same default | 728 // resources and all contexts that share resource share the same default |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 GL_UNSIGNED_BYTE, black); | 772 GL_UNSIGNED_BYTE, black); |
775 } | 773 } |
776 } | 774 } |
777 } | 775 } |
778 glBindTexture(target, 0); | 776 glBindTexture(target, 0); |
779 | 777 |
780 // Since we are manually setting up these textures | 778 // Since we are manually setting up these textures |
781 // we need to manually manipulate some of the their bookkeeping. | 779 // we need to manually manipulate some of the their bookkeeping. |
782 ++num_unrenderable_textures_; | 780 ++num_unrenderable_textures_; |
783 scoped_refptr<Texture> default_texture(new Texture(this, ids[1])); | 781 scoped_refptr<Texture> default_texture(new Texture(this, ids[1])); |
784 SetInfoTarget(default_texture, target); | 782 SetTarget(default_texture, target); |
785 if (needs_faces) { | 783 if (needs_faces) { |
786 for (int ii = 0; ii < GLES2Util::kNumFaces; ++ii) { | 784 for (int ii = 0; ii < GLES2Util::kNumFaces; ++ii) { |
787 SetLevelInfo( | 785 SetLevelInfo( |
788 default_texture, GLES2Util::IndexToGLFaceTarget(ii), | 786 default_texture, GLES2Util::IndexToGLFaceTarget(ii), |
789 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, true); | 787 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, true); |
790 } | 788 } |
791 } else { | 789 } else { |
792 if (needs_initialization) { | 790 if (needs_initialization) { |
793 SetLevelInfo(default_texture, | 791 SetLevelInfo(default_texture, |
794 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, | 792 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, |
(...skipping 21 matching lines...) Expand all Loading... |
816 height <= max_size && | 814 height <= max_size && |
817 depth <= max_size && | 815 depth <= max_size && |
818 (level == 0 || feature_info_->feature_flags().npot_ok || | 816 (level == 0 || feature_info_->feature_flags().npot_ok || |
819 (!GLES2Util::IsNPOT(width) && | 817 (!GLES2Util::IsNPOT(width) && |
820 !GLES2Util::IsNPOT(height) && | 818 !GLES2Util::IsNPOT(height) && |
821 !GLES2Util::IsNPOT(depth))) && | 819 !GLES2Util::IsNPOT(depth))) && |
822 (target != GL_TEXTURE_CUBE_MAP || (width == height && depth == 1)) && | 820 (target != GL_TEXTURE_CUBE_MAP || (width == height && depth == 1)) && |
823 (target != GL_TEXTURE_2D || (depth == 1)); | 821 (target != GL_TEXTURE_2D || (depth == 1)); |
824 } | 822 } |
825 | 823 |
826 void TextureManager::SetInfoTarget( | 824 void TextureManager::SetTarget(Texture* texture, GLenum target) { |
827 Texture* info, GLenum target) { | 825 DCHECK(texture); |
828 DCHECK(info); | 826 if (!texture->CanRender(feature_info_)) { |
829 if (!info->CanRender(feature_info_)) { | |
830 DCHECK_NE(0, num_unrenderable_textures_); | 827 DCHECK_NE(0, num_unrenderable_textures_); |
831 --num_unrenderable_textures_; | 828 --num_unrenderable_textures_; |
832 } | 829 } |
833 info->SetTarget(target, MaxLevelsForTarget(target)); | 830 texture->SetTarget(target, MaxLevelsForTarget(target)); |
834 if (!info->CanRender(feature_info_)) { | 831 if (!texture->CanRender(feature_info_)) { |
835 ++num_unrenderable_textures_; | 832 ++num_unrenderable_textures_; |
836 } | 833 } |
837 } | 834 } |
838 | 835 |
839 void TextureManager::SetLevelCleared(Texture* info, | 836 void TextureManager::SetLevelCleared(Texture* texture, |
840 GLenum target, | 837 GLenum target, |
841 GLint level, | 838 GLint level, |
842 bool cleared) { | 839 bool cleared) { |
843 DCHECK(info); | 840 DCHECK(texture); |
844 if (!info->SafeToRenderFrom()) { | 841 if (!texture->SafeToRenderFrom()) { |
845 DCHECK_NE(0, num_unsafe_textures_); | 842 DCHECK_NE(0, num_unsafe_textures_); |
846 --num_unsafe_textures_; | 843 --num_unsafe_textures_; |
847 } | 844 } |
848 num_uncleared_mips_ -= info->num_uncleared_mips(); | 845 num_uncleared_mips_ -= texture->num_uncleared_mips(); |
849 DCHECK_GE(num_uncleared_mips_, 0); | 846 DCHECK_GE(num_uncleared_mips_, 0); |
850 info->SetLevelCleared(target, level, cleared); | 847 texture->SetLevelCleared(target, level, cleared); |
851 num_uncleared_mips_ += info->num_uncleared_mips(); | 848 num_uncleared_mips_ += texture->num_uncleared_mips(); |
852 if (!info->SafeToRenderFrom()) { | 849 if (!texture->SafeToRenderFrom()) { |
853 ++num_unsafe_textures_; | 850 ++num_unsafe_textures_; |
854 } | 851 } |
855 } | 852 } |
856 | 853 |
857 bool TextureManager::ClearRenderableLevels( | 854 bool TextureManager::ClearRenderableLevels( |
858 GLES2Decoder* decoder,Texture* info) { | 855 GLES2Decoder* decoder,Texture* texture) { |
859 DCHECK(info); | 856 DCHECK(texture); |
860 if (info->SafeToRenderFrom()) { | 857 if (texture->SafeToRenderFrom()) { |
861 return true; | 858 return true; |
862 } | 859 } |
863 DCHECK_NE(0, num_unsafe_textures_); | 860 DCHECK_NE(0, num_unsafe_textures_); |
864 --num_unsafe_textures_; | 861 --num_unsafe_textures_; |
865 num_uncleared_mips_ -= info->num_uncleared_mips(); | 862 num_uncleared_mips_ -= texture->num_uncleared_mips(); |
866 DCHECK_GE(num_uncleared_mips_, 0); | 863 DCHECK_GE(num_uncleared_mips_, 0); |
867 bool result = info->ClearRenderableLevels(decoder); | 864 bool result = texture->ClearRenderableLevels(decoder); |
868 num_uncleared_mips_ += info->num_uncleared_mips(); | 865 num_uncleared_mips_ += texture->num_uncleared_mips(); |
869 if (!info->SafeToRenderFrom()) { | 866 if (!texture->SafeToRenderFrom()) { |
870 ++num_unsafe_textures_; | 867 ++num_unsafe_textures_; |
871 } | 868 } |
872 return result; | 869 return result; |
873 } | 870 } |
874 | 871 |
875 bool TextureManager::ClearTextureLevel( | 872 bool TextureManager::ClearTextureLevel( |
876 GLES2Decoder* decoder,Texture* info, | 873 GLES2Decoder* decoder,Texture* texture, |
877 GLenum target, GLint level) { | 874 GLenum target, GLint level) { |
878 DCHECK(info); | 875 DCHECK(texture); |
879 if (info->num_uncleared_mips() == 0) { | 876 if (texture->num_uncleared_mips() == 0) { |
880 return true; | 877 return true; |
881 } | 878 } |
882 num_uncleared_mips_ -= info->num_uncleared_mips(); | 879 num_uncleared_mips_ -= texture->num_uncleared_mips(); |
883 DCHECK_GE(num_uncleared_mips_, 0); | 880 DCHECK_GE(num_uncleared_mips_, 0); |
884 if (!info->SafeToRenderFrom()) { | 881 if (!texture->SafeToRenderFrom()) { |
885 DCHECK_NE(0, num_unsafe_textures_); | 882 DCHECK_NE(0, num_unsafe_textures_); |
886 --num_unsafe_textures_; | 883 --num_unsafe_textures_; |
887 } | 884 } |
888 bool result = info->ClearLevel(decoder, target, level); | 885 bool result = texture->ClearLevel(decoder, target, level); |
889 info->UpdateCleared(); | 886 texture->UpdateCleared(); |
890 num_uncleared_mips_ += info->num_uncleared_mips(); | 887 num_uncleared_mips_ += texture->num_uncleared_mips(); |
891 if (!info->SafeToRenderFrom()) { | 888 if (!texture->SafeToRenderFrom()) { |
892 ++num_unsafe_textures_; | 889 ++num_unsafe_textures_; |
893 } | 890 } |
894 return result; | 891 return result; |
895 } | 892 } |
896 | 893 |
897 void TextureManager::SetLevelInfo( | 894 void TextureManager::SetLevelInfo( |
898 Texture* info, | 895 Texture* texture, |
899 GLenum target, | 896 GLenum target, |
900 GLint level, | 897 GLint level, |
901 GLenum internal_format, | 898 GLenum internal_format, |
902 GLsizei width, | 899 GLsizei width, |
903 GLsizei height, | 900 GLsizei height, |
904 GLsizei depth, | 901 GLsizei depth, |
905 GLint border, | 902 GLint border, |
906 GLenum format, | 903 GLenum format, |
907 GLenum type, | 904 GLenum type, |
908 bool cleared) { | 905 bool cleared) { |
909 DCHECK(info); | 906 DCHECK(texture); |
910 if (!info->CanRender(feature_info_)) { | 907 if (!texture->CanRender(feature_info_)) { |
911 DCHECK_NE(0, num_unrenderable_textures_); | 908 DCHECK_NE(0, num_unrenderable_textures_); |
912 --num_unrenderable_textures_; | 909 --num_unrenderable_textures_; |
913 } | 910 } |
914 if (!info->SafeToRenderFrom()) { | 911 if (!texture->SafeToRenderFrom()) { |
915 DCHECK_NE(0, num_unsafe_textures_); | 912 DCHECK_NE(0, num_unsafe_textures_); |
916 --num_unsafe_textures_; | 913 --num_unsafe_textures_; |
917 } | 914 } |
918 num_uncleared_mips_ -= info->num_uncleared_mips(); | 915 num_uncleared_mips_ -= texture->num_uncleared_mips(); |
919 DCHECK_GE(num_uncleared_mips_, 0); | 916 DCHECK_GE(num_uncleared_mips_, 0); |
920 | 917 |
921 GetMemTracker(info->pool_)->TrackMemFree(info->estimated_size()); | 918 GetMemTracker(texture->pool_)->TrackMemFree(texture->estimated_size()); |
922 info->SetLevelInfo( | 919 texture->SetLevelInfo( |
923 feature_info_, target, level, internal_format, width, height, depth, | 920 feature_info_, target, level, internal_format, width, height, depth, |
924 border, format, type, cleared); | 921 border, format, type, cleared); |
925 GetMemTracker(info->pool_)->TrackMemAlloc(info->estimated_size()); | 922 GetMemTracker(texture->pool_)->TrackMemAlloc(texture->estimated_size()); |
926 | 923 |
927 num_uncleared_mips_ += info->num_uncleared_mips(); | 924 num_uncleared_mips_ += texture->num_uncleared_mips(); |
928 if (!info->CanRender(feature_info_)) { | 925 if (!texture->CanRender(feature_info_)) { |
929 ++num_unrenderable_textures_; | 926 ++num_unrenderable_textures_; |
930 } | 927 } |
931 if (!info->SafeToRenderFrom()) { | 928 if (!texture->SafeToRenderFrom()) { |
932 ++num_unsafe_textures_; | 929 ++num_unsafe_textures_; |
933 } | 930 } |
934 } | 931 } |
935 | 932 |
936 TextureDefinition* TextureManager::Save(Texture* info) { | 933 TextureDefinition* TextureManager::Save(Texture* texture) { |
937 DCHECK(info->owned_); | 934 DCHECK(texture->owned_); |
938 | 935 |
939 if (info->IsAttachedToFramebuffer()) | 936 if (texture->IsAttachedToFramebuffer()) |
940 return NULL; | 937 return NULL; |
941 | 938 |
942 TextureDefinition::LevelInfos level_infos(info->level_infos_.size()); | 939 TextureDefinition::LevelInfos level_infos(texture->level_infos_.size()); |
943 for (size_t face = 0; face < level_infos.size(); ++face) { | 940 for (size_t face = 0; face < level_infos.size(); ++face) { |
944 GLenum target = info->target() == GL_TEXTURE_2D ? | 941 GLenum target = texture->target() == GL_TEXTURE_2D ? |
945 GL_TEXTURE_2D : FaceIndexToGLTarget(face); | 942 GL_TEXTURE_2D : FaceIndexToGLTarget(face); |
946 for (size_t level = 0; level < info->level_infos_[face].size(); ++level) { | 943 for (size_t level = 0; level < texture->level_infos_[face].size(); |
| 944 ++level) { |
947 const Texture::LevelInfo& level_info = | 945 const Texture::LevelInfo& level_info = |
948 info->level_infos_[face][level]; | 946 texture->level_infos_[face][level]; |
949 level_infos[face].push_back( | 947 level_infos[face].push_back( |
950 TextureDefinition::LevelInfo(target, | 948 TextureDefinition::LevelInfo(target, |
951 level_info.internal_format, | 949 level_info.internal_format, |
952 level_info.width, | 950 level_info.width, |
953 level_info.height, | 951 level_info.height, |
954 level_info.depth, | 952 level_info.depth, |
955 level_info.border, | 953 level_info.border, |
956 level_info.format, | 954 level_info.format, |
957 level_info.type, | 955 level_info.type, |
958 level_info.cleared)); | 956 level_info.cleared)); |
959 | 957 |
960 SetLevelInfo(info, | 958 SetLevelInfo(texture, |
961 target, | 959 target, |
962 level, | 960 level, |
963 GL_RGBA, | 961 GL_RGBA, |
964 0, | 962 0, |
965 0, | 963 0, |
966 0, | 964 0, |
967 0, | 965 0, |
968 GL_RGBA, | 966 GL_RGBA, |
969 GL_UNSIGNED_BYTE, | 967 GL_UNSIGNED_BYTE, |
970 true); | 968 true); |
971 } | 969 } |
972 } | 970 } |
973 | 971 |
974 GLuint old_service_id = info->service_id(); | 972 GLuint old_service_id = texture->service_id(); |
975 bool immutable = info->IsImmutable(); | 973 bool immutable = texture->IsImmutable(); |
976 | 974 |
977 GLuint new_service_id = 0; | 975 GLuint new_service_id = 0; |
978 glGenTextures(1, &new_service_id); | 976 glGenTextures(1, &new_service_id); |
979 info->SetServiceId(new_service_id); | 977 texture->SetServiceId(new_service_id); |
980 info->SetImmutable(false); | 978 texture->SetImmutable(false); |
981 | 979 |
982 return new TextureDefinition(info->target(), | 980 return new TextureDefinition(texture->target(), |
983 old_service_id, | 981 old_service_id, |
984 info->min_filter(), | 982 texture->min_filter(), |
985 info->mag_filter(), | 983 texture->mag_filter(), |
986 info->wrap_s(), | 984 texture->wrap_s(), |
987 info->wrap_t(), | 985 texture->wrap_t(), |
988 info->usage(), | 986 texture->usage(), |
989 immutable, | 987 immutable, |
990 level_infos); | 988 level_infos); |
991 } | 989 } |
992 | 990 |
993 bool TextureManager::Restore(Texture* info, | 991 bool TextureManager::Restore( |
994 TextureDefinition* definition) { | 992 const char* function_name, |
995 DCHECK(info->owned_); | 993 GLES2Decoder* decoder, |
| 994 Texture* texture, |
| 995 TextureDefinition* definition) { |
| 996 DCHECK(texture->owned_); |
996 | 997 |
997 scoped_ptr<TextureDefinition> scoped_definition(definition); | 998 scoped_ptr<TextureDefinition> scoped_definition(definition); |
998 | 999 |
999 if (info->IsAttachedToFramebuffer()) | 1000 if (texture->IsAttachedToFramebuffer()) |
1000 return false; | 1001 return false; |
1001 | 1002 |
1002 if (info->target() != definition->target()) | 1003 if (texture->target() != definition->target()) |
1003 return false; | 1004 return false; |
1004 | 1005 |
1005 if (info->level_infos_.size() != definition->level_infos().size()) | 1006 if (texture->level_infos_.size() != definition->level_infos().size()) |
1006 return false; | 1007 return false; |
1007 | 1008 |
1008 if (info->level_infos_[0].size() != definition->level_infos()[0].size()) | 1009 if (texture->level_infos_[0].size() != definition->level_infos()[0].size()) |
1009 return false; | 1010 return false; |
1010 | 1011 |
1011 for (size_t face = 0; face < info->level_infos_.size(); ++face) { | 1012 for (size_t face = 0; face < texture->level_infos_.size(); ++face) { |
1012 GLenum target = info->target() == GL_TEXTURE_2D ? | 1013 GLenum target = texture->target() == GL_TEXTURE_2D ? |
1013 GL_TEXTURE_2D : FaceIndexToGLTarget(face); | 1014 GL_TEXTURE_2D : FaceIndexToGLTarget(face); |
1014 for (size_t level = 0; level < info->level_infos_[face].size(); ++level) { | 1015 for (size_t level = 0; level < texture->level_infos_[face].size(); |
| 1016 ++level) { |
1015 const TextureDefinition::LevelInfo& level_info = | 1017 const TextureDefinition::LevelInfo& level_info = |
1016 definition->level_infos()[face][level]; | 1018 definition->level_infos()[face][level]; |
1017 SetLevelInfo(info, | 1019 SetLevelInfo(texture, |
1018 target, | 1020 target, |
1019 level, | 1021 level, |
1020 level_info.internal_format, | 1022 level_info.internal_format, |
1021 level_info.width, | 1023 level_info.width, |
1022 level_info.height, | 1024 level_info.height, |
1023 level_info.depth, | 1025 level_info.depth, |
1024 level_info.border, | 1026 level_info.border, |
1025 level_info.format, | 1027 level_info.format, |
1026 level_info.type, | 1028 level_info.type, |
1027 level_info.cleared); | 1029 level_info.cleared); |
1028 } | 1030 } |
1029 } | 1031 } |
1030 | 1032 |
1031 GLuint old_service_id = info->service_id(); | 1033 GLuint old_service_id = texture->service_id(); |
1032 glDeleteTextures(1, &old_service_id); | 1034 glDeleteTextures(1, &old_service_id); |
1033 info->SetServiceId(definition->ReleaseServiceId()); | 1035 texture->SetServiceId(definition->ReleaseServiceId()); |
1034 info->SetImmutable(definition->immutable()); | 1036 glBindTexture(texture->target(), texture->service_id()); |
1035 SetParameter(info, GL_TEXTURE_MIN_FILTER, definition->min_filter()); | 1037 texture->SetImmutable(definition->immutable()); |
1036 SetParameter(info, GL_TEXTURE_MAG_FILTER, definition->mag_filter()); | 1038 SetParameter(function_name, decoder, texture, GL_TEXTURE_MIN_FILTER, |
1037 SetParameter(info, GL_TEXTURE_WRAP_S, definition->wrap_s()); | 1039 definition->min_filter()); |
1038 SetParameter(info, GL_TEXTURE_WRAP_T, definition->wrap_t()); | 1040 SetParameter(function_name, decoder, texture, GL_TEXTURE_MAG_FILTER, |
1039 SetParameter(info, GL_TEXTURE_USAGE_ANGLE, definition->usage()); | 1041 definition->mag_filter()); |
| 1042 SetParameter(function_name, decoder, texture, GL_TEXTURE_WRAP_S, |
| 1043 definition->wrap_s()); |
| 1044 SetParameter(function_name, decoder, texture, GL_TEXTURE_WRAP_T, |
| 1045 definition->wrap_t()); |
| 1046 if (feature_info_->validators()->texture_parameter.IsValid( |
| 1047 GL_TEXTURE_USAGE_ANGLE)) { |
| 1048 SetParameter(function_name, decoder, texture, GL_TEXTURE_USAGE_ANGLE, |
| 1049 definition->usage()); |
| 1050 } |
1040 | 1051 |
1041 return true; | 1052 return true; |
1042 } | 1053 } |
1043 | 1054 |
1044 GLenum TextureManager::SetParameter( | 1055 void TextureManager::SetParameter( |
1045 Texture* info, GLenum pname, GLint param) { | 1056 const char* function_name, GLES2Decoder* decoder, |
1046 DCHECK(info); | 1057 Texture* texture, GLenum pname, GLint param) { |
1047 if (!info->CanRender(feature_info_)) { | 1058 DCHECK(decoder); |
| 1059 DCHECK(texture); |
| 1060 if (!texture->CanRender(feature_info_)) { |
1048 DCHECK_NE(0, num_unrenderable_textures_); | 1061 DCHECK_NE(0, num_unrenderable_textures_); |
1049 --num_unrenderable_textures_; | 1062 --num_unrenderable_textures_; |
1050 } | 1063 } |
1051 if (!info->SafeToRenderFrom()) { | 1064 if (!texture->SafeToRenderFrom()) { |
1052 DCHECK_NE(0, num_unsafe_textures_); | 1065 DCHECK_NE(0, num_unsafe_textures_); |
1053 --num_unsafe_textures_; | 1066 --num_unsafe_textures_; |
1054 } | 1067 } |
1055 GLenum result = info->SetParameter(feature_info_, pname, param); | 1068 GLenum result = texture->SetParameter(feature_info_, pname, param); |
1056 if (!info->CanRender(feature_info_)) { | 1069 if (result != GL_NO_ERROR) { |
| 1070 if (result == GL_INVALID_ENUM) { |
| 1071 decoder->SetGLErrorInvalidEnum(function_name, param, "param"); |
| 1072 } else { |
| 1073 decoder->SetGLErrorInvalidParam( |
| 1074 result, function_name, pname, static_cast<GLint>(param)); |
| 1075 } |
| 1076 } else { |
| 1077 // Texture tracking pools exist only for the command decoder, so |
| 1078 // do not pass them on to the native GL implementation. |
| 1079 if (pname != GL_TEXTURE_POOL_CHROMIUM) { |
| 1080 glTexParameteri(texture->target(), pname, param); |
| 1081 } |
| 1082 } |
| 1083 |
| 1084 if (!texture->CanRender(feature_info_)) { |
1057 ++num_unrenderable_textures_; | 1085 ++num_unrenderable_textures_; |
1058 } | 1086 } |
1059 if (!info->SafeToRenderFrom()) { | 1087 if (!texture->SafeToRenderFrom()) { |
| 1088 ++num_unsafe_textures_; |
| 1089 } |
| 1090 } |
| 1091 |
| 1092 bool TextureManager::MarkMipmapsGenerated(Texture* texture) { |
| 1093 DCHECK(texture); |
| 1094 if (!texture->CanRender(feature_info_)) { |
| 1095 DCHECK_NE(0, num_unrenderable_textures_); |
| 1096 --num_unrenderable_textures_; |
| 1097 } |
| 1098 if (!texture->SafeToRenderFrom()) { |
| 1099 DCHECK_NE(0, num_unsafe_textures_); |
| 1100 --num_unsafe_textures_; |
| 1101 } |
| 1102 num_uncleared_mips_ -= texture->num_uncleared_mips(); |
| 1103 DCHECK_GE(num_uncleared_mips_, 0); |
| 1104 GetMemTracker(texture->pool_)->TrackMemFree(texture->estimated_size()); |
| 1105 bool result = texture->MarkMipmapsGenerated(feature_info_); |
| 1106 GetMemTracker(texture->pool_)->TrackMemAlloc(texture->estimated_size()); |
| 1107 |
| 1108 num_uncleared_mips_ += texture->num_uncleared_mips(); |
| 1109 if (!texture->CanRender(feature_info_)) { |
| 1110 ++num_unrenderable_textures_; |
| 1111 } |
| 1112 if (!texture->SafeToRenderFrom()) { |
1060 ++num_unsafe_textures_; | 1113 ++num_unsafe_textures_; |
1061 } | 1114 } |
1062 return result; | 1115 return result; |
1063 } | |
1064 | |
1065 bool TextureManager::MarkMipmapsGenerated(Texture* info) { | |
1066 DCHECK(info); | |
1067 if (!info->CanRender(feature_info_)) { | |
1068 DCHECK_NE(0, num_unrenderable_textures_); | |
1069 --num_unrenderable_textures_; | |
1070 } | |
1071 if (!info->SafeToRenderFrom()) { | |
1072 DCHECK_NE(0, num_unsafe_textures_); | |
1073 --num_unsafe_textures_; | |
1074 } | |
1075 num_uncleared_mips_ -= info->num_uncleared_mips(); | |
1076 DCHECK_GE(num_uncleared_mips_, 0); | |
1077 GetMemTracker(info->pool_)->TrackMemFree(info->estimated_size()); | |
1078 bool result = info->MarkMipmapsGenerated(feature_info_); | |
1079 GetMemTracker(info->pool_)->TrackMemAlloc(info->estimated_size()); | |
1080 | |
1081 num_uncleared_mips_ += info->num_uncleared_mips(); | |
1082 if (!info->CanRender(feature_info_)) { | |
1083 ++num_unrenderable_textures_; | |
1084 } | |
1085 if (!info->SafeToRenderFrom()) { | |
1086 ++num_unsafe_textures_; | |
1087 } | |
1088 return result; | |
1089 } | 1116 } |
1090 | 1117 |
1091 Texture* TextureManager::CreateTexture( | 1118 Texture* TextureManager::CreateTexture( |
1092 GLuint client_id, GLuint service_id) { | 1119 GLuint client_id, GLuint service_id) { |
1093 DCHECK_NE(0u, service_id); | 1120 DCHECK_NE(0u, service_id); |
1094 scoped_refptr<Texture> info(new Texture(this, service_id)); | 1121 scoped_refptr<Texture> texture(new Texture(this, service_id)); |
1095 std::pair<TextureInfoMap::iterator, bool> result = | 1122 std::pair<TextureMap::iterator, bool> result = |
1096 texture_infos_.insert(std::make_pair(client_id, info)); | 1123 textures_.insert(std::make_pair(client_id, texture)); |
1097 DCHECK(result.second); | 1124 DCHECK(result.second); |
1098 if (!info->CanRender(feature_info_)) { | 1125 if (!texture->CanRender(feature_info_)) { |
1099 ++num_unrenderable_textures_; | 1126 ++num_unrenderable_textures_; |
1100 } | 1127 } |
1101 if (!info->SafeToRenderFrom()) { | 1128 if (!texture->SafeToRenderFrom()) { |
1102 ++num_unsafe_textures_; | 1129 ++num_unsafe_textures_; |
1103 } | 1130 } |
1104 num_uncleared_mips_ += info->num_uncleared_mips(); | 1131 num_uncleared_mips_ += texture->num_uncleared_mips(); |
1105 return info.get(); | 1132 return texture.get(); |
1106 } | 1133 } |
1107 | 1134 |
1108 Texture* TextureManager::GetTexture( | 1135 Texture* TextureManager::GetTexture( |
1109 GLuint client_id) const { | 1136 GLuint client_id) const { |
1110 TextureInfoMap::const_iterator it = texture_infos_.find(client_id); | 1137 TextureMap::const_iterator it = textures_.find(client_id); |
1111 return it != texture_infos_.end() ? it->second : NULL; | 1138 return it != textures_.end() ? it->second : NULL; |
1112 } | 1139 } |
1113 | 1140 |
1114 void TextureManager::RemoveTexture(GLuint client_id) { | 1141 void TextureManager::RemoveTexture(GLuint client_id) { |
1115 TextureInfoMap::iterator it = texture_infos_.find(client_id); | 1142 TextureMap::iterator it = textures_.find(client_id); |
1116 if (it != texture_infos_.end()) { | 1143 if (it != textures_.end()) { |
1117 Texture* info = it->second; | 1144 Texture* texture = it->second; |
1118 info->MarkAsDeleted(); | 1145 texture->MarkAsDeleted(); |
1119 texture_infos_.erase(it); | 1146 textures_.erase(it); |
1120 } | 1147 } |
1121 } | 1148 } |
1122 | 1149 |
1123 void TextureManager::StartTracking(Texture* /* texture */) { | 1150 void TextureManager::StartTracking(Texture* /* texture */) { |
1124 ++texture_info_count_; | 1151 ++texture_count_; |
1125 } | 1152 } |
1126 | 1153 |
1127 void TextureManager::StopTracking(Texture* texture) { | 1154 void TextureManager::StopTracking(Texture* texture) { |
1128 --texture_info_count_; | 1155 --texture_count_; |
1129 if (!texture->CanRender(feature_info_)) { | 1156 if (!texture->CanRender(feature_info_)) { |
1130 DCHECK_NE(0, num_unrenderable_textures_); | 1157 DCHECK_NE(0, num_unrenderable_textures_); |
1131 --num_unrenderable_textures_; | 1158 --num_unrenderable_textures_; |
1132 } | 1159 } |
1133 if (!texture->SafeToRenderFrom()) { | 1160 if (!texture->SafeToRenderFrom()) { |
1134 DCHECK_NE(0, num_unsafe_textures_); | 1161 DCHECK_NE(0, num_unsafe_textures_); |
1135 --num_unsafe_textures_; | 1162 --num_unsafe_textures_; |
1136 } | 1163 } |
1137 num_uncleared_mips_ -= texture->num_uncleared_mips(); | 1164 num_uncleared_mips_ -= texture->num_uncleared_mips(); |
1138 DCHECK_GE(num_uncleared_mips_, 0); | 1165 DCHECK_GE(num_uncleared_mips_, 0); |
(...skipping 10 matching lines...) Expand all Loading... |
1149 break; | 1176 break; |
1150 default: | 1177 default: |
1151 break; | 1178 break; |
1152 } | 1179 } |
1153 NOTREACHED(); | 1180 NOTREACHED(); |
1154 return NULL; | 1181 return NULL; |
1155 } | 1182 } |
1156 | 1183 |
1157 bool TextureManager::GetClientId(GLuint service_id, GLuint* client_id) const { | 1184 bool TextureManager::GetClientId(GLuint service_id, GLuint* client_id) const { |
1158 // This doesn't need to be fast. It's only used during slow queries. | 1185 // This doesn't need to be fast. It's only used during slow queries. |
1159 for (TextureInfoMap::const_iterator it = texture_infos_.begin(); | 1186 for (TextureMap::const_iterator it = textures_.begin(); |
1160 it != texture_infos_.end(); ++it) { | 1187 it != textures_.end(); ++it) { |
1161 if (it->second->service_id() == service_id) { | 1188 if (it->second->service_id() == service_id) { |
1162 *client_id = it->first; | 1189 *client_id = it->first; |
1163 return true; | 1190 return true; |
1164 } | 1191 } |
1165 } | 1192 } |
1166 return false; | 1193 return false; |
1167 } | 1194 } |
1168 | 1195 |
1169 GLsizei TextureManager::ComputeMipMapCount( | 1196 GLsizei TextureManager::ComputeMipMapCount( |
1170 GLsizei width, GLsizei height, GLsizei depth) { | 1197 GLsizei width, GLsizei height, GLsizei depth) { |
1171 return 1 + base::bits::Log2Floor(std::max(std::max(width, height), depth)); | 1198 return 1 + base::bits::Log2Floor(std::max(std::max(width, height), depth)); |
1172 } | 1199 } |
1173 | 1200 |
1174 void TextureManager::SetLevelImage( | 1201 void TextureManager::SetLevelImage( |
1175 Texture* info, | 1202 Texture* texture, |
1176 GLenum target, | 1203 GLenum target, |
1177 GLint level, | 1204 GLint level, |
1178 gfx::GLImage* image) { | 1205 gfx::GLImage* image) { |
1179 DCHECK(info); | 1206 DCHECK(texture); |
1180 if (!info->CanRender(feature_info_)) { | 1207 if (!texture->CanRender(feature_info_)) { |
1181 DCHECK_NE(0, num_unrenderable_textures_); | 1208 DCHECK_NE(0, num_unrenderable_textures_); |
1182 --num_unrenderable_textures_; | 1209 --num_unrenderable_textures_; |
1183 } | 1210 } |
1184 if (!info->SafeToRenderFrom()) { | 1211 if (!texture->SafeToRenderFrom()) { |
1185 DCHECK_NE(0, num_unsafe_textures_); | 1212 DCHECK_NE(0, num_unsafe_textures_); |
1186 --num_unsafe_textures_; | 1213 --num_unsafe_textures_; |
1187 } | 1214 } |
1188 info->SetLevelImage(feature_info_, target, level, image); | 1215 texture->SetLevelImage(feature_info_, target, level, image); |
1189 if (!info->CanRender(feature_info_)) { | 1216 if (!texture->CanRender(feature_info_)) { |
1190 ++num_unrenderable_textures_; | 1217 ++num_unrenderable_textures_; |
1191 } | 1218 } |
1192 if (!info->SafeToRenderFrom()) { | 1219 if (!texture->SafeToRenderFrom()) { |
1193 ++num_unsafe_textures_; | 1220 ++num_unsafe_textures_; |
1194 } | 1221 } |
1195 } | 1222 } |
1196 | 1223 |
1197 void TextureManager::AddToSignature( | 1224 void TextureManager::AddToSignature( |
1198 Texture* info, | 1225 Texture* texture, |
1199 GLenum target, | 1226 GLenum target, |
1200 GLint level, | 1227 GLint level, |
1201 std::string* signature) const { | 1228 std::string* signature) const { |
1202 info->AddToSignature(feature_info_.get(), target, level, signature); | 1229 texture->AddToSignature(feature_info_.get(), target, level, signature); |
1203 } | 1230 } |
1204 | 1231 |
1205 void TextureManager::AddPendingAsyncPixelTransfer( | 1232 void TextureManager::AddPendingAsyncPixelTransfer( |
1206 base::WeakPtr<gfx::AsyncPixelTransferState> state, Texture* info) { | 1233 base::WeakPtr<gfx::AsyncPixelTransferState> state, Texture* texture) { |
1207 pending_async_transfers_.push_back(PendingAsyncTransfer(state,info)); | 1234 pending_async_transfers_.push_back(PendingAsyncTransfer(state, texture)); |
1208 } | 1235 } |
1209 | 1236 |
1210 void TextureManager::BindFinishedAsyncPixelTransfers( | 1237 void TextureManager::BindFinishedAsyncPixelTransfers( |
1211 bool* texture_dirty, bool* framebuffer_dirty) { | 1238 bool* texture_dirty, bool* framebuffer_dirty) { |
1212 DCHECK(texture_dirty); | 1239 DCHECK(texture_dirty); |
1213 DCHECK(framebuffer_dirty); | 1240 DCHECK(framebuffer_dirty); |
1214 *texture_dirty = false; | 1241 *texture_dirty = false; |
1215 *framebuffer_dirty = false; | 1242 *framebuffer_dirty = false; |
1216 | 1243 |
1217 // Remove finished transfers from the list, while | 1244 // Remove finished transfers from the list, while |
(...skipping 27 matching lines...) Expand all Loading... |
1245 tex_define_params.border, | 1272 tex_define_params.border, |
1246 tex_define_params.format, | 1273 tex_define_params.format, |
1247 tex_define_params.type, | 1274 tex_define_params.type, |
1248 true); // cleared | 1275 true); // cleared |
1249 pending_async_transfers_.pop_front(); | 1276 pending_async_transfers_.pop_front(); |
1250 } | 1277 } |
1251 } | 1278 } |
1252 | 1279 |
1253 } // namespace gles2 | 1280 } // namespace gles2 |
1254 } // namespace gpu | 1281 } // namespace gpu |
OLD | NEW |