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 #include "gpu/command_buffer/service/texture_manager.h" | 5 #include "gpu/command_buffer/service/texture_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 GLsizei height_; | 47 GLsizei height_; |
48 GLsizei depth_; | 48 GLsizei depth_; |
49 GLfloat max_lod_; | 49 GLfloat max_lod_; |
50 GLfloat min_lod_; | 50 GLfloat min_lod_; |
51 GLint base_level_; | 51 GLint base_level_; |
52 GLint border_; | 52 GLint border_; |
53 GLint max_level_; | 53 GLint max_level_; |
54 GLenum format_; | 54 GLenum format_; |
55 GLenum type_; | 55 GLenum type_; |
56 bool has_image_; | 56 bool has_image_; |
57 bool can_render_; | 57 bool texture_complete_; |
58 bool can_render_to_; | 58 bool can_render_to_; |
59 bool npot_; | 59 bool npot_; |
60 | 60 |
61 // Since we will be hashing this signature structure, the padding must be | 61 // Since we will be hashing this signature structure, the padding must be |
62 // zero initialized. Although the C++11 specifications specify that this is | 62 // zero initialized. Although the C++11 specifications specify that this is |
63 // true, we will use a constructor with a memset to further enforce it instead | 63 // true, we will use a constructor with a memset to further enforce it instead |
64 // of relying on compilers adhering to this deep dark corner specification. | 64 // of relying on compilers adhering to this deep dark corner specification. |
65 TextureSignature(GLenum target, | 65 TextureSignature(GLenum target, |
66 GLint level, | 66 GLint level, |
67 GLenum min_filter, | 67 GLenum min_filter, |
68 GLenum mag_filter, | 68 GLenum mag_filter, |
69 GLenum wrap_r, | 69 GLenum wrap_r, |
70 GLenum wrap_s, | 70 GLenum wrap_s, |
71 GLenum wrap_t, | 71 GLenum wrap_t, |
72 GLenum usage, | 72 GLenum usage, |
73 GLenum internal_format, | 73 GLenum internal_format, |
74 GLenum compare_func, | 74 GLenum compare_func, |
75 GLenum compare_mode, | 75 GLenum compare_mode, |
76 GLsizei width, | 76 GLsizei width, |
77 GLsizei height, | 77 GLsizei height, |
78 GLsizei depth, | 78 GLsizei depth, |
79 GLfloat max_lod, | 79 GLfloat max_lod, |
80 GLfloat min_lod, | 80 GLfloat min_lod, |
81 GLint base_level, | 81 GLint base_level, |
82 GLint border, | 82 GLint border, |
83 GLint max_level, | 83 GLint max_level, |
84 GLenum format, | 84 GLenum format, |
85 GLenum type, | 85 GLenum type, |
86 bool has_image, | 86 bool has_image, |
87 bool can_render, | 87 bool texture_complete, |
88 bool can_render_to, | 88 bool can_render_to, |
89 bool npot) { | 89 bool npot) { |
90 memset(this, 0, sizeof(TextureSignature)); | 90 memset(this, 0, sizeof(TextureSignature)); |
91 target_ = target; | 91 target_ = target; |
92 level_ = level; | 92 level_ = level; |
93 min_filter_ = min_filter; | 93 min_filter_ = min_filter; |
94 mag_filter_ = mag_filter; | 94 mag_filter_ = mag_filter; |
95 wrap_r_ = wrap_r; | 95 wrap_r_ = wrap_r; |
96 wrap_s_ = wrap_s; | 96 wrap_s_ = wrap_s; |
97 wrap_t_ = wrap_t; | 97 wrap_t_ = wrap_t; |
98 usage_ = usage; | 98 usage_ = usage; |
99 internal_format_ = internal_format; | 99 internal_format_ = internal_format; |
100 compare_func_ = compare_func; | 100 compare_func_ = compare_func; |
101 compare_mode_ = compare_mode; | 101 compare_mode_ = compare_mode; |
102 width_ = width; | 102 width_ = width; |
103 height_ = height; | 103 height_ = height; |
104 depth_ = depth; | 104 depth_ = depth; |
105 max_lod_ = max_lod; | 105 max_lod_ = max_lod; |
106 min_lod_ = min_lod; | 106 min_lod_ = min_lod; |
107 base_level_ = base_level; | 107 base_level_ = base_level; |
108 border_ = border; | 108 border_ = border; |
109 max_level_ = max_level; | 109 max_level_ = max_level; |
110 format_ = format; | 110 format_ = format; |
111 type_ = type; | 111 type_ = type; |
112 has_image_ = has_image; | 112 has_image_ = has_image; |
113 can_render_ = can_render; | 113 texture_complete_ = texture_complete; |
114 can_render_to_ = can_render_to; | 114 can_render_to_ = can_render_to; |
115 npot_ = npot; | 115 npot_ = npot; |
116 } | 116 } |
117 }; | 117 }; |
118 | 118 |
119 class FormatTypeValidator { | 119 class FormatTypeValidator { |
120 public: | 120 public: |
121 FormatTypeValidator() { | 121 FormatTypeValidator() { |
122 static const FormatType kSupportedFormatTypes[] = { | 122 static const FormatType kSupportedFormatTypes[] = { |
123 // ES2. | 123 // ES2. |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 wrap_t_(GL_REPEAT), | 321 wrap_t_(GL_REPEAT), |
322 usage_(GL_NONE), | 322 usage_(GL_NONE), |
323 pool_(GL_TEXTURE_POOL_UNMANAGED_CHROMIUM), | 323 pool_(GL_TEXTURE_POOL_UNMANAGED_CHROMIUM), |
324 compare_func_(GL_LEQUAL), | 324 compare_func_(GL_LEQUAL), |
325 compare_mode_(GL_NONE), | 325 compare_mode_(GL_NONE), |
326 max_lod_(1000.0f), | 326 max_lod_(1000.0f), |
327 min_lod_(-1000.0f), | 327 min_lod_(-1000.0f), |
328 base_level_(0), | 328 base_level_(0), |
329 max_level_(1000), | 329 max_level_(1000), |
330 max_level_set_(-1), | 330 max_level_set_(-1), |
331 texture_complete_(false), | 331 texture_2d_complete_(false), |
332 texture_mips_dirty_(false), | 332 texture_mips_dirty_(false), |
333 texture_mips_complete_(false), | 333 texture_mips_complete_(false), |
334 cube_complete_(false), | 334 cube_complete_(false), |
335 texture_level0_dirty_(false), | 335 texture_level0_dirty_(false), |
336 texture_level0_complete_(false), | 336 texture_level0_complete_(false), |
337 npot_(false), | 337 npot_(false), |
338 has_been_bound_(false), | 338 has_been_bound_(false), |
339 framebuffer_attachment_count_(0), | 339 framebuffer_attachment_count_(0), |
340 immutable_(false), | 340 immutable_(false), |
341 has_images_(false), | 341 has_images_(false), |
342 estimated_size_(0), | 342 estimated_size_(0), |
343 can_render_condition_(CAN_RENDER_ALWAYS), | 343 texture_completeness(TEXTURE_COMPLETE_ALWAYS), |
344 texture_max_anisotropy_initialized_(false) { | 344 texture_max_anisotropy_initialized_(false) {} |
345 } | |
346 | 345 |
347 Texture::~Texture() { | 346 Texture::~Texture() { |
348 if (mailbox_manager_) | 347 if (mailbox_manager_) |
349 mailbox_manager_->TextureDeleted(this); | 348 mailbox_manager_->TextureDeleted(this); |
350 } | 349 } |
351 | 350 |
352 void Texture::AddTextureRef(TextureRef* ref) { | 351 void Texture::AddTextureRef(TextureRef* ref) { |
353 DCHECK(refs_.find(ref) == refs_.end()); | 352 DCHECK(refs_.find(ref) == refs_.end()); |
354 refs_.insert(ref); | 353 refs_.insert(ref); |
355 if (!memory_tracking_ref_) { | 354 if (!memory_tracking_ref_) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 Texture::LevelInfo::~LevelInfo() { | 414 Texture::LevelInfo::~LevelInfo() { |
416 } | 415 } |
417 | 416 |
418 Texture::FaceInfo::FaceInfo() | 417 Texture::FaceInfo::FaceInfo() |
419 : num_mip_levels(0) { | 418 : num_mip_levels(0) { |
420 } | 419 } |
421 | 420 |
422 Texture::FaceInfo::~FaceInfo() { | 421 Texture::FaceInfo::~FaceInfo() { |
423 } | 422 } |
424 | 423 |
425 Texture::CanRenderCondition Texture::GetCanRenderCondition() const { | 424 Texture::TextureCompleteness Texture::GetTextureCompleteness() const { |
426 if (target_ == 0) | 425 if (target_ == 0) |
427 return CAN_RENDER_ALWAYS; | 426 return TEXTURE_COMPLETE_ALWAYS; |
428 | 427 |
429 if (target_ != GL_TEXTURE_EXTERNAL_OES) { | 428 if (target_ != GL_TEXTURE_EXTERNAL_OES) { |
430 if (face_infos_.empty()) { | 429 if (face_infos_.empty()) { |
431 return CAN_RENDER_NEVER; | 430 return TEXTURE_INCOMPLETE; |
432 } | 431 } |
433 | 432 |
434 const Texture::LevelInfo& first_face = face_infos_[0].level_infos[0]; | 433 const Texture::LevelInfo& first_face = face_infos_[0].level_infos[0]; |
435 if (first_face.width == 0 || | 434 if (first_face.width == 0 || |
436 first_face.height == 0 || | 435 first_face.height == 0 || |
437 first_face.depth == 0) { | 436 first_face.depth == 0) { |
438 return CAN_RENDER_NEVER; | 437 return TEXTURE_INCOMPLETE; |
439 } | 438 } |
440 } | 439 } |
441 | 440 |
442 bool needs_mips = NeedsMips(); | 441 bool needs_mips = NeedsMips(); |
443 if (needs_mips) { | 442 if (needs_mips) { |
444 if (!texture_complete()) | 443 if (!texture_2d_complete()) |
445 return CAN_RENDER_NEVER; | 444 return TEXTURE_INCOMPLETE; |
446 if (target_ == GL_TEXTURE_CUBE_MAP && !cube_complete()) | 445 if (target_ == GL_TEXTURE_CUBE_MAP && !cube_complete()) |
447 return CAN_RENDER_NEVER; | 446 return TEXTURE_INCOMPLETE; |
448 } | 447 } |
449 | 448 |
450 bool is_npot_compatible = !needs_mips && | 449 bool is_npot_compatible = !needs_mips && |
451 wrap_s_ == GL_CLAMP_TO_EDGE && | 450 wrap_s_ == GL_CLAMP_TO_EDGE && |
452 wrap_t_ == GL_CLAMP_TO_EDGE; | 451 wrap_t_ == GL_CLAMP_TO_EDGE; |
453 | 452 |
454 if (!is_npot_compatible) { | 453 if (!is_npot_compatible) { |
455 if (target_ == GL_TEXTURE_RECTANGLE_ARB) | 454 if (target_ == GL_TEXTURE_RECTANGLE_ARB) |
456 return CAN_RENDER_NEVER; | 455 return TEXTURE_INCOMPLETE; |
457 else if (npot()) | 456 else if (npot()) |
458 return CAN_RENDER_ONLY_IF_NPOT; | 457 return TEXTURE_COMPLETE_ONLY_IF_NPOT; |
459 } | 458 } |
460 | 459 |
461 return CAN_RENDER_ALWAYS; | 460 return TEXTURE_COMPLETE_ALWAYS; |
462 } | 461 } |
463 | 462 |
464 bool Texture::CanRender(const FeatureInfo* feature_info) const { | 463 bool Texture::IsTextureComplete(const FeatureInfo* feature_info) const { |
465 switch (can_render_condition_) { | 464 switch (texture_completeness) { |
466 case CAN_RENDER_ALWAYS: | 465 case TEXTURE_COMPLETE_ALWAYS: |
467 return true; | 466 return true; |
468 case CAN_RENDER_NEVER: | 467 case TEXTURE_INCOMPLETE: |
469 return false; | 468 return false; |
470 case CAN_RENDER_ONLY_IF_NPOT: | 469 case TEXTURE_COMPLETE_ONLY_IF_NPOT: |
471 break; | 470 break; |
472 } | 471 } |
473 return feature_info->feature_flags().npot_ok; | 472 return feature_info->feature_flags().npot_ok; |
474 } | 473 } |
475 | 474 |
476 void Texture::AddToSignature( | 475 void Texture::AddToSignature( |
477 const FeatureInfo* feature_info, | 476 const FeatureInfo* feature_info, |
478 GLenum target, | 477 GLenum target, |
479 GLint level, | 478 GLint level, |
480 std::string* signature) const { | 479 std::string* signature) const { |
481 DCHECK(feature_info); | 480 DCHECK(feature_info); |
482 DCHECK(signature); | 481 DCHECK(signature); |
483 DCHECK_GE(level, 0); | 482 DCHECK_GE(level, 0); |
484 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 483 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
485 DCHECK_LT(static_cast<size_t>(face_index), | 484 DCHECK_LT(static_cast<size_t>(face_index), |
486 face_infos_.size()); | 485 face_infos_.size()); |
487 DCHECK_LT(static_cast<size_t>(level), | 486 DCHECK_LT(static_cast<size_t>(level), |
488 face_infos_[face_index].level_infos.size()); | 487 face_infos_[face_index].level_infos.size()); |
489 | 488 |
490 const Texture::LevelInfo& info = | 489 const Texture::LevelInfo& info = |
491 face_infos_[face_index].level_infos[level]; | 490 face_infos_[face_index].level_infos[level]; |
492 | 491 |
493 TextureSignature signature_data(target, | 492 TextureSignature signature_data( |
494 level, | 493 target, level, min_filter_, mag_filter_, wrap_r_, wrap_s_, wrap_t_, |
495 min_filter_, | 494 usage_, info.internal_format, compare_func_, compare_mode_, info.width, |
496 mag_filter_, | 495 info.height, info.depth, max_lod_, min_lod_, base_level_, info.border, |
497 wrap_r_, | 496 max_level_, info.format, info.type, info.image.get() != NULL, |
498 wrap_s_, | 497 IsTextureComplete(feature_info), CanRenderTo(), npot_); |
499 wrap_t_, | |
500 usage_, | |
501 info.internal_format, | |
502 compare_func_, | |
503 compare_mode_, | |
504 info.width, | |
505 info.height, | |
506 info.depth, | |
507 max_lod_, | |
508 min_lod_, | |
509 base_level_, | |
510 info.border, | |
511 max_level_, | |
512 info.format, | |
513 info.type, | |
514 info.image.get() != NULL, | |
515 CanRender(feature_info), | |
516 CanRenderTo(), | |
517 npot_); | |
518 | 498 |
519 signature->append(TextureTag, sizeof(TextureTag)); | 499 signature->append(TextureTag, sizeof(TextureTag)); |
520 signature->append(reinterpret_cast<const char*>(&signature_data), | 500 signature->append(reinterpret_cast<const char*>(&signature_data), |
521 sizeof(signature_data)); | 501 sizeof(signature_data)); |
522 } | 502 } |
523 | 503 |
524 void Texture::SetMailboxManager(MailboxManager* mailbox_manager) { | 504 void Texture::SetMailboxManager(MailboxManager* mailbox_manager) { |
525 DCHECK(!mailbox_manager_ || mailbox_manager_ == mailbox_manager); | 505 DCHECK(!mailbox_manager_ || mailbox_manager_ == mailbox_manager); |
526 mailbox_manager_ = mailbox_manager; | 506 mailbox_manager_ = mailbox_manager; |
527 } | 507 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 | 546 |
567 if (target == GL_TEXTURE_EXTERNAL_OES || target == GL_TEXTURE_RECTANGLE_ARB) { | 547 if (target == GL_TEXTURE_EXTERNAL_OES || target == GL_TEXTURE_RECTANGLE_ARB) { |
568 min_filter_ = GL_LINEAR; | 548 min_filter_ = GL_LINEAR; |
569 wrap_s_ = wrap_t_ = GL_CLAMP_TO_EDGE; | 549 wrap_s_ = wrap_t_ = GL_CLAMP_TO_EDGE; |
570 } | 550 } |
571 | 551 |
572 if (target == GL_TEXTURE_EXTERNAL_OES) { | 552 if (target == GL_TEXTURE_EXTERNAL_OES) { |
573 immutable_ = true; | 553 immutable_ = true; |
574 } | 554 } |
575 Update(feature_info); | 555 Update(feature_info); |
576 UpdateCanRenderCondition(); | 556 UpdateTextureCompleteness(); |
577 } | 557 } |
578 | 558 |
579 bool Texture::CanGenerateMipmaps( | 559 bool Texture::CanGenerateMipmaps( |
580 const FeatureInfo* feature_info) const { | 560 const FeatureInfo* feature_info) const { |
581 if ((npot() && !feature_info->feature_flags().npot_ok) || | 561 if ((npot() && !feature_info->feature_flags().npot_ok) || |
582 face_infos_.empty() || | 562 face_infos_.empty() || |
583 target_ == GL_TEXTURE_EXTERNAL_OES || | 563 target_ == GL_TEXTURE_EXTERNAL_OES || |
584 target_ == GL_TEXTURE_RECTANGLE_ARB) { | 564 target_ == GL_TEXTURE_RECTANGLE_ARB) { |
585 return false; | 565 return false; |
586 } | 566 } |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 info->cleared_rect = cleared_rect; | 704 info->cleared_rect = cleared_rect; |
725 bool cleared = info->cleared_rect == gfx::Rect(info->width, info->height); | 705 bool cleared = info->cleared_rect == gfx::Rect(info->width, info->height); |
726 if (cleared == was_cleared) | 706 if (cleared == was_cleared) |
727 return; | 707 return; |
728 int delta = cleared ? -1 : +1; | 708 int delta = cleared ? -1 : +1; |
729 num_uncleared_mips_ += delta; | 709 num_uncleared_mips_ += delta; |
730 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) | 710 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) |
731 (*it)->manager()->UpdateUnclearedMips(delta); | 711 (*it)->manager()->UpdateUnclearedMips(delta); |
732 } | 712 } |
733 | 713 |
734 void Texture::UpdateCanRenderCondition() { | 714 void Texture::UpdateTextureCompleteness() { |
735 CanRenderCondition can_render_condition = GetCanRenderCondition(); | 715 TextureCompleteness new_texture_completeness = GetTextureCompleteness(); |
736 if (can_render_condition_ == can_render_condition) | 716 if (texture_completeness == new_texture_completeness) |
737 return; | 717 return; |
738 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) | 718 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) |
739 (*it)->manager()->UpdateCanRenderCondition(can_render_condition_, | 719 (*it)->manager()->UpdateTextureCompleteness(texture_completeness, |
740 can_render_condition); | 720 new_texture_completeness); |
741 can_render_condition_ = can_render_condition; | 721 texture_completeness = new_texture_completeness; |
742 } | 722 } |
743 | 723 |
744 void Texture::UpdateHasImages() { | 724 void Texture::UpdateHasImages() { |
745 if (face_infos_.empty()) | 725 if (face_infos_.empty()) |
746 return; | 726 return; |
747 | 727 |
748 bool has_images = false; | 728 bool has_images = false; |
749 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { | 729 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { |
750 for (size_t jj = 0; jj < face_infos_[ii].level_infos.size(); ++jj) { | 730 for (size_t jj = 0; jj < face_infos_[ii].level_infos.size(); ++jj) { |
751 const Texture::LevelInfo& info = face_infos_[ii].level_infos[jj]; | 731 const Texture::LevelInfo& info = face_infos_[ii].level_infos[jj]; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 UpdateMipCleared(&info, width, height, cleared_rect); | 813 UpdateMipCleared(&info, width, height, cleared_rect); |
834 | 814 |
835 estimated_size_ -= info.estimated_size; | 815 estimated_size_ -= info.estimated_size; |
836 GLES2Util::ComputeImageDataSizes( | 816 GLES2Util::ComputeImageDataSizes( |
837 width, height, 1, format, type, 4, &info.estimated_size, NULL, NULL); | 817 width, height, 1, format, type, 4, &info.estimated_size, NULL, NULL); |
838 estimated_size_ += info.estimated_size; | 818 estimated_size_ += info.estimated_size; |
839 | 819 |
840 max_level_set_ = std::max(max_level_set_, level); | 820 max_level_set_ = std::max(max_level_set_, level); |
841 Update(feature_info); | 821 Update(feature_info); |
842 UpdateCleared(); | 822 UpdateCleared(); |
843 UpdateCanRenderCondition(); | 823 UpdateTextureCompleteness(); |
844 UpdateHasImages(); | 824 UpdateHasImages(); |
845 if (IsAttachedToFramebuffer()) { | 825 if (IsAttachedToFramebuffer()) { |
846 // TODO(gman): If textures tracked which framebuffers they were attached to | 826 // TODO(gman): If textures tracked which framebuffers they were attached to |
847 // we could just mark those framebuffers as not complete. | 827 // we could just mark those framebuffers as not complete. |
848 IncAllFramebufferStateChangeCount(); | 828 IncAllFramebufferStateChangeCount(); |
849 } | 829 } |
850 } | 830 } |
851 | 831 |
852 bool Texture::ValidForTexture( | 832 bool Texture::ValidForTexture( |
853 GLint target, | 833 GLint target, |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 return GL_INVALID_ENUM; | 990 return GL_INVALID_ENUM; |
1011 } | 991 } |
1012 usage_ = param; | 992 usage_ = param; |
1013 break; | 993 break; |
1014 default: | 994 default: |
1015 NOTREACHED(); | 995 NOTREACHED(); |
1016 return GL_INVALID_ENUM; | 996 return GL_INVALID_ENUM; |
1017 } | 997 } |
1018 Update(feature_info); | 998 Update(feature_info); |
1019 UpdateCleared(); | 999 UpdateCleared(); |
1020 UpdateCanRenderCondition(); | 1000 UpdateTextureCompleteness(); |
1021 return GL_NO_ERROR; | 1001 return GL_NO_ERROR; |
1022 } | 1002 } |
1023 | 1003 |
1024 GLenum Texture::SetParameterf( | 1004 GLenum Texture::SetParameterf( |
1025 const FeatureInfo* feature_info, GLenum pname, GLfloat param) { | 1005 const FeatureInfo* feature_info, GLenum pname, GLfloat param) { |
1026 switch (pname) { | 1006 switch (pname) { |
1027 case GL_TEXTURE_MIN_FILTER: | 1007 case GL_TEXTURE_MIN_FILTER: |
1028 case GL_TEXTURE_MAG_FILTER: | 1008 case GL_TEXTURE_MAG_FILTER: |
1029 case GL_TEXTURE_POOL_CHROMIUM: | 1009 case GL_TEXTURE_POOL_CHROMIUM: |
1030 case GL_TEXTURE_WRAP_R: | 1010 case GL_TEXTURE_WRAP_R: |
(...skipping 25 matching lines...) Expand all Loading... |
1056 } | 1036 } |
1057 return GL_NO_ERROR; | 1037 return GL_NO_ERROR; |
1058 } | 1038 } |
1059 | 1039 |
1060 void Texture::Update(const FeatureInfo* feature_info) { | 1040 void Texture::Update(const FeatureInfo* feature_info) { |
1061 // Update npot status. | 1041 // Update npot status. |
1062 // Assume GL_TEXTURE_EXTERNAL_OES textures are npot, all others | 1042 // Assume GL_TEXTURE_EXTERNAL_OES textures are npot, all others |
1063 npot_ = (target_ == GL_TEXTURE_EXTERNAL_OES) || (num_npot_faces_ > 0); | 1043 npot_ = (target_ == GL_TEXTURE_EXTERNAL_OES) || (num_npot_faces_ > 0); |
1064 | 1044 |
1065 if (face_infos_.empty()) { | 1045 if (face_infos_.empty()) { |
1066 texture_complete_ = false; | 1046 texture_2d_complete_ = false; |
1067 cube_complete_ = false; | 1047 cube_complete_ = false; |
1068 return; | 1048 return; |
1069 } | 1049 } |
1070 | 1050 |
1071 // Update texture_complete and cube_complete status. | 1051 // Update texture_complete and cube_complete status. |
1072 const Texture::FaceInfo& first_face = face_infos_[0]; | 1052 const Texture::FaceInfo& first_face = face_infos_[0]; |
1073 const Texture::LevelInfo& first_level = first_face.level_infos[0]; | 1053 const Texture::LevelInfo& first_level = first_face.level_infos[0]; |
1074 const GLsizei levels_needed = first_face.num_mip_levels; | 1054 const GLsizei levels_needed = first_face.num_mip_levels; |
1075 | 1055 |
1076 texture_complete_ = | 1056 texture_2d_complete_ = |
1077 max_level_set_ >= (levels_needed - 1) && max_level_set_ >= 0; | 1057 max_level_set_ >= (levels_needed - 1) && max_level_set_ >= 0; |
1078 cube_complete_ = (face_infos_.size() == 6) && | 1058 cube_complete_ = (face_infos_.size() == 6) && |
1079 (first_level.width == first_level.height); | 1059 (first_level.width == first_level.height); |
1080 | 1060 |
1081 if (first_level.width == 0 || first_level.height == 0) { | 1061 if (first_level.width == 0 || first_level.height == 0) { |
1082 texture_complete_ = false; | 1062 texture_2d_complete_ = false; |
1083 } else if (first_level.type == GL_FLOAT && | 1063 } else if (first_level.type == GL_FLOAT && |
1084 !feature_info->feature_flags().enable_texture_float_linear && | 1064 !feature_info->feature_flags().enable_texture_float_linear && |
1085 (min_filter_ != GL_NEAREST_MIPMAP_NEAREST || | 1065 (min_filter_ != GL_NEAREST_MIPMAP_NEAREST || |
1086 mag_filter_ != GL_NEAREST)) { | 1066 mag_filter_ != GL_NEAREST)) { |
1087 texture_complete_ = false; | 1067 texture_2d_complete_ = false; |
1088 } else if (first_level.type == GL_HALF_FLOAT_OES && | 1068 } else if (first_level.type == GL_HALF_FLOAT_OES && |
1089 !feature_info->feature_flags().enable_texture_half_float_linear && | 1069 !feature_info->feature_flags().enable_texture_half_float_linear && |
1090 (min_filter_ != GL_NEAREST_MIPMAP_NEAREST || | 1070 (min_filter_ != GL_NEAREST_MIPMAP_NEAREST || |
1091 mag_filter_ != GL_NEAREST)) { | 1071 mag_filter_ != GL_NEAREST)) { |
1092 texture_complete_ = false; | 1072 texture_2d_complete_ = false; |
1093 } | 1073 } |
1094 | 1074 |
1095 if (cube_complete_ && texture_level0_dirty_) { | 1075 if (cube_complete_ && texture_level0_dirty_) { |
1096 texture_level0_complete_ = true; | 1076 texture_level0_complete_ = true; |
1097 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { | 1077 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { |
1098 const Texture::LevelInfo& level0 = face_infos_[ii].level_infos[0]; | 1078 const Texture::LevelInfo& level0 = face_infos_[ii].level_infos[0]; |
1099 if (!TextureFaceComplete(first_level, | 1079 if (!TextureFaceComplete(first_level, |
1100 ii, | 1080 ii, |
1101 level0.target, | 1081 level0.target, |
1102 level0.internal_format, | 1082 level0.internal_format, |
1103 level0.width, | 1083 level0.width, |
1104 level0.height, | 1084 level0.height, |
1105 level0.depth, | 1085 level0.depth, |
1106 level0.format, | 1086 level0.format, |
1107 level0.type)) { | 1087 level0.type)) { |
1108 texture_level0_complete_ = false; | 1088 texture_level0_complete_ = false; |
1109 break; | 1089 break; |
1110 } | 1090 } |
1111 } | 1091 } |
1112 texture_level0_dirty_ = false; | 1092 texture_level0_dirty_ = false; |
1113 } | 1093 } |
1114 cube_complete_ &= texture_level0_complete_; | 1094 cube_complete_ &= texture_level0_complete_; |
1115 | 1095 |
1116 if (texture_complete_ && texture_mips_dirty_) { | 1096 if (texture_2d_complete_ && texture_mips_dirty_) { |
1117 texture_mips_complete_ = true; | 1097 texture_mips_complete_ = true; |
1118 for (size_t ii = 0; | 1098 for (size_t ii = 0; |
1119 ii < face_infos_.size() && texture_mips_complete_; | 1099 ii < face_infos_.size() && texture_mips_complete_; |
1120 ++ii) { | 1100 ++ii) { |
1121 const Texture::FaceInfo& face_info = face_infos_[ii]; | 1101 const Texture::FaceInfo& face_info = face_infos_[ii]; |
1122 const Texture::LevelInfo& level0 = face_info.level_infos[0]; | 1102 const Texture::LevelInfo& level0 = face_info.level_infos[0]; |
1123 for (GLsizei jj = 1; jj < levels_needed; ++jj) { | 1103 for (GLsizei jj = 1; jj < levels_needed; ++jj) { |
1124 const Texture::LevelInfo& level_info = face_infos_[ii].level_infos[jj]; | 1104 const Texture::LevelInfo& level_info = face_infos_[ii].level_infos[jj]; |
1125 if (!TextureMipComplete(level0, | 1105 if (!TextureMipComplete(level0, |
1126 level_info.target, | 1106 level_info.target, |
1127 jj, | 1107 jj, |
1128 level_info.internal_format, | 1108 level_info.internal_format, |
1129 level_info.width, | 1109 level_info.width, |
1130 level_info.height, | 1110 level_info.height, |
1131 level_info.depth, | 1111 level_info.depth, |
1132 level_info.format, | 1112 level_info.format, |
1133 level_info.type)) { | 1113 level_info.type)) { |
1134 texture_mips_complete_ = false; | 1114 texture_mips_complete_ = false; |
1135 break; | 1115 break; |
1136 } | 1116 } |
1137 } | 1117 } |
1138 } | 1118 } |
1139 texture_mips_dirty_ = false; | 1119 texture_mips_dirty_ = false; |
1140 } | 1120 } |
1141 texture_complete_ &= texture_mips_complete_; | 1121 texture_2d_complete_ &= texture_mips_complete_; |
1142 } | 1122 } |
1143 | 1123 |
1144 bool Texture::ClearRenderableLevels(GLES2Decoder* decoder) { | 1124 bool Texture::ClearRenderableLevels(GLES2Decoder* decoder) { |
1145 DCHECK(decoder); | 1125 DCHECK(decoder); |
1146 if (cleared_) { | 1126 if (cleared_) { |
1147 return true; | 1127 return true; |
1148 } | 1128 } |
1149 | 1129 |
1150 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { | 1130 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { |
1151 const Texture::FaceInfo& face_info = face_infos_[ii]; | 1131 const Texture::FaceInfo& face_info = face_infos_[ii]; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1254 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 1234 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
1255 DCHECK_LT(static_cast<size_t>(face_index), | 1235 DCHECK_LT(static_cast<size_t>(face_index), |
1256 face_infos_.size()); | 1236 face_infos_.size()); |
1257 DCHECK_LT(static_cast<size_t>(level), | 1237 DCHECK_LT(static_cast<size_t>(level), |
1258 face_infos_[face_index].level_infos.size()); | 1238 face_infos_[face_index].level_infos.size()); |
1259 Texture::LevelInfo& info = | 1239 Texture::LevelInfo& info = |
1260 face_infos_[face_index].level_infos[level]; | 1240 face_infos_[face_index].level_infos[level]; |
1261 DCHECK_EQ(info.target, target); | 1241 DCHECK_EQ(info.target, target); |
1262 DCHECK_EQ(info.level, level); | 1242 DCHECK_EQ(info.level, level); |
1263 info.image = image; | 1243 info.image = image; |
1264 UpdateCanRenderCondition(); | 1244 UpdateTextureCompleteness(); |
1265 UpdateHasImages(); | 1245 UpdateHasImages(); |
1266 } | 1246 } |
1267 | 1247 |
1268 gfx::GLImage* Texture::GetLevelImage(GLint target, GLint level) const { | 1248 gfx::GLImage* Texture::GetLevelImage(GLint target, GLint level) const { |
1269 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES && | 1249 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES && |
1270 target != GL_TEXTURE_RECTANGLE_ARB) { | 1250 target != GL_TEXTURE_RECTANGLE_ARB) { |
1271 return NULL; | 1251 return NULL; |
1272 } | 1252 } |
1273 | 1253 |
1274 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 1254 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1626 textures_.erase(it); | 1606 textures_.erase(it); |
1627 } | 1607 } |
1628 } | 1608 } |
1629 | 1609 |
1630 void TextureManager::StartTracking(TextureRef* ref) { | 1610 void TextureManager::StartTracking(TextureRef* ref) { |
1631 Texture* texture = ref->texture(); | 1611 Texture* texture = ref->texture(); |
1632 ++texture_count_; | 1612 ++texture_count_; |
1633 num_uncleared_mips_ += texture->num_uncleared_mips(); | 1613 num_uncleared_mips_ += texture->num_uncleared_mips(); |
1634 if (!texture->SafeToRenderFrom()) | 1614 if (!texture->SafeToRenderFrom()) |
1635 ++num_unsafe_textures_; | 1615 ++num_unsafe_textures_; |
1636 if (!texture->CanRender(feature_info_.get())) | 1616 if (!texture->IsTextureComplete(feature_info_.get())) |
1637 ++num_unrenderable_textures_; | 1617 ++num_unrenderable_textures_; |
1638 if (texture->HasImages()) | 1618 if (texture->HasImages()) |
1639 ++num_images_; | 1619 ++num_images_; |
1640 } | 1620 } |
1641 | 1621 |
1642 void TextureManager::StopTracking(TextureRef* ref) { | 1622 void TextureManager::StopTracking(TextureRef* ref) { |
1643 if (ref->num_observers()) { | 1623 if (ref->num_observers()) { |
1644 for (unsigned int i = 0; i < destruction_observers_.size(); i++) { | 1624 for (unsigned int i = 0; i < destruction_observers_.size(); i++) { |
1645 destruction_observers_[i]->OnTextureRefDestroying(ref); | 1625 destruction_observers_[i]->OnTextureRefDestroying(ref); |
1646 } | 1626 } |
1647 DCHECK_EQ(ref->num_observers(), 0); | 1627 DCHECK_EQ(ref->num_observers(), 0); |
1648 } | 1628 } |
1649 | 1629 |
1650 Texture* texture = ref->texture(); | 1630 Texture* texture = ref->texture(); |
1651 | 1631 |
1652 --texture_count_; | 1632 --texture_count_; |
1653 if (texture->HasImages()) { | 1633 if (texture->HasImages()) { |
1654 DCHECK_NE(0, num_images_); | 1634 DCHECK_NE(0, num_images_); |
1655 --num_images_; | 1635 --num_images_; |
1656 } | 1636 } |
1657 if (!texture->CanRender(feature_info_.get())) { | 1637 if (!texture->IsTextureComplete(feature_info_.get())) { |
1658 DCHECK_NE(0, num_unrenderable_textures_); | 1638 DCHECK_NE(0, num_unrenderable_textures_); |
1659 --num_unrenderable_textures_; | 1639 --num_unrenderable_textures_; |
1660 } | 1640 } |
1661 if (!texture->SafeToRenderFrom()) { | 1641 if (!texture->SafeToRenderFrom()) { |
1662 DCHECK_NE(0, num_unsafe_textures_); | 1642 DCHECK_NE(0, num_unsafe_textures_); |
1663 --num_unsafe_textures_; | 1643 --num_unsafe_textures_; |
1664 } | 1644 } |
1665 num_uncleared_mips_ -= texture->num_uncleared_mips(); | 1645 num_uncleared_mips_ -= texture->num_uncleared_mips(); |
1666 DCHECK_GE(num_uncleared_mips_, 0); | 1646 DCHECK_GE(num_uncleared_mips_, 0); |
1667 } | 1647 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1729 void TextureManager::UpdateSafeToRenderFrom(int delta) { | 1709 void TextureManager::UpdateSafeToRenderFrom(int delta) { |
1730 num_unsafe_textures_ += delta; | 1710 num_unsafe_textures_ += delta; |
1731 DCHECK_GE(num_unsafe_textures_, 0); | 1711 DCHECK_GE(num_unsafe_textures_, 0); |
1732 } | 1712 } |
1733 | 1713 |
1734 void TextureManager::UpdateUnclearedMips(int delta) { | 1714 void TextureManager::UpdateUnclearedMips(int delta) { |
1735 num_uncleared_mips_ += delta; | 1715 num_uncleared_mips_ += delta; |
1736 DCHECK_GE(num_uncleared_mips_, 0); | 1716 DCHECK_GE(num_uncleared_mips_, 0); |
1737 } | 1717 } |
1738 | 1718 |
1739 void TextureManager::UpdateCanRenderCondition( | 1719 void TextureManager::UpdateTextureCompleteness( |
1740 Texture::CanRenderCondition old_condition, | 1720 Texture::TextureCompleteness old_completeness, |
1741 Texture::CanRenderCondition new_condition) { | 1721 Texture::TextureCompleteness new_completeness) { |
1742 if (old_condition == Texture::CAN_RENDER_NEVER || | 1722 if (old_completeness == Texture::TEXTURE_INCOMPLETE || |
1743 (old_condition == Texture::CAN_RENDER_ONLY_IF_NPOT && | 1723 (old_completeness == Texture::TEXTURE_COMPLETE_ONLY_IF_NPOT && |
1744 !feature_info_->feature_flags().npot_ok)) { | 1724 !feature_info_->feature_flags().npot_ok)) { |
1745 DCHECK_GT(num_unrenderable_textures_, 0); | 1725 DCHECK_GT(num_unrenderable_textures_, 0); |
1746 --num_unrenderable_textures_; | 1726 --num_unrenderable_textures_; |
1747 } | 1727 } |
1748 if (new_condition == Texture::CAN_RENDER_NEVER || | 1728 if (new_completeness == Texture::TEXTURE_INCOMPLETE || |
1749 (new_condition == Texture::CAN_RENDER_ONLY_IF_NPOT && | 1729 (new_completeness == Texture::TEXTURE_COMPLETE_ONLY_IF_NPOT && |
1750 !feature_info_->feature_flags().npot_ok)) | 1730 !feature_info_->feature_flags().npot_ok)) |
1751 ++num_unrenderable_textures_; | 1731 ++num_unrenderable_textures_; |
1752 } | 1732 } |
1753 | 1733 |
1754 void TextureManager::UpdateNumImages(int delta) { | 1734 void TextureManager::UpdateNumImages(int delta) { |
1755 num_images_ += delta; | 1735 num_images_ += delta; |
1756 DCHECK_GE(num_images_, 0); | 1736 DCHECK_GE(num_images_, 0); |
1757 } | 1737 } |
1758 | 1738 |
1759 void TextureManager::IncFramebufferStateChangeCount() { | 1739 void TextureManager::IncFramebufferStateChangeCount() { |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2099 // The link to the memory tracking |client_id| is given a higher importance | 2079 // The link to the memory tracking |client_id| is given a higher importance |
2100 // than other refs. | 2080 // than other refs. |
2101 if (ref == ref->texture()->memory_tracking_ref_) | 2081 if (ref == ref->texture()->memory_tracking_ref_) |
2102 importance = 2; | 2082 importance = 2; |
2103 | 2083 |
2104 pmd->AddOwnershipEdge(client_guid, service_guid, importance); | 2084 pmd->AddOwnershipEdge(client_guid, service_guid, importance); |
2105 } | 2085 } |
2106 | 2086 |
2107 } // namespace gles2 | 2087 } // namespace gles2 |
2108 } // namespace gpu | 2088 } // namespace gpu |
OLD | NEW |