Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Unified Diff: gpu/command_buffer/service/texture_manager.cc

Issue 2814583002: Service/ClientDiscardableManager (Closed)
Patch Set: feeedback Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: gpu/command_buffer/service/texture_manager.cc
diff --git a/gpu/command_buffer/service/texture_manager.cc b/gpu/command_buffer/service/texture_manager.cc
index b4fa9fc48bcd7a14fcbc495f263f0eef5a450311..34b955aa670b8a5f10d5fb5a180c2691e16727af 100644
--- a/gpu/command_buffer/service/texture_manager.cc
+++ b/gpu/command_buffer/service/texture_manager.cc
@@ -28,6 +28,7 @@
#include "gpu/command_buffer/service/mailbox_manager.h"
#include "gpu/command_buffer/service/memory_tracking.h"
#include "gpu/command_buffer/service/progress_reporter.h"
+#include "gpu/command_buffer/service/service_discardable_manager.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_state_restorer.h"
@@ -441,6 +442,10 @@ TextureManager::~TextureManager() {
void TextureManager::Destroy(bool have_context) {
have_context_ = have_context;
+ // Retreive any outstanding unlocked textures from the discardable manager so
+ // we can clean them up here.
+ discardable_manager_->OnTextureManagerDestruction(this);
+
while (!textures_.empty()) {
textures_.erase(textures_.begin());
if (progress_reporter_)
@@ -1890,7 +1895,8 @@ TextureManager::TextureManager(MemoryTracker* memory_tracker,
GLint max_3d_texture_size,
GLint max_array_texture_layers,
bool use_default_textures,
- ProgressReporter* progress_reporter)
+ ProgressReporter* progress_reporter,
+ ServiceDiscardableManager* discardable_manager)
: memory_type_tracker_(new MemoryTypeTracker(memory_tracker)),
memory_tracker_(memory_tracker),
feature_info_(feature_info),
@@ -1919,7 +1925,8 @@ TextureManager::TextureManager(MemoryTracker* memory_tracker,
texture_count_(0),
have_context_(true),
current_service_id_generation_(0),
- progress_reporter_(progress_reporter) {
+ progress_reporter_(progress_reporter),
+ discardable_manager_(discardable_manager) {
for (int ii = 0; ii < kNumDefaultTextures; ++ii) {
black_texture_ids_[ii] = 0;
}
@@ -2111,6 +2118,8 @@ void TextureManager::SetLevelInfo(TextureRef* ref,
texture->SetLevelInfo(target, level, internal_format, width, height, depth,
border, format, type, cleared_rect);
texture->GetMemTracker()->TrackMemAlloc(texture->estimated_size());
+ discardable_manager_->OnTextureSizeChanged(ref->client_id(), this,
+ texture->estimated_size());
}
Texture* TextureManager::Produce(TextureRef* ref) {
@@ -2204,9 +2213,25 @@ TextureRef* TextureManager::GetTexture(
return it != textures_.end() ? it->second.get() : NULL;
}
+scoped_refptr<TextureRef> TextureManager::TakeTexture(GLuint client_id) {
+ auto it = textures_.find(client_id);
+ if (it == textures_.end())
+ return nullptr;
+
+ scoped_refptr<TextureRef> ref = it->second;
+ textures_.erase(it);
+ return ref;
+}
+
+void TextureManager::ReturnTexture(scoped_refptr<TextureRef> texture_ref) {
+ GLuint client_id = texture_ref->client_id();
+ textures_.emplace(client_id, std::move(texture_ref));
+}
+
void TextureManager::RemoveTexture(GLuint client_id) {
TextureMap::iterator it = textures_.find(client_id);
if (it != textures_.end()) {
+ discardable_manager_->OnTextureDeleted(client_id, this);
ericrk 2017/05/10 21:36:03 Don't love doing this both here and in StopTrackin
it->second->reset_client_id();
textures_.erase(it);
}
@@ -2243,6 +2268,9 @@ void TextureManager::StopTracking(TextureRef* ref) {
}
num_uncleared_mips_ -= texture->num_uncleared_mips();
DCHECK_GE(num_uncleared_mips_, 0);
+
+ if (ref->client_id())
+ discardable_manager_->OnTextureDeleted(ref->client_id(), this);
}
MemoryTypeTracker* TextureManager::GetMemTracker() {

Powered by Google App Engine
This is Rietveld 408576698