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 18 matching lines...) Expand all Loading... | |
| 39 SkRect RectToSkRect(const Rect& rect) { | 40 SkRect RectToSkRect(const Rect& rect) { |
| 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 |
| 50 SkIRect RectToSkIRectChecked(const Rect& rect) { | |
| 51 return SkIRect::MakeLTRB( | |
| 52 rect.x(), rect.y(), | |
| 53 (base::CheckedNumeric<int32_t>(rect.x()) + rect.width()) | |
| 54 .ValueOrDefault(std::numeric_limits<int32_t>::max()), | |
| 55 (base::CheckedNumeric<int32_t>(rect.y()) + rect.height()) | |
| 56 .ValueOrDefault(std::numeric_limits<int32_t>::max())); | |
| 57 } | |
| 58 | |
| 49 Rect SkIRectToRect(const SkIRect& rect) { | 59 Rect SkIRectToRect(const SkIRect& rect) { |
| 50 return Rect(rect.x(), rect.y(), rect.width(), rect.height()); | 60 return Rect(rect.x(), rect.y(), rect.width(), rect.height()); |
| 51 } | 61 } |
| 52 | 62 |
| 63 Rect SkIRectToRectChecked(const SkIRect& rect) { | |
|
danakj
2016/08/11 18:13:37
OK I think I'd rather not have Checked version tha
| |
| 64 return Rect(rect.x(), rect.y(), | |
| 65 (base::CheckedNumeric<int>(rect.right()) - rect.left()) | |
| 66 .ValueOrDefault(std::numeric_limits<int>::max()), | |
| 67 (base::CheckedNumeric<int>(rect.bottom()) - rect.top()) | |
| 68 .ValueOrDefault(std::numeric_limits<int>::max())); | |
| 69 } | |
| 70 | |
| 53 SkRect RectFToSkRect(const RectF& rect) { | 71 SkRect RectFToSkRect(const RectF& rect) { |
| 54 return SkRect::MakeXYWH(SkFloatToScalar(rect.x()), | 72 return SkRect::MakeXYWH(SkFloatToScalar(rect.x()), |
| 55 SkFloatToScalar(rect.y()), | 73 SkFloatToScalar(rect.y()), |
| 56 SkFloatToScalar(rect.width()), | 74 SkFloatToScalar(rect.width()), |
| 57 SkFloatToScalar(rect.height())); | 75 SkFloatToScalar(rect.height())); |
| 58 } | 76 } |
| 59 | 77 |
| 60 RectF SkRectToRectF(const SkRect& rect) { | 78 RectF SkRectToRectF(const SkRect& rect) { |
| 61 return RectF(SkScalarToFloat(rect.x()), | 79 return RectF(SkScalarToFloat(rect.x()), |
| 62 SkScalarToFloat(rect.y()), | 80 SkScalarToFloat(rect.y()), |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 static const SkScalar kSkToHbRatio = SK_Scalar1 / kHbUnit1; | 294 static const SkScalar kSkToHbRatio = SK_Scalar1 / kHbUnit1; |
| 277 return kSkToHbRatio * value; | 295 return kSkToHbRatio * value; |
| 278 } | 296 } |
| 279 | 297 |
| 280 float HarfBuzzUnitsToFloat(int value) { | 298 float HarfBuzzUnitsToFloat(int value) { |
| 281 static const float kFloatToHbRatio = 1.0f / kHbUnit1; | 299 static const float kFloatToHbRatio = 1.0f / kHbUnit1; |
| 282 return kFloatToHbRatio * value; | 300 return kFloatToHbRatio * value; |
| 283 } | 301 } |
| 284 | 302 |
| 285 } // namespace gfx | 303 } // namespace gfx |
| OLD | NEW |