| 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 #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 <list> | 8 #include <list> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/hash_tables.h" | 12 #include "base/hash_tables.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "gpu/command_buffer/service/feature_info.h" | |
| 16 #include "gpu/command_buffer/service/gl_utils.h" | 15 #include "gpu/command_buffer/service/gl_utils.h" |
| 17 #include "gpu/command_buffer/service/memory_tracking.h" | 16 #include "gpu/command_buffer/service/memory_tracking.h" |
| 18 #include "gpu/gpu_export.h" | 17 #include "gpu/gpu_export.h" |
| 19 #include "ui/gl/async_pixel_transfer_delegate.h" | 18 #include "ui/gl/async_pixel_transfer_delegate.h" |
| 20 #include "ui/gl/gl_image.h" | 19 #include "ui/gl/gl_image.h" |
| 21 | 20 |
| 22 namespace gpu { | 21 namespace gpu { |
| 23 namespace gles2 { | 22 namespace gles2 { |
| 24 | 23 |
| 25 class GLES2Decoder; | 24 class GLES2Decoder; |
| 26 class Display; | 25 class Display; |
| 26 class FeatureInfo; |
| 27 class TextureDefinition; | 27 class TextureDefinition; |
| 28 class TextureManager; |
| 29 |
| 30 // Info about Textures currently in the system. |
| 31 class GPU_EXPORT Texture : public base::RefCounted<Texture> { |
| 32 public: |
| 33 Texture(TextureManager* manager, GLuint service_id); |
| 34 |
| 35 GLenum min_filter() const { |
| 36 return min_filter_; |
| 37 } |
| 38 |
| 39 GLenum mag_filter() const { |
| 40 return mag_filter_; |
| 41 } |
| 42 |
| 43 GLenum wrap_s() const { |
| 44 return wrap_s_; |
| 45 } |
| 46 |
| 47 GLenum wrap_t() const { |
| 48 return wrap_t_; |
| 49 } |
| 50 |
| 51 GLenum usage() const { |
| 52 return usage_; |
| 53 } |
| 54 |
| 55 GLenum pool() const { |
| 56 return pool_; |
| 57 } |
| 58 |
| 59 int num_uncleared_mips() const { |
| 60 return num_uncleared_mips_; |
| 61 } |
| 62 |
| 63 uint32 estimated_size() const { |
| 64 return estimated_size_; |
| 65 } |
| 66 |
| 67 bool CanRenderTo() const { |
| 68 return !stream_texture_ && target_ != GL_TEXTURE_EXTERNAL_OES; |
| 69 } |
| 70 |
| 71 // The service side OpenGL id of the texture. |
| 72 GLuint service_id() const { |
| 73 return service_id_; |
| 74 } |
| 75 |
| 76 void SetServiceId(GLuint service_id) { |
| 77 service_id_ = service_id; |
| 78 } |
| 79 |
| 80 // Returns the target this texure was first bound to or 0 if it has not |
| 81 // been bound. Once a texture is bound to a specific target it can never be |
| 82 // bound to a different target. |
| 83 GLenum target() const { |
| 84 return target_; |
| 85 } |
| 86 |
| 87 // In GLES2 "texture complete" means it has all required mips for filtering |
| 88 // down to a 1x1 pixel texture, they are in the correct order, they are all |
| 89 // the same format. |
| 90 bool texture_complete() const { |
| 91 return texture_complete_; |
| 92 } |
| 93 |
| 94 // In GLES2 "cube complete" means all 6 faces level 0 are defined, all the |
| 95 // same format, all the same dimensions and all width = height. |
| 96 bool cube_complete() const { |
| 97 return cube_complete_; |
| 98 } |
| 99 |
| 100 // Whether or not this texture is a non-power-of-two texture. |
| 101 bool npot() const { |
| 102 return npot_; |
| 103 } |
| 104 |
| 105 bool SafeToRenderFrom() const { |
| 106 return cleared_; |
| 107 } |
| 108 |
| 109 // Get the width and height for a particular level. Returns false if level |
| 110 // does not exist. |
| 111 bool GetLevelSize( |
| 112 GLint target, GLint level, GLsizei* width, GLsizei* height) const; |
| 113 |
| 114 // Get the type of a level. Returns false if level does not exist. |
| 115 bool GetLevelType( |
| 116 GLint target, GLint level, GLenum* type, GLenum* internal_format) const; |
| 117 |
| 118 // Get the image bound to a particular level. Returns NULL if level |
| 119 // does not exist. |
| 120 gfx::GLImage* GetLevelImage(GLint target, GLint level) const; |
| 121 |
| 122 bool IsDeleted() const { |
| 123 return deleted_; |
| 124 } |
| 125 |
| 126 // Returns true of the given dimensions are inside the dimensions of the |
| 127 // level and if the format and type match the level. |
| 128 bool ValidForTexture( |
| 129 GLint target, |
| 130 GLint level, |
| 131 GLint xoffset, |
| 132 GLint yoffset, |
| 133 GLsizei width, |
| 134 GLsizei height, |
| 135 GLenum format, |
| 136 GLenum type) const; |
| 137 |
| 138 bool IsValid() const { |
| 139 return target() && !IsDeleted(); |
| 140 } |
| 141 |
| 142 void SetNotOwned() { |
| 143 owned_ = false; |
| 144 } |
| 145 |
| 146 bool IsAttachedToFramebuffer() const { |
| 147 return framebuffer_attachment_count_ != 0; |
| 148 } |
| 149 |
| 150 void AttachToFramebuffer() { |
| 151 ++framebuffer_attachment_count_; |
| 152 } |
| 153 |
| 154 void DetachFromFramebuffer() { |
| 155 DCHECK_GT(framebuffer_attachment_count_, 0); |
| 156 --framebuffer_attachment_count_; |
| 157 } |
| 158 |
| 159 void SetStreamTexture(bool stream_texture) { |
| 160 stream_texture_ = stream_texture; |
| 161 } |
| 162 |
| 163 int IsStreamTexture() { |
| 164 return stream_texture_; |
| 165 } |
| 166 |
| 167 gfx::AsyncPixelTransferState* GetAsyncTransferState() const { |
| 168 return async_transfer_state_.get(); |
| 169 } |
| 170 void SetAsyncTransferState(scoped_ptr<gfx::AsyncPixelTransferState> state) { |
| 171 async_transfer_state_ = state.Pass(); |
| 172 } |
| 173 bool AsyncTransferIsInProgress() { |
| 174 return async_transfer_state_ && |
| 175 async_transfer_state_->TransferIsInProgress(); |
| 176 } |
| 177 |
| 178 void SetImmutable(bool immutable) { |
| 179 immutable_ = immutable; |
| 180 } |
| 181 |
| 182 bool IsImmutable() { |
| 183 return immutable_; |
| 184 } |
| 185 |
| 186 // Whether a particular level/face is cleared. |
| 187 bool IsLevelCleared(GLenum target, GLint level); |
| 188 |
| 189 // Whether the texture has been defined |
| 190 bool IsDefined() { |
| 191 return estimated_size() > 0; |
| 192 } |
| 193 |
| 194 private: |
| 195 friend class TextureManager; |
| 196 friend class base::RefCounted<Texture>; |
| 197 |
| 198 ~Texture(); |
| 199 |
| 200 struct LevelInfo { |
| 201 LevelInfo(); |
| 202 LevelInfo(const LevelInfo& rhs); |
| 203 ~LevelInfo(); |
| 204 |
| 205 bool cleared; |
| 206 GLenum target; |
| 207 GLint level; |
| 208 GLenum internal_format; |
| 209 GLsizei width; |
| 210 GLsizei height; |
| 211 GLsizei depth; |
| 212 GLint border; |
| 213 GLenum format; |
| 214 GLenum type; |
| 215 scoped_refptr<gfx::GLImage> image; |
| 216 uint32 estimated_size; |
| 217 }; |
| 218 |
| 219 // Set the info for a particular level. |
| 220 void SetLevelInfo( |
| 221 const FeatureInfo* feature_info, |
| 222 GLenum target, |
| 223 GLint level, |
| 224 GLenum internal_format, |
| 225 GLsizei width, |
| 226 GLsizei height, |
| 227 GLsizei depth, |
| 228 GLint border, |
| 229 GLenum format, |
| 230 GLenum type, |
| 231 bool cleared); |
| 232 |
| 233 // Marks a particular level as cleared or uncleared. |
| 234 void SetLevelCleared(GLenum target, GLint level, bool cleared); |
| 235 |
| 236 // Updates the cleared flag for this texture by inspecting all the mips. |
| 237 void UpdateCleared(); |
| 238 |
| 239 // Clears any renderable uncleared levels. |
| 240 // Returns false if a GL error was generated. |
| 241 bool ClearRenderableLevels(GLES2Decoder* decoder); |
| 242 |
| 243 // Clears the level. |
| 244 // Returns false if a GL error was generated. |
| 245 bool ClearLevel(GLES2Decoder* decoder, GLenum target, GLint level); |
| 246 |
| 247 // Sets a texture parameter. |
| 248 // TODO(gman): Expand to SetParameteri,f,iv,fv |
| 249 // Returns GL_NO_ERROR on success. Otherwise the error to generate. |
| 250 GLenum SetParameter( |
| 251 const FeatureInfo* feature_info, GLenum pname, GLint param); |
| 252 |
| 253 // Makes each of the mip levels as though they were generated. |
| 254 bool MarkMipmapsGenerated(const FeatureInfo* feature_info); |
| 255 |
| 256 void MarkAsDeleted() { |
| 257 deleted_ = true; |
| 258 } |
| 259 |
| 260 bool NeedsMips() const { |
| 261 return min_filter_ != GL_NEAREST && min_filter_ != GL_LINEAR; |
| 262 } |
| 263 |
| 264 // True if this texture meets all the GLES2 criteria for rendering. |
| 265 // See section 3.8.2 of the GLES2 spec. |
| 266 bool CanRender(const FeatureInfo* feature_info) const; |
| 267 |
| 268 // Returns true if mipmaps can be generated by GL. |
| 269 bool CanGenerateMipmaps(const FeatureInfo* feature_info) const; |
| 270 |
| 271 // Sets the Texture's target |
| 272 // Parameters: |
| 273 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP or |
| 274 // GL_TEXTURE_EXTERNAL_OES or GL_TEXTURE_RECTANGLE_ARB |
| 275 // max_levels: The maximum levels this type of target can have. |
| 276 void SetTarget(GLenum target, GLint max_levels); |
| 277 |
| 278 // Update info about this texture. |
| 279 void Update(const FeatureInfo* feature_info); |
| 280 |
| 281 // Set the image for a particular level. |
| 282 void SetLevelImage( |
| 283 const FeatureInfo* feature_info, |
| 284 GLenum target, |
| 285 GLint level, |
| 286 gfx::GLImage* image); |
| 287 |
| 288 // Appends a signature for the given level. |
| 289 void AddToSignature( |
| 290 const FeatureInfo* feature_info, |
| 291 GLenum target, GLint level, std::string* signature) const; |
| 292 |
| 293 // Info about each face and level of texture. |
| 294 std::vector<std::vector<LevelInfo> > level_infos_; |
| 295 |
| 296 // The texture manager that manages this Texture. |
| 297 TextureManager* manager_; |
| 298 |
| 299 // The id of the texure |
| 300 GLuint service_id_; |
| 301 |
| 302 // Whether this texture has been deleted. |
| 303 bool deleted_; |
| 304 |
| 305 // Whether all renderable mips of this texture have been cleared. |
| 306 bool cleared_; |
| 307 |
| 308 int num_uncleared_mips_; |
| 309 |
| 310 // The target. 0 if unset, otherwise GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP. |
| 311 GLenum target_; |
| 312 |
| 313 // Texture parameters. |
| 314 GLenum min_filter_; |
| 315 GLenum mag_filter_; |
| 316 GLenum wrap_s_; |
| 317 GLenum wrap_t_; |
| 318 GLenum usage_; |
| 319 GLenum pool_; |
| 320 |
| 321 // The maximum level that has been set. |
| 322 GLint max_level_set_; |
| 323 |
| 324 // Whether or not this texture is "texture complete" |
| 325 bool texture_complete_; |
| 326 |
| 327 // Whether or not this texture is "cube complete" |
| 328 bool cube_complete_; |
| 329 |
| 330 // Whether or not this texture is non-power-of-two |
| 331 bool npot_; |
| 332 |
| 333 // Whether this texture has ever been bound. |
| 334 bool has_been_bound_; |
| 335 |
| 336 // The number of framebuffers this texture is attached to. |
| 337 int framebuffer_attachment_count_; |
| 338 |
| 339 // Whether the associated context group owns this texture and should delete |
| 340 // it. |
| 341 bool owned_; |
| 342 |
| 343 // Whether this is a special streaming texture. |
| 344 bool stream_texture_; |
| 345 |
| 346 // State to facilitate async transfers on this texture. |
| 347 scoped_ptr<gfx::AsyncPixelTransferState> async_transfer_state_; |
| 348 |
| 349 // Whether the texture is immutable and no further changes to the format |
| 350 // or dimensions of the texture object can be made. |
| 351 bool immutable_; |
| 352 |
| 353 // Size in bytes this texture is assumed to take in memory. |
| 354 uint32 estimated_size_; |
| 355 |
| 356 DISALLOW_COPY_AND_ASSIGN(Texture); |
| 357 }; |
| 28 | 358 |
| 29 // This class keeps track of the textures and their sizes so we can do NPOT and | 359 // This class keeps track of the textures and their sizes so we can do NPOT and |
| 30 // texture complete checking. | 360 // texture complete checking. |
| 31 // | 361 // |
| 32 // NOTE: To support shared resources an instance of this class will need to be | 362 // NOTE: To support shared resources an instance of this class will need to be |
| 33 // shared by multiple GLES2Decoders. | 363 // shared by multiple GLES2Decoders. |
| 34 class GPU_EXPORT TextureManager { | 364 class GPU_EXPORT TextureManager { |
| 35 public: | 365 public: |
| 36 enum DefaultAndBlackTextures { | 366 enum DefaultAndBlackTextures { |
| 37 kTexture2D, | 367 kTexture2D, |
| 38 kCubeMap, | 368 kCubeMap, |
| 39 kExternalOES, | 369 kExternalOES, |
| 40 kRectangleARB, | 370 kRectangleARB, |
| 41 kNumDefaultTextures | 371 kNumDefaultTextures |
| 42 }; | 372 }; |
| 43 | 373 |
| 44 // Info about Textures currently in the system. | |
| 45 class GPU_EXPORT TextureInfo : public base::RefCounted<TextureInfo> { | |
| 46 public: | |
| 47 typedef scoped_refptr<TextureInfo> Ref; | |
| 48 | |
| 49 TextureInfo(TextureManager* manager, GLuint service_id); | |
| 50 | |
| 51 GLenum min_filter() const { | |
| 52 return min_filter_; | |
| 53 } | |
| 54 | |
| 55 GLenum mag_filter() const { | |
| 56 return mag_filter_; | |
| 57 } | |
| 58 | |
| 59 GLenum wrap_s() const { | |
| 60 return wrap_s_; | |
| 61 } | |
| 62 | |
| 63 GLenum wrap_t() const { | |
| 64 return wrap_t_; | |
| 65 } | |
| 66 | |
| 67 GLenum usage() const { | |
| 68 return usage_; | |
| 69 } | |
| 70 | |
| 71 GLenum pool() const { | |
| 72 return pool_; | |
| 73 } | |
| 74 | |
| 75 int num_uncleared_mips() const { | |
| 76 return num_uncleared_mips_; | |
| 77 } | |
| 78 | |
| 79 uint32 estimated_size() const { | |
| 80 return estimated_size_; | |
| 81 } | |
| 82 | |
| 83 bool CanRenderTo() const { | |
| 84 return !stream_texture_ && target_ != GL_TEXTURE_EXTERNAL_OES; | |
| 85 } | |
| 86 | |
| 87 // The service side OpenGL id of the texture. | |
| 88 GLuint service_id() const { | |
| 89 return service_id_; | |
| 90 } | |
| 91 | |
| 92 void SetServiceId(GLuint service_id) { | |
| 93 service_id_ = service_id; | |
| 94 } | |
| 95 | |
| 96 // Returns the target this texure was first bound to or 0 if it has not | |
| 97 // been bound. Once a texture is bound to a specific target it can never be | |
| 98 // bound to a different target. | |
| 99 GLenum target() const { | |
| 100 return target_; | |
| 101 } | |
| 102 | |
| 103 // In GLES2 "texture complete" means it has all required mips for filtering | |
| 104 // down to a 1x1 pixel texture, they are in the correct order, they are all | |
| 105 // the same format. | |
| 106 bool texture_complete() const { | |
| 107 return texture_complete_; | |
| 108 } | |
| 109 | |
| 110 // In GLES2 "cube complete" means all 6 faces level 0 are defined, all the | |
| 111 // same format, all the same dimensions and all width = height. | |
| 112 bool cube_complete() const { | |
| 113 return cube_complete_; | |
| 114 } | |
| 115 | |
| 116 // Whether or not this texture is a non-power-of-two texture. | |
| 117 bool npot() const { | |
| 118 return npot_; | |
| 119 } | |
| 120 | |
| 121 bool SafeToRenderFrom() const { | |
| 122 return cleared_; | |
| 123 } | |
| 124 | |
| 125 // Get the width and height for a particular level. Returns false if level | |
| 126 // does not exist. | |
| 127 bool GetLevelSize( | |
| 128 GLint target, GLint level, GLsizei* width, GLsizei* height) const; | |
| 129 | |
| 130 // Get the type of a level. Returns false if level does not exist. | |
| 131 bool GetLevelType( | |
| 132 GLint target, GLint level, GLenum* type, GLenum* internal_format) const; | |
| 133 | |
| 134 // Get the image bound to a particular level. Returns NULL if level | |
| 135 // does not exist. | |
| 136 gfx::GLImage* GetLevelImage(GLint target, GLint level) const; | |
| 137 | |
| 138 bool IsDeleted() const { | |
| 139 return deleted_; | |
| 140 } | |
| 141 | |
| 142 // Returns true of the given dimensions are inside the dimensions of the | |
| 143 // level and if the format and type match the level. | |
| 144 bool ValidForTexture( | |
| 145 GLint target, | |
| 146 GLint level, | |
| 147 GLint xoffset, | |
| 148 GLint yoffset, | |
| 149 GLsizei width, | |
| 150 GLsizei height, | |
| 151 GLenum format, | |
| 152 GLenum type) const; | |
| 153 | |
| 154 bool IsValid() const { | |
| 155 return target() && !IsDeleted(); | |
| 156 } | |
| 157 | |
| 158 void SetNotOwned() { | |
| 159 owned_ = false; | |
| 160 } | |
| 161 | |
| 162 bool IsAttachedToFramebuffer() const { | |
| 163 return framebuffer_attachment_count_ != 0; | |
| 164 } | |
| 165 | |
| 166 void AttachToFramebuffer() { | |
| 167 ++framebuffer_attachment_count_; | |
| 168 } | |
| 169 | |
| 170 void DetachFromFramebuffer() { | |
| 171 DCHECK_GT(framebuffer_attachment_count_, 0); | |
| 172 --framebuffer_attachment_count_; | |
| 173 } | |
| 174 | |
| 175 void SetStreamTexture(bool stream_texture) { | |
| 176 stream_texture_ = stream_texture; | |
| 177 } | |
| 178 | |
| 179 int IsStreamTexture() { | |
| 180 return stream_texture_; | |
| 181 } | |
| 182 | |
| 183 gfx::AsyncPixelTransferState* GetAsyncTransferState() const { | |
| 184 return async_transfer_state_.get(); | |
| 185 } | |
| 186 void SetAsyncTransferState(scoped_ptr<gfx::AsyncPixelTransferState> state) { | |
| 187 async_transfer_state_ = state.Pass(); | |
| 188 } | |
| 189 bool AsyncTransferIsInProgress() { | |
| 190 return async_transfer_state_ && | |
| 191 async_transfer_state_->TransferIsInProgress(); | |
| 192 } | |
| 193 | |
| 194 void SetImmutable(bool immutable) { | |
| 195 immutable_ = immutable; | |
| 196 } | |
| 197 | |
| 198 bool IsImmutable() { | |
| 199 return immutable_; | |
| 200 } | |
| 201 | |
| 202 // Whether a particular level/face is cleared. | |
| 203 bool IsLevelCleared(GLenum target, GLint level); | |
| 204 | |
| 205 // Whether the texture has been defined | |
| 206 bool IsDefined() { | |
| 207 return estimated_size() > 0; | |
| 208 } | |
| 209 | |
| 210 private: | |
| 211 friend class TextureManager; | |
| 212 friend class base::RefCounted<TextureInfo>; | |
| 213 | |
| 214 ~TextureInfo(); | |
| 215 | |
| 216 struct LevelInfo { | |
| 217 LevelInfo(); | |
| 218 LevelInfo(const LevelInfo& rhs); | |
| 219 ~LevelInfo(); | |
| 220 | |
| 221 bool cleared; | |
| 222 GLenum target; | |
| 223 GLint level; | |
| 224 GLenum internal_format; | |
| 225 GLsizei width; | |
| 226 GLsizei height; | |
| 227 GLsizei depth; | |
| 228 GLint border; | |
| 229 GLenum format; | |
| 230 GLenum type; | |
| 231 scoped_refptr<gfx::GLImage> image; | |
| 232 uint32 estimated_size; | |
| 233 }; | |
| 234 | |
| 235 // Set the info for a particular level. | |
| 236 void SetLevelInfo( | |
| 237 const FeatureInfo* feature_info, | |
| 238 GLenum target, | |
| 239 GLint level, | |
| 240 GLenum internal_format, | |
| 241 GLsizei width, | |
| 242 GLsizei height, | |
| 243 GLsizei depth, | |
| 244 GLint border, | |
| 245 GLenum format, | |
| 246 GLenum type, | |
| 247 bool cleared); | |
| 248 | |
| 249 // Marks a particular level as cleared or uncleared. | |
| 250 void SetLevelCleared(GLenum target, GLint level, bool cleared); | |
| 251 | |
| 252 // Updates the cleared flag for this texture by inspecting all the mips. | |
| 253 void UpdateCleared(); | |
| 254 | |
| 255 // Clears any renderable uncleared levels. | |
| 256 // Returns false if a GL error was generated. | |
| 257 bool ClearRenderableLevels(GLES2Decoder* decoder); | |
| 258 | |
| 259 // Clears the level. | |
| 260 // Returns false if a GL error was generated. | |
| 261 bool ClearLevel(GLES2Decoder* decoder, GLenum target, GLint level); | |
| 262 | |
| 263 // Sets a texture parameter. | |
| 264 // TODO(gman): Expand to SetParameteri,f,iv,fv | |
| 265 // Returns GL_NO_ERROR on success. Otherwise the error to generate. | |
| 266 GLenum SetParameter( | |
| 267 const FeatureInfo* feature_info, GLenum pname, GLint param); | |
| 268 | |
| 269 // Makes each of the mip levels as though they were generated. | |
| 270 bool MarkMipmapsGenerated(const FeatureInfo* feature_info); | |
| 271 | |
| 272 void MarkAsDeleted() { | |
| 273 deleted_ = true; | |
| 274 } | |
| 275 | |
| 276 bool NeedsMips() const { | |
| 277 return min_filter_ != GL_NEAREST && min_filter_ != GL_LINEAR; | |
| 278 } | |
| 279 | |
| 280 // True if this texture meets all the GLES2 criteria for rendering. | |
| 281 // See section 3.8.2 of the GLES2 spec. | |
| 282 bool CanRender(const FeatureInfo* feature_info) const; | |
| 283 | |
| 284 // Returns true if mipmaps can be generated by GL. | |
| 285 bool CanGenerateMipmaps(const FeatureInfo* feature_info) const; | |
| 286 | |
| 287 // Sets the TextureInfo's target | |
| 288 // Parameters: | |
| 289 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP or | |
| 290 // GL_TEXTURE_EXTERNAL_OES or GL_TEXTURE_RECTANGLE_ARB | |
| 291 // max_levels: The maximum levels this type of target can have. | |
| 292 void SetTarget(GLenum target, GLint max_levels); | |
| 293 | |
| 294 // Update info about this texture. | |
| 295 void Update(const FeatureInfo* feature_info); | |
| 296 | |
| 297 // Set the image for a particular level. | |
| 298 void SetLevelImage( | |
| 299 const FeatureInfo* feature_info, | |
| 300 GLenum target, | |
| 301 GLint level, | |
| 302 gfx::GLImage* image); | |
| 303 | |
| 304 // Appends a signature for the given level. | |
| 305 void AddToSignature( | |
| 306 const FeatureInfo* feature_info, | |
| 307 GLenum target, GLint level, std::string* signature) const; | |
| 308 | |
| 309 // Info about each face and level of texture. | |
| 310 std::vector<std::vector<LevelInfo> > level_infos_; | |
| 311 | |
| 312 // The texture manager that manages this TextureInfo. | |
| 313 TextureManager* manager_; | |
| 314 | |
| 315 // The id of the texure | |
| 316 GLuint service_id_; | |
| 317 | |
| 318 // Whether this texture has been deleted. | |
| 319 bool deleted_; | |
| 320 | |
| 321 // Whether all renderable mips of this texture have been cleared. | |
| 322 bool cleared_; | |
| 323 | |
| 324 int num_uncleared_mips_; | |
| 325 | |
| 326 // The target. 0 if unset, otherwise GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP. | |
| 327 GLenum target_; | |
| 328 | |
| 329 // Texture parameters. | |
| 330 GLenum min_filter_; | |
| 331 GLenum mag_filter_; | |
| 332 GLenum wrap_s_; | |
| 333 GLenum wrap_t_; | |
| 334 GLenum usage_; | |
| 335 GLenum pool_; | |
| 336 | |
| 337 // The maximum level that has been set. | |
| 338 GLint max_level_set_; | |
| 339 | |
| 340 // Whether or not this texture is "texture complete" | |
| 341 bool texture_complete_; | |
| 342 | |
| 343 // Whether or not this texture is "cube complete" | |
| 344 bool cube_complete_; | |
| 345 | |
| 346 // Whether or not this texture is non-power-of-two | |
| 347 bool npot_; | |
| 348 | |
| 349 // Whether this texture has ever been bound. | |
| 350 bool has_been_bound_; | |
| 351 | |
| 352 // The number of framebuffers this texture is attached to. | |
| 353 int framebuffer_attachment_count_; | |
| 354 | |
| 355 // Whether the associated context group owns this texture and should delete | |
| 356 // it. | |
| 357 bool owned_; | |
| 358 | |
| 359 // Whether this is a special streaming texture. | |
| 360 bool stream_texture_; | |
| 361 | |
| 362 // State to facilitate async transfers on this texture. | |
| 363 scoped_ptr<gfx::AsyncPixelTransferState> async_transfer_state_; | |
| 364 | |
| 365 // Whether the texture is immutable and no further changes to the format | |
| 366 // or dimensions of the texture object can be made. | |
| 367 bool immutable_; | |
| 368 | |
| 369 // Size in bytes this texture is assumed to take in memory. | |
| 370 uint32 estimated_size_; | |
| 371 | |
| 372 DISALLOW_COPY_AND_ASSIGN(TextureInfo); | |
| 373 }; | |
| 374 | |
| 375 TextureManager(MemoryTracker* memory_tracker, | 374 TextureManager(MemoryTracker* memory_tracker, |
| 376 FeatureInfo* feature_info, | 375 FeatureInfo* feature_info, |
| 377 GLsizei max_texture_size, | 376 GLsizei max_texture_size, |
| 378 GLsizei max_cube_map_texture_size); | 377 GLsizei max_cube_map_texture_size); |
| 379 ~TextureManager(); | 378 ~TextureManager(); |
| 380 | 379 |
| 381 // Init the texture manager. | 380 // Init the texture manager. |
| 382 bool Initialize(); | 381 bool Initialize(); |
| 383 | 382 |
| 384 // Must call before destruction. | 383 // Must call before destruction. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 411 static GLsizei ComputeMipMapCount( | 410 static GLsizei ComputeMipMapCount( |
| 412 GLsizei width, GLsizei height, GLsizei depth); | 411 GLsizei width, GLsizei height, GLsizei depth); |
| 413 | 412 |
| 414 // Checks if a dimensions are valid for a given target. | 413 // Checks if a dimensions are valid for a given target. |
| 415 bool ValidForTarget( | 414 bool ValidForTarget( |
| 416 GLenum target, GLint level, | 415 GLenum target, GLint level, |
| 417 GLsizei width, GLsizei height, GLsizei depth); | 416 GLsizei width, GLsizei height, GLsizei depth); |
| 418 | 417 |
| 419 // True if this texture meets all the GLES2 criteria for rendering. | 418 // True if this texture meets all the GLES2 criteria for rendering. |
| 420 // See section 3.8.2 of the GLES2 spec. | 419 // See section 3.8.2 of the GLES2 spec. |
| 421 bool CanRender(const TextureInfo* texture) const { | 420 bool CanRender(const Texture* texture) const { |
| 422 return texture->CanRender(feature_info_); | 421 return texture->CanRender(feature_info_); |
| 423 } | 422 } |
| 424 | 423 |
| 425 // Returns true if mipmaps can be generated by GL. | 424 // Returns true if mipmaps can be generated by GL. |
| 426 bool CanGenerateMipmaps(const TextureInfo* texture) const { | 425 bool CanGenerateMipmaps(const Texture* texture) const { |
| 427 return texture->CanGenerateMipmaps(feature_info_); | 426 return texture->CanGenerateMipmaps(feature_info_); |
| 428 } | 427 } |
| 429 | 428 |
| 430 // Sets the TextureInfo's target | 429 // Sets the Texture's target |
| 431 // Parameters: | 430 // Parameters: |
| 432 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP | 431 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP |
| 433 // max_levels: The maximum levels this type of target can have. | 432 // max_levels: The maximum levels this type of target can have. |
| 434 void SetInfoTarget( | 433 void SetInfoTarget( |
| 435 TextureInfo* info, | 434 Texture* info, |
| 436 GLenum target); | 435 GLenum target); |
| 437 | 436 |
| 438 // Set the info for a particular level in a TexureInfo. | 437 // Set the info for a particular level in a TexureInfo. |
| 439 void SetLevelInfo( | 438 void SetLevelInfo( |
| 440 TextureInfo* info, | 439 Texture* info, |
| 441 GLenum target, | 440 GLenum target, |
| 442 GLint level, | 441 GLint level, |
| 443 GLenum internal_format, | 442 GLenum internal_format, |
| 444 GLsizei width, | 443 GLsizei width, |
| 445 GLsizei height, | 444 GLsizei height, |
| 446 GLsizei depth, | 445 GLsizei depth, |
| 447 GLint border, | 446 GLint border, |
| 448 GLenum format, | 447 GLenum format, |
| 449 GLenum type, | 448 GLenum type, |
| 450 bool cleared); | 449 bool cleared); |
| 451 | 450 |
| 452 // Save the texture definition and leave it undefined. | 451 // Save the texture definition and leave it undefined. |
| 453 TextureDefinition* Save(TextureInfo* info); | 452 TextureDefinition* Save(Texture* info); |
| 454 | 453 |
| 455 // Redefine all the levels from the texture definition. | 454 // Redefine all the levels from the texture definition. |
| 456 bool Restore(TextureInfo* info, | 455 bool Restore(Texture* info, |
| 457 TextureDefinition* definition); | 456 TextureDefinition* definition); |
| 458 | 457 |
| 459 // Sets a mip as cleared. | 458 // Sets a mip as cleared. |
| 460 void SetLevelCleared(TextureInfo* info, GLenum target, | 459 void SetLevelCleared(Texture* info, GLenum target, |
| 461 GLint level, bool cleared); | 460 GLint level, bool cleared); |
| 462 | 461 |
| 463 // Sets a texture parameter of a TextureInfo | 462 // Sets a texture parameter of a Texture |
| 464 // Returns GL_NO_ERROR on success. Otherwise the error to generate. | 463 // Returns GL_NO_ERROR on success. Otherwise the error to generate. |
| 465 // TODO(gman): Expand to SetParameteri,f,iv,fv | 464 // TODO(gman): Expand to SetParameteri,f,iv,fv |
| 466 GLenum SetParameter( | 465 GLenum SetParameter( |
| 467 TextureInfo* info, GLenum pname, GLint param); | 466 Texture* info, GLenum pname, GLint param); |
| 468 | 467 |
| 469 // Makes each of the mip levels as though they were generated. | 468 // Makes each of the mip levels as though they were generated. |
| 470 // Returns false if that's not allowed for the given texture. | 469 // Returns false if that's not allowed for the given texture. |
| 471 bool MarkMipmapsGenerated(TextureInfo* info); | 470 bool MarkMipmapsGenerated(Texture* info); |
| 472 | 471 |
| 473 // Clears any uncleared renderable levels. | 472 // Clears any uncleared renderable levels. |
| 474 bool ClearRenderableLevels(GLES2Decoder* decoder, TextureInfo* info); | 473 bool ClearRenderableLevels(GLES2Decoder* decoder, Texture* info); |
| 475 | 474 |
| 476 // Clear a specific level. | 475 // Clear a specific level. |
| 477 bool ClearTextureLevel( | 476 bool ClearTextureLevel( |
| 478 GLES2Decoder* decoder,TextureInfo* info, GLenum target, GLint level); | 477 GLES2Decoder* decoder,Texture* info, GLenum target, GLint level); |
| 479 | 478 |
| 480 // Creates a new texture info. | 479 // Creates a new texture info. |
| 481 TextureInfo* CreateTextureInfo(GLuint client_id, GLuint service_id); | 480 Texture* CreateTexture(GLuint client_id, GLuint service_id); |
| 482 | 481 |
| 483 // Gets the texture info for the given texture. | 482 // Gets the texture info for the given texture. |
| 484 TextureInfo* GetTextureInfo(GLuint client_id) const; | 483 Texture* GetTexture(GLuint client_id) const; |
| 485 | 484 |
| 486 // Removes a texture info. | 485 // Removes a texture info. |
| 487 void RemoveTextureInfo(GLuint client_id); | 486 void RemoveTexture(GLuint client_id); |
| 488 | 487 |
| 489 // Gets a client id for a given service id. | 488 // Gets a client id for a given service id. |
| 490 bool GetClientId(GLuint service_id, GLuint* client_id) const; | 489 bool GetClientId(GLuint service_id, GLuint* client_id) const; |
| 491 | 490 |
| 492 TextureInfo* GetDefaultTextureInfo(GLenum target) { | 491 Texture* GetDefaultTextureInfo(GLenum target) { |
| 493 switch (target) { | 492 switch (target) { |
| 494 case GL_TEXTURE_2D: | 493 case GL_TEXTURE_2D: |
| 495 return default_textures_[kTexture2D]; | 494 return default_textures_[kTexture2D]; |
| 496 case GL_TEXTURE_CUBE_MAP: | 495 case GL_TEXTURE_CUBE_MAP: |
| 497 return default_textures_[kCubeMap]; | 496 return default_textures_[kCubeMap]; |
| 498 case GL_TEXTURE_EXTERNAL_OES: | 497 case GL_TEXTURE_EXTERNAL_OES: |
| 499 return default_textures_[kExternalOES]; | 498 return default_textures_[kExternalOES]; |
| 500 case GL_TEXTURE_RECTANGLE_ARB: | 499 case GL_TEXTURE_RECTANGLE_ARB: |
| 501 return default_textures_[kRectangleARB]; | 500 return default_textures_[kRectangleARB]; |
| 502 default: | 501 default: |
| (...skipping 30 matching lines...) Expand all Loading... |
| 533 } | 532 } |
| 534 } | 533 } |
| 535 | 534 |
| 536 size_t mem_represented() const { | 535 size_t mem_represented() const { |
| 537 return | 536 return |
| 538 memory_tracker_managed_->GetMemRepresented() + | 537 memory_tracker_managed_->GetMemRepresented() + |
| 539 memory_tracker_unmanaged_->GetMemRepresented(); | 538 memory_tracker_unmanaged_->GetMemRepresented(); |
| 540 } | 539 } |
| 541 | 540 |
| 542 void SetLevelImage( | 541 void SetLevelImage( |
| 543 TextureInfo* info, | 542 Texture* info, |
| 544 GLenum target, | 543 GLenum target, |
| 545 GLint level, | 544 GLint level, |
| 546 gfx::GLImage* image); | 545 gfx::GLImage* image); |
| 547 | 546 |
| 548 void AddToSignature( | 547 void AddToSignature( |
| 549 TextureInfo* info, | 548 Texture* info, |
| 550 GLenum target, | 549 GLenum target, |
| 551 GLint level, | 550 GLint level, |
| 552 std::string* signature) const; | 551 std::string* signature) const; |
| 553 | 552 |
| 554 // Transfers added will get their TextureInfo updated at the same time | 553 // Transfers added will get their Texture updated at the same time |
| 555 // the async transfer is bound to the real texture. | 554 // the async transfer is bound to the real texture. |
| 556 void AddPendingAsyncPixelTransfer( | 555 void AddPendingAsyncPixelTransfer( |
| 557 base::WeakPtr<gfx::AsyncPixelTransferState> state, TextureInfo* info); | 556 base::WeakPtr<gfx::AsyncPixelTransferState> state, Texture* info); |
| 558 void BindFinishedAsyncPixelTransfers(bool* texture_dirty, | 557 void BindFinishedAsyncPixelTransfers(bool* texture_dirty, |
| 559 bool* framebuffer_dirty); | 558 bool* framebuffer_dirty); |
| 560 | 559 |
| 561 private: | 560 private: |
| 561 friend class Texture; |
| 562 |
| 562 // Helper for Initialize(). | 563 // Helper for Initialize(). |
| 563 TextureInfo::Ref CreateDefaultAndBlackTextures( | 564 scoped_refptr<Texture> CreateDefaultAndBlackTextures( |
| 564 GLenum target, | 565 GLenum target, |
| 565 GLuint* black_texture); | 566 GLuint* black_texture); |
| 566 | 567 |
| 567 void StartTracking(TextureInfo* info); | 568 void StartTracking(Texture* info); |
| 568 void StopTracking(TextureInfo* info); | 569 void StopTracking(Texture* info); |
| 569 | 570 |
| 570 MemoryTypeTracker* GetMemTracker(GLenum texture_pool); | 571 MemoryTypeTracker* GetMemTracker(GLenum texture_pool); |
| 571 scoped_ptr<MemoryTypeTracker> memory_tracker_managed_; | 572 scoped_ptr<MemoryTypeTracker> memory_tracker_managed_; |
| 572 scoped_ptr<MemoryTypeTracker> memory_tracker_unmanaged_; | 573 scoped_ptr<MemoryTypeTracker> memory_tracker_unmanaged_; |
| 573 | 574 |
| 574 FeatureInfo::Ref feature_info_; | 575 scoped_refptr<FeatureInfo> feature_info_; |
| 575 | 576 |
| 576 // Info for each texture in the system. | 577 // Info for each texture in the system. |
| 577 typedef base::hash_map<GLuint, TextureInfo::Ref> TextureInfoMap; | 578 typedef base::hash_map<GLuint, scoped_refptr<Texture> > TextureInfoMap; |
| 578 TextureInfoMap texture_infos_; | 579 TextureInfoMap texture_infos_; |
| 579 | 580 |
| 580 GLsizei max_texture_size_; | 581 GLsizei max_texture_size_; |
| 581 GLsizei max_cube_map_texture_size_; | 582 GLsizei max_cube_map_texture_size_; |
| 582 GLint max_levels_; | 583 GLint max_levels_; |
| 583 GLint max_cube_map_levels_; | 584 GLint max_cube_map_levels_; |
| 584 | 585 |
| 585 int num_unrenderable_textures_; | 586 int num_unrenderable_textures_; |
| 586 int num_unsafe_textures_; | 587 int num_unsafe_textures_; |
| 587 int num_uncleared_mips_; | 588 int num_uncleared_mips_; |
| 588 | 589 |
| 589 // Counts the number of TextureInfo allocated with 'this' as its manager. | 590 // Counts the number of Texture allocated with 'this' as its manager. |
| 590 // Allows to check no TextureInfo will outlive this. | 591 // Allows to check no Texture will outlive this. |
| 591 unsigned int texture_info_count_; | 592 unsigned int texture_info_count_; |
| 592 | 593 |
| 593 bool have_context_; | 594 bool have_context_; |
| 594 | 595 |
| 595 // Black (0,0,0,1) textures for when non-renderable textures are used. | 596 // Black (0,0,0,1) textures for when non-renderable textures are used. |
| 596 // NOTE: There is no corresponding TextureInfo for these textures. | 597 // NOTE: There is no corresponding Texture for these textures. |
| 597 // TextureInfos are only for textures the client side can access. | 598 // TextureInfos are only for textures the client side can access. |
| 598 GLuint black_texture_ids_[kNumDefaultTextures]; | 599 GLuint black_texture_ids_[kNumDefaultTextures]; |
| 599 | 600 |
| 600 // The default textures for each target (texture name = 0) | 601 // The default textures for each target (texture name = 0) |
| 601 TextureInfo::Ref default_textures_[kNumDefaultTextures]; | 602 scoped_refptr<Texture> default_textures_[kNumDefaultTextures]; |
| 602 | 603 |
| 603 // Async texture allocations which haven't been bound to their textures | 604 // Async texture allocations which haven't been bound to their textures |
| 604 // yet. This facilitates updating the TextureInfo at the same time the | 605 // yet. This facilitates updating the Texture at the same time the |
| 605 // real texture data is bound. | 606 // real texture data is bound. |
| 606 typedef std::pair<base::WeakPtr<gfx::AsyncPixelTransferState>, | 607 typedef std::pair<base::WeakPtr<gfx::AsyncPixelTransferState>, |
| 607 TextureInfo*> PendingAsyncTransfer; | 608 Texture*> PendingAsyncTransfer; |
| 608 typedef std::list<PendingAsyncTransfer> PendingAsyncTransferList; | 609 typedef std::list<PendingAsyncTransfer> PendingAsyncTransferList; |
| 609 PendingAsyncTransferList pending_async_transfers_; | 610 PendingAsyncTransferList pending_async_transfers_; |
| 610 | 611 |
| 611 DISALLOW_COPY_AND_ASSIGN(TextureManager); | 612 DISALLOW_COPY_AND_ASSIGN(TextureManager); |
| 612 }; | 613 }; |
| 613 | 614 |
| 614 } // namespace gles2 | 615 } // namespace gles2 |
| 615 } // namespace gpu | 616 } // namespace gpu |
| 616 | 617 |
| 617 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ | 618 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ |
| OLD | NEW |