| OLD | NEW | 
|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ | 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ | 
| 6 #define GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ | 6 #define GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ | 
| 7 | 7 | 
| 8 #include <map> | 8 #include <map> | 
| 9 #include <vector> | 9 #include <vector> | 
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" | 
| 11 #include "base/logging.h" | 11 #include "base/logging.h" | 
| 12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" | 
| 13 #include "gpu/command_buffer/service/gl_utils.h" | 13 #include "gpu/command_buffer/service/gl_utils.h" | 
| 14 | 14 | 
| 15 namespace gpu { | 15 namespace gpu { | 
| 16 namespace gles2 { | 16 namespace gles2 { | 
| 17 | 17 | 
| 18 // This class keeps track of the textures and their sizes so we can do NPOT and | 18 // This class keeps track of the textures and their sizes so we can do NPOT and | 
| 19 // texture complete checking. | 19 // texture complete checking. | 
| 20 // | 20 // | 
| 21 // NOTE: To support shared resources an instance of this class will need to be | 21 // NOTE: To support shared resources an instance of this class will need to be | 
| 22 // shared by multiple GLES2Decoders. | 22 // shared by multiple GLES2Decoders. | 
| 23 class TextureManager { | 23 class TextureManager { | 
| 24  public: | 24  public: | 
| 25   // Info about Textures currently in the system. | 25   // Info about Textures currently in the system. | 
| 26   class TextureInfo : public base::RefCounted<TextureInfo> { | 26   class TextureInfo : public base::RefCounted<TextureInfo> { | 
| 27    public: | 27    public: | 
| 28     typedef scoped_refptr<TextureInfo> Ref; | 28     typedef scoped_refptr<TextureInfo> Ref; | 
| 29 | 29 | 
| 30     explicit TextureInfo(GLuint texture_id) | 30     explicit TextureInfo(GLuint service_id) | 
| 31         : texture_id_(texture_id), | 31         : service_id_(service_id), | 
| 32           deleted_(false), | 32           deleted_(false), | 
| 33           target_(0), | 33           target_(0), | 
| 34           min_filter_(GL_NEAREST_MIPMAP_LINEAR), | 34           min_filter_(GL_NEAREST_MIPMAP_LINEAR), | 
| 35           mag_filter_(GL_LINEAR), | 35           mag_filter_(GL_LINEAR), | 
| 36           wrap_s_(GL_REPEAT), | 36           wrap_s_(GL_REPEAT), | 
| 37           wrap_t_(GL_REPEAT), | 37           wrap_t_(GL_REPEAT), | 
| 38           max_level_set_(-1), | 38           max_level_set_(-1), | 
| 39           texture_complete_(false), | 39           texture_complete_(false), | 
| 40           cube_complete_(false), | 40           cube_complete_(false), | 
| 41           npot_(false) { | 41           npot_(false) { | 
| 42     } | 42     } | 
| 43 | 43 | 
| 44     // True if this texture meets all the GLES2 criteria for rendering. | 44     // True if this texture meets all the GLES2 criteria for rendering. | 
| 45     // See section 3.8.2 of the GLES2 spec. | 45     // See section 3.8.2 of the GLES2 spec. | 
| 46     bool CanRender() const; | 46     bool CanRender() const; | 
| 47 | 47 | 
| 48     // The service side OpenGL id of the texture. | 48     // The service side OpenGL id of the texture. | 
| 49     GLuint texture_id() const { | 49     GLuint service_id() const { | 
| 50       return texture_id_; | 50       return service_id_; | 
| 51     } | 51     } | 
| 52 | 52 | 
| 53     // Returns the target this texure was first bound to or 0 if it has not | 53     // Returns the target this texure was first bound to or 0 if it has not | 
| 54     // been bound. Once a texture is bound to a specific target it can never be | 54     // been bound. Once a texture is bound to a specific target it can never be | 
| 55     // bound to a different target. | 55     // bound to a different target. | 
| 56     GLenum target() const { | 56     GLenum target() const { | 
| 57       return target_; | 57       return target_; | 
| 58     } | 58     } | 
| 59 | 59 | 
| 60     // In GLES2 "texture complete" means it has all required mips for filtering | 60     // In GLES2 "texture complete" means it has all required mips for filtering | 
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 128       GLint internal_format; | 128       GLint internal_format; | 
| 129       GLsizei width; | 129       GLsizei width; | 
| 130       GLsizei height; | 130       GLsizei height; | 
| 131       GLsizei depth; | 131       GLsizei depth; | 
| 132       GLint border; | 132       GLint border; | 
| 133       GLenum format; | 133       GLenum format; | 
| 134       GLenum type; | 134       GLenum type; | 
| 135     }; | 135     }; | 
| 136 | 136 | 
| 137     void MarkAsDeleted() { | 137     void MarkAsDeleted() { | 
| 138       texture_id_ = 0; | 138       service_id_ = 0; | 
| 139       deleted_ = true; | 139       deleted_ = true; | 
| 140     } | 140     } | 
| 141 | 141 | 
| 142     bool NeedsMips() const { | 142     bool NeedsMips() const { | 
| 143       return min_filter_ != GL_NEAREST && min_filter_ != GL_LINEAR; | 143       return min_filter_ != GL_NEAREST && min_filter_ != GL_LINEAR; | 
| 144     } | 144     } | 
| 145 | 145 | 
| 146     // Sets the TextureInfo's target | 146     // Sets the TextureInfo's target | 
| 147     // Parameters: | 147     // Parameters: | 
| 148     //   target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP | 148     //   target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP | 
| 149     //   max_levels: The maximum levels this type of target can have. | 149     //   max_levels: The maximum levels this type of target can have. | 
| 150     void SetTarget(GLenum target, GLint max_levels) { | 150     void SetTarget(GLenum target, GLint max_levels) { | 
| 151       DCHECK_EQ(0u, target_);  // you can only set this once. | 151       DCHECK_EQ(0u, target_);  // you can only set this once. | 
| 152       target_ = target; | 152       target_ = target; | 
| 153       size_t num_faces = (target == GL_TEXTURE_2D) ? 1 : 6; | 153       size_t num_faces = (target == GL_TEXTURE_2D) ? 1 : 6; | 
| 154       level_infos_.resize(num_faces); | 154       level_infos_.resize(num_faces); | 
| 155       for (size_t ii = 0; ii < num_faces; ++ii) { | 155       for (size_t ii = 0; ii < num_faces; ++ii) { | 
| 156         level_infos_[ii].resize(max_levels); | 156         level_infos_[ii].resize(max_levels); | 
| 157       } | 157       } | 
| 158     } | 158     } | 
| 159 | 159 | 
| 160     // Update info about this texture. | 160     // Update info about this texture. | 
| 161     void Update(); | 161     void Update(); | 
| 162 | 162 | 
| 163     // Info about each face and level of texture. | 163     // Info about each face and level of texture. | 
| 164     std::vector<std::vector<LevelInfo> > level_infos_; | 164     std::vector<std::vector<LevelInfo> > level_infos_; | 
| 165 | 165 | 
| 166     // The id of the texure | 166     // The id of the texure | 
| 167     GLuint texture_id_; | 167     GLuint service_id_; | 
| 168 | 168 | 
| 169     // Whether this texture has been deleted. | 169     // Whether this texture has been deleted. | 
| 170     bool deleted_; | 170     bool deleted_; | 
| 171 | 171 | 
| 172     // The target. 0 if unset, otherwise GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP. | 172     // The target. 0 if unset, otherwise GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP. | 
| 173     GLenum target_; | 173     GLenum target_; | 
| 174 | 174 | 
| 175     // Texture parameters. | 175     // Texture parameters. | 
| 176     GLenum min_filter_; | 176     GLenum min_filter_; | 
| 177     GLenum mag_filter_; | 177     GLenum mag_filter_; | 
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 227   // Sets the TextureInfo's target | 227   // Sets the TextureInfo's target | 
| 228   // Parameters: | 228   // Parameters: | 
| 229   //   target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP | 229   //   target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP | 
| 230   //   max_levels: The maximum levels this type of target can have. | 230   //   max_levels: The maximum levels this type of target can have. | 
| 231   void SetInfoTarget(TextureInfo* info, GLenum target) { | 231   void SetInfoTarget(TextureInfo* info, GLenum target) { | 
| 232     DCHECK(info); | 232     DCHECK(info); | 
| 233     info->SetTarget(target, MaxLevelsForTarget(target)); | 233     info->SetTarget(target, MaxLevelsForTarget(target)); | 
| 234   } | 234   } | 
| 235 | 235 | 
| 236   // Creates a new texture info. | 236   // Creates a new texture info. | 
| 237   TextureInfo* CreateTextureInfo(GLuint texture_id); | 237   TextureInfo* CreateTextureInfo(GLuint client_id, GLuint service_id); | 
| 238 | 238 | 
| 239   // Gets the texture info for the given texture. | 239   // Gets the texture info for the given texture. | 
| 240   TextureInfo* GetTextureInfo(GLuint texture_id); | 240   TextureInfo* GetTextureInfo(GLuint client_id); | 
| 241 | 241 | 
| 242   // Removes a texture info. | 242   // Removes a texture info. | 
| 243   void RemoveTextureInfo(GLuint texture_id); | 243   void RemoveTextureInfo(GLuint client_id); | 
|  | 244 | 
|  | 245   // Gets a client id for a given service id. | 
|  | 246   bool GetClientId(GLuint service_id, GLuint* client_id) const; | 
| 244 | 247 | 
| 245   TextureInfo* GetDefaultTextureInfo(GLenum target) { | 248   TextureInfo* GetDefaultTextureInfo(GLenum target) { | 
| 246     return target == GL_TEXTURE_2D ? default_texture_2d_ : | 249     return target == GL_TEXTURE_2D ? default_texture_2d_ : | 
| 247                                      default_texture_cube_map_; | 250                                      default_texture_cube_map_; | 
| 248   } | 251   } | 
| 249 | 252 | 
| 250  private: | 253  private: | 
| 251   // Info for each texture in the system. | 254   // Info for each texture in the system. | 
| 252   // TODO(gman): Choose a faster container. | 255   // TODO(gman): Choose a faster container. | 
| 253   typedef std::map<GLuint, TextureInfo::Ref> TextureInfoMap; | 256   typedef std::map<GLuint, TextureInfo::Ref> TextureInfoMap; | 
| 254   TextureInfoMap texture_infos_; | 257   TextureInfoMap texture_infos_; | 
| 255 | 258 | 
| 256   GLsizei max_texture_size_; | 259   GLsizei max_texture_size_; | 
| 257   GLsizei max_cube_map_texture_size_; | 260   GLsizei max_cube_map_texture_size_; | 
| 258   GLint max_levels_; | 261   GLint max_levels_; | 
| 259   GLint max_cube_map_levels_; | 262   GLint max_cube_map_levels_; | 
| 260 | 263 | 
| 261   // The default textures for each target (texture name = 0) | 264   // The default textures for each target (texture name = 0) | 
| 262   TextureInfo::Ref default_texture_2d_; | 265   TextureInfo::Ref default_texture_2d_; | 
| 263   TextureInfo::Ref default_texture_cube_map_; | 266   TextureInfo::Ref default_texture_cube_map_; | 
| 264 | 267 | 
| 265   DISALLOW_COPY_AND_ASSIGN(TextureManager); | 268   DISALLOW_COPY_AND_ASSIGN(TextureManager); | 
| 266 }; | 269 }; | 
| 267 | 270 | 
| 268 }  // namespace gles2 | 271 }  // namespace gles2 | 
| 269 }  // namespace gpu | 272 }  // namespace gpu | 
| 270 | 273 | 
| 271 #endif  // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ | 274 #endif  // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ | 
| 272 | 275 | 
| OLD | NEW | 
|---|