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

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

Issue 2878573003: Initial skeleton of high-contrast mode. (Closed)
Patch Set: Rebase Created 3 years, 6 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) {
146 high_contrast_settings_ = settings;
147
148 SkHighContrastConfig config;
149 switch (high_contrast_settings_.mode) {
150 case HighContrastMode::kOff:
151 high_contrast_filter_.reset(nullptr);
152 return;
153 case HighContrastMode::kSimpleInvertForTesting: {
154 uint8_t identity[256], invert[256];
155 for (int i = 0; i < 256; ++i) {
156 identity[i] = i;
157 invert[i] = 255 - i;
158 }
159 high_contrast_filter_ =
160 SkTableColorFilter::MakeARGB(identity, invert, invert, invert);
161 return;
162 }
163 case HighContrastMode::kInvertBrightness:
164 config.fInvertStyle =
165 SkHighContrastConfig::InvertStyle::kInvertBrightness;
166 break;
167 case HighContrastMode::kInvertLightness:
168 config.fInvertStyle = SkHighContrastConfig::InvertStyle::kInvertLightness;
169 break;
170 }
171
172 config.fGrayscale = high_contrast_settings_.grayscale;
173 config.fContrast = high_contrast_settings_.contrast;
174 high_contrast_filter_ = SkHighContrastFilter::Make(config);
175 }
176
143 void GraphicsContext::SaveLayer(const SkRect* bounds, const PaintFlags* flags) { 177 void GraphicsContext::SaveLayer(const SkRect* bounds, const PaintFlags* flags) {
144 if (ContextDisabled()) 178 if (ContextDisabled())
145 return; 179 return;
146 180
147 DCHECK(canvas_); 181 DCHECK(canvas_);
148 canvas_->saveLayer(bounds, flags); 182 canvas_->saveLayer(bounds, flags);
149 } 183 }
150 184
151 void GraphicsContext::RestoreLayer() { 185 void GraphicsContext::RestoreLayer() {
152 if (ContextDisabled()) 186 if (ContextDisabled())
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 int GraphicsContext::FocusRingOutsetExtent(int offset, int width) { 378 int GraphicsContext::FocusRingOutsetExtent(int offset, int width) {
345 // Unlike normal outlines (whole width is outside of the offset), focus 379 // 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 380 // 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. 381 // only half of the width is outside of the offset.
348 return AdjustedFocusRingOffset(offset) + (width + 1) / 2; 382 return AdjustedFocusRingOffset(offset) + (width + 1) / 2;
349 } 383 }
350 384
351 void GraphicsContext::DrawFocusRingPath(const SkPath& path, 385 void GraphicsContext::DrawFocusRingPath(const SkPath& path,
352 const Color& color, 386 const Color& color,
353 float width) { 387 float width) {
354 DrawPlatformFocusRing(path, canvas_, color.Rgb(), width); 388 DrawPlatformFocusRing(path, canvas_, ApplyHighContrastFilter(color).Rgb(),
389 width);
355 } 390 }
356 391
357 void GraphicsContext::DrawFocusRingRect(const SkRect& rect, 392 void GraphicsContext::DrawFocusRingRect(const SkRect& rect,
358 const Color& color, 393 const Color& color,
359 float width) { 394 float width) {
360 DrawPlatformFocusRing(rect, canvas_, color.Rgb(), width); 395 DrawPlatformFocusRing(rect, canvas_, ApplyHighContrastFilter(color).Rgb(),
396 width);
361 } 397 }
362 398
363 void GraphicsContext::DrawFocusRing(const Path& focus_ring_path, 399 void GraphicsContext::DrawFocusRing(const Path& focus_ring_path,
364 float width, 400 float width,
365 int offset, 401 int offset,
366 const Color& color) { 402 const Color& color) {
367 // FIXME: Implement support for offset. 403 // FIXME: Implement support for offset.
368 if (ContextDisabled()) 404 if (ContextDisabled())
369 return; 405 return;
370 406
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 452
417 if (shadow_spread < 0) 453 if (shadow_spread < 0)
418 bounds.Inflate(-shadow_spread); 454 bounds.Inflate(-shadow_spread);
419 455
420 FloatRect offset_bounds = bounds; 456 FloatRect offset_bounds = bounds;
421 offset_bounds.Move(-shadow_offset); 457 offset_bounds.Move(-shadow_offset);
422 return UnionRect(bounds, offset_bounds); 458 return UnionRect(bounds, offset_bounds);
423 } 459 }
424 460
425 void GraphicsContext::DrawInnerShadow(const FloatRoundedRect& rect, 461 void GraphicsContext::DrawInnerShadow(const FloatRoundedRect& rect,
426 const Color& shadow_color, 462 const Color& orig_shadow_color,
427 const FloatSize& shadow_offset, 463 const FloatSize& shadow_offset,
428 float shadow_blur, 464 float shadow_blur,
429 float shadow_spread, 465 float shadow_spread,
430 Edges clipped_edges) { 466 Edges clipped_edges) {
431 if (ContextDisabled()) 467 if (ContextDisabled())
432 return; 468 return;
433 469
470 Color shadow_color = ApplyHighContrastFilter(orig_shadow_color);
471
434 FloatRect hole_rect(rect.Rect()); 472 FloatRect hole_rect(rect.Rect());
435 hole_rect.Inflate(-shadow_spread); 473 hole_rect.Inflate(-shadow_spread);
436 474
437 if (hole_rect.IsEmpty()) { 475 if (hole_rect.IsEmpty()) {
438 FillRoundedRect(rect, shadow_color); 476 FillRoundedRect(rect, shadow_color);
439 return; 477 return;
440 } 478 }
441 479
442 if (clipped_edges & kLeftEdge) { 480 if (clipped_edges & kLeftEdge) {
443 hole_rect.Move(-std::max(shadow_offset.Width(), 0.0f) - shadow_blur, 0); 481 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) { 568 if (is_vertical_line) {
531 p1.SetY(p1.Y() + width / 2.f); 569 p1.SetY(p1.Y() + width / 2.f);
532 p2.SetY(p2.Y() - width / 2.f); 570 p2.SetY(p2.Y() - width / 2.f);
533 } else { 571 } else {
534 p1.SetX(p1.X() + width / 2.f); 572 p1.SetX(p1.X() + width / 2.f);
535 p2.SetX(p2.X() - width / 2.f); 573 p2.SetX(p2.X() - width / 2.f);
536 } 574 }
537 } 575 }
538 576
539 AdjustLineToPixelBoundaries(p1, p2, width, pen_style); 577 AdjustLineToPixelBoundaries(p1, p2, width, pen_style);
540 canvas_->drawLine(p1.X(), p1.Y(), p2.X(), p2.Y(), flags); 578 canvas_->drawLine(p1.X(), p1.Y(), p2.X(), p2.Y(),
579 ApplyHighContrastFilter(&flags));
541 } 580 }
542 581
543 void GraphicsContext::DrawLineForText(const FloatPoint& pt, float width) { 582 void GraphicsContext::DrawLineForText(const FloatPoint& pt, float width) {
544 if (ContextDisabled()) 583 if (ContextDisabled())
545 return; 584 return;
546 585
547 if (width <= 0) 586 if (width <= 0)
548 return; 587 return;
549 588
550 PaintFlags flags; 589 PaintFlags flags;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 } 646 }
608 647
609 template <typename TextPaintInfo> 648 template <typename TextPaintInfo>
610 void GraphicsContext::DrawTextInternal(const Font& font, 649 void GraphicsContext::DrawTextInternal(const Font& font,
611 const TextPaintInfo& text_info, 650 const TextPaintInfo& text_info,
612 const FloatPoint& point, 651 const FloatPoint& point,
613 const PaintFlags& flags) { 652 const PaintFlags& flags) {
614 if (ContextDisabled()) 653 if (ContextDisabled())
615 return; 654 return;
616 655
617 if (font.DrawText(canvas_, text_info, point, device_scale_factor_, flags)) 656 if (font.DrawText(canvas_, text_info, point, device_scale_factor_,
657 ApplyHighContrastFilter(&flags))) {
618 paint_controller_.SetTextPainted(); 658 paint_controller_.SetTextPainted();
659 }
619 } 660 }
620 661
621 void GraphicsContext::DrawText(const Font& font, 662 void GraphicsContext::DrawText(const Font& font,
622 const TextRunPaintInfo& text_info, 663 const TextRunPaintInfo& text_info,
623 const FloatPoint& point, 664 const FloatPoint& point,
624 const PaintFlags& flags) { 665 const PaintFlags& flags) {
625 DrawTextInternal(font, text_info, point, flags); 666 DrawTextInternal(font, text_info, point, flags);
626 } 667 }
627 668
628 void GraphicsContext::DrawText(const Font& font, 669 void GraphicsContext::DrawText(const Font& font,
(...skipping 23 matching lines...) Expand all
652 } 693 }
653 694
654 template <typename TextPaintInfo> 695 template <typename TextPaintInfo>
655 void GraphicsContext::DrawTextInternal(const Font& font, 696 void GraphicsContext::DrawTextInternal(const Font& font,
656 const TextPaintInfo& text_info, 697 const TextPaintInfo& text_info,
657 const FloatPoint& point) { 698 const FloatPoint& point) {
658 if (ContextDisabled()) 699 if (ContextDisabled())
659 return; 700 return;
660 701
661 DrawTextPasses([&font, &text_info, &point, this](const PaintFlags& flags) { 702 DrawTextPasses([&font, &text_info, &point, this](const PaintFlags& flags) {
662 if (font.DrawText(canvas_, text_info, point, device_scale_factor_, flags)) 703 if (font.DrawText(canvas_, text_info, point, device_scale_factor_,
704 ApplyHighContrastFilter(&flags)))
663 paint_controller_.SetTextPainted(); 705 paint_controller_.SetTextPainted();
664 }); 706 });
665 } 707 }
666 708
667 void GraphicsContext::DrawText(const Font& font, 709 void GraphicsContext::DrawText(const Font& font,
668 const TextRunPaintInfo& text_info, 710 const TextRunPaintInfo& text_info,
669 const FloatPoint& point) { 711 const FloatPoint& point) {
670 DrawTextInternal(font, text_info, point); 712 DrawTextInternal(font, text_info, point);
671 } 713 }
672 714
673 void GraphicsContext::DrawText(const Font& font, 715 void GraphicsContext::DrawText(const Font& font,
674 const TextFragmentPaintInfo& text_info, 716 const TextFragmentPaintInfo& text_info,
675 const FloatPoint& point) { 717 const FloatPoint& point) {
676 DrawTextInternal(font, text_info, point); 718 DrawTextInternal(font, text_info, point);
677 } 719 }
678 720
679 template <typename TextPaintInfo> 721 template <typename TextPaintInfo>
680 void GraphicsContext::DrawEmphasisMarksInternal(const Font& font, 722 void GraphicsContext::DrawEmphasisMarksInternal(const Font& font,
681 const TextPaintInfo& text_info, 723 const TextPaintInfo& text_info,
682 const AtomicString& mark, 724 const AtomicString& mark,
683 const FloatPoint& point) { 725 const FloatPoint& point) {
684 if (ContextDisabled()) 726 if (ContextDisabled())
685 return; 727 return;
686 728
687 DrawTextPasses( 729 DrawTextPasses(
688 [&font, &text_info, &mark, &point, this](const PaintFlags& flags) { 730 [&font, &text_info, &mark, &point, this](const PaintFlags& flags) {
689 font.DrawEmphasisMarks(canvas_, text_info, mark, point, 731 font.DrawEmphasisMarks(canvas_, text_info, mark, point,
690 device_scale_factor_, flags); 732 device_scale_factor_,
733 ApplyHighContrastFilter(&flags));
691 }); 734 });
692 } 735 }
693 736
694 void GraphicsContext::DrawEmphasisMarks(const Font& font, 737 void GraphicsContext::DrawEmphasisMarks(const Font& font,
695 const TextRunPaintInfo& text_info, 738 const TextRunPaintInfo& text_info,
696 const AtomicString& mark, 739 const AtomicString& mark,
697 const FloatPoint& point) { 740 const FloatPoint& point) {
698 DrawEmphasisMarksInternal(font, text_info, mark, point); 741 DrawEmphasisMarksInternal(font, text_info, mark, point);
699 } 742 }
700 743
701 void GraphicsContext::DrawEmphasisMarks(const Font& font, 744 void GraphicsContext::DrawEmphasisMarks(const Font& font,
702 const TextFragmentPaintInfo& text_info, 745 const TextFragmentPaintInfo& text_info,
703 const AtomicString& mark, 746 const AtomicString& mark,
704 const FloatPoint& point) { 747 const FloatPoint& point) {
705 DrawEmphasisMarksInternal(font, text_info, mark, point); 748 DrawEmphasisMarksInternal(font, text_info, mark, point);
706 } 749 }
707 750
708 void GraphicsContext::DrawBidiText( 751 void GraphicsContext::DrawBidiText(
709 const Font& font, 752 const Font& font,
710 const TextRunPaintInfo& run_info, 753 const TextRunPaintInfo& run_info,
711 const FloatPoint& point, 754 const FloatPoint& point,
712 Font::CustomFontNotReadyAction custom_font_not_ready_action) { 755 Font::CustomFontNotReadyAction custom_font_not_ready_action) {
713 if (ContextDisabled()) 756 if (ContextDisabled())
714 return; 757 return;
715 758
716 DrawTextPasses([&font, &run_info, &point, custom_font_not_ready_action, 759 DrawTextPasses([&font, &run_info, &point, custom_font_not_ready_action,
717 this](const PaintFlags& flags) { 760 this](const PaintFlags& flags) {
718 if (font.DrawBidiText(canvas_, run_info, point, 761 if (font.DrawBidiText(canvas_, run_info, point,
719 custom_font_not_ready_action, device_scale_factor_, 762 custom_font_not_ready_action, device_scale_factor_,
720 flags)) 763 ApplyHighContrastFilter(&flags)))
721 paint_controller_.SetTextPainted(); 764 paint_controller_.SetTextPainted();
722 }); 765 });
723 } 766 }
724 767
725 void GraphicsContext::DrawHighlightForText(const Font& font, 768 void GraphicsContext::DrawHighlightForText(const Font& font,
726 const TextRun& run, 769 const TextRun& run,
727 const FloatPoint& point, 770 const FloatPoint& point,
728 int h, 771 int h,
729 const Color& background_color, 772 const Color& background_color,
730 int from, 773 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, 907 image->DrawTiledBorder(*this, dest, src_rect, tile_scale_factor, h_rule,
865 v_rule, op); 908 v_rule, op);
866 paint_controller_.SetImagePainted(); 909 paint_controller_.SetImagePainted();
867 } 910 }
868 911
869 void GraphicsContext::DrawOval(const SkRect& oval, const PaintFlags& flags) { 912 void GraphicsContext::DrawOval(const SkRect& oval, const PaintFlags& flags) {
870 if (ContextDisabled()) 913 if (ContextDisabled())
871 return; 914 return;
872 DCHECK(canvas_); 915 DCHECK(canvas_);
873 916
874 canvas_->drawOval(oval, flags); 917 canvas_->drawOval(oval, ApplyHighContrastFilter(&flags));
875 } 918 }
876 919
877 void GraphicsContext::DrawPath(const SkPath& path, const PaintFlags& flags) { 920 void GraphicsContext::DrawPath(const SkPath& path, const PaintFlags& flags) {
878 if (ContextDisabled()) 921 if (ContextDisabled())
879 return; 922 return;
880 DCHECK(canvas_); 923 DCHECK(canvas_);
881 924
882 canvas_->drawPath(path, flags); 925 canvas_->drawPath(path, ApplyHighContrastFilter(&flags));
883 } 926 }
884 927
885 void GraphicsContext::DrawRect(const SkRect& rect, const PaintFlags& flags) { 928 void GraphicsContext::DrawRect(const SkRect& rect, const PaintFlags& flags) {
886 if (ContextDisabled()) 929 if (ContextDisabled())
887 return; 930 return;
888 DCHECK(canvas_); 931 DCHECK(canvas_);
889 932
890 canvas_->drawRect(rect, flags); 933 canvas_->drawRect(rect, ApplyHighContrastFilter(&flags));
891 } 934 }
892 935
893 void GraphicsContext::DrawRRect(const SkRRect& rrect, const PaintFlags& flags) { 936 void GraphicsContext::DrawRRect(const SkRRect& rrect, const PaintFlags& flags) {
894 if (ContextDisabled()) 937 if (ContextDisabled())
895 return; 938 return;
896 DCHECK(canvas_); 939 DCHECK(canvas_);
897 940
898 canvas_->drawRRect(rrect, flags); 941 canvas_->drawRRect(rrect, ApplyHighContrastFilter(&flags));
899 } 942 }
900 943
901 void GraphicsContext::FillPath(const Path& path_to_fill) { 944 void GraphicsContext::FillPath(const Path& path_to_fill) {
902 if (ContextDisabled() || path_to_fill.IsEmpty()) 945 if (ContextDisabled() || path_to_fill.IsEmpty())
903 return; 946 return;
904 947
905 DrawPath(path_to_fill.GetSkPath(), ImmutableState()->FillFlags()); 948 DrawPath(path_to_fill.GetSkPath(), ImmutableState()->FillFlags());
906 } 949 }
907 950
908 void GraphicsContext::FillRect(const FloatRect& rect) { 951 void GraphicsContext::FillRect(const FloatRect& rect) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 const Color& color) { 1051 const Color& color) {
1009 if (ContextDisabled()) 1052 if (ContextDisabled())
1010 return; 1053 return;
1011 DCHECK(canvas_); 1054 DCHECK(canvas_);
1012 1055
1013 if (!IsSimpleDRRect(outer, inner)) { 1056 if (!IsSimpleDRRect(outer, inner)) {
1014 if (color == FillColor()) { 1057 if (color == FillColor()) {
1015 canvas_->drawDRRect(outer, inner, ImmutableState()->FillFlags()); 1058 canvas_->drawDRRect(outer, inner, ImmutableState()->FillFlags());
1016 } else { 1059 } else {
1017 PaintFlags flags(ImmutableState()->FillFlags()); 1060 PaintFlags flags(ImmutableState()->FillFlags());
1018 flags.setColor(color.Rgb()); 1061 flags.setColor(ApplyHighContrastFilter(color).Rgb());
1019 canvas_->drawDRRect(outer, inner, flags); 1062 canvas_->drawDRRect(outer, inner, flags);
1020 } 1063 }
1021 1064
1022 return; 1065 return;
1023 } 1066 }
1024 1067
1025 // We can draw this as a stroked rrect. 1068 // We can draw this as a stroked rrect.
1026 float stroke_width = inner.Rect().X() - outer.Rect().X(); 1069 float stroke_width = inner.Rect().X() - outer.Rect().X();
1027 SkRRect stroke_r_rect = outer; 1070 SkRRect stroke_r_rect = outer;
1028 stroke_r_rect.inset(stroke_width / 2, stroke_width / 2); 1071 stroke_r_rect.inset(stroke_width / 2, stroke_width / 2);
1029 1072
1030 PaintFlags stroke_flags(ImmutableState()->FillFlags()); 1073 PaintFlags stroke_flags(ImmutableState()->FillFlags());
1031 stroke_flags.setColor(color.Rgb()); 1074 stroke_flags.setColor(ApplyHighContrastFilter(color).Rgb());
1032 stroke_flags.setStyle(PaintFlags::kStroke_Style); 1075 stroke_flags.setStyle(PaintFlags::kStroke_Style);
1033 stroke_flags.setStrokeWidth(stroke_width); 1076 stroke_flags.setStrokeWidth(stroke_width);
1034 1077
1035 canvas_->drawRRect(stroke_r_rect, stroke_flags); 1078 canvas_->drawRRect(stroke_r_rect, stroke_flags);
1036 } 1079 }
1037 1080
1038 void GraphicsContext::FillEllipse(const FloatRect& ellipse) { 1081 void GraphicsContext::FillEllipse(const FloatRect& ellipse) {
1039 if (ContextDisabled()) 1082 if (ContextDisabled())
1040 return; 1083 return;
1041 1084
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 } 1256 }
1214 1257
1215 void GraphicsContext::FillRectWithRoundedHole( 1258 void GraphicsContext::FillRectWithRoundedHole(
1216 const FloatRect& rect, 1259 const FloatRect& rect,
1217 const FloatRoundedRect& rounded_hole_rect, 1260 const FloatRoundedRect& rounded_hole_rect,
1218 const Color& color) { 1261 const Color& color) {
1219 if (ContextDisabled()) 1262 if (ContextDisabled())
1220 return; 1263 return;
1221 1264
1222 PaintFlags flags(ImmutableState()->FillFlags()); 1265 PaintFlags flags(ImmutableState()->FillFlags());
1223 flags.setColor(color.Rgb()); 1266 flags.setColor(ApplyHighContrastFilter(color).Rgb());
1224 canvas_->drawDRRect(SkRRect::MakeRect(rect), rounded_hole_rect, flags); 1267 canvas_->drawDRRect(SkRRect::MakeRect(rect), rounded_hole_rect, flags);
1225 } 1268 }
1226 1269
1227 void GraphicsContext::AdjustLineToPixelBoundaries(FloatPoint& p1, 1270 void GraphicsContext::AdjustLineToPixelBoundaries(FloatPoint& p1,
1228 FloatPoint& p2, 1271 FloatPoint& p2,
1229 float stroke_width, 1272 float stroke_width,
1230 StrokeStyle pen_style) { 1273 StrokeStyle pen_style) {
1231 // For odd widths, we add in 0.5 to the appropriate x/y so that the float 1274 // 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 1275 // 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 1276 // 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: 1313 case kColorFilterNone:
1271 break; 1314 break;
1272 default: 1315 default:
1273 NOTREACHED(); 1316 NOTREACHED();
1274 break; 1317 break;
1275 } 1318 }
1276 1319
1277 return nullptr; 1320 return nullptr;
1278 } 1321 }
1279 1322
1323 Color GraphicsContext::ApplyHighContrastFilter(const Color& input) const {
1324 if (!high_contrast_filter_)
1325 return input;
1326
1327 SkColor sk_input =
1328 SkColorSetARGB(input.Alpha(), input.Red(), input.Green(), input.Blue());
1329 SkColor sk_output = high_contrast_filter_->filterColor(sk_input);
1330 return Color(MakeRGBA(SkColorGetR(sk_output), SkColorGetG(sk_output),
1331 SkColorGetB(sk_output), SkColorGetA(sk_output)));
1332 }
1333
1334 PaintFlags GraphicsContext::ApplyHighContrastFilter(
1335 const PaintFlags* input) const {
1336 if (input && !high_contrast_filter_)
1337 return *input;
1338
1339 PaintFlags output;
1340 if (input)
1341 output = *input;
1342 if (output.getSkShader()) {
1343 output.setColorFilter(high_contrast_filter_);
1344 } else {
1345 output.setColor(high_contrast_filter_->filterColor(output.getColor()));
1346 }
1347 return output;
1348 }
1349
1280 } // namespace blink 1350 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698