Change signature of GrAtlasGlyphCache::getProxies

Split out of https://skia-review.googlesource.com/c/skia/+/108001 (Fission GrAtlasGlyphCache in two)

TBR=bsalomon@google.com
Change-Id: I573730fdeddf178915eb5f5b8cf59a3ab29e0654
Reviewed-on: https://skia-review.googlesource.com/108441
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2018-02-20 15:18:59 -05:00 committed by Skia Commit-Bot
parent a8c55fa4fe
commit f3690dd416
6 changed files with 31 additions and 25 deletions

View File

@ -340,7 +340,7 @@ public:
/** Get pointer to atlas texture for given mask format. Note that this wraps an
actively mutating texture in an SkImage. This could yield unexpected results
if it gets cached or used more generally. */
sk_sp<SkImage> getFontAtlasImage_ForTesting(GrMaskFormat format, uint32_t index = 0);
sk_sp<SkImage> getFontAtlasImage_ForTesting(GrMaskFormat format, unsigned int index = 0);
GrAuditTrail* getAuditTrail() { return &fAuditTrail; }

View File

@ -39,7 +39,9 @@ SkInternalAtlasTextContext::~SkInternalAtlasTextContext() {
if (fDistanceFieldAtlas.fProxy) {
#ifdef SK_DEBUG
auto atlasGlyphCache = fGrContext->contextPriv().getAtlasGlyphCache();
SkASSERT(1 == atlasGlyphCache->getAtlasPageCount(kA8_GrMaskFormat));
unsigned int numProxies;
atlasGlyphCache->getProxies(kA8_GrMaskFormat, &numProxies);
SkASSERT(1 == numProxies);
#endif
fRenderer->deleteTexture(fDistanceFieldAtlas.fTextureHandle);
}
@ -86,8 +88,10 @@ void SkInternalAtlasTextContext::recordDraw(const void* srcVertexData, int glyph
void SkInternalAtlasTextContext::flush() {
auto* atlasGlyphCache = fGrContext->contextPriv().getAtlasGlyphCache();
if (!fDistanceFieldAtlas.fProxy) {
SkASSERT(1 == atlasGlyphCache->getAtlasPageCount(kA8_GrMaskFormat));
fDistanceFieldAtlas.fProxy = atlasGlyphCache->getProxies(kA8_GrMaskFormat)->get();
unsigned int numProxies;
fDistanceFieldAtlas.fProxy = atlasGlyphCache->getProxies(kA8_GrMaskFormat,
&numProxies)->get();
SkASSERT(1 == numProxies);
fDistanceFieldAtlas.fTextureHandle =
fRenderer->createTexture(SkAtlasTextRenderer::AtlasFormat::kA8,
fDistanceFieldAtlas.fProxy->width(),

View File

@ -218,8 +218,8 @@ void GrAtlasTextOp::onPrepareDraws(Target* target) {
GrMaskFormat maskFormat = this->maskFormat();
uint32_t atlasPageCount = fFontCache->getAtlasPageCount(maskFormat);
const sk_sp<GrTextureProxy>* proxies = fFontCache->getProxies(maskFormat);
unsigned int atlasPageCount;
const sk_sp<GrTextureProxy>* proxies = fFontCache->getProxies(maskFormat, &atlasPageCount);
if (!atlasPageCount || !proxies[0]) {
SkDebugf("Could not allocate backing texture for atlas\n");
return;
@ -305,20 +305,23 @@ void GrAtlasTextOp::onPrepareDraws(Target* target) {
void GrAtlasTextOp::flush(GrMeshDrawOp::Target* target, FlushInfo* flushInfo) const {
GrGeometryProcessor* gp = flushInfo->fGeometryProcessor.get();
GrMaskFormat maskFormat = this->maskFormat();
if (gp->numTextureSamplers() != (int)fFontCache->getAtlasPageCount(maskFormat)) {
unsigned int numProxies;
const sk_sp<GrTextureProxy>* proxies = fFontCache->getProxies(maskFormat, &numProxies);
if (gp->numTextureSamplers() != (int) numProxies) {
// During preparation the number of atlas pages has increased.
// Update the proxies used in the GP to match.
if (this->usesDistanceFields()) {
if (this->isLCD()) {
reinterpret_cast<GrDistanceFieldLCDTextGeoProc*>(gp)->addNewProxies(
fFontCache->getProxies(maskFormat), GrSamplerState::ClampBilerp());
proxies, GrSamplerState::ClampBilerp());
} else {
reinterpret_cast<GrDistanceFieldA8TextGeoProc*>(gp)->addNewProxies(
fFontCache->getProxies(maskFormat), GrSamplerState::ClampBilerp());
proxies, GrSamplerState::ClampBilerp());
}
} else {
reinterpret_cast<GrBitmapTextGeoProc*>(gp)->addNewProxies(
fFontCache->getProxies(maskFormat), GrSamplerState::ClampNearest());
proxies, GrSamplerState::ClampNearest());
}
}
@ -409,7 +412,8 @@ bool GrAtlasTextOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) {
// TODO trying to figure out why lcd is so whack
// (see comments in GrAtlasTextContext::ComputeCanonicalColor)
sk_sp<GrGeometryProcessor> GrAtlasTextOp::setupDfProcessor() const {
const sk_sp<GrTextureProxy>* p = fFontCache->getProxies(this->maskFormat());
unsigned int numProxies;
const sk_sp<GrTextureProxy>* p = fFontCache->getProxies(this->maskFormat(), &numProxies);
bool isLCD = this->isLCD();
SkMatrix localMatrix = SkMatrix::I();

View File

@ -95,8 +95,10 @@ public:
void visitProxies(const VisitProxyFunc& func) const override {
fProcessors.visitProxies(func);
const sk_sp<GrTextureProxy>* proxies = fFontCache->getProxies(this->maskFormat());
for (int i = 0; i < kMaxTextures; ++i) {
unsigned int numProxies;
const sk_sp<GrTextureProxy>* proxies = fFontCache->getProxies(this->maskFormat(),
&numProxies);
for (unsigned int i = 0; i < numProxies; ++i) {
if (proxies[i]) {
func(proxies[i].get());
}
@ -183,8 +185,6 @@ private:
bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override;
static constexpr auto kMaxTextures = 4;
sk_sp<GrGeometryProcessor> setupDfProcessor() const;
SkAutoSTMalloc<kMinGeometryAllocated, Geometry> fGeoData;

View File

@ -130,20 +130,17 @@ public:
// if getProxies returns nullptr, the client must not try to use other functions on the
// GrAtlasGlyphCache which use the atlas. This function *must* be called first, before other
// functions which use the atlas.
const sk_sp<GrTextureProxy>* getProxies(GrMaskFormat format) {
const sk_sp<GrTextureProxy>* getProxies(GrMaskFormat format, unsigned int* numProxies) {
SkASSERT(numProxies);
if (this->initAtlas(format)) {
*numProxies = this->getAtlas(format)->pageCount();
return this->getAtlas(format)->getProxies();
}
*numProxies = 0;
return nullptr;
}
uint32_t getAtlasPageCount(GrMaskFormat format) {
if (this->initAtlas(format)) {
return this->getAtlas(format)->pageCount();
}
return 0;
}
SkScalar getGlyphSizeLimit() const { return fGlyphSizeLimit; }
bool hasGlyph(GrGlyph* glyph) {

View File

@ -150,8 +150,9 @@ void GrContext::printGpuStats() const {
sk_sp<SkImage> GrContext::getFontAtlasImage_ForTesting(GrMaskFormat format, uint32_t index) {
GrAtlasGlyphCache* cache = this->contextPriv().getAtlasGlyphCache();
const sk_sp<GrTextureProxy>* proxies = cache->getProxies(format);
if (index >= cache->getAtlasPageCount(format) || !proxies[index]) {
unsigned int numProxies;
const sk_sp<GrTextureProxy>* proxies = cache->getProxies(format, &numProxies);
if (index >= numProxies || !proxies[index]) {
return nullptr;
}