aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ports
diff options
context:
space:
mode:
authorGravatar bungeman <bungeman@google.com>2016-06-16 14:41:53 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-06-16 14:41:53 -0700
commit73c7c3c2346033e0b5df123f1a6b488015443a55 (patch)
tree0b67bffde89371234b36122ccbdb378614c29633 /src/ports
parent74959a1471cd3b20e2dd79fc0c685e7205a25cd9 (diff)
Revert of Support pixel antialising in DirectWrite. (patchset #4 id:60001 of https://codereview.chromium.org/2065833002/ )
Reason for revert: Moving to the new glyph run analysis changes things anyway, and the Chromium Win 10 bots are having issues with this. Revert until I have time to make the suppression wider. Original issue's description: > Support pixel antialising in DirectWrite. > > DirectWrite2 supports pixel antialiasing and rendering without hinting. > > BUG=skia:5416 > GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2065833002 > > TBR=reed > Will move SkTScopedComPtr into src. > > Committed: https://skia.googlesource.com/skia/+/bd770d619553a88eeaa64ff29082f62db5c9b4d2 TBR=reed@google.com,mtklein@google.com # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=skia:5416 Review-Url: https://codereview.chromium.org/2075913002
Diffstat (limited to 'src/ports')
-rw-r--r--src/ports/SkFontMgr_win_dw.cpp2
-rw-r--r--src/ports/SkScalerContext_win_dw.cpp149
-rw-r--r--src/ports/SkScalerContext_win_dw.h7
-rw-r--r--src/ports/SkTypeface_win_dw.cpp7
-rw-r--r--src/ports/SkTypeface_win_dw.h21
5 files changed, 40 insertions, 146 deletions
diff --git a/src/ports/SkFontMgr_win_dw.cpp b/src/ports/SkFontMgr_win_dw.cpp
index 4358d80de2..bacac2ceef 100644
--- a/src/ports/SkFontMgr_win_dw.cpp
+++ b/src/ports/SkFontMgr_win_dw.cpp
@@ -17,12 +17,12 @@
#include "SkTScopedComPtr.h"
#include "SkTypeface.h"
#include "SkTypefaceCache.h"
-#include "SkTypeface_win.h"
#include "SkTypeface_win_dw.h"
#include "SkTypes.h"
#include "SkUtils.h"
#include <dwrite.h>
+
#if SK_HAS_DWRITE_2_H
#include <dwrite_2.h>
#endif
diff --git a/src/ports/SkScalerContext_win_dw.cpp b/src/ports/SkScalerContext_win_dw.cpp
index 6deeb66ff6..c9ff5d86c3 100644
--- a/src/ports/SkScalerContext_win_dw.cpp
+++ b/src/ports/SkScalerContext_win_dw.cpp
@@ -34,14 +34,6 @@
#include <dwrite.h>
#if SK_HAS_DWRITE_1_H
# include <dwrite_1.h>
-#else
-# pragma message("No dwrite_1.h is available, font metrics may be affected.")
-#endif
-
-#if SK_HAS_DWRITE_2_H
-# include <dwrite_2.h>
-#else
-# pragma message("No dwrite_2.h is available, pixel antialiased glyph quality may be affected.")
#endif
/* Note:
@@ -220,9 +212,11 @@ SkScalerContext_DW::SkScalerContext_DW(DWriteFontTypeface* typeface,
, fGlyphCount(-1) {
#if SK_HAS_DWRITE_2_H
- fIsColorFont = fTypeface->fFactory2 &&
- fTypeface->fDWriteFontFace2 &&
- fTypeface->fDWriteFontFace2->IsColorFont();
+ fTypeface->fFactory->QueryInterface<IDWriteFactory2>(&fFactory2);
+
+ SkTScopedComPtr<IDWriteFontFace2> fontFace2;
+ fTypeface->fDWriteFontFace->QueryInterface<IDWriteFontFace2>(&fontFace2);
+ fIsColorFont = fFactory2.get() && fontFace2.get() && fontFace2->IsColorFont();
#endif
// In general, all glyphs should use CLEARTYPE_NATURAL_SYMMETRIC
@@ -330,30 +324,6 @@ SkScalerContext_DW::SkScalerContext_DW(DWriteFontTypeface* typeface,
fMeasuringMode = DWRITE_MEASURING_MODE_NATURAL;
}
- // DirectWrite2 allows for grayscale hinting.
-#if SK_HAS_DWRITE_2_H
- fAntiAliasMode = DWRITE_TEXT_ANTIALIAS_MODE_CLEARTYPE;
-#ifndef SK_IGNORE_DW_GRAY_FIX
- if (fTypeface->fFactory2 && fTypeface->fDWriteFontFace2 &&
- !isLCD(fRec) && !(fRec.fFlags & SkScalerContext::kGenA8FromLCD_Flag))
- {
- // DWRITE_TEXTURE_ALIASED_1x1 is now misnamed, it must also be used with grayscale.
- fTextureType = DWRITE_TEXTURE_ALIASED_1x1;
- fAntiAliasMode = DWRITE_TEXT_ANTIALIAS_MODE_GRAYSCALE;
- }
-#endif
-#endif
-
- // DirectWrite2 allows hinting to be disabled.
-#if SK_HAS_DWRITE_2_H
- fGridFitMode = DWRITE_GRID_FIT_MODE_ENABLED;
- if (fTypeface->fFactory2 && fTypeface->fDWriteFontFace2 &&
- fRec.getHinting() == SkPaint::kNo_Hinting)
- {
- fGridFitMode = DWRITE_GRID_FIT_MODE_DISABLED;
- }
-#endif
-
if (this->isSubpixel()) {
fTextSizeMeasure = realTextSize;
fMeasuringMode = DWRITE_MEASURING_MODE_NATURAL;
@@ -462,31 +432,16 @@ HRESULT SkScalerContext_DW::getBoundingBox(SkGlyph* glyph,
SkTScopedComPtr<IDWriteGlyphRunAnalysis> glyphRunAnalysis;
{
SkAutoExclusive l(DWriteFactoryMutex);
- if (fTypeface->fFactory2) {
-#if SK_HAS_DWRITE_2_H
- HRNM(fTypeface->fFactory2->CreateGlyphRunAnalysis(
- &run,
- &fXform,
- renderingMode,
- fMeasuringMode,
- fGridFitMode,
- fAntiAliasMode,
- 0.0f, // baselineOriginX,
- 0.0f, // baselineOriginY,
- &glyphRunAnalysis),
- "Could not create DW2 glyph run analysis.");
-#endif
- } else {
- HRNM(fTypeface->fFactory->CreateGlyphRunAnalysis(&run,
- 1.0f, // pixelsPerDip,
- &fXform,
- renderingMode,
- fMeasuringMode,
- 0.0f, // baselineOriginX,
- 0.0f, // baselineOriginY,
- &glyphRunAnalysis),
- "Could not create glyph run analysis.");
- }
+ HRM(fTypeface->fFactory->CreateGlyphRunAnalysis(
+ &run,
+ 1.0f, // pixelsPerDip,
+ &fXform,
+ renderingMode,
+ fMeasuringMode,
+ 0.0f, // baselineOriginX,
+ 0.0f, // baselineOriginY,
+ &glyphRunAnalysis),
+ "Could not create glyph run analysis.");
}
{
Shared l(DWriteFactoryMutex);
@@ -543,7 +498,7 @@ bool SkScalerContext_DW::getColorGlyphRun(const SkGlyph& glyph,
run.isSideways = FALSE;
run.glyphOffsets = &offset;
- HRESULT hr = fTypeface->fFactory2->TranslateColorGlyphRun(
+ HRESULT hr = fFactory2->TranslateColorGlyphRun(
0, 0, &run, nullptr, fMeasuringMode, &fXform, 0, colorGlyph);
if (hr == DWRITE_E_NOCOLOR) {
return false;
@@ -636,6 +591,8 @@ void SkScalerContext_DW::generateFontMetrics(SkPaint::FontMetrics* metrics) {
metrics->fMaxCharWidth = metrics->fXMax - metrics->fXMin;
return;
}
+#else
+# pragma message("No dwrite_1.h is available, font metrics may be affected.")
#endif
AutoTDWriteTable<SkOTTableHead> head(fTypeface->fDWriteFontFace.get());
@@ -699,22 +656,6 @@ static void bilevel_to_bw(const uint8_t* SK_RESTRICT src, const SkGlyph& glyph)
}
template<bool APPLY_PREBLEND>
-static void grayscale_to_a8(const uint8_t* SK_RESTRICT src, const SkGlyph& glyph,
- const uint8_t* table8) {
- const size_t dstRB = glyph.rowBytes();
- const U16CPU width = glyph.fWidth;
- uint8_t* SK_RESTRICT dst = static_cast<uint8_t*>(glyph.fImage);
-
- for (U16CPU y = 0; y < glyph.fHeight; y++) {
- for (U16CPU i = 0; i < width; i++) {
- U8CPU a = *(src++);
- dst[i] = sk_apply_lut_if<APPLY_PREBLEND>(a, table8);
- }
- dst = SkTAddOffset<uint8_t>(dst, dstRB);
- }
-}
-
-template<bool APPLY_PREBLEND>
static void rgb_to_a8(const uint8_t* SK_RESTRICT src, const SkGlyph& glyph, const uint8_t* table8) {
const size_t dstRB = glyph.rowBytes();
const U16CPU width = glyph.fWidth;
@@ -727,7 +668,7 @@ static void rgb_to_a8(const uint8_t* SK_RESTRICT src, const SkGlyph& glyph, cons
U8CPU b = *(src++);
dst[i] = sk_apply_lut_if<APPLY_PREBLEND>((r + g + b) / 3, table8);
}
- dst = SkTAddOffset<uint8_t>(dst, dstRB);
+ dst = (uint8_t*)((char*)dst + dstRB);
}
}
@@ -752,7 +693,7 @@ static void rgb_to_lcd16(const uint8_t* SK_RESTRICT src, const SkGlyph& glyph,
}
dst[i] = SkPack888ToRGB16(r, g, b);
}
- dst = SkTAddOffset<uint16_t>(dst, dstRB);
+ dst = (uint16_t*)((char*)dst + dstRB);
}
}
@@ -761,7 +702,7 @@ const void* SkScalerContext_DW::drawDWMask(const SkGlyph& glyph,
DWRITE_TEXTURE_TYPE textureType)
{
int sizeNeeded = glyph.fWidth * glyph.fHeight;
- if (DWRITE_TEXTURE_CLEARTYPE_3x1 == textureType) {
+ if (DWRITE_RENDERING_MODE_ALIASED != renderingMode) {
sizeNeeded *= 3;
}
if (sizeNeeded > fBits.count()) {
@@ -792,33 +733,19 @@ const void* SkScalerContext_DW::drawDWMask(const SkGlyph& glyph,
run.isSideways = FALSE;
run.glyphOffsets = &offset;
{
+
SkTScopedComPtr<IDWriteGlyphRunAnalysis> glyphRunAnalysis;
{
SkAutoExclusive l(DWriteFactoryMutex);
- if (fTypeface->fFactory2) {
-#if SK_HAS_DWRITE_2_H
- HRNM(fTypeface->fFactory2->CreateGlyphRunAnalysis(&run,
- &fXform,
- renderingMode,
- fMeasuringMode,
- fGridFitMode,
- fAntiAliasMode,
- 0.0f, // baselineOriginX,
- 0.0f, // baselineOriginY,
- &glyphRunAnalysis),
- "Could not create DW2 glyph run analysis.");
-#endif
- } else {
- HRNM(fTypeface->fFactory->CreateGlyphRunAnalysis(&run,
- 1.0f, // pixelsPerDip,
- &fXform,
- renderingMode,
- fMeasuringMode,
- 0.0f, // baselineOriginX,
- 0.0f, // baselineOriginY,
- &glyphRunAnalysis),
- "Could not create glyph run analysis.");
- }
+ HRNM(fTypeface->fFactory->CreateGlyphRunAnalysis(&run,
+ 1.0f, // pixelsPerDip,
+ &fXform,
+ renderingMode,
+ fMeasuringMode,
+ 0.0f, // baselineOriginX,
+ 0.0f, // baselineOriginY,
+ &glyphRunAnalysis),
+ "Could not create glyph run analysis.");
}
//NOTE: this assumes that the glyph has already been measured
//with an exact same glyph run analysis.
@@ -938,18 +865,10 @@ void SkScalerContext_DW::generateImage(const SkGlyph& glyph) {
bilevel_to_bw(src, glyph);
const_cast<SkGlyph&>(glyph).fMaskFormat = SkMask::kBW_Format;
} else if (!isLCD(fRec)) {
- if (textureType == DWRITE_TEXTURE_ALIASED_1x1) {
- if (fPreBlend.isApplicable()) {
- grayscale_to_a8<true>(src, glyph, fPreBlend.fG);
- } else {
- grayscale_to_a8<false>(src, glyph, fPreBlend.fG);
- }
+ if (fPreBlend.isApplicable()) {
+ rgb_to_a8<true>(src, glyph, fPreBlend.fG);
} else {
- if (fPreBlend.isApplicable()) {
- rgb_to_a8<true>(src, glyph, fPreBlend.fG);
- } else {
- rgb_to_a8<false>(src, glyph, fPreBlend.fG);
- }
+ rgb_to_a8<false>(src, glyph, fPreBlend.fG);
}
} else {
SkASSERT(SkMask::kLCD16_Format == glyph.fMaskFormat);
diff --git a/src/ports/SkScalerContext_win_dw.h b/src/ports/SkScalerContext_win_dw.h
index defd4134c5..98c4910b27 100644
--- a/src/ports/SkScalerContext_win_dw.h
+++ b/src/ports/SkScalerContext_win_dw.h
@@ -15,7 +15,7 @@
#include <dwrite.h>
#if SK_HAS_DWRITE_2_H
-# include <dwrite_2.h>
+#include <dwrite_2.h>
#endif
class SkGlyph;
@@ -76,10 +76,9 @@ private:
DWRITE_TEXTURE_TYPE fTextureType;
DWRITE_MEASURING_MODE fMeasuringMode;
#if SK_HAS_DWRITE_2_H
- DWRITE_TEXT_ANTIALIAS_MODE fAntiAliasMode;
- DWRITE_GRID_FIT_MODE fGridFitMode;
-#endif
+ SkTScopedComPtr<IDWriteFactory2> fFactory2;
bool fIsColorFont;
+#endif
};
#endif
diff --git a/src/ports/SkTypeface_win_dw.cpp b/src/ports/SkTypeface_win_dw.cpp
index 78e3cac558..a12438c88f 100644
--- a/src/ports/SkTypeface_win_dw.cpp
+++ b/src/ports/SkTypeface_win_dw.cpp
@@ -252,7 +252,6 @@ SkScalerContext* DWriteFontTypeface::onCreateScalerContext(const SkScalerContext
void DWriteFontTypeface::onFilterRec(SkScalerContext::Rec* rec) const {
if (rec->fFlags & SkScalerContext::kLCD_Vertical_Flag) {
rec->fMaskFormat = SkMask::kA8_Format;
- rec->fFlags |= SkScalerContext::kGenA8FromLCD_Flag;
}
unsigned flagsWeDontSupport = SkScalerContext::kVertical_Flag |
@@ -263,10 +262,8 @@ void DWriteFontTypeface::onFilterRec(SkScalerContext::Rec* rec) const {
rec->fFlags &= ~flagsWeDontSupport;
SkPaint::Hinting h = rec->getHinting();
- // DirectWrite2 allows for hinting to be turned off. Force everything else to normal.
- if (h != SkPaint::kNo_Hinting || !fFactory2 || !fDWriteFontFace2) {
- h = SkPaint::kNormal_Hinting;
- }
+ // DirectWrite does not provide for hinting hints.
+ h = SkPaint::kSlight_Hinting;
rec->setHinting(h);
#if defined(SK_FONT_HOST_USE_SYSTEM_SETTINGS)
diff --git a/src/ports/SkTypeface_win_dw.h b/src/ports/SkTypeface_win_dw.h
index 4d1767ba2f..11b3fb5ffc 100644
--- a/src/ports/SkTypeface_win_dw.h
+++ b/src/ports/SkTypeface_win_dw.h
@@ -20,9 +20,6 @@
#if SK_HAS_DWRITE_1_H
# include <dwrite_1.h>
#endif
-#if SK_HAS_DWRITE_2_H
-# include <dwrite_2.h>
-#endif
class SkFontDescriptor;
struct SkScalerContextRec;
@@ -64,23 +61,10 @@ private:
SkASSERT_RELEASE(nullptr == fDWriteFontFace1.get());
}
#endif
-#if SK_HAS_DWRITE_2_H
- if (!SUCCEEDED(fDWriteFontFace->QueryInterface(&fDWriteFontFace2))) {
- SkASSERT_RELEASE(nullptr == fDWriteFontFace2.get());
- }
- if (!SUCCEEDED(fFactory->QueryInterface(&fFactory2))) {
- SkASSERT_RELEASE(nullptr == fFactory2.get());
- }
-#endif
}
public:
SkTScopedComPtr<IDWriteFactory> fFactory;
-#if SK_HAS_DWRITE_2_H
- SkTScopedComPtr<IDWriteFactory2> fFactory2;
-#else
- const decltype(nullptr) fFactory2 = nullptr;
-#endif
SkTScopedComPtr<IDWriteFontCollectionLoader> fDWriteFontCollectionLoader;
SkTScopedComPtr<IDWriteFontFileLoader> fDWriteFontFileLoader;
SkTScopedComPtr<IDWriteFontFamily> fDWriteFontFamily;
@@ -89,11 +73,6 @@ public:
#if SK_HAS_DWRITE_1_H
SkTScopedComPtr<IDWriteFontFace1> fDWriteFontFace1;
#endif
-#if SK_HAS_DWRITE_2_H
- SkTScopedComPtr<IDWriteFontFace2> fDWriteFontFace2;
-#else
- const decltype(nullptr) fDWriteFontFace2 = nullptr;
-#endif
static DWriteFontTypeface* Create(IDWriteFactory* factory,
IDWriteFontFace* fontFace,