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> |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 | 423 |
424 // Returns true if mipmaps can be generated by GL. | 424 // Returns true if mipmaps can be generated by GL. |
425 bool CanGenerateMipmaps(const Texture* texture) const { | 425 bool CanGenerateMipmaps(const Texture* texture) const { |
426 return texture->CanGenerateMipmaps(feature_info_); | 426 return texture->CanGenerateMipmaps(feature_info_); |
427 } | 427 } |
428 | 428 |
429 // Sets the Texture's target | 429 // Sets the Texture's target |
430 // Parameters: | 430 // Parameters: |
431 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP | 431 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP |
432 // max_levels: The maximum levels this type of target can have. | 432 // max_levels: The maximum levels this type of target can have. |
433 void SetInfoTarget( | 433 void SetTarget( |
434 Texture* info, | 434 Texture* texture, |
435 GLenum target); | 435 GLenum target); |
436 | 436 |
437 // Set the info for a particular level in a TexureInfo. | 437 // Set the info for a particular level in a TexureInfo. |
438 void SetLevelInfo( | 438 void SetLevelInfo( |
439 Texture* info, | 439 Texture* texture, |
440 GLenum target, | 440 GLenum target, |
441 GLint level, | 441 GLint level, |
442 GLenum internal_format, | 442 GLenum internal_format, |
443 GLsizei width, | 443 GLsizei width, |
444 GLsizei height, | 444 GLsizei height, |
445 GLsizei depth, | 445 GLsizei depth, |
446 GLint border, | 446 GLint border, |
447 GLenum format, | 447 GLenum format, |
448 GLenum type, | 448 GLenum type, |
449 bool cleared); | 449 bool cleared); |
450 | 450 |
451 // Save the texture definition and leave it undefined. | 451 // Save the texture definition and leave it undefined. |
452 TextureDefinition* Save(Texture* info); | 452 TextureDefinition* Save(Texture* texture); |
453 | 453 |
454 // Redefine all the levels from the texture definition. | 454 // Redefine all the levels from the texture definition. |
455 bool Restore(Texture* info, | 455 bool Restore( |
456 TextureDefinition* definition); | 456 const char* function_name, |
| 457 GLES2Decoder* decoder, |
| 458 Texture* texture, |
| 459 TextureDefinition* definition); |
457 | 460 |
458 // Sets a mip as cleared. | 461 // Sets a mip as cleared. |
459 void SetLevelCleared(Texture* info, GLenum target, | 462 void SetLevelCleared(Texture* texture, GLenum target, |
460 GLint level, bool cleared); | 463 GLint level, bool cleared); |
461 | 464 |
462 // Sets a texture parameter of a Texture | 465 // Sets a texture parameter of a Texture |
463 // Returns GL_NO_ERROR on success. Otherwise the error to generate. | 466 // Returns GL_NO_ERROR on success. Otherwise the error to generate. |
464 // TODO(gman): Expand to SetParameteri,f,iv,fv | 467 // TODO(gman): Expand to SetParameteri,f,iv,fv |
465 GLenum SetParameter( | 468 void SetParameter( |
466 Texture* info, GLenum pname, GLint param); | 469 const char* function_name, GLES2Decoder* decoder, |
| 470 Texture* texture, GLenum pname, GLint param); |
467 | 471 |
468 // Makes each of the mip levels as though they were generated. | 472 // Makes each of the mip levels as though they were generated. |
469 // Returns false if that's not allowed for the given texture. | 473 // Returns false if that's not allowed for the given texture. |
470 bool MarkMipmapsGenerated(Texture* info); | 474 bool MarkMipmapsGenerated(Texture* texture); |
471 | 475 |
472 // Clears any uncleared renderable levels. | 476 // Clears any uncleared renderable levels. |
473 bool ClearRenderableLevels(GLES2Decoder* decoder, Texture* info); | 477 bool ClearRenderableLevels(GLES2Decoder* decoder, Texture* texture); |
474 | 478 |
475 // Clear a specific level. | 479 // Clear a specific level. |
476 bool ClearTextureLevel( | 480 bool ClearTextureLevel( |
477 GLES2Decoder* decoder,Texture* info, GLenum target, GLint level); | 481 GLES2Decoder* decoder,Texture* texture, GLenum target, GLint level); |
478 | 482 |
479 // Creates a new texture info. | 483 // Creates a new texture info. |
480 Texture* CreateTexture(GLuint client_id, GLuint service_id); | 484 Texture* CreateTexture(GLuint client_id, GLuint service_id); |
481 | 485 |
482 // Gets the texture info for the given texture. | 486 // Gets the texture info for the given texture. |
483 Texture* GetTexture(GLuint client_id) const; | 487 Texture* GetTexture(GLuint client_id) const; |
484 | 488 |
485 // Removes a texture info. | 489 // Removes a texture info. |
486 void RemoveTexture(GLuint client_id); | 490 void RemoveTexture(GLuint client_id); |
487 | 491 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 } | 536 } |
533 } | 537 } |
534 | 538 |
535 size_t mem_represented() const { | 539 size_t mem_represented() const { |
536 return | 540 return |
537 memory_tracker_managed_->GetMemRepresented() + | 541 memory_tracker_managed_->GetMemRepresented() + |
538 memory_tracker_unmanaged_->GetMemRepresented(); | 542 memory_tracker_unmanaged_->GetMemRepresented(); |
539 } | 543 } |
540 | 544 |
541 void SetLevelImage( | 545 void SetLevelImage( |
542 Texture* info, | 546 Texture* texture, |
543 GLenum target, | 547 GLenum target, |
544 GLint level, | 548 GLint level, |
545 gfx::GLImage* image); | 549 gfx::GLImage* image); |
546 | 550 |
547 void AddToSignature( | 551 void AddToSignature( |
548 Texture* info, | 552 Texture* texture, |
549 GLenum target, | 553 GLenum target, |
550 GLint level, | 554 GLint level, |
551 std::string* signature) const; | 555 std::string* signature) const; |
552 | 556 |
553 // Transfers added will get their Texture updated at the same time | 557 // Transfers added will get their Texture updated at the same time |
554 // the async transfer is bound to the real texture. | 558 // the async transfer is bound to the real texture. |
555 void AddPendingAsyncPixelTransfer( | 559 void AddPendingAsyncPixelTransfer( |
556 base::WeakPtr<gfx::AsyncPixelTransferState> state, Texture* info); | 560 base::WeakPtr<gfx::AsyncPixelTransferState> state, Texture* texture); |
557 void BindFinishedAsyncPixelTransfers(bool* texture_dirty, | 561 void BindFinishedAsyncPixelTransfers(bool* texture_dirty, |
558 bool* framebuffer_dirty); | 562 bool* framebuffer_dirty); |
559 | 563 |
560 private: | 564 private: |
561 friend class Texture; | 565 friend class Texture; |
562 | 566 |
563 // Helper for Initialize(). | 567 // Helper for Initialize(). |
564 scoped_refptr<Texture> CreateDefaultAndBlackTextures( | 568 scoped_refptr<Texture> CreateDefaultAndBlackTextures( |
565 GLenum target, | 569 GLenum target, |
566 GLuint* black_texture); | 570 GLuint* black_texture); |
567 | 571 |
568 void StartTracking(Texture* info); | 572 void StartTracking(Texture* texture); |
569 void StopTracking(Texture* info); | 573 void StopTracking(Texture* texture); |
570 | 574 |
571 MemoryTypeTracker* GetMemTracker(GLenum texture_pool); | 575 MemoryTypeTracker* GetMemTracker(GLenum texture_pool); |
572 scoped_ptr<MemoryTypeTracker> memory_tracker_managed_; | 576 scoped_ptr<MemoryTypeTracker> memory_tracker_managed_; |
573 scoped_ptr<MemoryTypeTracker> memory_tracker_unmanaged_; | 577 scoped_ptr<MemoryTypeTracker> memory_tracker_unmanaged_; |
574 | 578 |
575 scoped_refptr<FeatureInfo> feature_info_; | 579 scoped_refptr<FeatureInfo> feature_info_; |
576 | 580 |
577 // Info for each texture in the system. | 581 // Info for each texture in the system. |
578 typedef base::hash_map<GLuint, scoped_refptr<Texture> > TextureInfoMap; | 582 typedef base::hash_map<GLuint, scoped_refptr<Texture> > TextureMap; |
579 TextureInfoMap texture_infos_; | 583 TextureMap textures_; |
580 | 584 |
581 GLsizei max_texture_size_; | 585 GLsizei max_texture_size_; |
582 GLsizei max_cube_map_texture_size_; | 586 GLsizei max_cube_map_texture_size_; |
583 GLint max_levels_; | 587 GLint max_levels_; |
584 GLint max_cube_map_levels_; | 588 GLint max_cube_map_levels_; |
585 | 589 |
586 int num_unrenderable_textures_; | 590 int num_unrenderable_textures_; |
587 int num_unsafe_textures_; | 591 int num_unsafe_textures_; |
588 int num_uncleared_mips_; | 592 int num_uncleared_mips_; |
589 | 593 |
590 // Counts the number of Texture allocated with 'this' as its manager. | 594 // Counts the number of Textures allocated with 'this' as its manager. |
591 // Allows to check no Texture will outlive this. | 595 // Allows to check no Texture will outlive this. |
592 unsigned int texture_info_count_; | 596 unsigned int texture_count_; |
593 | 597 |
594 bool have_context_; | 598 bool have_context_; |
595 | 599 |
596 // Black (0,0,0,1) textures for when non-renderable textures are used. | 600 // Black (0,0,0,1) textures for when non-renderable textures are used. |
597 // NOTE: There is no corresponding Texture for these textures. | 601 // NOTE: There is no corresponding Texture for these textures. |
598 // TextureInfos are only for textures the client side can access. | 602 // TextureInfos are only for textures the client side can access. |
599 GLuint black_texture_ids_[kNumDefaultTextures]; | 603 GLuint black_texture_ids_[kNumDefaultTextures]; |
600 | 604 |
601 // The default textures for each target (texture name = 0) | 605 // The default textures for each target (texture name = 0) |
602 scoped_refptr<Texture> default_textures_[kNumDefaultTextures]; | 606 scoped_refptr<Texture> default_textures_[kNumDefaultTextures]; |
603 | 607 |
604 // Async texture allocations which haven't been bound to their textures | 608 // Async texture allocations which haven't been bound to their textures |
605 // yet. This facilitates updating the Texture at the same time the | 609 // yet. This facilitates updating the Texture at the same time the |
606 // real texture data is bound. | 610 // real texture data is bound. |
607 typedef std::pair<base::WeakPtr<gfx::AsyncPixelTransferState>, | 611 typedef std::pair<base::WeakPtr<gfx::AsyncPixelTransferState>, |
608 Texture*> PendingAsyncTransfer; | 612 Texture*> PendingAsyncTransfer; |
609 typedef std::list<PendingAsyncTransfer> PendingAsyncTransferList; | 613 typedef std::list<PendingAsyncTransfer> PendingAsyncTransferList; |
610 PendingAsyncTransferList pending_async_transfers_; | 614 PendingAsyncTransferList pending_async_transfers_; |
611 | 615 |
612 DISALLOW_COPY_AND_ASSIGN(TextureManager); | 616 DISALLOW_COPY_AND_ASSIGN(TextureManager); |
613 }; | 617 }; |
614 | 618 |
615 } // namespace gles2 | 619 } // namespace gles2 |
616 } // namespace gpu | 620 } // namespace gpu |
617 | 621 |
618 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ | 622 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ |
OLD | NEW |