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/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "crypto/symmetric_key.h" |
8 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 9 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
9 #include "gpu/command_buffer/service/feature_info.h" | 10 #include "gpu/command_buffer/service/feature_info.h" |
10 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 11 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 12 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 13 #include "gpu/command_buffer/service/texture_definition.h" |
11 | 14 |
12 namespace gpu { | 15 namespace gpu { |
13 namespace gles2 { | 16 namespace gles2 { |
14 | 17 |
15 static size_t GLTargetToFaceIndex(GLenum target) { | 18 static size_t GLTargetToFaceIndex(GLenum target) { |
16 switch (target) { | 19 switch (target) { |
17 case GL_TEXTURE_2D: | 20 case GL_TEXTURE_2D: |
18 case GL_TEXTURE_EXTERNAL_OES: | 21 case GL_TEXTURE_EXTERNAL_OES: |
19 case GL_TEXTURE_RECTANGLE_ARB: | 22 case GL_TEXTURE_RECTANGLE_ARB: |
20 return 0; | 23 return 0; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 } | 83 } |
81 | 84 |
82 if (have_context) { | 85 if (have_context) { |
83 glDeleteTextures(arraysize(ids), ids); | 86 glDeleteTextures(arraysize(ids), ids); |
84 } | 87 } |
85 | 88 |
86 DCHECK_EQ(0u, mem_represented_); | 89 DCHECK_EQ(0u, mem_represented_); |
87 UpdateMemRepresented(); | 90 UpdateMemRepresented(); |
88 } | 91 } |
89 | 92 |
| 93 TextureManager::TextureInfo::TextureInfo(TextureManager* manager, |
| 94 GLuint service_id) |
| 95 : manager_(manager), |
| 96 service_id_(service_id), |
| 97 deleted_(false), |
| 98 cleared_(true), |
| 99 num_uncleared_mips_(0), |
| 100 target_(0), |
| 101 min_filter_(GL_NEAREST_MIPMAP_LINEAR), |
| 102 mag_filter_(GL_LINEAR), |
| 103 wrap_s_(GL_REPEAT), |
| 104 wrap_t_(GL_REPEAT), |
| 105 usage_(GL_NONE), |
| 106 max_level_set_(-1), |
| 107 texture_complete_(false), |
| 108 cube_complete_(false), |
| 109 npot_(false), |
| 110 has_been_bound_(false), |
| 111 framebuffer_attachment_count_(0), |
| 112 owned_(true), |
| 113 stream_texture_(false), |
| 114 immutable_(false), |
| 115 estimated_size_(0) { |
| 116 if (manager_) { |
| 117 manager_->StartTracking(this); |
| 118 } |
| 119 } |
| 120 |
90 TextureManager::TextureInfo::~TextureInfo() { | 121 TextureManager::TextureInfo::~TextureInfo() { |
91 if (manager_) { | 122 if (manager_) { |
92 if (owned_ && manager_->have_context_) { | 123 if (owned_ && manager_->have_context_) { |
93 GLuint id = service_id(); | 124 GLuint id = service_id(); |
94 glDeleteTextures(1, &id); | 125 glDeleteTextures(1, &id); |
95 } | 126 } |
96 MarkAsDeleted(); | 127 MarkAsDeleted(); |
97 manager_->StopTracking(this); | 128 manager_->StopTracking(this); |
98 manager_ = NULL; | 129 manager_ = NULL; |
99 } | 130 } |
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 | 822 |
792 num_uncleared_mips_ += info->num_uncleared_mips(); | 823 num_uncleared_mips_ += info->num_uncleared_mips(); |
793 if (!info->CanRender(feature_info_)) { | 824 if (!info->CanRender(feature_info_)) { |
794 ++num_unrenderable_textures_; | 825 ++num_unrenderable_textures_; |
795 } | 826 } |
796 if (!info->SafeToRenderFrom()) { | 827 if (!info->SafeToRenderFrom()) { |
797 ++num_unsafe_textures_; | 828 ++num_unsafe_textures_; |
798 } | 829 } |
799 } | 830 } |
800 | 831 |
| 832 TextureDefinition* TextureManager::Save(TextureInfo* info) { |
| 833 DCHECK(info->owned_); |
| 834 |
| 835 if (info->IsAttachedToFramebuffer()) |
| 836 return NULL; |
| 837 |
| 838 if (info->IsImmutable()) |
| 839 return NULL; |
| 840 |
| 841 TextureDefinition::LevelInfos level_infos(info->level_infos_.size()); |
| 842 for (size_t face = 0; face < level_infos.size(); ++face) { |
| 843 GLenum target = info->target() == GL_TEXTURE_2D ? |
| 844 GL_TEXTURE_2D : FaceIndexToGLTarget(face); |
| 845 for (size_t level = 0; level < info->level_infos_[face].size(); ++level) { |
| 846 const TextureInfo::LevelInfo& level_info = |
| 847 info->level_infos_[face][level]; |
| 848 level_infos[face].push_back( |
| 849 TextureDefinition::LevelInfo(target, |
| 850 level_info.internal_format, |
| 851 level_info.width, |
| 852 level_info.height, |
| 853 level_info.depth, |
| 854 level_info.border, |
| 855 level_info.format, |
| 856 level_info.type, |
| 857 level_info.cleared)); |
| 858 |
| 859 SetLevelInfo(info, |
| 860 target, |
| 861 level, |
| 862 GL_RGBA, |
| 863 0, |
| 864 0, |
| 865 0, |
| 866 0, |
| 867 GL_RGBA, |
| 868 GL_UNSIGNED_BYTE, |
| 869 true); |
| 870 } |
| 871 } |
| 872 |
| 873 GLuint old_service_id = info->service_id(); |
| 874 |
| 875 GLuint new_service_id = 0; |
| 876 glGenTextures(1, &new_service_id); |
| 877 info->SetServiceId(new_service_id); |
| 878 |
| 879 return new TextureDefinition(info->target(), |
| 880 old_service_id, |
| 881 level_infos); |
| 882 } |
| 883 |
| 884 bool TextureManager::Restore(TextureInfo* info, |
| 885 TextureDefinition* definition) { |
| 886 DCHECK(info->owned_); |
| 887 |
| 888 scoped_ptr<TextureDefinition> scoped_definition(definition); |
| 889 |
| 890 if (info->IsAttachedToFramebuffer()) |
| 891 return false; |
| 892 |
| 893 if (info->IsImmutable()) |
| 894 return false; |
| 895 |
| 896 if (info->target() != definition->target()) |
| 897 return false; |
| 898 |
| 899 if (info->level_infos_.size() != definition->level_infos().size()) |
| 900 return false; |
| 901 |
| 902 if (info->level_infos_[0].size() != definition->level_infos()[0].size()) |
| 903 return false; |
| 904 |
| 905 for (size_t face = 0; face < info->level_infos_.size(); ++face) { |
| 906 GLenum target = info->target() == GL_TEXTURE_2D ? |
| 907 GL_TEXTURE_2D : FaceIndexToGLTarget(face); |
| 908 for (size_t level = 0; level < info->level_infos_[face].size(); ++level) { |
| 909 const TextureDefinition::LevelInfo& level_info = |
| 910 definition->level_infos()[face][level]; |
| 911 SetLevelInfo(info, |
| 912 target, |
| 913 level, |
| 914 level_info.internal_format, |
| 915 level_info.width, |
| 916 level_info.height, |
| 917 level_info.depth, |
| 918 level_info.border, |
| 919 level_info.format, |
| 920 level_info.type, |
| 921 level_info.cleared); |
| 922 } |
| 923 } |
| 924 |
| 925 GLuint old_service_id = info->service_id(); |
| 926 glDeleteTextures(1, &old_service_id); |
| 927 info->SetServiceId(definition->ReleaseServiceId()); |
| 928 |
| 929 return true; |
| 930 } |
| 931 |
801 bool TextureManager::SetParameter( | 932 bool TextureManager::SetParameter( |
802 TextureManager::TextureInfo* info, GLenum pname, GLint param) { | 933 TextureManager::TextureInfo* info, GLenum pname, GLint param) { |
803 DCHECK(info); | 934 DCHECK(info); |
804 if (!info->CanRender(feature_info_)) { | 935 if (!info->CanRender(feature_info_)) { |
805 DCHECK_NE(0, num_unrenderable_textures_); | 936 DCHECK_NE(0, num_unrenderable_textures_); |
806 --num_unrenderable_textures_; | 937 --num_unrenderable_textures_; |
807 } | 938 } |
808 if (!info->SafeToRenderFrom()) { | 939 if (!info->SafeToRenderFrom()) { |
809 DCHECK_NE(0, num_unsafe_textures_); | 940 DCHECK_NE(0, num_unsafe_textures_); |
810 --num_unsafe_textures_; | 941 --num_unsafe_textures_; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 } | 1039 } |
909 } | 1040 } |
910 return false; | 1041 return false; |
911 } | 1042 } |
912 | 1043 |
913 GLsizei TextureManager::ComputeMipMapCount( | 1044 GLsizei TextureManager::ComputeMipMapCount( |
914 GLsizei width, GLsizei height, GLsizei depth) { | 1045 GLsizei width, GLsizei height, GLsizei depth) { |
915 return 1 + base::bits::Log2Floor(std::max(std::max(width, height), depth)); | 1046 return 1 + base::bits::Log2Floor(std::max(std::max(width, height), depth)); |
916 } | 1047 } |
917 | 1048 |
918 | |
919 } // namespace gles2 | 1049 } // namespace gles2 |
920 } // namespace gpu | 1050 } // namespace gpu |
921 | 1051 |
922 | 1052 |
OLD | NEW |