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

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

Issue 2744423002: Handle large rects better. (Closed)
Patch Set: Rebased on size patch Created 3 years, 8 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 26 matching lines...) Expand all
37 SkRect RectToSkRect(const Rect& rect) { 37 SkRect RectToSkRect(const Rect& rect) {
38 return SkRect::MakeXYWH( 38 return SkRect::MakeXYWH(
39 SkIntToScalar(rect.x()), SkIntToScalar(rect.y()), 39 SkIntToScalar(rect.x()), SkIntToScalar(rect.y()),
40 SkIntToScalar(rect.width()), SkIntToScalar(rect.height())); 40 SkIntToScalar(rect.width()), SkIntToScalar(rect.height()));
41 } 41 }
42 42
43 SkIRect RectToSkIRect(const Rect& rect) { 43 SkIRect RectToSkIRect(const Rect& rect) {
44 return SkIRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height()); 44 return SkIRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height());
45 } 45 }
46 46
47 // Produces a non-negative integer for the difference between min and max,
48 // yielding 0 if it would be negative and INT_MAX if it would overflow.
49 // This yields a length such that min+length is in range as well.
50 static int ClampLengthFromRange(int min, int max) {
51 if (min > max)
52 return 0;
53 return (base::CheckedNumeric<int>(max) - min)
54 .ValueOrDefault(std::numeric_limits<int>::max());
55 }
56
57 Rect SkIRectToRect(const SkIRect& rect) { 47 Rect SkIRectToRect(const SkIRect& rect) {
58 return Rect(rect.x(), rect.y(), 48 Rect result;
59 ClampLengthFromRange(rect.left(), rect.right()), 49 result.SetByBounds(rect.left(), rect.right(), rect.top(), rect.bottom());
60 ClampLengthFromRange(rect.top(), rect.bottom())); 50 return result;
61 } 51 }
62 52
63 SkRect RectFToSkRect(const RectF& rect) { 53 SkRect RectFToSkRect(const RectF& rect) {
64 return SkRect::MakeXYWH(SkFloatToScalar(rect.x()), 54 return SkRect::MakeXYWH(SkFloatToScalar(rect.x()),
65 SkFloatToScalar(rect.y()), 55 SkFloatToScalar(rect.y()),
66 SkFloatToScalar(rect.width()), 56 SkFloatToScalar(rect.width()),
67 SkFloatToScalar(rect.height())); 57 SkFloatToScalar(rect.height()));
68 } 58 }
69 59
70 RectF SkRectToRectF(const SkRect& rect) { 60 RectF SkRectToRectF(const SkRect& rect) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 static const SkScalar kSkToHbRatio = SK_Scalar1 / kHbUnit1; 152 static const SkScalar kSkToHbRatio = SK_Scalar1 / kHbUnit1;
163 return kSkToHbRatio * value; 153 return kSkToHbRatio * value;
164 } 154 }
165 155
166 float HarfBuzzUnitsToFloat(int value) { 156 float HarfBuzzUnitsToFloat(int value) {
167 static const float kFloatToHbRatio = 1.0f / kHbUnit1; 157 static const float kFloatToHbRatio = 1.0f / kHbUnit1;
168 return kFloatToHbRatio * value; 158 return kFloatToHbRatio * value;
169 } 159 }
170 160
171 } // namespace gfx 161 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698