MCPcopy Create free account
hub / github.com/Tencent/tgfx / getGradient

Method getGradient

src/gpu/GlobalCache.cpp:74–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72}
73
74std::shared_ptr<TextureProxy> GlobalCache::getGradient(const Color* colors, const float* positions,
75 int count) {
76 BytesKey bytesKey = {};
77 for (int i = 0; i < count; ++i) {
78 bytesKey.write(colors[i].red);
79 bytesKey.write(colors[i].green);
80 bytesKey.write(colors[i].blue);
81 bytesKey.write(colors[i].alpha);
82 bytesKey.write(positions[i]);
83 }
84 auto result = gradientTextures.find(bytesKey);
85 if (result != gradientTextures.end()) {
86 auto& texture = result->second;
87 gradientLRU.erase(texture->cachedPosition);
88 gradientLRU.push_front(texture.get());
89 texture->cachedPosition = gradientLRU.begin();
90 return texture->textureProxy;
91 }
92 auto generator = std::make_shared<GradientGenerator>(colors, positions, count);
93 auto textureProxy = context->proxyProvider()->createTextureProxy(std::move(generator));
94 if (textureProxy == nullptr) {
95 return nullptr;
96 }
97 auto gradientTexture = std::make_unique<GradientTexture>(textureProxy, bytesKey);
98 gradientLRU.push_front(gradientTexture.get());
99 gradientTexture->cachedPosition = gradientLRU.begin();
100 gradientTextures[bytesKey] = std::move(gradientTexture);
101 while (gradientLRU.size() > MaxNumCachedGradientBitmaps) {
102 auto texture = gradientLRU.back();
103 gradientLRU.pop_back();
104 gradientTextures.erase(texture->gradientKey);
105 }
106 return textureProxy;
107}
108
109// clang-format off
110static constexpr uint16_t NonAAQuadIndexPattern[] = {

Callers 1

MakeColorizerFunction · 0.80

Calls 8

createTextureProxyMethod · 0.80
writeMethod · 0.45
findMethod · 0.45
endMethod · 0.45
getMethod · 0.45
beginMethod · 0.45
proxyProviderMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected