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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 bool can_render_; | 64 bool can_render_; |
65 bool can_render_to_; | 65 bool can_render_to_; |
66 bool npot_; | 66 bool npot_; |
67 | 67 |
68 // Since we will be hashing this signature structure, the padding must be | 68 // Since we will be hashing this signature structure, the padding must be |
69 // zero initialized. Although the C++11 specifications specify that this is | 69 // zero initialized. Although the C++11 specifications specify that this is |
70 // true, we will use a constructor with a memset to further enforce it instead | 70 // true, we will use a constructor with a memset to further enforce it instead |
71 // of relying on compilers adhering to this deep dark corner specification. | 71 // of relying on compilers adhering to this deep dark corner specification. |
72 TextureSignature(GLenum target, | 72 TextureSignature(GLenum target, |
73 GLint level, | 73 GLint level, |
74 const SamplerState& sampler_state, | 74 GLenum min_filter, |
| 75 GLenum mag_filter, |
| 76 GLenum wrap_r, |
| 77 GLenum wrap_s, |
| 78 GLenum wrap_t, |
75 GLenum usage, | 79 GLenum usage, |
76 GLenum internal_format, | 80 GLenum internal_format, |
| 81 GLenum compare_func, |
| 82 GLenum compare_mode, |
77 GLsizei width, | 83 GLsizei width, |
78 GLsizei height, | 84 GLsizei height, |
79 GLsizei depth, | 85 GLsizei depth, |
| 86 GLfloat max_lod, |
| 87 GLfloat min_lod, |
80 GLint base_level, | 88 GLint base_level, |
81 GLint border, | 89 GLint border, |
82 GLint max_level, | 90 GLint max_level, |
83 GLenum format, | 91 GLenum format, |
84 GLenum type, | 92 GLenum type, |
85 bool has_image, | 93 bool has_image, |
86 bool can_render, | 94 bool can_render, |
87 bool can_render_to, | 95 bool can_render_to, |
88 bool npot) { | 96 bool npot) { |
89 memset(this, 0, sizeof(TextureSignature)); | 97 memset(this, 0, sizeof(TextureSignature)); |
90 target_ = target; | 98 target_ = target; |
91 level_ = level; | 99 level_ = level; |
92 min_filter_ = sampler_state.min_filter; | 100 min_filter_ = min_filter; |
93 mag_filter_ = sampler_state.mag_filter; | 101 mag_filter_ = mag_filter; |
94 wrap_r_ = sampler_state.wrap_r; | 102 wrap_r_ = wrap_r; |
95 wrap_s_ = sampler_state.wrap_s; | 103 wrap_s_ = wrap_s; |
96 wrap_t_ = sampler_state.wrap_t; | 104 wrap_t_ = wrap_t; |
97 usage_ = usage; | 105 usage_ = usage; |
98 internal_format_ = internal_format; | 106 internal_format_ = internal_format; |
99 compare_func_ = sampler_state.compare_func; | 107 compare_func_ = compare_func; |
100 compare_mode_ = sampler_state.compare_mode; | 108 compare_mode_ = compare_mode; |
101 width_ = width; | 109 width_ = width; |
102 height_ = height; | 110 height_ = height; |
103 depth_ = depth; | 111 depth_ = depth; |
104 max_lod_ = sampler_state.max_lod; | 112 max_lod_ = max_lod; |
105 min_lod_ = sampler_state.min_lod; | 113 min_lod_ = min_lod; |
106 base_level_ = base_level; | 114 base_level_ = base_level; |
107 border_ = border; | 115 border_ = border; |
108 max_level_ = max_level; | 116 max_level_ = max_level; |
109 format_ = format; | 117 format_ = format; |
110 type_ = type; | 118 type_ = type; |
111 has_image_ = has_image; | 119 has_image_ = has_image; |
112 can_render_ = can_render; | 120 can_render_ = can_render; |
113 can_render_to_ = can_render_to; | 121 can_render_to_ = can_render_to; |
114 npot_ = npot; | 122 npot_ = npot; |
115 } | 123 } |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 TextureManager::~TextureManager() { | 282 TextureManager::~TextureManager() { |
275 for (unsigned int i = 0; i < destruction_observers_.size(); i++) | 283 for (unsigned int i = 0; i < destruction_observers_.size(); i++) |
276 destruction_observers_[i]->OnTextureManagerDestroying(this); | 284 destruction_observers_[i]->OnTextureManagerDestroying(this); |
277 | 285 |
278 DCHECK(textures_.empty()); | 286 DCHECK(textures_.empty()); |
279 | 287 |
280 // If this triggers, that means something is keeping a reference to | 288 // If this triggers, that means something is keeping a reference to |
281 // a Texture belonging to this. | 289 // a Texture belonging to this. |
282 CHECK_EQ(texture_count_, 0u); | 290 CHECK_EQ(texture_count_, 0u); |
283 | 291 |
| 292 DCHECK_EQ(0, num_unrenderable_textures_); |
284 DCHECK_EQ(0, num_unsafe_textures_); | 293 DCHECK_EQ(0, num_unsafe_textures_); |
285 DCHECK_EQ(0, num_uncleared_mips_); | 294 DCHECK_EQ(0, num_uncleared_mips_); |
286 DCHECK_EQ(0, num_images_); | 295 DCHECK_EQ(0, num_images_); |
287 | 296 |
288 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | 297 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
289 this); | 298 this); |
290 } | 299 } |
291 | 300 |
292 void TextureManager::Destroy(bool have_context) { | 301 void TextureManager::Destroy(bool have_context) { |
293 have_context_ = have_context; | 302 have_context_ = have_context; |
(...skipping 11 matching lines...) Expand all Loading... |
305 | 314 |
306 Texture::Texture(GLuint service_id) | 315 Texture::Texture(GLuint service_id) |
307 : mailbox_manager_(NULL), | 316 : mailbox_manager_(NULL), |
308 memory_tracking_ref_(NULL), | 317 memory_tracking_ref_(NULL), |
309 service_id_(service_id), | 318 service_id_(service_id), |
310 owned_service_id_(service_id), | 319 owned_service_id_(service_id), |
311 cleared_(true), | 320 cleared_(true), |
312 num_uncleared_mips_(0), | 321 num_uncleared_mips_(0), |
313 num_npot_faces_(0), | 322 num_npot_faces_(0), |
314 target_(0), | 323 target_(0), |
| 324 min_filter_(GL_NEAREST_MIPMAP_LINEAR), |
| 325 mag_filter_(GL_LINEAR), |
| 326 wrap_r_(GL_REPEAT), |
| 327 wrap_s_(GL_REPEAT), |
| 328 wrap_t_(GL_REPEAT), |
315 usage_(GL_NONE), | 329 usage_(GL_NONE), |
| 330 compare_func_(GL_LEQUAL), |
| 331 compare_mode_(GL_NONE), |
| 332 max_lod_(1000.0f), |
| 333 min_lod_(-1000.0f), |
316 base_level_(0), | 334 base_level_(0), |
317 max_level_(1000), | 335 max_level_(1000), |
318 max_level_set_(-1), | 336 max_level_set_(-1), |
319 texture_complete_(false), | 337 texture_complete_(false), |
320 texture_mips_dirty_(false), | 338 texture_mips_dirty_(false), |
321 cube_complete_(false), | 339 cube_complete_(false), |
322 texture_level0_dirty_(false), | 340 texture_level0_dirty_(false), |
323 npot_(false), | 341 npot_(false), |
324 has_been_bound_(false), | 342 has_been_bound_(false), |
325 framebuffer_attachment_count_(0), | 343 framebuffer_attachment_count_(0), |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 } | 434 } |
417 const Texture::LevelInfo& first_face = | 435 const Texture::LevelInfo& first_face = |
418 face_infos_[0].level_infos[base_level_]; | 436 face_infos_[0].level_infos[base_level_]; |
419 if (first_face.width == 0 || | 437 if (first_face.width == 0 || |
420 first_face.height == 0 || | 438 first_face.height == 0 || |
421 first_face.depth == 0) { | 439 first_face.depth == 0) { |
422 return CAN_RENDER_NEVER; | 440 return CAN_RENDER_NEVER; |
423 } | 441 } |
424 } | 442 } |
425 | 443 |
| 444 bool needs_mips = NeedsMips(); |
| 445 if (needs_mips) { |
| 446 if (!texture_complete()) |
| 447 return CAN_RENDER_NEVER; |
| 448 } |
| 449 |
426 if (target_ == GL_TEXTURE_CUBE_MAP && !cube_complete()) | 450 if (target_ == GL_TEXTURE_CUBE_MAP && !cube_complete()) |
427 return CAN_RENDER_NEVER; | 451 return CAN_RENDER_NEVER; |
428 | 452 |
429 // Texture may be renderable, but it depends on the sampler it's used with, | 453 bool is_npot_compatible = !needs_mips && |
430 // the context that's using it, and the extensions available. | 454 wrap_s_ == GL_CLAMP_TO_EDGE && |
431 return CAN_RENDER_NEEDS_VALIDATION; | 455 wrap_t_ == GL_CLAMP_TO_EDGE; |
| 456 |
| 457 if (!is_npot_compatible) { |
| 458 if (target_ == GL_TEXTURE_RECTANGLE_ARB) |
| 459 return CAN_RENDER_NEVER; |
| 460 else if (npot()) |
| 461 return CAN_RENDER_ONLY_IF_NPOT; |
| 462 } |
| 463 |
| 464 return CAN_RENDER_ALWAYS; |
432 } | 465 } |
433 | 466 |
434 bool Texture::CanRender(const FeatureInfo* feature_info) const { | 467 bool Texture::CanRender(const FeatureInfo* feature_info) const { |
435 return CanRenderWithSampler(feature_info, sampler_state()); | |
436 } | |
437 | |
438 bool Texture::CanRenderWithSampler(const FeatureInfo* feature_info, | |
439 const SamplerState& sampler_state) const { | |
440 switch (can_render_condition_) { | 468 switch (can_render_condition_) { |
441 case CAN_RENDER_ALWAYS: | 469 case CAN_RENDER_ALWAYS: |
442 return true; | 470 return true; |
443 case CAN_RENDER_NEVER: | 471 case CAN_RENDER_NEVER: |
444 return false; | 472 return false; |
445 case CAN_RENDER_NEEDS_VALIDATION: | 473 case CAN_RENDER_ONLY_IF_NPOT: |
446 break; | 474 break; |
447 } | 475 } |
448 | 476 return feature_info->feature_flags().npot_ok; |
449 bool needs_mips = sampler_state.min_filter != GL_NEAREST && | |
450 sampler_state.min_filter != GL_LINEAR; | |
451 if (needs_mips && !texture_complete()) | |
452 return false; | |
453 | |
454 if (!feature_info->IsES3Enabled()) { | |
455 bool is_npot_compatible = !needs_mips && | |
456 sampler_state.wrap_s == GL_CLAMP_TO_EDGE && | |
457 sampler_state.wrap_t == GL_CLAMP_TO_EDGE; | |
458 | |
459 if (!is_npot_compatible) { | |
460 if (target_ == GL_TEXTURE_RECTANGLE_ARB) | |
461 return false; | |
462 else if (npot()) | |
463 return feature_info->feature_flags().npot_ok; | |
464 } | |
465 } | |
466 | |
467 if (static_cast<size_t>(base_level_) >= face_infos_[0].level_infos.size()) { | |
468 return false; | |
469 } | |
470 | |
471 const Texture::LevelInfo& first_level = | |
472 face_infos_[0].level_infos[base_level_]; | |
473 | |
474 if (first_level.type == GL_FLOAT && | |
475 !feature_info->feature_flags().enable_texture_float_linear && | |
476 (sampler_state.min_filter != GL_NEAREST_MIPMAP_NEAREST || | |
477 sampler_state.mag_filter != GL_NEAREST)) { | |
478 return false; | |
479 } else if (first_level.type == GL_HALF_FLOAT_OES && | |
480 !feature_info->feature_flags().enable_texture_half_float_linear && | |
481 (sampler_state.min_filter != GL_NEAREST_MIPMAP_NEAREST || | |
482 sampler_state.mag_filter != GL_NEAREST)) { | |
483 return false; | |
484 } | |
485 | |
486 return true; | |
487 } | 477 } |
488 | 478 |
489 void Texture::AddToSignature( | 479 void Texture::AddToSignature( |
490 const FeatureInfo* feature_info, | 480 const FeatureInfo* feature_info, |
491 GLenum target, | 481 GLenum target, |
492 GLint level, | 482 GLint level, |
493 std::string* signature) const { | 483 std::string* signature) const { |
494 DCHECK(feature_info); | 484 DCHECK(feature_info); |
495 DCHECK(signature); | 485 DCHECK(signature); |
496 DCHECK_GE(level, 0); | 486 DCHECK_GE(level, 0); |
497 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 487 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
498 DCHECK_LT(static_cast<size_t>(face_index), | 488 DCHECK_LT(static_cast<size_t>(face_index), |
499 face_infos_.size()); | 489 face_infos_.size()); |
500 DCHECK_LT(static_cast<size_t>(level), | 490 DCHECK_LT(static_cast<size_t>(level), |
501 face_infos_[face_index].level_infos.size()); | 491 face_infos_[face_index].level_infos.size()); |
502 | 492 |
503 const Texture::LevelInfo& info = | 493 const Texture::LevelInfo& info = |
504 face_infos_[face_index].level_infos[level]; | 494 face_infos_[face_index].level_infos[level]; |
505 | 495 |
506 TextureSignature signature_data(target, | 496 TextureSignature signature_data(target, |
507 level, | 497 level, |
508 sampler_state_, | 498 min_filter_, |
| 499 mag_filter_, |
| 500 wrap_r_, |
| 501 wrap_s_, |
| 502 wrap_t_, |
509 usage_, | 503 usage_, |
510 info.internal_format, | 504 info.internal_format, |
| 505 compare_func_, |
| 506 compare_mode_, |
511 info.width, | 507 info.width, |
512 info.height, | 508 info.height, |
513 info.depth, | 509 info.depth, |
| 510 max_lod_, |
| 511 min_lod_, |
514 base_level_, | 512 base_level_, |
515 info.border, | 513 info.border, |
516 max_level_, | 514 max_level_, |
517 info.format, | 515 info.format, |
518 info.type, | 516 info.type, |
519 info.image.get() != NULL, | 517 info.image.get() != NULL, |
520 CanRender(feature_info), | 518 CanRender(feature_info), |
521 CanRenderTo(), | 519 CanRenderTo(), |
522 npot_); | 520 npot_); |
523 | 521 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 const FeatureInfo* feature_info, GLenum target, GLint max_levels) { | 558 const FeatureInfo* feature_info, GLenum target, GLint max_levels) { |
561 DCHECK_EQ(0u, target_); // you can only set this once. | 559 DCHECK_EQ(0u, target_); // you can only set this once. |
562 target_ = target; | 560 target_ = target; |
563 size_t num_faces = (target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; | 561 size_t num_faces = (target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; |
564 face_infos_.resize(num_faces); | 562 face_infos_.resize(num_faces); |
565 for (size_t ii = 0; ii < num_faces; ++ii) { | 563 for (size_t ii = 0; ii < num_faces; ++ii) { |
566 face_infos_[ii].level_infos.resize(max_levels); | 564 face_infos_[ii].level_infos.resize(max_levels); |
567 } | 565 } |
568 | 566 |
569 if (target == GL_TEXTURE_EXTERNAL_OES || target == GL_TEXTURE_RECTANGLE_ARB) { | 567 if (target == GL_TEXTURE_EXTERNAL_OES || target == GL_TEXTURE_RECTANGLE_ARB) { |
570 sampler_state_.min_filter = GL_LINEAR; | 568 min_filter_ = GL_LINEAR; |
571 sampler_state_.wrap_s = sampler_state_.wrap_t = GL_CLAMP_TO_EDGE; | 569 wrap_s_ = wrap_t_ = GL_CLAMP_TO_EDGE; |
572 } | 570 } |
573 | 571 |
574 if (target == GL_TEXTURE_EXTERNAL_OES) { | 572 if (target == GL_TEXTURE_EXTERNAL_OES) { |
575 immutable_ = true; | 573 immutable_ = true; |
576 } | 574 } |
577 Update(feature_info); | 575 Update(feature_info); |
578 UpdateCanRenderCondition(); | 576 UpdateCanRenderCondition(); |
579 } | 577 } |
580 | 578 |
581 bool Texture::CanGenerateMipmaps( | 579 bool Texture::CanGenerateMipmaps( |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 bool cleared = info->cleared_rect == gfx::Rect(info->width, info->height); | 743 bool cleared = info->cleared_rect == gfx::Rect(info->width, info->height); |
746 if (cleared == was_cleared) | 744 if (cleared == was_cleared) |
747 return; | 745 return; |
748 int delta = cleared ? -1 : +1; | 746 int delta = cleared ? -1 : +1; |
749 num_uncleared_mips_ += delta; | 747 num_uncleared_mips_ += delta; |
750 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) | 748 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) |
751 (*it)->manager()->UpdateUnclearedMips(delta); | 749 (*it)->manager()->UpdateUnclearedMips(delta); |
752 } | 750 } |
753 | 751 |
754 void Texture::UpdateCanRenderCondition() { | 752 void Texture::UpdateCanRenderCondition() { |
755 can_render_condition_ = GetCanRenderCondition(); | 753 CanRenderCondition can_render_condition = GetCanRenderCondition(); |
| 754 if (can_render_condition_ == can_render_condition) |
| 755 return; |
| 756 for (RefSet::iterator it = refs_.begin(); it != refs_.end(); ++it) |
| 757 (*it)->manager()->UpdateCanRenderCondition(can_render_condition_, |
| 758 can_render_condition); |
| 759 can_render_condition_ = can_render_condition; |
756 } | 760 } |
757 | 761 |
758 void Texture::UpdateHasImages() { | 762 void Texture::UpdateHasImages() { |
759 if (face_infos_.empty()) | 763 if (face_infos_.empty()) |
760 return; | 764 return; |
761 | 765 |
762 bool has_images = false; | 766 bool has_images = false; |
763 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { | 767 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { |
764 for (size_t jj = 0; jj < face_infos_[ii].level_infos.size(); ++jj) { | 768 for (size_t jj = 0; jj < face_infos_[ii].level_infos.size(); ++jj) { |
765 const Texture::LevelInfo& info = face_infos_[ii].level_infos[jj]; | 769 const Texture::LevelInfo& info = face_infos_[ii].level_infos[jj]; |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
984 case GL_TEXTURE_MIN_LOD: | 988 case GL_TEXTURE_MIN_LOD: |
985 case GL_TEXTURE_MAX_LOD: | 989 case GL_TEXTURE_MAX_LOD: |
986 { | 990 { |
987 GLfloat fparam = static_cast<GLfloat>(param); | 991 GLfloat fparam = static_cast<GLfloat>(param); |
988 return SetParameterf(feature_info, pname, fparam); | 992 return SetParameterf(feature_info, pname, fparam); |
989 } | 993 } |
990 case GL_TEXTURE_MIN_FILTER: | 994 case GL_TEXTURE_MIN_FILTER: |
991 if (!feature_info->validators()->texture_min_filter_mode.IsValid(param)) { | 995 if (!feature_info->validators()->texture_min_filter_mode.IsValid(param)) { |
992 return GL_INVALID_ENUM; | 996 return GL_INVALID_ENUM; |
993 } | 997 } |
994 sampler_state_.min_filter = param; | 998 min_filter_ = param; |
995 break; | 999 break; |
996 case GL_TEXTURE_MAG_FILTER: | 1000 case GL_TEXTURE_MAG_FILTER: |
997 if (!feature_info->validators()->texture_mag_filter_mode.IsValid(param)) { | 1001 if (!feature_info->validators()->texture_mag_filter_mode.IsValid(param)) { |
998 return GL_INVALID_ENUM; | 1002 return GL_INVALID_ENUM; |
999 } | 1003 } |
1000 sampler_state_.mag_filter = param; | 1004 mag_filter_ = param; |
1001 break; | 1005 break; |
1002 case GL_TEXTURE_WRAP_R: | 1006 case GL_TEXTURE_WRAP_R: |
1003 if (!feature_info->validators()->texture_wrap_mode.IsValid(param)) { | 1007 if (!feature_info->validators()->texture_wrap_mode.IsValid(param)) { |
1004 return GL_INVALID_ENUM; | 1008 return GL_INVALID_ENUM; |
1005 } | 1009 } |
1006 sampler_state_.wrap_r = param; | 1010 wrap_r_ = param; |
1007 break; | 1011 break; |
1008 case GL_TEXTURE_WRAP_S: | 1012 case GL_TEXTURE_WRAP_S: |
1009 if (!feature_info->validators()->texture_wrap_mode.IsValid(param)) { | 1013 if (!feature_info->validators()->texture_wrap_mode.IsValid(param)) { |
1010 return GL_INVALID_ENUM; | 1014 return GL_INVALID_ENUM; |
1011 } | 1015 } |
1012 sampler_state_.wrap_s = param; | 1016 wrap_s_ = param; |
1013 break; | 1017 break; |
1014 case GL_TEXTURE_WRAP_T: | 1018 case GL_TEXTURE_WRAP_T: |
1015 if (!feature_info->validators()->texture_wrap_mode.IsValid(param)) { | 1019 if (!feature_info->validators()->texture_wrap_mode.IsValid(param)) { |
1016 return GL_INVALID_ENUM; | 1020 return GL_INVALID_ENUM; |
1017 } | 1021 } |
1018 sampler_state_.wrap_t = param; | 1022 wrap_t_ = param; |
1019 break; | 1023 break; |
1020 case GL_TEXTURE_COMPARE_FUNC: | 1024 case GL_TEXTURE_COMPARE_FUNC: |
1021 if (!feature_info->validators()->texture_compare_func.IsValid(param)) { | 1025 if (!feature_info->validators()->texture_compare_func.IsValid(param)) { |
1022 return GL_INVALID_ENUM; | 1026 return GL_INVALID_ENUM; |
1023 } | 1027 } |
1024 sampler_state_.compare_func = param; | 1028 compare_func_ = param; |
1025 break; | 1029 break; |
1026 case GL_TEXTURE_COMPARE_MODE: | 1030 case GL_TEXTURE_COMPARE_MODE: |
1027 if (!feature_info->validators()->texture_compare_mode.IsValid(param)) { | 1031 if (!feature_info->validators()->texture_compare_mode.IsValid(param)) { |
1028 return GL_INVALID_ENUM; | 1032 return GL_INVALID_ENUM; |
1029 } | 1033 } |
1030 sampler_state_.compare_mode = param; | 1034 compare_mode_ = param; |
1031 break; | 1035 break; |
1032 case GL_TEXTURE_BASE_LEVEL: | 1036 case GL_TEXTURE_BASE_LEVEL: |
1033 if (param < 0) { | 1037 if (param < 0) { |
1034 return GL_INVALID_VALUE; | 1038 return GL_INVALID_VALUE; |
1035 } | 1039 } |
1036 UpdateBaseLevel(param); | 1040 UpdateBaseLevel(param); |
1037 break; | 1041 break; |
1038 case GL_TEXTURE_MAX_LEVEL: | 1042 case GL_TEXTURE_MAX_LEVEL: |
1039 if (param < 0) { | 1043 if (param < 0) { |
1040 return GL_INVALID_VALUE; | 1044 return GL_INVALID_VALUE; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1073 case GL_TEXTURE_COMPARE_FUNC: | 1077 case GL_TEXTURE_COMPARE_FUNC: |
1074 case GL_TEXTURE_COMPARE_MODE: | 1078 case GL_TEXTURE_COMPARE_MODE: |
1075 case GL_TEXTURE_BASE_LEVEL: | 1079 case GL_TEXTURE_BASE_LEVEL: |
1076 case GL_TEXTURE_MAX_LEVEL: | 1080 case GL_TEXTURE_MAX_LEVEL: |
1077 case GL_TEXTURE_USAGE_ANGLE: | 1081 case GL_TEXTURE_USAGE_ANGLE: |
1078 { | 1082 { |
1079 GLint iparam = static_cast<GLint>(param); | 1083 GLint iparam = static_cast<GLint>(param); |
1080 return SetParameteri(feature_info, pname, iparam); | 1084 return SetParameteri(feature_info, pname, iparam); |
1081 } | 1085 } |
1082 case GL_TEXTURE_MIN_LOD: | 1086 case GL_TEXTURE_MIN_LOD: |
1083 sampler_state_.min_lod = param; | 1087 min_lod_ = param; |
1084 break; | 1088 break; |
1085 case GL_TEXTURE_MAX_LOD: | 1089 case GL_TEXTURE_MAX_LOD: |
1086 sampler_state_.max_lod = param; | 1090 max_lod_ = param; |
1087 break; | 1091 break; |
1088 case GL_TEXTURE_MAX_ANISOTROPY_EXT: | 1092 case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
1089 if (param < 1.f) { | 1093 if (param < 1.f) { |
1090 return GL_INVALID_VALUE; | 1094 return GL_INVALID_VALUE; |
1091 } | 1095 } |
1092 break; | 1096 break; |
1093 default: | 1097 default: |
1094 NOTREACHED(); | 1098 NOTREACHED(); |
1095 return GL_INVALID_ENUM; | 1099 return GL_INVALID_ENUM; |
1096 } | 1100 } |
(...skipping 18 matching lines...) Expand all Loading... |
1115 const GLsizei levels_needed = first_face.num_mip_levels; | 1119 const GLsizei levels_needed = first_face.num_mip_levels; |
1116 | 1120 |
1117 texture_complete_ = | 1121 texture_complete_ = |
1118 max_level_set_ >= (levels_needed - 1) && max_level_set_ >= 0; | 1122 max_level_set_ >= (levels_needed - 1) && max_level_set_ >= 0; |
1119 cube_complete_ = (face_infos_.size() == 6) && | 1123 cube_complete_ = (face_infos_.size() == 6) && |
1120 (first_level.width == first_level.height) && | 1124 (first_level.width == first_level.height) && |
1121 (first_level.width > 0); | 1125 (first_level.width > 0); |
1122 | 1126 |
1123 if (first_level.width == 0 || first_level.height == 0) { | 1127 if (first_level.width == 0 || first_level.height == 0) { |
1124 texture_complete_ = false; | 1128 texture_complete_ = false; |
| 1129 } else if (first_level.type == GL_FLOAT && |
| 1130 !feature_info->feature_flags().enable_texture_float_linear && |
| 1131 (min_filter_ != GL_NEAREST_MIPMAP_NEAREST || |
| 1132 mag_filter_ != GL_NEAREST)) { |
| 1133 texture_complete_ = false; |
| 1134 } else if (first_level.type == GL_HALF_FLOAT_OES && |
| 1135 !feature_info->feature_flags().enable_texture_half_float_linear && |
| 1136 (min_filter_ != GL_NEAREST_MIPMAP_NEAREST || |
| 1137 mag_filter_ != GL_NEAREST)) { |
| 1138 texture_complete_ = false; |
1125 } | 1139 } |
1126 | 1140 |
1127 bool texture_level0_complete = true; | 1141 bool texture_level0_complete = true; |
1128 if (cube_complete_ && texture_level0_dirty_) { | 1142 if (cube_complete_ && texture_level0_dirty_) { |
1129 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { | 1143 for (size_t ii = 0; ii < face_infos_.size(); ++ii) { |
1130 const Texture::LevelInfo& face_base_level = | 1144 const Texture::LevelInfo& face_base_level = |
1131 face_infos_[ii].level_infos[base_level_]; | 1145 face_infos_[ii].level_infos[base_level_]; |
1132 if (!TextureFaceComplete(first_level, | 1146 if (!TextureFaceComplete(first_level, |
1133 ii, | 1147 ii, |
1134 face_base_level.target, | 1148 face_base_level.target, |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1435 max_cube_map_levels_(ComputeMipMapCount(GL_TEXTURE_CUBE_MAP, | 1449 max_cube_map_levels_(ComputeMipMapCount(GL_TEXTURE_CUBE_MAP, |
1436 max_cube_map_texture_size, | 1450 max_cube_map_texture_size, |
1437 max_cube_map_texture_size, | 1451 max_cube_map_texture_size, |
1438 max_cube_map_texture_size)), | 1452 max_cube_map_texture_size)), |
1439 max_3d_levels_(ComputeMipMapCount(GL_TEXTURE_3D, | 1453 max_3d_levels_(ComputeMipMapCount(GL_TEXTURE_3D, |
1440 // Same as GL_TEXTURE_2D_ARRAY | 1454 // Same as GL_TEXTURE_2D_ARRAY |
1441 max_3d_texture_size, | 1455 max_3d_texture_size, |
1442 max_3d_texture_size, | 1456 max_3d_texture_size, |
1443 max_3d_texture_size)), | 1457 max_3d_texture_size)), |
1444 use_default_textures_(use_default_textures), | 1458 use_default_textures_(use_default_textures), |
| 1459 num_unrenderable_textures_(0), |
1445 num_unsafe_textures_(0), | 1460 num_unsafe_textures_(0), |
1446 num_uncleared_mips_(0), | 1461 num_uncleared_mips_(0), |
1447 num_images_(0), | 1462 num_images_(0), |
1448 texture_count_(0), | 1463 texture_count_(0), |
1449 have_context_(true), | 1464 have_context_(true), |
1450 current_service_id_generation_(0) { | 1465 current_service_id_generation_(0) { |
1451 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { | 1466 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { |
1452 black_texture_ids_[ii] = 0; | 1467 black_texture_ids_[ii] = 0; |
1453 } | 1468 } |
1454 } | 1469 } |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1722 textures_.erase(it); | 1737 textures_.erase(it); |
1723 } | 1738 } |
1724 } | 1739 } |
1725 | 1740 |
1726 void TextureManager::StartTracking(TextureRef* ref) { | 1741 void TextureManager::StartTracking(TextureRef* ref) { |
1727 Texture* texture = ref->texture(); | 1742 Texture* texture = ref->texture(); |
1728 ++texture_count_; | 1743 ++texture_count_; |
1729 num_uncleared_mips_ += texture->num_uncleared_mips(); | 1744 num_uncleared_mips_ += texture->num_uncleared_mips(); |
1730 if (!texture->SafeToRenderFrom()) | 1745 if (!texture->SafeToRenderFrom()) |
1731 ++num_unsafe_textures_; | 1746 ++num_unsafe_textures_; |
| 1747 if (!texture->CanRender(feature_info_.get())) |
| 1748 ++num_unrenderable_textures_; |
1732 if (texture->HasImages()) | 1749 if (texture->HasImages()) |
1733 ++num_images_; | 1750 ++num_images_; |
1734 } | 1751 } |
1735 | 1752 |
1736 void TextureManager::StopTracking(TextureRef* ref) { | 1753 void TextureManager::StopTracking(TextureRef* ref) { |
1737 if (ref->num_observers()) { | 1754 if (ref->num_observers()) { |
1738 for (unsigned int i = 0; i < destruction_observers_.size(); i++) { | 1755 for (unsigned int i = 0; i < destruction_observers_.size(); i++) { |
1739 destruction_observers_[i]->OnTextureRefDestroying(ref); | 1756 destruction_observers_[i]->OnTextureRefDestroying(ref); |
1740 } | 1757 } |
1741 DCHECK_EQ(ref->num_observers(), 0); | 1758 DCHECK_EQ(ref->num_observers(), 0); |
1742 } | 1759 } |
1743 | 1760 |
1744 Texture* texture = ref->texture(); | 1761 Texture* texture = ref->texture(); |
1745 | 1762 |
1746 --texture_count_; | 1763 --texture_count_; |
1747 if (texture->HasImages()) { | 1764 if (texture->HasImages()) { |
1748 DCHECK_NE(0, num_images_); | 1765 DCHECK_NE(0, num_images_); |
1749 --num_images_; | 1766 --num_images_; |
1750 } | 1767 } |
| 1768 if (!texture->CanRender(feature_info_.get())) { |
| 1769 DCHECK_NE(0, num_unrenderable_textures_); |
| 1770 --num_unrenderable_textures_; |
| 1771 } |
1751 if (!texture->SafeToRenderFrom()) { | 1772 if (!texture->SafeToRenderFrom()) { |
1752 DCHECK_NE(0, num_unsafe_textures_); | 1773 DCHECK_NE(0, num_unsafe_textures_); |
1753 --num_unsafe_textures_; | 1774 --num_unsafe_textures_; |
1754 } | 1775 } |
1755 num_uncleared_mips_ -= texture->num_uncleared_mips(); | 1776 num_uncleared_mips_ -= texture->num_uncleared_mips(); |
1756 DCHECK_GE(num_uncleared_mips_, 0); | 1777 DCHECK_GE(num_uncleared_mips_, 0); |
1757 } | 1778 } |
1758 | 1779 |
1759 MemoryTypeTracker* TextureManager::GetMemTracker() { | 1780 MemoryTypeTracker* TextureManager::GetMemTracker() { |
1760 return memory_type_tracker_.get(); | 1781 return memory_type_tracker_.get(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1808 void TextureManager::UpdateSafeToRenderFrom(int delta) { | 1829 void TextureManager::UpdateSafeToRenderFrom(int delta) { |
1809 num_unsafe_textures_ += delta; | 1830 num_unsafe_textures_ += delta; |
1810 DCHECK_GE(num_unsafe_textures_, 0); | 1831 DCHECK_GE(num_unsafe_textures_, 0); |
1811 } | 1832 } |
1812 | 1833 |
1813 void TextureManager::UpdateUnclearedMips(int delta) { | 1834 void TextureManager::UpdateUnclearedMips(int delta) { |
1814 num_uncleared_mips_ += delta; | 1835 num_uncleared_mips_ += delta; |
1815 DCHECK_GE(num_uncleared_mips_, 0); | 1836 DCHECK_GE(num_uncleared_mips_, 0); |
1816 } | 1837 } |
1817 | 1838 |
| 1839 void TextureManager::UpdateCanRenderCondition( |
| 1840 Texture::CanRenderCondition old_condition, |
| 1841 Texture::CanRenderCondition new_condition) { |
| 1842 if (old_condition == Texture::CAN_RENDER_NEVER || |
| 1843 (old_condition == Texture::CAN_RENDER_ONLY_IF_NPOT && |
| 1844 !feature_info_->feature_flags().npot_ok)) { |
| 1845 DCHECK_GT(num_unrenderable_textures_, 0); |
| 1846 --num_unrenderable_textures_; |
| 1847 } |
| 1848 if (new_condition == Texture::CAN_RENDER_NEVER || |
| 1849 (new_condition == Texture::CAN_RENDER_ONLY_IF_NPOT && |
| 1850 !feature_info_->feature_flags().npot_ok)) |
| 1851 ++num_unrenderable_textures_; |
| 1852 } |
| 1853 |
1818 void TextureManager::UpdateNumImages(int delta) { | 1854 void TextureManager::UpdateNumImages(int delta) { |
1819 num_images_ += delta; | 1855 num_images_ += delta; |
1820 DCHECK_GE(num_images_, 0); | 1856 DCHECK_GE(num_images_, 0); |
1821 } | 1857 } |
1822 | 1858 |
1823 void TextureManager::IncFramebufferStateChangeCount() { | 1859 void TextureManager::IncFramebufferStateChangeCount() { |
1824 if (framebuffer_manager_) | 1860 if (framebuffer_manager_) |
1825 framebuffer_manager_->IncFramebufferStateChangeCount(); | 1861 framebuffer_manager_->IncFramebufferStateChangeCount(); |
1826 } | 1862 } |
1827 | 1863 |
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2637 uint32_t TextureManager::GetServiceIdGeneration() const { | 2673 uint32_t TextureManager::GetServiceIdGeneration() const { |
2638 return current_service_id_generation_; | 2674 return current_service_id_generation_; |
2639 } | 2675 } |
2640 | 2676 |
2641 void TextureManager::IncrementServiceIdGeneration() { | 2677 void TextureManager::IncrementServiceIdGeneration() { |
2642 current_service_id_generation_++; | 2678 current_service_id_generation_++; |
2643 } | 2679 } |
2644 | 2680 |
2645 } // namespace gles2 | 2681 } // namespace gles2 |
2646 } // namespace gpu | 2682 } // namespace gpu |
OLD | NEW |