| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <utility> | 12 #include <utility> |
| 13 | 13 |
| 14 #include "base/bits.h" | 14 #include "base/bits.h" |
| 15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
| 16 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "base/thread_task_runner_handle.h" | 18 #include "base/thread_task_runner_handle.h" |
| 19 #include "base/trace_event/memory_dump_manager.h" | 19 #include "base/trace_event/memory_dump_manager.h" |
| 20 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 20 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
| 21 #include "gpu/command_buffer/service/context_state.h" | 21 #include "gpu/command_buffer/service/context_state.h" |
| 22 #include "gpu/command_buffer/service/error_state.h" | 22 #include "gpu/command_buffer/service/error_state.h" |
| 23 #include "gpu/command_buffer/service/feature_info.h" | 23 #include "gpu/command_buffer/service/feature_info.h" |
| 24 #include "gpu/command_buffer/service/framebuffer_manager.h" | 24 #include "gpu/command_buffer/service/framebuffer_manager.h" |
| 25 #include "gpu/command_buffer/service/gl_stream_texture_image.h" |
| 25 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 26 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 26 #include "gpu/command_buffer/service/mailbox_manager.h" | 27 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 27 #include "gpu/command_buffer/service/memory_tracking.h" | 28 #include "gpu/command_buffer/service/memory_tracking.h" |
| 28 #include "ui/gl/gl_context.h" | 29 #include "ui/gl/gl_context.h" |
| 29 #include "ui/gl/gl_implementation.h" | 30 #include "ui/gl/gl_implementation.h" |
| 30 #include "ui/gl/gl_state_restorer.h" | 31 #include "ui/gl/gl_state_restorer.h" |
| 31 #include "ui/gl/gl_version_info.h" | 32 #include "ui/gl/gl_version_info.h" |
| 32 #include "ui/gl/trace_util.h" | 33 #include "ui/gl/trace_util.h" |
| 33 | 34 |
| 34 namespace gpu { | 35 namespace gpu { |
| (...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 } | 905 } |
| 905 | 906 |
| 906 info.target = target; | 907 info.target = target; |
| 907 info.level = level; | 908 info.level = level; |
| 908 info.internal_format = internal_format; | 909 info.internal_format = internal_format; |
| 909 info.depth = depth; | 910 info.depth = depth; |
| 910 info.border = border; | 911 info.border = border; |
| 911 info.format = format; | 912 info.format = format; |
| 912 info.type = type; | 913 info.type = type; |
| 913 info.image = 0; | 914 info.image = 0; |
| 915 info.stream_texture_image = 0; |
| 914 info.image_state = UNBOUND; | 916 info.image_state = UNBOUND; |
| 915 info.internal_workaround = false; | 917 info.internal_workaround = false; |
| 916 | 918 |
| 917 UpdateMipCleared(&info, width, height, cleared_rect); | 919 UpdateMipCleared(&info, width, height, cleared_rect); |
| 918 | 920 |
| 919 estimated_size_ -= info.estimated_size; | 921 estimated_size_ -= info.estimated_size; |
| 920 GLES2Util::ComputeImageDataSizes( | 922 GLES2Util::ComputeImageDataSizes( |
| 921 width, height, depth, format, type, 4, &info.estimated_size, NULL, NULL); | 923 width, height, depth, format, type, 4, &info.estimated_size, NULL, NULL); |
| 922 estimated_size_ += info.estimated_size; | 924 estimated_size_ += info.estimated_size; |
| 923 | 925 |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1340 return false; | 1342 return false; |
| 1341 } | 1343 } |
| 1342 } | 1344 } |
| 1343 } | 1345 } |
| 1344 | 1346 |
| 1345 UpdateMipCleared(&info, info.width, info.height, | 1347 UpdateMipCleared(&info, info.width, info.height, |
| 1346 gfx::Rect(info.width, info.height)); | 1348 gfx::Rect(info.width, info.height)); |
| 1347 return true; | 1349 return true; |
| 1348 } | 1350 } |
| 1349 | 1351 |
| 1350 void Texture::SetLevelImage(GLenum target, | 1352 void Texture::SetLevelImageInternal(GLenum target, |
| 1351 GLint level, | 1353 GLint level, |
| 1352 gl::GLImage* image, | 1354 gl::GLImage* image, |
| 1353 ImageState state) { | 1355 GLStreamTextureImage* stream_texture_image, |
| 1356 ImageState state) { |
| 1354 DCHECK_GE(level, 0); | 1357 DCHECK_GE(level, 0); |
| 1355 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 1358 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
| 1356 DCHECK_LT(static_cast<size_t>(face_index), | 1359 DCHECK_LT(static_cast<size_t>(face_index), |
| 1357 face_infos_.size()); | 1360 face_infos_.size()); |
| 1358 DCHECK_LT(static_cast<size_t>(level), | 1361 DCHECK_LT(static_cast<size_t>(level), |
| 1359 face_infos_[face_index].level_infos.size()); | 1362 face_infos_[face_index].level_infos.size()); |
| 1360 Texture::LevelInfo& info = | 1363 Texture::LevelInfo& info = |
| 1361 face_infos_[face_index].level_infos[level]; | 1364 face_infos_[face_index].level_infos[level]; |
| 1362 DCHECK_EQ(info.target, target); | 1365 DCHECK_EQ(info.target, target); |
| 1363 DCHECK_EQ(info.level, level); | 1366 DCHECK_EQ(info.level, level); |
| 1364 info.image = image; | 1367 info.image = image; |
| 1368 info.stream_texture_image = stream_texture_image; |
| 1365 info.image_state = state; | 1369 info.image_state = state; |
| 1366 | 1370 |
| 1367 UpdateCanRenderCondition(); | 1371 UpdateCanRenderCondition(); |
| 1368 UpdateHasImages(); | 1372 UpdateHasImages(); |
| 1369 } | 1373 } |
| 1370 | 1374 |
| 1371 gl::GLImage* Texture::GetLevelImage(GLint target, | 1375 void Texture::SetLevelImage(GLenum target, |
| 1372 GLint level, | 1376 GLint level, |
| 1373 ImageState* state) const { | 1377 gl::GLImage* image, |
| 1378 ImageState state) { |
| 1379 SetLevelImageInternal(target, level, image, nullptr, state); |
| 1380 } |
| 1381 |
| 1382 void Texture::SetLevelStreamTextureImage(GLenum target, |
| 1383 GLint level, |
| 1384 GLStreamTextureImage* image, |
| 1385 ImageState state) { |
| 1386 SetLevelImageInternal(target, level, image, image, state); |
| 1387 } |
| 1388 |
| 1389 const Texture::LevelInfo* Texture::GetLevelInfo(GLint target, |
| 1390 GLint level) const { |
| 1374 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES && | 1391 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES && |
| 1375 target != GL_TEXTURE_RECTANGLE_ARB) { | 1392 target != GL_TEXTURE_RECTANGLE_ARB) { |
| 1376 return NULL; | 1393 return NULL; |
| 1377 } | 1394 } |
| 1378 | 1395 |
| 1379 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 1396 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
| 1380 if (level >= 0 && face_index < face_infos_.size() && | 1397 if (level >= 0 && face_index < face_infos_.size() && |
| 1381 static_cast<size_t>(level) < face_infos_[face_index].level_infos.size()) { | 1398 static_cast<size_t>(level) < face_infos_[face_index].level_infos.size()) { |
| 1382 const LevelInfo& info = face_infos_[face_index].level_infos[level]; | 1399 const LevelInfo& info = face_infos_[face_index].level_infos[level]; |
| 1383 if (info.target != 0) { | 1400 if (info.target != 0) |
| 1384 if (state) | 1401 return &info; |
| 1385 *state = info.image_state; | |
| 1386 return info.image.get(); | |
| 1387 } | |
| 1388 } | 1402 } |
| 1389 return NULL; | 1403 return NULL; |
| 1390 } | 1404 } |
| 1391 | 1405 |
| 1406 gl::GLImage* Texture::GetLevelImage(GLint target, |
| 1407 GLint level, |
| 1408 ImageState* state) const { |
| 1409 const LevelInfo* info = GetLevelInfo(target, level); |
| 1410 if (!info) |
| 1411 return nullptr; |
| 1412 |
| 1413 if (state) |
| 1414 *state = info->image_state; |
| 1415 return info->image.get(); |
| 1416 } |
| 1417 |
| 1392 gl::GLImage* Texture::GetLevelImage(GLint target, GLint level) const { | 1418 gl::GLImage* Texture::GetLevelImage(GLint target, GLint level) const { |
| 1393 return GetLevelImage(target, level, nullptr); | 1419 return GetLevelImage(target, level, nullptr); |
| 1394 } | 1420 } |
| 1395 | 1421 |
| 1422 GLStreamTextureImage* Texture::GetLevelStreamTextureImage(GLint target, |
| 1423 GLint level) const { |
| 1424 const LevelInfo* info = GetLevelInfo(target, level); |
| 1425 if (!info) |
| 1426 return nullptr; |
| 1427 |
| 1428 return info->stream_texture_image.get(); |
| 1429 } |
| 1430 |
| 1396 void Texture::DumpLevelMemory(base::trace_event::ProcessMemoryDump* pmd, | 1431 void Texture::DumpLevelMemory(base::trace_event::ProcessMemoryDump* pmd, |
| 1397 uint64_t client_tracing_id, | 1432 uint64_t client_tracing_id, |
| 1398 const std::string& dump_name) const { | 1433 const std::string& dump_name) const { |
| 1399 for (uint32_t face_index = 0; face_index < face_infos_.size(); ++face_index) { | 1434 for (uint32_t face_index = 0; face_index < face_infos_.size(); ++face_index) { |
| 1400 const auto& level_infos = face_infos_[face_index].level_infos; | 1435 const auto& level_infos = face_infos_[face_index].level_infos; |
| 1401 for (uint32_t level_index = 0; level_index < level_infos.size(); | 1436 for (uint32_t level_index = 0; level_index < level_infos.size(); |
| 1402 ++level_index) { | 1437 ++level_index) { |
| 1403 // Skip levels with no size. Textures will have empty levels for all | 1438 // Skip levels with no size. Textures will have empty levels for all |
| 1404 // potential mip levels which are not in use. | 1439 // potential mip levels which are not in use. |
| 1405 if (!level_infos[level_index].estimated_size) | 1440 if (!level_infos[level_index].estimated_size) |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1881 | 1916 |
| 1882 void TextureManager::SetLevelImage(TextureRef* ref, | 1917 void TextureManager::SetLevelImage(TextureRef* ref, |
| 1883 GLenum target, | 1918 GLenum target, |
| 1884 GLint level, | 1919 GLint level, |
| 1885 gl::GLImage* image, | 1920 gl::GLImage* image, |
| 1886 Texture::ImageState state) { | 1921 Texture::ImageState state) { |
| 1887 DCHECK(ref); | 1922 DCHECK(ref); |
| 1888 ref->texture()->SetLevelImage(target, level, image, state); | 1923 ref->texture()->SetLevelImage(target, level, image, state); |
| 1889 } | 1924 } |
| 1890 | 1925 |
| 1926 void TextureManager::SetLevelStreamTextureImage(TextureRef* ref, |
| 1927 GLenum target, |
| 1928 GLint level, |
| 1929 GLStreamTextureImage* image, |
| 1930 Texture::ImageState state) { |
| 1931 DCHECK(ref); |
| 1932 ref->texture()->SetLevelStreamTextureImage(target, level, image, state); |
| 1933 } |
| 1934 |
| 1891 size_t TextureManager::GetSignatureSize() const { | 1935 size_t TextureManager::GetSignatureSize() const { |
| 1892 return sizeof(TextureTag) + sizeof(TextureSignature); | 1936 return sizeof(TextureTag) + sizeof(TextureSignature); |
| 1893 } | 1937 } |
| 1894 | 1938 |
| 1895 void TextureManager::AddToSignature( | 1939 void TextureManager::AddToSignature( |
| 1896 TextureRef* ref, | 1940 TextureRef* ref, |
| 1897 GLenum target, | 1941 GLenum target, |
| 1898 GLint level, | 1942 GLint level, |
| 1899 std::string* signature) const { | 1943 std::string* signature) const { |
| 1900 ref->texture()->AddToSignature(feature_info_.get(), target, level, signature); | 1944 ref->texture()->AddToSignature(feature_info_.get(), target, level, signature); |
| (...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2763 uint32_t TextureManager::GetServiceIdGeneration() const { | 2807 uint32_t TextureManager::GetServiceIdGeneration() const { |
| 2764 return current_service_id_generation_; | 2808 return current_service_id_generation_; |
| 2765 } | 2809 } |
| 2766 | 2810 |
| 2767 void TextureManager::IncrementServiceIdGeneration() { | 2811 void TextureManager::IncrementServiceIdGeneration() { |
| 2768 current_service_id_generation_++; | 2812 current_service_id_generation_++; |
| 2769 } | 2813 } |
| 2770 | 2814 |
| 2771 } // namespace gles2 | 2815 } // namespace gles2 |
| 2772 } // namespace gpu | 2816 } // namespace gpu |
| OLD | NEW |