Changeset 103262 in webkit
- Timestamp:
- Dec 19, 2011 1:40:00 PM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r103251 r103262 1 2011-12-19 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. optimization only, existing tests in play 9 10 * platform/graphics/chromium/FontChromiumWin.cpp: 11 (WebCore::TransparencyAwareFontPainter::TransparencyAwareGlyphPainter::drawGlyphs): 12 (WebCore::Font::drawGlyphs): 13 * platform/graphics/chromium/FontPlatformDataChromiumWin.cpp: 14 (WebCore::CreateTypefaceFromHFont): 15 (WebCore::FontPlatformData::FontPlatformData): 16 (WebCore::FontPlatformData::operator=): 17 (WebCore::FontPlatformData::~FontPlatformData): 18 * platform/graphics/chromium/FontPlatformDataChromiumWin.h: 19 (WebCore::FontPlatformData::typeface): 20 (WebCore::FontPlatformData::lfQuality): 21 (WebCore::FontPlatformData::hash): 22 * platform/graphics/skia/SkiaFontWin.cpp: 23 (WebCore::setupPaintForFont): 24 (WebCore::paintSkiaText): 25 * platform/graphics/skia/SkiaFontWin.h: 26 1 27 2011-12-04 Robert Hogan <robert@webkit.org> 2 28 -
trunk/Source/WebCore/platform/graphics/chromium/FontChromiumWin.cpp
r102858 r103262 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
r102858 r103262 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 SkTypeface* CreateTypefaceFromHFont(HFONT hfont, int* size, int* lfQuality) 47 { 48 LOGFONT info; 49 GetObject(hfont, sizeof(info), &info); 50 if (size) { 51 int height = info.lfHeight; 52 if (height < 0) 53 height = -height; 54 *size = height; 55 } 56 if (lfQuality) 57 *lfQuality = info.lfQuality; 58 return SkCreateTypefaceFromLOGFONT(info); 59 } 44 60 45 61 FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType) … … 48 64 , m_scriptCache(0) 49 65 , m_scriptFontProperties(0) 66 , m_typeface(0) 67 , m_lfQuality(DEFAULT_QUALITY) 50 68 { 51 69 } … … 56 74 , m_scriptCache(0) 57 75 , m_scriptFontProperties(0) 76 , m_typeface(0) 77 , m_lfQuality(DEFAULT_QUALITY) 58 78 { 59 79 } … … 64 84 , m_scriptCache(0) 65 85 , m_scriptFontProperties(0) 86 , m_typeface(CreateTypefaceFromHFont(font, 0, &m_lfQuality)) 66 87 { 67 88 } … … 73 94 , m_scriptCache(0) 74 95 , m_scriptFontProperties(0) 96 , m_typeface(0) 97 , m_lfQuality(DEFAULT_QUALITY) 75 98 { 76 99 } … … 81 104 , m_scriptCache(0) 82 105 , m_scriptFontProperties(0) 106 , m_typeface(data.m_typeface) 107 , m_lfQuality(data.m_lfQuality) 83 108 { 109 SkSafeRef(m_typeface); 84 110 } 85 111 … … 89 115 m_font = data.m_font; 90 116 m_size = data.m_size; 117 SkRefCnt_SafeAssign(m_typeface, data.m_typeface); 118 m_lfQuality = data.m_lfQuality; 91 119 92 120 // The following fields will get re-computed if necessary. … … 102 130 FontPlatformData::~FontPlatformData() 103 131 { 132 SkSafeUnref(m_typeface); 133 104 134 ScriptFreeCache(&m_scriptCache); 105 135 m_scriptCache = 0; -
trunk/Source/WebCore/platform/graphics/chromium/FontPlatformDataChromiumWin.h
r102858 r103262 36 36 37 37 #include "FontOrientation.h" 38 #include "SkTypeface.h" 38 39 #include <wtf/Forward.h> 39 40 #include <wtf/PassRefPtr.h> … … 46 47 47 48 namespace WebCore { 49 50 // Return a typeface associated with the hfont, and return its size and 51 // lfQuality from the hfont's LOGFONT. The caller is now an owner of the 52 // typeface. 53 SkTypeface* CreateTypefaceFromHFont(HFONT, int* size, int* lfQuality); 48 54 49 55 class FontDescription; … … 58 64 FontPlatformData(WTF::HashTableDeletedValueType); 59 65 FontPlatformData(); 66 // This constructor takes ownership of the HFONT 60 67 FontPlatformData(HFONT, float size); 61 68 FontPlatformData(float size, bool bold, bool oblique); … … 70 77 HFONT hfont() const { return m_font ? m_font->hfont() : 0; } 71 78 float size() const { return m_size; } 79 SkTypeface* typeface() const { return m_typeface; } 80 int lfQuality() const { return m_lfQuality; } 72 81 73 82 FontOrientation orientation() const { return Horizontal; } // FIXME: Implement. … … 75 84 76 85 unsigned hash() const 77 { 86 { 78 87 return m_font ? m_font->hash() : NULL; 79 88 } … … 130 139 float m_size; // Point size of the font in pixels. 131 140 141 SkTypeface* m_typeface; // cached from m_font 142 int m_lfQuality; // cached from m_font 143 132 144 mutable SCRIPT_CACHE m_scriptCache; 133 145 mutable SCRIPT_FONTPROPERTIES* m_scriptFontProperties; -
trunk/Source/WebCore/platform/graphics/skia/SkiaFontWin.cpp
r102858 r103262 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); 182 static void setupPaintForFont(SkPaint* paint, PlatformContextSkia* pcs, 183 SkTypeface* face, float size, int quality) 184 { 185 paint->setTextSize(SkFloatToScalar(size)); 197 186 paint->setTypeface(face); 198 SkSafeUnref(face); 199 200 // turn lfQuality into text flags 187 188 // turn quality into text flags 201 189 uint32_t textFlags; 202 switch ( info.lfQuality) {190 switch (quality) { 203 191 case NONANTIALIASED_QUALITY: 204 192 textFlags = 0; … … 228 216 } 229 217 230 void paintSkiaText(GraphicsContext* context,231 HFONT hfont,232 int numGlyphs,233 const WORD* glyphs,234 const int* advances,235 const GOFFSET* offsets,236 const SkPoint* origin)218 static void paintSkiaText(GraphicsContext* context, HFONT hfont, 219 SkTypeface* face, float size, int quality, 220 int numGlyphs, 221 const WORD* glyphs, 222 const int* advances, 223 const GOFFSET* offsets, 224 const SkPoint* origin) 237 225 { 238 226 PlatformContextSkia* platformContext = context->platformContext(); … … 247 235 platformContext->setupPaintForFilling(&paint); 248 236 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); 249 setupPaintForFont( hfont, &paint, platformContext);237 setupPaintForFont(&paint, platformContext, face, size, quality); 250 238 251 239 bool didFill = false; … … 264 252 platformContext->setupPaintForStroking(&paint, 0, 0); 265 253 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); 266 setupPaintForFont( hfont, &paint, platformContext);254 setupPaintForFont(&paint, platformContext, face, size, quality); 267 255 268 256 if (didFill) { … … 283 271 } 284 272 273 /////////////////////////////////////////////////////////////////////////////////////////// 274 275 void paintSkiaText(GraphicsContext* context, 276 const FontPlatformData& data, 277 int numGlyphs, 278 const WORD* glyphs, 279 const int* advances, 280 const GOFFSET* offsets, 281 const SkPoint* origin) 282 { 283 paintSkiaText(context, data.hfont(), data.typeface(), data.size(), data.lfQuality(), 284 numGlyphs, glyphs, advances, offsets, origin); 285 } 286 287 void paintSkiaText(GraphicsContext* context, 288 HFONT hfont, 289 int numGlyphs, 290 const WORD* glyphs, 291 const int* advances, 292 const GOFFSET* offsets, 293 const SkPoint* origin) 294 { 295 int size; 296 int quality; 297 SkTypeface* face = CreateTypefaceFromHFont(hfont, &size, &quality); 298 SkAutoUnref aur(face); 299 300 paintSkiaText(context, hfont, face, size, quality, numGlyphs, glyphs, advances, offsets, origin); 301 } 302 285 303 } // namespace WebCore -
trunk/Source/WebCore/platform/graphics/skia/SkiaFontWin.h
r102858 r103262 39 39 namespace WebCore { 40 40 41 class FontPlatformData; 41 42 class GraphicsContext; 42 43 class PlatformContextSkia; … … 70 71 #endif 71 72 72 // Note that the offsets parameter is optional. If not NULLit represents a73 // Note that the offsets parameter is optional. If not null it represents a 73 74 // per glyph offset (such as returned by ScriptPlace Windows API function). 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 // Note that the offsets parameter is optional. If not null it represents a 84 // per glyph offset (such as returned by ScriptPlace Windows API function). 85 // Note: this is less efficient than calling the version with FontPlatformData, 86 // as that caches the SkTypeface object. 74 87 void paintSkiaText(GraphicsContext*, 75 88 HFONT,
Note: See TracChangeset
for help on using the changeset viewer.