| 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 image_state(UNBOUND), | 395 estimated_size(0) { |
| 396 estimated_size(0) {} | 396 } |
| 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 image_state(rhs.image_state), | 410 estimated_size(rhs.estimated_size) { |
| 411 estimated_size(rhs.estimated_size) {} | 411 } |
| 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; | |
| 836 | 835 |
| 837 UpdateMipCleared(&info, width, height, cleared_rect); | 836 UpdateMipCleared(&info, width, height, cleared_rect); |
| 838 | 837 |
| 839 estimated_size_ -= info.estimated_size; | 838 estimated_size_ -= info.estimated_size; |
| 840 GLES2Util::ComputeImageDataSizes( | 839 GLES2Util::ComputeImageDataSizes( |
| 841 width, height, 1, format, type, 4, &info.estimated_size, NULL, NULL); | 840 width, height, 1, format, type, 4, &info.estimated_size, NULL, NULL); |
| 842 estimated_size_ += info.estimated_size; | 841 estimated_size_ += info.estimated_size; |
| 843 | 842 |
| 844 max_level_set_ = std::max(max_level_set_, level); | 843 max_level_set_ = std::max(max_level_set_, level); |
| 845 Update(feature_info); | 844 Update(feature_info); |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1231 if (!cleared) | 1230 if (!cleared) |
| 1232 return false; | 1231 return false; |
| 1233 } | 1232 } |
| 1234 } | 1233 } |
| 1235 | 1234 |
| 1236 UpdateMipCleared(&info, info.width, info.height, | 1235 UpdateMipCleared(&info, info.width, info.height, |
| 1237 gfx::Rect(info.width, info.height)); | 1236 gfx::Rect(info.width, info.height)); |
| 1238 return true; | 1237 return true; |
| 1239 } | 1238 } |
| 1240 | 1239 |
| 1241 void Texture::SetLevelImage(GLenum target, | 1240 void Texture::SetLevelImage( |
| 1242 GLint level, | 1241 const FeatureInfo* feature_info, |
| 1243 gfx::GLImage* image, | 1242 GLenum target, |
| 1244 ImageState state) { | 1243 GLint level, |
| 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; | |
| 1257 UpdateCanRenderCondition(); | 1256 UpdateCanRenderCondition(); |
| 1258 UpdateHasImages(); | 1257 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 |
| 1259 } | 1262 } |
| 1260 | 1263 |
| 1261 gfx::GLImage* Texture::GetLevelImage(GLint target, | 1264 gfx::GLImage* Texture::GetLevelImage(GLint target, GLint level) const { |
| 1262 GLint level, | |
| 1263 ImageState* state) const { | |
| 1264 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES && | 1265 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES && |
| 1265 target != GL_TEXTURE_RECTANGLE_ARB) { | 1266 target != GL_TEXTURE_RECTANGLE_ARB) { |
| 1266 return NULL; | 1267 return NULL; |
| 1267 } | 1268 } |
| 1268 | 1269 |
| 1269 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 1270 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
| 1270 if (level >= 0 && face_index < face_infos_.size() && | 1271 if (level >= 0 && face_index < face_infos_.size() && |
| 1271 static_cast<size_t>(level) < face_infos_[face_index].level_infos.size()) { | 1272 static_cast<size_t>(level) < face_infos_[face_index].level_infos.size()) { |
| 1272 const LevelInfo& info = face_infos_[face_index].level_infos[level]; | 1273 const LevelInfo& info = face_infos_[face_index].level_infos[level]; |
| 1273 if (info.target != 0) { | 1274 if (info.target != 0) { |
| 1274 if (state) | |
| 1275 *state = info.image_state; | |
| 1276 return info.image.get(); | 1275 return info.image.get(); |
| 1277 } | 1276 } |
| 1278 } | 1277 } |
| 1279 return NULL; | 1278 return NULL; |
| 1280 } | 1279 } |
| 1281 | 1280 |
| 1282 gfx::GLImage* Texture::GetLevelImage(GLint target, GLint level) const { | 1281 void Texture::OnWillModifyPixels() { |
| 1283 return GetLevelImage(target, level, nullptr); | 1282 gfx::GLImage* image = GetLevelImage(target(), 0); |
| 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(); |
| 1284 } | 1291 } |
| 1285 | 1292 |
| 1286 void Texture::DumpLevelMemory(base::trace_event::ProcessMemoryDump* pmd, | 1293 void Texture::DumpLevelMemory(base::trace_event::ProcessMemoryDump* pmd, |
| 1287 uint64_t client_tracing_id, | 1294 uint64_t client_tracing_id, |
| 1288 const std::string& dump_name) const { | 1295 const std::string& dump_name) const { |
| 1289 for (uint32_t face_index = 0; face_index < face_infos_.size(); ++face_index) { | 1296 for (uint32_t face_index = 0; face_index < face_infos_.size(); ++face_index) { |
| 1290 const auto& level_infos = face_infos_[face_index].level_infos; | 1297 const auto& level_infos = face_infos_[face_index].level_infos; |
| 1291 for (uint32_t level_index = 0; level_index < level_infos.size(); | 1298 for (uint32_t level_index = 0; level_index < level_infos.size(); |
| 1292 ++level_index) { | 1299 ++level_index) { |
| 1293 // Skip levels with no size. Textures will have empty levels for all | 1300 // Skip levels with no size. Textures will have empty levels for all |
| 1294 // potential mip levels which are not in use. | 1301 // potential mip levels which are not in use. |
| 1295 if (!level_infos[level_index].estimated_size) | 1302 if (!level_infos[level_index].estimated_size) |
| 1296 continue; | 1303 continue; |
| 1297 | 1304 |
| 1298 // If a level has a GLImage, ask the GLImage to dump itself. | |
| 1299 if (level_infos[level_index].image) { | 1305 if (level_infos[level_index].image) { |
| 1306 // If a level is backed by a GLImage, ask the GLImage to dump itself. |
| 1300 level_infos[level_index].image->OnMemoryDump( | 1307 level_infos[level_index].image->OnMemoryDump( |
| 1301 pmd, client_tracing_id, | 1308 pmd, client_tracing_id, |
| 1302 base::StringPrintf("%s/face_%d/level_%d", dump_name.c_str(), | 1309 base::StringPrintf("%s/face_%d/level_%d", dump_name.c_str(), |
| 1303 face_index, level_index)); | 1310 face_index, level_index)); |
| 1304 } | 1311 } else { |
| 1305 | 1312 // If a level is not backed by a GLImage, create a simple dump. |
| 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) { | |
| 1310 base::trace_event::MemoryAllocatorDump* dump = pmd->CreateAllocatorDump( | 1313 base::trace_event::MemoryAllocatorDump* dump = pmd->CreateAllocatorDump( |
| 1311 base::StringPrintf("%s/face_%d/level_%d", dump_name.c_str(), | 1314 base::StringPrintf("%s/face_%d/level_%d", dump_name.c_str(), |
| 1312 face_index, level_index)); | 1315 face_index, level_index)); |
| 1313 dump->AddScalar( | 1316 dump->AddScalar( |
| 1314 base::trace_event::MemoryAllocatorDump::kNameSize, | 1317 base::trace_event::MemoryAllocatorDump::kNameSize, |
| 1315 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 1318 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 1316 static_cast<uint64_t>(level_infos[level_index].estimated_size)); | 1319 static_cast<uint64_t>(level_infos[level_index].estimated_size)); |
| 1317 } | 1320 } |
| 1318 } | 1321 } |
| 1319 } | 1322 } |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1715 GLsizei depth) { | 1718 GLsizei depth) { |
| 1716 switch (target) { | 1719 switch (target) { |
| 1717 case GL_TEXTURE_EXTERNAL_OES: | 1720 case GL_TEXTURE_EXTERNAL_OES: |
| 1718 return 1; | 1721 return 1; |
| 1719 default: | 1722 default: |
| 1720 return 1 + | 1723 return 1 + |
| 1721 base::bits::Log2Floor(std::max(std::max(width, height), depth)); | 1724 base::bits::Log2Floor(std::max(std::max(width, height), depth)); |
| 1722 } | 1725 } |
| 1723 } | 1726 } |
| 1724 | 1727 |
| 1725 void TextureManager::SetLevelImage(TextureRef* ref, | 1728 void TextureManager::SetLevelImage( |
| 1726 GLenum target, | 1729 TextureRef* ref, |
| 1727 GLint level, | 1730 GLenum target, |
| 1728 gfx::GLImage* image, | 1731 GLint level, |
| 1729 Texture::ImageState state) { | 1732 gfx::GLImage* image) { |
| 1730 DCHECK(ref); | 1733 DCHECK(ref); |
| 1731 ref->texture()->SetLevelImage(target, level, image, state); | 1734 ref->texture()->SetLevelImage(feature_info_.get(), target, level, image); |
| 1732 } | 1735 } |
| 1733 | 1736 |
| 1734 size_t TextureManager::GetSignatureSize() const { | 1737 size_t TextureManager::GetSignatureSize() const { |
| 1735 return sizeof(TextureTag) + sizeof(TextureSignature); | 1738 return sizeof(TextureTag) + sizeof(TextureSignature); |
| 1736 } | 1739 } |
| 1737 | 1740 |
| 1738 void TextureManager::AddToSignature( | 1741 void TextureManager::AddToSignature( |
| 1739 TextureRef* ref, | 1742 TextureRef* ref, |
| 1740 GLenum target, | 1743 GLenum target, |
| 1741 GLint level, | 1744 GLint level, |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2163 pmd->AddOwnershipEdge(client_guid, service_guid, importance); | 2166 pmd->AddOwnershipEdge(client_guid, service_guid, importance); |
| 2164 | 2167 |
| 2165 // Dump all sub-levels held by the texture. They will appear below the main | 2168 // Dump all sub-levels held by the texture. They will appear below the main |
| 2166 // gl/textures/client_X/texture_Y dump. | 2169 // gl/textures/client_X/texture_Y dump. |
| 2167 ref->texture()->DumpLevelMemory(pmd, memory_tracker_->ClientTracingId(), | 2170 ref->texture()->DumpLevelMemory(pmd, memory_tracker_->ClientTracingId(), |
| 2168 dump_name); | 2171 dump_name); |
| 2169 } | 2172 } |
| 2170 | 2173 |
| 2171 } // namespace gles2 | 2174 } // namespace gles2 |
| 2172 } // namespace gpu | 2175 } // namespace gpu |
| OLD | NEW |