OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "gpu/command_buffer/common/gles2_cmd_utils.h" | 7 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
8 #include "gpu/command_buffer/service/feature_info.h" | 8 #include "gpu/command_buffer/service/feature_info.h" |
9 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 9 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
10 | 10 |
11 namespace gpu { | 11 namespace gpu { |
12 namespace gles2 { | 12 namespace gles2 { |
13 | 13 |
14 static GLsizei ComputeMipMapCount( | |
15 GLsizei width, GLsizei height, GLsizei depth) { | |
16 return 1 + base::bits::Log2Floor(std::max(std::max(width, height), depth)); | |
17 } | |
18 | |
19 static size_t GLTargetToFaceIndex(GLenum target) { | 14 static size_t GLTargetToFaceIndex(GLenum target) { |
20 switch (target) { | 15 switch (target) { |
21 case GL_TEXTURE_2D: | 16 case GL_TEXTURE_2D: |
22 case GL_TEXTURE_EXTERNAL_OES: | 17 case GL_TEXTURE_EXTERNAL_OES: |
23 case GL_TEXTURE_RECTANGLE_ARB: | 18 case GL_TEXTURE_RECTANGLE_ARB: |
24 return 0; | 19 return 0; |
25 case GL_TEXTURE_CUBE_MAP_POSITIVE_X: | 20 case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
26 return 0; | 21 return 0; |
27 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: | 22 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
28 return 1; | 23 return 1; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 return texture_complete(); | 99 return texture_complete(); |
105 } else { | 100 } else { |
106 return texture_complete() && cube_complete(); | 101 return texture_complete() && cube_complete(); |
107 } | 102 } |
108 } else { | 103 } else { |
109 return true; | 104 return true; |
110 } | 105 } |
111 } | 106 } |
112 | 107 |
113 bool TextureManager::TextureInfo::MarkMipmapsGenerated( | 108 bool TextureManager::TextureInfo::MarkMipmapsGenerated( |
114 const FeatureInfo* feature_info) { | 109 const FeatureInfo* feature_info, |
| 110 bool cleared) { |
115 if (!CanGenerateMipmaps(feature_info)) { | 111 if (!CanGenerateMipmaps(feature_info)) { |
116 return false; | 112 return false; |
117 } | 113 } |
118 for (size_t ii = 0; ii < level_infos_.size(); ++ii) { | 114 for (size_t ii = 0; ii < level_infos_.size(); ++ii) { |
119 const TextureInfo::LevelInfo& info1 = level_infos_[ii][0]; | 115 const TextureInfo::LevelInfo& info1 = level_infos_[ii][0]; |
120 GLsizei width = info1.width; | 116 GLsizei width = info1.width; |
121 GLsizei height = info1.height; | 117 GLsizei height = info1.height; |
122 GLsizei depth = info1.depth; | 118 GLsizei depth = info1.depth; |
123 GLenum target = target_ == GL_TEXTURE_2D ? GL_TEXTURE_2D : | 119 GLenum target = target_ == GL_TEXTURE_2D ? GL_TEXTURE_2D : |
124 FaceIndexToGLTarget(ii); | 120 FaceIndexToGLTarget(ii); |
125 int num_mips = ComputeMipMapCount(width, height, depth); | 121 int num_mips = ComputeMipMapCount(width, height, depth); |
126 for (int level = 1; level < num_mips; ++level) { | 122 for (int level = 1; level < num_mips; ++level) { |
127 width = std::max(1, width >> 1); | 123 width = std::max(1, width >> 1); |
128 height = std::max(1, height >> 1); | 124 height = std::max(1, height >> 1); |
129 depth = std::max(1, depth >> 1); | 125 depth = std::max(1, depth >> 1); |
130 SetLevelInfo(feature_info, | 126 SetLevelInfo(feature_info, |
131 target, | 127 target, |
132 level, | 128 level, |
133 info1.internal_format, | 129 info1.internal_format, |
134 width, | 130 width, |
135 height, | 131 height, |
136 depth, | 132 depth, |
137 info1.border, | 133 info1.border, |
138 info1.format, | 134 info1.format, |
139 info1.type, | 135 info1.type, |
140 true); | 136 cleared); |
141 } | 137 } |
142 } | 138 } |
143 | 139 |
144 return true; | 140 return true; |
145 } | 141 } |
146 | 142 |
147 void TextureManager::TextureInfo::SetTarget(GLenum target, GLint max_levels) { | 143 void TextureManager::TextureInfo::SetTarget(GLenum target, GLint max_levels) { |
148 DCHECK_EQ(0u, target_); // you can only set this once. | 144 DCHECK_EQ(0u, target_); // you can only set this once. |
149 target_ = target; | 145 target_ = target; |
150 size_t num_faces = (target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; | 146 size_t num_faces = (target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 break; | 357 break; |
362 case GL_TEXTURE_WRAP_T: | 358 case GL_TEXTURE_WRAP_T: |
363 if (!feature_info->validators()->texture_wrap_mode.IsValid(param)) { | 359 if (!feature_info->validators()->texture_wrap_mode.IsValid(param)) { |
364 return false; | 360 return false; |
365 } | 361 } |
366 wrap_t_ = param; | 362 wrap_t_ = param; |
367 break; | 363 break; |
368 case GL_TEXTURE_MAX_ANISOTROPY_EXT: | 364 case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
369 // Nothing to do for this case at the moment. | 365 // Nothing to do for this case at the moment. |
370 break; | 366 break; |
| 367 case GL_TEXTURE_USAGE_ANGLE: |
| 368 if (!feature_info->validators()->texture_usage.IsValid(param)) { |
| 369 return false; |
| 370 } |
| 371 usage_ = param; |
| 372 break; |
371 default: | 373 default: |
372 NOTREACHED(); | 374 NOTREACHED(); |
373 return false; | 375 return false; |
374 } | 376 } |
375 Update(feature_info); | 377 Update(feature_info); |
376 UpdateCleared(); | 378 UpdateCleared(); |
377 return true; | 379 return true; |
378 } | 380 } |
379 | 381 |
380 void TextureManager::TextureInfo::Update(const FeatureInfo* feature_info) { | 382 void TextureManager::TextureInfo::Update(const FeatureInfo* feature_info) { |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 ++num_unrenderable_textures_; | 784 ++num_unrenderable_textures_; |
783 } | 785 } |
784 if (!info->SafeToRenderFrom()) { | 786 if (!info->SafeToRenderFrom()) { |
785 ++num_unsafe_textures_; | 787 ++num_unsafe_textures_; |
786 } | 788 } |
787 return result; | 789 return result; |
788 } | 790 } |
789 | 791 |
790 bool TextureManager::MarkMipmapsGenerated( | 792 bool TextureManager::MarkMipmapsGenerated( |
791 const FeatureInfo* feature_info, | 793 const FeatureInfo* feature_info, |
792 TextureManager::TextureInfo* info) { | 794 TextureManager::TextureInfo* info, |
| 795 bool cleared) { |
793 DCHECK(info); | 796 DCHECK(info); |
794 if (!info->CanRender(feature_info)) { | 797 if (!info->CanRender(feature_info)) { |
795 DCHECK_NE(0, num_unrenderable_textures_); | 798 DCHECK_NE(0, num_unrenderable_textures_); |
796 --num_unrenderable_textures_; | 799 --num_unrenderable_textures_; |
797 } | 800 } |
798 if (!info->SafeToRenderFrom()) { | 801 if (!info->SafeToRenderFrom()) { |
799 DCHECK_NE(0, num_unsafe_textures_); | 802 DCHECK_NE(0, num_unsafe_textures_); |
800 --num_unsafe_textures_; | 803 --num_unsafe_textures_; |
801 } | 804 } |
802 num_uncleared_mips_ -= info->num_uncleared_mips(); | 805 num_uncleared_mips_ -= info->num_uncleared_mips(); |
803 DCHECK_GE(num_uncleared_mips_, 0); | 806 DCHECK_GE(num_uncleared_mips_, 0); |
804 bool result = info->MarkMipmapsGenerated(feature_info); | 807 bool result = info->MarkMipmapsGenerated(feature_info, cleared); |
805 num_uncleared_mips_ += info->num_uncleared_mips(); | 808 num_uncleared_mips_ += info->num_uncleared_mips(); |
806 if (!info->CanRender(feature_info)) { | 809 if (!info->CanRender(feature_info)) { |
807 ++num_unrenderable_textures_; | 810 ++num_unrenderable_textures_; |
808 } | 811 } |
809 if (!info->SafeToRenderFrom()) { | 812 if (!info->SafeToRenderFrom()) { |
810 ++num_unsafe_textures_; | 813 ++num_unsafe_textures_; |
811 } | 814 } |
812 return result; | 815 return result; |
813 } | 816 } |
814 | 817 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 for (TextureInfoMap::const_iterator it = texture_infos_.begin(); | 863 for (TextureInfoMap::const_iterator it = texture_infos_.begin(); |
861 it != texture_infos_.end(); ++it) { | 864 it != texture_infos_.end(); ++it) { |
862 if (it->second->service_id() == service_id) { | 865 if (it->second->service_id() == service_id) { |
863 *client_id = it->first; | 866 *client_id = it->first; |
864 return true; | 867 return true; |
865 } | 868 } |
866 } | 869 } |
867 return false; | 870 return false; |
868 } | 871 } |
869 | 872 |
| 873 GLsizei TextureManager::ComputeMipMapCount( |
| 874 GLsizei width, GLsizei height, GLsizei depth) { |
| 875 return 1 + base::bits::Log2Floor(std::max(std::max(width, height), depth)); |
| 876 } |
| 877 |
| 878 |
870 } // namespace gles2 | 879 } // namespace gles2 |
871 } // namespace gpu | 880 } // namespace gpu |
872 | 881 |
873 | 882 |
OLD | NEW |