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

Side by Side Diff: ui/gfx/skia_util.cc

Issue 2744423002: Handle large rects better. (Closed)
Patch Set: Followup fixes Created 3 years, 9 months 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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/skia_util.h" 5 #include "ui/gfx/skia_util.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/numerics/safe_conversions.h" 10 #include "base/numerics/safe_conversions.h"
(...skipping 28 matching lines...) Expand all
39 SkRect RectToSkRect(const Rect& rect) { 39 SkRect RectToSkRect(const Rect& rect) {
40 return SkRect::MakeXYWH( 40 return SkRect::MakeXYWH(
41 SkIntToScalar(rect.x()), SkIntToScalar(rect.y()), 41 SkIntToScalar(rect.x()), SkIntToScalar(rect.y()),
42 SkIntToScalar(rect.width()), SkIntToScalar(rect.height())); 42 SkIntToScalar(rect.width()), SkIntToScalar(rect.height()));
43 } 43 }
44 44
45 SkIRect RectToSkIRect(const Rect& rect) { 45 SkIRect RectToSkIRect(const Rect& rect) {
46 return SkIRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height()); 46 return SkIRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height());
47 } 47 }
48 48
49 // Produces a non-negative integer for the difference between min and max,
50 // yielding 0 if it would be negative and INT_MAX if it would overflow.
51 // This yields a length such that min+length is in range as well.
52 static int ClampLengthFromRange(int min, int max) {
53 if (min > max)
54 return 0;
55 return (base::CheckedNumeric<int>(max) - min)
56 .ValueOrDefault(std::numeric_limits<int>::max());
57 }
58
59 Rect SkIRectToRect(const SkIRect& rect) { 49 Rect SkIRectToRect(const SkIRect& rect) {
60 return Rect(rect.x(), rect.y(), 50 Rect result;
61 ClampLengthFromRange(rect.left(), rect.right()), 51 result.SetByBounds(rect.left(), rect.right(), rect.top(), rect.bottom());
62 ClampLengthFromRange(rect.top(), rect.bottom())); 52 return result;
63 } 53 }
64 54
65 SkRect RectFToSkRect(const RectF& rect) { 55 SkRect RectFToSkRect(const RectF& rect) {
66 return SkRect::MakeXYWH(SkFloatToScalar(rect.x()), 56 return SkRect::MakeXYWH(SkFloatToScalar(rect.x()),
67 SkFloatToScalar(rect.y()), 57 SkFloatToScalar(rect.y()),
68 SkFloatToScalar(rect.width()), 58 SkFloatToScalar(rect.width()),
69 SkFloatToScalar(rect.height())); 59 SkFloatToScalar(rect.height()));
70 } 60 }
71 61
72 RectF SkRectToRectF(const SkRect& rect) { 62 RectF SkRectToRectF(const SkRect& rect) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 static const SkScalar kSkToHbRatio = SK_Scalar1 / kHbUnit1; 154 static const SkScalar kSkToHbRatio = SK_Scalar1 / kHbUnit1;
165 return kSkToHbRatio * value; 155 return kSkToHbRatio * value;
166 } 156 }
167 157
168 float HarfBuzzUnitsToFloat(int value) { 158 float HarfBuzzUnitsToFloat(int value) {
169 static const float kFloatToHbRatio = 1.0f / kHbUnit1; 159 static const float kFloatToHbRatio = 1.0f / kHbUnit1;
170 return kFloatToHbRatio * value; 160 return kFloatToHbRatio * value;
171 } 161 }
172 162
173 } // namespace gfx 163 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698