| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
| 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 | 9 |
| 10 #include "SkRect.h" | 10 #include "SkRect.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 void SkRect::toQuad(SkPoint quad[4]) const { | 49 void SkRect::toQuad(SkPoint quad[4]) const { |
| 50 SkASSERT(quad); | 50 SkASSERT(quad); |
| 51 | 51 |
| 52 quad[0].set(fLeft, fTop); | 52 quad[0].set(fLeft, fTop); |
| 53 quad[1].set(fRight, fTop); | 53 quad[1].set(fRight, fTop); |
| 54 quad[2].set(fRight, fBottom); | 54 quad[2].set(fRight, fBottom); |
| 55 quad[3].set(fLeft, fBottom); | 55 quad[3].set(fLeft, fBottom); |
| 56 } | 56 } |
| 57 | 57 |
| 58 #ifdef SK_SCALAR_IS_FLOAT | |
| 59 #define SkFLOATCODE(code) code | |
| 60 #else | |
| 61 #define SkFLOATCODE(code) | |
| 62 #endif | |
| 63 | |
| 64 // For float compares (at least on x86, by removing the else from the min/max | |
| 65 // computation, we get MAXSS and MINSS instructions, and no branches. | |
| 66 // Fixed point has no such opportunity (afaik), so we leave the else in that cas
e | |
| 67 #ifdef SK_SCALAR_IS_FLOAT | |
| 68 #define MINMAX_ELSE | |
| 69 #else | |
| 70 #define MINMAX_ELSE else | |
| 71 #endif | |
| 72 | |
| 73 bool SkRect::setBoundsCheck(const SkPoint pts[], int count) { | 58 bool SkRect::setBoundsCheck(const SkPoint pts[], int count) { |
| 74 SkASSERT((pts && count > 0) || count == 0); | 59 SkASSERT((pts && count > 0) || count == 0); |
| 75 | 60 |
| 76 bool isFinite = true; | 61 bool isFinite = true; |
| 77 | 62 |
| 78 if (count <= 0) { | 63 if (count <= 0) { |
| 79 sk_bzero(this, sizeof(SkRect)); | 64 sk_bzero(this, sizeof(SkRect)); |
| 80 } else { | 65 } else { |
| 81 SkScalar l, t, r, b; | 66 SkScalar l, t, r, b; |
| 82 | 67 |
| 83 l = r = pts[0].fX; | 68 l = r = pts[0].fX; |
| 84 t = b = pts[0].fY; | 69 t = b = pts[0].fY; |
| 85 | 70 |
| 86 // If all of the points are finite, accum should stay 0. If we encounter | 71 // If all of the points are finite, accum should stay 0. If we encounter |
| 87 // a NaN or infinity, then accum should become NaN. | 72 // a NaN or infinity, then accum should become NaN. |
| 88 SkFLOATCODE(float accum = 0;) | 73 float accum = 0; |
| 89 SkFLOATCODE(accum *= l; accum *= t;) | 74 accum *= l; accum *= t; |
| 90 | 75 |
| 91 for (int i = 1; i < count; i++) { | 76 for (int i = 1; i < count; i++) { |
| 92 SkScalar x = pts[i].fX; | 77 SkScalar x = pts[i].fX; |
| 93 SkScalar y = pts[i].fY; | 78 SkScalar y = pts[i].fY; |
| 94 | 79 |
| 95 SkFLOATCODE(accum *= x; accum *= y;) | 80 accum *= x; accum *= y; |
| 96 | 81 |
| 97 if (x < l) l = x; MINMAX_ELSE if (x > r) r = x; | 82 // we use if instead of if/else, so we can generate min/max |
| 98 if (y < t) t = y; MINMAX_ELSE if (y > b) b = y; | 83 // float instructions (at least on SSE) |
| 84 if (x < l) l = x; |
| 85 if (x > r) r = x; |
| 86 |
| 87 if (y < t) t = y; |
| 88 if (y > b) b = y; |
| 99 } | 89 } |
| 100 | 90 |
| 101 SkASSERT(!accum || !SkScalarIsFinite(accum)); | 91 SkASSERT(!accum || !SkScalarIsFinite(accum)); |
| 102 if (accum) { | 92 if (accum) { |
| 103 l = t = r = b = 0; | 93 l = t = r = b = 0; |
| 104 isFinite = false; | 94 isFinite = false; |
| 105 } | 95 } |
| 106 this->set(l, t, r, b); | 96 this->set(l, t, r, b); |
| 107 } | 97 } |
| 108 | 98 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 // if we are empty, just assign | 143 // if we are empty, just assign |
| 154 if (fLeft >= fRight || fTop >= fBottom) { | 144 if (fLeft >= fRight || fTop >= fBottom) { |
| 155 this->set(left, top, right, bottom); | 145 this->set(left, top, right, bottom); |
| 156 } else { | 146 } else { |
| 157 if (left < fLeft) fLeft = left; | 147 if (left < fLeft) fLeft = left; |
| 158 if (top < fTop) fTop = top; | 148 if (top < fTop) fTop = top; |
| 159 if (right > fRight) fRight = right; | 149 if (right > fRight) fRight = right; |
| 160 if (bottom > fBottom) fBottom = bottom; | 150 if (bottom > fBottom) fBottom = bottom; |
| 161 } | 151 } |
| 162 } | 152 } |
| OLD | NEW |