Chris Yang cc04914ab4 Add onUnregistered callback in 'Texture' and 'FlutterTexture' (flutter/engine#12695)
Texture unregistration is finished on the GPU thread. The FlutterTexture implementation might not know when it is finished which leads to a race condition. Adding this callback so the FlutterTexture is aware of end of the unregistration process.
2019-10-08 12:45:57 -07:00

44 lines
1.0 KiB
C++

// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/flow/texture.h"
namespace flutter {
TextureRegistry::TextureRegistry() = default;
TextureRegistry::~TextureRegistry() = default;
void TextureRegistry::RegisterTexture(std::shared_ptr<Texture> texture) {
mapping_[texture->Id()] = texture;
}
void TextureRegistry::UnregisterTexture(int64_t id) {
mapping_[id]->OnTextureUnregistered();
mapping_.erase(id);
}
void TextureRegistry::OnGrContextCreated() {
for (auto& it : mapping_) {
it.second->OnGrContextCreated();
}
}
void TextureRegistry::OnGrContextDestroyed() {
for (auto& it : mapping_) {
it.second->OnGrContextDestroyed();
}
}
std::shared_ptr<Texture> TextureRegistry::GetTexture(int64_t id) {
auto it = mapping_.find(id);
return it != mapping_.end() ? it->second : nullptr;
}
Texture::Texture(int64_t id) : id_(id) {}
Texture::~Texture() = default;
} // namespace flutter