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

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

Issue 2482863004: Check negative overflow of quickSkFDot6Div (Closed)
Patch Set: Created 4 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 | « no previous file | no next file » | 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 8
9 #include "SkAnalyticEdge.h" 9 #include "SkAnalyticEdge.h"
10 #include "SkFDot6.h" 10 #include "SkFDot6.h"
11 #include "SkMathPriv.h" 11 #include "SkMathPriv.h"
12 #include "SkAAAConstants.h" 12 #include "SkAAAConstants.h"
13 13
14 class QuickFDot6Inverse { 14 class QuickFDot6Inverse {
15 private: 15 private:
16 static constexpr const SkFDot6* table = gFDot6INVERSE + kInverseTableSize; 16 static constexpr const SkFDot6* table = gFDot6INVERSE + kInverseTableSize;
17 public: 17 public:
18 inline static SkFixed Lookup(SkFDot6 x) { 18 inline static SkFixed Lookup(SkFDot6 x) {
19 SkASSERT(SkAbs32(x) < kInverseTableSize); 19 SkASSERT(SkAbs32(x) < kInverseTableSize);
20 return table[x]; 20 return table[x];
21 } 21 }
22 }; 22 };
23 23
24 static inline SkFixed quickSkFDot6Div(SkFDot6 a, SkFDot6 b) { 24 static inline SkFixed quickSkFDot6Div(SkFDot6 a, SkFDot6 b) {
25 if (SkAbs32(b) < kInverseTableSize) { 25 // Max inverse of b is 2^6 which is 2^22 in SkFixed format.
26 SkASSERT((int64_t)a * QuickFDot6Inverse::Lookup(b) <= SK_MaxS32); 26 // Hence the safe value of abs(a) should be less than 2^10.
27 if (SkAbs32(b) < kInverseTableSize && SkAbs32(a) < (1 << 10)) {
28 SkASSERT((int64_t)a * QuickFDot6Inverse::Lookup(b) <= SK_MaxS32
29 && (int64_t)a * QuickFDot6Inverse::Lookup(b) >= SK_MinS32);
27 SkFixed ourAnswer = (a * QuickFDot6Inverse::Lookup(b)) >> 6; 30 SkFixed ourAnswer = (a * QuickFDot6Inverse::Lookup(b)) >> 6;
28 #ifdef SK_DEBUG 31 #ifdef SK_DEBUG
29 SkFixed directAnswer = SkFDot6Div(a, b); 32 SkFixed directAnswer = SkFDot6Div(a, b);
30 SkASSERT( 33 SkASSERT(
31 (directAnswer == 0 && ourAnswer == 0) || 34 (directAnswer == 0 && ourAnswer == 0) ||
32 SkFixedDiv(SkAbs32(directAnswer - ourAnswer), SkAbs32(directAnswer)) <= 1 << 10 35 SkFixedDiv(SkAbs32(directAnswer - ourAnswer), SkAbs32(directAnswer)) <= 1 << 10
33 ); 36 );
34 #endif 37 #endif
35 return ourAnswer; 38 return ourAnswer;
36 } else { 39 } else {
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 SkFDot6Div(SkFixedToFDot6(newx - oldx), SkFixedToFDot6(n ewy - oldy))); 239 SkFDot6Div(SkFixedToFDot6(newx - oldx), SkFixedToFDot6(n ewy - oldy)));
237 oldx = newx; 240 oldx = newx;
238 oldy = newy; 241 oldy = newy;
239 } while (count < 0 && !success); 242 } while (count < 0 && !success);
240 243
241 fCEdge.fCx = newx; 244 fCEdge.fCx = newx;
242 fCEdge.fCy = newy; 245 fCEdge.fCy = newy;
243 fCurveCount = SkToS8(count); 246 fCurveCount = SkToS8(count);
244 return success; 247 return success;
245 } 248 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698