aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/text
diff options
context:
space:
mode:
authorGravatar Khushal <khushalsagar@chromium.org>2018-06-06 17:46:38 -0700
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-06-07 18:03:11 +0000
commitfa8ff09457f82119be0d00b7f37afb790487819e (patch)
tree65ee0f8eff9997add651bf8f3b48ac74b4413cdf /src/gpu/text
parentd5b4593024544c3405615066aa5b4f94352eb3cb (diff)
fonts: Hook up FallbackTextHelper to font remoting.
Use GrContext::FallbackTextHelper in SkTextBlobCacheDiffCanvas to replicate glyph generation logic for fallback text during analysis. This ensures that we correctly handle these fallback cases when using distance field or paths for text rendering. R=herb@google.com, jvanverth@google.com Bug: skia:7913 Change-Id: I3067c4f1bd09231a564ac7c4cd89efcb876d2abd Reviewed-on: https://skia-review.googlesource.com/132285 Reviewed-by: Jim Van Verth <jvanverth@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Khusal Sagar <khushalsagar@chromium.org>
Diffstat (limited to 'src/gpu/text')
-rw-r--r--src/gpu/text/GrAtlasManager.cpp14
-rw-r--r--src/gpu/text/GrAtlasManager.h4
-rw-r--r--src/gpu/text/GrGlyphCache.cpp20
-rw-r--r--src/gpu/text/GrGlyphCache.h3
-rw-r--r--src/gpu/text/GrTextContext.cpp33
-rw-r--r--src/gpu/text/GrTextContext.h23
6 files changed, 57 insertions, 40 deletions
diff --git a/src/gpu/text/GrAtlasManager.cpp b/src/gpu/text/GrAtlasManager.cpp
index f75224d0bc..ec07429180 100644
--- a/src/gpu/text/GrAtlasManager.cpp
+++ b/src/gpu/text/GrAtlasManager.cpp
@@ -12,15 +12,16 @@
#include "GrGlyphCache.h"
#include "GrProxyProvider.h"
-void GrAtlasManager::ComputeAtlasLimits(const GrCaps* caps, float maxTextureBytes,
- int* maxDim, int* minDim, int* maxPlot, int* minPlot) {
+void GrAtlasManager::ComputeAtlasLimits(int maxTextureSize, size_t 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 log2MaxTextureSize = SkPrevLog2(maxTextureSize);
int log2MaxDim = 9;
+ static const size_t kOne = 1u;
for (; log2MaxDim <= log2MaxTextureSize; ++log2MaxDim) {
- int maxDimTmp = 1 << log2MaxDim;
- int minDimTmp = 1 << (log2MaxDim - 1);
+ size_t maxDimTmp = kOne << log2MaxDim;
+ size_t minDimTmp = kOne << (log2MaxDim - 1);
if (maxDimTmp * minDimTmp * 4 >= maxTextureBytes) {
break;
@@ -45,7 +46,8 @@ GrAtlasManager::GrAtlasManager(GrProxyProvider* proxyProvider, GrGlyphCache* gly
fCaps = fProxyProvider->refCaps();
int maxDim, minDim, maxPlot, minPlot;
- ComputeAtlasLimits(fCaps.get(), maxTextureBytes, &maxDim, &minDim, &maxPlot, &minPlot);
+ ComputeAtlasLimits(fCaps->maxTextureSize(), 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.
diff --git a/src/gpu/text/GrAtlasManager.h b/src/gpu/text/GrAtlasManager.h
index 18ccfd096f..38e2781d4d 100644
--- a/src/gpu/text/GrAtlasManager.h
+++ b/src/gpu/text/GrAtlasManager.h
@@ -43,8 +43,8 @@ public:
SkScalar getGlyphSizeLimit() const { return fGlyphSizeLimit; }
- static void ComputeAtlasLimits(const GrCaps* caps, float maxTextureBytes,
- int* maxDim, int* minDim, int* maxPlot, int* minPlot);
+ static void ComputeAtlasLimits(int maxTextureSize, size_t maxTextureBytes, int* maxDim,
+ int* minDim, int* maxPlot, int* minPlot);
void freeAll();
diff --git a/src/gpu/text/GrGlyphCache.cpp b/src/gpu/text/GrGlyphCache.cpp
index b564c93c02..f6a18c3271 100644
--- a/src/gpu/text/GrGlyphCache.cpp
+++ b/src/gpu/text/GrGlyphCache.cpp
@@ -5,20 +5,17 @@
* found in the LICENSE file.
*/
+#include "GrGlyphCache.h"
#include "GrAtlasManager.h"
+#include "GrCaps.h"
#include "GrDistanceFieldGenFromVector.h"
-#include "GrGlyphCache.h"
#include "SkAutoMalloc.h"
#include "SkDistanceFieldGen.h"
-GrGlyphCache::GrGlyphCache(const GrCaps* caps, float maxTextureBytes)
- : fPreserveStrike(nullptr)
- , fGlyphSizeLimit(0) {
-
- int maxDim, minDim, maxPlot, minPlot;
- GrAtlasManager::ComputeAtlasLimits(caps, maxTextureBytes, &maxDim, &minDim, &maxPlot, &minPlot);
- fGlyphSizeLimit = minPlot;
+GrGlyphCache::GrGlyphCache(const GrCaps* caps, size_t maxTextureBytes)
+ : fPreserveStrike(nullptr), fGlyphSizeLimit(0) {
+ fGlyphSizeLimit = ComputeGlyphSizeLimit(caps->maxTextureSize(), maxTextureBytes);
}
GrGlyphCache::~GrGlyphCache() {
@@ -40,6 +37,13 @@ void GrGlyphCache::freeAll() {
fCache.rewind();
}
+SkScalar GrGlyphCache::ComputeGlyphSizeLimit(int maxTextureSize, size_t maxTextureBytes) {
+ int maxDim, minDim, maxPlot, minPlot;
+ GrAtlasManager::ComputeAtlasLimits(maxTextureSize, maxTextureBytes, &maxDim, &minDim, &maxPlot,
+ &minPlot);
+ return minPlot;
+}
+
void GrGlyphCache::HandleEviction(GrDrawOpAtlas::AtlasID id, void* ptr) {
GrGlyphCache* glyphCache = reinterpret_cast<GrGlyphCache*>(ptr);
diff --git a/src/gpu/text/GrGlyphCache.h b/src/gpu/text/GrGlyphCache.h
index cff309501d..7e707ec64c 100644
--- a/src/gpu/text/GrGlyphCache.h
+++ b/src/gpu/text/GrGlyphCache.h
@@ -108,7 +108,7 @@ private:
*/
class GrGlyphCache {
public:
- GrGlyphCache(const GrCaps* caps, float maxTextureBytes);
+ GrGlyphCache(const GrCaps* caps, size_t maxTextureBytes);
~GrGlyphCache();
SkScalar getGlyphSizeLimit() const { return fGlyphSizeLimit; }
@@ -130,6 +130,7 @@ public:
void freeAll();
static void HandleEviction(GrDrawOpAtlas::AtlasID, void*);
+ static SkScalar ComputeGlyphSizeLimit(int maxTextureSize, size_t maxTextureBytes);
private:
sk_sp<GrTextStrike> generateStrike(const SkGlyphCache* cache) {
diff --git a/src/gpu/text/GrTextContext.cpp b/src/gpu/text/GrTextContext.cpp
index 033506f220..9864d027de 100644
--- a/src/gpu/text/GrTextContext.cpp
+++ b/src/gpu/text/GrTextContext.cpp
@@ -380,7 +380,8 @@ void GrTextContext::DrawBmpPosTextAsPaths(GrTextBlob* blob, int runIndex,
// setup our std paint, in hopes of getting hits in the cache
SkPaint pathPaint(origPaint);
SkScalar matrixScale = pathPaint.setupForAsPaths();
- FallbackTextHelper fallbackTextHelper(viewMatrix, origPaint, glyphCache, matrixScale);
+ FallbackTextHelper fallbackTextHelper(viewMatrix, origPaint, glyphCache->getGlyphSizeLimit(),
+ matrixScale);
// Temporarily jam in kFill, so we only ever ask for the raw outline from the cache.
pathPaint.setStyle(SkPaint::kFill_Style);
@@ -596,7 +597,8 @@ void GrTextContext::drawDFPosText(GrTextBlob* blob, int runIndex,
blob->setSubRunHasDistanceFields(runIndex, paint.skPaint().isLCDRenderText(),
paint.skPaint().isAntiAlias(), hasWCoord);
- FallbackTextHelper fallbackTextHelper(viewMatrix, paint, glyphCache, textRatio);
+ FallbackTextHelper fallbackTextHelper(viewMatrix, paint, glyphCache->getGlyphSizeLimit(),
+ textRatio);
sk_sp<GrTextStrike> currStrike;
@@ -672,6 +674,8 @@ void GrTextContext::DfAppendGlyph(GrTextBlob* blob, int runIndex,
void GrTextContext::FallbackTextHelper::appendText(const SkGlyph& glyph, int count,
const char* text, SkPoint glyphPos) {
SkScalar maxDim = SkTMax(glyph.fWidth, glyph.fHeight)*fTextRatio;
+ if (SkScalarNearlyZero(maxDim)) return;
+
if (!fUseTransformedFallback) {
if (!fViewMatrix.isScaleTranslate() || maxDim*fMaxScale > fMaxTextSize) {
fUseTransformedFallback = true;
@@ -706,18 +710,12 @@ void GrTextContext::FallbackTextHelper::drawText(GrTextBlob* blob, int runIndex,
SkPaint::GlyphCacheProc glyphCacheProc =
SkPaint::GetGlyphCacheProc(skPaint.getTextEncoding(), true);
SkColor textColor = paint.filteredPremulColor();
+
SkScalar textRatio = SK_Scalar1;
- if (fUseTransformedFallback) {
- // Set up paint and matrix to scale glyphs
- SkPaint scaledPaint(skPaint);
- scaledPaint.setTextSize(fTransformedFallbackTextSize);
- textRatio = fTextSize / fTransformedFallbackTextSize;
- cache = blob->setupCache(runIndex, props, scalerContextFlags, scaledPaint,
- &SkMatrix::I());
- } else {
- cache = blob->setupCache(runIndex, props, scalerContextFlags, paint,
- &fViewMatrix);
- }
+ SkPaint fallbackPaint(skPaint);
+ SkMatrix matrix = fViewMatrix;
+ this->initializeForDraw(&fallbackPaint, &textRatio, &matrix);
+ cache = blob->setupCache(runIndex, props, scalerContextFlags, fallbackPaint, &matrix);
sk_sp<GrTextStrike> currStrike;
const char* text = fFallbackTxt.begin();
@@ -738,6 +736,15 @@ void GrTextContext::FallbackTextHelper::drawText(GrTextBlob* blob, int runIndex,
}
}
+void GrTextContext::FallbackTextHelper::initializeForDraw(SkPaint* paint, SkScalar* textRatio,
+ SkMatrix* matrix) const {
+ if (!fUseTransformedFallback) return;
+
+ paint->setTextSize(fTransformedFallbackTextSize);
+ *textRatio = fTextSize / fTransformedFallbackTextSize;
+ *matrix = SkMatrix::I();
+}
+
///////////////////////////////////////////////////////////////////////////////////////////////////
#if GR_TEST_UTILS
diff --git a/src/gpu/text/GrTextContext.h b/src/gpu/text/GrTextContext.h
index 7d31d84a05..478d4c42b6 100644
--- a/src/gpu/text/GrTextContext.h
+++ b/src/gpu/text/GrTextContext.h
@@ -69,21 +69,18 @@ public:
SkScalar* textRatio,
SkScalerContextFlags* flags);
-private:
- GrTextContext(const Options& options);
-
class FallbackTextHelper {
public:
FallbackTextHelper(const SkMatrix& viewMatrix,
const SkPaint& pathPaint,
- const GrGlyphCache* glyphCache,
+ SkScalar maxTextSize,
SkScalar textRatio)
- : fViewMatrix(viewMatrix)
- , fTextSize(pathPaint.getTextSize())
- , fMaxTextSize(glyphCache->getGlyphSizeLimit())
- , fTextRatio(textRatio)
- , fTransformedFallbackTextSize(fMaxTextSize)
- , fUseTransformedFallback(false) {
+ : fViewMatrix(viewMatrix)
+ , fTextSize(pathPaint.getTextSize())
+ , fMaxTextSize(maxTextSize)
+ , fTextRatio(textRatio)
+ , fTransformedFallbackTextSize(fMaxTextSize)
+ , fUseTransformedFallback(false) {
fMaxScale = viewMatrix.getMaxScale();
}
@@ -91,6 +88,9 @@ private:
void drawText(GrTextBlob* blob, int runIndex, GrGlyphCache*, const SkSurfaceProps&,
const GrTextUtils::Paint&, SkScalerContextFlags);
+ void initializeForDraw(SkPaint* paint, SkScalar* textRatio, SkMatrix* matrix) const;
+ const SkTDArray<char>& fallbackText() const { return fFallbackTxt; }
+
private:
SkTDArray<char> fFallbackTxt;
SkTDArray<SkPoint> fFallbackPos;
@@ -104,6 +104,9 @@ private:
bool fUseTransformedFallback;
};
+private:
+ GrTextContext(const Options& options);
+
// sets up the descriptor on the blob and returns a detached cache. Client must attach
static SkColor ComputeCanonicalColor(const SkPaint&, bool lcd);
// Determines if we need to use fake gamma (and contrast boost):