Break GrTextContext's reliance on SkGpuDevice
This CL seems to have 2 main downsides:
1) It duplicates some code in SkBaseDevice::filterTextFlags
2) It makes it tougher to derive from SkGpuDevice
It seems reasonable (at least to me) that the TextContexts get the power to reset the LCD flags.
Review URL: https://codereview.chromium.org/1159973002
diff --git a/src/gpu/GrTextContext.cpp b/src/gpu/GrTextContext.cpp
index 1edacfc..91c8e85 100644
--- a/src/gpu/GrTextContext.cpp
+++ b/src/gpu/GrTextContext.cpp
@@ -101,7 +101,37 @@
scalarsPerPosition, offset, clipBounds);
}
-void GrTextContext::drawTextBlob(SkGpuDevice* gpuDevice, GrRenderTarget* rt,
+bool GrTextContext::ShouldDisableLCD(const SkPaint& paint) {
+ if (paint.getShader() ||
+ !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode) ||
+ paint.getMaskFilter() ||
+ paint.getRasterizer() ||
+ paint.getColorFilter() ||
+ paint.getPathEffect() ||
+ paint.isFakeBoldText() ||
+ paint.getStyle() != SkPaint::kFill_Style)
+ {
+ return true;
+ }
+ return false;
+}
+
+uint32_t GrTextContext::FilterTextFlags(const SkDeviceProperties& devProps, const SkPaint& paint) {
+ uint32_t flags = paint.getFlags();
+
+ if (!paint.isLCDRenderText() || !paint.isAntiAlias()) {
+ return flags;
+ }
+
+ if (kUnknown_SkPixelGeometry == devProps.pixelGeometry() || ShouldDisableLCD(paint)) {
+ flags &= ~SkPaint::kLCDRenderText_Flag;
+ flags |= SkPaint::kGenA8FromLCD_Flag;
+ }
+
+ return flags;
+}
+
+void GrTextContext::drawTextBlob(GrRenderTarget* rt,
const GrClip& clip, const SkPaint& skPaint,
const SkMatrix& viewMatrix, const SkTextBlob* blob,
SkScalar x, SkScalar y,
@@ -122,7 +152,7 @@
continue;
}
- runPaint.setFlags(gpuDevice->filterTextFlags(runPaint));
+ runPaint.setFlags(FilterTextFlags(fDeviceProperties, runPaint));
GrPaint grPaint;
if (!SkPaint2GrPaint(fContext, fRenderTarget, runPaint, viewMatrix, true, &grPaint)) {