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

Side by Side Diff: sky/engine/platform/graphics/GraphicsContext.cpp

Issue 709603006: Remove a bunch of OS(MACOSX) code (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Even more Created 6 years, 1 month 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 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 if (strokeStyle() != NoStroke) 573 if (strokeStyle() != NoStroke)
574 drawPath(path, immutableState()->strokePaint()); 574 drawPath(path, immutableState()->strokePaint());
575 } 575 }
576 576
577 float GraphicsContext::prepareFocusRingPaint(SkPaint& paint, const Color& color, int width) const 577 float GraphicsContext::prepareFocusRingPaint(SkPaint& paint, const Color& color, int width) const
578 { 578 {
579 paint.setAntiAlias(true); 579 paint.setAntiAlias(true);
580 paint.setStyle(SkPaint::kStroke_Style); 580 paint.setStyle(SkPaint::kStroke_Style);
581 paint.setColor(color.rgb()); 581 paint.setColor(color.rgb());
582 paint.setStrokeWidth(focusRingWidth(width)); 582 paint.setStrokeWidth(focusRingWidth(width));
583
584 #if OS(MACOSX)
585 paint.setAlpha(64);
586 return (width - 1) * 0.5f;
587 #else
588 return 1; 583 return 1;
589 #endif
590 } 584 }
591 585
592 void GraphicsContext::drawFocusRingPath(const SkPath& path, const Color& color, int width) 586 void GraphicsContext::drawFocusRingPath(const SkPath& path, const Color& color, int width)
593 { 587 {
594 SkPaint paint; 588 SkPaint paint;
595 float cornerRadius = prepareFocusRingPaint(paint, color, width); 589 float cornerRadius = prepareFocusRingPaint(paint, color, width);
596 590
597 paint.setPathEffect(SkCornerPathEffect::Create(SkFloatToScalar(cornerRadius) ))->unref(); 591 paint.setPathEffect(SkCornerPathEffect::Create(SkFloatToScalar(cornerRadius) ))->unref();
598 592
599 // Outer path 593 // Outer path
600 drawPath(path, paint); 594 drawPath(path, paint);
601
602 #if OS(MACOSX)
603 // Inner path
604 paint.setAlpha(128);
605 paint.setStrokeWidth(paint.getStrokeWidth() * 0.5f);
606 drawPath(path, paint);
607 #endif
608 } 595 }
609 596
610 void GraphicsContext::drawFocusRingRect(const SkRect& rect, const Color& color, int width) 597 void GraphicsContext::drawFocusRingRect(const SkRect& rect, const Color& color, int width)
611 { 598 {
612 SkPaint paint; 599 SkPaint paint;
613 float cornerRadius = prepareFocusRingPaint(paint, color, width); 600 float cornerRadius = prepareFocusRingPaint(paint, color, width);
614 601
615 SkRRect rrect; 602 SkRRect rrect;
616 rrect.setRectXY(rect, SkFloatToScalar(cornerRadius), SkFloatToScalar(cornerR adius)); 603 rrect.setRectXY(rect, SkFloatToScalar(cornerRadius), SkFloatToScalar(cornerR adius));
617 604
618 // Outer rect 605 // Outer rect
619 drawRRect(rrect, paint); 606 drawRRect(rrect, paint);
620
621 #if OS(MACOSX)
622 // Inner rect
623 paint.setAlpha(128);
624 paint.setStrokeWidth(paint.getStrokeWidth() * 0.5f);
625 drawRRect(rrect, paint);
626 #endif
627 } 607 }
628 608
629 void GraphicsContext::drawFocusRing(const Path& focusRingPath, int width, int of fset, const Color& color) 609 void GraphicsContext::drawFocusRing(const Path& focusRingPath, int width, int of fset, const Color& color)
630 { 610 {
631 // FIXME: Implement support for offset. 611 // FIXME: Implement support for offset.
632 if (contextDisabled()) 612 if (contextDisabled())
633 return; 613 return;
634 614
635 drawFocusRingPath(focusRingPath.skPath(), color, width); 615 drawFocusRingPath(focusRingPath.skPath(), color, width);
636 } 616 }
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 765
786 // Use 2x resources for a device scale factor of 1.5 or above. 766 // Use 2x resources for a device scale factor of 1.5 or above.
787 int deviceScaleFactor = m_deviceScaleFactor > 1.5f ? 2 : 1; 767 int deviceScaleFactor = m_deviceScaleFactor > 1.5f ? 2 : 1;
788 768
789 // Create the pattern we'll use to draw the underline. 769 // Create the pattern we'll use to draw the underline.
790 int index = style == DocumentMarkerGrammarLineStyle ? 1 : 0; 770 int index = style == DocumentMarkerGrammarLineStyle ? 1 : 0;
791 static SkBitmap* misspellBitmap1x[2] = { 0, 0 }; 771 static SkBitmap* misspellBitmap1x[2] = { 0, 0 };
792 static SkBitmap* misspellBitmap2x[2] = { 0, 0 }; 772 static SkBitmap* misspellBitmap2x[2] = { 0, 0 };
793 SkBitmap** misspellBitmap = deviceScaleFactor == 2 ? misspellBitmap2x : miss pellBitmap1x; 773 SkBitmap** misspellBitmap = deviceScaleFactor == 2 ? misspellBitmap2x : miss pellBitmap1x;
794 if (!misspellBitmap[index]) { 774 if (!misspellBitmap[index]) {
795 #if OS(MACOSX)
796 // Match the artwork used by the Mac.
797 const int rowPixels = 4 * deviceScaleFactor;
798 const int colPixels = 3 * deviceScaleFactor;
799 SkBitmap bitmap;
800 bitmap.allocN32Pixels(rowPixels, colPixels);
801
802 bitmap.eraseARGB(0, 0, 0, 0);
803 const uint32_t transparentColor = 0x00000000;
804
805 if (deviceScaleFactor == 1) {
806 const uint32_t colors[2][6] = {
807 { 0x2a2a0600, 0x57571000, 0xa8a81b00, 0xbfbf1f00, 0x70701200, 0xe0e02400 },
808 { 0x2a0f0f0f, 0x571e1e1e, 0xa83d3d3d, 0xbf454545, 0x70282828, 0xe0515151 }
809 };
810
811 // Pattern: a b a a b a
812 // c d c c d c
813 // e f e e f e
814 for (int x = 0; x < colPixels; ++x) {
815 uint32_t* row = bitmap.getAddr32(0, x);
816 row[0] = colors[index][x * 2];
817 row[1] = colors[index][x * 2 + 1];
818 row[2] = colors[index][x * 2];
819 row[3] = transparentColor;
820 }
821 } else if (deviceScaleFactor == 2) {
822 const uint32_t colors[2][18] = {
823 { 0x0a090101, 0x33320806, 0x55540f0a, 0x37360906, 0x6e6c120c, 0 x6e6c120c, 0x7674140d, 0x8d8b1810, 0x8d8b1810,
824 0x96941a11, 0xb3b01f15, 0xb3b01f15, 0x6d6b130c, 0xd9d62619, 0 xd9d62619, 0x19180402, 0x7c7a150e, 0xcecb2418 },
825 { 0x0a020202, 0x33141414, 0x55232323, 0x37161616, 0x6e2e2e2e, 0 x6e2e2e2e, 0x76313131, 0x8d3a3a3a, 0x8d3a3a3a,
826 0x963e3e3e, 0xb34b4b4b, 0xb34b4b4b, 0x6d2d2d2d, 0xd95b5b5b, 0 xd95b5b5b, 0x19090909, 0x7c343434, 0xce575757 }
827 };
828
829 // Pattern: a b c c b a
830 // d e f f e d
831 // g h j j h g
832 // k l m m l k
833 // n o p p o n
834 // q r s s r q
835 for (int x = 0; x < colPixels; ++x) {
836 uint32_t* row = bitmap.getAddr32(0, x);
837 row[0] = colors[index][x * 3];
838 row[1] = colors[index][x * 3 + 1];
839 row[2] = colors[index][x * 3 + 2];
840 row[3] = colors[index][x * 3 + 2];
841 row[4] = colors[index][x * 3 + 1];
842 row[5] = colors[index][x * 3];
843 row[6] = transparentColor;
844 row[7] = transparentColor;
845 }
846 } else
847 ASSERT_NOT_REACHED();
848
849 misspellBitmap[index] = new SkBitmap(bitmap);
850 #else
851 // We use a 2-pixel-high misspelling indicator because that seems to be 775 // We use a 2-pixel-high misspelling indicator because that seems to be
852 // what WebKit is designed for, and how much room there is in a typical 776 // what WebKit is designed for, and how much room there is in a typical
853 // page for it. 777 // page for it.
854 const int rowPixels = 32 * deviceScaleFactor; // Must be multiple of 4 f or pattern below. 778 const int rowPixels = 32 * deviceScaleFactor; // Must be multiple of 4 f or pattern below.
855 const int colPixels = 2 * deviceScaleFactor; 779 const int colPixels = 2 * deviceScaleFactor;
856 SkBitmap bitmap; 780 SkBitmap bitmap;
857 bitmap.allocN32Pixels(rowPixels, colPixels); 781 bitmap.allocN32Pixels(rowPixels, colPixels);
858 782
859 bitmap.eraseARGB(0, 0, 0, 0); 783 bitmap.eraseARGB(0, 0, 0, 0);
860 if (deviceScaleFactor == 1) 784 if (deviceScaleFactor == 1)
861 draw1xMarker(&bitmap, index); 785 draw1xMarker(&bitmap, index);
862 else if (deviceScaleFactor == 2) 786 else if (deviceScaleFactor == 2)
863 draw2xMarker(&bitmap, index); 787 draw2xMarker(&bitmap, index);
864 else 788 else
865 ASSERT_NOT_REACHED(); 789 ASSERT_NOT_REACHED();
866 790
867 misspellBitmap[index] = new SkBitmap(bitmap); 791 misspellBitmap[index] = new SkBitmap(bitmap);
868 #endif
869 } 792 }
870 793
871 #if OS(MACOSX)
872 SkScalar originX = WebCoreFloatToSkScalar(pt.x()) * deviceScaleFactor;
873 SkScalar originY = WebCoreFloatToSkScalar(pt.y()) * deviceScaleFactor;
874
875 // Make sure to draw only complete dots.
876 int rowPixels = misspellBitmap[index]->width();
877 float widthMod = fmodf(width * deviceScaleFactor, rowPixels);
878 if (rowPixels - widthMod > deviceScaleFactor)
879 width -= widthMod / deviceScaleFactor;
880 #else
881 SkScalar originX = WebCoreFloatToSkScalar(pt.x()); 794 SkScalar originX = WebCoreFloatToSkScalar(pt.x());
882 795
883 // Offset it vertically by 1 so that there's some space under the text. 796 // Offset it vertically by 1 so that there's some space under the text.
884 SkScalar originY = WebCoreFloatToSkScalar(pt.y()) + 1; 797 SkScalar originY = WebCoreFloatToSkScalar(pt.y()) + 1;
885 originX *= deviceScaleFactor; 798 originX *= deviceScaleFactor;
886 originY *= deviceScaleFactor; 799 originY *= deviceScaleFactor;
887 #endif
888 800
889 SkMatrix localMatrix; 801 SkMatrix localMatrix;
890 localMatrix.setTranslate(originX, originY); 802 localMatrix.setTranslate(originX, originY);
891 RefPtr<SkShader> shader = adoptRef(SkShader::CreateBitmapShader( 803 RefPtr<SkShader> shader = adoptRef(SkShader::CreateBitmapShader(
892 *misspellBitmap[index], SkShader::kRepeat_TileMode, SkShader::kRepeat_Ti leMode, &localMatrix)); 804 *misspellBitmap[index], SkShader::kRepeat_TileMode, SkShader::kRepeat_Ti leMode, &localMatrix));
893 805
894 SkPaint paint; 806 SkPaint paint;
895 paint.setShader(shader.get()); 807 paint.setShader(shader.get());
896 808
897 SkRect rect; 809 SkRect rect;
(...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after
1812 case ColorFilterNone: 1724 case ColorFilterNone:
1813 break; 1725 break;
1814 default: 1726 default:
1815 ASSERT_NOT_REACHED(); 1727 ASSERT_NOT_REACHED();
1816 break; 1728 break;
1817 } 1729 }
1818 1730
1819 return nullptr; 1731 return nullptr;
1820 } 1732 }
1821 1733
1822 #if !OS(MACOSX)
1823 void GraphicsContext::draw2xMarker(SkBitmap* bitmap, int index) 1734 void GraphicsContext::draw2xMarker(SkBitmap* bitmap, int index)
1824 { 1735 {
1825 const SkPMColor lineColor = lineColors(index); 1736 const SkPMColor lineColor = lineColors(index);
1826 const SkPMColor antiColor1 = antiColors1(index); 1737 const SkPMColor antiColor1 = antiColors1(index);
1827 const SkPMColor antiColor2 = antiColors2(index); 1738 const SkPMColor antiColor2 = antiColors2(index);
1828 1739
1829 uint32_t* row1 = bitmap->getAddr32(0, 0); 1740 uint32_t* row1 = bitmap->getAddr32(0, 0);
1830 uint32_t* row2 = bitmap->getAddr32(0, 1); 1741 uint32_t* row2 = bitmap->getAddr32(0, 1);
1831 uint32_t* row3 = bitmap->getAddr32(0, 2); 1742 uint32_t* row3 = bitmap->getAddr32(0, 2);
1832 uint32_t* row4 = bitmap->getAddr32(0, 3); 1743 uint32_t* row4 = bitmap->getAddr32(0, 3);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1902 1813
1903 SkPMColor GraphicsContext::antiColors2(int index) 1814 SkPMColor GraphicsContext::antiColors2(int index)
1904 { 1815 {
1905 static const SkPMColor colors[] = { 1816 static const SkPMColor colors[] = {
1906 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red 1817 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red
1907 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray 1818 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray
1908 }; 1819 };
1909 1820
1910 return colors[index]; 1821 return colors[index];
1911 } 1822 }
1912 #endif
1913 1823
1914 void GraphicsContext::didDrawTextInRect(const SkRect& textRect) 1824 void GraphicsContext::didDrawTextInRect(const SkRect& textRect)
1915 { 1825 {
1916 if (m_trackTextRegion) { 1826 if (m_trackTextRegion) {
1917 TRACE_EVENT0("skia", "GraphicsContext::didDrawTextInRect"); 1827 TRACE_EVENT0("skia", "GraphicsContext::didDrawTextInRect");
1918 m_textRegion.join(textRect); 1828 m_textRegion.join(textRect);
1919 } 1829 }
1920 } 1830 }
1921 1831
1922 void GraphicsContext::preparePaintForDrawRectToRect( 1832 void GraphicsContext::preparePaintForDrawRectToRect(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1956 // FIXME: This is to not break tests (it results in the filter bitmap fl ag 1866 // FIXME: This is to not break tests (it results in the filter bitmap fl ag
1957 // being set to true). We need to decide if we respect InterpolationNone 1867 // being set to true). We need to decide if we respect InterpolationNone
1958 // being returned from computeInterpolationQuality. 1868 // being returned from computeInterpolationQuality.
1959 resampling = InterpolationLow; 1869 resampling = InterpolationLow;
1960 } 1870 }
1961 resampling = limitInterpolationQuality(this, resampling); 1871 resampling = limitInterpolationQuality(this, resampling);
1962 paint->setFilterLevel(static_cast<SkPaint::FilterLevel>(resampling)); 1872 paint->setFilterLevel(static_cast<SkPaint::FilterLevel>(resampling));
1963 } 1873 }
1964 1874
1965 } // namespace blink 1875 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698