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

Side by Side Diff: Source/core/rendering/TextPainter.cpp

Issue 554613004: TextBlob: Start caching a text blob per InlineTextBox. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: turn off runtime-enabled feature for landing Created 6 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/rendering/TextPainter.h ('k') | Source/platform/fonts/Font.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 "config.h" 5 #include "config.h"
6 #include "core/rendering/TextPainter.h" 6 #include "core/rendering/TextPainter.h"
7 7
8 #include "core/rendering/InlineTextBox.h" 8 #include "core/rendering/InlineTextBox.h"
9 #include "core/rendering/RenderCombineText.h" 9 #include "core/rendering/RenderCombineText.h"
10 #include "core/rendering/style/ShadowList.h" 10 #include "core/rendering/style/ShadowList.h"
(...skipping 29 matching lines...) Expand all
40 if (emphasisMark.isNull()) { 40 if (emphasisMark.isNull()) {
41 m_emphasisMarkOffset = 0; 41 m_emphasisMarkOffset = 0;
42 } else if (position == TextEmphasisPositionOver) { 42 } else if (position == TextEmphasisPositionOver) {
43 m_emphasisMarkOffset = -m_font.fontMetrics().ascent() - m_font.emphasisM arkDescent(emphasisMark); 43 m_emphasisMarkOffset = -m_font.fontMetrics().ascent() - m_font.emphasisM arkDescent(emphasisMark);
44 } else { 44 } else {
45 ASSERT(position == TextEmphasisPositionUnder); 45 ASSERT(position == TextEmphasisPositionUnder);
46 m_emphasisMarkOffset = m_font.fontMetrics().descent() + m_font.emphasisM arkAscent(emphasisMark); 46 m_emphasisMarkOffset = m_font.fontMetrics().descent() + m_font.emphasisM arkAscent(emphasisMark);
47 } 47 }
48 } 48 }
49 49
50 void TextPainter::paint(int startOffset, int endOffset, int length, const Style& textStyle) 50 void TextPainter::paint(int startOffset, int endOffset, int length, const Style& textStyle, TextBlobPtr* cachedTextBlob)
51 { 51 {
52 GraphicsContextStateSaver stateSaver(*m_graphicsContext, false); 52 GraphicsContextStateSaver stateSaver(*m_graphicsContext, false);
53 updateGraphicsContext(textStyle, stateSaver); 53 updateGraphicsContext(textStyle, stateSaver);
54 paintInternal<PaintText>(startOffset, endOffset, length); 54 paintInternal<PaintText>(startOffset, endOffset, length, cachedTextBlob);
55 55
56 if (!m_emphasisMark.isEmpty()) { 56 if (!m_emphasisMark.isEmpty()) {
57 if (textStyle.emphasisMarkColor != textStyle.fillColor) 57 if (textStyle.emphasisMarkColor != textStyle.fillColor)
58 m_graphicsContext->setFillColor(textStyle.emphasisMarkColor); 58 m_graphicsContext->setFillColor(textStyle.emphasisMarkColor);
59 59
60 if (m_combinedText) 60 if (m_combinedText)
61 paintEmphasisMarkForCombinedText(); 61 paintEmphasisMarkForCombinedText();
62 else 62 else
63 paintInternal<PaintEmphasisMark>(startOffset, endOffset, length); 63 paintInternal<PaintEmphasisMark>(startOffset, endOffset, length);
64 } 64 }
(...skipping 24 matching lines...) Expand all
89 } 89 }
90 90
91 // Text shadows are disabled when printing. http://crbug.com/258321 91 // Text shadows are disabled when printing. http://crbug.com/258321
92 if (textStyle.shadow && !context->printing()) { 92 if (textStyle.shadow && !context->printing()) {
93 if (!stateSaver.saved()) 93 if (!stateSaver.saved())
94 stateSaver.save(); 94 stateSaver.save();
95 context->setDrawLooper(textStyle.shadow->createDrawLooper(DrawLooperBuil der::ShadowIgnoresAlpha, horizontal)); 95 context->setDrawLooper(textStyle.shadow->createDrawLooper(DrawLooperBuil der::ShadowIgnoresAlpha, horizontal));
96 } 96 }
97 } 97 }
98 98
99 static bool graphicsContextAllowsTextBlobs(GraphicsContext* context)
100 {
101 // Text blobs affect the shader coordinate space.
102 // FIXME: Fix this, most likely in Skia.
103 return !context->strokeGradient() && !context->strokePattern() && !context-> fillGradient() && !context->fillPattern();
104 }
105
99 template <TextPainter::PaintInternalStep step> 106 template <TextPainter::PaintInternalStep step>
100 void TextPainter::paintInternalRun(TextRunPaintInfo& textRunPaintInfo, int from, int to) 107 void TextPainter::paintInternalRun(TextRunPaintInfo& textRunPaintInfo, int from, int to, TextBlobPtr* cachedTextBlob)
101 { 108 {
102 textRunPaintInfo.from = from; 109 textRunPaintInfo.from = from;
103 textRunPaintInfo.to = to; 110 textRunPaintInfo.to = to;
104 if (step == PaintEmphasisMark) 111
112 if (step == PaintEmphasisMark) {
105 m_graphicsContext->drawEmphasisMarks(m_font, textRunPaintInfo, m_emphasi sMark, m_textOrigin + IntSize(0, m_emphasisMarkOffset)); 113 m_graphicsContext->drawEmphasisMarks(m_font, textRunPaintInfo, m_emphasi sMark, m_textOrigin + IntSize(0, m_emphasisMarkOffset));
114 return;
115 }
116
117 ASSERT(step == PaintText);
118
119 TextBlobPtr localTextBlob;
120 TextBlobPtr& textBlob = cachedTextBlob ? *cachedTextBlob : localTextBlob;
121 bool canUseTextBlobs = RuntimeEnabledFeatures::textBlobEnabled() && graphics ContextAllowsTextBlobs(m_graphicsContext);
122
123 if (canUseTextBlobs && !textBlob)
124 textBlob = m_font.buildTextBlob(textRunPaintInfo, m_textOrigin, m_graphi csContext->couldUseLCDRenderedText());
125
126 if (canUseTextBlobs && textBlob)
127 m_font.drawTextBlob(m_graphicsContext, textBlob.get(), m_textOrigin.data ());
106 else 128 else
107 m_graphicsContext->drawText(m_font, textRunPaintInfo, m_textOrigin); 129 m_graphicsContext->drawText(m_font, textRunPaintInfo, m_textOrigin);
108
109 } 130 }
110 131
111 template <TextPainter::PaintInternalStep Step> 132 template <TextPainter::PaintInternalStep Step>
112 void TextPainter::paintInternal(int startOffset, int endOffset, int truncationPo int) 133 void TextPainter::paintInternal(int startOffset, int endOffset, int truncationPo int, TextBlobPtr* cachedTextBlob)
113 { 134 {
135 // FIXME: We should be able to use cachedTextBlob in more cases.
114 TextRunPaintInfo textRunPaintInfo(m_run); 136 TextRunPaintInfo textRunPaintInfo(m_run);
115 textRunPaintInfo.bounds = m_textBounds; 137 textRunPaintInfo.bounds = m_textBounds;
116 if (startOffset <= endOffset) { 138 if (startOffset <= endOffset) {
117 paintInternalRun<Step>(textRunPaintInfo, startOffset, endOffset); 139 paintInternalRun<Step>(textRunPaintInfo, startOffset, endOffset, cachedT extBlob);
118 } else { 140 } else {
119 if (endOffset > 0) 141 if (endOffset > 0)
120 paintInternalRun<Step>(textRunPaintInfo, 0, endOffset); 142 paintInternalRun<Step>(textRunPaintInfo, 0, endOffset);
121 if (startOffset < truncationPoint) 143 if (startOffset < truncationPoint)
122 paintInternalRun<Step>(textRunPaintInfo, startOffset, truncationPoin t); 144 paintInternalRun<Step>(textRunPaintInfo, startOffset, truncationPoin t);
123 } 145 }
124 } 146 }
125 147
126 void TextPainter::paintEmphasisMarkForCombinedText() 148 void TextPainter::paintEmphasisMarkForCombinedText()
127 { 149 {
128 ASSERT(m_combinedText); 150 ASSERT(m_combinedText);
129 DEFINE_STATIC_LOCAL(TextRun, objectReplacementCharacterTextRun, (&objectRepl acementCharacter, 1)); 151 DEFINE_STATIC_LOCAL(TextRun, objectReplacementCharacterTextRun, (&objectRepl acementCharacter, 1));
130 FloatPoint emphasisMarkTextOrigin(m_textBounds.x() + m_textBounds.width() / 2, m_textBounds.y() + m_font.fontMetrics().ascent() + m_emphasisMarkOffset); 152 FloatPoint emphasisMarkTextOrigin(m_textBounds.x() + m_textBounds.width() / 2, m_textBounds.y() + m_font.fontMetrics().ascent() + m_emphasisMarkOffset);
131 TextRunPaintInfo textRunPaintInfo(objectReplacementCharacterTextRun); 153 TextRunPaintInfo textRunPaintInfo(objectReplacementCharacterTextRun);
132 textRunPaintInfo.bounds = m_textBounds; 154 textRunPaintInfo.bounds = m_textBounds;
133 m_graphicsContext->concatCTM(InlineTextBox::rotation(m_textBounds, InlineTex tBox::Clockwise)); 155 m_graphicsContext->concatCTM(InlineTextBox::rotation(m_textBounds, InlineTex tBox::Clockwise));
134 m_graphicsContext->drawEmphasisMarks(m_combinedText->originalFont(), textRun PaintInfo, m_emphasisMark, emphasisMarkTextOrigin); 156 m_graphicsContext->drawEmphasisMarks(m_combinedText->originalFont(), textRun PaintInfo, m_emphasisMark, emphasisMarkTextOrigin);
135 m_graphicsContext->concatCTM(InlineTextBox::rotation(m_textBounds, InlineTex tBox::Counterclockwise)); 157 m_graphicsContext->concatCTM(InlineTextBox::rotation(m_textBounds, InlineTex tBox::Counterclockwise));
136 } 158 }
137 159
138 } // namespace blink 160 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/rendering/TextPainter.h ('k') | Source/platform/fonts/Font.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698