| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "gpu/command_buffer/common/gles2_cmd_utils.h" | 7 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
| 8 #include "gpu/command_buffer/service/feature_info.h" | 8 #include "gpu/command_buffer/service/feature_info.h" |
| 9 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 9 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 10 #include "gpu/GLES2/gles2_command_buffer.h" | 10 #include "gpu/GLES2/gles2_command_buffer.h" |
| 11 | 11 |
| 12 namespace gpu { | 12 namespace gpu { |
| 13 namespace gles2 { | 13 namespace gles2 { |
| 14 | 14 |
| 15 static GLsizei ComputeMipMapCount( | 15 static GLsizei ComputeMipMapCount( |
| 16 GLsizei width, GLsizei height, GLsizei depth) { | 16 GLsizei width, GLsizei height, GLsizei depth) { |
| 17 return 1 + base::bits::Log2Floor(std::max(std::max(width, height), depth)); | 17 return 1 + base::bits::Log2Floor(std::max(std::max(width, height), depth)); |
| 18 } | 18 } |
| 19 | 19 |
| 20 static size_t GLTargetToFaceIndex(GLenum target) { | 20 static size_t GLTargetToFaceIndex(GLenum target) { |
| 21 switch (target) { | 21 switch (target) { |
| 22 case GL_TEXTURE_2D: | 22 case GL_TEXTURE_2D: |
| 23 case GL_TEXTURE_EXTERNAL_OES: |
| 23 return 0; | 24 return 0; |
| 24 case GL_TEXTURE_CUBE_MAP_POSITIVE_X: | 25 case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 25 return 0; | 26 return 0; |
| 26 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: | 27 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 27 return 1; | 28 return 1; |
| 28 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: | 29 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 29 return 2; | 30 return 2; |
| 30 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: | 31 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 31 return 3; | 32 return 3; |
| 32 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: | 33 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 info1.format, | 136 info1.format, |
| 136 info1.type); | 137 info1.type); |
| 137 } | 138 } |
| 138 } | 139 } |
| 139 return true; | 140 return true; |
| 140 } | 141 } |
| 141 | 142 |
| 142 bool TextureManager::TextureInfo::CanGenerateMipmaps( | 143 bool TextureManager::TextureInfo::CanGenerateMipmaps( |
| 143 const FeatureInfo* feature_info) const { | 144 const FeatureInfo* feature_info) const { |
| 144 if ((npot() && !feature_info->feature_flags().npot_ok) || | 145 if ((npot() && !feature_info->feature_flags().npot_ok) || |
| 145 level_infos_.empty() || IsDeleted()) { | 146 level_infos_.empty() || IsDeleted() || |
| 147 target_ == GL_TEXTURE_EXTERNAL_OES) { |
| 146 return false; | 148 return false; |
| 147 } | 149 } |
| 148 const TextureInfo::LevelInfo& first = level_infos_[0][0]; | 150 const TextureInfo::LevelInfo& first = level_infos_[0][0]; |
| 149 // TODO(gman): Check internal_format, format and type. | 151 // TODO(gman): Check internal_format, format and type. |
| 150 for (size_t ii = 0; ii < level_infos_.size(); ++ii) { | 152 for (size_t ii = 0; ii < level_infos_.size(); ++ii) { |
| 151 const LevelInfo& info = level_infos_[ii][0]; | 153 const LevelInfo& info = level_infos_[ii][0]; |
| 152 if ((!info.valid) || | 154 if ((!info.valid) || |
| 153 (info.width != first.width) || | 155 (info.width != first.width) || |
| 154 (info.height != first.height) || | 156 (info.height != first.height) || |
| 155 (info.depth != 1) || | 157 (info.depth != 1) || |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 *internal_format = info.internal_format; | 254 *internal_format = info.internal_format; |
| 253 return true; | 255 return true; |
| 254 } | 256 } |
| 255 } | 257 } |
| 256 return false; | 258 return false; |
| 257 } | 259 } |
| 258 | 260 |
| 259 bool TextureManager::TextureInfo::SetParameter( | 261 bool TextureManager::TextureInfo::SetParameter( |
| 260 const FeatureInfo* feature_info, GLenum pname, GLint param) { | 262 const FeatureInfo* feature_info, GLenum pname, GLint param) { |
| 261 DCHECK(feature_info); | 263 DCHECK(feature_info); |
| 264 |
| 265 if (target_ == GL_TEXTURE_EXTERNAL_OES) { |
| 266 if (pname == GL_TEXTURE_MIN_FILTER && |
| 267 (param != GL_NEAREST && param != GL_LINEAR)) |
| 268 return false; |
| 269 if ((pname == GL_TEXTURE_WRAP_S || pname == GL_TEXTURE_WRAP_T) && |
| 270 param != GL_CLAMP_TO_EDGE) |
| 271 return false; |
| 272 } |
| 273 |
| 262 switch (pname) { | 274 switch (pname) { |
| 263 case GL_TEXTURE_MIN_FILTER: | 275 case GL_TEXTURE_MIN_FILTER: |
| 264 if (!feature_info->validators()->texture_min_filter_mode.IsValid(param)) { | 276 if (!feature_info->validators()->texture_min_filter_mode.IsValid(param)) { |
| 265 return false; | 277 return false; |
| 266 } | 278 } |
| 267 min_filter_ = param; | 279 min_filter_ = param; |
| 268 break; | 280 break; |
| 269 case GL_TEXTURE_MAG_FILTER: | 281 case GL_TEXTURE_MAG_FILTER: |
| 270 if (!feature_info->validators()->texture_mag_filter_mode.IsValid(param)) { | 282 if (!feature_info->validators()->texture_mag_filter_mode.IsValid(param)) { |
| 271 return false; | 283 return false; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 max_texture_size, | 396 max_texture_size, |
| 385 max_texture_size)), | 397 max_texture_size)), |
| 386 max_cube_map_levels_(ComputeMipMapCount(max_cube_map_texture_size, | 398 max_cube_map_levels_(ComputeMipMapCount(max_cube_map_texture_size, |
| 387 max_cube_map_texture_size, | 399 max_cube_map_texture_size, |
| 388 max_cube_map_texture_size)), | 400 max_cube_map_texture_size)), |
| 389 num_unrenderable_textures_(0), | 401 num_unrenderable_textures_(0), |
| 390 black_2d_texture_id_(0), | 402 black_2d_texture_id_(0), |
| 391 black_cube_texture_id_(0) { | 403 black_cube_texture_id_(0) { |
| 392 } | 404 } |
| 393 | 405 |
| 394 bool TextureManager::Initialize() { | 406 bool TextureManager::Initialize(const FeatureInfo* feature_info) { |
| 395 // TODO(gman): The default textures have to be real textures, not the 0 | 407 // TODO(gman): The default textures have to be real textures, not the 0 |
| 396 // texture because we simulate non shared resources on top of shared | 408 // texture because we simulate non shared resources on top of shared |
| 397 // resources and all contexts that share resource share the same default | 409 // resources and all contexts that share resource share the same default |
| 398 // texture. | 410 // texture. |
| 399 | 411 |
| 400 // Make default textures and texture for replacing non-renderable textures. | 412 // Make default textures and texture for replacing non-renderable textures. |
| 401 GLuint ids[4]; | 413 GLuint ids[4]; |
| 402 glGenTextures(arraysize(ids), ids); | 414 glGenTextures(arraysize(ids), ids); |
| 403 static uint8 black[] = {0, 0, 0, 255}; | 415 static uint8 black[] = {0, 0, 0, 255}; |
| 404 for (int ii = 0; ii < 2; ++ii) { | 416 for (int ii = 0; ii < 2; ++ii) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 423 SetInfoTarget(default_texture_cube_map_, GL_TEXTURE_CUBE_MAP); | 435 SetInfoTarget(default_texture_cube_map_, GL_TEXTURE_CUBE_MAP); |
| 424 for (int ii = 0; ii < GLES2Util::kNumFaces; ++ii) { | 436 for (int ii = 0; ii < GLES2Util::kNumFaces; ++ii) { |
| 425 default_texture_cube_map_->SetLevelInfo( | 437 default_texture_cube_map_->SetLevelInfo( |
| 426 &temp_feature_info, GLES2Util::IndexToGLFaceTarget(ii), | 438 &temp_feature_info, GLES2Util::IndexToGLFaceTarget(ii), |
| 427 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE); | 439 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE); |
| 428 } | 440 } |
| 429 | 441 |
| 430 black_2d_texture_id_ = ids[0]; | 442 black_2d_texture_id_ = ids[0]; |
| 431 black_cube_texture_id_ = ids[2]; | 443 black_cube_texture_id_ = ids[2]; |
| 432 | 444 |
| 445 if (feature_info->feature_flags().oes_egl_image_external) { |
| 446 GLuint external_ids[2]; |
| 447 glGenTextures(arraysize(external_ids), external_ids); |
| 448 glBindTexture(GL_TEXTURE_EXTERNAL_OES, 0); |
| 449 default_texture_external_oes_ = TextureInfo::Ref( |
| 450 new TextureInfo(external_ids[0])); |
| 451 SetInfoTarget(default_texture_external_oes_, GL_TEXTURE_EXTERNAL_OES); |
| 452 default_texture_external_oes_->SetLevelInfo( |
| 453 &temp_feature_info, GL_TEXTURE_EXTERNAL_OES, 0, |
| 454 GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE); |
| 455 default_texture_external_oes_->SetParameter(feature_info, |
| 456 GL_TEXTURE_MIN_FILTER, |
| 457 GL_LINEAR); |
| 458 default_texture_external_oes_->SetParameter(feature_info, |
| 459 GL_TEXTURE_WRAP_S, |
| 460 GL_CLAMP_TO_EDGE); |
| 461 default_texture_external_oes_->SetParameter(feature_info, |
| 462 GL_TEXTURE_WRAP_T, |
| 463 GL_CLAMP_TO_EDGE); |
| 464 |
| 465 // Sampling a texture not associated with any EGLImage sibling will return |
| 466 // black values according to the spec. |
| 467 black_oes_external_texture_id_ = external_ids[1]; |
| 468 } |
| 469 |
| 433 return true; | 470 return true; |
| 434 } | 471 } |
| 435 | 472 |
| 436 bool TextureManager::ValidForTarget( | 473 bool TextureManager::ValidForTarget( |
| 437 const FeatureInfo* feature_info, | 474 const FeatureInfo* feature_info, |
| 438 GLenum target, GLint level, | 475 GLenum target, GLint level, |
| 439 GLsizei width, GLsizei height, GLsizei depth) { | 476 GLsizei width, GLsizei height, GLsizei depth) { |
| 440 GLsizei max_size = MaxSizeForTarget(target); | 477 GLsizei max_size = MaxSizeForTarget(target); |
| 441 return level >= 0 && | 478 return level >= 0 && |
| 442 width >= 0 && | 479 width >= 0 && |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 return true; | 588 return true; |
| 552 } | 589 } |
| 553 } | 590 } |
| 554 return false; | 591 return false; |
| 555 } | 592 } |
| 556 | 593 |
| 557 } // namespace gles2 | 594 } // namespace gles2 |
| 558 } // namespace gpu | 595 } // namespace gpu |
| 559 | 596 |
| 560 | 597 |
| OLD | NEW |