| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 GetMemTracker()->TrackMemAlloc(estimated_size()); | 372 GetMemTracker()->TrackMemAlloc(estimated_size()); |
| 373 } | 373 } |
| 374 } | 374 } |
| 375 | 375 |
| 376 MemoryTypeTracker* Texture::GetMemTracker() { | 376 MemoryTypeTracker* Texture::GetMemTracker() { |
| 377 DCHECK(memory_tracking_ref_); | 377 DCHECK(memory_tracking_ref_); |
| 378 return memory_tracking_ref_->manager()->GetMemTracker(pool_); | 378 return memory_tracking_ref_->manager()->GetMemTracker(pool_); |
| 379 } | 379 } |
| 380 | 380 |
| 381 Texture::LevelInfo::LevelInfo() | 381 Texture::LevelInfo::LevelInfo() |
| 382 : cleared(true), | 382 : target(0), |
| 383 target(0), | |
| 384 level(-1), | 383 level(-1), |
| 385 internal_format(0), | 384 internal_format(0), |
| 386 width(0), | 385 width(0), |
| 387 height(0), | 386 height(0), |
| 388 depth(0), | 387 depth(0), |
| 389 border(0), | 388 border(0), |
| 390 format(0), | 389 format(0), |
| 391 type(0), | 390 type(0), |
| 392 estimated_size(0) { | 391 estimated_size(0) { |
| 393 } | 392 } |
| 394 | 393 |
| 395 Texture::LevelInfo::LevelInfo(const LevelInfo& rhs) | 394 Texture::LevelInfo::LevelInfo(const LevelInfo& rhs) |
| 396 : cleared(rhs.cleared), | 395 : cleared_rect(rhs.cleared_rect), |
| 397 target(rhs.target), | 396 target(rhs.target), |
| 398 level(rhs.level), | 397 level(rhs.level), |
| 399 internal_format(rhs.internal_format), | 398 internal_format(rhs.internal_format), |
| 400 width(rhs.width), | 399 width(rhs.width), |
| 401 height(rhs.height), | 400 height(rhs.height), |
| 402 depth(rhs.depth), | 401 depth(rhs.depth), |
| 403 border(rhs.border), | 402 border(rhs.border), |
| 404 format(rhs.format), | 403 format(rhs.format), |
| 405 type(rhs.type), | 404 type(rhs.type), |
| 406 image(rhs.image), | 405 image(rhs.image), |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 GLsizei height = level0_info.height; | 532 GLsizei height = level0_info.height; |
| 534 GLsizei depth = level0_info.depth; | 533 GLsizei depth = level0_info.depth; |
| 535 GLenum target = target_ == GL_TEXTURE_2D ? GL_TEXTURE_2D : | 534 GLenum target = target_ == GL_TEXTURE_2D ? GL_TEXTURE_2D : |
| 536 GLES2Util::IndexToGLFaceTarget(ii); | 535 GLES2Util::IndexToGLFaceTarget(ii); |
| 537 | 536 |
| 538 const GLsizei num_mips = face_info.num_mip_levels; | 537 const GLsizei num_mips = face_info.num_mip_levels; |
| 539 for (GLsizei level = 1; level < num_mips; ++level) { | 538 for (GLsizei level = 1; level < num_mips; ++level) { |
| 540 width = std::max(1, width >> 1); | 539 width = std::max(1, width >> 1); |
| 541 height = std::max(1, height >> 1); | 540 height = std::max(1, height >> 1); |
| 542 depth = std::max(1, depth >> 1); | 541 depth = std::max(1, depth >> 1); |
| 543 SetLevelInfo(feature_info, | 542 SetLevelInfo(feature_info, target, level, level0_info.internal_format, |
| 544 target, | 543 width, height, depth, level0_info.border, level0_info.format, |
| 545 level, | 544 level0_info.type, gfx::Rect(width, height)); |
| 546 level0_info.internal_format, | |
| 547 width, | |
| 548 height, | |
| 549 depth, | |
| 550 level0_info.border, | |
| 551 level0_info.format, | |
| 552 level0_info.type, | |
| 553 true); | |
| 554 } | 545 } |
| 555 } | 546 } |
| 556 | 547 |
| 557 return true; | 548 return true; |
| 558 } | 549 } |
| 559 | 550 |
| 560 void Texture::SetTarget( | 551 void Texture::SetTarget( |
| 561 const FeatureInfo* feature_info, GLenum target, GLint max_levels) { | 552 const FeatureInfo* feature_info, GLenum target, GLint max_levels) { |
| 562 DCHECK_EQ(0u, target_); // you can only set this once. | 553 DCHECK_EQ(0u, target_); // you can only set this once. |
| 563 target_ = target; | 554 target_ = target; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 complete &= (width == mip_width && | 649 complete &= (width == mip_width && |
| 659 height == mip_height && | 650 height == mip_height && |
| 660 depth == mip_depth && | 651 depth == mip_depth && |
| 661 internal_format == level0_face.internal_format && | 652 internal_format == level0_face.internal_format && |
| 662 format == level0_face.format && | 653 format == level0_face.format && |
| 663 type == level0_face.type); | 654 type == level0_face.type); |
| 664 } | 655 } |
| 665 return complete; | 656 return complete; |
| 666 } | 657 } |
| 667 | 658 |
| 668 void Texture::SetLevelCleared(GLenum target, GLint level, bool cleared) { | 659 void Texture::SetLevelClearedRect(GLenum target, |
| 660 GLint level, |
| 661 const gfx::Rect& cleared_rect) { |
| 669 DCHECK_GE(level, 0); | 662 DCHECK_GE(level, 0); |
| 670 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 663 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
| 671 DCHECK_LT(static_cast<size_t>(face_index), | 664 DCHECK_LT(static_cast<size_t>(face_index), |
| 672 face_infos_.size()); | 665 face_infos_.size()); |
| 673 DCHECK_LT(static_cast<size_t>(level), | 666 DCHECK_LT(static_cast<size_t>(level), |
| 674 face_infos_[face_index].level_infos.size()); | 667 face_infos_[face_index].level_infos.size()); |
| 675 Texture::LevelInfo& info = | 668 Texture::LevelInfo& info = |
| 676 face_infos_[face_index].level_infos[level]; | 669 face_infos_[face_index].level_infos[level]; |
| 677 UpdateMipCleared(&info, cleared); | 670 UpdateMipCleared(&info, info.width, info.height, cleared_rect); |
| 678 UpdateCleared(); | 671 UpdateCleared(); |
| 679 } | 672 } |
| 680 | 673 |
| 674 void Texture::SetLevelCleared(GLenum target, GLint level, bool cleared) { |
| 675 DCHECK_GE(level, 0); |
| 676 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
| 677 DCHECK_LT(static_cast<size_t>(face_index), face_infos_.size()); |
| 678 DCHECK_LT(static_cast<size_t>(level), |
| 679 face_infos_[face_index].level_infos.size()); |
| 680 Texture::LevelInfo& info = face_infos_[face_index].level_infos[level]; |
| 681 UpdateMipCleared(&info, info.width, info.height, |
| 682 cleared ? gfx::Rect(info.width, info.height) : gfx::Rect()); |
| 683 UpdateCleared(); |
| 684 } |
| 685 |
| 681 void Texture::UpdateCleared() { | 686 void Texture::UpdateCleared() { |
| 682 if (face_infos_.empty()) { | 687 if (face_infos_.empty()) { |
| 683 return; | 688 return; |
| 684 } | 689 } |
| 685 | 690 |
| 686 const bool cleared = (num_uncleared_mips_ == 0); | 691 const bool cleared = (num_uncleared_mips_ == 0); |
| 687 | 692 |
| 688 // If texture is uncleared and is attached to a framebuffer, | 693 // If texture is uncleared and is attached to a framebuffer, |
| 689 // that framebuffer must be marked possibly incomplete. | 694 // that framebuffer must be marked possibly incomplete. |
| 690 if (!cleared && IsAttachedToFramebuffer()) { | 695 if (!cleared && IsAttachedToFramebuffer()) { |
| 691 IncAllFramebufferStateChangeCount(); | 696 IncAllFramebufferStateChangeCount(); |
| 692 } | 697 } |
| 693 | 698 |
| 694 UpdateSafeToRenderFrom(cleared); | 699 UpdateSafeToRenderFrom(cleared); |
| 695 } | 700 } |
| 696 | 701 |
| 697 void Texture::UpdateSafeToRenderFrom(bool cleared) { | 702 void Texture::UpdateSafeToRenderFrom(bool cleared) { |
| 698 if (cleared_ == cleared) | 703 if (cleared_ == cleared) |
| 699 return; | 704 return; |
| 700 cleared_ = cleared; | 705 cleared_ = cleared; |
| 701 int delta = cleared ? -1 : +1; | 706 int delta = cleared ? -1 : +1; |
| 702 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) | 707 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) |
| 703 (*it)->manager()->UpdateSafeToRenderFrom(delta); | 708 (*it)->manager()->UpdateSafeToRenderFrom(delta); |
| 704 } | 709 } |
| 705 | 710 |
| 706 void Texture::UpdateMipCleared(LevelInfo* info, bool cleared) { | 711 void Texture::UpdateMipCleared(LevelInfo* info, |
| 707 if (info->cleared == cleared) | 712 GLsizei width, |
| 713 GLsizei height, |
| 714 const gfx::Rect& cleared_rect) { |
| 715 bool was_cleared = info->cleared_rect == gfx::Rect(info->width, info->height); |
| 716 info->width = width; |
| 717 info->height = height; |
| 718 info->cleared_rect = cleared_rect; |
| 719 bool cleared = info->cleared_rect == gfx::Rect(info->width, info->height); |
| 720 if (cleared == was_cleared) |
| 708 return; | 721 return; |
| 709 info->cleared = cleared; | |
| 710 int delta = cleared ? -1 : +1; | 722 int delta = cleared ? -1 : +1; |
| 711 num_uncleared_mips_ += delta; | 723 num_uncleared_mips_ += delta; |
| 712 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) | 724 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) |
| 713 (*it)->manager()->UpdateUnclearedMips(delta); | 725 (*it)->manager()->UpdateUnclearedMips(delta); |
| 714 } | 726 } |
| 715 | 727 |
| 716 void Texture::UpdateCanRenderCondition() { | 728 void Texture::UpdateCanRenderCondition() { |
| 717 CanRenderCondition can_render_condition = GetCanRenderCondition(); | 729 CanRenderCondition can_render_condition = GetCanRenderCondition(); |
| 718 if (can_render_condition_ == can_render_condition) | 730 if (can_render_condition_ == can_render_condition) |
| 719 return; | 731 return; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 744 int delta = has_images ? +1 : -1; | 756 int delta = has_images ? +1 : -1; |
| 745 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) | 757 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) |
| 746 (*it)->manager()->UpdateNumImages(delta); | 758 (*it)->manager()->UpdateNumImages(delta); |
| 747 } | 759 } |
| 748 | 760 |
| 749 void Texture::IncAllFramebufferStateChangeCount() { | 761 void Texture::IncAllFramebufferStateChangeCount() { |
| 750 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) | 762 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) |
| 751 (*it)->manager()->IncFramebufferStateChangeCount(); | 763 (*it)->manager()->IncFramebufferStateChangeCount(); |
| 752 } | 764 } |
| 753 | 765 |
| 754 void Texture::SetLevelInfo( | 766 void Texture::SetLevelInfo(const FeatureInfo* feature_info, |
| 755 const FeatureInfo* feature_info, | 767 GLenum target, |
| 756 GLenum target, | 768 GLint level, |
| 757 GLint level, | 769 GLenum internal_format, |
| 758 GLenum internal_format, | 770 GLsizei width, |
| 759 GLsizei width, | 771 GLsizei height, |
| 760 GLsizei height, | 772 GLsizei depth, |
| 761 GLsizei depth, | 773 GLint border, |
| 762 GLint border, | 774 GLenum format, |
| 763 GLenum format, | 775 GLenum type, |
| 764 GLenum type, | 776 const gfx::Rect& cleared_rect) { |
| 765 bool cleared) { | |
| 766 DCHECK_GE(level, 0); | 777 DCHECK_GE(level, 0); |
| 767 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 778 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
| 768 DCHECK_LT(static_cast<size_t>(face_index), | 779 DCHECK_LT(static_cast<size_t>(face_index), |
| 769 face_infos_.size()); | 780 face_infos_.size()); |
| 770 DCHECK_LT(static_cast<size_t>(level), | 781 DCHECK_LT(static_cast<size_t>(level), |
| 771 face_infos_[face_index].level_infos.size()); | 782 face_infos_[face_index].level_infos.size()); |
| 772 DCHECK_GE(width, 0); | 783 DCHECK_GE(width, 0); |
| 773 DCHECK_GE(height, 0); | 784 DCHECK_GE(height, 0); |
| 774 DCHECK_GE(depth, 0); | 785 DCHECK_GE(depth, 0); |
| 775 Texture::LevelInfo& info = | 786 Texture::LevelInfo& info = |
| (...skipping 24 matching lines...) Expand all Loading... |
| 800 texture_level0_dirty_ = true; | 811 texture_level0_dirty_ = true; |
| 801 } | 812 } |
| 802 | 813 |
| 803 // Signify that at least one of the mips has changed. | 814 // Signify that at least one of the mips has changed. |
| 804 texture_mips_dirty_ = true; | 815 texture_mips_dirty_ = true; |
| 805 } | 816 } |
| 806 | 817 |
| 807 info.target = target; | 818 info.target = target; |
| 808 info.level = level; | 819 info.level = level; |
| 809 info.internal_format = internal_format; | 820 info.internal_format = internal_format; |
| 810 info.width = width; | |
| 811 info.height = height; | |
| 812 info.depth = depth; | 821 info.depth = depth; |
| 813 info.border = border; | 822 info.border = border; |
| 814 info.format = format; | 823 info.format = format; |
| 815 info.type = type; | 824 info.type = type; |
| 816 info.image = 0; | 825 info.image = 0; |
| 817 | 826 |
| 827 UpdateMipCleared(&info, width, height, cleared_rect); |
| 828 |
| 818 estimated_size_ -= info.estimated_size; | 829 estimated_size_ -= info.estimated_size; |
| 819 GLES2Util::ComputeImageDataSizes( | 830 GLES2Util::ComputeImageDataSizes( |
| 820 width, height, 1, format, type, 4, &info.estimated_size, NULL, NULL); | 831 width, height, 1, format, type, 4, &info.estimated_size, NULL, NULL); |
| 821 estimated_size_ += info.estimated_size; | 832 estimated_size_ += info.estimated_size; |
| 822 | 833 |
| 823 UpdateMipCleared(&info, cleared); | |
| 824 max_level_set_ = std::max(max_level_set_, level); | 834 max_level_set_ = std::max(max_level_set_, level); |
| 825 Update(feature_info); | 835 Update(feature_info); |
| 826 UpdateCleared(); | 836 UpdateCleared(); |
| 827 UpdateCanRenderCondition(); | 837 UpdateCanRenderCondition(); |
| 828 UpdateHasImages(); | 838 UpdateHasImages(); |
| 829 if (IsAttachedToFramebuffer()) { | 839 if (IsAttachedToFramebuffer()) { |
| 830 // TODO(gman): If textures tracked which framebuffers they were attached to | 840 // TODO(gman): If textures tracked which framebuffers they were attached to |
| 831 // we could just mark those framebuffers as not complete. | 841 // we could just mark those framebuffers as not complete. |
| 832 IncAllFramebufferStateChangeCount(); | 842 IncAllFramebufferStateChangeCount(); |
| 833 } | 843 } |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1139 if (!ClearLevel(decoder, info.target, jj)) { | 1149 if (!ClearLevel(decoder, info.target, jj)) { |
| 1140 return false; | 1150 return false; |
| 1141 } | 1151 } |
| 1142 } | 1152 } |
| 1143 } | 1153 } |
| 1144 } | 1154 } |
| 1145 UpdateSafeToRenderFrom(true); | 1155 UpdateSafeToRenderFrom(true); |
| 1146 return true; | 1156 return true; |
| 1147 } | 1157 } |
| 1148 | 1158 |
| 1159 gfx::Rect Texture::GetLevelClearedRect(GLenum target, GLint level) const { |
| 1160 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
| 1161 if (face_index >= face_infos_.size() || |
| 1162 level >= static_cast<GLint>(face_infos_[face_index].level_infos.size())) { |
| 1163 return gfx::Rect(); |
| 1164 } |
| 1165 |
| 1166 const Texture::LevelInfo& info = face_infos_[face_index].level_infos[level]; |
| 1167 |
| 1168 return info.cleared_rect; |
| 1169 } |
| 1170 |
| 1149 bool Texture::IsLevelCleared(GLenum target, GLint level) const { | 1171 bool Texture::IsLevelCleared(GLenum target, GLint level) const { |
| 1150 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 1172 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
| 1151 if (face_index >= face_infos_.size() || | 1173 if (face_index >= face_infos_.size() || |
| 1152 level >= static_cast<GLint>(face_infos_[face_index].level_infos.size())) { | 1174 level >= static_cast<GLint>(face_infos_[face_index].level_infos.size())) { |
| 1153 return true; | 1175 return true; |
| 1154 } | 1176 } |
| 1155 | 1177 |
| 1156 const Texture::LevelInfo& info = face_infos_[face_index].level_infos[level]; | 1178 const Texture::LevelInfo& info = face_infos_[face_index].level_infos[level]; |
| 1157 | 1179 |
| 1158 return info.cleared; | 1180 return info.cleared_rect == gfx::Rect(info.width, info.height); |
| 1159 } | 1181 } |
| 1160 | 1182 |
| 1161 void Texture::InitTextureMaxAnisotropyIfNeeded(GLenum target) { | 1183 void Texture::InitTextureMaxAnisotropyIfNeeded(GLenum target) { |
| 1162 if (texture_max_anisotropy_initialized_) | 1184 if (texture_max_anisotropy_initialized_) |
| 1163 return; | 1185 return; |
| 1164 texture_max_anisotropy_initialized_ = true; | 1186 texture_max_anisotropy_initialized_ = true; |
| 1165 GLfloat params[] = { 1.0f }; | 1187 GLfloat params[] = { 1.0f }; |
| 1166 glTexParameterfv(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, params); | 1188 glTexParameterfv(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, params); |
| 1167 } | 1189 } |
| 1168 | 1190 |
| 1169 bool Texture::ClearLevel( | 1191 bool Texture::ClearLevel( |
| 1170 GLES2Decoder* decoder, GLenum target, GLint level) { | 1192 GLES2Decoder* decoder, GLenum target, GLint level) { |
| 1171 DCHECK(decoder); | 1193 DCHECK(decoder); |
| 1172 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 1194 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
| 1173 if (face_index >= face_infos_.size() || | 1195 if (face_index >= face_infos_.size() || |
| 1174 level >= static_cast<GLint>(face_infos_[face_index].level_infos.size())) { | 1196 level >= static_cast<GLint>(face_infos_[face_index].level_infos.size())) { |
| 1175 return true; | 1197 return true; |
| 1176 } | 1198 } |
| 1177 | 1199 |
| 1178 Texture::LevelInfo& info = face_infos_[face_index].level_infos[level]; | 1200 Texture::LevelInfo& info = face_infos_[face_index].level_infos[level]; |
| 1179 | 1201 |
| 1180 DCHECK(target == info.target); | 1202 DCHECK(target == info.target); |
| 1181 | 1203 |
| 1182 if (info.target == 0 || | 1204 if (info.target == 0 || |
| 1183 info.cleared || | 1205 info.cleared_rect == gfx::Rect(info.width, info.height) || |
| 1184 info.width == 0 || | 1206 info.width == 0 || info.height == 0 || info.depth == 0) { |
| 1185 info.height == 0 || | |
| 1186 info.depth == 0) { | |
| 1187 return true; | 1207 return true; |
| 1188 } | 1208 } |
| 1189 | 1209 |
| 1190 // NOTE: It seems kind of gross to call back into the decoder for this | 1210 // Clear all remaining sub regions. |
| 1191 // but only the decoder knows all the state (like unpack_alignment_) that's | 1211 const int x[] = { |
| 1192 // needed to be able to call GL correctly. | 1212 0, info.cleared_rect.x(), info.cleared_rect.right(), info.width}; |
| 1193 bool cleared = decoder->ClearLevel( | 1213 const int y[] = { |
| 1194 this, info.target, info.level, info.internal_format, info.format, | 1214 0, info.cleared_rect.y(), info.cleared_rect.bottom(), info.height}; |
| 1195 info.type, info.width, info.height, immutable_); | 1215 |
| 1196 UpdateMipCleared(&info, cleared); | 1216 for (size_t j = 0; j < 3; ++j) { |
| 1197 return info.cleared; | 1217 for (size_t i = 0; i < 3; ++i) { |
| 1218 // Center of nine patch is already cleared. |
| 1219 if (j == 1 && i == 1) |
| 1220 continue; |
| 1221 |
| 1222 gfx::Rect rect(x[i], y[j], x[i + 1] - x[i], y[j + 1] - y[j]); |
| 1223 if (rect.IsEmpty()) |
| 1224 continue; |
| 1225 |
| 1226 // NOTE: It seems kind of gross to call back into the decoder for this |
| 1227 // but only the decoder knows all the state (like unpack_alignment_) |
| 1228 // that's needed to be able to call GL correctly. |
| 1229 bool cleared = decoder->ClearLevel(this, info.target, info.level, |
| 1230 info.format, info.type, rect.x(), |
| 1231 rect.y(), rect.width(), rect.height()); |
| 1232 if (!cleared) |
| 1233 return false; |
| 1234 } |
| 1235 } |
| 1236 |
| 1237 UpdateMipCleared(&info, info.width, info.height, |
| 1238 gfx::Rect(info.width, info.height)); |
| 1239 return true; |
| 1198 } | 1240 } |
| 1199 | 1241 |
| 1200 void Texture::SetLevelImage( | 1242 void Texture::SetLevelImage( |
| 1201 const FeatureInfo* feature_info, | 1243 const FeatureInfo* feature_info, |
| 1202 GLenum target, | 1244 GLenum target, |
| 1203 GLint level, | 1245 GLint level, |
| 1204 gfx::GLImage* image) { | 1246 gfx::GLImage* image) { |
| 1205 DCHECK_GE(level, 0); | 1247 DCHECK_GE(level, 0); |
| 1206 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 1248 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
| 1207 DCHECK_LT(static_cast<size_t>(face_index), | 1249 DCHECK_LT(static_cast<size_t>(face_index), |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1366 } | 1408 } |
| 1367 } | 1409 } |
| 1368 glBindTexture(target, 0); | 1410 glBindTexture(target, 0); |
| 1369 | 1411 |
| 1370 scoped_refptr<TextureRef> default_texture; | 1412 scoped_refptr<TextureRef> default_texture; |
| 1371 if (use_default_textures_) { | 1413 if (use_default_textures_) { |
| 1372 default_texture = TextureRef::Create(this, 0, ids[1]); | 1414 default_texture = TextureRef::Create(this, 0, ids[1]); |
| 1373 SetTarget(default_texture.get(), target); | 1415 SetTarget(default_texture.get(), target); |
| 1374 if (needs_faces) { | 1416 if (needs_faces) { |
| 1375 for (int ii = 0; ii < GLES2Util::kNumFaces; ++ii) { | 1417 for (int ii = 0; ii < GLES2Util::kNumFaces; ++ii) { |
| 1376 SetLevelInfo(default_texture.get(), | 1418 SetLevelInfo(default_texture.get(), GLES2Util::IndexToGLFaceTarget(ii), |
| 1377 GLES2Util::IndexToGLFaceTarget(ii), | 1419 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 1378 0, | 1420 gfx::Rect(1, 1)); |
| 1379 GL_RGBA, | |
| 1380 1, | |
| 1381 1, | |
| 1382 1, | |
| 1383 0, | |
| 1384 GL_RGBA, | |
| 1385 GL_UNSIGNED_BYTE, | |
| 1386 true); | |
| 1387 } | 1421 } |
| 1388 } else { | 1422 } else { |
| 1389 if (needs_initialization) { | 1423 if (needs_initialization) { |
| 1390 SetLevelInfo(default_texture.get(), | 1424 SetLevelInfo(default_texture.get(), GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, |
| 1391 GL_TEXTURE_2D, | 1425 0, GL_RGBA, GL_UNSIGNED_BYTE, gfx::Rect(1, 1)); |
| 1392 0, | |
| 1393 GL_RGBA, | |
| 1394 1, | |
| 1395 1, | |
| 1396 1, | |
| 1397 0, | |
| 1398 GL_RGBA, | |
| 1399 GL_UNSIGNED_BYTE, | |
| 1400 true); | |
| 1401 } else { | 1426 } else { |
| 1402 SetLevelInfo(default_texture.get(), | 1427 SetLevelInfo(default_texture.get(), GL_TEXTURE_EXTERNAL_OES, 0, GL_RGBA, |
| 1403 GL_TEXTURE_EXTERNAL_OES, | 1428 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, gfx::Rect(1, 1)); |
| 1404 0, | |
| 1405 GL_RGBA, | |
| 1406 1, | |
| 1407 1, | |
| 1408 1, | |
| 1409 0, | |
| 1410 GL_RGBA, | |
| 1411 GL_UNSIGNED_BYTE, | |
| 1412 true); | |
| 1413 } | 1429 } |
| 1414 } | 1430 } |
| 1415 } | 1431 } |
| 1416 | 1432 |
| 1417 *black_texture = ids[0]; | 1433 *black_texture = ids[0]; |
| 1418 return default_texture; | 1434 return default_texture; |
| 1419 } | 1435 } |
| 1420 | 1436 |
| 1421 bool TextureManager::ValidForTarget( | 1437 bool TextureManager::ValidForTarget( |
| 1422 GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth) { | 1438 GLenum target, GLint level, GLsizei width, GLsizei height, GLsizei depth) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1436 (target != GL_TEXTURE_CUBE_MAP || (width == height && depth == 1)) && | 1452 (target != GL_TEXTURE_CUBE_MAP || (width == height && depth == 1)) && |
| 1437 (target != GL_TEXTURE_2D || (depth == 1)); | 1453 (target != GL_TEXTURE_2D || (depth == 1)); |
| 1438 } | 1454 } |
| 1439 | 1455 |
| 1440 void TextureManager::SetTarget(TextureRef* ref, GLenum target) { | 1456 void TextureManager::SetTarget(TextureRef* ref, GLenum target) { |
| 1441 DCHECK(ref); | 1457 DCHECK(ref); |
| 1442 ref->texture() | 1458 ref->texture() |
| 1443 ->SetTarget(feature_info_.get(), target, MaxLevelsForTarget(target)); | 1459 ->SetTarget(feature_info_.get(), target, MaxLevelsForTarget(target)); |
| 1444 } | 1460 } |
| 1445 | 1461 |
| 1462 void TextureManager::SetLevelClearedRect(TextureRef* ref, |
| 1463 GLenum target, |
| 1464 GLint level, |
| 1465 const gfx::Rect& cleared_rect) { |
| 1466 DCHECK(ref); |
| 1467 ref->texture()->SetLevelClearedRect(target, level, cleared_rect); |
| 1468 } |
| 1469 |
| 1446 void TextureManager::SetLevelCleared(TextureRef* ref, | 1470 void TextureManager::SetLevelCleared(TextureRef* ref, |
| 1447 GLenum target, | 1471 GLenum target, |
| 1448 GLint level, | 1472 GLint level, |
| 1449 bool cleared) { | 1473 bool cleared) { |
| 1450 DCHECK(ref); | 1474 DCHECK(ref); |
| 1451 ref->texture()->SetLevelCleared(target, level, cleared); | 1475 ref->texture()->SetLevelCleared(target, level, cleared); |
| 1452 } | 1476 } |
| 1453 | 1477 |
| 1454 bool TextureManager::ClearRenderableLevels( | 1478 bool TextureManager::ClearRenderableLevels( |
| 1455 GLES2Decoder* decoder, TextureRef* ref) { | 1479 GLES2Decoder* decoder, TextureRef* ref) { |
| 1456 DCHECK(ref); | 1480 DCHECK(ref); |
| 1457 return ref->texture()->ClearRenderableLevels(decoder); | 1481 return ref->texture()->ClearRenderableLevels(decoder); |
| 1458 } | 1482 } |
| 1459 | 1483 |
| 1460 bool TextureManager::ClearTextureLevel( | 1484 bool TextureManager::ClearTextureLevel( |
| 1461 GLES2Decoder* decoder, TextureRef* ref, | 1485 GLES2Decoder* decoder, TextureRef* ref, |
| 1462 GLenum target, GLint level) { | 1486 GLenum target, GLint level) { |
| 1463 DCHECK(ref); | 1487 DCHECK(ref); |
| 1464 Texture* texture = ref->texture(); | 1488 Texture* texture = ref->texture(); |
| 1465 if (texture->num_uncleared_mips() == 0) { | 1489 if (texture->num_uncleared_mips() == 0) { |
| 1466 return true; | 1490 return true; |
| 1467 } | 1491 } |
| 1468 bool result = texture->ClearLevel(decoder, target, level); | 1492 bool result = texture->ClearLevel(decoder, target, level); |
| 1469 texture->UpdateCleared(); | 1493 texture->UpdateCleared(); |
| 1470 return result; | 1494 return result; |
| 1471 } | 1495 } |
| 1472 | 1496 |
| 1473 void TextureManager::SetLevelInfo( | 1497 void TextureManager::SetLevelInfo(TextureRef* ref, |
| 1474 TextureRef* ref, | 1498 GLenum target, |
| 1475 GLenum target, | 1499 GLint level, |
| 1476 GLint level, | 1500 GLenum internal_format, |
| 1477 GLenum internal_format, | 1501 GLsizei width, |
| 1478 GLsizei width, | 1502 GLsizei height, |
| 1479 GLsizei height, | 1503 GLsizei depth, |
| 1480 GLsizei depth, | 1504 GLint border, |
| 1481 GLint border, | 1505 GLenum format, |
| 1482 GLenum format, | 1506 GLenum type, |
| 1483 GLenum type, | 1507 const gfx::Rect& cleared_rect) { |
| 1484 bool cleared) { | 1508 DCHECK(gfx::Rect(width, height).Contains(cleared_rect)); |
| 1485 DCHECK(ref); | 1509 DCHECK(ref); |
| 1486 Texture* texture = ref->texture(); | 1510 Texture* texture = ref->texture(); |
| 1487 | 1511 |
| 1488 texture->GetMemTracker()->TrackMemFree(texture->estimated_size()); | 1512 texture->GetMemTracker()->TrackMemFree(texture->estimated_size()); |
| 1489 texture->SetLevelInfo(feature_info_.get(), | 1513 texture->SetLevelInfo(feature_info_.get(), target, level, internal_format, |
| 1490 target, | 1514 width, height, depth, border, format, type, |
| 1491 level, | 1515 cleared_rect); |
| 1492 internal_format, | |
| 1493 width, | |
| 1494 height, | |
| 1495 depth, | |
| 1496 border, | |
| 1497 format, | |
| 1498 type, | |
| 1499 cleared); | |
| 1500 texture->GetMemTracker()->TrackMemAlloc(texture->estimated_size()); | 1516 texture->GetMemTracker()->TrackMemAlloc(texture->estimated_size()); |
| 1501 } | 1517 } |
| 1502 | 1518 |
| 1503 Texture* TextureManager::Produce(TextureRef* ref) { | 1519 Texture* TextureManager::Produce(TextureRef* ref) { |
| 1504 DCHECK(ref); | 1520 DCHECK(ref); |
| 1505 return ref->texture(); | 1521 return ref->texture(); |
| 1506 } | 1522 } |
| 1507 | 1523 |
| 1508 TextureRef* TextureManager::Consume( | 1524 TextureRef* TextureManager::Consume( |
| 1509 GLuint client_id, | 1525 GLuint client_id, |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1940 bool level_is_same = | 1956 bool level_is_same = |
| 1941 texture->GetLevelSize( | 1957 texture->GetLevelSize( |
| 1942 args.target, args.level, &tex_width, &tex_height, &tex_depth) && | 1958 args.target, args.level, &tex_width, &tex_height, &tex_depth) && |
| 1943 texture->GetLevelType(args.target, args.level, &tex_type, &tex_format) && | 1959 texture->GetLevelType(args.target, args.level, &tex_type, &tex_format) && |
| 1944 args.width == tex_width && args.height == tex_height && | 1960 args.width == tex_width && args.height == tex_height && |
| 1945 args.depth == tex_depth && args.type == tex_type && | 1961 args.depth == tex_depth && args.type == tex_type && |
| 1946 args.format == tex_format; | 1962 args.format == tex_format; |
| 1947 | 1963 |
| 1948 if (level_is_same && !args.pixels) { | 1964 if (level_is_same && !args.pixels) { |
| 1949 // Just set the level texture but mark the texture as uncleared. | 1965 // Just set the level texture but mark the texture as uncleared. |
| 1950 SetLevelInfo( | 1966 SetLevelInfo(texture_ref, args.target, args.level, args.internal_format, |
| 1951 texture_ref, | 1967 args.width, args.height, args.depth, args.border, args.format, |
| 1952 args.target, args.level, args.internal_format, args.width, args.height, | 1968 args.type, gfx::Rect()); |
| 1953 args.depth, args.border, args.format, args.type, false); | |
| 1954 texture_state->tex_image_failed = false; | 1969 texture_state->tex_image_failed = false; |
| 1955 return; | 1970 return; |
| 1956 } | 1971 } |
| 1957 | 1972 |
| 1958 if (texture->IsAttachedToFramebuffer()) { | 1973 if (texture->IsAttachedToFramebuffer()) { |
| 1959 framebuffer_state->clear_state_dirty = true; | 1974 framebuffer_state->clear_state_dirty = true; |
| 1960 } | 1975 } |
| 1961 | 1976 |
| 1962 if (texture_state->texsubimage_faster_than_teximage && | 1977 if (texture_state->texsubimage_faster_than_teximage && |
| 1963 level_is_same && args.pixels) { | 1978 level_is_same && args.pixels) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1986 args.type, args.pixels); | 2001 args.type, args.pixels); |
| 1987 } else { | 2002 } else { |
| 1988 glTexImage2D(args.target, args.level, args.internal_format, args.width, | 2003 glTexImage2D(args.target, args.level, args.internal_format, args.width, |
| 1989 args.height, args.border, AdjustTexFormat(args.format), | 2004 args.height, args.border, AdjustTexFormat(args.format), |
| 1990 args.type, args.pixels); | 2005 args.type, args.pixels); |
| 1991 } | 2006 } |
| 1992 } | 2007 } |
| 1993 GLenum error = ERRORSTATE_PEEK_GL_ERROR(error_state, function_name); | 2008 GLenum error = ERRORSTATE_PEEK_GL_ERROR(error_state, function_name); |
| 1994 if (error == GL_NO_ERROR) { | 2009 if (error == GL_NO_ERROR) { |
| 1995 SetLevelInfo( | 2010 SetLevelInfo( |
| 1996 texture_ref, | 2011 texture_ref, args.target, args.level, args.internal_format, args.width, |
| 1997 args.target, args.level, args.internal_format, args.width, args.height, | 2012 args.height, args.depth, args.border, args.format, args.type, |
| 1998 args.depth, args.border, args.format, args.type, args.pixels != NULL); | 2013 args.pixels != NULL ? gfx::Rect(args.width, args.height) : gfx::Rect()); |
| 1999 texture_state->tex_image_failed = false; | 2014 texture_state->tex_image_failed = false; |
| 2000 } | 2015 } |
| 2001 } | 2016 } |
| 2002 | 2017 |
| 2003 ScopedTextureUploadTimer::ScopedTextureUploadTimer( | 2018 ScopedTextureUploadTimer::ScopedTextureUploadTimer( |
| 2004 DecoderTextureState* texture_state) | 2019 DecoderTextureState* texture_state) |
| 2005 : texture_state_(texture_state), | 2020 : texture_state_(texture_state), |
| 2006 begin_time_(base::TimeTicks::Now()) { | 2021 begin_time_(base::TimeTicks::Now()) { |
| 2007 } | 2022 } |
| 2008 | 2023 |
| 2009 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() { | 2024 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() { |
| 2010 texture_state_->texture_upload_count++; | 2025 texture_state_->texture_upload_count++; |
| 2011 texture_state_->total_texture_upload_time += | 2026 texture_state_->total_texture_upload_time += |
| 2012 base::TimeTicks::Now() - begin_time_; | 2027 base::TimeTicks::Now() - begin_time_; |
| 2013 } | 2028 } |
| 2014 | 2029 |
| 2015 } // namespace gles2 | 2030 } // namespace gles2 |
| 2016 } // namespace gpu | 2031 } // namespace gpu |
| OLD | NEW |