Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| 11 #include "base/numerics/safe_math.h" | |
| 11 #include "third_party/skia/include/core/SkBitmap.h" | 12 #include "third_party/skia/include/core/SkBitmap.h" |
| 12 #include "third_party/skia/include/core/SkColorFilter.h" | 13 #include "third_party/skia/include/core/SkColorFilter.h" |
| 13 #include "third_party/skia/include/core/SkColorPriv.h" | 14 #include "third_party/skia/include/core/SkColorPriv.h" |
| 14 #include "third_party/skia/include/core/SkUnPreMultiply.h" | 15 #include "third_party/skia/include/core/SkUnPreMultiply.h" |
| 15 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" | 16 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" |
| 16 #include "third_party/skia/include/effects/SkGradientShader.h" | 17 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 17 #include "third_party/skia/include/effects/SkLayerDrawLooper.h" | 18 #include "third_party/skia/include/effects/SkLayerDrawLooper.h" |
| 18 #include "ui/gfx/geometry/quad_f.h" | 19 #include "ui/gfx/geometry/quad_f.h" |
| 19 #include "ui/gfx/geometry/rect.h" | 20 #include "ui/gfx/geometry/rect.h" |
| 20 #include "ui/gfx/geometry/rect_f.h" | 21 #include "ui/gfx/geometry/rect_f.h" |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 40 return SkRect::MakeXYWH( | 41 return SkRect::MakeXYWH( |
| 41 SkIntToScalar(rect.x()), SkIntToScalar(rect.y()), | 42 SkIntToScalar(rect.x()), SkIntToScalar(rect.y()), |
| 42 SkIntToScalar(rect.width()), SkIntToScalar(rect.height())); | 43 SkIntToScalar(rect.width()), SkIntToScalar(rect.height())); |
| 43 } | 44 } |
| 44 | 45 |
| 45 SkIRect RectToSkIRect(const Rect& rect) { | 46 SkIRect RectToSkIRect(const Rect& rect) { |
| 46 return SkIRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height()); | 47 return SkIRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height()); |
| 47 } | 48 } |
| 48 | 49 |
| 49 Rect SkIRectToRect(const SkIRect& rect) { | 50 Rect SkIRectToRect(const SkIRect& rect) { |
| 50 return Rect(rect.x(), rect.y(), rect.width(), rect.height()); | 51 return Rect(rect.x(), rect.y(), |
| 52 (base::CheckedNumeric<int>(rect.right()) - rect.left()) | |
|
danakj
2016/08/22 20:01:49
I see, ok so checking right-left here makes sense
| |
| 53 .ValueOrDefault(std::numeric_limits<int>::max()), | |
|
danakj
2016/08/22 20:01:49
But if x >= 0, the right() will still overflow wit
jbroman
2016/08/23 03:26:58
That cannot happen here, since SkIRect::fRight mus
| |
| 54 (base::CheckedNumeric<int>(rect.bottom()) - rect.top()) | |
| 55 .ValueOrDefault(std::numeric_limits<int>::max())); | |
| 51 } | 56 } |
| 52 | 57 |
| 53 SkRect RectFToSkRect(const RectF& rect) { | 58 SkRect RectFToSkRect(const RectF& rect) { |
| 54 return SkRect::MakeXYWH(SkFloatToScalar(rect.x()), | 59 return SkRect::MakeXYWH(SkFloatToScalar(rect.x()), |
| 55 SkFloatToScalar(rect.y()), | 60 SkFloatToScalar(rect.y()), |
| 56 SkFloatToScalar(rect.width()), | 61 SkFloatToScalar(rect.width()), |
| 57 SkFloatToScalar(rect.height())); | 62 SkFloatToScalar(rect.height())); |
| 58 } | 63 } |
| 59 | 64 |
| 60 RectF SkRectToRectF(const SkRect& rect) { | 65 RectF SkRectToRectF(const SkRect& rect) { |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 static const SkScalar kSkToHbRatio = SK_Scalar1 / kHbUnit1; | 281 static const SkScalar kSkToHbRatio = SK_Scalar1 / kHbUnit1; |
| 277 return kSkToHbRatio * value; | 282 return kSkToHbRatio * value; |
| 278 } | 283 } |
| 279 | 284 |
| 280 float HarfBuzzUnitsToFloat(int value) { | 285 float HarfBuzzUnitsToFloat(int value) { |
| 281 static const float kFloatToHbRatio = 1.0f / kHbUnit1; | 286 static const float kFloatToHbRatio = 1.0f / kHbUnit1; |
| 282 return kFloatToHbRatio * value; | 287 return kFloatToHbRatio * value; |
| 283 } | 288 } |
| 284 | 289 |
| 285 } // namespace gfx | 290 } // namespace gfx |
| OLD | NEW |