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 <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 Texture::LevelInfo::LevelInfo() | 385 Texture::LevelInfo::LevelInfo() |
386 : target(0), | 386 : target(0), |
387 level(-1), | 387 level(-1), |
388 internal_format(0), | 388 internal_format(0), |
389 width(0), | 389 width(0), |
390 height(0), | 390 height(0), |
391 depth(0), | 391 depth(0), |
392 border(0), | 392 border(0), |
393 format(0), | 393 format(0), |
394 type(0), | 394 type(0), |
395 estimated_size(0) { | 395 image_state(UNBOUND), |
396 } | 396 estimated_size(0) {} |
397 | 397 |
398 Texture::LevelInfo::LevelInfo(const LevelInfo& rhs) | 398 Texture::LevelInfo::LevelInfo(const LevelInfo& rhs) |
399 : cleared_rect(rhs.cleared_rect), | 399 : cleared_rect(rhs.cleared_rect), |
400 target(rhs.target), | 400 target(rhs.target), |
401 level(rhs.level), | 401 level(rhs.level), |
402 internal_format(rhs.internal_format), | 402 internal_format(rhs.internal_format), |
403 width(rhs.width), | 403 width(rhs.width), |
404 height(rhs.height), | 404 height(rhs.height), |
405 depth(rhs.depth), | 405 depth(rhs.depth), |
406 border(rhs.border), | 406 border(rhs.border), |
407 format(rhs.format), | 407 format(rhs.format), |
408 type(rhs.type), | 408 type(rhs.type), |
409 image(rhs.image), | 409 image(rhs.image), |
410 estimated_size(rhs.estimated_size) { | 410 image_state(rhs.image_state), |
411 } | 411 estimated_size(rhs.estimated_size) {} |
412 | 412 |
413 Texture::LevelInfo::~LevelInfo() { | 413 Texture::LevelInfo::~LevelInfo() { |
414 } | 414 } |
415 | 415 |
416 Texture::FaceInfo::FaceInfo() | 416 Texture::FaceInfo::FaceInfo() |
417 : num_mip_levels(0) { | 417 : num_mip_levels(0) { |
418 } | 418 } |
419 | 419 |
420 Texture::FaceInfo::~FaceInfo() { | 420 Texture::FaceInfo::~FaceInfo() { |
421 } | 421 } |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 } | 825 } |
826 | 826 |
827 info.target = target; | 827 info.target = target; |
828 info.level = level; | 828 info.level = level; |
829 info.internal_format = internal_format; | 829 info.internal_format = internal_format; |
830 info.depth = depth; | 830 info.depth = depth; |
831 info.border = border; | 831 info.border = border; |
832 info.format = format; | 832 info.format = format; |
833 info.type = type; | 833 info.type = type; |
834 info.image = 0; | 834 info.image = 0; |
| 835 info.image_state = UNBOUND; |
835 | 836 |
836 UpdateMipCleared(&info, width, height, cleared_rect); | 837 UpdateMipCleared(&info, width, height, cleared_rect); |
837 | 838 |
838 estimated_size_ -= info.estimated_size; | 839 estimated_size_ -= info.estimated_size; |
839 GLES2Util::ComputeImageDataSizes( | 840 GLES2Util::ComputeImageDataSizes( |
840 width, height, 1, format, type, 4, &info.estimated_size, NULL, NULL); | 841 width, height, 1, format, type, 4, &info.estimated_size, NULL, NULL); |
841 estimated_size_ += info.estimated_size; | 842 estimated_size_ += info.estimated_size; |
842 | 843 |
843 max_level_set_ = std::max(max_level_set_, level); | 844 max_level_set_ = std::max(max_level_set_, level); |
844 Update(feature_info); | 845 Update(feature_info); |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 if (!cleared) | 1231 if (!cleared) |
1231 return false; | 1232 return false; |
1232 } | 1233 } |
1233 } | 1234 } |
1234 | 1235 |
1235 UpdateMipCleared(&info, info.width, info.height, | 1236 UpdateMipCleared(&info, info.width, info.height, |
1236 gfx::Rect(info.width, info.height)); | 1237 gfx::Rect(info.width, info.height)); |
1237 return true; | 1238 return true; |
1238 } | 1239 } |
1239 | 1240 |
1240 void Texture::SetLevelImage( | 1241 void Texture::SetLevelImage(GLenum target, |
1241 const FeatureInfo* feature_info, | 1242 GLint level, |
1242 GLenum target, | 1243 gfx::GLImage* image, |
1243 GLint level, | 1244 ImageState state) { |
1244 gfx::GLImage* image) { | |
1245 DCHECK_GE(level, 0); | 1245 DCHECK_GE(level, 0); |
1246 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 1246 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
1247 DCHECK_LT(static_cast<size_t>(face_index), | 1247 DCHECK_LT(static_cast<size_t>(face_index), |
1248 face_infos_.size()); | 1248 face_infos_.size()); |
1249 DCHECK_LT(static_cast<size_t>(level), | 1249 DCHECK_LT(static_cast<size_t>(level), |
1250 face_infos_[face_index].level_infos.size()); | 1250 face_infos_[face_index].level_infos.size()); |
1251 Texture::LevelInfo& info = | 1251 Texture::LevelInfo& info = |
1252 face_infos_[face_index].level_infos[level]; | 1252 face_infos_[face_index].level_infos[level]; |
1253 DCHECK_EQ(info.target, target); | 1253 DCHECK_EQ(info.target, target); |
1254 DCHECK_EQ(info.level, level); | 1254 DCHECK_EQ(info.level, level); |
1255 info.image = image; | 1255 info.image = image; |
| 1256 info.image_state = state; |
1256 UpdateCanRenderCondition(); | 1257 UpdateCanRenderCondition(); |
1257 UpdateHasImages(); | 1258 UpdateHasImages(); |
1258 | |
1259 // TODO(ericrk): Images may have complex sizing not accounted for by | |
1260 // |estimated_size_|, we should add logic here to update |estimated_size_| | |
1261 // based on the new GLImage. crbug.com/526298 | |
1262 } | 1259 } |
1263 | 1260 |
1264 gfx::GLImage* Texture::GetLevelImage(GLint target, GLint level) const { | 1261 gfx::GLImage* Texture::GetLevelImage(GLint target, |
| 1262 GLint level, |
| 1263 ImageState* state) const { |
1265 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES && | 1264 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES && |
1266 target != GL_TEXTURE_RECTANGLE_ARB) { | 1265 target != GL_TEXTURE_RECTANGLE_ARB) { |
1267 return NULL; | 1266 return NULL; |
1268 } | 1267 } |
1269 | 1268 |
1270 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 1269 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
1271 if (level >= 0 && face_index < face_infos_.size() && | 1270 if (level >= 0 && face_index < face_infos_.size() && |
1272 static_cast<size_t>(level) < face_infos_[face_index].level_infos.size()) { | 1271 static_cast<size_t>(level) < face_infos_[face_index].level_infos.size()) { |
1273 const LevelInfo& info = face_infos_[face_index].level_infos[level]; | 1272 const LevelInfo& info = face_infos_[face_index].level_infos[level]; |
1274 if (info.target != 0) { | 1273 if (info.target != 0) { |
| 1274 if (state) |
| 1275 *state = info.image_state; |
1275 return info.image.get(); | 1276 return info.image.get(); |
1276 } | 1277 } |
1277 } | 1278 } |
1278 return NULL; | 1279 return NULL; |
1279 } | 1280 } |
1280 | 1281 |
1281 void Texture::OnWillModifyPixels() { | 1282 gfx::GLImage* Texture::GetLevelImage(GLint target, GLint level) const { |
1282 gfx::GLImage* image = GetLevelImage(target(), 0); | 1283 return GetLevelImage(target, level, nullptr); |
1283 if (image) | |
1284 image->WillModifyTexImage(); | |
1285 } | |
1286 | |
1287 void Texture::OnDidModifyPixels() { | |
1288 gfx::GLImage* image = GetLevelImage(target(), 0); | |
1289 if (image) | |
1290 image->DidModifyTexImage(); | |
1291 } | 1284 } |
1292 | 1285 |
1293 void Texture::DumpLevelMemory(base::trace_event::ProcessMemoryDump* pmd, | 1286 void Texture::DumpLevelMemory(base::trace_event::ProcessMemoryDump* pmd, |
1294 uint64_t client_tracing_id, | 1287 uint64_t client_tracing_id, |
1295 const std::string& dump_name) const { | 1288 const std::string& dump_name) const { |
1296 for (uint32_t face_index = 0; face_index < face_infos_.size(); ++face_index) { | 1289 for (uint32_t face_index = 0; face_index < face_infos_.size(); ++face_index) { |
1297 const auto& level_infos = face_infos_[face_index].level_infos; | 1290 const auto& level_infos = face_infos_[face_index].level_infos; |
1298 for (uint32_t level_index = 0; level_index < level_infos.size(); | 1291 for (uint32_t level_index = 0; level_index < level_infos.size(); |
1299 ++level_index) { | 1292 ++level_index) { |
1300 // Skip levels with no size. Textures will have empty levels for all | 1293 // Skip levels with no size. Textures will have empty levels for all |
1301 // potential mip levels which are not in use. | 1294 // potential mip levels which are not in use. |
1302 if (!level_infos[level_index].estimated_size) | 1295 if (!level_infos[level_index].estimated_size) |
1303 continue; | 1296 continue; |
1304 | 1297 |
| 1298 // If a level has a GLImage, ask the GLImage to dump itself. |
1305 if (level_infos[level_index].image) { | 1299 if (level_infos[level_index].image) { |
1306 // If a level is backed by a GLImage, ask the GLImage to dump itself. | |
1307 level_infos[level_index].image->OnMemoryDump( | 1300 level_infos[level_index].image->OnMemoryDump( |
1308 pmd, client_tracing_id, | 1301 pmd, client_tracing_id, |
1309 base::StringPrintf("%s/face_%d/level_%d", dump_name.c_str(), | 1302 base::StringPrintf("%s/face_%d/level_%d", dump_name.c_str(), |
1310 face_index, level_index)); | 1303 face_index, level_index)); |
1311 } else { | 1304 } |
1312 // If a level is not backed by a GLImage, create a simple dump. | 1305 |
| 1306 // If a level does not have a GLImage bound to it, then dump the |
| 1307 // texture allocation also as the storage is not provided by the |
| 1308 // GLImage in that case. |
| 1309 if (level_infos[level_index].image_state != BOUND) { |
1313 base::trace_event::MemoryAllocatorDump* dump = pmd->CreateAllocatorDump( | 1310 base::trace_event::MemoryAllocatorDump* dump = pmd->CreateAllocatorDump( |
1314 base::StringPrintf("%s/face_%d/level_%d", dump_name.c_str(), | 1311 base::StringPrintf("%s/face_%d/level_%d", dump_name.c_str(), |
1315 face_index, level_index)); | 1312 face_index, level_index)); |
1316 dump->AddScalar( | 1313 dump->AddScalar( |
1317 base::trace_event::MemoryAllocatorDump::kNameSize, | 1314 base::trace_event::MemoryAllocatorDump::kNameSize, |
1318 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 1315 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
1319 static_cast<uint64_t>(level_infos[level_index].estimated_size)); | 1316 static_cast<uint64_t>(level_infos[level_index].estimated_size)); |
1320 } | 1317 } |
1321 } | 1318 } |
1322 } | 1319 } |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1718 GLsizei depth) { | 1715 GLsizei depth) { |
1719 switch (target) { | 1716 switch (target) { |
1720 case GL_TEXTURE_EXTERNAL_OES: | 1717 case GL_TEXTURE_EXTERNAL_OES: |
1721 return 1; | 1718 return 1; |
1722 default: | 1719 default: |
1723 return 1 + | 1720 return 1 + |
1724 base::bits::Log2Floor(std::max(std::max(width, height), depth)); | 1721 base::bits::Log2Floor(std::max(std::max(width, height), depth)); |
1725 } | 1722 } |
1726 } | 1723 } |
1727 | 1724 |
1728 void TextureManager::SetLevelImage( | 1725 void TextureManager::SetLevelImage(TextureRef* ref, |
1729 TextureRef* ref, | 1726 GLenum target, |
1730 GLenum target, | 1727 GLint level, |
1731 GLint level, | 1728 gfx::GLImage* image, |
1732 gfx::GLImage* image) { | 1729 Texture::ImageState state) { |
1733 DCHECK(ref); | 1730 DCHECK(ref); |
1734 ref->texture()->SetLevelImage(feature_info_.get(), target, level, image); | 1731 ref->texture()->SetLevelImage(target, level, image, state); |
1735 } | 1732 } |
1736 | 1733 |
1737 size_t TextureManager::GetSignatureSize() const { | 1734 size_t TextureManager::GetSignatureSize() const { |
1738 return sizeof(TextureTag) + sizeof(TextureSignature); | 1735 return sizeof(TextureTag) + sizeof(TextureSignature); |
1739 } | 1736 } |
1740 | 1737 |
1741 void TextureManager::AddToSignature( | 1738 void TextureManager::AddToSignature( |
1742 TextureRef* ref, | 1739 TextureRef* ref, |
1743 GLenum target, | 1740 GLenum target, |
1744 GLint level, | 1741 GLint level, |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2166 pmd->AddOwnershipEdge(client_guid, service_guid, importance); | 2163 pmd->AddOwnershipEdge(client_guid, service_guid, importance); |
2167 | 2164 |
2168 // Dump all sub-levels held by the texture. They will appear below the main | 2165 // Dump all sub-levels held by the texture. They will appear below the main |
2169 // gl/textures/client_X/texture_Y dump. | 2166 // gl/textures/client_X/texture_Y dump. |
2170 ref->texture()->DumpLevelMemory(pmd, memory_tracker_->ClientTracingId(), | 2167 ref->texture()->DumpLevelMemory(pmd, memory_tracker_->ClientTracingId(), |
2171 dump_name); | 2168 dump_name); |
2172 } | 2169 } |
2173 | 2170 |
2174 } // namespace gles2 | 2171 } // namespace gles2 |
2175 } // namespace gpu | 2172 } // namespace gpu |
OLD | NEW |