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

Side by Side Diff: ui/gfx/render_text_harfbuzz.cc

Issue 1919123002: RenderTextMac: Cache the SkTypeface on the TextRun [reland] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes, and a test, but somewhat orthogonal Created 4 years, 7 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 | « ui/gfx/render_text_harfbuzz.h ('k') | ui/gfx/render_text_mac.h » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium 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 #include "ui/gfx/render_text_harfbuzz.h" 5 #include "ui/gfx/render_text_harfbuzz.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <set> 8 #include <set>
9 9
10 #include "base/i18n/bidi_line_iterator.h" 10 #include "base/i18n/bidi_line_iterator.h"
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 bool operator() (const Font& a, const Font& b) const { 560 bool operator() (const Font& a, const Font& b) const {
561 return base::CompareCaseInsensitiveASCII(a.GetFontName(), b.GetFontName()) < 561 return base::CompareCaseInsensitiveASCII(a.GetFontName(), b.GetFontName()) <
562 0; 562 0;
563 } 563 }
564 }; 564 };
565 565
566 } // namespace 566 } // namespace
567 567
568 namespace internal { 568 namespace internal {
569 569
570 #if !defined(OS_MACOSX)
571 sk_sp<SkTypeface> CreateSkiaTypeface(const gfx::Font& font, int style) {
572 int skia_style = SkTypeface::kNormal;
573 skia_style |= (style & Font::BOLD) ? SkTypeface::kBold : 0;
574 skia_style |= (style & Font::ITALIC) ? SkTypeface::kItalic : 0;
575 return sk_sp<SkTypeface>(SkTypeface::CreateFromName(
576 font.GetFontName().c_str(), static_cast<SkTypeface::Style>(skia_style)));
577 }
578 #endif
579
570 TextRunHarfBuzz::TextRunHarfBuzz() 580 TextRunHarfBuzz::TextRunHarfBuzz()
571 : width(0.0f), 581 : width(0.0f),
572 preceding_run_widths(0.0f), 582 preceding_run_widths(0.0f),
573 is_rtl(false), 583 is_rtl(false),
574 level(0), 584 level(0),
575 script(USCRIPT_INVALID_CODE), 585 script(USCRIPT_INVALID_CODE),
576 glyph_count(static_cast<size_t>(-1)), 586 glyph_count(static_cast<size_t>(-1)),
577 font_size(0), 587 font_size(0),
578 baseline_offset(0), 588 baseline_offset(0),
579 baseline_type(0), 589 baseline_type(0),
(...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after
1450 return; 1460 return;
1451 1461
1452 run->glyph_count = 0; 1462 run->glyph_count = 0;
1453 run->width = 0.0f; 1463 run->width = 0.0f;
1454 } 1464 }
1455 1465
1456 bool RenderTextHarfBuzz::ShapeRunWithFont(const base::string16& text, 1466 bool RenderTextHarfBuzz::ShapeRunWithFont(const base::string16& text,
1457 const gfx::Font& font, 1467 const gfx::Font& font,
1458 const FontRenderParams& params, 1468 const FontRenderParams& params,
1459 internal::TextRunHarfBuzz* run) { 1469 internal::TextRunHarfBuzz* run) {
1460 skia::RefPtr<SkTypeface> skia_face = 1470 sk_sp<SkTypeface> skia_face(
1461 internal::CreateSkiaTypeface(font, run->font_style); 1471 internal::CreateSkiaTypeface(font, run->font_style));
1462 if (skia_face == NULL) 1472 if (!skia_face)
1463 return false; 1473 return false;
1474
1464 run->skia_face = skia_face; 1475 run->skia_face = skia_face;
1465 run->font = font; 1476 run->font = font;
1466 run->render_params = params; 1477 run->render_params = params;
1467 1478
1468 hb_font_t* harfbuzz_font = CreateHarfBuzzFont( 1479 hb_font_t* harfbuzz_font = CreateHarfBuzzFont(
1469 run->skia_face.get(), SkIntToScalar(run->font_size), run->render_params, 1480 run->skia_face.get(), SkIntToScalar(run->font_size), run->render_params,
1470 subpixel_rendering_suppressed()); 1481 subpixel_rendering_suppressed());
1471 1482
1472 // Create a HarfBuzz buffer and add the string to be shaped. The HarfBuzz 1483 // Create a HarfBuzz buffer and add the string to be shaped. The HarfBuzz
1473 // buffer holds our text, run information to be used by the shaping engine, 1484 // buffer holds our text, run information to be used by the shaping engine,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1569 DCHECK(!update_layout_run_list_); 1580 DCHECK(!update_layout_run_list_);
1570 DCHECK(!update_display_run_list_); 1581 DCHECK(!update_display_run_list_);
1571 return text_elided() ? display_run_list_.get() : &layout_run_list_; 1582 return text_elided() ? display_run_list_.get() : &layout_run_list_;
1572 } 1583 }
1573 1584
1574 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { 1585 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const {
1575 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); 1586 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList();
1576 } 1587 }
1577 1588
1578 } // namespace gfx 1589 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/render_text_harfbuzz.h ('k') | ui/gfx/render_text_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698