| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "gfx/skia_util.h" | |
| 6 | |
| 7 #include "gfx/rect.h" | |
| 8 #include "third_party/skia/include/core/SkBitmap.h" | |
| 9 #include "third_party/skia/include/core/SkColorPriv.h" | |
| 10 #include "third_party/skia/include/core/SkShader.h" | |
| 11 #include "third_party/skia/include/effects/SkGradientShader.h" | |
| 12 | |
| 13 namespace gfx { | |
| 14 | |
| 15 SkRect RectToSkRect(const gfx::Rect& rect) { | |
| 16 SkRect r; | |
| 17 r.set(SkIntToScalar(rect.x()), SkIntToScalar(rect.y()), | |
| 18 SkIntToScalar(rect.right()), SkIntToScalar(rect.bottom())); | |
| 19 return r; | |
| 20 } | |
| 21 | |
| 22 gfx::Rect SkRectToRect(const SkRect& rect) { | |
| 23 return gfx::Rect(SkScalarToFixed(rect.fLeft), | |
| 24 SkScalarToFixed(rect.fTop), | |
| 25 SkScalarToFixed(rect.width()), | |
| 26 SkScalarToFixed(rect.height())); | |
| 27 } | |
| 28 | |
| 29 SkShader* CreateGradientShader(int start_point, | |
| 30 int end_point, | |
| 31 SkColor start_color, | |
| 32 SkColor end_color) { | |
| 33 SkColor grad_colors[2] = { start_color, end_color}; | |
| 34 SkPoint grad_points[2]; | |
| 35 grad_points[0].set(SkIntToScalar(0), SkIntToScalar(start_point)); | |
| 36 grad_points[1].set(SkIntToScalar(0), SkIntToScalar(end_point)); | |
| 37 | |
| 38 return SkGradientShader::CreateLinear( | |
| 39 grad_points, grad_colors, NULL, 2, SkShader::kRepeat_TileMode); | |
| 40 } | |
| 41 | |
| 42 bool BitmapsAreEqual(const SkBitmap& bitmap1, const SkBitmap& bitmap2) { | |
| 43 void* addr1 = NULL; | |
| 44 void* addr2 = NULL; | |
| 45 size_t size1 = 0; | |
| 46 size_t size2 = 0; | |
| 47 | |
| 48 bitmap1.lockPixels(); | |
| 49 addr1 = bitmap1.getAddr32(0, 0); | |
| 50 size1 = bitmap1.getSize(); | |
| 51 bitmap1.unlockPixels(); | |
| 52 | |
| 53 bitmap2.lockPixels(); | |
| 54 addr2 = bitmap2.getAddr32(0, 0); | |
| 55 size2 = bitmap2.getSize(); | |
| 56 bitmap2.unlockPixels(); | |
| 57 | |
| 58 return (size1 == size2) && (0 == memcmp(addr1, addr2, bitmap1.getSize())); | |
| 59 } | |
| 60 | |
| 61 } // namespace gfx | |
| OLD | NEW |