| 72 | } |
| 73 | |
| 74 | std::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 |
| 110 | static constexpr uint16_t NonAAQuadIndexPattern[] = { |
no test coverage detected