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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 height, | 133 height, |
133 depth, | 134 depth, |
134 info1.border, | 135 info1.border, |
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 |
| 143 void TextureManager::TextureInfo::SetTarget(GLenum target, GLint max_levels) { |
| 144 DCHECK_EQ(0u, target_); // you can only set this once. |
| 145 target_ = target; |
| 146 size_t num_faces = (target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; |
| 147 level_infos_.resize(num_faces); |
| 148 for (size_t ii = 0; ii < num_faces; ++ii) { |
| 149 level_infos_[ii].resize(max_levels); |
| 150 } |
| 151 |
| 152 if (target == GL_TEXTURE_EXTERNAL_OES) { |
| 153 min_filter_ = GL_LINEAR; |
| 154 wrap_s_ = wrap_t_ = GL_CLAMP_TO_EDGE; |
| 155 } |
| 156 } |
| 157 |
142 bool TextureManager::TextureInfo::CanGenerateMipmaps( | 158 bool TextureManager::TextureInfo::CanGenerateMipmaps( |
143 const FeatureInfo* feature_info) const { | 159 const FeatureInfo* feature_info) const { |
144 if ((npot() && !feature_info->feature_flags().npot_ok) || | 160 if ((npot() && !feature_info->feature_flags().npot_ok) || |
145 level_infos_.empty() || IsDeleted()) { | 161 level_infos_.empty() || IsDeleted() || |
| 162 target_ == GL_TEXTURE_EXTERNAL_OES) { |
146 return false; | 163 return false; |
147 } | 164 } |
148 const TextureInfo::LevelInfo& first = level_infos_[0][0]; | 165 const TextureInfo::LevelInfo& first = level_infos_[0][0]; |
149 // TODO(gman): Check internal_format, format and type. | 166 // TODO(gman): Check internal_format, format and type. |
150 for (size_t ii = 0; ii < level_infos_.size(); ++ii) { | 167 for (size_t ii = 0; ii < level_infos_.size(); ++ii) { |
151 const LevelInfo& info = level_infos_[ii][0]; | 168 const LevelInfo& info = level_infos_[ii][0]; |
152 if ((!info.valid) || | 169 if ((!info.valid) || |
153 (info.width != first.width) || | 170 (info.width != first.width) || |
154 (info.height != first.height) || | 171 (info.height != first.height) || |
155 (info.depth != 1) || | 172 (info.depth != 1) || |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 *internal_format = info.internal_format; | 269 *internal_format = info.internal_format; |
253 return true; | 270 return true; |
254 } | 271 } |
255 } | 272 } |
256 return false; | 273 return false; |
257 } | 274 } |
258 | 275 |
259 bool TextureManager::TextureInfo::SetParameter( | 276 bool TextureManager::TextureInfo::SetParameter( |
260 const FeatureInfo* feature_info, GLenum pname, GLint param) { | 277 const FeatureInfo* feature_info, GLenum pname, GLint param) { |
261 DCHECK(feature_info); | 278 DCHECK(feature_info); |
| 279 |
| 280 if (target_ == GL_TEXTURE_EXTERNAL_OES) { |
| 281 if (pname == GL_TEXTURE_MIN_FILTER && |
| 282 (param != GL_NEAREST && param != GL_LINEAR)) |
| 283 return false; |
| 284 if ((pname == GL_TEXTURE_WRAP_S || pname == GL_TEXTURE_WRAP_T) && |
| 285 param != GL_CLAMP_TO_EDGE) |
| 286 return false; |
| 287 } |
| 288 |
262 switch (pname) { | 289 switch (pname) { |
263 case GL_TEXTURE_MIN_FILTER: | 290 case GL_TEXTURE_MIN_FILTER: |
264 if (!feature_info->validators()->texture_min_filter_mode.IsValid(param)) { | 291 if (!feature_info->validators()->texture_min_filter_mode.IsValid(param)) { |
265 return false; | 292 return false; |
266 } | 293 } |
267 min_filter_ = param; | 294 min_filter_ = param; |
268 break; | 295 break; |
269 case GL_TEXTURE_MAG_FILTER: | 296 case GL_TEXTURE_MAG_FILTER: |
270 if (!feature_info->validators()->texture_mag_filter_mode.IsValid(param)) { | 297 if (!feature_info->validators()->texture_mag_filter_mode.IsValid(param)) { |
271 return false; | 298 return false; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 max_texture_size, | 411 max_texture_size, |
385 max_texture_size)), | 412 max_texture_size)), |
386 max_cube_map_levels_(ComputeMipMapCount(max_cube_map_texture_size, | 413 max_cube_map_levels_(ComputeMipMapCount(max_cube_map_texture_size, |
387 max_cube_map_texture_size, | 414 max_cube_map_texture_size, |
388 max_cube_map_texture_size)), | 415 max_cube_map_texture_size)), |
389 num_unrenderable_textures_(0), | 416 num_unrenderable_textures_(0), |
390 black_2d_texture_id_(0), | 417 black_2d_texture_id_(0), |
391 black_cube_texture_id_(0) { | 418 black_cube_texture_id_(0) { |
392 } | 419 } |
393 | 420 |
394 bool TextureManager::Initialize() { | 421 bool TextureManager::Initialize(const FeatureInfo* feature_info) { |
395 // TODO(gman): The default textures have to be real textures, not the 0 | 422 // 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 | 423 // texture because we simulate non shared resources on top of shared |
397 // resources and all contexts that share resource share the same default | 424 // resources and all contexts that share resource share the same default |
398 // texture. | 425 // texture. |
399 | 426 |
400 // Make default textures and texture for replacing non-renderable textures. | 427 // Make default textures and texture for replacing non-renderable textures. |
401 GLuint ids[4]; | 428 GLuint ids[4]; |
402 glGenTextures(arraysize(ids), ids); | 429 glGenTextures(arraysize(ids), ids); |
403 static uint8 black[] = {0, 0, 0, 255}; | 430 static uint8 black[] = {0, 0, 0, 255}; |
404 for (int ii = 0; ii < 2; ++ii) { | 431 for (int ii = 0; ii < 2; ++ii) { |
(...skipping 18 matching lines...) Expand all Loading... |
423 SetInfoTarget(default_texture_cube_map_, GL_TEXTURE_CUBE_MAP); | 450 SetInfoTarget(default_texture_cube_map_, GL_TEXTURE_CUBE_MAP); |
424 for (int ii = 0; ii < GLES2Util::kNumFaces; ++ii) { | 451 for (int ii = 0; ii < GLES2Util::kNumFaces; ++ii) { |
425 default_texture_cube_map_->SetLevelInfo( | 452 default_texture_cube_map_->SetLevelInfo( |
426 &temp_feature_info, GLES2Util::IndexToGLFaceTarget(ii), | 453 &temp_feature_info, GLES2Util::IndexToGLFaceTarget(ii), |
427 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE); | 454 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE); |
428 } | 455 } |
429 | 456 |
430 black_2d_texture_id_ = ids[0]; | 457 black_2d_texture_id_ = ids[0]; |
431 black_cube_texture_id_ = ids[2]; | 458 black_cube_texture_id_ = ids[2]; |
432 | 459 |
| 460 if (feature_info->feature_flags().oes_egl_image_external) { |
| 461 GLuint external_ids[2]; |
| 462 glGenTextures(arraysize(external_ids), external_ids); |
| 463 glBindTexture(GL_TEXTURE_EXTERNAL_OES, 0); |
| 464 default_texture_external_oes_ = TextureInfo::Ref( |
| 465 new TextureInfo(external_ids[0])); |
| 466 SetInfoTarget(default_texture_external_oes_, GL_TEXTURE_EXTERNAL_OES); |
| 467 default_texture_external_oes_->SetLevelInfo( |
| 468 &temp_feature_info, GL_TEXTURE_EXTERNAL_OES, 0, |
| 469 GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE); |
| 470 |
| 471 // Sampling a texture not associated with any EGLImage sibling will return |
| 472 // black values according to the spec. |
| 473 black_oes_external_texture_id_ = external_ids[1]; |
| 474 } |
| 475 |
433 return true; | 476 return true; |
434 } | 477 } |
435 | 478 |
436 bool TextureManager::ValidForTarget( | 479 bool TextureManager::ValidForTarget( |
437 const FeatureInfo* feature_info, | 480 const FeatureInfo* feature_info, |
438 GLenum target, GLint level, | 481 GLenum target, GLint level, |
439 GLsizei width, GLsizei height, GLsizei depth) { | 482 GLsizei width, GLsizei height, GLsizei depth) { |
440 GLsizei max_size = MaxSizeForTarget(target); | 483 GLsizei max_size = MaxSizeForTarget(target); |
441 return level >= 0 && | 484 return level >= 0 && |
442 width >= 0 && | 485 width >= 0 && |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 return true; | 594 return true; |
552 } | 595 } |
553 } | 596 } |
554 return false; | 597 return false; |
555 } | 598 } |
556 | 599 |
557 } // namespace gles2 | 600 } // namespace gles2 |
558 } // namespace gpu | 601 } // namespace gpu |
559 | 602 |
560 | 603 |
OLD | NEW |