1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "flutter/flow/texture.h"
6
7namespace flutter {
8
9Texture::Texture(int64_t id) : id_(id) {}
10
11Texture::~Texture() = default;
12
13TextureRegistry::TextureRegistry() = default;
14
15void TextureRegistry::RegisterTexture(std::shared_ptr<Texture> texture) {
16 if (!texture) {
17 return;
18 }
19 mapping_[texture->Id()] = texture;
20}
21
22void TextureRegistry::UnregisterTexture(int64_t id) {
23 auto found = mapping_.find(id);
24 if (found == mapping_.end()) {
25 return;
26 }
27 found->second->OnTextureUnregistered();
28 mapping_.erase(found);
29}
30
31void TextureRegistry::OnGrContextCreated() {
32 for (auto& it : mapping_) {
33 it.second->OnGrContextCreated();
34 }
35}
36
37void TextureRegistry::OnGrContextDestroyed() {
38 for (auto& it : mapping_) {
39 it.second->OnGrContextDestroyed();
40 }
41}
42
43std::shared_ptr<Texture> TextureRegistry::GetTexture(int64_t id) {
44 auto it = mapping_.find(id);
45 return it != mapping_.end() ? it->second : nullptr;
46}
47
48} // namespace flutter
49