Chromium Code Reviews| 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> |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 21 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
| 22 #include "gpu/command_buffer/service/context_state.h" | 22 #include "gpu/command_buffer/service/context_state.h" |
| 23 #include "gpu/command_buffer/service/error_state.h" | 23 #include "gpu/command_buffer/service/error_state.h" |
| 24 #include "gpu/command_buffer/service/feature_info.h" | 24 #include "gpu/command_buffer/service/feature_info.h" |
| 25 #include "gpu/command_buffer/service/framebuffer_manager.h" | 25 #include "gpu/command_buffer/service/framebuffer_manager.h" |
| 26 #include "gpu/command_buffer/service/gl_stream_texture_image.h" | 26 #include "gpu/command_buffer/service/gl_stream_texture_image.h" |
| 27 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 27 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 28 #include "gpu/command_buffer/service/mailbox_manager.h" | 28 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 29 #include "gpu/command_buffer/service/memory_tracking.h" | 29 #include "gpu/command_buffer/service/memory_tracking.h" |
| 30 #include "gpu/command_buffer/service/progress_reporter.h" | 30 #include "gpu/command_buffer/service/progress_reporter.h" |
| 31 #include "gpu/command_buffer/service/service_discardable_manager.h" | |
| 31 #include "ui/gl/gl_context.h" | 32 #include "ui/gl/gl_context.h" |
| 32 #include "ui/gl/gl_implementation.h" | 33 #include "ui/gl/gl_implementation.h" |
| 33 #include "ui/gl/gl_state_restorer.h" | 34 #include "ui/gl/gl_state_restorer.h" |
| 34 #include "ui/gl/gl_version_info.h" | 35 #include "ui/gl/gl_version_info.h" |
| 35 #include "ui/gl/trace_util.h" | 36 #include "ui/gl/trace_util.h" |
| 36 | 37 |
| 37 using base::trace_event::MemoryAllocatorDump; | 38 using base::trace_event::MemoryAllocatorDump; |
| 38 using base::trace_event::MemoryDumpLevelOfDetail; | 39 using base::trace_event::MemoryDumpLevelOfDetail; |
| 39 | 40 |
| 40 namespace gpu { | 41 namespace gpu { |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 434 DCHECK_EQ(0, num_uncleared_mips_); | 435 DCHECK_EQ(0, num_uncleared_mips_); |
| 435 DCHECK_EQ(0, num_images_); | 436 DCHECK_EQ(0, num_images_); |
| 436 | 437 |
| 437 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | 438 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
| 438 this); | 439 this); |
| 439 } | 440 } |
| 440 | 441 |
| 441 void TextureManager::Destroy(bool have_context) { | 442 void TextureManager::Destroy(bool have_context) { |
| 442 have_context_ = have_context; | 443 have_context_ = have_context; |
| 443 | 444 |
| 445 // Retreive any outstanding unlocked textures from the discardable manager so | |
| 446 // we can clean them up here. | |
| 447 discardable_manager_->OnTextureManagerDestruction(this); | |
| 448 | |
| 444 while (!textures_.empty()) { | 449 while (!textures_.empty()) { |
| 445 textures_.erase(textures_.begin()); | 450 textures_.erase(textures_.begin()); |
| 446 if (progress_reporter_) | 451 if (progress_reporter_) |
| 447 progress_reporter_->ReportProgress(); | 452 progress_reporter_->ReportProgress(); |
| 448 } | 453 } |
| 449 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { | 454 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { |
| 450 default_textures_[ii] = NULL; | 455 default_textures_[ii] = NULL; |
| 451 if (progress_reporter_) | 456 if (progress_reporter_) |
| 452 progress_reporter_->ReportProgress(); | 457 progress_reporter_->ReportProgress(); |
| 453 } | 458 } |
| (...skipping 1429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1883 } | 1888 } |
| 1884 | 1889 |
| 1885 TextureManager::TextureManager(MemoryTracker* memory_tracker, | 1890 TextureManager::TextureManager(MemoryTracker* memory_tracker, |
| 1886 FeatureInfo* feature_info, | 1891 FeatureInfo* feature_info, |
| 1887 GLint max_texture_size, | 1892 GLint max_texture_size, |
| 1888 GLint max_cube_map_texture_size, | 1893 GLint max_cube_map_texture_size, |
| 1889 GLint max_rectangle_texture_size, | 1894 GLint max_rectangle_texture_size, |
| 1890 GLint max_3d_texture_size, | 1895 GLint max_3d_texture_size, |
| 1891 GLint max_array_texture_layers, | 1896 GLint max_array_texture_layers, |
| 1892 bool use_default_textures, | 1897 bool use_default_textures, |
| 1893 ProgressReporter* progress_reporter) | 1898 ProgressReporter* progress_reporter, |
| 1899 ServiceDiscardableManager* discardable_manager) | |
| 1894 : memory_type_tracker_(new MemoryTypeTracker(memory_tracker)), | 1900 : memory_type_tracker_(new MemoryTypeTracker(memory_tracker)), |
| 1895 memory_tracker_(memory_tracker), | 1901 memory_tracker_(memory_tracker), |
| 1896 feature_info_(feature_info), | 1902 feature_info_(feature_info), |
| 1897 framebuffer_manager_(NULL), | 1903 framebuffer_manager_(NULL), |
| 1898 max_texture_size_(max_texture_size), | 1904 max_texture_size_(max_texture_size), |
| 1899 max_cube_map_texture_size_(max_cube_map_texture_size), | 1905 max_cube_map_texture_size_(max_cube_map_texture_size), |
| 1900 max_rectangle_texture_size_(max_rectangle_texture_size), | 1906 max_rectangle_texture_size_(max_rectangle_texture_size), |
| 1901 max_3d_texture_size_(max_3d_texture_size), | 1907 max_3d_texture_size_(max_3d_texture_size), |
| 1902 max_array_texture_layers_(max_array_texture_layers), | 1908 max_array_texture_layers_(max_array_texture_layers), |
| 1903 max_levels_(ComputeMipMapCount(GL_TEXTURE_2D, | 1909 max_levels_(ComputeMipMapCount(GL_TEXTURE_2D, |
| 1904 max_texture_size, | 1910 max_texture_size, |
| 1905 max_texture_size, | 1911 max_texture_size, |
| 1906 0)), | 1912 0)), |
| 1907 max_cube_map_levels_(ComputeMipMapCount(GL_TEXTURE_CUBE_MAP, | 1913 max_cube_map_levels_(ComputeMipMapCount(GL_TEXTURE_CUBE_MAP, |
| 1908 max_cube_map_texture_size, | 1914 max_cube_map_texture_size, |
| 1909 max_cube_map_texture_size, | 1915 max_cube_map_texture_size, |
| 1910 0)), | 1916 0)), |
| 1911 max_3d_levels_(ComputeMipMapCount(GL_TEXTURE_3D, | 1917 max_3d_levels_(ComputeMipMapCount(GL_TEXTURE_3D, |
| 1912 max_3d_texture_size, | 1918 max_3d_texture_size, |
| 1913 max_3d_texture_size, | 1919 max_3d_texture_size, |
| 1914 max_3d_texture_size)), | 1920 max_3d_texture_size)), |
| 1915 use_default_textures_(use_default_textures), | 1921 use_default_textures_(use_default_textures), |
| 1916 num_unsafe_textures_(0), | 1922 num_unsafe_textures_(0), |
| 1917 num_uncleared_mips_(0), | 1923 num_uncleared_mips_(0), |
| 1918 num_images_(0), | 1924 num_images_(0), |
| 1919 texture_count_(0), | 1925 texture_count_(0), |
| 1920 have_context_(true), | 1926 have_context_(true), |
| 1921 current_service_id_generation_(0), | 1927 current_service_id_generation_(0), |
| 1922 progress_reporter_(progress_reporter) { | 1928 progress_reporter_(progress_reporter), |
| 1929 discardable_manager_(discardable_manager) { | |
| 1923 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { | 1930 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { |
| 1924 black_texture_ids_[ii] = 0; | 1931 black_texture_ids_[ii] = 0; |
| 1925 } | 1932 } |
| 1926 } | 1933 } |
| 1927 | 1934 |
| 1928 bool TextureManager::Initialize() { | 1935 bool TextureManager::Initialize() { |
| 1929 // Reset PIXEL_UNPACK_BUFFER to avoid unrelated GL error on some GL drivers. | 1936 // Reset PIXEL_UNPACK_BUFFER to avoid unrelated GL error on some GL drivers. |
| 1930 if (feature_info_->gl_version_info().is_es3_capable) { | 1937 if (feature_info_->gl_version_info().is_es3_capable) { |
| 1931 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); | 1938 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); |
| 1932 } | 1939 } |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2104 GLenum type, | 2111 GLenum type, |
| 2105 const gfx::Rect& cleared_rect) { | 2112 const gfx::Rect& cleared_rect) { |
| 2106 DCHECK(gfx::Rect(width, height).Contains(cleared_rect)); | 2113 DCHECK(gfx::Rect(width, height).Contains(cleared_rect)); |
| 2107 DCHECK(ref); | 2114 DCHECK(ref); |
| 2108 Texture* texture = ref->texture(); | 2115 Texture* texture = ref->texture(); |
| 2109 | 2116 |
| 2110 texture->GetMemTracker()->TrackMemFree(texture->estimated_size()); | 2117 texture->GetMemTracker()->TrackMemFree(texture->estimated_size()); |
| 2111 texture->SetLevelInfo(target, level, internal_format, width, height, depth, | 2118 texture->SetLevelInfo(target, level, internal_format, width, height, depth, |
| 2112 border, format, type, cleared_rect); | 2119 border, format, type, cleared_rect); |
| 2113 texture->GetMemTracker()->TrackMemAlloc(texture->estimated_size()); | 2120 texture->GetMemTracker()->TrackMemAlloc(texture->estimated_size()); |
| 2121 discardable_manager_->OnTextureSizeChanged(ref->client_id(), this, | |
| 2122 texture->estimated_size()); | |
| 2114 } | 2123 } |
| 2115 | 2124 |
| 2116 Texture* TextureManager::Produce(TextureRef* ref) { | 2125 Texture* TextureManager::Produce(TextureRef* ref) { |
| 2117 DCHECK(ref); | 2126 DCHECK(ref); |
| 2118 return ref->texture(); | 2127 return ref->texture(); |
| 2119 } | 2128 } |
| 2120 | 2129 |
| 2121 TextureRef* TextureManager::Consume( | 2130 TextureRef* TextureManager::Consume( |
| 2122 GLuint client_id, | 2131 GLuint client_id, |
| 2123 Texture* texture) { | 2132 Texture* texture) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2197 DCHECK(result.second); | 2206 DCHECK(result.second); |
| 2198 return ref.get(); | 2207 return ref.get(); |
| 2199 } | 2208 } |
| 2200 | 2209 |
| 2201 TextureRef* TextureManager::GetTexture( | 2210 TextureRef* TextureManager::GetTexture( |
| 2202 GLuint client_id) const { | 2211 GLuint client_id) const { |
| 2203 TextureMap::const_iterator it = textures_.find(client_id); | 2212 TextureMap::const_iterator it = textures_.find(client_id); |
| 2204 return it != textures_.end() ? it->second.get() : NULL; | 2213 return it != textures_.end() ? it->second.get() : NULL; |
| 2205 } | 2214 } |
| 2206 | 2215 |
| 2216 scoped_refptr<TextureRef> TextureManager::TakeTexture(GLuint client_id) { | |
| 2217 auto it = textures_.find(client_id); | |
| 2218 if (it == textures_.end()) | |
| 2219 return nullptr; | |
| 2220 | |
| 2221 scoped_refptr<TextureRef> ref = it->second; | |
| 2222 textures_.erase(it); | |
| 2223 return ref; | |
| 2224 } | |
| 2225 | |
| 2226 void TextureManager::ReturnTexture(scoped_refptr<TextureRef> texture_ref) { | |
| 2227 GLuint client_id = texture_ref->client_id(); | |
| 2228 textures_.emplace(client_id, std::move(texture_ref)); | |
| 2229 } | |
| 2230 | |
| 2207 void TextureManager::RemoveTexture(GLuint client_id) { | 2231 void TextureManager::RemoveTexture(GLuint client_id) { |
| 2208 TextureMap::iterator it = textures_.find(client_id); | 2232 TextureMap::iterator it = textures_.find(client_id); |
| 2209 if (it != textures_.end()) { | 2233 if (it != textures_.end()) { |
| 2234 discardable_manager_->OnTextureDeleted(client_id, this); | |
|
ericrk
2017/05/10 21:36:03
Don't love doing this both here and in StopTrackin
| |
| 2210 it->second->reset_client_id(); | 2235 it->second->reset_client_id(); |
| 2211 textures_.erase(it); | 2236 textures_.erase(it); |
| 2212 } | 2237 } |
| 2213 } | 2238 } |
| 2214 | 2239 |
| 2215 void TextureManager::StartTracking(TextureRef* ref) { | 2240 void TextureManager::StartTracking(TextureRef* ref) { |
| 2216 Texture* texture = ref->texture(); | 2241 Texture* texture = ref->texture(); |
| 2217 ++texture_count_; | 2242 ++texture_count_; |
| 2218 num_uncleared_mips_ += texture->num_uncleared_mips(); | 2243 num_uncleared_mips_ += texture->num_uncleared_mips(); |
| 2219 if (!texture->SafeToRenderFrom()) | 2244 if (!texture->SafeToRenderFrom()) |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 2236 if (texture->HasImages()) { | 2261 if (texture->HasImages()) { |
| 2237 DCHECK_NE(0, num_images_); | 2262 DCHECK_NE(0, num_images_); |
| 2238 --num_images_; | 2263 --num_images_; |
| 2239 } | 2264 } |
| 2240 if (!texture->SafeToRenderFrom()) { | 2265 if (!texture->SafeToRenderFrom()) { |
| 2241 DCHECK_NE(0, num_unsafe_textures_); | 2266 DCHECK_NE(0, num_unsafe_textures_); |
| 2242 --num_unsafe_textures_; | 2267 --num_unsafe_textures_; |
| 2243 } | 2268 } |
| 2244 num_uncleared_mips_ -= texture->num_uncleared_mips(); | 2269 num_uncleared_mips_ -= texture->num_uncleared_mips(); |
| 2245 DCHECK_GE(num_uncleared_mips_, 0); | 2270 DCHECK_GE(num_uncleared_mips_, 0); |
| 2271 | |
| 2272 if (ref->client_id()) | |
| 2273 discardable_manager_->OnTextureDeleted(ref->client_id(), this); | |
| 2246 } | 2274 } |
| 2247 | 2275 |
| 2248 MemoryTypeTracker* TextureManager::GetMemTracker() { | 2276 MemoryTypeTracker* TextureManager::GetMemTracker() { |
| 2249 return memory_type_tracker_.get(); | 2277 return memory_type_tracker_.get(); |
| 2250 } | 2278 } |
| 2251 | 2279 |
| 2252 Texture* TextureManager::GetTextureForServiceId(GLuint service_id) const { | 2280 Texture* TextureManager::GetTextureForServiceId(GLuint service_id) const { |
| 2253 // This doesn't need to be fast. It's only used during slow queries. | 2281 // This doesn't need to be fast. It's only used during slow queries. |
| 2254 for (TextureMap::const_iterator it = textures_.begin(); | 2282 for (TextureMap::const_iterator it = textures_.begin(); |
| 2255 it != textures_.end(); ++it) { | 2283 it != textures_.end(); ++it) { |
| (...skipping 1431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3687 uint32_t TextureManager::GetServiceIdGeneration() const { | 3715 uint32_t TextureManager::GetServiceIdGeneration() const { |
| 3688 return current_service_id_generation_; | 3716 return current_service_id_generation_; |
| 3689 } | 3717 } |
| 3690 | 3718 |
| 3691 void TextureManager::IncrementServiceIdGeneration() { | 3719 void TextureManager::IncrementServiceIdGeneration() { |
| 3692 current_service_id_generation_++; | 3720 current_service_id_generation_++; |
| 3693 } | 3721 } |
| 3694 | 3722 |
| 3695 } // namespace gles2 | 3723 } // namespace gles2 |
| 3696 } // namespace gpu | 3724 } // namespace gpu |
| OLD | NEW |