| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "GrRectanizer_skyline.h" | 9 #include "GrRectanizer_skyline.h" |
| 10 #include "SkPoint.h" | 10 #include "SkPoint.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 void GrRectanizerSkyline::addSkylineLevel(int skylineIndex, int x, int y, int wi
dth, int height) { | 74 void GrRectanizerSkyline::addSkylineLevel(int skylineIndex, int x, int y, int wi
dth, int height) { |
| 75 SkylineSegment newSegment; | 75 SkylineSegment newSegment; |
| 76 newSegment.fX = x; | 76 newSegment.fX = x; |
| 77 newSegment.fY = y + height; | 77 newSegment.fY = y + height; |
| 78 newSegment.fWidth = width; | 78 newSegment.fWidth = width; |
| 79 fSkyline.insert(skylineIndex, 1, &newSegment); | 79 fSkyline.insert(skylineIndex, 1, &newSegment); |
| 80 | 80 |
| 81 SkASSERT(newSegment.fX + newSegment.fWidth <= this->width()); | 81 SkASSERT(newSegment.fX + newSegment.fWidth <= this->width()); |
| 82 SkASSERT(newSegment.fY <= this->height()); | 82 SkASSERT(newSegment.fY <= this->height()); |
| 83 | 83 |
| 84 // delete width of this skyline segment from following ones | 84 // delete width of the new skyline segment from following ones |
| 85 for (int i = skylineIndex+1; i < fSkyline.count(); ++i) { | 85 for (int i = skylineIndex+1; i < fSkyline.count(); ++i) { |
| 86 // The new segment subsumes all or part of fSkyline[i] |
| 86 SkASSERT(fSkyline[i-1].fX <= fSkyline[i].fX); | 87 SkASSERT(fSkyline[i-1].fX <= fSkyline[i].fX); |
| 87 | 88 |
| 88 if (fSkyline[i].fX < fSkyline[i-1].fX + fSkyline[i-1].fWidth) { | 89 if (fSkyline[i].fX < fSkyline[i-1].fX + fSkyline[i-1].fWidth) { |
| 89 int shrink = fSkyline[i-1].fX + fSkyline[i-1].fWidth - fSkyline[i].f
X; | 90 int shrink = fSkyline[i-1].fX + fSkyline[i-1].fWidth - fSkyline[i].f
X; |
| 90 | 91 |
| 91 fSkyline[i].fX += shrink; | 92 fSkyline[i].fX += shrink; |
| 92 fSkyline[i].fWidth -= shrink; | 93 fSkyline[i].fWidth -= shrink; |
| 93 | 94 |
| 94 if (fSkyline[i].fWidth <= 0) { | 95 if (fSkyline[i].fWidth <= 0) { |
| 96 // fully consumed |
| 95 fSkyline.remove(i); | 97 fSkyline.remove(i); |
| 96 --i; | 98 --i; |
| 97 } else { | 99 } else { |
| 100 // only partially consumed |
| 98 break; | 101 break; |
| 99 } | 102 } |
| 100 } else { | 103 } else { |
| 101 break; | 104 break; |
| 102 } | 105 } |
| 103 } | 106 } |
| 104 | 107 |
| 105 // merge fSkylines | 108 // merge fSkylines |
| 106 for (int i = 0; i < fSkyline.count()-1; ++i) { | 109 for (int i = 0; i < fSkyline.count()-1; ++i) { |
| 107 if (fSkyline[i].fY == fSkyline[i+1].fY) { | 110 if (fSkyline[i].fY == fSkyline[i+1].fY) { |
| 108 fSkyline[i].fWidth += fSkyline[i+1].fWidth; | 111 fSkyline[i].fWidth += fSkyline[i+1].fWidth; |
| 109 fSkyline.remove(i+1); | 112 fSkyline.remove(i+1); |
| 110 --i; | 113 --i; |
| 111 } | 114 } |
| 112 } | 115 } |
| 113 } | 116 } |
| 114 | 117 |
| 115 /////////////////////////////////////////////////////////////////////////////// | 118 /////////////////////////////////////////////////////////////////////////////// |
| 116 | 119 |
| 117 GrRectanizer* GrRectanizer::Factory(int width, int height) { | 120 GrRectanizer* GrRectanizer::Factory(int width, int height) { |
| 118 return SkNEW_ARGS(GrRectanizerSkyline, (width, height)); | 121 return SkNEW_ARGS(GrRectanizerSkyline, (width, height)); |
| 119 } | 122 } |
| OLD | NEW |