aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Jim Van Verth <jvanverth@google.com>2018-05-16 14:54:41 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-05-16 19:28:32 +0000
commitcbeae03caee3b6c26c22f5f24c817521c78f8e43 (patch)
treebc24b50ca9e52de8fc783e087656027af1db53ce
parentaf0f79c286ac955a94b2a0834099f3abd61584b5 (diff)
Fix check for valid proxies returned by AtlasManager.
Also renames a lot of variables to make it clearer that getProxies() returns the number of instantiated proxies, not the number of all proxies. Bug: skia: Change-Id: Ifbc910cbd6635dccdb4e7f0df2e69a0f341130af Reviewed-on: https://skia-review.googlesource.com/128660 Commit-Queue: Jim Van Verth <jvanverth@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
-rw-r--r--src/gpu/effects/GrBitmapTextGeoProc.cpp12
-rw-r--r--src/gpu/effects/GrBitmapTextGeoProc.h6
-rw-r--r--src/gpu/effects/GrDistanceFieldGeoProc.h29
-rw-r--r--src/gpu/ops/GrAtlasTextOp.cpp36
-rw-r--r--src/gpu/ops/GrAtlasTextOp.h3
-rw-r--r--src/gpu/text/GrAtlasManager.h9
-rw-r--r--tools/gpu/GrTest.cpp6
7 files changed, 52 insertions, 49 deletions
diff --git a/src/gpu/effects/GrBitmapTextGeoProc.cpp b/src/gpu/effects/GrBitmapTextGeoProc.cpp
index 3efba9f509..14126794d7 100644
--- a/src/gpu/effects/GrBitmapTextGeoProc.cpp
+++ b/src/gpu/effects/GrBitmapTextGeoProc.cpp
@@ -122,7 +122,7 @@ private:
GrBitmapTextGeoProc::GrBitmapTextGeoProc(GrColor color,
const sk_sp<GrTextureProxy>* proxies,
- int numProxies,
+ int numActiveProxies,
const GrSamplerState& params, GrMaskFormat format,
const SkMatrix& localMatrix, bool usesLocalCoords)
: INHERITED(kGrBitmapTextGeoProc_ClassID)
@@ -131,7 +131,7 @@ GrBitmapTextGeoProc::GrBitmapTextGeoProc(GrColor color,
, fUsesLocalCoords(usesLocalCoords)
, fInColor(nullptr)
, fMaskFormat(format) {
- SkASSERT(numProxies <= kMaxTextures);
+ SkASSERT(numActiveProxies <= kMaxTextures);
fInPosition = &this->addVertexAttrib("inPosition", kFloat2_GrVertexAttribType);
@@ -142,7 +142,7 @@ GrBitmapTextGeoProc::GrBitmapTextGeoProc(GrColor color,
}
fInTextureCoords = &this->addVertexAttrib("inTextureCoords", kUShort2_GrVertexAttribType);
- for (int i = 0; i < numProxies; ++i) {
+ for (int i = 0; i < numActiveProxies; ++i) {
SkASSERT(proxies[i]);
fTextureSamplers[i].reset(std::move(proxies[i]), params);
@@ -151,11 +151,11 @@ GrBitmapTextGeoProc::GrBitmapTextGeoProc(GrColor color,
}
void GrBitmapTextGeoProc::addNewProxies(const sk_sp<GrTextureProxy>* proxies,
- int numProxies,
+ int numActiveProxies,
const GrSamplerState& params) {
- SkASSERT(numProxies <= kMaxTextures);
+ SkASSERT(numActiveProxies <= kMaxTextures);
- for (int i = 0; i < numProxies; ++i) {
+ for (int i = 0; i < numActiveProxies; ++i) {
SkASSERT(proxies[i]);
if (!fTextureSamplers[i].isInitialized()) {
diff --git a/src/gpu/effects/GrBitmapTextGeoProc.h b/src/gpu/effects/GrBitmapTextGeoProc.h
index 1f52e075b1..3b95f76192 100644
--- a/src/gpu/effects/GrBitmapTextGeoProc.h
+++ b/src/gpu/effects/GrBitmapTextGeoProc.h
@@ -24,11 +24,11 @@ public:
static sk_sp<GrGeometryProcessor> Make(GrColor color,
const sk_sp<GrTextureProxy>* proxies,
- int numProxies,
+ int numActiveProxies,
const GrSamplerState& p, GrMaskFormat format,
const SkMatrix& localMatrix, bool usesLocalCoords) {
return sk_sp<GrGeometryProcessor>(
- new GrBitmapTextGeoProc(color, proxies, numProxies, p, format,
+ new GrBitmapTextGeoProc(color, proxies, numActiveProxies, p, format,
localMatrix, usesLocalCoords));
}
@@ -45,7 +45,7 @@ public:
const SkMatrix& localMatrix() const { return fLocalMatrix; }
bool usesLocalCoords() const { return fUsesLocalCoords; }
- void addNewProxies(const sk_sp<GrTextureProxy>* proxies, int numProxies, const GrSamplerState&);
+ void addNewProxies(const sk_sp<GrTextureProxy>*, int numActiveProxies, const GrSamplerState&);
void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override;
diff --git a/src/gpu/effects/GrDistanceFieldGeoProc.h b/src/gpu/effects/GrDistanceFieldGeoProc.h
index 4ac6ae0304..5ba19ed5a5 100644
--- a/src/gpu/effects/GrDistanceFieldGeoProc.h
+++ b/src/gpu/effects/GrDistanceFieldGeoProc.h
@@ -56,19 +56,19 @@ public:
/** The local matrix should be identity if local coords are not required by the GrPipeline. */
#ifdef SK_GAMMA_APPLY_TO_A8
static sk_sp<GrGeometryProcessor> Make(const sk_sp<GrTextureProxy>* proxies,
- int numProxies,
+ int numActiveProxies,
const GrSamplerState& params, float lum, uint32_t flags,
const SkMatrix& localMatrixIfUsesLocalCoords) {
return sk_sp<GrGeometryProcessor>(new GrDistanceFieldA8TextGeoProc(
- proxies, numProxies, params, lum, flags, localMatrixIfUsesLocalCoords));
+ proxies, numActiveProxies, params, lum, flags, localMatrixIfUsesLocalCoords));
}
#else
static sk_sp<GrGeometryProcessor> Make(const sk_sp<GrTextureProxy>* proxies,
- int numProxies,
+ int numActiveProxies,
const GrSamplerState& params, uint32_t flags,
const SkMatrix& localMatrixIfUsesLocalCoords) {
return sk_sp<GrGeometryProcessor>(new GrDistanceFieldA8TextGeoProc(
- proxies, numProxies, params, flags, localMatrixIfUsesLocalCoords));
+ proxies, numActiveProxies, params, flags, localMatrixIfUsesLocalCoords));
}
#endif
@@ -93,7 +93,7 @@ public:
private:
GrDistanceFieldA8TextGeoProc(const sk_sp<GrTextureProxy>* proxies,
- int numProxies,
+ int numActiveProxies,
const GrSamplerState& params,
#ifdef SK_GAMMA_APPLY_TO_A8
float distanceAdjust,
@@ -129,10 +129,10 @@ public:
/** The local matrix should be identity if local coords are not required by the GrPipeline. */
static sk_sp<GrGeometryProcessor> Make(const SkMatrix& matrix,
const sk_sp<GrTextureProxy>* proxies,
- int numProxies,
+ int numActiveProxies,
const GrSamplerState& params, uint32_t flags) {
return sk_sp<GrGeometryProcessor>(
- new GrDistanceFieldPathGeoProc(matrix, proxies, numProxies, params, flags));
+ new GrDistanceFieldPathGeoProc(matrix, proxies, numActiveProxies, params, flags));
}
~GrDistanceFieldPathGeoProc() override {}
@@ -145,7 +145,7 @@ public:
const SkMatrix& matrix() const { return fMatrix; }
uint32_t getFlags() const { return fFlags; }
- void addNewProxies(const sk_sp<GrTextureProxy>* proxies, int numProxies, const GrSamplerState&);
+ void addNewProxies(const sk_sp<GrTextureProxy>*, int numActiveProxies, const GrSamplerState&);
void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override;
@@ -156,7 +156,7 @@ private:
GrDistanceFieldPathGeoProc(const SkMatrix& matrix,
const sk_sp<GrTextureProxy>* proxies,
- int numProxies,
+ int numActiveProxies,
const GrSamplerState&, uint32_t flags);
SkMatrix fMatrix; // view matrix if perspective, local matrix otherwise
@@ -195,13 +195,14 @@ public:
};
static sk_sp<GrGeometryProcessor> Make(const sk_sp<GrTextureProxy>* proxies,
- int numProxies,
+ int numActiveProxies,
const GrSamplerState& params,
DistanceAdjust distanceAdjust,
uint32_t flags,
const SkMatrix& localMatrixIfUsesLocalCoords) {
- return sk_sp<GrGeometryProcessor>(new GrDistanceFieldLCDTextGeoProc(
- proxies, numProxies, params, distanceAdjust, flags, localMatrixIfUsesLocalCoords));
+ return sk_sp<GrGeometryProcessor>(
+ new GrDistanceFieldLCDTextGeoProc(proxies, numActiveProxies, params, distanceAdjust,
+ flags, localMatrixIfUsesLocalCoords));
}
~GrDistanceFieldLCDTextGeoProc() override {}
@@ -215,14 +216,14 @@ public:
uint32_t getFlags() const { return fFlags; }
const SkMatrix& localMatrix() const { return fLocalMatrix; }
- void addNewProxies(const sk_sp<GrTextureProxy>* proxies, int numProxies, const GrSamplerState&);
+ void addNewProxies(const sk_sp<GrTextureProxy>*, int numActiveProxies, const GrSamplerState&);
void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override;
GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override;
private:
- GrDistanceFieldLCDTextGeoProc(const sk_sp<GrTextureProxy>* proxies, int numProxies,
+ GrDistanceFieldLCDTextGeoProc(const sk_sp<GrTextureProxy>* proxies, int numActiveProxies,
const GrSamplerState& params, DistanceAdjust wa, uint32_t flags,
const SkMatrix& localMatrix);
diff --git a/src/gpu/ops/GrAtlasTextOp.cpp b/src/gpu/ops/GrAtlasTextOp.cpp
index 96c592d5b4..99af581120 100644
--- a/src/gpu/ops/GrAtlasTextOp.cpp
+++ b/src/gpu/ops/GrAtlasTextOp.cpp
@@ -228,25 +228,26 @@ void GrAtlasTextOp::onPrepareDraws(Target* target) {
GrMaskFormat maskFormat = this->maskFormat();
- unsigned int atlasPageCount;
- const sk_sp<GrTextureProxy>* proxies = atlasManager->getProxies(maskFormat, &atlasPageCount);
- if (!proxies[0]) {
+ unsigned int numActiveProxies;
+ const sk_sp<GrTextureProxy>* proxies = atlasManager->getProxies(maskFormat, &numActiveProxies);
+ if (!proxies) {
SkDebugf("Could not allocate backing texture for atlas\n");
return;
}
+ SkASSERT(proxies[0]);
FlushInfo flushInfo;
flushInfo.fPipeline =
target->makePipeline(fSRGBFlags, std::move(fProcessors), target->detachAppliedClip());
SkDEBUGCODE(bool dfPerspective = false);
if (this->usesDistanceFields()) {
- flushInfo.fGeometryProcessor = this->setupDfProcessor(atlasManager);
+ flushInfo.fGeometryProcessor = this->setupDfProcessor(proxies, numActiveProxies);
SkDEBUGCODE(dfPerspective = fGeoData[0].fViewMatrix.hasPerspective());
} else {
GrSamplerState samplerState = fHasScaledGlyphs ? GrSamplerState::ClampBilerp()
: GrSamplerState::ClampNearest();
flushInfo.fGeometryProcessor = GrBitmapTextGeoProc::Make(
- this->color(), proxies, atlasPageCount, samplerState, maskFormat,
+ this->color(), proxies, numActiveProxies, samplerState, maskFormat,
localMatrix, this->usesLocalCoords());
}
@@ -330,23 +331,24 @@ void GrAtlasTextOp::flush(GrMeshDrawOp::Target* target, FlushInfo* flushInfo) co
GrGeometryProcessor* gp = flushInfo->fGeometryProcessor.get();
GrMaskFormat maskFormat = this->maskFormat();
- unsigned int numProxies;
- const sk_sp<GrTextureProxy>* proxies = atlasManager->getProxies(maskFormat, &numProxies);
- if (gp->numTextureSamplers() != (int) numProxies) {
+ unsigned int numActiveProxies;
+ const sk_sp<GrTextureProxy>* proxies = atlasManager->getProxies(maskFormat, &numActiveProxies);
+ SkASSERT(proxies);
+ if (gp->numTextureSamplers() != (int) numActiveProxies) {
// 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(
- proxies, numProxies, GrSamplerState::ClampBilerp());
+ proxies, numActiveProxies, GrSamplerState::ClampBilerp());
} else {
reinterpret_cast<GrDistanceFieldA8TextGeoProc*>(gp)->addNewProxies(
- proxies, numProxies, GrSamplerState::ClampBilerp());
+ proxies, numActiveProxies, GrSamplerState::ClampBilerp());
}
} else {
GrSamplerState samplerState = fHasScaledGlyphs ? GrSamplerState::ClampBilerp()
: GrSamplerState::ClampNearest();
- reinterpret_cast<GrBitmapTextGeoProc*>(gp)->addNewProxies(proxies, numProxies,
+ reinterpret_cast<GrBitmapTextGeoProc*>(gp)->addNewProxies(proxies, numActiveProxies,
samplerState);
}
}
@@ -441,10 +443,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(GrAtlasManager* atlasManager) const {
- unsigned int numProxies;
- const sk_sp<GrTextureProxy>* proxies = atlasManager->getProxies(this->maskFormat(),
- &numProxies);
+sk_sp<GrGeometryProcessor> GrAtlasTextOp::setupDfProcessor(const sk_sp<GrTextureProxy>* proxies,
+ unsigned int numActiveProxies) const {
bool isLCD = this->isLCD();
SkMatrix localMatrix = SkMatrix::I();
@@ -468,7 +468,7 @@ sk_sp<GrGeometryProcessor> GrAtlasTextOp::setupDfProcessor(GrAtlasManager* atlas
GrDistanceFieldLCDTextGeoProc::DistanceAdjust widthAdjust =
GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make(
redCorrection, greenCorrection, blueCorrection);
- return GrDistanceFieldLCDTextGeoProc::Make(proxies, numProxies,
+ return GrDistanceFieldLCDTextGeoProc::Make(proxies, numActiveProxies,
GrSamplerState::ClampBilerp(), widthAdjust,
fDFGPFlags, localMatrix);
} else {
@@ -480,11 +480,11 @@ sk_sp<GrGeometryProcessor> GrAtlasTextOp::setupDfProcessor(GrAtlasManager* atlas
correction = fDistanceAdjustTable->getAdjustment(lum >> kDistanceAdjustLumShift,
fUseGammaCorrectDistanceTable);
}
- return GrDistanceFieldA8TextGeoProc::Make(proxies, numProxies,
+ return GrDistanceFieldA8TextGeoProc::Make(proxies, numActiveProxies,
GrSamplerState::ClampBilerp(),
correction, fDFGPFlags, localMatrix);
#else
- return GrDistanceFieldA8TextGeoProc::Make(proxies, numProxies,
+ return GrDistanceFieldA8TextGeoProc::Make(proxies, numActiveProxies,
GrSamplerState::ClampBilerp(),
fDFGPFlags, localMatrix);
#endif
diff --git a/src/gpu/ops/GrAtlasTextOp.h b/src/gpu/ops/GrAtlasTextOp.h
index 2f0fcaec70..67474be827 100644
--- a/src/gpu/ops/GrAtlasTextOp.h
+++ b/src/gpu/ops/GrAtlasTextOp.h
@@ -175,7 +175,8 @@ private:
bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override;
- sk_sp<GrGeometryProcessor> setupDfProcessor(GrAtlasManager*) const;
+ sk_sp<GrGeometryProcessor> setupDfProcessor(const sk_sp<GrTextureProxy>* proxies,
+ unsigned int numActiveProxies) const;
SkAutoSTMalloc<kMinGeometryAllocated, Geometry> fGeoData;
int fGeoDataAllocSize;
diff --git a/src/gpu/text/GrAtlasManager.h b/src/gpu/text/GrAtlasManager.h
index 9bf03c1f40..18ccfd096f 100644
--- a/src/gpu/text/GrAtlasManager.h
+++ b/src/gpu/text/GrAtlasManager.h
@@ -30,13 +30,14 @@ public:
// if getProxies returns nullptr, the client must not try to use other functions on the
// GrGlyphCache which use the atlas. This function *must* be called first, before other
- // functions which use the atlas.
- const sk_sp<GrTextureProxy>* getProxies(GrMaskFormat format, unsigned int* numProxies) {
+ // functions which use the atlas. Note that we can have proxies available but none active
+ // (i.e., none instantiated).
+ const sk_sp<GrTextureProxy>* getProxies(GrMaskFormat format, unsigned int* numActiveProxies) {
if (this->initAtlas(format)) {
- *numProxies = this->getAtlas(format)->numActivePages();
+ *numActiveProxies = this->getAtlas(format)->numActivePages();
return this->getAtlas(format)->getProxies();
}
- *numProxies = 0;
+ *numActiveProxies = 0;
return nullptr;
}
diff --git a/tools/gpu/GrTest.cpp b/tools/gpu/GrTest.cpp
index 311f318b9f..ec07758db2 100644
--- a/tools/gpu/GrTest.cpp
+++ b/tools/gpu/GrTest.cpp
@@ -130,9 +130,9 @@ sk_sp<SkImage> GrContextPriv::getFontAtlasImage_ForTesting(GrMaskFormat format,
return nullptr;
}
- unsigned int numProxies;
- const sk_sp<GrTextureProxy>* proxies = atlasManager->getProxies(format, &numProxies);
- if (index >= numProxies || !proxies[index]) {
+ unsigned int numActiveProxies;
+ const sk_sp<GrTextureProxy>* proxies = atlasManager->getProxies(format, &numActiveProxies);
+ if (index >= numActiveProxies || !proxies || !proxies[index]) {
return nullptr;
}