aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/text
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2018-02-23 12:09:22 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-02-26 14:56:17 +0000
commit96165ebeaa36a2aae0eedaf12d81f53d3caf999a (patch)
treef40174bb314aa1e17dea2c62af7851a2e2a59a57 /src/gpu/text
parent08c96b830ee9a94ededc5129d66148fb404c83f4 (diff)
Separate creation time & flush time behavior in GrDrawOpAtlas (take 2)
This CL clarifies what is going on in the GrDrawOpAtlas and GrAtlasGlyphCache. For the GrDrawOpAtlas: At creation time all the allowed pages are created (with their backing GrTextureProxies) but they aren't instantiated. The GrDrawOpAtlas::instantiate call is called in preFlushCB and allocates any pages known to be needed at the start of flush GrDrawOpAtlas::addToAtlas is called at flush time and, if a new page is activated, will instantiated it at that time. During compaction, an unused page will be deInstantiated but its Plots and backing GrTextureProxy will remain alive. The GrAtlasGlyphCache reflects the changes to the GrDrawOpAtlas It now carries a GrProxyProvider for when it needs to create an atlas It passes in a GrResourceProvider* at flush time to allow instantiation. It does not, yet, allocate that GrDrawOpAtlases it might ever require. Change-Id: Ie9b64b13e261b01ee14be09fbf7e17841b7781dc Reviewed-on: https://skia-review.googlesource.com/109749 Reviewed-by: Jim Van Verth <jvanverth@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/gpu/text')
-rw-r--r--src/gpu/text/GrAtlasGlyphCache.cpp27
-rw-r--r--src/gpu/text/GrAtlasGlyphCache.h24
-rw-r--r--src/gpu/text/GrAtlasTextBlob.h7
-rw-r--r--src/gpu/text/GrAtlasTextBlobVertexRegenerator.cpp10
4 files changed, 38 insertions, 30 deletions
diff --git a/src/gpu/text/GrAtlasGlyphCache.cpp b/src/gpu/text/GrAtlasGlyphCache.cpp
index fb52250781..f7b1e1269a 100644
--- a/src/gpu/text/GrAtlasGlyphCache.cpp
+++ b/src/gpu/text/GrAtlasGlyphCache.cpp
@@ -9,6 +9,7 @@
#include "GrContext.h"
#include "GrDistanceFieldGenFromVector.h"
#include "GrGpu.h"
+#include "GrProxyProvider.h"
#include "GrRectanizer.h"
#include "SkAutoMalloc.h"
@@ -19,14 +20,14 @@
bool GrAtlasGlyphCache::initAtlas(GrMaskFormat format) {
int index = MaskFormatToAtlasIndex(format);
if (!fAtlases[index]) {
- GrPixelConfig config = MaskFormatToPixelConfig(format, *fContext->caps());
+ GrPixelConfig config = MaskFormatToPixelConfig(format, *fProxyProvider->caps());
int width = fAtlasConfigs[index].fWidth;
int height = fAtlasConfigs[index].fHeight;
int numPlotsX = fAtlasConfigs[index].numPlotsX();
int numPlotsY = fAtlasConfigs[index].numPlotsY();
- fAtlases[index] = GrDrawOpAtlas::Make(fContext, config, width, height, numPlotsX, numPlotsY,
- fAllowMultitexturing,
+ fAtlases[index] = GrDrawOpAtlas::Make(fProxyProvider, config, width, height,
+ numPlotsX, numPlotsY, fAllowMultitexturing,
&GrAtlasGlyphCache::HandleEviction, (void*)this);
if (!fAtlases[index]) {
return false;
@@ -35,11 +36,13 @@ bool GrAtlasGlyphCache::initAtlas(GrMaskFormat format) {
return true;
}
-GrAtlasGlyphCache::GrAtlasGlyphCache(GrContext* context, float maxTextureBytes,
+GrAtlasGlyphCache::GrAtlasGlyphCache(GrProxyProvider* proxyProvider, float maxTextureBytes,
GrDrawOpAtlas::AllowMultitexturing allowMultitexturing)
- : fContext(context), fAllowMultitexturing(allowMultitexturing), fPreserveStrike(nullptr) {
+ : fProxyProvider(proxyProvider)
+ , fAllowMultitexturing(allowMultitexturing)
+ , fPreserveStrike(nullptr) {
// Calculate RGBA size. Must be between 512 x 256 and MaxTextureSize x MaxTextureSize / 2
- int log2MaxTextureSize = SkPrevLog2(context->caps()->maxTextureSize());
+ int log2MaxTextureSize = SkPrevLog2(fProxyProvider->caps()->maxTextureSize());
int log2MaxDim = 9;
for (; log2MaxDim <= log2MaxTextureSize; ++log2MaxDim) {
int maxDim = 1 << log2MaxDim;
@@ -174,12 +177,12 @@ static bool save_pixels(GrContext* context, GrSurfaceProxy* sProxy, const char*
return true;
}
-void GrAtlasGlyphCache::dump() const {
+void GrAtlasGlyphCache::dump(GrContext* context) const {
static int gDumpCount = 0;
for (int i = 0; i < kMaskFormatCount; ++i) {
if (fAtlases[i]) {
const sk_sp<GrTextureProxy>* proxies = fAtlases[i]->getProxies();
- for (uint32_t pageIdx = 0; pageIdx < fAtlases[i]->pageCount(); ++pageIdx) {
+ for (uint32_t pageIdx = 0; pageIdx < fAtlases[i]->numActivePages(); ++pageIdx) {
SkASSERT(proxies[pageIdx]);
SkString filename;
#ifdef SK_BUILD_FOR_ANDROID
@@ -188,7 +191,7 @@ void GrAtlasGlyphCache::dump() const {
filename.printf("fontcache_%d%d%d.png", gDumpCount, i, pageIdx);
#endif
- save_pixels(fContext, proxies[pageIdx].get(), filename.c_str());
+ save_pixels(context, proxies[pageIdx].get(), filename.c_str());
}
}
}
@@ -445,7 +448,8 @@ void GrAtlasTextStrike::removeID(GrDrawOpAtlas::AtlasID id) {
}
}
-bool GrAtlasTextStrike::addGlyphToAtlas(GrDeferredUploadTarget* target,
+bool GrAtlasTextStrike::addGlyphToAtlas(GrResourceProvider* resourceProvider,
+ GrDeferredUploadTarget* target,
GrAtlasGlyphCache* atlasGlyphCache,
GrGlyph* glyph,
SkGlyphCache* cache,
@@ -473,7 +477,8 @@ bool GrAtlasTextStrike::addGlyphToAtlas(GrDeferredUploadTarget* target,
}
}
- bool success = atlasGlyphCache->addToAtlas(this, &glyph->fID, target, expectedMaskFormat,
+ bool success = atlasGlyphCache->addToAtlas(resourceProvider, this, &glyph->fID, target,
+ expectedMaskFormat,
glyph->width(), glyph->height(),
storage.get(), &glyph->fAtlasLocation);
if (success) {
diff --git a/src/gpu/text/GrAtlasGlyphCache.h b/src/gpu/text/GrAtlasGlyphCache.h
index 6175342c26..84b7d1b249 100644
--- a/src/gpu/text/GrAtlasGlyphCache.h
+++ b/src/gpu/text/GrAtlasGlyphCache.h
@@ -64,8 +64,8 @@ public:
// happen.
// TODO we can handle some of these cases if we really want to, but the long term solution is to
// get the actual glyph image itself when we get the glyph metrics.
- bool addGlyphToAtlas(GrDeferredUploadTarget*, GrAtlasGlyphCache*, GrGlyph*, SkGlyphCache*,
- GrMaskFormat expectedMaskFormat);
+ bool addGlyphToAtlas(GrResourceProvider*, GrDeferredUploadTarget*, GrAtlasGlyphCache*, GrGlyph*,
+ SkGlyphCache*, GrMaskFormat expectedMaskFormat);
// testing
int countGlyphs() const { return fCache.count(); }
@@ -109,7 +109,8 @@ private:
*/
class GrAtlasGlyphCache : public GrOnFlushCallbackObject {
public:
- GrAtlasGlyphCache(GrContext*, float maxTextureBytes, GrDrawOpAtlas::AllowMultitexturing);
+ GrAtlasGlyphCache(GrProxyProvider*, float maxTextureBytes,
+ GrDrawOpAtlas::AllowMultitexturing);
~GrAtlasGlyphCache() override;
// The user of the cache may hold a long-lived ref to the returned strike. However, actions by
// another client of the cache may cause the strike to be purged while it is still reffed.
@@ -132,7 +133,7 @@ public:
SkASSERT(numProxies);
if (this->initAtlas(format)) {
- *numProxies = this->getAtlas(format)->pageCount();
+ *numProxies = this->getAtlas(format)->numActivePages();
return this->getAtlas(format)->getProxies();
}
*numProxies = 0;
@@ -165,11 +166,13 @@ public:
}
// add to texture atlas that matches this format
- bool addToAtlas(GrAtlasTextStrike* strike, GrDrawOpAtlas::AtlasID* id,
+ bool addToAtlas(GrResourceProvider* resourceProvider, GrAtlasTextStrike* strike,
+ GrDrawOpAtlas::AtlasID* id,
GrDeferredUploadTarget* target, GrMaskFormat format, int width, int height,
const void* image, SkIPoint16* loc) {
fPreserveStrike = strike;
- return this->getAtlas(format)->addToAtlas(id, target, width, height, image, loc);
+ return this->getAtlas(format)->addToAtlas(resourceProvider, id, target,
+ width, height, image, loc);
}
// Some clients may wish to verify the integrity of the texture backing store of the
@@ -190,8 +193,7 @@ public:
}
}
- void postFlush(GrDeferredUploadToken startTokenForNextFlush,
- const uint32_t* opListIDs, int numOpListIDs) override {
+ void postFlush(GrDeferredUploadToken startTokenForNextFlush, const uint32_t*, int) override {
for (int i = 0; i < kMaskFormatCount; ++i) {
if (fAtlases[i]) {
fAtlases[i]->compact(startTokenForNextFlush);
@@ -206,13 +208,11 @@ public:
///////////////////////////////////////////////////////////////////////////
// Functions intended debug only
#ifdef SK_DEBUG
- void dump() const;
+ void dump(GrContext*) const;
#endif
void setAtlasSizes_ForTesting(const GrDrawOpAtlasConfig configs[3]);
- GrContext* context() const { return fContext; }
-
private:
static GrPixelConfig MaskFormatToPixelConfig(GrMaskFormat format, const GrCaps& caps) {
switch (format) {
@@ -258,7 +258,7 @@ private:
static void HandleEviction(GrDrawOpAtlas::AtlasID, void*);
using StrikeHash = SkTDynamicHash<GrAtlasTextStrike, SkDescriptor>;
- GrContext* fContext;
+ GrProxyProvider* fProxyProvider;
StrikeHash fCache;
GrDrawOpAtlas::AllowMultitexturing fAllowMultitexturing;
std::unique_ptr<GrDrawOpAtlas> fAtlases[kMaskFormatCount];
diff --git a/src/gpu/text/GrAtlasTextBlob.h b/src/gpu/text/GrAtlasTextBlob.h
index 6e1d0b1bde..0fae3cd8c7 100644
--- a/src/gpu/text/GrAtlasTextBlob.h
+++ b/src/gpu/text/GrAtlasTextBlob.h
@@ -560,9 +560,9 @@ public:
* SkAutoGlyphCache is reused then it can save the cost of multiple detach/attach operations of
* SkGlyphCache.
*/
- VertexRegenerator(GrAtlasTextBlob* blob, int runIdx, int subRunIdx, const SkMatrix& viewMatrix,
- SkScalar x, SkScalar y, GrColor color, GrDeferredUploadTarget*,
- GrAtlasGlyphCache*, SkAutoGlyphCache*);
+ VertexRegenerator(GrResourceProvider*, GrAtlasTextBlob*, int runIdx, int subRunIdx,
+ const SkMatrix& viewMatrix, SkScalar x, SkScalar y, GrColor color,
+ GrDeferredUploadTarget*, GrAtlasGlyphCache*, SkAutoGlyphCache*);
struct Result {
/**
@@ -589,6 +589,7 @@ private:
template <bool regenPos, bool regenCol, bool regenTexCoords, bool regenGlyphs>
Result doRegen();
+ GrResourceProvider* fResourceProvider;
const SkMatrix& fViewMatrix;
GrAtlasTextBlob* fBlob;
GrDeferredUploadTarget* fUploadTarget;
diff --git a/src/gpu/text/GrAtlasTextBlobVertexRegenerator.cpp b/src/gpu/text/GrAtlasTextBlobVertexRegenerator.cpp
index 1a9c3d73e4..500ae31703 100644
--- a/src/gpu/text/GrAtlasTextBlobVertexRegenerator.cpp
+++ b/src/gpu/text/GrAtlasTextBlobVertexRegenerator.cpp
@@ -190,11 +190,13 @@ inline void regen_vertices(char* vertex, const GrGlyph* glyph, size_t vertexStri
}
}
-Regenerator::VertexRegenerator(GrAtlasTextBlob* blob, int runIdx, int subRunIdx,
+Regenerator::VertexRegenerator(GrResourceProvider* resourceProvider, GrAtlasTextBlob* blob,
+ int runIdx, int subRunIdx,
const SkMatrix& viewMatrix, SkScalar x, SkScalar y, GrColor color,
GrDeferredUploadTarget* uploadTarget, GrAtlasGlyphCache* glyphCache,
SkAutoGlyphCache* lazyCache)
- : fViewMatrix(viewMatrix)
+ : fResourceProvider(resourceProvider)
+ , fViewMatrix(viewMatrix)
, fBlob(blob)
, fUploadTarget(uploadTarget)
, fGlyphCache(glyphCache)
@@ -274,8 +276,8 @@ Regenerator::Result Regenerator::doRegen() {
SkASSERT(glyph && glyph->fMaskFormat == fSubRun->maskFormat());
if (!fGlyphCache->hasGlyph(glyph) &&
- !strike->addGlyphToAtlas(fUploadTarget, fGlyphCache, glyph, fLazyCache->get(),
- fSubRun->maskFormat())) {
+ !strike->addGlyphToAtlas(fResourceProvider, fUploadTarget, fGlyphCache, glyph,
+ fLazyCache->get(), fSubRun->maskFormat())) {
fBrokenRun = glyphIdx > 0;
result.fFinished = false;
return result;