Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: gpu/command_buffer/service/texture_manager.cc

Issue 24152009: Allow rendering from non-stream GL_TEXTURE_EXTERNAL_OES (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@git-svn
Patch Set: eead63fe Rebase. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 estimated_size(rhs.estimated_size) { 191 estimated_size(rhs.estimated_size) {
192 } 192 }
193 193
194 Texture::LevelInfo::~LevelInfo() { 194 Texture::LevelInfo::~LevelInfo() {
195 } 195 }
196 196
197 Texture::CanRenderCondition Texture::GetCanRenderCondition() const { 197 Texture::CanRenderCondition Texture::GetCanRenderCondition() const {
198 if (target_ == 0) 198 if (target_ == 0)
199 return CAN_RENDER_ALWAYS; 199 return CAN_RENDER_ALWAYS;
200 200
201 if (target_ == GL_TEXTURE_EXTERNAL_OES) { 201 if (target_ != GL_TEXTURE_EXTERNAL_OES) {
202 if (!IsStreamTexture()) {
203 return CAN_RENDER_NEVER;
204 }
205 } else {
206 if (level_infos_.empty()) { 202 if (level_infos_.empty()) {
207 return CAN_RENDER_NEVER; 203 return CAN_RENDER_NEVER;
208 } 204 }
209 205
210 const Texture::LevelInfo& first_face = level_infos_[0][0]; 206 const Texture::LevelInfo& first_face = level_infos_[0][0];
211 if (first_face.width == 0 || 207 if (first_face.width == 0 ||
212 first_face.height == 0 || 208 first_face.height == 0 ||
213 first_face.depth == 0) { 209 first_face.depth == 0) {
214 return CAN_RENDER_NEVER; 210 return CAN_RENDER_NEVER;
215 } 211 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 if (!CanGenerateMipmaps(feature_info)) { 283 if (!CanGenerateMipmaps(feature_info)) {
288 return false; 284 return false;
289 } 285 }
290 for (size_t ii = 0; ii < level_infos_.size(); ++ii) { 286 for (size_t ii = 0; ii < level_infos_.size(); ++ii) {
291 const Texture::LevelInfo& info1 = level_infos_[ii][0]; 287 const Texture::LevelInfo& info1 = level_infos_[ii][0];
292 GLsizei width = info1.width; 288 GLsizei width = info1.width;
293 GLsizei height = info1.height; 289 GLsizei height = info1.height;
294 GLsizei depth = info1.depth; 290 GLsizei depth = info1.depth;
295 GLenum target = target_ == GL_TEXTURE_2D ? GL_TEXTURE_2D : 291 GLenum target = target_ == GL_TEXTURE_2D ? GL_TEXTURE_2D :
296 FaceIndexToGLTarget(ii); 292 FaceIndexToGLTarget(ii);
297 int num_mips = TextureManager::ComputeMipMapCount(width, height, depth); 293 int num_mips =
294 TextureManager::ComputeMipMapCount(target_, width, height, depth);
298 for (int level = 1; level < num_mips; ++level) { 295 for (int level = 1; level < num_mips; ++level) {
299 width = std::max(1, width >> 1); 296 width = std::max(1, width >> 1);
300 height = std::max(1, height >> 1); 297 height = std::max(1, height >> 1);
301 depth = std::max(1, depth >> 1); 298 depth = std::max(1, depth >> 1);
302 SetLevelInfo(feature_info, 299 SetLevelInfo(feature_info,
303 target, 300 target,
304 level, 301 level,
305 info1.internal_format, 302 info1.internal_format,
306 width, 303 width,
307 height, 304 height,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 UpdateCleared(); 380 UpdateCleared();
384 } 381 }
385 382
386 void Texture::UpdateCleared() { 383 void Texture::UpdateCleared() {
387 if (level_infos_.empty()) { 384 if (level_infos_.empty()) {
388 return; 385 return;
389 } 386 }
390 387
391 const Texture::LevelInfo& first_face = level_infos_[0][0]; 388 const Texture::LevelInfo& first_face = level_infos_[0][0];
392 int levels_needed = TextureManager::ComputeMipMapCount( 389 int levels_needed = TextureManager::ComputeMipMapCount(
393 first_face.width, first_face.height, first_face.depth); 390 target_, first_face.width, first_face.height, first_face.depth);
394 bool cleared = true; 391 bool cleared = true;
395 for (size_t ii = 0; ii < level_infos_.size(); ++ii) { 392 for (size_t ii = 0; ii < level_infos_.size(); ++ii) {
396 for (GLint jj = 0; jj < levels_needed; ++jj) { 393 for (GLint jj = 0; jj < levels_needed; ++jj) {
397 const Texture::LevelInfo& info = level_infos_[ii][jj]; 394 const Texture::LevelInfo& info = level_infos_[ii][jj];
398 if (info.width > 0 && info.height > 0 && info.depth > 0 && 395 if (info.width > 0 && info.height > 0 && info.depth > 0 &&
399 !info.cleared) { 396 !info.cleared) {
400 cleared = false; 397 cleared = false;
401 break; 398 break;
402 } 399 }
403 } 400 }
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 GLES2Util::IsNPOT(info.height) || 633 GLES2Util::IsNPOT(info.height) ||
637 GLES2Util::IsNPOT(info.depth)) { 634 GLES2Util::IsNPOT(info.depth)) {
638 npot_ = true; 635 npot_ = true;
639 break; 636 break;
640 } 637 }
641 } 638 }
642 639
643 // Update texture_complete and cube_complete status. 640 // Update texture_complete and cube_complete status.
644 const Texture::LevelInfo& first_face = level_infos_[0][0]; 641 const Texture::LevelInfo& first_face = level_infos_[0][0];
645 int levels_needed = TextureManager::ComputeMipMapCount( 642 int levels_needed = TextureManager::ComputeMipMapCount(
646 first_face.width, first_face.height, first_face.depth); 643 target_, first_face.width, first_face.height, first_face.depth);
647 texture_complete_ = 644 texture_complete_ =
648 max_level_set_ >= (levels_needed - 1) && max_level_set_ >= 0; 645 max_level_set_ >= (levels_needed - 1) && max_level_set_ >= 0;
649 cube_complete_ = (level_infos_.size() == 6) && 646 cube_complete_ = (level_infos_.size() == 6) &&
650 (first_face.width == first_face.height); 647 (first_face.width == first_face.height);
651 648
652 if (first_face.width == 0 || first_face.height == 0) { 649 if (first_face.width == 0 || first_face.height == 0) {
653 texture_complete_ = false; 650 texture_complete_ = false;
654 } 651 }
655 if (first_face.type == GL_FLOAT && 652 if (first_face.type == GL_FLOAT &&
656 !feature_info->feature_flags().enable_texture_float_linear && 653 !feature_info->feature_flags().enable_texture_float_linear &&
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 } 698 }
702 699
703 bool Texture::ClearRenderableLevels(GLES2Decoder* decoder) { 700 bool Texture::ClearRenderableLevels(GLES2Decoder* decoder) {
704 DCHECK(decoder); 701 DCHECK(decoder);
705 if (cleared_) { 702 if (cleared_) {
706 return true; 703 return true;
707 } 704 }
708 705
709 const Texture::LevelInfo& first_face = level_infos_[0][0]; 706 const Texture::LevelInfo& first_face = level_infos_[0][0];
710 int levels_needed = TextureManager::ComputeMipMapCount( 707 int levels_needed = TextureManager::ComputeMipMapCount(
711 first_face.width, first_face.height, first_face.depth); 708 target_, first_face.width, first_face.height, first_face.depth);
712 709
713 for (size_t ii = 0; ii < level_infos_.size(); ++ii) { 710 for (size_t ii = 0; ii < level_infos_.size(); ++ii) {
714 for (GLint jj = 0; jj < levels_needed; ++jj) { 711 for (GLint jj = 0; jj < levels_needed; ++jj) {
715 Texture::LevelInfo& info = level_infos_[ii][jj]; 712 Texture::LevelInfo& info = level_infos_[ii][jj];
716 if (info.target != 0) { 713 if (info.target != 0) {
717 if (!ClearLevel(decoder, info.target, jj)) { 714 if (!ClearLevel(decoder, info.target, jj)) {
718 return false; 715 return false;
719 } 716 }
720 } 717 }
721 } 718 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 GLuint service_id) { 814 GLuint service_id) {
818 return new TextureRef(manager, client_id, new Texture(service_id)); 815 return new TextureRef(manager, client_id, new Texture(service_id));
819 } 816 }
820 817
821 TextureRef::~TextureRef() { 818 TextureRef::~TextureRef() {
822 manager_->StopTracking(this); 819 manager_->StopTracking(this);
823 texture_->RemoveTextureRef(this, manager_->have_context_); 820 texture_->RemoveTextureRef(this, manager_->have_context_);
824 manager_ = NULL; 821 manager_ = NULL;
825 } 822 }
826 823
827 TextureManager::TextureManager( 824 TextureManager::TextureManager(MemoryTracker* memory_tracker,
828 MemoryTracker* memory_tracker, 825 FeatureInfo* feature_info,
829 FeatureInfo* feature_info, 826 GLint max_texture_size,
830 GLint max_texture_size, 827 GLint max_cube_map_texture_size)
831 GLint max_cube_map_texture_size) 828 : memory_tracker_managed_(new MemoryTypeTracker(memory_tracker,
832 : memory_tracker_managed_( 829 MemoryTracker::kManaged)),
833 new MemoryTypeTracker(memory_tracker, MemoryTracker::kManaged)),
834 memory_tracker_unmanaged_( 830 memory_tracker_unmanaged_(
835 new MemoryTypeTracker(memory_tracker, MemoryTracker::kUnmanaged)), 831 new MemoryTypeTracker(memory_tracker, MemoryTracker::kUnmanaged)),
836 feature_info_(feature_info), 832 feature_info_(feature_info),
837 framebuffer_manager_(NULL), 833 framebuffer_manager_(NULL),
838 stream_texture_manager_(NULL), 834 stream_texture_manager_(NULL),
839 max_texture_size_(max_texture_size), 835 max_texture_size_(max_texture_size),
840 max_cube_map_texture_size_(max_cube_map_texture_size), 836 max_cube_map_texture_size_(max_cube_map_texture_size),
841 max_levels_(ComputeMipMapCount(max_texture_size, 837 max_levels_(ComputeMipMapCount(GL_TEXTURE_2D,
838 max_texture_size,
842 max_texture_size, 839 max_texture_size,
843 max_texture_size)), 840 max_texture_size)),
844 max_cube_map_levels_(ComputeMipMapCount(max_cube_map_texture_size, 841 max_cube_map_levels_(ComputeMipMapCount(GL_TEXTURE_CUBE_MAP,
842 max_cube_map_texture_size,
845 max_cube_map_texture_size, 843 max_cube_map_texture_size,
846 max_cube_map_texture_size)), 844 max_cube_map_texture_size)),
847 num_unrenderable_textures_(0), 845 num_unrenderable_textures_(0),
848 num_unsafe_textures_(0), 846 num_unsafe_textures_(0),
849 num_uncleared_mips_(0), 847 num_uncleared_mips_(0),
850 texture_count_(0), 848 texture_count_(0),
851 have_context_(true) { 849 have_context_(true) {
852 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { 850 for (int ii = 0; ii < kNumDefaultTextures; ++ii) {
853 black_texture_ids_[ii] = 0; 851 black_texture_ids_[ii] = 0;
854 } 852 }
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 // This doesn't need to be fast. It's only used during slow queries. 1175 // This doesn't need to be fast. It's only used during slow queries.
1178 for (TextureMap::const_iterator it = textures_.begin(); 1176 for (TextureMap::const_iterator it = textures_.begin();
1179 it != textures_.end(); ++it) { 1177 it != textures_.end(); ++it) {
1180 Texture* texture = it->second->texture(); 1178 Texture* texture = it->second->texture();
1181 if (texture->service_id() == service_id) 1179 if (texture->service_id() == service_id)
1182 return texture; 1180 return texture;
1183 } 1181 }
1184 return NULL; 1182 return NULL;
1185 } 1183 }
1186 1184
1187 GLsizei TextureManager::ComputeMipMapCount( 1185 GLsizei TextureManager::ComputeMipMapCount(GLenum target,
1188 GLsizei width, GLsizei height, GLsizei depth) { 1186 GLsizei width,
1189 return 1 + base::bits::Log2Floor(std::max(std::max(width, height), depth)); 1187 GLsizei height,
1188 GLsizei depth) {
1189 switch (target) {
1190 case GL_TEXTURE_EXTERNAL_OES:
1191 return 1;
1192 default:
1193 return 1 +
1194 base::bits::Log2Floor(std::max(std::max(width, height), depth));
1195 }
1190 } 1196 }
1191 1197
1192 void TextureManager::SetLevelImage( 1198 void TextureManager::SetLevelImage(
1193 TextureRef* ref, 1199 TextureRef* ref,
1194 GLenum target, 1200 GLenum target,
1195 GLint level, 1201 GLint level,
1196 gfx::GLImage* image) { 1202 gfx::GLImage* image) {
1197 DCHECK(ref); 1203 DCHECK(ref);
1198 ref->texture()->SetLevelImage(feature_info_.get(), target, level, image); 1204 ref->texture()->SetLevelImage(feature_info_.get(), target, level, image);
1199 } 1205 }
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1465 } 1471 }
1466 1472
1467 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() { 1473 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() {
1468 texture_state_->texture_upload_count++; 1474 texture_state_->texture_upload_count++;
1469 texture_state_->total_texture_upload_time += 1475 texture_state_->total_texture_upload_time +=
1470 base::TimeTicks::HighResNow() - begin_time_; 1476 base::TimeTicks::HighResNow() - begin_time_;
1471 } 1477 }
1472 1478
1473 } // namespace gles2 1479 } // namespace gles2
1474 } // namespace gpu 1480 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698