aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/text/GrTextUtils.cpp
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2017-01-13 12:02:17 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-01-13 17:38:10 +0000
commit6f1d36cc54dc635f5e4d0f925ef79c14914342bb (patch)
treeb133ea2048fe159d2fef718e828ede8965a031cb /src/gpu/text/GrTextUtils.cpp
parent0ed3b640c9da71fbbd73c65a4ec1992f85596271 (diff)
Delay SkPaint->GrPaint conversion in text rendering.
This fixes an issue where color filters aren't correctly applied to color glyphs. Instead we apply the filter to the SkPaint's color which is correct for mask glyphs only. Add color filter and alpha + various effects to coloremoji gm Change-Id: If77dece71d43468fec65499857eaaaedb56428e9 Reviewed-on: https://skia-review.googlesource.com/6891 Commit-Queue: Brian Salomon <bsalomon@google.com> Reviewed-by: Jim Van Verth <jvanverth@google.com>
Diffstat (limited to 'src/gpu/text/GrTextUtils.cpp')
-rw-r--r--src/gpu/text/GrTextUtils.cpp146
1 files changed, 79 insertions, 67 deletions
diff --git a/src/gpu/text/GrTextUtils.cpp b/src/gpu/text/GrTextUtils.cpp
index 548d4aa27e..a199d8c92d 100644
--- a/src/gpu/text/GrTextUtils.cpp
+++ b/src/gpu/text/GrTextUtils.cpp
@@ -6,20 +6,22 @@
*/
#include "GrTextUtils.h"
-
#include "GrAtlasGlyphCache.h"
#include "GrAtlasTextBlob.h"
#include "GrBlurUtils.h"
#include "GrCaps.h"
#include "GrContext.h"
#include "GrRenderTargetContext.h"
-
+#include "GrSurfaceContextPriv.h"
#include "SkDistanceFieldGen.h"
+#include "SkDrawFilter.h"
#include "SkDrawProcs.h"
#include "SkFindAndPlaceGlyph.h"
#include "SkGlyphCache.h"
+#include "SkGrPriv.h"
#include "SkPaint.h"
#include "SkRect.h"
+#include "SkTextBlobRunIterator.h"
#include "SkTextMapStateProc.h"
#include "SkTextToPathIter.h"
@@ -37,13 +39,43 @@ static const int kLargeDFFontLimit = 2 * kLargeDFFontSize;
#endif
};
-void GrTextUtils::DrawBmpText(GrAtlasTextBlob* blob, int runIndex,
- GrAtlasGlyphCache* fontCache,
- const SkSurfaceProps& props, const SkPaint& skPaint,
- GrColor color, uint32_t scalerContextFlags,
- const SkMatrix& viewMatrix,
- const char text[], size_t byteLength,
- SkScalar x, SkScalar y) {
+bool GrTextUtils::Paint::toGrPaint(GrMaskFormat maskFormat, GrRenderTargetContext* rtc,
+ const SkMatrix& viewMatrix, GrPaint* grPaint) const {
+ GrContext* context = rtc->surfPriv().getContext();
+ if (kARGB_GrMaskFormat == maskFormat) {
+ return SkPaintToGrPaintWithPrimitiveColor(context, rtc, this->skPaint(), grPaint);
+ } else {
+ return SkPaintToGrPaint(context, rtc, this->skPaint(), viewMatrix, grPaint);
+ }
+}
+
+bool GrTextUtils::RunPaint::modifyForRun(const SkTextBlobRunIterator& run) {
+ if (!fModifiedPaint.isValid()) {
+ fModifiedPaint.init(fOriginalPaint->skPaint());
+ fPaint = fModifiedPaint.get();
+ } else if (fFilter) {
+ // We have to reset before applying the run because the filter could have arbitrary
+ // changed the paint.
+ *fModifiedPaint.get() = fOriginalPaint->skPaint();
+ }
+ run.applyFontToPaint(fModifiedPaint.get());
+
+ if (fFilter) {
+ if (!fFilter->filter(fModifiedPaint.get(), SkDrawFilter::kText_Type)) {
+ // A false return from filter() means we should abort the current draw.
+ return false;
+ }
+ // The draw filter could have changed either the paint color or color filter.
+ this->initFilteredColor();
+ }
+ fModifiedPaint.get()->setFlags(FilterTextFlags(fProps, *fModifiedPaint.get()));
+ return true;
+}
+
+void GrTextUtils::DrawBmpText(GrAtlasTextBlob* blob, int runIndex, GrAtlasGlyphCache* fontCache,
+ const SkSurfaceProps& props, const GrTextUtils::Paint& paint,
+ uint32_t scalerContextFlags, const SkMatrix& viewMatrix,
+ const char text[], size_t byteLength, SkScalar x, SkScalar y) {
SkASSERT(byteLength == 0 || text != nullptr);
// nothing to draw
@@ -56,32 +88,28 @@ void GrTextUtils::DrawBmpText(GrAtlasTextBlob* blob, int runIndex,
GrAtlasTextStrike* currStrike = nullptr;
- SkGlyphCache* cache = blob->setupCache(runIndex, props, scalerContextFlags, skPaint,
- &viewMatrix);
+ SkGlyphCache* cache = blob->setupCache(runIndex, props, scalerContextFlags, paint, &viewMatrix);
SkFindAndPlaceGlyph::ProcessText(
- skPaint.getTextEncoding(), text, byteLength,
- {x, y}, viewMatrix, skPaint.getTextAlign(),
+ paint.skPaint().getTextEncoding(), text, byteLength,
+ {x, y}, viewMatrix, paint.skPaint().getTextAlign(),
cache,
[&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) {
- position += rounding;
- BmpAppendGlyph(
- blob, runIndex, fontCache, &currStrike, glyph,
- SkScalarFloorToInt(position.fX), SkScalarFloorToInt(position.fY),
- color, cache);
+ position += rounding;
+ BmpAppendGlyph(
+ blob, runIndex, fontCache, &currStrike, glyph,
+ SkScalarFloorToInt(position.fX), SkScalarFloorToInt(position.fY),
+ paint.filteredPremulGrColor(), cache);
}
);
SkGlyphCache::AttachCache(cache);
}
-void GrTextUtils::DrawBmpPosText(GrAtlasTextBlob* blob, int runIndex,
- GrAtlasGlyphCache* fontCache,
- const SkSurfaceProps& props, const SkPaint& skPaint,
- GrColor color, uint32_t scalerContextFlags,
- const SkMatrix& viewMatrix,
- const char text[], size_t byteLength,
- const SkScalar pos[], int scalarsPerPosition,
- const SkPoint& offset) {
+void GrTextUtils::DrawBmpPosText(GrAtlasTextBlob* blob, int runIndex, GrAtlasGlyphCache* fontCache,
+ const SkSurfaceProps& props, const GrTextUtils::Paint& paint,
+ uint32_t scalerContextFlags, const SkMatrix& viewMatrix,
+ const char text[], size_t byteLength, const SkScalar pos[],
+ int scalarsPerPosition, const SkPoint& offset) {
SkASSERT(byteLength == 0 || text != nullptr);
SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
@@ -95,19 +123,18 @@ void GrTextUtils::DrawBmpPosText(GrAtlasTextBlob* blob, int runIndex,
GrAtlasTextStrike* currStrike = nullptr;
- SkGlyphCache* cache = blob->setupCache(runIndex, props, scalerContextFlags, skPaint,
- &viewMatrix);
+ SkGlyphCache* cache = blob->setupCache(runIndex, props, scalerContextFlags, paint, &viewMatrix);
SkFindAndPlaceGlyph::ProcessPosText(
- skPaint.getTextEncoding(), text, byteLength,
+ paint.skPaint().getTextEncoding(), text, byteLength,
offset, viewMatrix, pos, scalarsPerPosition,
- skPaint.getTextAlign(), cache,
+ paint.skPaint().getTextAlign(), cache,
[&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) {
position += rounding;
BmpAppendGlyph(
blob, runIndex, fontCache, &currStrike, glyph,
SkScalarFloorToInt(position.fX), SkScalarFloorToInt(position.fY),
- color, cache);
+ paint.filteredPremulGrColor(), cache);
}
);
@@ -156,7 +183,7 @@ bool GrTextUtils::CanDrawAsDistanceFields(const SkPaint& skPaint, const SkMatrix
}
SkScalar maxScale = viewMatrix.getMaxScale();
- SkScalar scaledTextSize = maxScale*skPaint.getTextSize();
+ SkScalar scaledTextSize = maxScale * skPaint.getTextSize();
// Hinted text looks far better at small resolutions
// Scaling up beyond 2x yields undesireable artifacts
if (scaledTextSize < kMinDFFontSize ||
@@ -242,7 +269,7 @@ void GrTextUtils::InitDistanceFieldPaint(GrAtlasTextBlob* blob,
void GrTextUtils::DrawDFText(GrAtlasTextBlob* blob, int runIndex,
GrAtlasGlyphCache* fontCache, const SkSurfaceProps& props,
- const SkPaint& skPaint, GrColor color, uint32_t scalerContextFlags,
+ const GrTextUtils::Paint& paint, uint32_t scalerContextFlags,
const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
SkScalar x, SkScalar y) {
@@ -253,6 +280,7 @@ void GrTextUtils::DrawDFText(GrAtlasTextBlob* blob, int runIndex,
return;
}
+ const SkPaint& skPaint = paint.skPaint();
SkPaint::GlyphCacheProc glyphCacheProc = SkPaint::GetGlyphCacheProc(skPaint.getTextEncoding(),
skPaint.isDevKernText(),
true);
@@ -311,18 +339,15 @@ void GrTextUtils::DrawDFText(GrAtlasTextBlob* blob, int runIndex,
y -= alignY;
SkPoint offset = SkPoint::Make(x, y);
- DrawDFPosText(blob, runIndex, fontCache, props, skPaint, color, scalerContextFlags, viewMatrix,
- text, byteLength, positions.begin(), 2, offset);
+ DrawDFPosText(blob, runIndex, fontCache, props, paint, scalerContextFlags, viewMatrix, text,
+ byteLength, positions.begin(), 2, offset);
}
-void GrTextUtils::DrawDFPosText(GrAtlasTextBlob* blob, int runIndex,
- GrAtlasGlyphCache* fontCache, const SkSurfaceProps& props,
- const SkPaint& origPaint,
- GrColor color, uint32_t scalerContextFlags,
- const SkMatrix& viewMatrix,
- const char text[], size_t byteLength,
- const SkScalar pos[], int scalarsPerPosition,
- const SkPoint& offset) {
+void GrTextUtils::DrawDFPosText(GrAtlasTextBlob* blob, int runIndex, GrAtlasGlyphCache* fontCache,
+ const SkSurfaceProps& props, const GrTextUtils::Paint& paint,
+ uint32_t scalerContextFlags, const SkMatrix& viewMatrix,
+ const char text[], size_t byteLength, const SkScalar pos[],
+ int scalarsPerPosition, const SkPoint& offset) {
SkASSERT(byteLength == 0 || text != nullptr);
SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
@@ -336,10 +361,10 @@ void GrTextUtils::DrawDFPosText(GrAtlasTextBlob* blob, int runIndex,
// Setup distance field paint and text ratio
SkScalar textRatio;
- SkPaint dfPaint(origPaint);
+ SkPaint dfPaint(paint);
GrTextUtils::InitDistanceFieldPaint(blob, &dfPaint, &textRatio, viewMatrix);
blob->setHasDistanceField();
- blob->setSubRunHasDistanceFields(runIndex, origPaint.isLCDRenderText());
+ blob->setSubRunHasDistanceFields(runIndex, paint.skPaint().isLCDRenderText());
GrAtlasTextStrike* currStrike = nullptr;
@@ -363,13 +388,8 @@ void GrTextUtils::DrawDFPosText(GrAtlasTextBlob* blob, int runIndex,
SkScalar x = offset.x() + pos[0];
SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0);
- if (!DfAppendGlyph(blob,
- runIndex,
- fontCache,
- &currStrike,
- glyph,
- x, y, color, cache,
- textRatio, viewMatrix)) {
+ if (!DfAppendGlyph(blob, runIndex, fontCache, &currStrike, glyph, x, y,
+ paint.filteredPremulGrColor(), cache, textRatio, viewMatrix)) {
// couldn't append, send to fallback
fallbackTxt.append(SkToInt(text-lastText), lastText);
*fallbackPos.append() = pos[0];
@@ -395,14 +415,8 @@ void GrTextUtils::DrawDFPosText(GrAtlasTextBlob* blob, int runIndex,
SkScalar advanceX = SkFloatToScalar(glyph.fAdvanceX) * alignMul * textRatio;
SkScalar advanceY = SkFloatToScalar(glyph.fAdvanceY) * alignMul * textRatio;
- if (!DfAppendGlyph(blob,
- runIndex,
- fontCache,
- &currStrike,
- glyph,
- x - advanceX, y - advanceY, color,
- cache,
- textRatio,
+ if (!DfAppendGlyph(blob, runIndex, fontCache, &currStrike, glyph, x - advanceX,
+ y - advanceY, paint.filteredPremulGrColor(), cache, textRatio,
viewMatrix)) {
// couldn't append, send to fallback
fallbackTxt.append(SkToInt(text-lastText), lastText);
@@ -419,9 +433,8 @@ void GrTextUtils::DrawDFPosText(GrAtlasTextBlob* blob, int runIndex,
SkGlyphCache::AttachCache(cache);
if (fallbackTxt.count()) {
blob->initOverride(runIndex);
- GrTextUtils::DrawBmpPosText(blob, runIndex, fontCache, props,
- origPaint, origPaint.getColor(), scalerContextFlags, viewMatrix,
- fallbackTxt.begin(), fallbackTxt.count(),
+ GrTextUtils::DrawBmpPosText(blob, runIndex, fontCache, props, paint, scalerContextFlags,
+ viewMatrix, fallbackTxt.begin(), fallbackTxt.count(),
fallbackPos.begin(), scalarsPerPosition, offset);
}
}
@@ -468,12 +481,11 @@ bool GrTextUtils::DfAppendGlyph(GrAtlasTextBlob* blob, int runIndex, GrAtlasGlyp
return true;
}
-void GrTextUtils::DrawTextAsPath(GrContext* context, GrRenderTargetContext* rtc,
- const GrClip& clip,
- const SkPaint& skPaint, const SkMatrix& viewMatrix,
+void GrTextUtils::DrawTextAsPath(GrContext* context, GrRenderTargetContext* rtc, const GrClip& clip,
+ const SkPaint& paint, const SkMatrix& viewMatrix,
const char text[], size_t byteLength, SkScalar x, SkScalar y,
const SkIRect& clipBounds) {
- SkTextToPathIter iter(text, byteLength, skPaint, true);
+ SkTextToPathIter iter(text, byteLength, paint, true);
SkMatrix matrix;
matrix.setScale(iter.getPathScale(), iter.getPathScale());