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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/GraphicsContext.cpp

Issue 2878573003: Initial skeleton of high-contrast mode. (Closed)
Patch Set: 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 /* 1 /*
2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 29 matching lines...) Expand all
40 #include "platform/instrumentation/tracing/TraceEvent.h" 40 #include "platform/instrumentation/tracing/TraceEvent.h"
41 #include "platform/weborigin/KURL.h" 41 #include "platform/weborigin/KURL.h"
42 #include "platform/wtf/Assertions.h" 42 #include "platform/wtf/Assertions.h"
43 #include "platform/wtf/MathExtras.h" 43 #include "platform/wtf/MathExtras.h"
44 #include "skia/ext/platform_canvas.h" 44 #include "skia/ext/platform_canvas.h"
45 #include "third_party/skia/include/core/SkAnnotation.h" 45 #include "third_party/skia/include/core/SkAnnotation.h"
46 #include "third_party/skia/include/core/SkColorFilter.h" 46 #include "third_party/skia/include/core/SkColorFilter.h"
47 #include "third_party/skia/include/core/SkData.h" 47 #include "third_party/skia/include/core/SkData.h"
48 #include "third_party/skia/include/core/SkRRect.h" 48 #include "third_party/skia/include/core/SkRRect.h"
49 #include "third_party/skia/include/core/SkRefCnt.h" 49 #include "third_party/skia/include/core/SkRefCnt.h"
50 #include "third_party/skia/include/effects/SkHighContrastFilter.h"
50 #include "third_party/skia/include/effects/SkLumaColorFilter.h" 51 #include "third_party/skia/include/effects/SkLumaColorFilter.h"
51 #include "third_party/skia/include/effects/SkPictureImageFilter.h" 52 #include "third_party/skia/include/effects/SkPictureImageFilter.h"
53 #include "third_party/skia/include/effects/SkTableColorFilter.h"
52 #include "third_party/skia/include/pathops/SkPathOps.h" 54 #include "third_party/skia/include/pathops/SkPathOps.h"
53 #include "third_party/skia/include/utils/SkNullCanvas.h" 55 #include "third_party/skia/include/utils/SkNullCanvas.h"
54 56
55 namespace blink { 57 namespace blink {
56 58
57 GraphicsContext::GraphicsContext(PaintController& paint_controller, 59 GraphicsContext::GraphicsContext(PaintController& paint_controller,
58 DisabledMode disable_context_or_painting, 60 DisabledMode disable_context_or_painting,
59 SkMetaData* meta_data) 61 SkMetaData* meta_data)
60 : canvas_(nullptr), 62 : canvas_(nullptr),
61 paint_controller_(paint_controller), 63 paint_controller_(paint_controller),
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 // (on top of its own saveCount), except for the first frame. 135 // (on top of its own saveCount), except for the first frame.
134 unsigned count = paint_state_index_; 136 unsigned count = paint_state_index_;
135 DCHECK_GE(paint_state_stack_.size(), paint_state_index_); 137 DCHECK_GE(paint_state_stack_.size(), paint_state_index_);
136 for (unsigned i = 0; i <= paint_state_index_; ++i) 138 for (unsigned i = 0; i <= paint_state_index_; ++i)
137 count += paint_state_stack_[i]->SaveCount(); 139 count += paint_state_stack_[i]->SaveCount();
138 140
139 return count; 141 return count;
140 } 142 }
141 #endif 143 #endif
142 144
145 void GraphicsContext::SetHighContrast(const HighContrastSettings& settings) {
chrishtr 2017/06/01 04:10:51 PaintRecordBuilder, and a couple of other cases, c
dmazzoni 2017/06/01 21:44:01 OK, I made it an optional constructor parameter an
chrishtr 2017/06/02 21:12:30 Do you care about anything except the mainline cas
146 SkHighContrastConfig config;
147
148 switch (settings.mode) {
149 case HighContrastMode::kOff:
150 high_contrast_filter_.reset(nullptr);
151 return;
152 case HighContrastMode::kSimpleInvertForTesting: {
153 uint8_t identity[256], invert[256];
154 for (int i = 0; i < 256; ++i) {
155 identity[i] = i;
156 invert[i] = 255 - i;
157 }
158 high_contrast_filter_ =
159 SkTableColorFilter::MakeARGB(identity, invert, invert, invert);
160 return;
161 }
162 case HighContrastMode::kInvertBrightness:
163 config.fInvertStyle =
164 SkHighContrastConfig::InvertStyle::kInvertBrightness;
165 break;
166 case HighContrastMode::kInvertLightness:
167 config.fInvertStyle = SkHighContrastConfig::InvertStyle::kInvertLightness;
168 break;
169 default:
chrishtr 2017/06/01 04:10:51 I don't think you need this, since there are label
dmazzoni 2017/06/01 21:44:01 Done.
170 NOTREACHED();
171 high_contrast_filter_.reset(nullptr);
172 return;
173 }
174
175 config.fGrayscale = settings.grayscale;
176 config.fContrast = settings.contrast;
177 high_contrast_filter_ = SkHighContrastFilter::Make(config);
178 }
179
143 void GraphicsContext::SaveLayer(const SkRect* bounds, const PaintFlags* flags) { 180 void GraphicsContext::SaveLayer(const SkRect* bounds, const PaintFlags* flags) {
144 if (ContextDisabled()) 181 if (ContextDisabled())
145 return; 182 return;
146 183
147 DCHECK(canvas_); 184 DCHECK(canvas_);
148 canvas_->saveLayer(bounds, flags); 185 canvas_->saveLayer(bounds, flags);
149 } 186 }
150 187
151 void GraphicsContext::RestoreLayer() { 188 void GraphicsContext::RestoreLayer() {
152 if (ContextDisabled()) 189 if (ContextDisabled())
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 int GraphicsContext::FocusRingOutsetExtent(int offset, int width) { 381 int GraphicsContext::FocusRingOutsetExtent(int offset, int width) {
345 // Unlike normal outlines (whole width is outside of the offset), focus 382 // Unlike normal outlines (whole width is outside of the offset), focus
346 // rings are drawn with the center of the path aligned with the offset, so 383 // rings are drawn with the center of the path aligned with the offset, so
347 // only half of the width is outside of the offset. 384 // only half of the width is outside of the offset.
348 return AdjustedFocusRingOffset(offset) + (width + 1) / 2; 385 return AdjustedFocusRingOffset(offset) + (width + 1) / 2;
349 } 386 }
350 387
351 void GraphicsContext::DrawFocusRingPath(const SkPath& path, 388 void GraphicsContext::DrawFocusRingPath(const SkPath& path,
352 const Color& color, 389 const Color& color,
353 float width) { 390 float width) {
354 DrawPlatformFocusRing(path, canvas_, color.Rgb(), width); 391 DrawPlatformFocusRing(path, canvas_, ApplyHighContrastFilter(color).Rgb(),
392 width);
355 } 393 }
356 394
357 void GraphicsContext::DrawFocusRingRect(const SkRect& rect, 395 void GraphicsContext::DrawFocusRingRect(const SkRect& rect,
358 const Color& color, 396 const Color& color,
359 float width) { 397 float width) {
360 DrawPlatformFocusRing(rect, canvas_, color.Rgb(), width); 398 DrawPlatformFocusRing(rect, canvas_, ApplyHighContrastFilter(color).Rgb(),
399 width);
361 } 400 }
362 401
363 void GraphicsContext::DrawFocusRing(const Path& focus_ring_path, 402 void GraphicsContext::DrawFocusRing(const Path& focus_ring_path,
364 float width, 403 float width,
365 int offset, 404 int offset,
366 const Color& color) { 405 const Color& color) {
367 // FIXME: Implement support for offset. 406 // FIXME: Implement support for offset.
368 if (ContextDisabled()) 407 if (ContextDisabled())
369 return; 408 return;
370 409
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 455
417 if (shadow_spread < 0) 456 if (shadow_spread < 0)
418 bounds.Inflate(-shadow_spread); 457 bounds.Inflate(-shadow_spread);
419 458
420 FloatRect offset_bounds = bounds; 459 FloatRect offset_bounds = bounds;
421 offset_bounds.Move(-shadow_offset); 460 offset_bounds.Move(-shadow_offset);
422 return UnionRect(bounds, offset_bounds); 461 return UnionRect(bounds, offset_bounds);
423 } 462 }
424 463
425 void GraphicsContext::DrawInnerShadow(const FloatRoundedRect& rect, 464 void GraphicsContext::DrawInnerShadow(const FloatRoundedRect& rect,
426 const Color& shadow_color, 465 const Color& orig_shadow_color,
427 const FloatSize& shadow_offset, 466 const FloatSize& shadow_offset,
428 float shadow_blur, 467 float shadow_blur,
429 float shadow_spread, 468 float shadow_spread,
430 Edges clipped_edges) { 469 Edges clipped_edges) {
431 if (ContextDisabled()) 470 if (ContextDisabled())
432 return; 471 return;
433 472
473 Color shadow_color = ApplyHighContrastFilter(orig_shadow_color);
474
434 FloatRect hole_rect(rect.Rect()); 475 FloatRect hole_rect(rect.Rect());
435 hole_rect.Inflate(-shadow_spread); 476 hole_rect.Inflate(-shadow_spread);
436 477
437 if (hole_rect.IsEmpty()) { 478 if (hole_rect.IsEmpty()) {
438 FillRoundedRect(rect, shadow_color); 479 FillRoundedRect(rect, shadow_color);
439 return; 480 return;
440 } 481 }
441 482
442 if (clipped_edges & kLeftEdge) { 483 if (clipped_edges & kLeftEdge) {
443 hole_rect.Move(-std::max(shadow_offset.Width(), 0.0f) - shadow_blur, 0); 484 hole_rect.Move(-std::max(shadow_offset.Width(), 0.0f) - shadow_blur, 0);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 if (is_vertical_line) { 571 if (is_vertical_line) {
531 p1.SetY(p1.Y() + width / 2.f); 572 p1.SetY(p1.Y() + width / 2.f);
532 p2.SetY(p2.Y() - width / 2.f); 573 p2.SetY(p2.Y() - width / 2.f);
533 } else { 574 } else {
534 p1.SetX(p1.X() + width / 2.f); 575 p1.SetX(p1.X() + width / 2.f);
535 p2.SetX(p2.X() - width / 2.f); 576 p2.SetX(p2.X() - width / 2.f);
536 } 577 }
537 } 578 }
538 579
539 AdjustLineToPixelBoundaries(p1, p2, width, pen_style); 580 AdjustLineToPixelBoundaries(p1, p2, width, pen_style);
540 canvas_->drawLine(p1.X(), p1.Y(), p2.X(), p2.Y(), flags); 581 canvas_->drawLine(p1.X(), p1.Y(), p2.X(), p2.Y(),
582 ApplyHighContrastFilter(&flags));
541 } 583 }
542 584
543 void GraphicsContext::DrawLineForText(const FloatPoint& pt, float width) { 585 void GraphicsContext::DrawLineForText(const FloatPoint& pt, float width) {
544 if (ContextDisabled()) 586 if (ContextDisabled())
545 return; 587 return;
546 588
547 if (width <= 0) 589 if (width <= 0)
548 return; 590 return;
549 591
550 PaintFlags flags; 592 PaintFlags flags;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 } 649 }
608 650
609 template <typename TextPaintInfo> 651 template <typename TextPaintInfo>
610 void GraphicsContext::DrawTextInternal(const Font& font, 652 void GraphicsContext::DrawTextInternal(const Font& font,
611 const TextPaintInfo& text_info, 653 const TextPaintInfo& text_info,
612 const FloatPoint& point, 654 const FloatPoint& point,
613 const PaintFlags& flags) { 655 const PaintFlags& flags) {
614 if (ContextDisabled()) 656 if (ContextDisabled())
615 return; 657 return;
616 658
617 if (font.DrawText(canvas_, text_info, point, device_scale_factor_, flags)) 659 if (font.DrawText(canvas_, text_info, point, device_scale_factor_,
660 ApplyHighContrastFilter(&flags))) {
618 paint_controller_.SetTextPainted(); 661 paint_controller_.SetTextPainted();
662 }
619 } 663 }
620 664
621 void GraphicsContext::DrawText(const Font& font, 665 void GraphicsContext::DrawText(const Font& font,
622 const TextRunPaintInfo& text_info, 666 const TextRunPaintInfo& text_info,
623 const FloatPoint& point, 667 const FloatPoint& point,
624 const PaintFlags& flags) { 668 const PaintFlags& flags) {
625 DrawTextInternal(font, text_info, point, flags); 669 DrawTextInternal(font, text_info, point, flags);
626 } 670 }
627 671
628 void GraphicsContext::DrawText(const Font& font, 672 void GraphicsContext::DrawText(const Font& font,
(...skipping 23 matching lines...) Expand all
652 } 696 }
653 697
654 template <typename TextPaintInfo> 698 template <typename TextPaintInfo>
655 void GraphicsContext::DrawTextInternal(const Font& font, 699 void GraphicsContext::DrawTextInternal(const Font& font,
656 const TextPaintInfo& text_info, 700 const TextPaintInfo& text_info,
657 const FloatPoint& point) { 701 const FloatPoint& point) {
658 if (ContextDisabled()) 702 if (ContextDisabled())
659 return; 703 return;
660 704
661 DrawTextPasses([&font, &text_info, &point, this](const PaintFlags& flags) { 705 DrawTextPasses([&font, &text_info, &point, this](const PaintFlags& flags) {
662 if (font.DrawText(canvas_, text_info, point, device_scale_factor_, flags)) 706 if (font.DrawText(canvas_, text_info, point, device_scale_factor_,
707 ApplyHighContrastFilter(&flags)))
663 paint_controller_.SetTextPainted(); 708 paint_controller_.SetTextPainted();
664 }); 709 });
665 } 710 }
666 711
667 void GraphicsContext::DrawText(const Font& font, 712 void GraphicsContext::DrawText(const Font& font,
668 const TextRunPaintInfo& text_info, 713 const TextRunPaintInfo& text_info,
669 const FloatPoint& point) { 714 const FloatPoint& point) {
670 DrawTextInternal(font, text_info, point); 715 DrawTextInternal(font, text_info, point);
671 } 716 }
672 717
673 void GraphicsContext::DrawText(const Font& font, 718 void GraphicsContext::DrawText(const Font& font,
674 const TextFragmentPaintInfo& text_info, 719 const TextFragmentPaintInfo& text_info,
675 const FloatPoint& point) { 720 const FloatPoint& point) {
676 DrawTextInternal(font, text_info, point); 721 DrawTextInternal(font, text_info, point);
677 } 722 }
678 723
679 template <typename TextPaintInfo> 724 template <typename TextPaintInfo>
680 void GraphicsContext::DrawEmphasisMarksInternal(const Font& font, 725 void GraphicsContext::DrawEmphasisMarksInternal(const Font& font,
681 const TextPaintInfo& text_info, 726 const TextPaintInfo& text_info,
682 const AtomicString& mark, 727 const AtomicString& mark,
683 const FloatPoint& point) { 728 const FloatPoint& point) {
684 if (ContextDisabled()) 729 if (ContextDisabled())
685 return; 730 return;
686 731
687 DrawTextPasses( 732 DrawTextPasses(
688 [&font, &text_info, &mark, &point, this](const PaintFlags& flags) { 733 [&font, &text_info, &mark, &point, this](const PaintFlags& flags) {
689 font.DrawEmphasisMarks(canvas_, text_info, mark, point, 734 font.DrawEmphasisMarks(canvas_, text_info, mark, point,
690 device_scale_factor_, flags); 735 device_scale_factor_,
736 ApplyHighContrastFilter(&flags));
691 }); 737 });
692 } 738 }
693 739
694 void GraphicsContext::DrawEmphasisMarks(const Font& font, 740 void GraphicsContext::DrawEmphasisMarks(const Font& font,
695 const TextRunPaintInfo& text_info, 741 const TextRunPaintInfo& text_info,
696 const AtomicString& mark, 742 const AtomicString& mark,
697 const FloatPoint& point) { 743 const FloatPoint& point) {
698 DrawEmphasisMarksInternal(font, text_info, mark, point); 744 DrawEmphasisMarksInternal(font, text_info, mark, point);
699 } 745 }
700 746
701 void GraphicsContext::DrawEmphasisMarks(const Font& font, 747 void GraphicsContext::DrawEmphasisMarks(const Font& font,
702 const TextFragmentPaintInfo& text_info, 748 const TextFragmentPaintInfo& text_info,
703 const AtomicString& mark, 749 const AtomicString& mark,
704 const FloatPoint& point) { 750 const FloatPoint& point) {
705 DrawEmphasisMarksInternal(font, text_info, mark, point); 751 DrawEmphasisMarksInternal(font, text_info, mark, point);
706 } 752 }
707 753
708 void GraphicsContext::DrawBidiText( 754 void GraphicsContext::DrawBidiText(
709 const Font& font, 755 const Font& font,
710 const TextRunPaintInfo& run_info, 756 const TextRunPaintInfo& run_info,
711 const FloatPoint& point, 757 const FloatPoint& point,
712 Font::CustomFontNotReadyAction custom_font_not_ready_action) { 758 Font::CustomFontNotReadyAction custom_font_not_ready_action) {
713 if (ContextDisabled()) 759 if (ContextDisabled())
714 return; 760 return;
715 761
716 DrawTextPasses([&font, &run_info, &point, custom_font_not_ready_action, 762 DrawTextPasses([&font, &run_info, &point, custom_font_not_ready_action,
717 this](const PaintFlags& flags) { 763 this](const PaintFlags& flags) {
718 if (font.DrawBidiText(canvas_, run_info, point, 764 if (font.DrawBidiText(canvas_, run_info, point,
719 custom_font_not_ready_action, device_scale_factor_, 765 custom_font_not_ready_action, device_scale_factor_,
720 flags)) 766 ApplyHighContrastFilter(&flags)))
721 paint_controller_.SetTextPainted(); 767 paint_controller_.SetTextPainted();
722 }); 768 });
723 } 769 }
724 770
725 void GraphicsContext::DrawHighlightForText(const Font& font, 771 void GraphicsContext::DrawHighlightForText(const Font& font,
726 const TextRun& run, 772 const TextRun& run,
727 const FloatPoint& point, 773 const FloatPoint& point,
728 int h, 774 int h,
729 const Color& background_color, 775 const Color& background_color,
730 int from, 776 int from,
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 image->DrawTiledBorder(*this, dest, src_rect, tile_scale_factor, h_rule, 910 image->DrawTiledBorder(*this, dest, src_rect, tile_scale_factor, h_rule,
865 v_rule, op); 911 v_rule, op);
866 paint_controller_.SetImagePainted(); 912 paint_controller_.SetImagePainted();
867 } 913 }
868 914
869 void GraphicsContext::DrawOval(const SkRect& oval, const PaintFlags& flags) { 915 void GraphicsContext::DrawOval(const SkRect& oval, const PaintFlags& flags) {
870 if (ContextDisabled()) 916 if (ContextDisabled())
871 return; 917 return;
872 DCHECK(canvas_); 918 DCHECK(canvas_);
873 919
874 canvas_->drawOval(oval, flags); 920 canvas_->drawOval(oval, ApplyHighContrastFilter(&flags));
875 } 921 }
876 922
877 void GraphicsContext::DrawPath(const SkPath& path, const PaintFlags& flags) { 923 void GraphicsContext::DrawPath(const SkPath& path, const PaintFlags& flags) {
878 if (ContextDisabled()) 924 if (ContextDisabled())
879 return; 925 return;
880 DCHECK(canvas_); 926 DCHECK(canvas_);
881 927
882 canvas_->drawPath(path, flags); 928 canvas_->drawPath(path, ApplyHighContrastFilter(&flags));
883 } 929 }
884 930
885 void GraphicsContext::DrawRect(const SkRect& rect, const PaintFlags& flags) { 931 void GraphicsContext::DrawRect(const SkRect& rect, const PaintFlags& flags) {
886 if (ContextDisabled()) 932 if (ContextDisabled())
887 return; 933 return;
888 DCHECK(canvas_); 934 DCHECK(canvas_);
889 935
890 canvas_->drawRect(rect, flags); 936 canvas_->drawRect(rect, ApplyHighContrastFilter(&flags));
891 } 937 }
892 938
893 void GraphicsContext::DrawRRect(const SkRRect& rrect, const PaintFlags& flags) { 939 void GraphicsContext::DrawRRect(const SkRRect& rrect, const PaintFlags& flags) {
894 if (ContextDisabled()) 940 if (ContextDisabled())
895 return; 941 return;
896 DCHECK(canvas_); 942 DCHECK(canvas_);
897 943
898 canvas_->drawRRect(rrect, flags); 944 canvas_->drawRRect(rrect, ApplyHighContrastFilter(&flags));
899 } 945 }
900 946
901 void GraphicsContext::FillPath(const Path& path_to_fill) { 947 void GraphicsContext::FillPath(const Path& path_to_fill) {
902 if (ContextDisabled() || path_to_fill.IsEmpty()) 948 if (ContextDisabled() || path_to_fill.IsEmpty())
903 return; 949 return;
904 950
905 DrawPath(path_to_fill.GetSkPath(), ImmutableState()->FillFlags()); 951 DrawPath(path_to_fill.GetSkPath(), ImmutableState()->FillFlags());
906 } 952 }
907 953
908 void GraphicsContext::FillRect(const FloatRect& rect) { 954 void GraphicsContext::FillRect(const FloatRect& rect) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 const Color& color) { 1054 const Color& color) {
1009 if (ContextDisabled()) 1055 if (ContextDisabled())
1010 return; 1056 return;
1011 DCHECK(canvas_); 1057 DCHECK(canvas_);
1012 1058
1013 if (!IsSimpleDRRect(outer, inner)) { 1059 if (!IsSimpleDRRect(outer, inner)) {
1014 if (color == FillColor()) { 1060 if (color == FillColor()) {
1015 canvas_->drawDRRect(outer, inner, ImmutableState()->FillFlags()); 1061 canvas_->drawDRRect(outer, inner, ImmutableState()->FillFlags());
1016 } else { 1062 } else {
1017 PaintFlags flags(ImmutableState()->FillFlags()); 1063 PaintFlags flags(ImmutableState()->FillFlags());
1018 flags.setColor(color.Rgb()); 1064 flags.setColor(ApplyHighContrastFilter(color).Rgb());
1019 canvas_->drawDRRect(outer, inner, flags); 1065 canvas_->drawDRRect(outer, inner, flags);
1020 } 1066 }
1021 1067
1022 return; 1068 return;
1023 } 1069 }
1024 1070
1025 // We can draw this as a stroked rrect. 1071 // We can draw this as a stroked rrect.
1026 float stroke_width = inner.Rect().X() - outer.Rect().X(); 1072 float stroke_width = inner.Rect().X() - outer.Rect().X();
1027 SkRRect stroke_r_rect = outer; 1073 SkRRect stroke_r_rect = outer;
1028 stroke_r_rect.inset(stroke_width / 2, stroke_width / 2); 1074 stroke_r_rect.inset(stroke_width / 2, stroke_width / 2);
1029 1075
1030 PaintFlags stroke_flags(ImmutableState()->FillFlags()); 1076 PaintFlags stroke_flags(ImmutableState()->FillFlags());
1031 stroke_flags.setColor(color.Rgb()); 1077 stroke_flags.setColor(ApplyHighContrastFilter(color).Rgb());
1032 stroke_flags.setStyle(PaintFlags::kStroke_Style); 1078 stroke_flags.setStyle(PaintFlags::kStroke_Style);
1033 stroke_flags.setStrokeWidth(stroke_width); 1079 stroke_flags.setStrokeWidth(stroke_width);
1034 1080
1035 canvas_->drawRRect(stroke_r_rect, stroke_flags); 1081 canvas_->drawRRect(stroke_r_rect, stroke_flags);
1036 } 1082 }
1037 1083
1038 void GraphicsContext::FillEllipse(const FloatRect& ellipse) { 1084 void GraphicsContext::FillEllipse(const FloatRect& ellipse) {
1039 if (ContextDisabled()) 1085 if (ContextDisabled())
1040 return; 1086 return;
1041 1087
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 } 1259 }
1214 1260
1215 void GraphicsContext::FillRectWithRoundedHole( 1261 void GraphicsContext::FillRectWithRoundedHole(
1216 const FloatRect& rect, 1262 const FloatRect& rect,
1217 const FloatRoundedRect& rounded_hole_rect, 1263 const FloatRoundedRect& rounded_hole_rect,
1218 const Color& color) { 1264 const Color& color) {
1219 if (ContextDisabled()) 1265 if (ContextDisabled())
1220 return; 1266 return;
1221 1267
1222 PaintFlags flags(ImmutableState()->FillFlags()); 1268 PaintFlags flags(ImmutableState()->FillFlags());
1223 flags.setColor(color.Rgb()); 1269 flags.setColor(ApplyHighContrastFilter(color).Rgb());
1224 canvas_->drawDRRect(SkRRect::MakeRect(rect), rounded_hole_rect, flags); 1270 canvas_->drawDRRect(SkRRect::MakeRect(rect), rounded_hole_rect, flags);
1225 } 1271 }
1226 1272
1227 void GraphicsContext::AdjustLineToPixelBoundaries(FloatPoint& p1, 1273 void GraphicsContext::AdjustLineToPixelBoundaries(FloatPoint& p1,
1228 FloatPoint& p2, 1274 FloatPoint& p2,
1229 float stroke_width, 1275 float stroke_width,
1230 StrokeStyle pen_style) { 1276 StrokeStyle pen_style) {
1231 // For odd widths, we add in 0.5 to the appropriate x/y so that the float 1277 // For odd widths, we add in 0.5 to the appropriate x/y so that the float
1232 // arithmetic works out. For example, with a border width of 3, WebKit will 1278 // arithmetic works out. For example, with a border width of 3, WebKit will
1233 // pass us (y1+y2)/2, e.g., (50+53)/2 = 103/2 = 51 when we want 51.5. It is 1279 // pass us (y1+y2)/2, e.g., (50+53)/2 = 103/2 = 51 when we want 51.5. It is
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1270 case kColorFilterNone: 1316 case kColorFilterNone:
1271 break; 1317 break;
1272 default: 1318 default:
1273 NOTREACHED(); 1319 NOTREACHED();
1274 break; 1320 break;
1275 } 1321 }
1276 1322
1277 return nullptr; 1323 return nullptr;
1278 } 1324 }
1279 1325
1326 Color GraphicsContext::ApplyHighContrastFilter(const Color& input) const {
1327 if (!high_contrast_filter_)
1328 return input;
1329
1330 SkColor sk_input =
1331 SkColorSetARGB(input.Alpha(), input.Red(), input.Green(), input.Blue());
1332 SkColor sk_output = high_contrast_filter_->filterColor(sk_input);
1333 return Color(MakeRGBA(SkColorGetR(sk_output), SkColorGetG(sk_output),
1334 SkColorGetB(sk_output), SkColorGetA(sk_output)));
1335 }
1336
1337 PaintFlags GraphicsContext::ApplyHighContrastFilter(
1338 const PaintFlags* input) const {
1339 if (input && !high_contrast_filter_)
1340 return *input;
1341
1342 PaintFlags output;
1343 if (input)
1344 output = *input;
1345 if (output.getShader()) {
1346 output.setColorFilter(high_contrast_filter_);
1347 } else {
1348 output.setColor(high_contrast_filter_->filterColor(output.getColor()));
1349 }
1350 return output;
1351 }
1352
1280 } // namespace blink 1353 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698