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 #include "gpu/command_buffer/service/texture_manager.h" | 5 #include "gpu/command_buffer/service/texture_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 GLfloat min_lod_; | 58 GLfloat min_lod_; |
| 59 GLint base_level_; | 59 GLint base_level_; |
| 60 GLint border_; | 60 GLint border_; |
| 61 GLint max_level_; | 61 GLint max_level_; |
| 62 GLenum format_; | 62 GLenum format_; |
| 63 GLenum type_; | 63 GLenum type_; |
| 64 bool has_image_; | 64 bool has_image_; |
| 65 bool can_render_; | 65 bool can_render_; |
| 66 bool can_render_to_; | 66 bool can_render_to_; |
| 67 bool npot_; | 67 bool npot_; |
| 68 bool emulating_rgb_; | |
| 68 | 69 |
| 69 // Since we will be hashing this signature structure, the padding must be | 70 // Since we will be hashing this signature structure, the padding must be |
| 70 // zero initialized. Although the C++11 specifications specify that this is | 71 // zero initialized. Although the C++11 specifications specify that this is |
| 71 // true, we will use a constructor with a memset to further enforce it instead | 72 // true, we will use a constructor with a memset to further enforce it instead |
| 72 // of relying on compilers adhering to this deep dark corner specification. | 73 // of relying on compilers adhering to this deep dark corner specification. |
| 73 TextureSignature(GLenum target, | 74 TextureSignature(GLenum target, |
| 74 GLint level, | 75 GLint level, |
| 75 const SamplerState& sampler_state, | 76 const SamplerState& sampler_state, |
| 76 GLenum usage, | 77 GLenum usage, |
| 77 GLenum internal_format, | 78 GLenum internal_format, |
| 78 GLsizei width, | 79 GLsizei width, |
| 79 GLsizei height, | 80 GLsizei height, |
| 80 GLsizei depth, | 81 GLsizei depth, |
| 81 GLint base_level, | 82 GLint base_level, |
| 82 GLint border, | 83 GLint border, |
| 83 GLint max_level, | 84 GLint max_level, |
| 84 GLenum format, | 85 GLenum format, |
| 85 GLenum type, | 86 GLenum type, |
| 86 bool has_image, | 87 bool has_image, |
| 87 bool can_render, | 88 bool can_render, |
| 88 bool can_render_to, | 89 bool can_render_to, |
| 89 bool npot) { | 90 bool npot, |
| 91 bool emulating_rgb) { | |
| 90 memset(this, 0, sizeof(TextureSignature)); | 92 memset(this, 0, sizeof(TextureSignature)); |
| 91 target_ = target; | 93 target_ = target; |
| 92 level_ = level; | 94 level_ = level; |
| 93 min_filter_ = sampler_state.min_filter; | 95 min_filter_ = sampler_state.min_filter; |
| 94 mag_filter_ = sampler_state.mag_filter; | 96 mag_filter_ = sampler_state.mag_filter; |
| 95 wrap_r_ = sampler_state.wrap_r; | 97 wrap_r_ = sampler_state.wrap_r; |
| 96 wrap_s_ = sampler_state.wrap_s; | 98 wrap_s_ = sampler_state.wrap_s; |
| 97 wrap_t_ = sampler_state.wrap_t; | 99 wrap_t_ = sampler_state.wrap_t; |
| 98 usage_ = usage; | 100 usage_ = usage; |
| 99 internal_format_ = internal_format; | 101 internal_format_ = internal_format; |
| 100 compare_func_ = sampler_state.compare_func; | 102 compare_func_ = sampler_state.compare_func; |
| 101 compare_mode_ = sampler_state.compare_mode; | 103 compare_mode_ = sampler_state.compare_mode; |
| 102 width_ = width; | 104 width_ = width; |
| 103 height_ = height; | 105 height_ = height; |
| 104 depth_ = depth; | 106 depth_ = depth; |
| 105 max_lod_ = sampler_state.max_lod; | 107 max_lod_ = sampler_state.max_lod; |
| 106 min_lod_ = sampler_state.min_lod; | 108 min_lod_ = sampler_state.min_lod; |
| 107 base_level_ = base_level; | 109 base_level_ = base_level; |
| 108 border_ = border; | 110 border_ = border; |
| 109 max_level_ = max_level; | 111 max_level_ = max_level; |
| 110 format_ = format; | 112 format_ = format; |
| 111 type_ = type; | 113 type_ = type; |
| 112 has_image_ = has_image; | 114 has_image_ = has_image; |
| 113 can_render_ = can_render; | 115 can_render_ = can_render; |
| 114 can_render_to_ = can_render_to; | 116 can_render_to_ = can_render_to; |
| 115 npot_ = npot; | 117 npot_ = npot; |
| 118 emulating_rgb_ = emulating_rgb; | |
| 116 } | 119 } |
| 117 }; | 120 }; |
| 118 | 121 |
| 119 class FormatTypeValidator { | 122 class FormatTypeValidator { |
| 120 public: | 123 public: |
| 121 FormatTypeValidator() { | 124 FormatTypeValidator() { |
| 122 static const FormatType kSupportedFormatTypes[] = { | 125 static const FormatType kSupportedFormatTypes[] = { |
| 123 // ES2. | 126 // ES2. |
| 124 { GL_RGB, GL_RGB, GL_UNSIGNED_BYTE }, | 127 { GL_RGB, GL_RGB, GL_UNSIGNED_BYTE }, |
| 125 { GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 }, | 128 { GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 }, |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 369 texture_mips_dirty_(false), | 372 texture_mips_dirty_(false), |
| 370 cube_complete_(false), | 373 cube_complete_(false), |
| 371 npot_(false), | 374 npot_(false), |
| 372 has_been_bound_(false), | 375 has_been_bound_(false), |
| 373 framebuffer_attachment_count_(0), | 376 framebuffer_attachment_count_(0), |
| 374 immutable_(false), | 377 immutable_(false), |
| 375 has_images_(false), | 378 has_images_(false), |
| 376 estimated_size_(0), | 379 estimated_size_(0), |
| 377 can_render_condition_(CAN_RENDER_ALWAYS), | 380 can_render_condition_(CAN_RENDER_ALWAYS), |
| 378 texture_max_anisotropy_initialized_(false), | 381 texture_max_anisotropy_initialized_(false), |
| 379 compatibility_swizzle_(nullptr) {} | 382 compatibility_swizzle_(nullptr), |
| 383 emulating_rgb_(false) {} | |
| 380 | 384 |
| 381 Texture::~Texture() { | 385 Texture::~Texture() { |
| 382 if (mailbox_manager_) | 386 if (mailbox_manager_) |
| 383 mailbox_manager_->TextureDeleted(this); | 387 mailbox_manager_->TextureDeleted(this); |
| 384 } | 388 } |
| 385 | 389 |
| 386 void Texture::AddTextureRef(TextureRef* ref) { | 390 void Texture::AddTextureRef(TextureRef* ref) { |
| 387 DCHECK(refs_.find(ref) == refs_.end()); | 391 DCHECK(refs_.find(ref) == refs_.end()); |
| 388 refs_.insert(ref); | 392 refs_.insert(ref); |
| 389 if (!memory_tracking_ref_) { | 393 if (!memory_tracking_ref_) { |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 580 info.height, | 584 info.height, |
| 581 info.depth, | 585 info.depth, |
| 582 base_level_, | 586 base_level_, |
| 583 info.border, | 587 info.border, |
| 584 max_level_, | 588 max_level_, |
| 585 info.format, | 589 info.format, |
| 586 info.type, | 590 info.type, |
| 587 info.image.get() != NULL, | 591 info.image.get() != NULL, |
| 588 CanRender(feature_info), | 592 CanRender(feature_info), |
| 589 CanRenderTo(feature_info, level), | 593 CanRenderTo(feature_info, level), |
| 590 npot_); | 594 npot_, |
| 595 emulating_rgb_); | |
| 591 | 596 |
| 592 signature->append(TextureTag, sizeof(TextureTag)); | 597 signature->append(TextureTag, sizeof(TextureTag)); |
| 593 signature->append(reinterpret_cast<const char*>(&signature_data), | 598 signature->append(reinterpret_cast<const char*>(&signature_data), |
| 594 sizeof(signature_data)); | 599 sizeof(signature_data)); |
| 595 } | 600 } |
| 596 | 601 |
| 597 void Texture::SetMailboxManager(MailboxManager* mailbox_manager) { | 602 void Texture::SetMailboxManager(MailboxManager* mailbox_manager) { |
| 598 DCHECK(!mailbox_manager_ || mailbox_manager_ == mailbox_manager); | 603 DCHECK(!mailbox_manager_ || mailbox_manager_ == mailbox_manager); |
| 599 mailbox_manager_ = mailbox_manager; | 604 mailbox_manager_ = mailbox_manager; |
| 600 } | 605 } |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 859 } | 864 } |
| 860 | 865 |
| 861 if (has_images_ == has_images) | 866 if (has_images_ == has_images) |
| 862 return; | 867 return; |
| 863 has_images_ = has_images; | 868 has_images_ = has_images; |
| 864 int delta = has_images ? +1 : -1; | 869 int delta = has_images ? +1 : -1; |
| 865 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) | 870 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) |
| 866 (*it)->manager()->UpdateNumImages(delta); | 871 (*it)->manager()->UpdateNumImages(delta); |
| 867 } | 872 } |
| 868 | 873 |
| 874 void Texture::UpdateEmulatingRGB() { | |
| 875 for (const FaceInfo& face_info : face_infos_) { | |
| 876 for (const LevelInfo& level_info : face_info.level_infos) { | |
| 877 if (level_info.image && level_info.image->EmulatingRGB()) | |
| 878 emulating_rgb_ = true; | |
|
erikchen
2016/04/15 18:54:07
piman: Request for comment.
This code is never ru
piman
2016/04/15 19:20:24
Why is this not run on non-mac platforms? Is it be
| |
| 879 return; | |
| 880 } | |
| 881 } | |
| 882 emulating_rgb_ = false; | |
| 883 } | |
| 884 | |
| 885 | |
| 869 void Texture::IncAllFramebufferStateChangeCount() { | 886 void Texture::IncAllFramebufferStateChangeCount() { |
| 870 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) | 887 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) |
| 871 (*it)->manager()->IncFramebufferStateChangeCount(); | 888 (*it)->manager()->IncFramebufferStateChangeCount(); |
| 872 } | 889 } |
| 873 | 890 |
| 874 void Texture::UpdateBaseLevel(GLint base_level) { | 891 void Texture::UpdateBaseLevel(GLint base_level) { |
| 875 if (base_level_ == base_level) | 892 if (base_level_ == base_level) |
| 876 return; | 893 return; |
| 877 base_level_ = base_level; | 894 base_level_ = base_level; |
| 878 | 895 |
| (...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1438 Texture::LevelInfo& info = | 1455 Texture::LevelInfo& info = |
| 1439 face_infos_[face_index].level_infos[level]; | 1456 face_infos_[face_index].level_infos[level]; |
| 1440 DCHECK_EQ(info.target, target); | 1457 DCHECK_EQ(info.target, target); |
| 1441 DCHECK_EQ(info.level, level); | 1458 DCHECK_EQ(info.level, level); |
| 1442 info.image = image; | 1459 info.image = image; |
| 1443 info.stream_texture_image = stream_texture_image; | 1460 info.stream_texture_image = stream_texture_image; |
| 1444 info.image_state = state; | 1461 info.image_state = state; |
| 1445 | 1462 |
| 1446 UpdateCanRenderCondition(); | 1463 UpdateCanRenderCondition(); |
| 1447 UpdateHasImages(); | 1464 UpdateHasImages(); |
| 1465 UpdateEmulatingRGB(); | |
| 1448 } | 1466 } |
| 1449 | 1467 |
| 1450 void Texture::SetLevelImage(GLenum target, | 1468 void Texture::SetLevelImage(GLenum target, |
| 1451 GLint level, | 1469 GLint level, |
| 1452 gl::GLImage* image, | 1470 gl::GLImage* image, |
| 1453 ImageState state) { | 1471 ImageState state) { |
| 1454 SetLevelImageInternal(target, level, image, nullptr, state); | 1472 SetLevelImageInternal(target, level, image, nullptr, state); |
| 1455 } | 1473 } |
| 1456 | 1474 |
| 1457 void Texture::SetLevelStreamTextureImage(GLenum target, | 1475 void Texture::SetLevelStreamTextureImage(GLenum target, |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1614 | 1632 |
| 1615 void Texture::ApplyFormatWorkarounds(FeatureInfo* feature_info) { | 1633 void Texture::ApplyFormatWorkarounds(FeatureInfo* feature_info) { |
| 1616 if (feature_info->gl_version_info().is_desktop_core_profile) { | 1634 if (feature_info->gl_version_info().is_desktop_core_profile) { |
| 1617 if (static_cast<size_t>(base_level_) >= face_infos_[0].level_infos.size()) | 1635 if (static_cast<size_t>(base_level_) >= face_infos_[0].level_infos.size()) |
| 1618 return; | 1636 return; |
| 1619 const Texture::LevelInfo& info = face_infos_[0].level_infos[base_level_]; | 1637 const Texture::LevelInfo& info = face_infos_[0].level_infos[base_level_]; |
| 1620 SetCompatibilitySwizzle(GetCompatibilitySwizzle(info.format)); | 1638 SetCompatibilitySwizzle(GetCompatibilitySwizzle(info.format)); |
| 1621 } | 1639 } |
| 1622 } | 1640 } |
| 1623 | 1641 |
| 1642 bool Texture::EmulatingRGB() { | |
| 1643 return emulating_rgb_; | |
| 1644 } | |
| 1645 | |
| 1624 TextureRef::TextureRef(TextureManager* manager, | 1646 TextureRef::TextureRef(TextureManager* manager, |
| 1625 GLuint client_id, | 1647 GLuint client_id, |
| 1626 Texture* texture) | 1648 Texture* texture) |
| 1627 : manager_(manager), | 1649 : manager_(manager), |
| 1628 texture_(texture), | 1650 texture_(texture), |
| 1629 client_id_(client_id), | 1651 client_id_(client_id), |
| 1630 num_observers_(0) { | 1652 num_observers_(0) { |
| 1631 DCHECK(manager_); | 1653 DCHECK(manager_); |
| 1632 DCHECK(texture_); | 1654 DCHECK(texture_); |
| 1633 texture_->AddTextureRef(this); | 1655 texture_->AddTextureRef(this); |
| (...skipping 1500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3134 uint32_t TextureManager::GetServiceIdGeneration() const { | 3156 uint32_t TextureManager::GetServiceIdGeneration() const { |
| 3135 return current_service_id_generation_; | 3157 return current_service_id_generation_; |
| 3136 } | 3158 } |
| 3137 | 3159 |
| 3138 void TextureManager::IncrementServiceIdGeneration() { | 3160 void TextureManager::IncrementServiceIdGeneration() { |
| 3139 current_service_id_generation_++; | 3161 current_service_id_generation_++; |
| 3140 } | 3162 } |
| 3141 | 3163 |
| 3142 } // namespace gles2 | 3164 } // namespace gles2 |
| 3143 } // namespace gpu | 3165 } // namespace gpu |
| OLD | NEW |