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 #include "base/bits.h" | 6 #include "base/bits.h" |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 8 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
9 #include "gpu/command_buffer/service/context_state.h" | 9 #include "gpu/command_buffer/service/context_state.h" |
10 #include "gpu/command_buffer/service/error_state.h" | 10 #include "gpu/command_buffer/service/error_state.h" |
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 const LevelInfo& info = level_infos_[GLTargetToFaceIndex(target)][level]; | 563 const LevelInfo& info = level_infos_[GLTargetToFaceIndex(target)][level]; |
564 if (info.target != 0) { | 564 if (info.target != 0) { |
565 *type = info.type; | 565 *type = info.type; |
566 *internal_format = info.internal_format; | 566 *internal_format = info.internal_format; |
567 return true; | 567 return true; |
568 } | 568 } |
569 } | 569 } |
570 return false; | 570 return false; |
571 } | 571 } |
572 | 572 |
573 GLenum Texture::SetParameter( | 573 GLenum Texture::SetParameteri( |
574 const FeatureInfo* feature_info, GLenum pname, GLint param) { | 574 const FeatureInfo* feature_info, GLenum pname, GLint param) { |
575 DCHECK(feature_info); | 575 DCHECK(feature_info); |
576 | 576 |
577 if (target_ == GL_TEXTURE_EXTERNAL_OES || | 577 if (target_ == GL_TEXTURE_EXTERNAL_OES || |
578 target_ == GL_TEXTURE_RECTANGLE_ARB) { | 578 target_ == GL_TEXTURE_RECTANGLE_ARB) { |
579 if (pname == GL_TEXTURE_MIN_FILTER && | 579 if (pname == GL_TEXTURE_MIN_FILTER && |
580 (param != GL_NEAREST && param != GL_LINEAR)) | 580 (param != GL_NEAREST && param != GL_LINEAR)) |
581 return GL_INVALID_ENUM; | 581 return GL_INVALID_ENUM; |
582 if ((pname == GL_TEXTURE_WRAP_S || pname == GL_TEXTURE_WRAP_T) && | 582 if ((pname == GL_TEXTURE_WRAP_S || pname == GL_TEXTURE_WRAP_T) && |
583 param != GL_CLAMP_TO_EDGE) | 583 param != GL_CLAMP_TO_EDGE) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 default: | 631 default: |
632 NOTREACHED(); | 632 NOTREACHED(); |
633 return GL_INVALID_ENUM; | 633 return GL_INVALID_ENUM; |
634 } | 634 } |
635 Update(feature_info); | 635 Update(feature_info); |
636 UpdateCleared(); | 636 UpdateCleared(); |
637 UpdateCanRenderCondition(); | 637 UpdateCanRenderCondition(); |
638 return GL_NO_ERROR; | 638 return GL_NO_ERROR; |
639 } | 639 } |
640 | 640 |
| 641 GLenum Texture::SetParameterf( |
| 642 const FeatureInfo* feature_info, GLenum pname, GLfloat param) { |
| 643 switch (pname) { |
| 644 case GL_TEXTURE_MIN_FILTER: |
| 645 case GL_TEXTURE_MAG_FILTER: |
| 646 case GL_TEXTURE_POOL_CHROMIUM: |
| 647 case GL_TEXTURE_WRAP_S: |
| 648 case GL_TEXTURE_WRAP_T: |
| 649 case GL_TEXTURE_USAGE_ANGLE: |
| 650 { |
| 651 GLint iparam = static_cast<GLint>(param); |
| 652 return SetParameteri(feature_info, pname, iparam); |
| 653 } |
| 654 case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
| 655 if (param < 1.f) { |
| 656 return GL_INVALID_VALUE; |
| 657 } |
| 658 break; |
| 659 default: |
| 660 NOTREACHED(); |
| 661 return GL_INVALID_ENUM; |
| 662 } |
| 663 return GL_NO_ERROR; |
| 664 } |
| 665 |
641 void Texture::Update(const FeatureInfo* feature_info) { | 666 void Texture::Update(const FeatureInfo* feature_info) { |
642 // Update npot status. | 667 // Update npot status. |
643 // Assume GL_TEXTURE_EXTERNAL_OES textures are npot, all others | 668 // Assume GL_TEXTURE_EXTERNAL_OES textures are npot, all others |
644 npot_ = target_ == GL_TEXTURE_EXTERNAL_OES; | 669 npot_ = target_ == GL_TEXTURE_EXTERNAL_OES; |
645 | 670 |
646 if (level_infos_.empty()) { | 671 if (level_infos_.empty()) { |
647 texture_complete_ = false; | 672 texture_complete_ = false; |
648 cube_complete_ = false; | 673 cube_complete_ = false; |
649 return; | 674 return; |
650 } | 675 } |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1074 TextureRef* TextureManager::Consume( | 1099 TextureRef* TextureManager::Consume( |
1075 GLuint client_id, | 1100 GLuint client_id, |
1076 Texture* texture) { | 1101 Texture* texture) { |
1077 DCHECK(client_id); | 1102 DCHECK(client_id); |
1078 scoped_refptr<TextureRef> ref(new TextureRef(this, client_id, texture)); | 1103 scoped_refptr<TextureRef> ref(new TextureRef(this, client_id, texture)); |
1079 bool result = textures_.insert(std::make_pair(client_id, ref)).second; | 1104 bool result = textures_.insert(std::make_pair(client_id, ref)).second; |
1080 DCHECK(result); | 1105 DCHECK(result); |
1081 return ref.get(); | 1106 return ref.get(); |
1082 } | 1107 } |
1083 | 1108 |
1084 void TextureManager::SetParameter( | 1109 void TextureManager::SetParameteri( |
1085 const char* function_name, ErrorState* error_state, | 1110 const char* function_name, ErrorState* error_state, |
1086 TextureRef* ref, GLenum pname, GLint param) { | 1111 TextureRef* ref, GLenum pname, GLint param) { |
1087 DCHECK(error_state); | 1112 DCHECK(error_state); |
1088 DCHECK(ref); | 1113 DCHECK(ref); |
1089 Texture* texture = ref->texture(); | 1114 Texture* texture = ref->texture(); |
1090 GLenum result = texture->SetParameter(feature_info_.get(), pname, param); | 1115 GLenum result = texture->SetParameteri(feature_info_.get(), pname, param); |
1091 if (result != GL_NO_ERROR) { | 1116 if (result != GL_NO_ERROR) { |
1092 if (result == GL_INVALID_ENUM) { | 1117 if (result == GL_INVALID_ENUM) { |
1093 ERRORSTATE_SET_GL_ERROR_INVALID_ENUM( | 1118 ERRORSTATE_SET_GL_ERROR_INVALID_ENUM( |
1094 error_state, function_name, param, "param"); | 1119 error_state, function_name, param, "param"); |
1095 } else { | 1120 } else { |
1096 ERRORSTATE_SET_GL_ERROR_INVALID_PARAM( | 1121 ERRORSTATE_SET_GL_ERROR_INVALID_PARAMI( |
1097 error_state, result, function_name, pname, static_cast<GLint>(param)); | 1122 error_state, result, function_name, pname, param); |
1098 } | 1123 } |
1099 } else { | 1124 } else { |
1100 // Texture tracking pools exist only for the command decoder, so | 1125 // Texture tracking pools exist only for the command decoder, so |
1101 // do not pass them on to the native GL implementation. | 1126 // do not pass them on to the native GL implementation. |
1102 if (pname != GL_TEXTURE_POOL_CHROMIUM) { | 1127 if (pname != GL_TEXTURE_POOL_CHROMIUM) { |
1103 glTexParameteri(texture->target(), pname, param); | 1128 glTexParameteri(texture->target(), pname, param); |
1104 } | 1129 } |
1105 } | 1130 } |
1106 } | 1131 } |
1107 | 1132 |
| 1133 void TextureManager::SetParameterf( |
| 1134 const char* function_name, ErrorState* error_state, |
| 1135 TextureRef* ref, GLenum pname, GLfloat param) { |
| 1136 DCHECK(error_state); |
| 1137 DCHECK(ref); |
| 1138 Texture* texture = ref->texture(); |
| 1139 GLenum result = texture->SetParameterf(feature_info_.get(), pname, param); |
| 1140 if (result != GL_NO_ERROR) { |
| 1141 if (result == GL_INVALID_ENUM) { |
| 1142 ERRORSTATE_SET_GL_ERROR_INVALID_ENUM( |
| 1143 error_state, function_name, param, "param"); |
| 1144 } else { |
| 1145 ERRORSTATE_SET_GL_ERROR_INVALID_PARAMF( |
| 1146 error_state, result, function_name, pname, param); |
| 1147 } |
| 1148 } else { |
| 1149 // Texture tracking pools exist only for the command decoder, so |
| 1150 // do not pass them on to the native GL implementation. |
| 1151 if (pname != GL_TEXTURE_POOL_CHROMIUM) { |
| 1152 glTexParameterf(texture->target(), pname, param); |
| 1153 } |
| 1154 } |
| 1155 } |
| 1156 |
1108 bool TextureManager::MarkMipmapsGenerated(TextureRef* ref) { | 1157 bool TextureManager::MarkMipmapsGenerated(TextureRef* ref) { |
1109 DCHECK(ref); | 1158 DCHECK(ref); |
1110 Texture* texture = ref->texture(); | 1159 Texture* texture = ref->texture(); |
1111 texture->GetMemTracker()->TrackMemFree(texture->estimated_size()); | 1160 texture->GetMemTracker()->TrackMemFree(texture->estimated_size()); |
1112 bool result = texture->MarkMipmapsGenerated(feature_info_.get()); | 1161 bool result = texture->MarkMipmapsGenerated(feature_info_.get()); |
1113 texture->GetMemTracker()->TrackMemAlloc(texture->estimated_size()); | 1162 texture->GetMemTracker()->TrackMemAlloc(texture->estimated_size()); |
1114 return result; | 1163 return result; |
1115 } | 1164 } |
1116 | 1165 |
1117 TextureRef* TextureManager::CreateTexture( | 1166 TextureRef* TextureManager::CreateTexture( |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1502 } | 1551 } |
1503 | 1552 |
1504 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() { | 1553 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() { |
1505 texture_state_->texture_upload_count++; | 1554 texture_state_->texture_upload_count++; |
1506 texture_state_->total_texture_upload_time += | 1555 texture_state_->total_texture_upload_time += |
1507 base::TimeTicks::HighResNow() - begin_time_; | 1556 base::TimeTicks::HighResNow() - begin_time_; |
1508 } | 1557 } |
1509 | 1558 |
1510 } // namespace gles2 | 1559 } // namespace gles2 |
1511 } // namespace gpu | 1560 } // namespace gpu |
OLD | NEW |