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

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

Issue 2878573003: Initial skeleton of high-contrast mode. (Closed)
Patch Set: Don't pass settings to GraphicsLayer, address other feedback from chrishtr 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(
58 DisabledMode disable_context_or_painting, 60 PaintController& paint_controller,
59 SkMetaData* meta_data) 61 const HighContrastSettings* high_contrast_settings,
62 DisabledMode disable_context_or_painting,
63 SkMetaData* meta_data)
60 : canvas_(nullptr), 64 : canvas_(nullptr),
61 paint_controller_(paint_controller), 65 paint_controller_(paint_controller),
62 paint_state_stack_(), 66 paint_state_stack_(),
63 paint_state_index_(0), 67 paint_state_index_(0),
64 #if DCHECK_IS_ON() 68 #if DCHECK_IS_ON()
65 layer_count_(0), 69 layer_count_(0),
66 disable_destruction_checks_(false), 70 disable_destruction_checks_(false),
67 in_drawing_recorder_(false), 71 in_drawing_recorder_(false),
68 #endif 72 #endif
69 disabled_state_(disable_context_or_painting), 73 disabled_state_(disable_context_or_painting),
70 device_scale_factor_(1.0f), 74 device_scale_factor_(1.0f),
71 printing_(false), 75 printing_(false),
72 has_meta_data_(!!meta_data) { 76 has_meta_data_(!!meta_data) {
73 if (meta_data) 77 if (meta_data)
74 meta_data_ = *meta_data; 78 meta_data_ = *meta_data;
75 79
76 // FIXME: Do some tests to determine how many states are typically used, and 80 // FIXME: Do some tests to determine how many states are typically used, and
77 // allocate several here. 81 // allocate several here.
78 paint_state_stack_.push_back(GraphicsContextState::Create()); 82 paint_state_stack_.push_back(GraphicsContextState::Create());
79 paint_state_ = paint_state_stack_.back().get(); 83 paint_state_ = paint_state_stack_.back().get();
80 84
81 if (ContextDisabled()) { 85 if (ContextDisabled()) {
82 DEFINE_STATIC_LOCAL(SkCanvas*, null_sk_canvas, 86 DEFINE_STATIC_LOCAL(SkCanvas*, null_sk_canvas,
83 (SkMakeNullCanvas().release())); 87 (SkMakeNullCanvas().release()));
84 DEFINE_STATIC_LOCAL(SkiaPaintCanvas, null_canvas, (null_sk_canvas)); 88 DEFINE_STATIC_LOCAL(SkiaPaintCanvas, null_canvas, (null_sk_canvas));
85 canvas_ = &null_canvas; 89 canvas_ = &null_canvas;
86 } 90 }
91
92 if (high_contrast_settings) {
93 high_contrast_settings_ = *high_contrast_settings;
94 UpdateHighContrastFilterFromSettings();
95 }
87 } 96 }
88 97
89 GraphicsContext::~GraphicsContext() { 98 GraphicsContext::~GraphicsContext() {
90 #if DCHECK_IS_ON() 99 #if DCHECK_IS_ON()
91 if (!disable_destruction_checks_) { 100 if (!disable_destruction_checks_) {
92 DCHECK(!paint_state_index_); 101 DCHECK(!paint_state_index_);
93 DCHECK(!paint_state_->SaveCount()); 102 DCHECK(!paint_state_->SaveCount());
94 DCHECK(!layer_count_); 103 DCHECK(!layer_count_);
95 DCHECK(!SaveCount()); 104 DCHECK(!SaveCount());
96 } 105 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 // (on top of its own saveCount), except for the first frame. 142 // (on top of its own saveCount), except for the first frame.
134 unsigned count = paint_state_index_; 143 unsigned count = paint_state_index_;
135 DCHECK_GE(paint_state_stack_.size(), paint_state_index_); 144 DCHECK_GE(paint_state_stack_.size(), paint_state_index_);
136 for (unsigned i = 0; i <= paint_state_index_; ++i) 145 for (unsigned i = 0; i <= paint_state_index_; ++i)
137 count += paint_state_stack_[i]->SaveCount(); 146 count += paint_state_stack_[i]->SaveCount();
138 147
139 return count; 148 return count;
140 } 149 }
141 #endif 150 #endif
142 151
152 void GraphicsContext::SetHighContrast(const HighContrastSettings& settings) {
153 high_contrast_settings_ = settings;
154 UpdateHighContrastFilterFromSettings();
155 }
156
143 void GraphicsContext::SaveLayer(const SkRect* bounds, const PaintFlags* flags) { 157 void GraphicsContext::SaveLayer(const SkRect* bounds, const PaintFlags* flags) {
144 if (ContextDisabled()) 158 if (ContextDisabled())
145 return; 159 return;
146 160
147 DCHECK(canvas_); 161 DCHECK(canvas_);
148 canvas_->saveLayer(bounds, flags); 162 canvas_->saveLayer(bounds, flags);
149 } 163 }
150 164
151 void GraphicsContext::RestoreLayer() { 165 void GraphicsContext::RestoreLayer() {
152 if (ContextDisabled()) 166 if (ContextDisabled())
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 int GraphicsContext::FocusRingOutsetExtent(int offset, int width) { 358 int GraphicsContext::FocusRingOutsetExtent(int offset, int width) {
345 // Unlike normal outlines (whole width is outside of the offset), focus 359 // 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 360 // 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. 361 // only half of the width is outside of the offset.
348 return AdjustedFocusRingOffset(offset) + (width + 1) / 2; 362 return AdjustedFocusRingOffset(offset) + (width + 1) / 2;
349 } 363 }
350 364
351 void GraphicsContext::DrawFocusRingPath(const SkPath& path, 365 void GraphicsContext::DrawFocusRingPath(const SkPath& path,
352 const Color& color, 366 const Color& color,
353 float width) { 367 float width) {
354 DrawPlatformFocusRing(path, canvas_, color.Rgb(), width); 368 DrawPlatformFocusRing(path, canvas_, ApplyHighContrastFilter(color).Rgb(),
369 width);
355 } 370 }
356 371
357 void GraphicsContext::DrawFocusRingRect(const SkRect& rect, 372 void GraphicsContext::DrawFocusRingRect(const SkRect& rect,
358 const Color& color, 373 const Color& color,
359 float width) { 374 float width) {
360 DrawPlatformFocusRing(rect, canvas_, color.Rgb(), width); 375 DrawPlatformFocusRing(rect, canvas_, ApplyHighContrastFilter(color).Rgb(),
376 width);
361 } 377 }
362 378
363 void GraphicsContext::DrawFocusRing(const Path& focus_ring_path, 379 void GraphicsContext::DrawFocusRing(const Path& focus_ring_path,
364 float width, 380 float width,
365 int offset, 381 int offset,
366 const Color& color) { 382 const Color& color) {
367 // FIXME: Implement support for offset. 383 // FIXME: Implement support for offset.
368 if (ContextDisabled()) 384 if (ContextDisabled())
369 return; 385 return;
370 386
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 432
417 if (shadow_spread < 0) 433 if (shadow_spread < 0)
418 bounds.Inflate(-shadow_spread); 434 bounds.Inflate(-shadow_spread);
419 435
420 FloatRect offset_bounds = bounds; 436 FloatRect offset_bounds = bounds;
421 offset_bounds.Move(-shadow_offset); 437 offset_bounds.Move(-shadow_offset);
422 return UnionRect(bounds, offset_bounds); 438 return UnionRect(bounds, offset_bounds);
423 } 439 }
424 440
425 void GraphicsContext::DrawInnerShadow(const FloatRoundedRect& rect, 441 void GraphicsContext::DrawInnerShadow(const FloatRoundedRect& rect,
426 const Color& shadow_color, 442 const Color& orig_shadow_color,
427 const FloatSize& shadow_offset, 443 const FloatSize& shadow_offset,
428 float shadow_blur, 444 float shadow_blur,
429 float shadow_spread, 445 float shadow_spread,
430 Edges clipped_edges) { 446 Edges clipped_edges) {
431 if (ContextDisabled()) 447 if (ContextDisabled())
432 return; 448 return;
433 449
450 Color shadow_color = ApplyHighContrastFilter(orig_shadow_color);
451
434 FloatRect hole_rect(rect.Rect()); 452 FloatRect hole_rect(rect.Rect());
435 hole_rect.Inflate(-shadow_spread); 453 hole_rect.Inflate(-shadow_spread);
436 454
437 if (hole_rect.IsEmpty()) { 455 if (hole_rect.IsEmpty()) {
438 FillRoundedRect(rect, shadow_color); 456 FillRoundedRect(rect, shadow_color);
439 return; 457 return;
440 } 458 }
441 459
442 if (clipped_edges & kLeftEdge) { 460 if (clipped_edges & kLeftEdge) {
443 hole_rect.Move(-std::max(shadow_offset.Width(), 0.0f) - shadow_blur, 0); 461 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) { 548 if (is_vertical_line) {
531 p1.SetY(p1.Y() + width / 2.f); 549 p1.SetY(p1.Y() + width / 2.f);
532 p2.SetY(p2.Y() - width / 2.f); 550 p2.SetY(p2.Y() - width / 2.f);
533 } else { 551 } else {
534 p1.SetX(p1.X() + width / 2.f); 552 p1.SetX(p1.X() + width / 2.f);
535 p2.SetX(p2.X() - width / 2.f); 553 p2.SetX(p2.X() - width / 2.f);
536 } 554 }
537 } 555 }
538 556
539 AdjustLineToPixelBoundaries(p1, p2, width, pen_style); 557 AdjustLineToPixelBoundaries(p1, p2, width, pen_style);
540 canvas_->drawLine(p1.X(), p1.Y(), p2.X(), p2.Y(), flags); 558 canvas_->drawLine(p1.X(), p1.Y(), p2.X(), p2.Y(),
559 ApplyHighContrastFilter(&flags));
541 } 560 }
542 561
543 void GraphicsContext::DrawLineForText(const FloatPoint& pt, float width) { 562 void GraphicsContext::DrawLineForText(const FloatPoint& pt, float width) {
544 if (ContextDisabled()) 563 if (ContextDisabled())
545 return; 564 return;
546 565
547 if (width <= 0) 566 if (width <= 0)
548 return; 567 return;
549 568
550 PaintFlags flags; 569 PaintFlags flags;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 } 626 }
608 627
609 template <typename TextPaintInfo> 628 template <typename TextPaintInfo>
610 void GraphicsContext::DrawTextInternal(const Font& font, 629 void GraphicsContext::DrawTextInternal(const Font& font,
611 const TextPaintInfo& text_info, 630 const TextPaintInfo& text_info,
612 const FloatPoint& point, 631 const FloatPoint& point,
613 const PaintFlags& flags) { 632 const PaintFlags& flags) {
614 if (ContextDisabled()) 633 if (ContextDisabled())
615 return; 634 return;
616 635
617 if (font.DrawText(canvas_, text_info, point, device_scale_factor_, flags)) 636 if (font.DrawText(canvas_, text_info, point, device_scale_factor_,
637 ApplyHighContrastFilter(&flags))) {
618 paint_controller_.SetTextPainted(); 638 paint_controller_.SetTextPainted();
639 }
619 } 640 }
620 641
621 void GraphicsContext::DrawText(const Font& font, 642 void GraphicsContext::DrawText(const Font& font,
622 const TextRunPaintInfo& text_info, 643 const TextRunPaintInfo& text_info,
623 const FloatPoint& point, 644 const FloatPoint& point,
624 const PaintFlags& flags) { 645 const PaintFlags& flags) {
625 DrawTextInternal(font, text_info, point, flags); 646 DrawTextInternal(font, text_info, point, flags);
626 } 647 }
627 648
628 void GraphicsContext::DrawText(const Font& font, 649 void GraphicsContext::DrawText(const Font& font,
(...skipping 23 matching lines...) Expand all
652 } 673 }
653 674
654 template <typename TextPaintInfo> 675 template <typename TextPaintInfo>
655 void GraphicsContext::DrawTextInternal(const Font& font, 676 void GraphicsContext::DrawTextInternal(const Font& font,
656 const TextPaintInfo& text_info, 677 const TextPaintInfo& text_info,
657 const FloatPoint& point) { 678 const FloatPoint& point) {
658 if (ContextDisabled()) 679 if (ContextDisabled())
659 return; 680 return;
660 681
661 DrawTextPasses([&font, &text_info, &point, this](const PaintFlags& flags) { 682 DrawTextPasses([&font, &text_info, &point, this](const PaintFlags& flags) {
662 if (font.DrawText(canvas_, text_info, point, device_scale_factor_, flags)) 683 if (font.DrawText(canvas_, text_info, point, device_scale_factor_,
684 ApplyHighContrastFilter(&flags)))
663 paint_controller_.SetTextPainted(); 685 paint_controller_.SetTextPainted();
664 }); 686 });
665 } 687 }
666 688
667 void GraphicsContext::DrawText(const Font& font, 689 void GraphicsContext::DrawText(const Font& font,
668 const TextRunPaintInfo& text_info, 690 const TextRunPaintInfo& text_info,
669 const FloatPoint& point) { 691 const FloatPoint& point) {
670 DrawTextInternal(font, text_info, point); 692 DrawTextInternal(font, text_info, point);
671 } 693 }
672 694
673 void GraphicsContext::DrawText(const Font& font, 695 void GraphicsContext::DrawText(const Font& font,
674 const TextFragmentPaintInfo& text_info, 696 const TextFragmentPaintInfo& text_info,
675 const FloatPoint& point) { 697 const FloatPoint& point) {
676 DrawTextInternal(font, text_info, point); 698 DrawTextInternal(font, text_info, point);
677 } 699 }
678 700
679 template <typename TextPaintInfo> 701 template <typename TextPaintInfo>
680 void GraphicsContext::DrawEmphasisMarksInternal(const Font& font, 702 void GraphicsContext::DrawEmphasisMarksInternal(const Font& font,
681 const TextPaintInfo& text_info, 703 const TextPaintInfo& text_info,
682 const AtomicString& mark, 704 const AtomicString& mark,
683 const FloatPoint& point) { 705 const FloatPoint& point) {
684 if (ContextDisabled()) 706 if (ContextDisabled())
685 return; 707 return;
686 708
687 DrawTextPasses( 709 DrawTextPasses(
688 [&font, &text_info, &mark, &point, this](const PaintFlags& flags) { 710 [&font, &text_info, &mark, &point, this](const PaintFlags& flags) {
689 font.DrawEmphasisMarks(canvas_, text_info, mark, point, 711 font.DrawEmphasisMarks(canvas_, text_info, mark, point,
690 device_scale_factor_, flags); 712 device_scale_factor_,
713 ApplyHighContrastFilter(&flags));
691 }); 714 });
692 } 715 }
693 716
694 void GraphicsContext::DrawEmphasisMarks(const Font& font, 717 void GraphicsContext::DrawEmphasisMarks(const Font& font,
695 const TextRunPaintInfo& text_info, 718 const TextRunPaintInfo& text_info,
696 const AtomicString& mark, 719 const AtomicString& mark,
697 const FloatPoint& point) { 720 const FloatPoint& point) {
698 DrawEmphasisMarksInternal(font, text_info, mark, point); 721 DrawEmphasisMarksInternal(font, text_info, mark, point);
699 } 722 }
700 723
701 void GraphicsContext::DrawEmphasisMarks(const Font& font, 724 void GraphicsContext::DrawEmphasisMarks(const Font& font,
702 const TextFragmentPaintInfo& text_info, 725 const TextFragmentPaintInfo& text_info,
703 const AtomicString& mark, 726 const AtomicString& mark,
704 const FloatPoint& point) { 727 const FloatPoint& point) {
705 DrawEmphasisMarksInternal(font, text_info, mark, point); 728 DrawEmphasisMarksInternal(font, text_info, mark, point);
706 } 729 }
707 730
708 void GraphicsContext::DrawBidiText( 731 void GraphicsContext::DrawBidiText(
709 const Font& font, 732 const Font& font,
710 const TextRunPaintInfo& run_info, 733 const TextRunPaintInfo& run_info,
711 const FloatPoint& point, 734 const FloatPoint& point,
712 Font::CustomFontNotReadyAction custom_font_not_ready_action) { 735 Font::CustomFontNotReadyAction custom_font_not_ready_action) {
713 if (ContextDisabled()) 736 if (ContextDisabled())
714 return; 737 return;
715 738
716 DrawTextPasses([&font, &run_info, &point, custom_font_not_ready_action, 739 DrawTextPasses([&font, &run_info, &point, custom_font_not_ready_action,
717 this](const PaintFlags& flags) { 740 this](const PaintFlags& flags) {
718 if (font.DrawBidiText(canvas_, run_info, point, 741 if (font.DrawBidiText(canvas_, run_info, point,
719 custom_font_not_ready_action, device_scale_factor_, 742 custom_font_not_ready_action, device_scale_factor_,
720 flags)) 743 ApplyHighContrastFilter(&flags)))
721 paint_controller_.SetTextPainted(); 744 paint_controller_.SetTextPainted();
722 }); 745 });
723 } 746 }
724 747
725 void GraphicsContext::DrawHighlightForText(const Font& font, 748 void GraphicsContext::DrawHighlightForText(const Font& font,
726 const TextRun& run, 749 const TextRun& run,
727 const FloatPoint& point, 750 const FloatPoint& point,
728 int h, 751 int h,
729 const Color& background_color, 752 const Color& background_color,
730 int from, 753 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, 887 image->DrawTiledBorder(*this, dest, src_rect, tile_scale_factor, h_rule,
865 v_rule, op); 888 v_rule, op);
866 paint_controller_.SetImagePainted(); 889 paint_controller_.SetImagePainted();
867 } 890 }
868 891
869 void GraphicsContext::DrawOval(const SkRect& oval, const PaintFlags& flags) { 892 void GraphicsContext::DrawOval(const SkRect& oval, const PaintFlags& flags) {
870 if (ContextDisabled()) 893 if (ContextDisabled())
871 return; 894 return;
872 DCHECK(canvas_); 895 DCHECK(canvas_);
873 896
874 canvas_->drawOval(oval, flags); 897 canvas_->drawOval(oval, ApplyHighContrastFilter(&flags));
875 } 898 }
876 899
877 void GraphicsContext::DrawPath(const SkPath& path, const PaintFlags& flags) { 900 void GraphicsContext::DrawPath(const SkPath& path, const PaintFlags& flags) {
878 if (ContextDisabled()) 901 if (ContextDisabled())
879 return; 902 return;
880 DCHECK(canvas_); 903 DCHECK(canvas_);
881 904
882 canvas_->drawPath(path, flags); 905 canvas_->drawPath(path, ApplyHighContrastFilter(&flags));
883 } 906 }
884 907
885 void GraphicsContext::DrawRect(const SkRect& rect, const PaintFlags& flags) { 908 void GraphicsContext::DrawRect(const SkRect& rect, const PaintFlags& flags) {
886 if (ContextDisabled()) 909 if (ContextDisabled())
887 return; 910 return;
888 DCHECK(canvas_); 911 DCHECK(canvas_);
889 912
890 canvas_->drawRect(rect, flags); 913 canvas_->drawRect(rect, ApplyHighContrastFilter(&flags));
891 } 914 }
892 915
893 void GraphicsContext::DrawRRect(const SkRRect& rrect, const PaintFlags& flags) { 916 void GraphicsContext::DrawRRect(const SkRRect& rrect, const PaintFlags& flags) {
894 if (ContextDisabled()) 917 if (ContextDisabled())
895 return; 918 return;
896 DCHECK(canvas_); 919 DCHECK(canvas_);
897 920
898 canvas_->drawRRect(rrect, flags); 921 canvas_->drawRRect(rrect, ApplyHighContrastFilter(&flags));
899 } 922 }
900 923
901 void GraphicsContext::FillPath(const Path& path_to_fill) { 924 void GraphicsContext::FillPath(const Path& path_to_fill) {
902 if (ContextDisabled() || path_to_fill.IsEmpty()) 925 if (ContextDisabled() || path_to_fill.IsEmpty())
903 return; 926 return;
904 927
905 DrawPath(path_to_fill.GetSkPath(), ImmutableState()->FillFlags()); 928 DrawPath(path_to_fill.GetSkPath(), ImmutableState()->FillFlags());
906 } 929 }
907 930
908 void GraphicsContext::FillRect(const FloatRect& rect) { 931 void GraphicsContext::FillRect(const FloatRect& rect) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 const Color& color) { 1031 const Color& color) {
1009 if (ContextDisabled()) 1032 if (ContextDisabled())
1010 return; 1033 return;
1011 DCHECK(canvas_); 1034 DCHECK(canvas_);
1012 1035
1013 if (!IsSimpleDRRect(outer, inner)) { 1036 if (!IsSimpleDRRect(outer, inner)) {
1014 if (color == FillColor()) { 1037 if (color == FillColor()) {
1015 canvas_->drawDRRect(outer, inner, ImmutableState()->FillFlags()); 1038 canvas_->drawDRRect(outer, inner, ImmutableState()->FillFlags());
1016 } else { 1039 } else {
1017 PaintFlags flags(ImmutableState()->FillFlags()); 1040 PaintFlags flags(ImmutableState()->FillFlags());
1018 flags.setColor(color.Rgb()); 1041 flags.setColor(ApplyHighContrastFilter(color).Rgb());
1019 canvas_->drawDRRect(outer, inner, flags); 1042 canvas_->drawDRRect(outer, inner, flags);
1020 } 1043 }
1021 1044
1022 return; 1045 return;
1023 } 1046 }
1024 1047
1025 // We can draw this as a stroked rrect. 1048 // We can draw this as a stroked rrect.
1026 float stroke_width = inner.Rect().X() - outer.Rect().X(); 1049 float stroke_width = inner.Rect().X() - outer.Rect().X();
1027 SkRRect stroke_r_rect = outer; 1050 SkRRect stroke_r_rect = outer;
1028 stroke_r_rect.inset(stroke_width / 2, stroke_width / 2); 1051 stroke_r_rect.inset(stroke_width / 2, stroke_width / 2);
1029 1052
1030 PaintFlags stroke_flags(ImmutableState()->FillFlags()); 1053 PaintFlags stroke_flags(ImmutableState()->FillFlags());
1031 stroke_flags.setColor(color.Rgb()); 1054 stroke_flags.setColor(ApplyHighContrastFilter(color).Rgb());
1032 stroke_flags.setStyle(PaintFlags::kStroke_Style); 1055 stroke_flags.setStyle(PaintFlags::kStroke_Style);
1033 stroke_flags.setStrokeWidth(stroke_width); 1056 stroke_flags.setStrokeWidth(stroke_width);
1034 1057
1035 canvas_->drawRRect(stroke_r_rect, stroke_flags); 1058 canvas_->drawRRect(stroke_r_rect, stroke_flags);
1036 } 1059 }
1037 1060
1038 void GraphicsContext::FillEllipse(const FloatRect& ellipse) { 1061 void GraphicsContext::FillEllipse(const FloatRect& ellipse) {
1039 if (ContextDisabled()) 1062 if (ContextDisabled())
1040 return; 1063 return;
1041 1064
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 } 1236 }
1214 1237
1215 void GraphicsContext::FillRectWithRoundedHole( 1238 void GraphicsContext::FillRectWithRoundedHole(
1216 const FloatRect& rect, 1239 const FloatRect& rect,
1217 const FloatRoundedRect& rounded_hole_rect, 1240 const FloatRoundedRect& rounded_hole_rect,
1218 const Color& color) { 1241 const Color& color) {
1219 if (ContextDisabled()) 1242 if (ContextDisabled())
1220 return; 1243 return;
1221 1244
1222 PaintFlags flags(ImmutableState()->FillFlags()); 1245 PaintFlags flags(ImmutableState()->FillFlags());
1223 flags.setColor(color.Rgb()); 1246 flags.setColor(ApplyHighContrastFilter(color).Rgb());
1224 canvas_->drawDRRect(SkRRect::MakeRect(rect), rounded_hole_rect, flags); 1247 canvas_->drawDRRect(SkRRect::MakeRect(rect), rounded_hole_rect, flags);
1225 } 1248 }
1226 1249
1227 void GraphicsContext::AdjustLineToPixelBoundaries(FloatPoint& p1, 1250 void GraphicsContext::AdjustLineToPixelBoundaries(FloatPoint& p1,
1228 FloatPoint& p2, 1251 FloatPoint& p2,
1229 float stroke_width, 1252 float stroke_width,
1230 StrokeStyle pen_style) { 1253 StrokeStyle pen_style) {
1231 // For odd widths, we add in 0.5 to the appropriate x/y so that the float 1254 // 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 1255 // 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 1256 // 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: 1293 case kColorFilterNone:
1271 break; 1294 break;
1272 default: 1295 default:
1273 NOTREACHED(); 1296 NOTREACHED();
1274 break; 1297 break;
1275 } 1298 }
1276 1299
1277 return nullptr; 1300 return nullptr;
1278 } 1301 }
1279 1302
1303 void GraphicsContext::UpdateHighContrastFilterFromSettings() {
chrishtr 2017/06/02 21:12:30 Please unittest these.
dmazzoni 2017/06/05 15:56:37 Done. I didn't see many examples of calling privat
1304 SkHighContrastConfig config;
1305
1306 switch (high_contrast_settings_.mode) {
1307 case HighContrastMode::kOff:
1308 high_contrast_filter_.reset(nullptr);
1309 return;
1310 case HighContrastMode::kSimpleInvertForTesting: {
1311 uint8_t identity[256], invert[256];
1312 for (int i = 0; i < 256; ++i) {
1313 identity[i] = i;
1314 invert[i] = 255 - i;
1315 }
1316 high_contrast_filter_ =
1317 SkTableColorFilter::MakeARGB(identity, invert, invert, invert);
1318 return;
1319 }
1320 case HighContrastMode::kInvertBrightness:
1321 config.fInvertStyle =
1322 SkHighContrastConfig::InvertStyle::kInvertBrightness;
1323 break;
1324 case HighContrastMode::kInvertLightness:
1325 config.fInvertStyle = SkHighContrastConfig::InvertStyle::kInvertLightness;
1326 break;
1327 }
1328
1329 config.fGrayscale = high_contrast_settings_.grayscale;
1330 config.fContrast = high_contrast_settings_.contrast;
1331 high_contrast_filter_ = SkHighContrastFilter::Make(config);
1332 }
1333
1334 Color GraphicsContext::ApplyHighContrastFilter(const Color& input) const {
1335 if (!high_contrast_filter_)
1336 return input;
1337
1338 SkColor sk_input =
1339 SkColorSetARGB(input.Alpha(), input.Red(), input.Green(), input.Blue());
1340 SkColor sk_output = high_contrast_filter_->filterColor(sk_input);
1341 return Color(MakeRGBA(SkColorGetR(sk_output), SkColorGetG(sk_output),
1342 SkColorGetB(sk_output), SkColorGetA(sk_output)));
1343 }
1344
1345 PaintFlags GraphicsContext::ApplyHighContrastFilter(
1346 const PaintFlags* input) const {
1347 if (input && !high_contrast_filter_)
1348 return *input;
1349
1350 PaintFlags output;
1351 if (input)
1352 output = *input;
1353 if (output.getShader()) {
1354 output.setColorFilter(high_contrast_filter_);
1355 } else {
1356 output.setColor(high_contrast_filter_->filterColor(output.getColor()));
1357 }
1358 return output;
1359 }
1360
1280 } // namespace blink 1361 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698