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

Side by Side Diff: third_party/WebKit/Source/core/paint/InlineTextBoxPainter.cpp

Issue 2707083002: Remove the text blob cache (Closed)
Patch Set: Created 3 years, 10 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
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 "core/paint/InlineTextBoxPainter.h" 5 #include "core/paint/InlineTextBoxPainter.h"
6 6
7 #include "core/editing/CompositionUnderline.h" 7 #include "core/editing/CompositionUnderline.h"
8 #include "core/editing/Editor.h" 8 #include "core/editing/Editor.h"
9 #include "core/editing/markers/DocumentMarkerController.h" 9 #include "core/editing/markers/DocumentMarkerController.h"
10 #include "core/frame/LocalFrame.h" 10 #include "core/frame/LocalFrame.h"
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 for (float x = x1; x + 2 * step <= x2;) { 435 for (float x = x1; x + 2 * step <= x2;) {
436 controlPoint1.setX(x + step); 436 controlPoint1.setX(x + step);
437 controlPoint2.setX(x + step); 437 controlPoint2.setX(x + step);
438 x += 2 * step; 438 x += 2 * step;
439 path.addBezierCurveTo(controlPoint1, controlPoint2, FloatPoint(x, yAxis)); 439 path.addBezierCurveTo(controlPoint1, controlPoint2, FloatPoint(x, yAxis));
440 } 440 }
441 } 441 }
442 return path; 442 return path;
443 } 443 }
444 444
445 typedef WTF::HashMap<const InlineTextBox*, TextBlobPtr>
446 InlineTextBoxBlobCacheMap;
447 static InlineTextBoxBlobCacheMap* gTextBlobCache;
448
449 static const int misspellingLineThickness = 3; 445 static const int misspellingLineThickness = 3;
450 446
451 void InlineTextBoxPainter::removeFromTextBlobCache(
452 const InlineTextBox& inlineTextBox) {
453 if (gTextBlobCache)
454 gTextBlobCache->remove(&inlineTextBox);
455 }
456
457 static TextBlobPtr* addToTextBlobCache(const InlineTextBox& inlineTextBox) {
458 if (!gTextBlobCache)
459 gTextBlobCache = new InlineTextBoxBlobCacheMap;
460 return &gTextBlobCache->insert(&inlineTextBox, nullptr).storedValue->value;
461 }
462
463 LayoutObject& InlineTextBoxPainter::inlineLayoutObject() const { 447 LayoutObject& InlineTextBoxPainter::inlineLayoutObject() const {
464 return *LineLayoutAPIShim::layoutObjectFrom( 448 return *LineLayoutAPIShim::layoutObjectFrom(
465 m_inlineTextBox.getLineLayoutItem()); 449 m_inlineTextBox.getLineLayoutItem());
466 } 450 }
467 451
468 bool InlineTextBoxPainter::paintsMarkerHighlights( 452 bool InlineTextBoxPainter::paintsMarkerHighlights(
469 const LayoutObject& layoutObject) { 453 const LayoutObject& layoutObject) {
470 return layoutObject.node() && 454 return layoutObject.node() &&
471 layoutObject.document().markers().hasMarkers(layoutObject.node()); 455 layoutObject.document().markers().hasMarkers(layoutObject.node());
472 } 456 }
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 if (m_inlineTextBox.truncation() != cNoTruncation && ltr != flowIsLTR) { 669 if (m_inlineTextBox.truncation() != cNoTruncation && ltr != flowIsLTR) {
686 startOffset = m_inlineTextBox.truncation(); 670 startOffset = m_inlineTextBox.truncation();
687 endOffset = textRun.length(); 671 endOffset = textRun.length();
688 } 672 }
689 673
690 if (paintSelectedTextSeparately && selectionStart < selectionEnd) { 674 if (paintSelectedTextSeparately && selectionStart < selectionEnd) {
691 startOffset = selectionEnd; 675 startOffset = selectionEnd;
692 endOffset = selectionStart; 676 endOffset = selectionStart;
693 } 677 }
694 678
695 // FIXME: This cache should probably ultimately be held somewhere else. 679 textPainter.paint(startOffset, endOffset, length, textStyle);
696 // A hashmap is convenient to avoid a memory hit when the
697 // RuntimeEnabledFeature is off.
698 bool textBlobIsCacheable = startOffset == 0 && endOffset == length;
699 TextBlobPtr* cachedTextBlob = 0;
700 if (textBlobIsCacheable)
701 cachedTextBlob = addToTextBlobCache(m_inlineTextBox);
702 textPainter.paint(startOffset, endOffset, length, textStyle,
703 cachedTextBlob);
704 } 680 }
705 681
706 if ((paintSelectedTextOnly || paintSelectedTextSeparately) && 682 if ((paintSelectedTextOnly || paintSelectedTextSeparately) &&
707 selectionStart < selectionEnd) { 683 selectionStart < selectionEnd) {
708 // paint only the text that is selected 684 // paint only the text that is selected
709 bool textBlobIsCacheable = selectionStart == 0 && selectionEnd == length; 685 textPainter.paint(selectionStart, selectionEnd, length, selectionStyle);
710 TextBlobPtr* cachedTextBlob = 0;
711 if (textBlobIsCacheable)
712 cachedTextBlob = addToTextBlobCache(m_inlineTextBox);
713 textPainter.paint(selectionStart, selectionEnd, length, selectionStyle,
714 cachedTextBlob);
715 } 686 }
716 687
717 // Paint decorations 688 // Paint decorations
718 if (styleToUse.textDecorationsInEffect() != TextDecorationNone && 689 if (styleToUse.textDecorationsInEffect() != TextDecorationNone &&
719 !paintSelectedTextOnly) { 690 !paintSelectedTextOnly) {
720 GraphicsContextStateSaver stateSaver(context, false); 691 GraphicsContextStateSaver stateSaver(context, false);
721 692
722 TextPainter::updateGraphicsContext( 693 TextPainter::updateGraphicsContext(
723 context, textStyle, m_inlineTextBox.isHorizontal(), stateSaver); 694 context, textStyle, m_inlineTextBox.isHorizontal(), stateSaver);
724 695
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
1358 textStyle.shadow = 0; 1329 textStyle.shadow = 0;
1359 1330
1360 LayoutRect boxRect(boxOrigin, LayoutSize(m_inlineTextBox.logicalWidth(), 1331 LayoutRect boxRect(boxOrigin, LayoutSize(m_inlineTextBox.logicalWidth(),
1361 m_inlineTextBox.logicalHeight())); 1332 m_inlineTextBox.logicalHeight()));
1362 LayoutPoint textOrigin(boxOrigin.x(), 1333 LayoutPoint textOrigin(boxOrigin.x(),
1363 boxOrigin.y() + fontData->getFontMetrics().ascent()); 1334 boxOrigin.y() + fontData->getFontMetrics().ascent());
1364 TextPainter textPainter(paintInfo.context, font, run, textOrigin, boxRect, 1335 TextPainter textPainter(paintInfo.context, font, run, textOrigin, boxRect,
1365 m_inlineTextBox.isHorizontal()); 1336 m_inlineTextBox.isHorizontal());
1366 1337
1367 textPainter.paint(paintOffsets.first, paintOffsets.second, 1338 textPainter.paint(paintOffsets.first, paintOffsets.second,
1368 m_inlineTextBox.len(), textStyle, 0); 1339 m_inlineTextBox.len(), textStyle);
1369 } 1340 }
1370 1341
1371 void InlineTextBoxPainter::paintTextMatchMarkerBackground( 1342 void InlineTextBoxPainter::paintTextMatchMarkerBackground(
1372 const PaintInfo& paintInfo, 1343 const PaintInfo& paintInfo,
1373 const LayoutPoint& boxOrigin, 1344 const LayoutPoint& boxOrigin,
1374 const DocumentMarker& marker, 1345 const DocumentMarker& marker,
1375 const ComputedStyle& style, 1346 const ComputedStyle& style,
1376 const Font& font) { 1347 const Font& font) {
1377 if (!LineLayoutAPIShim::layoutObjectFrom(m_inlineTextBox.getLineLayoutItem()) 1348 if (!LineLayoutAPIShim::layoutObjectFrom(m_inlineTextBox.getLineLayoutItem())
1378 ->frame() 1349 ->frame()
(...skipping 11 matching lines...) Expand all
1390 1361
1391 LayoutRect boxRect(boxOrigin, LayoutSize(m_inlineTextBox.logicalWidth(), 1362 LayoutRect boxRect(boxOrigin, LayoutSize(m_inlineTextBox.logicalWidth(),
1392 m_inlineTextBox.logicalHeight())); 1363 m_inlineTextBox.logicalHeight()));
1393 context.clip(FloatRect(boxRect)); 1364 context.clip(FloatRect(boxRect));
1394 context.drawHighlightForText(font, run, FloatPoint(boxOrigin), 1365 context.drawHighlightForText(font, run, FloatPoint(boxOrigin),
1395 boxRect.height().toInt(), color, 1366 boxRect.height().toInt(), color,
1396 paintOffsets.first, paintOffsets.second); 1367 paintOffsets.first, paintOffsets.second);
1397 } 1368 }
1398 1369
1399 } // namespace blink 1370 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/paint/InlineTextBoxPainter.h ('k') | third_party/WebKit/Source/core/paint/TextPainter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698