Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(338)

Side by Side Diff: core/fxge/ge/cfx_facecache.cpp

Issue 2350243002: Make CFX_FontCache global (Closed)
Patch Set: Remove fix leaks code. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fxge/apple/fx_quartz_device.cpp ('k') | core/fxge/ge/cfx_font.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fxge/include/cfx_facecache.h" 7 #include "core/fxge/include/cfx_facecache.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 #endif 82 #endif
83 { 83 {
84 } 84 }
85 85
86 CFX_FaceCache::~CFX_FaceCache() { 86 CFX_FaceCache::~CFX_FaceCache() {
87 #ifdef _SKIA_SUPPORT_ 87 #ifdef _SKIA_SUPPORT_
88 SkSafeUnref(m_pTypeface); 88 SkSafeUnref(m_pTypeface);
89 #endif 89 #endif
90 } 90 }
91 91
92 CFX_GlyphBitmap* CFX_FaceCache::RenderGlyph(CFX_Font* pFont, 92 CFX_GlyphBitmap* CFX_FaceCache::RenderGlyph(const CFX_Font* pFont,
93 uint32_t glyph_index, 93 uint32_t glyph_index,
94 FX_BOOL bFontStyle, 94 FX_BOOL bFontStyle,
95 const CFX_Matrix* pMatrix, 95 const CFX_Matrix* pMatrix,
96 int dest_width, 96 int dest_width,
97 int anti_alias) { 97 int anti_alias) {
98 if (!m_Face) 98 if (!m_Face)
99 return nullptr; 99 return nullptr;
100 100
101 FXFT_Matrix ft_matrix; 101 FXFT_Matrix ft_matrix;
102 ft_matrix.xx = (signed long)(pMatrix->GetA() / 64 * 65536); 102 ft_matrix.xx = (signed long)(pMatrix->GetA() / 64 * 65536);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 } else { 216 } else {
217 ContrastAdjust(pSrcBuf, pDestBuf, bmwidth, bmheight, src_pitch, 217 ContrastAdjust(pSrcBuf, pDestBuf, bmwidth, bmheight, src_pitch,
218 dest_pitch); 218 dest_pitch);
219 GammaAdjust(pDestBuf, bmheight, dest_pitch, 219 GammaAdjust(pDestBuf, bmheight, dest_pitch,
220 CFX_GEModule::Get()->GetTextGammaTable()); 220 CFX_GEModule::Get()->GetTextGammaTable());
221 } 221 }
222 } 222 }
223 return pGlyphBitmap; 223 return pGlyphBitmap;
224 } 224 }
225 225
226 const CFX_PathData* CFX_FaceCache::LoadGlyphPath(CFX_Font* pFont, 226 const CFX_PathData* CFX_FaceCache::LoadGlyphPath(const CFX_Font* pFont,
227 uint32_t glyph_index, 227 uint32_t glyph_index,
228 int dest_width) { 228 int dest_width) {
229 if (!m_Face || glyph_index == kInvalidGlyphIndex || dest_width < 0) 229 if (!m_Face || glyph_index == kInvalidGlyphIndex || dest_width < 0)
230 return nullptr; 230 return nullptr;
231 231
232 uint32_t key = glyph_index; 232 uint32_t key = glyph_index;
233 auto* pSubstFont = pFont->GetSubstFont(); 233 auto* pSubstFont = pFont->GetSubstFont();
234 if (pSubstFont) { 234 if (pSubstFont) {
235 if (pSubstFont->m_Weight < 0 || pSubstFont->m_ItalicAngle < 0) 235 if (pSubstFont->m_Weight < 0 || pSubstFont->m_ItalicAngle < 0)
236 return nullptr; 236 return nullptr;
237 uint32_t weight = static_cast<uint32_t>(pSubstFont->m_Weight); 237 uint32_t weight = static_cast<uint32_t>(pSubstFont->m_Weight);
238 uint32_t angle = static_cast<uint32_t>(pSubstFont->m_ItalicAngle); 238 uint32_t angle = static_cast<uint32_t>(pSubstFont->m_ItalicAngle);
239 uint32_t key_modifier = (weight / 16) << 15; 239 uint32_t key_modifier = (weight / 16) << 15;
240 key_modifier += (angle / 2) << 21; 240 key_modifier += (angle / 2) << 21;
241 key_modifier += (static_cast<uint32_t>(dest_width) / 16) << 25; 241 key_modifier += (static_cast<uint32_t>(dest_width) / 16) << 25;
242 if (pFont->IsVertical()) 242 if (pFont->IsVertical())
243 key_modifier += 1U << 31; 243 key_modifier += 1U << 31;
244 key += key_modifier; 244 key += key_modifier;
245 } 245 }
246 auto it = m_PathMap.find(key); 246 auto it = m_PathMap.find(key);
247 if (it != m_PathMap.end()) 247 if (it != m_PathMap.end())
248 return it->second.get(); 248 return it->second.get();
249 249
250 CFX_PathData* pGlyphPath = pFont->LoadGlyphPath(glyph_index, dest_width); 250 CFX_PathData* pGlyphPath = pFont->LoadGlyphPathImpl(glyph_index, dest_width);
251 m_PathMap[key] = std::unique_ptr<CFX_PathData>(pGlyphPath); 251 m_PathMap[key] = std::unique_ptr<CFX_PathData>(pGlyphPath);
252 return pGlyphPath; 252 return pGlyphPath;
253 } 253 }
254 254
255 const CFX_GlyphBitmap* CFX_FaceCache::LoadGlyphBitmap(CFX_Font* pFont, 255 const CFX_GlyphBitmap* CFX_FaceCache::LoadGlyphBitmap(const CFX_Font* pFont,
256 uint32_t glyph_index, 256 uint32_t glyph_index,
257 FX_BOOL bFontStyle, 257 FX_BOOL bFontStyle,
258 const CFX_Matrix* pMatrix, 258 const CFX_Matrix* pMatrix,
259 int dest_width, 259 int dest_width,
260 int anti_alias, 260 int anti_alias,
261 int& text_flags) { 261 int& text_flags) {
262 if (glyph_index == kInvalidGlyphIndex) 262 if (glyph_index == kInvalidGlyphIndex)
263 return nullptr; 263 return nullptr;
264 264
265 _CFX_UniqueKeyGen keygen; 265 _CFX_UniqueKeyGen keygen;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 anti_alias); 342 anti_alias);
343 } 343 }
344 CFX_ByteString FaceGlyphsKey2(keygen.m_Key, keygen.m_KeyLen); 344 CFX_ByteString FaceGlyphsKey2(keygen.m_Key, keygen.m_KeyLen);
345 text_flags |= FXTEXT_NO_NATIVETEXT; 345 text_flags |= FXTEXT_NO_NATIVETEXT;
346 return LookUpGlyphBitmap(pFont, pMatrix, FaceGlyphsKey2, glyph_index, 346 return LookUpGlyphBitmap(pFont, pMatrix, FaceGlyphsKey2, glyph_index,
347 bFontStyle, dest_width, anti_alias); 347 bFontStyle, dest_width, anti_alias);
348 #endif 348 #endif
349 } 349 }
350 350
351 #ifdef _SKIA_SUPPORT_ 351 #ifdef _SKIA_SUPPORT_
352 CFX_TypeFace* CFX_FaceCache::GetDeviceCache(CFX_Font* pFont) { 352 CFX_TypeFace* CFX_FaceCache::GetDeviceCache(const CFX_Font* pFont) {
353 if (!m_pTypeface) { 353 if (!m_pTypeface) {
354 m_pTypeface = 354 m_pTypeface =
355 SkTypeface::MakeFromStream( 355 SkTypeface::MakeFromStream(
356 new SkMemoryStream(pFont->GetFontData(), pFont->GetSize())) 356 new SkMemoryStream(pFont->GetFontData(), pFont->GetSize()))
357 .release(); 357 .release();
358 } 358 }
359 return m_pTypeface; 359 return m_pTypeface;
360 } 360 }
361 #endif 361 #endif
362 362
363 #if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ 363 #if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_
364 void CFX_FaceCache::InitPlatform() {} 364 void CFX_FaceCache::InitPlatform() {}
365 #endif 365 #endif
366 366
367 CFX_GlyphBitmap* CFX_FaceCache::LookUpGlyphBitmap( 367 CFX_GlyphBitmap* CFX_FaceCache::LookUpGlyphBitmap(
368 CFX_Font* pFont, 368 const CFX_Font* pFont,
369 const CFX_Matrix* pMatrix, 369 const CFX_Matrix* pMatrix,
370 const CFX_ByteString& FaceGlyphsKey, 370 const CFX_ByteString& FaceGlyphsKey,
371 uint32_t glyph_index, 371 uint32_t glyph_index,
372 FX_BOOL bFontStyle, 372 FX_BOOL bFontStyle,
373 int dest_width, 373 int dest_width,
374 int anti_alias) { 374 int anti_alias) {
375 CFX_SizeGlyphCache* pSizeCache; 375 CFX_SizeGlyphCache* pSizeCache;
376 auto it = m_SizeMap.find(FaceGlyphsKey); 376 auto it = m_SizeMap.find(FaceGlyphsKey);
377 if (it == m_SizeMap.end()) { 377 if (it == m_SizeMap.end()) {
378 pSizeCache = new CFX_SizeGlyphCache; 378 pSizeCache = new CFX_SizeGlyphCache;
379 m_SizeMap[FaceGlyphsKey] = std::unique_ptr<CFX_SizeGlyphCache>(pSizeCache); 379 m_SizeMap[FaceGlyphsKey] = std::unique_ptr<CFX_SizeGlyphCache>(pSizeCache);
380 } else { 380 } else {
381 pSizeCache = it->second.get(); 381 pSizeCache = it->second.get();
382 } 382 }
383 auto it2 = pSizeCache->m_GlyphMap.find(glyph_index); 383 auto it2 = pSizeCache->m_GlyphMap.find(glyph_index);
384 if (it2 != pSizeCache->m_GlyphMap.end()) 384 if (it2 != pSizeCache->m_GlyphMap.end())
385 return it2->second; 385 return it2->second;
386 386
387 CFX_GlyphBitmap* pGlyphBitmap = RenderGlyph(pFont, glyph_index, bFontStyle, 387 CFX_GlyphBitmap* pGlyphBitmap = RenderGlyph(pFont, glyph_index, bFontStyle,
388 pMatrix, dest_width, anti_alias); 388 pMatrix, dest_width, anti_alias);
389 pSizeCache->m_GlyphMap[glyph_index] = pGlyphBitmap; 389 pSizeCache->m_GlyphMap[glyph_index] = pGlyphBitmap;
390 return pGlyphBitmap; 390 return pGlyphBitmap;
391 } 391 }
OLDNEW
« no previous file with comments | « core/fxge/apple/fx_quartz_device.cpp ('k') | core/fxge/ge/cfx_font.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698