Have GrGlyphCache and GrAtlasManager compute the atlas limits independently
DDL contexts will have a GrGlyphCache but not a GrAtlasManager. This CL
disentangles the computation of the atlas limits so the GrGlyphCache
can function independently.
Change-Id: Ia698c7d1ec625d1a0d1f0b5521b56731cfeafde9
Reviewed-on: https://skia-review.googlesource.com/112708
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
diff --git a/src/gpu/text/GrAtlasManager.cpp b/src/gpu/text/GrAtlasManager.cpp
index b688c1c..208e707 100644
--- a/src/gpu/text/GrAtlasManager.cpp
+++ b/src/gpu/text/GrAtlasManager.cpp
@@ -12,28 +12,42 @@
#include "GrGlyphCache.h"
#include "GrProxyProvider.h"
+
+void GrRestrictedAtlasManager::ComputeAtlasLimits(const GrCaps* caps, float maxTextureBytes,
+ int* maxDim, int* minDim,
+ int* maxPlot, int* minPlot) {
+ SkASSERT(maxDim && minDim && maxPlot && minPlot);
+
+ // Calculate RGBA size. Must be between 512 x 256 and MaxTextureSize x MaxTextureSize / 2
+ int log2MaxTextureSize = SkPrevLog2(caps->maxTextureSize());
+ int log2MaxDim = 9;
+ for (; log2MaxDim <= log2MaxTextureSize; ++log2MaxDim) {
+ int maxDimTmp = 1 << log2MaxDim;
+ int minDimTmp = 1 << (log2MaxDim - 1);
+
+ if (maxDimTmp * minDimTmp * 4 >= maxTextureBytes) {
+ break;
+ }
+ }
+
+
+ int log2MinDim = log2MaxDim - 1;
+ *maxDim = 1 << log2MaxDim;
+ *minDim = 1 << log2MinDim;
+ // Plots are either 256 or 512.
+ *maxPlot = SkTMin(512, SkTMax(256, 1 << (log2MaxDim - 2)));
+ *minPlot = SkTMin(512, SkTMax(256, 1 << (log2MaxDim - 3)));
+}
+
GrRestrictedAtlasManager::GrRestrictedAtlasManager(
sk_sp<const GrCaps> caps,
float maxTextureBytes,
GrDrawOpAtlas::AllowMultitexturing allowMultitexturing)
: fCaps(std::move(caps))
, fAllowMultitexturing(allowMultitexturing) {
- // Calculate RGBA size. Must be between 512 x 256 and MaxTextureSize x MaxTextureSize / 2
- int log2MaxTextureSize = SkPrevLog2(fCaps->maxTextureSize());
- int log2MaxDim = 9;
- for (; log2MaxDim <= log2MaxTextureSize; ++log2MaxDim) {
- int maxDim = 1 << log2MaxDim;
- int minDim = 1 << (log2MaxDim - 1);
- if (maxDim * minDim * 4 >= maxTextureBytes) break;
- }
-
- int log2MinDim = log2MaxDim - 1;
- int maxDim = 1 << log2MaxDim;
- int minDim = 1 << log2MinDim;
- // Plots are either 256 or 512.
- int maxPlot = SkTMin(512, SkTMax(256, 1 << (log2MaxDim - 2)));
- int minPlot = SkTMin(512, SkTMax(256, 1 << (log2MaxDim - 3)));
+ int maxDim, minDim, maxPlot, minPlot;
+ ComputeAtlasLimits(fCaps.get(), maxTextureBytes, &maxDim, &minDim, &maxPlot, &minPlot);
// Setup default atlas configs. The A8 atlas uses maxDim for both width and height, as the A8
// format is already very compact.