Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
texture.cc
Go to the documentation of this file.
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/common/graphics/texture.h"
6
7namespace flutter {
8
10
12
13Texture::Texture(int64_t id) : id_(id) {}
14
15Texture::~Texture() = default;
16
18
19void TextureRegistry::RegisterTexture(const std::shared_ptr<Texture>& texture) {
20 if (!texture) {
21 return;
22 }
23 mapping_[texture->Id()] = texture;
24}
25
27 uintptr_t id,
28 std::weak_ptr<ContextListener> image) {
29 size_t next_id = image_counter_++;
30 auto const result = image_indices_.insert({id, next_id});
31 if (!result.second) {
32 ordered_images_.erase(result.first->second);
33 result.first->second = next_id;
34 }
35 ordered_images_[next_id] = {next_id, std::move(image)};
36}
37
39 auto found = mapping_.find(id);
40 if (found == mapping_.end()) {
41 return;
42 }
43 found->second->OnTextureUnregistered();
44 mapping_.erase(found);
45}
46
48 ordered_images_.erase(image_indices_[id]);
49 image_indices_.erase(id);
50}
51
53 for (auto& it : mapping_) {
54 it.second->OnGrContextCreated();
55 }
56
57 // Calling OnGrContextCreated may result in a subsequent call to
58 // RegisterContextListener from the listener, which may modify the map.
59 std::vector<InsertionOrderMap::value_type> ordered_images(
60 ordered_images_.begin(), ordered_images_.end());
61
62 for (const auto& [id, pair] : ordered_images) {
63 auto index_id = pair.first;
64 auto weak_image = pair.second;
65 if (auto image = weak_image.lock()) {
66 image->OnGrContextCreated();
67 } else {
68 image_indices_.erase(index_id);
69 ordered_images_.erase(id);
70 }
71 }
72}
73
75 for (auto& it : mapping_) {
76 it.second->OnGrContextDestroyed();
77 }
78
79 auto it = ordered_images_.begin();
80 while (it != ordered_images_.end()) {
81 auto index_id = it->second.first;
82 auto weak_image = it->second.second;
83 if (auto image = weak_image.lock()) {
84 image->OnGrContextDestroyed();
85 it++;
86 } else {
87 image_indices_.erase(index_id);
88 it = ordered_images_.erase(it);
89 }
90 }
91}
92
93std::shared_ptr<Texture> TextureRegistry::GetTexture(int64_t id) {
94 auto it = mapping_.find(id);
95 return it != mapping_.end() ? it->second : nullptr;
96}
97
98} // namespace flutter
static uint32_t next_id()
void RegisterTexture(const std::shared_ptr< Texture > &texture)
Definition texture.cc:19
std::shared_ptr< Texture > GetTexture(int64_t id)
Definition texture.cc:93
void UnregisterTexture(int64_t id)
Definition texture.cc:38
void UnregisterContextListener(uintptr_t id)
Definition texture.cc:47
void RegisterContextListener(uintptr_t id, std::weak_ptr< ContextListener > image)
Definition texture.cc:26
Texture(int64_t id)
Definition texture.cc:13
virtual ~Texture()
sk_sp< SkImage > image
Definition examples.cpp:29
GAsyncResult * result
FlTexture * texture
const uintptr_t id