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

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

Issue 2894843002: Revert of Remove cullRect() from PaintOpBuffer. (Closed)
Patch Set: rebase TestExpectations Created 3 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
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 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 default: 699 default:
700 NOTREACHED(); 700 NOTREACHED();
701 } 701 }
702 } 702 }
703 } 703 }
704 704
705 namespace { 705 namespace {
706 706
707 #if !OS(MACOSX) 707 #if !OS(MACOSX)
708 708
709 static const float kMarkerWidth = 4;
710 static const float kMarkerHeight = 2;
711
712 sk_sp<PaintRecord> RecordMarker(DocumentMarker::MarkerType marker_type) { 709 sk_sp<PaintRecord> RecordMarker(DocumentMarker::MarkerType marker_type) {
713 SkColor color = (marker_type == DocumentMarker::kGrammar) 710 SkColor color = (marker_type == DocumentMarker::kGrammar)
714 ? SkColorSetRGB(0xC0, 0xC0, 0xC0) 711 ? SkColorSetRGB(0xC0, 0xC0, 0xC0)
715 : SK_ColorRED; 712 : SK_ColorRED;
716 713
717 // Record the path equivalent to this legacy pattern: 714 // Record the path equivalent to this legacy pattern:
718 // X o o X o o X 715 // X o o X o o X
719 // o X o o X o 716 // o X o o X o
720 717
718 static const float kW = 4;
719 static const float kH = 2;
720
721 // Adjust the phase such that f' == 0 is "pixel"-centered 721 // Adjust the phase such that f' == 0 is "pixel"-centered
722 // (for optimal rasterization at native rez). 722 // (for optimal rasterization at native rez).
723 SkPath path; 723 SkPath path;
724 path.moveTo(kMarkerWidth * -3 / 8, kMarkerHeight * 3 / 4); 724 path.moveTo(kW * -3 / 8, kH * 3 / 4);
725 path.cubicTo(kMarkerWidth * -1 / 8, kMarkerHeight * 3 / 4, 725 path.cubicTo(kW * -1 / 8, kH * 3 / 4,
726 kMarkerWidth * -1 / 8, kMarkerHeight * 1 / 4, 726 kW * -1 / 8, kH * 1 / 4,
727 kMarkerWidth * 1 / 8, kMarkerHeight * 1 / 4); 727 kW * 1 / 8, kH * 1 / 4);
728 path.cubicTo(kMarkerWidth * 3 / 8, kMarkerHeight * 1 / 4, 728 path.cubicTo(kW * 3 / 8, kH * 1 / 4,
729 kMarkerWidth * 3 / 8, kMarkerHeight * 3 / 4, 729 kW * 3 / 8, kH * 3 / 4,
730 kMarkerWidth * 5 / 8, kMarkerHeight * 3 / 4); 730 kW * 5 / 8, kH * 3 / 4);
731 path.cubicTo(kMarkerWidth * 7 / 8, kMarkerHeight * 3 / 4, 731 path.cubicTo(kW * 7 / 8, kH * 3 / 4,
732 kMarkerWidth * 7 / 8, kMarkerHeight * 1 / 4, 732 kW * 7 / 8, kH * 1 / 4,
733 kMarkerWidth * 9 / 8, kMarkerHeight * 1 / 4); 733 kW * 9 / 8, kH * 1 / 4);
734 734
735 PaintFlags flags; 735 PaintFlags flags;
736 flags.setAntiAlias(true); 736 flags.setAntiAlias(true);
737 flags.setColor(color); 737 flags.setColor(color);
738 flags.setStyle(PaintFlags::kStroke_Style); 738 flags.setStyle(PaintFlags::kStroke_Style);
739 flags.setStrokeWidth(kMarkerHeight * 1 / 2); 739 flags.setStrokeWidth(kH * 1 / 2);
740 740
741 PaintRecorder recorder; 741 PaintRecorder recorder;
742 recorder.beginRecording(kMarkerWidth, kMarkerHeight); 742 recorder.beginRecording(kW, kH);
743 recorder.getRecordingCanvas()->drawPath(path, flags); 743 recorder.getRecordingCanvas()->drawPath(path, flags);
744 744
745 return recorder.finishRecordingAsPicture(); 745 return recorder.finishRecordingAsPicture();
746 } 746 }
747 747
748 #else // OS(MACOSX) 748 #else // OS(MACOSX)
749 749
750 static const float kMarkerWidth = 4;
751 static const float kMarkerHeight = 3;
752
753 sk_sp<PaintRecord> RecordMarker(DocumentMarker::MarkerType marker_type) { 750 sk_sp<PaintRecord> RecordMarker(DocumentMarker::MarkerType marker_type) {
754 SkColor color = (marker_type == DocumentMarker::kGrammar) 751 SkColor color = (marker_type == DocumentMarker::kGrammar)
755 ? SkColorSetRGB(0x6B, 0x6B, 0x6B) 752 ? SkColorSetRGB(0x6B, 0x6B, 0x6B)
756 : SkColorSetRGB(0xFB, 0x2D, 0x1D); 753 : SkColorSetRGB(0xFB, 0x2D, 0x1D);
757 754
758 // Match the artwork used by the Mac. 755 // Match the artwork used by the Mac.
756 static const float kW = 4;
757 static const float kH = 3;
759 static const float kR = 1.5f; 758 static const float kR = 1.5f;
760 759
761 // top->bottom translucent gradient. 760 // top->bottom translucent gradient.
762 const SkColor colors[2] = { 761 const SkColor colors[2] = {
763 SkColorSetARGB(0x48, 762 SkColorSetARGB(0x48,
764 SkColorGetR(color), 763 SkColorGetR(color),
765 SkColorGetG(color), 764 SkColorGetG(color),
766 SkColorGetB(color)), 765 SkColorGetB(color)),
767 color 766 color
768 }; 767 };
769 const SkPoint pts[2] = { 768 const SkPoint pts[2] = {
770 SkPoint::Make(0, 0), 769 SkPoint::Make(0, 0),
771 SkPoint::Make(0, 2 * kR) 770 SkPoint::Make(0, 2 * kR)
772 }; 771 };
773 772
774 PaintFlags flags; 773 PaintFlags flags;
775 flags.setAntiAlias(true); 774 flags.setAntiAlias(true);
776 flags.setColor(color); 775 flags.setColor(color);
777 flags.setShader(SkGradientShader::MakeLinear( 776 flags.setShader(SkGradientShader::MakeLinear(
778 pts, colors, nullptr, ARRAY_SIZE(colors), SkShader::kClamp_TileMode)); 777 pts, colors, nullptr, ARRAY_SIZE(colors), SkShader::kClamp_TileMode));
779 PaintRecorder recorder; 778 PaintRecorder recorder;
780 recorder.beginRecording(kMarkerWidth, kMarkerHeight); 779 recorder.beginRecording(kW, kH);
781 recorder.getRecordingCanvas()->drawCircle(kR, kR, kR, flags); 780 recorder.getRecordingCanvas()->drawCircle(kR, kR, kR, flags);
782 781
783 return recorder.finishRecordingAsPicture(); 782 return recorder.finishRecordingAsPicture();
784 } 783 }
785 784
786 #endif // OS(MACOSX) 785 #endif // OS(MACOSX)
787 786
788 void DrawDocumentMarker(GraphicsContext& context, 787 void DrawDocumentMarker(GraphicsContext& context,
789 const FloatPoint& pt, 788 const FloatPoint& pt,
790 float width, 789 float width,
791 DocumentMarker::MarkerType marker_type, 790 DocumentMarker::MarkerType marker_type,
792 float zoom) { 791 float zoom) {
793 DCHECK(marker_type == DocumentMarker::kSpelling || 792 DCHECK(marker_type == DocumentMarker::kSpelling ||
794 marker_type == DocumentMarker::kGrammar); 793 marker_type == DocumentMarker::kGrammar);
795 794
796 DEFINE_STATIC_LOCAL(PaintRecord*, spelling_marker, 795 DEFINE_STATIC_LOCAL(PaintRecord*, spelling_marker,
797 (RecordMarker(DocumentMarker::kSpelling).release())); 796 (RecordMarker(DocumentMarker::kSpelling).release()));
798 DEFINE_STATIC_LOCAL(PaintRecord*, grammar_marker, 797 DEFINE_STATIC_LOCAL(PaintRecord*, grammar_marker,
799 (RecordMarker(DocumentMarker::kGrammar).release())); 798 (RecordMarker(DocumentMarker::kGrammar).release()));
800 const auto& marker = marker_type == DocumentMarker::kSpelling 799 const auto& marker = marker_type == DocumentMarker::kSpelling
801 ? spelling_marker 800 ? spelling_marker
802 : grammar_marker; 801 : grammar_marker;
803 802
804 // Position already includes zoom and device scale factor. 803 // Position already includes zoom and device scale factor.
805 SkScalar origin_x = WebCoreFloatToSkScalar(pt.X()); 804 SkScalar origin_x = WebCoreFloatToSkScalar(pt.X());
806 SkScalar origin_y = WebCoreFloatToSkScalar(pt.Y()); 805 SkScalar origin_y = WebCoreFloatToSkScalar(pt.Y());
807 806
808 #if OS(MACOSX) 807 #if OS(MACOSX)
809 // Make sure to draw only complete dots, and finish inside the marked text. 808 // Make sure to draw only complete dots, and finish inside the marked text.
810 width -= fmodf(width, kMarkerWidth * zoom); 809 width -= fmodf(width, marker->cullRect().width() * zoom);
811 #else 810 #else
812 // Offset it vertically by 1 so that there's some space under the text. 811 // Offset it vertically by 1 so that there's some space under the text.
813 origin_y += 1; 812 origin_y += 1;
814 #endif 813 #endif
815 814
816 const auto rect = SkRect::MakeWH(width, kMarkerHeight * zoom); 815 const auto rect = SkRect::MakeWH(width, marker->cullRect().height() * zoom);
817 const auto local_matrix = SkMatrix::MakeScale(zoom, zoom); 816 const auto local_matrix = SkMatrix::MakeScale(zoom, zoom);
818 817
819 PaintFlags flags; 818 PaintFlags flags;
820 flags.setAntiAlias(true); 819 flags.setAntiAlias(true);
821 flags.setShader(WrapSkShader(MakePaintShaderRecord( 820 flags.setShader(WrapSkShader(MakePaintShaderRecord(
822 sk_ref_sp(marker), FloatRect(0, 0, kMarkerWidth, kMarkerHeight), 821 sk_ref_sp(marker), SkShader::kRepeat_TileMode, SkShader::kClamp_TileMode,
823 SkShader::kRepeat_TileMode, SkShader::kClamp_TileMode, &local_matrix))); 822 &local_matrix, nullptr)));
824 823
825 // Apply the origin translation as a global transform. This ensures that the 824 // Apply the origin translation as a global transform. This ensures that the
826 // shader local matrix depends solely on zoom => Skia can reuse the same 825 // shader local matrix depends solely on zoom => Skia can reuse the same
827 // cached tile for all markers at a given zoom level. 826 // cached tile for all markers at a given zoom level.
828 GraphicsContextStateSaver saver(context); 827 GraphicsContextStateSaver saver(context);
829 context.Translate(origin_x, origin_y); 828 context.Translate(origin_x, origin_y);
830 context.DrawRect(rect, flags); 829 context.DrawRect(rect, flags);
831 } 830 }
832 831
833 } // anonymous ns 832 } // anonymous ns
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 1180
1182 LayoutRect box_rect(box_origin, LayoutSize(inline_text_box_.LogicalWidth(), 1181 LayoutRect box_rect(box_origin, LayoutSize(inline_text_box_.LogicalWidth(),
1183 inline_text_box_.LogicalHeight())); 1182 inline_text_box_.LogicalHeight()));
1184 context.Clip(FloatRect(box_rect)); 1183 context.Clip(FloatRect(box_rect));
1185 context.DrawHighlightForText(font, run, FloatPoint(box_origin), 1184 context.DrawHighlightForText(font, run, FloatPoint(box_origin),
1186 box_rect.Height().ToInt(), color, 1185 box_rect.Height().ToInt(), color,
1187 paint_offsets.first, paint_offsets.second); 1186 paint_offsets.first, paint_offsets.second);
1188 } 1187 }
1189 1188
1190 } // namespace blink 1189 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698