Chromium Code Reviews| 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 <set> | |
| 9 #include <string> | 10 #include <string> |
| 10 #include <vector> | 11 #include <vector> |
| 11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 12 #include "base/hash_tables.h" | 13 #include "base/hash_tables.h" |
| 13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 15 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" | 16 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" |
| 16 #include "gpu/command_buffer/service/gl_utils.h" | 17 #include "gpu/command_buffer/service/gl_utils.h" |
| 17 #include "gpu/command_buffer/service/memory_tracking.h" | 18 #include "gpu/command_buffer/service/memory_tracking.h" |
| 18 #include "gpu/gpu_export.h" | 19 #include "gpu/gpu_export.h" |
| 19 #include "ui/gl/gl_image.h" | 20 #include "ui/gl/gl_image.h" |
| 20 | 21 |
| 21 namespace gpu { | 22 namespace gpu { |
| 22 namespace gles2 { | 23 namespace gles2 { |
| 23 | 24 |
| 24 class GLES2Decoder; | 25 class GLES2Decoder; |
| 25 class Display; | 26 class Display; |
| 26 class ErrorState; | 27 class ErrorState; |
| 27 class FeatureInfo; | 28 class FeatureInfo; |
| 29 class FramebufferManager; | |
| 28 class TextureDefinition; | 30 class TextureDefinition; |
| 29 class TextureManager; | 31 class TextureManager; |
| 32 class TextureRef; | |
| 30 | 33 |
| 31 // Info about Textures currently in the system. | 34 // Info about Textures currently in the system. |
| 32 class GPU_EXPORT Texture : public base::RefCounted<Texture> { | 35 // This class wraps a real GL texture, keeping track of its meta-data. It is |
| 36 // jointly owned by possibly multiple TextureRef. | |
| 37 class GPU_EXPORT Texture { | |
| 33 public: | 38 public: |
| 34 Texture(TextureManager* manager, GLuint service_id); | 39 explicit Texture(GLuint service_id); |
| 35 | 40 |
| 36 GLenum min_filter() const { | 41 GLenum min_filter() const { |
| 37 return min_filter_; | 42 return min_filter_; |
| 38 } | 43 } |
| 39 | 44 |
| 40 GLenum mag_filter() const { | 45 GLenum mag_filter() const { |
| 41 return mag_filter_; | 46 return mag_filter_; |
| 42 } | 47 } |
| 43 | 48 |
| 44 GLenum wrap_s() const { | 49 GLenum wrap_s() const { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 GLint target, GLint level, GLsizei* width, GLsizei* height) const; | 100 GLint target, GLint level, GLsizei* width, GLsizei* height) const; |
| 96 | 101 |
| 97 // Get the type of a level. Returns false if level does not exist. | 102 // Get the type of a level. Returns false if level does not exist. |
| 98 bool GetLevelType( | 103 bool GetLevelType( |
| 99 GLint target, GLint level, GLenum* type, GLenum* internal_format) const; | 104 GLint target, GLint level, GLenum* type, GLenum* internal_format) const; |
| 100 | 105 |
| 101 // Get the image bound to a particular level. Returns NULL if level | 106 // Get the image bound to a particular level. Returns NULL if level |
| 102 // does not exist. | 107 // does not exist. |
| 103 gfx::GLImage* GetLevelImage(GLint target, GLint level) const; | 108 gfx::GLImage* GetLevelImage(GLint target, GLint level) const; |
| 104 | 109 |
| 105 bool IsDeleted() const { | |
| 106 return deleted_; | |
| 107 } | |
|
piman
2013/05/14 01:34:50
Note: I removed this because it didn't seem to be
| |
| 108 | |
| 109 // Returns true of the given dimensions are inside the dimensions of the | 110 // Returns true of the given dimensions are inside the dimensions of the |
| 110 // level and if the format and type match the level. | 111 // level and if the format and type match the level. |
| 111 bool ValidForTexture( | 112 bool ValidForTexture( |
| 112 GLint target, | 113 GLint target, |
| 113 GLint level, | 114 GLint level, |
| 114 GLint xoffset, | 115 GLint xoffset, |
| 115 GLint yoffset, | 116 GLint yoffset, |
| 116 GLsizei width, | 117 GLsizei width, |
| 117 GLsizei height, | 118 GLsizei height, |
| 118 GLenum format, | 119 GLenum format, |
| 119 GLenum type) const; | 120 GLenum type) const; |
| 120 | 121 |
| 121 bool IsValid() const { | 122 bool IsValid() const { |
| 122 return target() && !IsDeleted(); | 123 return !!target(); |
| 123 } | 124 } |
| 124 | 125 |
| 125 void SetNotOwned() { | 126 void SetNotOwned() { |
| 126 owned_ = false; | 127 owned_ = false; |
| 127 } | 128 } |
| 128 | 129 |
| 129 bool IsAttachedToFramebuffer() const { | 130 bool IsAttachedToFramebuffer() const { |
| 130 return framebuffer_attachment_count_ != 0; | 131 return framebuffer_attachment_count_ != 0; |
| 131 } | 132 } |
| 132 | 133 |
| 133 void AttachToFramebuffer() { | 134 void AttachToFramebuffer() { |
| 134 ++framebuffer_attachment_count_; | 135 ++framebuffer_attachment_count_; |
| 135 } | 136 } |
| 136 | 137 |
| 137 void DetachFromFramebuffer() { | 138 void DetachFromFramebuffer() { |
| 138 DCHECK_GT(framebuffer_attachment_count_, 0); | 139 DCHECK_GT(framebuffer_attachment_count_, 0); |
| 139 --framebuffer_attachment_count_; | 140 --framebuffer_attachment_count_; |
| 140 } | 141 } |
| 141 | 142 |
| 142 void SetStreamTexture(bool stream_texture) { | 143 void SetStreamTexture(bool stream_texture) { |
| 143 stream_texture_ = stream_texture; | 144 stream_texture_ = stream_texture; |
| 144 } | 145 } |
| 145 | 146 |
| 146 bool IsStreamTexture() { | 147 bool IsStreamTexture() { |
| 147 return stream_texture_; | 148 return stream_texture_; |
| 148 } | 149 } |
| 149 | 150 |
| 150 gpu::AsyncPixelTransferState* GetAsyncTransferState() const { | 151 // Gets the async transfer state for this texture. Note: the transfer state is |
| 151 return async_transfer_state_.get(); | 152 // owned by a single TextureRef. |
| 152 } | 153 AsyncPixelTransferState* GetAsyncTransferState() const; |
| 153 void SetAsyncTransferState(scoped_ptr<gpu::AsyncPixelTransferState> state) { | 154 |
| 154 async_transfer_state_ = state.Pass(); | |
| 155 } | |
| 156 bool AsyncTransferIsInProgress() { | 155 bool AsyncTransferIsInProgress() { |
| 157 return async_transfer_state_ && | 156 AsyncPixelTransferState* state = GetAsyncTransferState(); |
| 158 async_transfer_state_->TransferIsInProgress(); | 157 return state && state->TransferIsInProgress(); |
| 159 } | 158 } |
| 160 | 159 |
| 161 void SetImmutable(bool immutable) { | 160 void SetImmutable(bool immutable) { |
| 162 immutable_ = immutable; | 161 immutable_ = immutable; |
| 163 } | 162 } |
| 164 | 163 |
| 165 bool IsImmutable() { | 164 bool IsImmutable() { |
| 166 return immutable_; | 165 return immutable_; |
| 167 } | 166 } |
| 168 | 167 |
| 169 // Whether a particular level/face is cleared. | 168 // Whether a particular level/face is cleared. |
| 170 bool IsLevelCleared(GLenum target, GLint level) const; | 169 bool IsLevelCleared(GLenum target, GLint level) const; |
| 171 | 170 |
| 172 // Whether the texture has been defined | 171 // Whether the texture has been defined |
| 173 bool IsDefined() { | 172 bool IsDefined() { |
| 174 return estimated_size() > 0; | 173 return estimated_size() > 0; |
| 175 } | 174 } |
| 176 | 175 |
| 177 private: | 176 private: |
| 178 friend class TextureManager; | 177 friend class TextureManager; |
| 178 friend class TextureRef; | |
| 179 friend class TextureTestHelper; | 179 friend class TextureTestHelper; |
| 180 friend class base::RefCounted<Texture>; | |
| 181 | 180 |
| 182 ~Texture(); | 181 ~Texture(); |
| 182 void AddTextureRef(TextureRef* ref); | |
| 183 void RemoveTextureRef(TextureRef* ref, bool have_context); | |
| 184 MemoryTypeTracker* GetMemTracker(); | |
| 185 | |
| 186 // Condition on which this texture is renderable. Can be ONLY_IF_NPOT if it | |
| 187 // depends on context support for non-power-of-two textures (i.e. will be | |
| 188 // renderable if NPOT support is in the context, otherwise not, e.g. texture | |
| 189 // with a NPOT level). ALWAYS means it doesn't depend on context features | |
| 190 // (e.g. complete POT), NEVER means it's not renderable regardless (e.g. | |
| 191 // incomplete). | |
| 192 enum CanRenderCondition { | |
| 193 CAN_RENDER_ALWAYS, | |
| 194 CAN_RENDER_NEVER, | |
| 195 CAN_RENDER_ONLY_IF_NPOT | |
| 196 }; | |
| 183 | 197 |
| 184 struct LevelInfo { | 198 struct LevelInfo { |
| 185 LevelInfo(); | 199 LevelInfo(); |
| 186 LevelInfo(const LevelInfo& rhs); | 200 LevelInfo(const LevelInfo& rhs); |
| 187 ~LevelInfo(); | 201 ~LevelInfo(); |
| 188 | 202 |
| 189 bool cleared; | 203 bool cleared; |
| 190 GLenum target; | 204 GLenum target; |
| 191 GLint level; | 205 GLint level; |
| 192 GLenum internal_format; | 206 GLenum internal_format; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 | 262 |
| 249 // Sets a texture parameter. | 263 // Sets a texture parameter. |
| 250 // TODO(gman): Expand to SetParameteri,f,iv,fv | 264 // TODO(gman): Expand to SetParameteri,f,iv,fv |
| 251 // Returns GL_NO_ERROR on success. Otherwise the error to generate. | 265 // Returns GL_NO_ERROR on success. Otherwise the error to generate. |
| 252 GLenum SetParameter( | 266 GLenum SetParameter( |
| 253 const FeatureInfo* feature_info, GLenum pname, GLint param); | 267 const FeatureInfo* feature_info, GLenum pname, GLint param); |
| 254 | 268 |
| 255 // Makes each of the mip levels as though they were generated. | 269 // Makes each of the mip levels as though they were generated. |
| 256 bool MarkMipmapsGenerated(const FeatureInfo* feature_info); | 270 bool MarkMipmapsGenerated(const FeatureInfo* feature_info); |
| 257 | 271 |
| 258 void MarkAsDeleted() { | |
| 259 deleted_ = true; | |
| 260 } | |
| 261 | |
| 262 bool NeedsMips() const { | 272 bool NeedsMips() const { |
| 263 return min_filter_ != GL_NEAREST && min_filter_ != GL_LINEAR; | 273 return min_filter_ != GL_NEAREST && min_filter_ != GL_LINEAR; |
| 264 } | 274 } |
| 265 | 275 |
| 266 // True if this texture meets all the GLES2 criteria for rendering. | 276 // True if this texture meets all the GLES2 criteria for rendering. |
| 267 // See section 3.8.2 of the GLES2 spec. | 277 // See section 3.8.2 of the GLES2 spec. |
| 268 bool CanRender(const FeatureInfo* feature_info) const; | 278 bool CanRender(const FeatureInfo* feature_info) const; |
| 269 | 279 |
| 270 // Returns true if mipmaps can be generated by GL. | 280 // Returns true if mipmaps can be generated by GL. |
| 271 bool CanGenerateMipmaps(const FeatureInfo* feature_info) const; | 281 bool CanGenerateMipmaps(const FeatureInfo* feature_info) const; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 285 const FeatureInfo* feature_info, | 295 const FeatureInfo* feature_info, |
| 286 GLenum target, | 296 GLenum target, |
| 287 GLint level, | 297 GLint level, |
| 288 gfx::GLImage* image); | 298 gfx::GLImage* image); |
| 289 | 299 |
| 290 // Appends a signature for the given level. | 300 // Appends a signature for the given level. |
| 291 void AddToSignature( | 301 void AddToSignature( |
| 292 const FeatureInfo* feature_info, | 302 const FeatureInfo* feature_info, |
| 293 GLenum target, GLint level, std::string* signature) const; | 303 GLenum target, GLint level, std::string* signature) const; |
| 294 | 304 |
| 305 // Updates the unsafe textures count in all the managers referencing this | |
| 306 // texture. | |
| 307 void UpdateSafeToRenderFrom(bool cleared); | |
| 308 | |
| 309 // Updates the uncleared mip count in all the managers referencing this | |
| 310 // texture. | |
| 311 void UpdateMipCleared(LevelInfo* info, bool cleared); | |
| 312 | |
| 313 // Computes the CanRenderCondition flag. | |
| 314 CanRenderCondition GetCanRenderCondition() const; | |
| 315 | |
| 316 // Updates the unrenderable texture count in all the managers referencing this | |
| 317 // texture. | |
| 318 void UpdateCanRenderCondition(); | |
| 319 | |
| 320 // Increment the framebuffer state change count in all the managers | |
| 321 // referencing this texture. | |
| 322 void IncAllFramebufferStateChangeCount(); | |
| 323 | |
| 295 // Info about each face and level of texture. | 324 // Info about each face and level of texture. |
| 296 std::vector<std::vector<LevelInfo> > level_infos_; | 325 std::vector<std::vector<LevelInfo> > level_infos_; |
| 297 | 326 |
| 298 // The texture manager that manages this Texture. | 327 // The texture refs that point to this Texture. |
| 299 TextureManager* manager_; | 328 typedef std::set<TextureRef*> RefSet; |
| 329 RefSet refs_; | |
| 330 | |
| 331 // The single TextureRef that accounts for memory for this texture. Must be | |
| 332 // one of refs_. | |
| 333 TextureRef* memory_tracking_ref_; | |
| 300 | 334 |
| 301 // The id of the texure | 335 // The id of the texure |
| 302 GLuint service_id_; | 336 GLuint service_id_; |
| 303 | 337 |
| 304 // Whether this texture has been deleted. | |
| 305 bool deleted_; | |
| 306 | |
| 307 // Whether all renderable mips of this texture have been cleared. | 338 // Whether all renderable mips of this texture have been cleared. |
| 308 bool cleared_; | 339 bool cleared_; |
| 309 | 340 |
| 310 int num_uncleared_mips_; | 341 int num_uncleared_mips_; |
| 311 | 342 |
| 312 // The target. 0 if unset, otherwise GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP. | 343 // The target. 0 if unset, otherwise GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP. |
| 313 GLenum target_; | 344 GLenum target_; |
| 314 | 345 |
| 315 // Texture parameters. | 346 // Texture parameters. |
| 316 GLenum min_filter_; | 347 GLenum min_filter_; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 338 // The number of framebuffers this texture is attached to. | 369 // The number of framebuffers this texture is attached to. |
| 339 int framebuffer_attachment_count_; | 370 int framebuffer_attachment_count_; |
| 340 | 371 |
| 341 // Whether the associated context group owns this texture and should delete | 372 // Whether the associated context group owns this texture and should delete |
| 342 // it. | 373 // it. |
| 343 bool owned_; | 374 bool owned_; |
| 344 | 375 |
| 345 // Whether this is a special streaming texture. | 376 // Whether this is a special streaming texture. |
| 346 bool stream_texture_; | 377 bool stream_texture_; |
| 347 | 378 |
| 348 // State to facilitate async transfers on this texture. | |
| 349 scoped_ptr<gpu::AsyncPixelTransferState> async_transfer_state_; | |
| 350 | |
| 351 // Whether the texture is immutable and no further changes to the format | 379 // Whether the texture is immutable and no further changes to the format |
| 352 // or dimensions of the texture object can be made. | 380 // or dimensions of the texture object can be made. |
| 353 bool immutable_; | 381 bool immutable_; |
| 354 | 382 |
| 355 // Size in bytes this texture is assumed to take in memory. | 383 // Size in bytes this texture is assumed to take in memory. |
| 356 uint32 estimated_size_; | 384 uint32 estimated_size_; |
| 357 | 385 |
| 386 // Cache of the computed CanRenderCondition flag. | |
| 387 CanRenderCondition can_render_condition_; | |
| 388 | |
| 358 DISALLOW_COPY_AND_ASSIGN(Texture); | 389 DISALLOW_COPY_AND_ASSIGN(Texture); |
| 359 }; | 390 }; |
| 360 | 391 |
| 392 // This class represents a texture in a client context group. It's mostly 1:1 | |
| 393 // with a client id, though it can outlive the client id if it's still bound to | |
| 394 // a FBO or another context when destroyed. | |
| 395 // Multiple TextureRef can point to the same texture with cross-context sharing. | |
| 396 class GPU_EXPORT TextureRef : public base::RefCounted<TextureRef> { | |
| 397 public: | |
| 398 TextureRef(TextureManager* manager, Texture* texture); | |
| 399 static scoped_refptr<TextureRef> Create(TextureManager* manager, | |
| 400 GLuint service_id); | |
| 401 const Texture* texture() const { return texture_; } | |
| 402 Texture* texture() { return texture_; } | |
| 403 GLuint service_id() const { return texture_->service_id(); } | |
| 404 | |
| 405 // Sets the async transfer state for this texture. Only a single TextureRef | |
| 406 // can set this on a given texture at any time. | |
| 407 // NOTE: this should be per-context rather than per-texture. crbug.com/240504 | |
| 408 void SetAsyncTransferState( | |
| 409 scoped_ptr<AsyncPixelTransferState> state) { | |
| 410 DCHECK(!state || !texture_->GetAsyncTransferState()); | |
| 411 async_transfer_state_ = state.Pass(); | |
| 412 } | |
| 413 | |
| 414 private: | |
| 415 friend class base::RefCounted<TextureRef>; | |
| 416 friend class Texture; | |
| 417 friend class TextureManager; | |
| 418 | |
| 419 ~TextureRef(); | |
| 420 const TextureManager* manager() const { return manager_; } | |
| 421 TextureManager* manager() { return manager_; } | |
| 422 AsyncPixelTransferState* async_transfer_state() const { | |
| 423 return async_transfer_state_.get(); | |
| 424 } | |
| 425 | |
| 426 TextureManager* manager_; | |
| 427 Texture* texture_; | |
| 428 | |
| 429 // State to facilitate async transfers on this texture. | |
| 430 scoped_ptr<AsyncPixelTransferState> async_transfer_state_; | |
| 431 | |
| 432 DISALLOW_COPY_AND_ASSIGN(TextureRef); | |
| 433 }; | |
| 434 | |
| 361 // This class keeps track of the textures and their sizes so we can do NPOT and | 435 // This class keeps track of the textures and their sizes so we can do NPOT and |
| 362 // texture complete checking. | 436 // texture complete checking. |
| 363 // | 437 // |
| 364 // NOTE: To support shared resources an instance of this class will need to be | 438 // NOTE: To support shared resources an instance of this class will need to be |
| 365 // shared by multiple GLES2Decoders. | 439 // shared by multiple GLES2Decoders. |
| 366 class GPU_EXPORT TextureManager { | 440 class GPU_EXPORT TextureManager { |
| 367 public: | 441 public: |
| 368 enum DefaultAndBlackTextures { | 442 enum DefaultAndBlackTextures { |
| 369 kTexture2D, | 443 kTexture2D, |
| 370 kCubeMap, | 444 kCubeMap, |
| 371 kExternalOES, | 445 kExternalOES, |
| 372 kRectangleARB, | 446 kRectangleARB, |
| 373 kNumDefaultTextures | 447 kNumDefaultTextures |
| 374 }; | 448 }; |
| 375 | 449 |
| 376 TextureManager(MemoryTracker* memory_tracker, | 450 TextureManager(MemoryTracker* memory_tracker, |
| 377 FeatureInfo* feature_info, | 451 FeatureInfo* feature_info, |
| 378 GLsizei max_texture_size, | 452 GLsizei max_texture_size, |
| 379 GLsizei max_cube_map_texture_size); | 453 GLsizei max_cube_map_texture_size); |
| 380 ~TextureManager(); | 454 ~TextureManager(); |
| 381 | 455 |
| 456 void set_framebuffer_manager(FramebufferManager* manager) { | |
| 457 framebuffer_manager_ = manager; | |
| 458 } | |
| 459 | |
| 382 // Init the texture manager. | 460 // Init the texture manager. |
| 383 bool Initialize(); | 461 bool Initialize(); |
| 384 | 462 |
| 385 // Must call before destruction. | 463 // Must call before destruction. |
| 386 void Destroy(bool have_context); | 464 void Destroy(bool have_context); |
| 387 | 465 |
| 388 // Returns the maximum number of levels. | 466 // Returns the maximum number of levels. |
| 389 GLint MaxLevelsForTarget(GLenum target) const { | 467 GLint MaxLevelsForTarget(GLenum target) const { |
| 390 switch (target) { | 468 switch (target) { |
| 391 case GL_TEXTURE_2D: | 469 case GL_TEXTURE_2D: |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 412 static GLsizei ComputeMipMapCount( | 490 static GLsizei ComputeMipMapCount( |
| 413 GLsizei width, GLsizei height, GLsizei depth); | 491 GLsizei width, GLsizei height, GLsizei depth); |
| 414 | 492 |
| 415 // Checks if a dimensions are valid for a given target. | 493 // Checks if a dimensions are valid for a given target. |
| 416 bool ValidForTarget( | 494 bool ValidForTarget( |
| 417 GLenum target, GLint level, | 495 GLenum target, GLint level, |
| 418 GLsizei width, GLsizei height, GLsizei depth); | 496 GLsizei width, GLsizei height, GLsizei depth); |
| 419 | 497 |
| 420 // True if this texture meets all the GLES2 criteria for rendering. | 498 // True if this texture meets all the GLES2 criteria for rendering. |
| 421 // See section 3.8.2 of the GLES2 spec. | 499 // See section 3.8.2 of the GLES2 spec. |
| 422 bool CanRender(const Texture* texture) const { | 500 bool CanRender(const TextureRef* ref) const { |
| 423 return texture->CanRender(feature_info_); | 501 return ref->texture()->CanRender(feature_info_); |
| 424 } | 502 } |
| 425 | 503 |
| 426 // Returns true if mipmaps can be generated by GL. | 504 // Returns true if mipmaps can be generated by GL. |
| 427 bool CanGenerateMipmaps(const Texture* texture) const { | 505 bool CanGenerateMipmaps(const TextureRef* ref) const { |
| 428 return texture->CanGenerateMipmaps(feature_info_); | 506 return ref->texture()->CanGenerateMipmaps(feature_info_); |
| 429 } | 507 } |
| 430 | 508 |
| 431 // Sets the Texture's target | 509 // Sets the Texture's target |
| 432 // Parameters: | 510 // Parameters: |
| 433 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP | 511 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP |
| 434 // max_levels: The maximum levels this type of target can have. | 512 // max_levels: The maximum levels this type of target can have. |
| 435 void SetTarget( | 513 void SetTarget( |
| 436 Texture* texture, | 514 TextureRef* ref, |
| 437 GLenum target); | 515 GLenum target); |
| 438 | 516 |
| 439 // Set the info for a particular level in a TexureInfo. | 517 // Set the info for a particular level in a TexureInfo. |
| 440 void SetLevelInfo( | 518 void SetLevelInfo( |
| 441 Texture* texture, | 519 TextureRef* ref, |
| 442 GLenum target, | 520 GLenum target, |
| 443 GLint level, | 521 GLint level, |
| 444 GLenum internal_format, | 522 GLenum internal_format, |
| 445 GLsizei width, | 523 GLsizei width, |
| 446 GLsizei height, | 524 GLsizei height, |
| 447 GLsizei depth, | 525 GLsizei depth, |
| 448 GLint border, | 526 GLint border, |
| 449 GLenum format, | 527 GLenum format, |
| 450 GLenum type, | 528 GLenum type, |
| 451 bool cleared); | 529 bool cleared); |
| 452 | 530 |
| 453 // Adapter to call above function. | 531 // Adapter to call above function. |
| 454 void SetLevelInfoFromParams(Texture* texture, | 532 void SetLevelInfoFromParams(TextureRef* ref, |
| 455 const gpu::AsyncTexImage2DParams& params) { | 533 const gpu::AsyncTexImage2DParams& params) { |
| 456 SetLevelInfo( | 534 SetLevelInfo( |
| 457 texture, params.target, params.level, params.internal_format, | 535 ref, params.target, params.level, params.internal_format, |
| 458 params.width, params.height, 1 /* depth */, | 536 params.width, params.height, 1 /* depth */, |
| 459 params.border, params.format, | 537 params.border, params.format, |
| 460 params.type, true /* cleared */ ); | 538 params.type, true /* cleared */ ); |
| 461 } | 539 } |
| 462 | 540 |
| 463 // Save the texture definition and leave it undefined. | 541 // Save the texture definition and leave it undefined. |
| 464 TextureDefinition* Save(Texture* texture); | 542 TextureDefinition* Save(TextureRef* ref); |
| 465 | 543 |
| 466 // Redefine all the levels from the texture definition. | 544 // Redefine all the levels from the texture definition. |
| 467 bool Restore( | 545 bool Restore( |
| 468 const char* function_name, | 546 const char* function_name, |
| 469 GLES2Decoder* decoder, | 547 GLES2Decoder* decoder, |
| 470 Texture* texture, | 548 TextureRef* ref, |
| 471 TextureDefinition* definition); | 549 TextureDefinition* definition); |
| 472 | 550 |
| 473 // Sets a mip as cleared. | 551 // Sets a mip as cleared. |
| 474 void SetLevelCleared(Texture* texture, GLenum target, | 552 void SetLevelCleared(TextureRef* ref, GLenum target, |
| 475 GLint level, bool cleared); | 553 GLint level, bool cleared); |
| 476 | 554 |
| 477 // Sets a texture parameter of a Texture | 555 // Sets a texture parameter of a Texture |
| 478 // Returns GL_NO_ERROR on success. Otherwise the error to generate. | 556 // Returns GL_NO_ERROR on success. Otherwise the error to generate. |
| 479 // TODO(gman): Expand to SetParameteri,f,iv,fv | 557 // TODO(gman): Expand to SetParameteri,f,iv,fv |
| 480 void SetParameter( | 558 void SetParameter( |
| 481 const char* function_name, ErrorState* error_state, | 559 const char* function_name, ErrorState* error_state, |
| 482 Texture* texture, GLenum pname, GLint param); | 560 TextureRef* ref, GLenum pname, GLint param); |
| 483 | 561 |
| 484 // Makes each of the mip levels as though they were generated. | 562 // Makes each of the mip levels as though they were generated. |
| 485 // Returns false if that's not allowed for the given texture. | 563 // Returns false if that's not allowed for the given texture. |
| 486 bool MarkMipmapsGenerated(Texture* texture); | 564 bool MarkMipmapsGenerated(TextureRef* ref); |
| 487 | 565 |
| 488 // Clears any uncleared renderable levels. | 566 // Clears any uncleared renderable levels. |
| 489 bool ClearRenderableLevels(GLES2Decoder* decoder, Texture* texture); | 567 bool ClearRenderableLevels(GLES2Decoder* decoder, TextureRef* ref); |
| 490 | 568 |
| 491 // Clear a specific level. | 569 // Clear a specific level. |
| 492 bool ClearTextureLevel( | 570 bool ClearTextureLevel( |
| 493 GLES2Decoder* decoder,Texture* texture, GLenum target, GLint level); | 571 GLES2Decoder* decoder, TextureRef* ref, GLenum target, GLint level); |
| 494 | 572 |
| 495 // Creates a new texture info. | 573 // Creates a new texture info. |
| 496 Texture* CreateTexture(GLuint client_id, GLuint service_id); | 574 TextureRef* CreateTexture(GLuint client_id, GLuint service_id); |
| 497 | 575 |
| 498 // Gets the texture info for the given texture. | 576 // Gets the texture info for the given texture. |
| 499 Texture* GetTexture(GLuint client_id) const; | 577 TextureRef* GetTexture(GLuint client_id) const; |
| 500 | 578 |
| 501 // Removes a texture info. | 579 // Removes a texture info. |
| 502 void RemoveTexture(GLuint client_id); | 580 void RemoveTexture(GLuint client_id); |
| 503 | 581 |
| 504 // Gets a client id for a given service id. | 582 // Gets a client id for a given service id. |
| 505 bool GetClientId(GLuint service_id, GLuint* client_id) const; | 583 bool GetClientId(GLuint service_id, GLuint* client_id) const; |
| 506 | 584 |
| 507 Texture* GetDefaultTextureInfo(GLenum target) { | 585 TextureRef* GetDefaultTextureInfo(GLenum target) { |
| 508 switch (target) { | 586 switch (target) { |
| 509 case GL_TEXTURE_2D: | 587 case GL_TEXTURE_2D: |
| 510 return default_textures_[kTexture2D]; | 588 return default_textures_[kTexture2D]; |
| 511 case GL_TEXTURE_CUBE_MAP: | 589 case GL_TEXTURE_CUBE_MAP: |
| 512 return default_textures_[kCubeMap]; | 590 return default_textures_[kCubeMap]; |
| 513 case GL_TEXTURE_EXTERNAL_OES: | 591 case GL_TEXTURE_EXTERNAL_OES: |
| 514 return default_textures_[kExternalOES]; | 592 return default_textures_[kExternalOES]; |
| 515 case GL_TEXTURE_RECTANGLE_ARB: | 593 case GL_TEXTURE_RECTANGLE_ARB: |
| 516 return default_textures_[kRectangleARB]; | 594 return default_textures_[kRectangleARB]; |
| 517 default: | 595 default: |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 548 } | 626 } |
| 549 } | 627 } |
| 550 | 628 |
| 551 size_t mem_represented() const { | 629 size_t mem_represented() const { |
| 552 return | 630 return |
| 553 memory_tracker_managed_->GetMemRepresented() + | 631 memory_tracker_managed_->GetMemRepresented() + |
| 554 memory_tracker_unmanaged_->GetMemRepresented(); | 632 memory_tracker_unmanaged_->GetMemRepresented(); |
| 555 } | 633 } |
| 556 | 634 |
| 557 void SetLevelImage( | 635 void SetLevelImage( |
| 558 Texture* texture, | 636 TextureRef* ref, |
| 559 GLenum target, | 637 GLenum target, |
| 560 GLint level, | 638 GLint level, |
| 561 gfx::GLImage* image); | 639 gfx::GLImage* image); |
| 562 | 640 |
| 563 void AddToSignature( | 641 void AddToSignature( |
| 564 Texture* texture, | 642 TextureRef* ref, |
| 565 GLenum target, | 643 GLenum target, |
| 566 GLint level, | 644 GLint level, |
| 567 std::string* signature) const; | 645 std::string* signature) const; |
| 568 | 646 |
| 569 private: | 647 private: |
| 570 friend class Texture; | 648 friend class Texture; |
| 649 friend class TextureRef; | |
| 571 | 650 |
| 572 // Helper for Initialize(). | 651 // Helper for Initialize(). |
| 573 scoped_refptr<Texture> CreateDefaultAndBlackTextures( | 652 scoped_refptr<TextureRef> CreateDefaultAndBlackTextures( |
| 574 GLenum target, | 653 GLenum target, |
| 575 GLuint* black_texture); | 654 GLuint* black_texture); |
| 576 | 655 |
| 577 void StartTracking(Texture* texture); | 656 void StartTracking(TextureRef* texture); |
| 578 void StopTracking(Texture* texture); | 657 void StopTracking(TextureRef* texture); |
| 658 | |
| 659 void UpdateSafeToRenderFrom(int delta); | |
| 660 void UpdateUnclearedMips(int delta); | |
| 661 void UpdateCanRenderCondition(Texture::CanRenderCondition old_condition, | |
| 662 Texture::CanRenderCondition new_condition); | |
| 663 void IncFramebufferStateChangeCount(); | |
| 579 | 664 |
| 580 MemoryTypeTracker* GetMemTracker(GLenum texture_pool); | 665 MemoryTypeTracker* GetMemTracker(GLenum texture_pool); |
| 581 scoped_ptr<MemoryTypeTracker> memory_tracker_managed_; | 666 scoped_ptr<MemoryTypeTracker> memory_tracker_managed_; |
| 582 scoped_ptr<MemoryTypeTracker> memory_tracker_unmanaged_; | 667 scoped_ptr<MemoryTypeTracker> memory_tracker_unmanaged_; |
| 583 | 668 |
| 584 scoped_refptr<FeatureInfo> feature_info_; | 669 scoped_refptr<FeatureInfo> feature_info_; |
| 585 | 670 |
| 671 FramebufferManager* framebuffer_manager_; | |
| 672 | |
| 586 // Info for each texture in the system. | 673 // Info for each texture in the system. |
| 587 typedef base::hash_map<GLuint, scoped_refptr<Texture> > TextureMap; | 674 typedef base::hash_map<GLuint, scoped_refptr<TextureRef> > TextureMap; |
| 588 TextureMap textures_; | 675 TextureMap textures_; |
| 589 | 676 |
| 590 GLsizei max_texture_size_; | 677 GLsizei max_texture_size_; |
| 591 GLsizei max_cube_map_texture_size_; | 678 GLsizei max_cube_map_texture_size_; |
| 592 GLint max_levels_; | 679 GLint max_levels_; |
| 593 GLint max_cube_map_levels_; | 680 GLint max_cube_map_levels_; |
| 594 | 681 |
| 595 int num_unrenderable_textures_; | 682 int num_unrenderable_textures_; |
| 596 int num_unsafe_textures_; | 683 int num_unsafe_textures_; |
| 597 int num_uncleared_mips_; | 684 int num_uncleared_mips_; |
| 598 | 685 |
| 599 // Counts the number of Textures allocated with 'this' as its manager. | 686 // Counts the number of Textures allocated with 'this' as its manager. |
| 600 // Allows to check no Texture will outlive this. | 687 // Allows to check no Texture will outlive this. |
| 601 unsigned int texture_count_; | 688 unsigned int texture_count_; |
| 602 | 689 |
| 603 bool have_context_; | 690 bool have_context_; |
| 604 | 691 |
| 605 // Black (0,0,0,1) textures for when non-renderable textures are used. | 692 // Black (0,0,0,1) textures for when non-renderable textures are used. |
| 606 // NOTE: There is no corresponding Texture for these textures. | 693 // NOTE: There is no corresponding Texture for these textures. |
| 607 // TextureInfos are only for textures the client side can access. | 694 // TextureInfos are only for textures the client side can access. |
| 608 GLuint black_texture_ids_[kNumDefaultTextures]; | 695 GLuint black_texture_ids_[kNumDefaultTextures]; |
| 609 | 696 |
| 610 // The default textures for each target (texture name = 0) | 697 // The default textures for each target (texture name = 0) |
| 611 scoped_refptr<Texture> default_textures_[kNumDefaultTextures]; | 698 scoped_refptr<TextureRef> default_textures_[kNumDefaultTextures]; |
| 612 | 699 |
| 613 DISALLOW_COPY_AND_ASSIGN(TextureManager); | 700 DISALLOW_COPY_AND_ASSIGN(TextureManager); |
| 614 }; | 701 }; |
| 615 | 702 |
| 616 } // namespace gles2 | 703 } // namespace gles2 |
| 617 } // namespace gpu | 704 } // namespace gpu |
| 618 | 705 |
| 619 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ | 706 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ |
| OLD | NEW |