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

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

Powered by Google App Engine
This is Rietveld 408576698