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 | |
7 | namespace flutter { |
8 | |
9 | Texture::Texture(int64_t id) : id_(id) {} |
10 | |
11 | Texture::~Texture() = default; |
12 | |
13 | TextureRegistry::TextureRegistry() = default; |
14 | |
15 | void TextureRegistry::RegisterTexture(std::shared_ptr<Texture> texture) { |
16 | if (!texture) { |
17 | return; |
18 | } |
19 | mapping_[texture->Id()] = texture; |
20 | } |
21 | |
22 | void 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 | |
31 | void TextureRegistry::OnGrContextCreated() { |
32 | for (auto& it : mapping_) { |
33 | it.second->OnGrContextCreated(); |
34 | } |
35 | } |
36 | |
37 | void TextureRegistry::OnGrContextDestroyed() { |
38 | for (auto& it : mapping_) { |
39 | it.second->OnGrContextDestroyed(); |
40 | } |
41 | } |
42 | |
43 | std::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 |