Changeset 102816 in webkit
- Timestamp:
- Dec 14, 2011 1:21:38 PM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r102815 r102816 1 2011-12-14 Mike Reed <reed@google.com> 2 3 [skia] cache typeface in FontPlatformData 4 https://bugs.webkit.org/show_bug.cgi?id=74415 5 6 Reviewed by Stephen White. 7 8 No new tests. Existing tests apply, this is just an optimization 9 to avoid looking up the typeface on each drawText call. 10 11 * platform/graphics/chromium/FontChromiumWin.cpp: 12 (WebCore::TransparencyAwareFontPainter::TransparencyAwareGlyphPainter::drawGlyphs): 13 (WebCore::Font::drawGlyphs): 14 * platform/graphics/chromium/FontPlatformDataChromiumWin.cpp: 15 (WebCore::createTypefaceFromHFont): 16 (WebCore::FontPlatformData::FontPlatformData): 17 (WebCore::FontPlatformData::operator=): 18 (WebCore::FontPlatformData::~FontPlatformData): 19 * platform/graphics/chromium/FontPlatformDataChromiumWin.h: 20 (WebCore::FontPlatformData::typeface): 21 (WebCore::FontPlatformData::lfQuality): 22 (WebCore::FontPlatformData::hash): 23 (WebCore::FontPlatformData::operator==): 24 * platform/graphics/skia/SkiaFontWin.cpp: 25 (WebCore::setupPaintForFont): 26 (WebCore::paintSkiaText): 27 * platform/graphics/skia/SkiaFontWin.h: 28 1 29 2011-12-14 Simon Fraser <simon.fraser@apple.com> 2 30 -
trunk/Source/WebCore/platform/graphics/chromium/FontChromiumWin.cpp
r98692 r102816 266 266 SkPoint origin = m_point; 267 267 origin.fX += SkFloatToScalar(startAdvance); 268 paintSkiaText(m_graphicsContext, m_font->platformData() .hfont(),268 paintSkiaText(m_graphicsContext, m_font->platformData(), 269 269 numGlyphs, glyphs, advances, 0, &origin); 270 270 return true; … … 394 394 if (!alpha && graphicsContext->platformContext()->getStrokeStyle() == NoStroke && !graphicsContext->hasShadow()) 395 395 return; 396 397 HFONT hfont = font->platformData().hfont();398 396 399 397 // We draw the glyphs in chunks to avoid having to do a heap allocation for … … 437 435 SkPoint origin = point; 438 436 origin.fX += SkFloatToScalar(horizontalOffset - point.x() - currentWidth); 439 paintSkiaText(graphicsContext, hfont, curLen, &glyphs[0], &advances[0], 0, &origin);437 paintSkiaText(graphicsContext, font->platformData(), curLen, &glyphs[0], &advances[0], 0, &origin); 440 438 } 441 439 } -
trunk/Source/WebCore/platform/graphics/chromium/FontPlatformDataChromiumWin.cpp
r95901 r102816 38 38 39 39 #include "PlatformSupport.h" 40 #include "SkTypeface_win.h" 40 41 #include "SkiaFontWin.h" 41 42 #include "StdLibExtras.h" 42 43 43 44 namespace WebCore { 45 46 static SkTypeface* createTypefaceFromHFont(HFONT hfont, uint8_t* lfQuality) 47 { 48 LOGFONT info; 49 GetObject(hfont, sizeof(info), &info); 50 *lfQuality = info.lfQuality; 51 return SkCreateTypefaceFromLOGFONT(info); 52 } 44 53 45 54 FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType) … … 48 57 , m_scriptCache(0) 49 58 , m_scriptFontProperties(0) 59 , m_typeface(0) 60 , m_lfQuality(DEFAULT_QUALITY) 50 61 { 51 62 } … … 56 67 , m_scriptCache(0) 57 68 , m_scriptFontProperties(0) 69 , m_typeface(0) 70 , m_lfQuality(DEFAULT_QUALITY) 58 71 { 59 72 } … … 64 77 , m_scriptCache(0) 65 78 , m_scriptFontProperties(0) 79 , m_typeface(createTypefaceFromHFont(font, &m_lfQuality)) 66 80 { 67 81 } … … 73 87 , m_scriptCache(0) 74 88 , m_scriptFontProperties(0) 89 , m_typeface(0) 90 , m_lfQuality(DEFAULT_QUALITY) 75 91 { 76 92 } … … 81 97 , m_scriptCache(0) 82 98 , m_scriptFontProperties(0) 99 , m_typeface(data.m_typeface) 100 , m_lfQuality(data.m_lfQuality) 83 101 { 102 SkSafeRef(m_typeface); 84 103 } 85 104 … … 89 108 m_font = data.m_font; 90 109 m_size = data.m_size; 110 SkRefCnt_SafeAssign(m_typeface, data.m_typeface); 111 m_lfQuality = data.m_lfQuality; 91 112 92 113 // The following fields will get re-computed if necessary. … … 102 123 FontPlatformData::~FontPlatformData() 103 124 { 125 SkSafeUnref(m_typeface); 126 104 127 ScriptFreeCache(&m_scriptCache); 105 128 m_scriptCache = 0; -
trunk/Source/WebCore/platform/graphics/chromium/FontPlatformDataChromiumWin.h
r95901 r102816 36 36 37 37 #include "FontOrientation.h" 38 #include "SkTypeface.h" 38 39 #include <wtf/Forward.h> 39 40 #include <wtf/PassRefPtr.h> … … 70 71 HFONT hfont() const { return m_font ? m_font->hfont() : 0; } 71 72 float size() const { return m_size; } 73 SkTypeface* typeface() const { return m_typeface; } 74 uint8_t lfQuality() const { return m_lfQuality; } 72 75 73 76 FontOrientation orientation() const { return Horizontal; } // FIXME: Implement. … … 75 78 76 79 unsigned hash() const 77 { 80 { 78 81 return m_font ? m_font->hash() : NULL; 79 82 } … … 130 133 float m_size; // Point size of the font in pixels. 131 134 135 SkTypeface* m_typeface; // cached from m_font 136 uint8_t m_lfQuality; // cached from m_font 137 132 138 mutable SCRIPT_CACHE m_scriptCache; 133 139 mutable SCRIPT_FONTPROPERTIES* m_scriptFontProperties; -
trunk/Source/WebCore/platform/graphics/skia/SkiaFontWin.cpp
r98692 r102816 33 33 34 34 #include "AffineTransform.h" 35 #include "Gradient.h" 36 #include "Pattern.h" 35 37 #include "PlatformContextSkia.h" 36 38 #include "PlatformSupport.h" 37 #include "Gradient.h" 38 #include "Pattern.h" 39 #include "SimpleFontData.h" 39 40 #include "SkCanvas.h" 40 41 #include "SkDevice.h" … … 42 43 #include "SkShader.h" 43 44 #include "SkTemplates.h" 44 #include "SkTypeface_win.h"45 45 46 46 namespace WebCore { … … 180 180 } 181 181 182 static void setupPaintForFont(HFONT hfont, SkPaint* paint, PlatformContextSkia* pcs) 183 { 184 // FIXME: 185 // Much of this logic could also happen in 186 // FontCustomPlatformData::fontPlatformData and be cached, 187 // allowing us to avoid talking to GDI at this point. 188 // 189 LOGFONT info; 190 GetObject(hfont, sizeof(info), &info); 191 int size = info.lfHeight; 192 if (size < 0) 193 size = -size; // We don't let GDI dpi-scale us (see SkFontHost_win.cpp). 194 paint->setTextSize(SkIntToScalar(size)); 195 196 SkTypeface* face = SkCreateTypefaceFromLOGFONT(info); 197 paint->setTypeface(face); 198 SkSafeUnref(face); 182 static void setupPaintForFont(SkPaint* paint, const FontPlatformData& font, PlatformContextSkia* pcs) 183 { 184 paint->setTextSize(SkFloatToScalar(font.size())); 185 paint->setTypeface(font.typeface()); 199 186 200 187 // turn lfQuality into text flags 201 188 uint32_t textFlags; 202 switch ( info.lfQuality) {189 switch (font.lfQuality()) { 203 190 case NONANTIALIASED_QUALITY: 204 191 textFlags = 0; … … 229 216 230 217 void paintSkiaText(GraphicsContext* context, 231 HFONT hfont,218 const FontPlatformData& font, 232 219 int numGlyphs, 233 220 const WORD* glyphs, … … 241 228 // Ensure font load for printing, because PDF device needs it. 242 229 if (canvas->getTopDevice()->getDeviceCapabilities() & SkDevice::kVector_Capability) 243 PlatformSupport::ensureFontLoaded( hfont);230 PlatformSupport::ensureFontLoaded(font.hfont()); 244 231 245 232 // Filling (if necessary). This is the common case. … … 247 234 platformContext->setupPaintForFilling(&paint); 248 235 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); 249 setupPaintForFont( hfont, &paint, platformContext);236 setupPaintForFont(&paint, font, platformContext); 250 237 251 238 bool didFill = false; … … 264 251 platformContext->setupPaintForStroking(&paint, 0, 0); 265 252 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); 266 setupPaintForFont( hfont, &paint, platformContext);253 setupPaintForFont(&paint, font, platformContext); 267 254 268 255 if (didFill) { … … 283 270 } 284 271 272 void paintSkiaText(GraphicsContext* context, 273 HFONT hfont, 274 int numGlyphs, 275 const WORD* glyphs, 276 const int* advances, 277 const GOFFSET* offsets, 278 const SkPoint* origin) 279 { 280 LOGFONT info; 281 GetObject(hfont, sizeof(info), &info); 282 float size = info.lfHeight; 283 if (size < 0) 284 size = -size; 285 286 FontPlatformData font(hfont, size); 287 paintSkiaText(context, font, numGlyphs, glyphs, advances, offsets, origin); 288 } 289 285 290 } // namespace WebCore -
trunk/Source/WebCore/platform/graphics/skia/SkiaFontWin.h
r97573 r102816 39 39 namespace WebCore { 40 40 41 class FontPlatformData; 41 42 class GraphicsContext; 42 43 class PlatformContextSkia; … … 73 74 // per glyph offset (such as returned by ScriptPlace Windows API function). 74 75 void paintSkiaText(GraphicsContext*, 76 const FontPlatformData&, 77 int numGlyphs, 78 const WORD* glyphs, 79 const int* advances, 80 const GOFFSET* offsets, 81 const SkPoint* origin); 82 83 // Convenience call for clients that don't cache the typeface or size 84 void paintSkiaText(GraphicsContext*, 75 85 HFONT, 76 86 int numGlyphs,
Note: See TracChangeset
for help on using the changeset viewer.