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 |
11 #include "base/bits.h" | 11 #include "base/bits.h" |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "base/trace_event/memory_dump_manager.h" | |
14 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 15 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
15 #include "gpu/command_buffer/service/context_state.h" | 16 #include "gpu/command_buffer/service/context_state.h" |
16 #include "gpu/command_buffer/service/error_state.h" | 17 #include "gpu/command_buffer/service/error_state.h" |
17 #include "gpu/command_buffer/service/feature_info.h" | 18 #include "gpu/command_buffer/service/feature_info.h" |
18 #include "gpu/command_buffer/service/framebuffer_manager.h" | 19 #include "gpu/command_buffer/service/framebuffer_manager.h" |
19 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 20 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
20 #include "gpu/command_buffer/service/mailbox_manager.h" | 21 #include "gpu/command_buffer/service/mailbox_manager.h" |
21 #include "gpu/command_buffer/service/memory_tracking.h" | 22 #include "gpu/command_buffer/service/memory_tracking.h" |
22 #include "ui/gl/gl_implementation.h" | 23 #include "ui/gl/gl_implementation.h" |
23 | 24 |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 DCHECK(textures_.empty()); | 277 DCHECK(textures_.empty()); |
277 | 278 |
278 // If this triggers, that means something is keeping a reference to | 279 // If this triggers, that means something is keeping a reference to |
279 // a Texture belonging to this. | 280 // a Texture belonging to this. |
280 CHECK_EQ(texture_count_, 0u); | 281 CHECK_EQ(texture_count_, 0u); |
281 | 282 |
282 DCHECK_EQ(0, num_unrenderable_textures_); | 283 DCHECK_EQ(0, num_unrenderable_textures_); |
283 DCHECK_EQ(0, num_unsafe_textures_); | 284 DCHECK_EQ(0, num_unsafe_textures_); |
284 DCHECK_EQ(0, num_uncleared_mips_); | 285 DCHECK_EQ(0, num_uncleared_mips_); |
285 DCHECK_EQ(0, num_images_); | 286 DCHECK_EQ(0, num_images_); |
287 | |
288 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | |
289 this); | |
286 } | 290 } |
287 | 291 |
288 void TextureManager::Destroy(bool have_context) { | 292 void TextureManager::Destroy(bool have_context) { |
289 have_context_ = have_context; | 293 have_context_ = have_context; |
290 textures_.clear(); | 294 textures_.clear(); |
291 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { | 295 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { |
292 default_textures_[ii] = NULL; | 296 default_textures_[ii] = NULL; |
293 } | 297 } |
294 | 298 |
295 if (have_context) { | 299 if (have_context) { |
(...skipping 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1317 FeatureInfo* feature_info, | 1321 FeatureInfo* feature_info, |
1318 GLint max_texture_size, | 1322 GLint max_texture_size, |
1319 GLint max_cube_map_texture_size, | 1323 GLint max_cube_map_texture_size, |
1320 GLint max_rectangle_texture_size, | 1324 GLint max_rectangle_texture_size, |
1321 GLint max_3d_texture_size, | 1325 GLint max_3d_texture_size, |
1322 bool use_default_textures) | 1326 bool use_default_textures) |
1323 : memory_tracker_managed_( | 1327 : memory_tracker_managed_( |
1324 new MemoryTypeTracker(memory_tracker, MemoryTracker::kManaged)), | 1328 new MemoryTypeTracker(memory_tracker, MemoryTracker::kManaged)), |
1325 memory_tracker_unmanaged_( | 1329 memory_tracker_unmanaged_( |
1326 new MemoryTypeTracker(memory_tracker, MemoryTracker::kUnmanaged)), | 1330 new MemoryTypeTracker(memory_tracker, MemoryTracker::kUnmanaged)), |
1331 memory_tracker_(memory_tracker), | |
1327 feature_info_(feature_info), | 1332 feature_info_(feature_info), |
1328 framebuffer_manager_(NULL), | 1333 framebuffer_manager_(NULL), |
1329 max_texture_size_(max_texture_size), | 1334 max_texture_size_(max_texture_size), |
1330 max_cube_map_texture_size_(max_cube_map_texture_size), | 1335 max_cube_map_texture_size_(max_cube_map_texture_size), |
1331 max_rectangle_texture_size_(max_rectangle_texture_size), | 1336 max_rectangle_texture_size_(max_rectangle_texture_size), |
1332 max_3d_texture_size_(max_3d_texture_size), | 1337 max_3d_texture_size_(max_3d_texture_size), |
1333 max_levels_(ComputeMipMapCount(GL_TEXTURE_2D, | 1338 max_levels_(ComputeMipMapCount(GL_TEXTURE_2D, |
1334 max_texture_size, | 1339 max_texture_size, |
1335 max_texture_size, | 1340 max_texture_size, |
1336 max_texture_size)), | 1341 max_texture_size)), |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1368 if (feature_info_->feature_flags().oes_egl_image_external) { | 1373 if (feature_info_->feature_flags().oes_egl_image_external) { |
1369 default_textures_[kExternalOES] = CreateDefaultAndBlackTextures( | 1374 default_textures_[kExternalOES] = CreateDefaultAndBlackTextures( |
1370 GL_TEXTURE_EXTERNAL_OES, &black_texture_ids_[kExternalOES]); | 1375 GL_TEXTURE_EXTERNAL_OES, &black_texture_ids_[kExternalOES]); |
1371 } | 1376 } |
1372 | 1377 |
1373 if (feature_info_->feature_flags().arb_texture_rectangle) { | 1378 if (feature_info_->feature_flags().arb_texture_rectangle) { |
1374 default_textures_[kRectangleARB] = CreateDefaultAndBlackTextures( | 1379 default_textures_[kRectangleARB] = CreateDefaultAndBlackTextures( |
1375 GL_TEXTURE_RECTANGLE_ARB, &black_texture_ids_[kRectangleARB]); | 1380 GL_TEXTURE_RECTANGLE_ARB, &black_texture_ids_[kRectangleARB]); |
1376 } | 1381 } |
1377 | 1382 |
1383 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | |
1384 this); | |
reveman
2015/07/24 21:16:36
You'll need to provide a ThreadTaskRunnerHandle he
ericrk
2015/07/28 21:02:32
Done.
| |
1385 | |
1378 return true; | 1386 return true; |
1379 } | 1387 } |
1380 | 1388 |
1381 scoped_refptr<TextureRef> | 1389 scoped_refptr<TextureRef> |
1382 TextureManager::CreateDefaultAndBlackTextures( | 1390 TextureManager::CreateDefaultAndBlackTextures( |
1383 GLenum target, | 1391 GLenum target, |
1384 GLuint* black_texture) { | 1392 GLuint* black_texture) { |
1385 static uint8 black[] = {0, 0, 0, 255}; | 1393 static uint8 black[] = {0, 0, 0, 255}; |
1386 | 1394 |
1387 // Sampling a texture not associated with any EGLImage sibling will return | 1395 // Sampling a texture not associated with any EGLImage sibling will return |
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2020 : texture_state_(texture_state), | 2028 : texture_state_(texture_state), |
2021 begin_time_(base::TimeTicks::Now()) { | 2029 begin_time_(base::TimeTicks::Now()) { |
2022 } | 2030 } |
2023 | 2031 |
2024 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() { | 2032 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() { |
2025 texture_state_->texture_upload_count++; | 2033 texture_state_->texture_upload_count++; |
2026 texture_state_->total_texture_upload_time += | 2034 texture_state_->total_texture_upload_time += |
2027 base::TimeTicks::Now() - begin_time_; | 2035 base::TimeTicks::Now() - begin_time_; |
2028 } | 2036 } |
2029 | 2037 |
2038 bool TextureManager::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd) { | |
2039 for (const auto& resource : textures_) { | |
2040 // Only dump memory info for textures actually owned by this TextureManager. | |
2041 if (resource.second == resource.second->texture()->memory_tracking_ref_) { | |
2042 DumpTextureRef(pmd, resource.second.get()); | |
2043 } | |
2044 } | |
2045 | |
2046 // Also dump TextureManager internal textures, if allocated. | |
2047 for (int i = 0; i < kNumDefaultTextures; i++) { | |
2048 if (default_textures_[i]) { | |
2049 DumpTextureRef(pmd, default_textures_[i].get()); | |
2050 } | |
2051 } | |
2052 | |
2053 return true; | |
2054 } | |
2055 | |
2056 void TextureManager::DumpTextureRef(base::trace_event::ProcessMemoryDump* pmd, | |
2057 TextureRef* ref) { | |
2058 uint32_t size = ref->texture()->estimated_size(); | |
2059 | |
2060 // Ignore unallocated texture IDs. | |
2061 if (size == 0) | |
2062 return; | |
2063 | |
2064 uint64_t tracing_id = memory_tracker_->ClientTracingId(); | |
2065 std::string dump_name = base::StringPrintf( | |
2066 "gl/process_%" PRIx64 "/textures/%d", tracing_id, ref->client_id()); | |
reveman
2015/07/24 21:16:36
s/%" PRIx64 "/%d/
nit: "gl/textures/client_%d/tex
ericrk
2015/07/28 21:02:32
Re-worked this to be consistent with gpu-memory-bu
| |
2067 base::trace_event::MemoryAllocatorDump* dump = | |
2068 pmd->CreateAllocatorDump(dump_name); | |
2069 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | |
2070 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
2071 static_cast<uint64_t>(size)); | |
2072 | |
2073 // Add GUID info for shared ownership with client process. | |
2074 auto guid = base::trace_event::MemoryAllocatorDumpGuid(base::StringPrintf( | |
2075 "gl-x-process/%" PRIx64 "/texture_%d", tracing_id, ref->client_id())); | |
reveman
2015/07/24 21:16:36
Can you move this logic to where it can be shared
ericrk
2015/07/28 21:02:32
Done.
| |
2076 pmd->CreateSharedGlobalAllocatorDump(guid); | |
2077 pmd->AddOwnershipEdge(dump->guid(), guid); | |
2078 } | |
2079 | |
2030 } // namespace gles2 | 2080 } // namespace gles2 |
2031 } // namespace gpu | 2081 } // namespace gpu |
OLD | NEW |