Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: gpu/command_buffer/service/texture_manager.cc

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

Powered by Google App Engine
This is Rietveld 408576698