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 "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 #include "gpu/command_buffer/service/mailbox_manager.h" | 10 #include "gpu/command_buffer/service/mailbox_manager.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 : cleared(rhs.cleared), | 143 : cleared(rhs.cleared), |
144 target(rhs.target), | 144 target(rhs.target), |
145 level(rhs.level), | 145 level(rhs.level), |
146 internal_format(rhs.internal_format), | 146 internal_format(rhs.internal_format), |
147 width(rhs.width), | 147 width(rhs.width), |
148 height(rhs.height), | 148 height(rhs.height), |
149 depth(rhs.depth), | 149 depth(rhs.depth), |
150 border(rhs.border), | 150 border(rhs.border), |
151 format(rhs.format), | 151 format(rhs.format), |
152 type(rhs.type), | 152 type(rhs.type), |
| 153 image(rhs.image), |
153 estimated_size(rhs.estimated_size) { | 154 estimated_size(rhs.estimated_size) { |
154 } | 155 } |
155 | 156 |
| 157 TextureManager::TextureInfo::LevelInfo::~LevelInfo() { |
| 158 } |
| 159 |
156 bool TextureManager::TextureInfo::CanRender( | 160 bool TextureManager::TextureInfo::CanRender( |
157 const FeatureInfo* feature_info) const { | 161 const FeatureInfo* feature_info) const { |
158 if (target_ == 0) { | 162 if (target_ == 0) { |
159 return false; | 163 return false; |
160 } | 164 } |
161 bool needs_mips = NeedsMips(); | 165 bool needs_mips = NeedsMips(); |
162 if ((npot() && !feature_info->feature_flags().npot_ok) || | 166 if ((npot() && !feature_info->feature_flags().npot_ok) || |
163 (target_ == GL_TEXTURE_RECTANGLE_ARB)) { | 167 (target_ == GL_TEXTURE_RECTANGLE_ARB)) { |
164 return !needs_mips && | 168 return !needs_mips && |
165 wrap_s_ == GL_CLAMP_TO_EDGE && | 169 wrap_s_ == GL_CLAMP_TO_EDGE && |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 for (size_t ii = 0; ii < level_infos_.size(); ++ii) { | 249 for (size_t ii = 0; ii < level_infos_.size(); ++ii) { |
246 const LevelInfo& info = level_infos_[ii][0]; | 250 const LevelInfo& info = level_infos_[ii][0]; |
247 if ((info.target == 0) || | 251 if ((info.target == 0) || |
248 (info.width != first.width) || | 252 (info.width != first.width) || |
249 (info.height != first.height) || | 253 (info.height != first.height) || |
250 (info.depth != 1) || | 254 (info.depth != 1) || |
251 (info.format != first.format) || | 255 (info.format != first.format) || |
252 (info.internal_format != first.internal_format) || | 256 (info.internal_format != first.internal_format) || |
253 (info.type != first.type) || | 257 (info.type != first.type) || |
254 feature_info->validators()->compressed_texture_format.IsValid( | 258 feature_info->validators()->compressed_texture_format.IsValid( |
255 info.internal_format)) { | 259 info.internal_format) || |
| 260 info.image) { |
256 return false; | 261 return false; |
257 } | 262 } |
258 } | 263 } |
259 return true; | 264 return true; |
260 } | 265 } |
261 | 266 |
262 void TextureManager::TextureInfo::SetLevelCleared(GLenum target, GLint level) { | 267 void TextureManager::TextureInfo::SetLevelCleared(GLenum target, GLint level) { |
263 DCHECK_GE(level, 0); | 268 DCHECK_GE(level, 0); |
264 DCHECK_LT(static_cast<size_t>(GLTargetToFaceIndex(target)), | 269 DCHECK_LT(static_cast<size_t>(GLTargetToFaceIndex(target)), |
265 level_infos_.size()); | 270 level_infos_.size()); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 level_infos_[GLTargetToFaceIndex(target)][level]; | 325 level_infos_[GLTargetToFaceIndex(target)][level]; |
321 info.target = target; | 326 info.target = target; |
322 info.level = level; | 327 info.level = level; |
323 info.internal_format = internal_format; | 328 info.internal_format = internal_format; |
324 info.width = width; | 329 info.width = width; |
325 info.height = height; | 330 info.height = height; |
326 info.depth = depth; | 331 info.depth = depth; |
327 info.border = border; | 332 info.border = border; |
328 info.format = format; | 333 info.format = format; |
329 info.type = type; | 334 info.type = type; |
| 335 info.image = 0; |
330 | 336 |
331 estimated_size_ -= info.estimated_size; | 337 estimated_size_ -= info.estimated_size; |
332 GLES2Util::ComputeImageDataSizes( | 338 GLES2Util::ComputeImageDataSizes( |
333 width, height, format, type, 4, &info.estimated_size, NULL, NULL); | 339 width, height, format, type, 4, &info.estimated_size, NULL, NULL); |
334 estimated_size_ += info.estimated_size; | 340 estimated_size_ += info.estimated_size; |
335 | 341 |
336 if (!info.cleared) { | 342 if (!info.cleared) { |
337 DCHECK_NE(0, num_uncleared_mips_); | 343 DCHECK_NE(0, num_uncleared_mips_); |
338 --num_uncleared_mips_; | 344 --num_uncleared_mips_; |
339 } | 345 } |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 // needed to be able to call GL correctly. | 615 // needed to be able to call GL correctly. |
610 info.cleared = decoder->ClearLevel( | 616 info.cleared = decoder->ClearLevel( |
611 service_id_, target_, info.target, info.level, info.format, info.type, | 617 service_id_, target_, info.target, info.level, info.format, info.type, |
612 info.width, info.height, immutable_); | 618 info.width, info.height, immutable_); |
613 if (!info.cleared) { | 619 if (!info.cleared) { |
614 ++num_uncleared_mips_; | 620 ++num_uncleared_mips_; |
615 } | 621 } |
616 return info.cleared; | 622 return info.cleared; |
617 } | 623 } |
618 | 624 |
| 625 void TextureManager::TextureInfo::SetLevelImage( |
| 626 const FeatureInfo* feature_info, |
| 627 GLenum target, |
| 628 GLint level, |
| 629 gfx::GLImage* image) { |
| 630 DCHECK_GE(level, 0); |
| 631 DCHECK_LT(static_cast<size_t>(GLTargetToFaceIndex(target)), |
| 632 level_infos_.size()); |
| 633 DCHECK_LT(static_cast<size_t>(level), |
| 634 level_infos_[GLTargetToFaceIndex(target)].size()); |
| 635 TextureInfo::LevelInfo& info = |
| 636 level_infos_[GLTargetToFaceIndex(target)][level]; |
| 637 DCHECK_EQ(info.target, target); |
| 638 DCHECK_EQ(info.level, level); |
| 639 info.image = image; |
| 640 } |
| 641 |
| 642 gfx::GLImage* TextureManager::TextureInfo::GetLevelImage( |
| 643 GLint face, GLint level) const { |
| 644 size_t face_index = GLTargetToFaceIndex(face); |
| 645 if (level >= 0 && face_index < level_infos_.size() && |
| 646 static_cast<size_t>(level) < level_infos_[face_index].size()) { |
| 647 const LevelInfo& info = level_infos_[GLTargetToFaceIndex(face)][level]; |
| 648 if (info.target != 0) { |
| 649 return info.image; |
| 650 } |
| 651 } |
| 652 return 0; |
| 653 } |
| 654 |
619 TextureManager::TextureManager( | 655 TextureManager::TextureManager( |
620 MemoryTracker* memory_tracker, | 656 MemoryTracker* memory_tracker, |
621 FeatureInfo* feature_info, | 657 FeatureInfo* feature_info, |
622 GLint max_texture_size, | 658 GLint max_texture_size, |
623 GLint max_cube_map_texture_size) | 659 GLint max_cube_map_texture_size) |
624 : texture_memory_tracker_(new MemoryTypeTracker(memory_tracker)), | 660 : texture_memory_tracker_(new MemoryTypeTracker(memory_tracker)), |
625 feature_info_(feature_info), | 661 feature_info_(feature_info), |
626 max_texture_size_(max_texture_size), | 662 max_texture_size_(max_texture_size), |
627 max_cube_map_texture_size_(max_cube_map_texture_size), | 663 max_cube_map_texture_size_(max_cube_map_texture_size), |
628 max_levels_(ComputeMipMapCount(max_texture_size, | 664 max_levels_(ComputeMipMapCount(max_texture_size, |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1063 } | 1099 } |
1064 } | 1100 } |
1065 return false; | 1101 return false; |
1066 } | 1102 } |
1067 | 1103 |
1068 GLsizei TextureManager::ComputeMipMapCount( | 1104 GLsizei TextureManager::ComputeMipMapCount( |
1069 GLsizei width, GLsizei height, GLsizei depth) { | 1105 GLsizei width, GLsizei height, GLsizei depth) { |
1070 return 1 + base::bits::Log2Floor(std::max(std::max(width, height), depth)); | 1106 return 1 + base::bits::Log2Floor(std::max(std::max(width, height), depth)); |
1071 } | 1107 } |
1072 | 1108 |
| 1109 void TextureManager::SetLevelImage( |
| 1110 TextureManager::TextureInfo* info, |
| 1111 GLenum target, |
| 1112 GLint level, |
| 1113 gfx::GLImage* image) { |
| 1114 DCHECK(info); |
| 1115 if (!info->CanRender(feature_info_)) { |
| 1116 DCHECK_NE(0, num_unrenderable_textures_); |
| 1117 --num_unrenderable_textures_; |
| 1118 } |
| 1119 if (!info->SafeToRenderFrom()) { |
| 1120 DCHECK_NE(0, num_unsafe_textures_); |
| 1121 --num_unsafe_textures_; |
| 1122 } |
| 1123 info->SetLevelImage(feature_info_, target, level, image); |
| 1124 if (!info->CanRender(feature_info_)) { |
| 1125 ++num_unrenderable_textures_; |
| 1126 } |
| 1127 if (!info->SafeToRenderFrom()) { |
| 1128 ++num_unsafe_textures_; |
| 1129 } |
| 1130 } |
| 1131 |
1073 } // namespace gles2 | 1132 } // namespace gles2 |
1074 } // namespace gpu | 1133 } // namespace gpu |
OLD | NEW |