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 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 DCHECK_EQ(0, num_uncleared_mips_); | 434 DCHECK_EQ(0, num_uncleared_mips_); |
434 DCHECK_EQ(0, num_images_); | 435 DCHECK_EQ(0, num_images_); |
435 | 436 |
436 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | 437 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
437 this); | 438 this); |
438 } | 439 } |
439 | 440 |
440 void TextureManager::Destroy(bool have_context) { | 441 void TextureManager::Destroy(bool have_context) { |
441 have_context_ = have_context; | 442 have_context_ = have_context; |
442 | 443 |
| 444 // Retreive any outstanding unlocked textures from the discardable manager so |
| 445 // we can clean them up here. |
| 446 discardable_manager_->OnTextureManagerDestruction(this); |
| 447 |
443 while (!textures_.empty()) { | 448 while (!textures_.empty()) { |
444 textures_.erase(textures_.begin()); | 449 textures_.erase(textures_.begin()); |
445 if (progress_reporter_) | 450 if (progress_reporter_) |
446 progress_reporter_->ReportProgress(); | 451 progress_reporter_->ReportProgress(); |
447 } | 452 } |
448 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { | 453 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { |
449 default_textures_[ii] = NULL; | 454 default_textures_[ii] = NULL; |
450 if (progress_reporter_) | 455 if (progress_reporter_) |
451 progress_reporter_->ReportProgress(); | 456 progress_reporter_->ReportProgress(); |
452 } | 457 } |
(...skipping 1429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1882 } | 1887 } |
1883 | 1888 |
1884 TextureManager::TextureManager(MemoryTracker* memory_tracker, | 1889 TextureManager::TextureManager(MemoryTracker* memory_tracker, |
1885 FeatureInfo* feature_info, | 1890 FeatureInfo* feature_info, |
1886 GLint max_texture_size, | 1891 GLint max_texture_size, |
1887 GLint max_cube_map_texture_size, | 1892 GLint max_cube_map_texture_size, |
1888 GLint max_rectangle_texture_size, | 1893 GLint max_rectangle_texture_size, |
1889 GLint max_3d_texture_size, | 1894 GLint max_3d_texture_size, |
1890 GLint max_array_texture_layers, | 1895 GLint max_array_texture_layers, |
1891 bool use_default_textures, | 1896 bool use_default_textures, |
1892 ProgressReporter* progress_reporter) | 1897 ProgressReporter* progress_reporter, |
| 1898 ServiceDiscardableManager* discardable_manager) |
1893 : memory_type_tracker_(new MemoryTypeTracker(memory_tracker)), | 1899 : memory_type_tracker_(new MemoryTypeTracker(memory_tracker)), |
1894 memory_tracker_(memory_tracker), | 1900 memory_tracker_(memory_tracker), |
1895 feature_info_(feature_info), | 1901 feature_info_(feature_info), |
1896 max_texture_size_(max_texture_size), | 1902 max_texture_size_(max_texture_size), |
1897 max_cube_map_texture_size_(max_cube_map_texture_size), | 1903 max_cube_map_texture_size_(max_cube_map_texture_size), |
1898 max_rectangle_texture_size_(max_rectangle_texture_size), | 1904 max_rectangle_texture_size_(max_rectangle_texture_size), |
1899 max_3d_texture_size_(max_3d_texture_size), | 1905 max_3d_texture_size_(max_3d_texture_size), |
1900 max_array_texture_layers_(max_array_texture_layers), | 1906 max_array_texture_layers_(max_array_texture_layers), |
1901 max_levels_(ComputeMipMapCount(GL_TEXTURE_2D, | 1907 max_levels_(ComputeMipMapCount(GL_TEXTURE_2D, |
1902 max_texture_size, | 1908 max_texture_size, |
1903 max_texture_size, | 1909 max_texture_size, |
1904 0)), | 1910 0)), |
1905 max_cube_map_levels_(ComputeMipMapCount(GL_TEXTURE_CUBE_MAP, | 1911 max_cube_map_levels_(ComputeMipMapCount(GL_TEXTURE_CUBE_MAP, |
1906 max_cube_map_texture_size, | 1912 max_cube_map_texture_size, |
1907 max_cube_map_texture_size, | 1913 max_cube_map_texture_size, |
1908 0)), | 1914 0)), |
1909 max_3d_levels_(ComputeMipMapCount(GL_TEXTURE_3D, | 1915 max_3d_levels_(ComputeMipMapCount(GL_TEXTURE_3D, |
1910 max_3d_texture_size, | 1916 max_3d_texture_size, |
1911 max_3d_texture_size, | 1917 max_3d_texture_size, |
1912 max_3d_texture_size)), | 1918 max_3d_texture_size)), |
1913 use_default_textures_(use_default_textures), | 1919 use_default_textures_(use_default_textures), |
1914 num_unsafe_textures_(0), | 1920 num_unsafe_textures_(0), |
1915 num_uncleared_mips_(0), | 1921 num_uncleared_mips_(0), |
1916 num_images_(0), | 1922 num_images_(0), |
1917 texture_count_(0), | 1923 texture_count_(0), |
1918 have_context_(true), | 1924 have_context_(true), |
1919 current_service_id_generation_(0), | 1925 current_service_id_generation_(0), |
1920 progress_reporter_(progress_reporter) { | 1926 progress_reporter_(progress_reporter), |
| 1927 discardable_manager_(discardable_manager) { |
1921 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { | 1928 for (int ii = 0; ii < kNumDefaultTextures; ++ii) { |
1922 black_texture_ids_[ii] = 0; | 1929 black_texture_ids_[ii] = 0; |
1923 } | 1930 } |
1924 } | 1931 } |
1925 | 1932 |
1926 void TextureManager::AddFramebufferManager( | 1933 void TextureManager::AddFramebufferManager( |
1927 FramebufferManager* framebuffer_manager) { | 1934 FramebufferManager* framebuffer_manager) { |
1928 framebuffer_managers_.push_back(framebuffer_manager); | 1935 framebuffer_managers_.push_back(framebuffer_manager); |
1929 } | 1936 } |
1930 | 1937 |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2119 GLenum type, | 2126 GLenum type, |
2120 const gfx::Rect& cleared_rect) { | 2127 const gfx::Rect& cleared_rect) { |
2121 DCHECK(gfx::Rect(width, height).Contains(cleared_rect)); | 2128 DCHECK(gfx::Rect(width, height).Contains(cleared_rect)); |
2122 DCHECK(ref); | 2129 DCHECK(ref); |
2123 Texture* texture = ref->texture(); | 2130 Texture* texture = ref->texture(); |
2124 | 2131 |
2125 texture->GetMemTracker()->TrackMemFree(texture->estimated_size()); | 2132 texture->GetMemTracker()->TrackMemFree(texture->estimated_size()); |
2126 texture->SetLevelInfo(target, level, internal_format, width, height, depth, | 2133 texture->SetLevelInfo(target, level, internal_format, width, height, depth, |
2127 border, format, type, cleared_rect); | 2134 border, format, type, cleared_rect); |
2128 texture->GetMemTracker()->TrackMemAlloc(texture->estimated_size()); | 2135 texture->GetMemTracker()->TrackMemAlloc(texture->estimated_size()); |
| 2136 discardable_manager_->OnTextureSizeChanged(ref->client_id(), this, |
| 2137 texture->estimated_size()); |
2129 } | 2138 } |
2130 | 2139 |
2131 Texture* TextureManager::Produce(TextureRef* ref) { | 2140 Texture* TextureManager::Produce(TextureRef* ref) { |
2132 DCHECK(ref); | 2141 DCHECK(ref); |
2133 return ref->texture(); | 2142 return ref->texture(); |
2134 } | 2143 } |
2135 | 2144 |
2136 TextureRef* TextureManager::Consume( | 2145 TextureRef* TextureManager::Consume( |
2137 GLuint client_id, | 2146 GLuint client_id, |
2138 Texture* texture) { | 2147 Texture* texture) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2212 DCHECK(result.second); | 2221 DCHECK(result.second); |
2213 return ref.get(); | 2222 return ref.get(); |
2214 } | 2223 } |
2215 | 2224 |
2216 TextureRef* TextureManager::GetTexture( | 2225 TextureRef* TextureManager::GetTexture( |
2217 GLuint client_id) const { | 2226 GLuint client_id) const { |
2218 TextureMap::const_iterator it = textures_.find(client_id); | 2227 TextureMap::const_iterator it = textures_.find(client_id); |
2219 return it != textures_.end() ? it->second.get() : NULL; | 2228 return it != textures_.end() ? it->second.get() : NULL; |
2220 } | 2229 } |
2221 | 2230 |
| 2231 scoped_refptr<TextureRef> TextureManager::TakeTexture(GLuint client_id) { |
| 2232 auto it = textures_.find(client_id); |
| 2233 if (it == textures_.end()) |
| 2234 return nullptr; |
| 2235 |
| 2236 scoped_refptr<TextureRef> ref = it->second; |
| 2237 textures_.erase(it); |
| 2238 return ref; |
| 2239 } |
| 2240 |
| 2241 void TextureManager::ReturnTexture(scoped_refptr<TextureRef> texture_ref) { |
| 2242 GLuint client_id = texture_ref->client_id(); |
| 2243 // If we've generated a replacement texture due to "bind generates resource", |
| 2244 // behavior, just delete the resource being returned. |
| 2245 TextureMap::iterator it = textures_.find(client_id); |
| 2246 if (it != textures_.end()) { |
| 2247 // Reset the client id so it doesn't interfere with the generated resource. |
| 2248 texture_ref->reset_client_id(); |
| 2249 return; |
| 2250 } |
| 2251 |
| 2252 textures_.emplace(client_id, std::move(texture_ref)); |
| 2253 } |
| 2254 |
2222 void TextureManager::RemoveTexture(GLuint client_id) { | 2255 void TextureManager::RemoveTexture(GLuint client_id) { |
2223 TextureMap::iterator it = textures_.find(client_id); | 2256 TextureMap::iterator it = textures_.find(client_id); |
2224 if (it != textures_.end()) { | 2257 if (it != textures_.end()) { |
| 2258 discardable_manager_->OnTextureDeleted(client_id, this); |
2225 it->second->reset_client_id(); | 2259 it->second->reset_client_id(); |
2226 textures_.erase(it); | 2260 textures_.erase(it); |
2227 } | 2261 } |
2228 } | 2262 } |
2229 | 2263 |
2230 void TextureManager::StartTracking(TextureRef* ref) { | 2264 void TextureManager::StartTracking(TextureRef* ref) { |
2231 Texture* texture = ref->texture(); | 2265 Texture* texture = ref->texture(); |
2232 ++texture_count_; | 2266 ++texture_count_; |
2233 num_uncleared_mips_ += texture->num_uncleared_mips(); | 2267 num_uncleared_mips_ += texture->num_uncleared_mips(); |
2234 if (!texture->SafeToRenderFrom()) | 2268 if (!texture->SafeToRenderFrom()) |
(...skipping 16 matching lines...) Expand all Loading... |
2251 if (texture->HasImages()) { | 2285 if (texture->HasImages()) { |
2252 DCHECK_NE(0, num_images_); | 2286 DCHECK_NE(0, num_images_); |
2253 --num_images_; | 2287 --num_images_; |
2254 } | 2288 } |
2255 if (!texture->SafeToRenderFrom()) { | 2289 if (!texture->SafeToRenderFrom()) { |
2256 DCHECK_NE(0, num_unsafe_textures_); | 2290 DCHECK_NE(0, num_unsafe_textures_); |
2257 --num_unsafe_textures_; | 2291 --num_unsafe_textures_; |
2258 } | 2292 } |
2259 num_uncleared_mips_ -= texture->num_uncleared_mips(); | 2293 num_uncleared_mips_ -= texture->num_uncleared_mips(); |
2260 DCHECK_GE(num_uncleared_mips_, 0); | 2294 DCHECK_GE(num_uncleared_mips_, 0); |
| 2295 |
| 2296 if (ref->client_id()) |
| 2297 discardable_manager_->OnTextureDeleted(ref->client_id(), this); |
2261 } | 2298 } |
2262 | 2299 |
2263 MemoryTypeTracker* TextureManager::GetMemTracker() { | 2300 MemoryTypeTracker* TextureManager::GetMemTracker() { |
2264 return memory_type_tracker_.get(); | 2301 return memory_type_tracker_.get(); |
2265 } | 2302 } |
2266 | 2303 |
2267 Texture* TextureManager::GetTextureForServiceId(GLuint service_id) const { | 2304 Texture* TextureManager::GetTextureForServiceId(GLuint service_id) const { |
2268 // This doesn't need to be fast. It's only used during slow queries. | 2305 // This doesn't need to be fast. It's only used during slow queries. |
2269 for (TextureMap::const_iterator it = textures_.begin(); | 2306 for (TextureMap::const_iterator it = textures_.begin(); |
2270 it != textures_.end(); ++it) { | 2307 it != textures_.end(); ++it) { |
(...skipping 1430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3701 uint32_t TextureManager::GetServiceIdGeneration() const { | 3738 uint32_t TextureManager::GetServiceIdGeneration() const { |
3702 return current_service_id_generation_; | 3739 return current_service_id_generation_; |
3703 } | 3740 } |
3704 | 3741 |
3705 void TextureManager::IncrementServiceIdGeneration() { | 3742 void TextureManager::IncrementServiceIdGeneration() { |
3706 current_service_id_generation_++; | 3743 current_service_id_generation_++; |
3707 } | 3744 } |
3708 | 3745 |
3709 } // namespace gles2 | 3746 } // namespace gles2 |
3710 } // namespace gpu | 3747 } // namespace gpu |
OLD | NEW |