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 <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bits.h" | 10 #include "base/bits.h" |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 info.border = border; | 622 info.border = border; |
623 info.format = format; | 623 info.format = format; |
624 info.type = type; | 624 info.type = type; |
625 info.image = 0; | 625 info.image = 0; |
626 | 626 |
627 estimated_size_ -= info.estimated_size; | 627 estimated_size_ -= info.estimated_size; |
628 GLES2Util::ComputeImageDataSizes( | 628 GLES2Util::ComputeImageDataSizes( |
629 width, height, format, type, 4, &info.estimated_size, NULL, NULL); | 629 width, height, format, type, 4, &info.estimated_size, NULL, NULL); |
630 estimated_size_ += info.estimated_size; | 630 estimated_size_ += info.estimated_size; |
631 | 631 |
| 632 UpdateLevelInfo(info, feature_info, level, cleared); |
| 633 } |
| 634 |
| 635 void Texture::SetCompressedLevelInfo(const FeatureInfo* feature_info, |
| 636 GLenum target, |
| 637 GLint level, |
| 638 GLenum internal_format, |
| 639 GLsizei width, |
| 640 GLsizei height, |
| 641 GLsizei depth, |
| 642 GLint border, |
| 643 GLsizei image_size, |
| 644 bool cleared) { |
| 645 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
| 646 DCHECK_GE(level, 0); |
| 647 DCHECK_LT(static_cast<size_t>(face_index), face_infos_.size()); |
| 648 DCHECK_LT(static_cast<size_t>(level), |
| 649 face_infos_[face_index].level_infos.size()); |
| 650 DCHECK_GE(width, 0); |
| 651 DCHECK_GE(height, 0); |
| 652 DCHECK_GE(depth, 0); |
| 653 DCHECK_EQ(border, 0); |
| 654 Texture::LevelInfo& info = face_infos_[face_index].level_infos[level]; |
| 655 info.target = target; |
| 656 info.level = level; |
| 657 info.internal_format = internal_format; |
| 658 info.width = width; |
| 659 info.height = height; |
| 660 info.depth = depth; |
| 661 info.border = border; |
| 662 // TODO(peterp): Compressed formats only have the internal format and no type, |
| 663 // but we could potentially have a lookup table to figure that out. |
| 664 // In practice it seems to work ok to always treat compressed formats as |
| 665 // RGBA + UNSIGNED_BYTE through. |
| 666 info.format = GL_RGBA; |
| 667 info.type = GL_UNSIGNED_BYTE; |
| 668 info.image = 0; |
| 669 |
| 670 estimated_size_ -= info.estimated_size; |
| 671 info.estimated_size = image_size; |
| 672 estimated_size_ += info.estimated_size; |
| 673 |
| 674 UpdateLevelInfo(info, feature_info, level, cleared); |
| 675 } |
| 676 |
| 677 void Texture::UpdateLevelInfo(Texture::LevelInfo& info, |
| 678 const FeatureInfo* feature_info, |
| 679 GLint level, |
| 680 bool cleared) { |
632 UpdateMipCleared(&info, cleared); | 681 UpdateMipCleared(&info, cleared); |
633 max_level_set_ = std::max(max_level_set_, level); | 682 max_level_set_ = std::max(max_level_set_, level); |
634 Update(feature_info); | 683 Update(feature_info); |
635 UpdateCleared(); | 684 UpdateCleared(); |
636 UpdateCanRenderCondition(); | 685 UpdateCanRenderCondition(); |
637 UpdateHasImages(); | 686 UpdateHasImages(); |
638 if (IsAttachedToFramebuffer()) { | 687 if (IsAttachedToFramebuffer()) { |
639 // TODO(gman): If textures tracked which framebuffers they were attached to | 688 // TODO(gman): If textures tracked which framebuffers they were attached to |
640 // we could just mark those framebuffers as not complete. | 689 // we could just mark those framebuffers as not complete. |
641 IncAllFramebufferStateChangeCount(); | 690 IncAllFramebufferStateChangeCount(); |
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1237 width, | 1286 width, |
1238 height, | 1287 height, |
1239 depth, | 1288 depth, |
1240 border, | 1289 border, |
1241 format, | 1290 format, |
1242 type, | 1291 type, |
1243 cleared); | 1292 cleared); |
1244 texture->GetMemTracker()->TrackMemAlloc(texture->estimated_size()); | 1293 texture->GetMemTracker()->TrackMemAlloc(texture->estimated_size()); |
1245 } | 1294 } |
1246 | 1295 |
| 1296 void TextureManager::SetCompressedLevelInfo(TextureRef* ref, |
| 1297 GLenum target, |
| 1298 GLint level, |
| 1299 GLenum internal_format, |
| 1300 GLsizei width, |
| 1301 GLsizei height, |
| 1302 GLsizei depth, |
| 1303 GLint border, |
| 1304 GLsizei image_size, |
| 1305 bool cleared) { |
| 1306 DCHECK(ref); |
| 1307 Texture* texture = ref->texture(); |
| 1308 |
| 1309 texture->GetMemTracker()->TrackMemFree(texture->estimated_size()); |
| 1310 texture->SetCompressedLevelInfo(feature_info_.get(), target, level, |
| 1311 internal_format, width, height, depth, border, |
| 1312 image_size, cleared); |
| 1313 texture->GetMemTracker()->TrackMemAlloc(texture->estimated_size()); |
| 1314 } |
| 1315 |
1247 Texture* TextureManager::Produce(TextureRef* ref) { | 1316 Texture* TextureManager::Produce(TextureRef* ref) { |
1248 DCHECK(ref); | 1317 DCHECK(ref); |
1249 return ref->texture(); | 1318 return ref->texture(); |
1250 } | 1319 } |
1251 | 1320 |
1252 TextureRef* TextureManager::Consume( | 1321 TextureRef* TextureManager::Consume( |
1253 GLuint client_id, | 1322 GLuint client_id, |
1254 Texture* texture) { | 1323 Texture* texture) { |
1255 DCHECK(client_id); | 1324 DCHECK(client_id); |
1256 scoped_refptr<TextureRef> ref(new TextureRef(this, client_id, texture)); | 1325 scoped_refptr<TextureRef> ref(new TextureRef(this, client_id, texture)); |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1706 GLenum error = ERRORSTATE_PEEK_GL_ERROR(error_state, "glTexImage2D"); | 1775 GLenum error = ERRORSTATE_PEEK_GL_ERROR(error_state, "glTexImage2D"); |
1707 if (error == GL_NO_ERROR) { | 1776 if (error == GL_NO_ERROR) { |
1708 SetLevelInfo( | 1777 SetLevelInfo( |
1709 texture_ref, | 1778 texture_ref, |
1710 args.target, args.level, args.internal_format, args.width, args.height, | 1779 args.target, args.level, args.internal_format, args.width, args.height, |
1711 1, args.border, args.format, args.type, args.pixels != NULL); | 1780 1, args.border, args.format, args.type, args.pixels != NULL); |
1712 texture_state->tex_image_2d_failed = false; | 1781 texture_state->tex_image_2d_failed = false; |
1713 } | 1782 } |
1714 } | 1783 } |
1715 | 1784 |
| 1785 bool TextureManager::ValidateCompressedTexImage2D( |
| 1786 ContextState* state, |
| 1787 const char* function_name, |
| 1788 const DoCompressedTexImage2DArguments& args, |
| 1789 TextureRef** texture_ref) { |
| 1790 ErrorState* error_state = state->GetErrorState(); |
| 1791 const Validators* validators = feature_info_->validators(); |
| 1792 if (!validators->texture_target.IsValid(args.target)) { |
| 1793 ERRORSTATE_SET_GL_ERROR_INVALID_ENUM(error_state, function_name, |
| 1794 args.target, "target"); |
| 1795 return false; |
| 1796 } |
| 1797 if (!validators->compressed_texture_format.IsValid(args.internal_format)) { |
| 1798 ERRORSTATE_SET_GL_ERROR_INVALID_ENUM( |
| 1799 error_state, function_name, args.internal_format, "internal_format"); |
| 1800 return false; |
| 1801 } |
| 1802 if (!ValidForTarget(args.target, args.level, args.width, args.height, 1) || |
| 1803 args.border != 0) { |
| 1804 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_VALUE, function_name, |
| 1805 "dimensions out of range"); |
| 1806 return false; |
| 1807 } |
| 1808 |
| 1809 if (!GLES2Util::IsValidCompressedImageSize( |
| 1810 args.level, args.width, args.height, args.internal_format)) { |
| 1811 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_VALUE, function_name, |
| 1812 "width or height invalid for level"); |
| 1813 return false; |
| 1814 } |
| 1815 int bytes_required = 0; |
| 1816 if (!GLES2Util::ComputeCompressedImageSize( |
| 1817 args.width, args.height, args.internal_format, &bytes_required) || |
| 1818 args.image_size != static_cast<GLsizei>(bytes_required)) { |
| 1819 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_VALUE, function_name, |
| 1820 "size is not correct for dimension"); |
| 1821 return false; |
| 1822 } |
| 1823 |
| 1824 TextureRef* local_texture_ref = GetTextureInfoForTarget(state, args.target); |
| 1825 if (!local_texture_ref) { |
| 1826 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_OPERATION, function_name, |
| 1827 "unknown texture for target"); |
| 1828 return false; |
| 1829 } |
| 1830 if (local_texture_ref->texture()->IsImmutable()) { |
| 1831 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_OPERATION, function_name, |
| 1832 "texture is immutable"); |
| 1833 return false; |
| 1834 } |
| 1835 |
| 1836 // TODO - verify that using the managed vs unmanaged does not matter. |
| 1837 // They both use the same MemoryTracker, and this call just re-routes |
| 1838 // to it. |
| 1839 if (!memory_tracker_managed_->EnsureGPUMemoryAvailable(args.image_size)) { |
| 1840 ERRORSTATE_SET_GL_ERROR(error_state, GL_OUT_OF_MEMORY, "glTexImage2D", |
| 1841 "out of memory"); |
| 1842 return false; |
| 1843 } |
| 1844 |
| 1845 // Write the TextureReference since this is valid. |
| 1846 *texture_ref = local_texture_ref; |
| 1847 return true; |
| 1848 } |
| 1849 |
1716 ScopedTextureUploadTimer::ScopedTextureUploadTimer( | 1850 ScopedTextureUploadTimer::ScopedTextureUploadTimer( |
1717 DecoderTextureState* texture_state) | 1851 DecoderTextureState* texture_state) |
1718 : texture_state_(texture_state), | 1852 : texture_state_(texture_state), |
1719 begin_time_(base::TimeTicks::HighResNow()) { | 1853 begin_time_(base::TimeTicks::HighResNow()) { |
1720 } | 1854 } |
1721 | 1855 |
1722 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() { | 1856 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() { |
1723 texture_state_->texture_upload_count++; | 1857 texture_state_->texture_upload_count++; |
1724 texture_state_->total_texture_upload_time += | 1858 texture_state_->total_texture_upload_time += |
1725 base::TimeTicks::HighResNow() - begin_time_; | 1859 base::TimeTicks::HighResNow() - begin_time_; |
1726 } | 1860 } |
1727 | 1861 |
1728 } // namespace gles2 | 1862 } // namespace gles2 |
1729 } // namespace gpu | 1863 } // namespace gpu |
OLD | NEW |