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

Side by Side Diff: src/core/SkPath.cpp

Issue 1461763004: add SkPath::isRRect (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: incorporated Rob's comments Created 5 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
« no previous file with comments | « include/core/SkPathRef.h ('k') | src/core/SkPathRef.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkBuffer.h" 8 #include "SkBuffer.h"
9 #include "SkErrorInternals.h" 9 #include "SkErrorInternals.h"
10 #include "SkGeometry.h" 10 #include "SkGeometry.h"
(...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 this->addRRect(rrect, dir, dir == kCW_Direction ? 6 : 7); 1065 this->addRRect(rrect, dir, dir == kCW_Direction ? 6 : 7);
1066 } 1066 }
1067 1067
1068 void SkPath::addRRect(const SkRRect &rrect, Direction dir, unsigned startIndex) { 1068 void SkPath::addRRect(const SkRRect &rrect, Direction dir, unsigned startIndex) {
1069 assert_known_direction(dir); 1069 assert_known_direction(dir);
1070 1070
1071 if (rrect.isEmpty()) { 1071 if (rrect.isEmpty()) {
1072 return; 1072 return;
1073 } 1073 }
1074 1074
1075 bool isRRect = hasOnlyMoveTos();
1075 const SkRect& bounds = rrect.getBounds(); 1076 const SkRect& bounds = rrect.getBounds();
1076 1077
1077 if (rrect.isRect()) { 1078 if (rrect.isRect()) {
1078 // degenerate(rect) => radii points are collapsing 1079 // degenerate(rect) => radii points are collapsing
1079 this->addRect(bounds, dir, (startIndex + 1) / 2); 1080 this->addRect(bounds, dir, (startIndex + 1) / 2);
1080 } else if (rrect.isOval()) { 1081 } else if (rrect.isOval()) {
1081 // degenerate(oval) => line points are collapsing 1082 // degenerate(oval) => line points are collapsing
1082 this->addOval(bounds, dir, startIndex / 2); 1083 this->addOval(bounds, dir, startIndex / 2);
1083 } else { 1084 } else {
1084 fFirstDirection = this->hasOnlyMoveTos() ? 1085 fFirstDirection = this->hasOnlyMoveTos() ?
(...skipping 27 matching lines...) Expand all
1112 this->conicTo(rectIter.next(), rrectIter.next(), weight); 1113 this->conicTo(rectIter.next(), rrectIter.next(), weight);
1113 // final lineTo handled by close(). 1114 // final lineTo handled by close().
1114 } else { 1115 } else {
1115 for (unsigned i = 0; i < 4; ++i) { 1116 for (unsigned i = 0; i < 4; ++i) {
1116 this->lineTo(rrectIter.next()); 1117 this->lineTo(rrectIter.next());
1117 this->conicTo(rectIter.next(), rrectIter.next(), weight); 1118 this->conicTo(rectIter.next(), rrectIter.next(), weight);
1118 } 1119 }
1119 } 1120 }
1120 this->close(); 1121 this->close();
1121 1122
1123 SkPathRef::Editor ed(&fPathRef);
1124 ed.setIsRRect(isRRect);
1125
1122 SkASSERT(this->countVerbs() == initialVerbCount + kVerbs); 1126 SkASSERT(this->countVerbs() == initialVerbCount + kVerbs);
1123 } 1127 }
1124 1128
1125 SkDEBUGCODE(fPathRef->validate();) 1129 SkDEBUGCODE(fPathRef->validate();)
1126 } 1130 }
1127 1131
1128 bool SkPath::hasOnlyMoveTos() const { 1132 bool SkPath::hasOnlyMoveTos() const {
1129 int count = fPathRef->countVerbs(); 1133 int count = fPathRef->countVerbs();
1130 const uint8_t* verbs = const_cast<const SkPathRef*>(fPathRef.get())->verbsMe mBegin(); 1134 const uint8_t* verbs = const_cast<const SkPathRef*>(fPathRef.get())->verbsMe mBegin();
1131 for (int i = 0; i < count; ++i) { 1135 for (int i = 0; i < count; ++i) {
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
1854 } 1858 }
1855 fLastPt = fMoveTo; 1859 fLastPt = fMoveTo;
1856 break; 1860 break;
1857 } 1861 }
1858 fPts = srcPts; 1862 fPts = srcPts;
1859 return (Verb)verb; 1863 return (Verb)verb;
1860 } 1864 }
1861 1865
1862 /////////////////////////////////////////////////////////////////////////////// 1866 ///////////////////////////////////////////////////////////////////////////////
1863 1867
1864 SkPath::RawIter::RawIter() {
1865 #ifdef SK_DEBUG
1866 fPts = nullptr;
1867 fConicWeights = nullptr;
1868 #endif
1869 // need to init enough to make next() harmlessly return kDone_Verb
1870 fVerbs = nullptr;
1871 fVerbStop = nullptr;
1872 }
1873
1874 SkPath::RawIter::RawIter(const SkPath& path) {
1875 this->setPath(path);
1876 }
1877
1878 void SkPath::RawIter::setPath(const SkPath& path) {
1879 fPts = path.fPathRef->points();
1880 fVerbs = path.fPathRef->verbs();
1881 fVerbStop = path.fPathRef->verbsMemBegin();
1882 fConicWeights = path.fPathRef->conicWeights() - 1; // begin one behind
1883 }
1884
1885 SkPath::Verb SkPath::RawIter::next(SkPoint pts[4]) {
1886 SkASSERT(pts);
1887 if (fVerbs == fVerbStop) {
1888 return kDone_Verb;
1889 }
1890
1891 // fVerbs points one beyond next verb so decrement first.
1892 unsigned verb = *(--fVerbs);
1893 const SkPoint* srcPts = fPts;
1894
1895 switch (verb) {
1896 case kMove_Verb:
1897 pts[0] = srcPts[0];
1898 srcPts += 1;
1899 break;
1900 case kLine_Verb:
1901 pts[0] = srcPts[-1];
1902 pts[1] = srcPts[0];
1903 srcPts += 1;
1904 break;
1905 case kConic_Verb:
1906 fConicWeights += 1;
1907 // fall-through
1908 case kQuad_Verb:
1909 pts[0] = srcPts[-1];
1910 pts[1] = srcPts[0];
1911 pts[2] = srcPts[1];
1912 srcPts += 2;
1913 break;
1914 case kCubic_Verb:
1915 pts[0] = srcPts[-1];
1916 pts[1] = srcPts[0];
1917 pts[2] = srcPts[1];
1918 pts[3] = srcPts[2];
1919 srcPts += 3;
1920 break;
1921 case kClose_Verb:
1922 break;
1923 case kDone_Verb:
1924 SkASSERT(fVerbs == fVerbStop);
1925 break;
1926 }
1927 fPts = srcPts;
1928 return (Verb)verb;
1929 }
1930
1931 ///////////////////////////////////////////////////////////////////////////////
1932
1933 /* 1868 /*
1934 Format in compressed buffer: [ptCount, verbCount, pts[], verbs[]] 1869 Format in compressed buffer: [ptCount, verbCount, pts[], verbs[]]
1935 */ 1870 */
1936 1871
1937 size_t SkPath::writeToMemory(void* storage) const { 1872 size_t SkPath::writeToMemory(void* storage) const {
1938 SkDEBUGCODE(this->validate();) 1873 SkDEBUGCODE(this->validate();)
1939 1874
1940 if (nullptr == storage) { 1875 if (nullptr == storage) {
1941 const int byteCount = sizeof(int32_t) + fPathRef->writeSize(); 1876 const int byteCount = sizeof(int32_t) + fPathRef->writeSize();
1942 return SkAlign4(byteCount); 1877 return SkAlign4(byteCount);
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after
2895 switch (this->getFillType()) { 2830 switch (this->getFillType()) {
2896 case SkPath::kEvenOdd_FillType: 2831 case SkPath::kEvenOdd_FillType:
2897 case SkPath::kInverseEvenOdd_FillType: 2832 case SkPath::kInverseEvenOdd_FillType:
2898 w &= 1; 2833 w &= 1;
2899 break; 2834 break;
2900 default: 2835 default:
2901 break; 2836 break;
2902 } 2837 }
2903 return SkToBool(w); 2838 return SkToBool(w);
2904 } 2839 }
OLDNEW
« no previous file with comments | « include/core/SkPathRef.h ('k') | src/core/SkPathRef.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698