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 #ifndef UI_GFX_SKIA_UTIL_H_ | 5 #ifndef UI_GFX_SKIA_UTIL_H_ |
6 #define UI_GFX_SKIA_UTIL_H_ | 6 #define UI_GFX_SKIA_UTIL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
| 11 #include "skia/ext/refptr.h" |
11 #include "third_party/skia/include/core/SkColor.h" | 12 #include "third_party/skia/include/core/SkColor.h" |
12 #include "third_party/skia/include/core/SkRect.h" | 13 #include "third_party/skia/include/core/SkRect.h" |
13 #include "third_party/skia/include/core/SkShader.h" | 14 #include "third_party/skia/include/core/SkShader.h" |
14 #include "ui/base/ui_export.h" | 15 #include "ui/base/ui_export.h" |
15 | 16 |
16 class SkBitmap; | 17 class SkBitmap; |
17 class SkDrawLooper; | 18 class SkDrawLooper; |
18 | 19 |
19 namespace gfx { | 20 namespace gfx { |
20 | 21 |
21 class ImageSkiaRep; | 22 class ImageSkiaRep; |
22 class Rect; | 23 class Rect; |
23 class RectF; | 24 class RectF; |
24 class ShadowValue; | 25 class ShadowValue; |
25 | 26 |
26 // Convert between Skia and gfx rect types. | 27 // Convert between Skia and gfx rect types. |
27 UI_EXPORT SkRect RectToSkRect(const Rect& rect); | 28 UI_EXPORT SkRect RectToSkRect(const Rect& rect); |
28 UI_EXPORT SkIRect RectToSkIRect(const Rect& rect); | 29 UI_EXPORT SkIRect RectToSkIRect(const Rect& rect); |
29 UI_EXPORT Rect SkIRectToRect(const SkIRect& rect); | 30 UI_EXPORT Rect SkIRectToRect(const SkIRect& rect); |
30 UI_EXPORT SkRect RectFToSkRect(const RectF& rect); | 31 UI_EXPORT SkRect RectFToSkRect(const RectF& rect); |
31 UI_EXPORT RectF SkRectToRectF(const SkRect& rect); | 32 UI_EXPORT RectF SkRectToRectF(const SkRect& rect); |
32 | 33 |
33 // Creates a bitmap shader for the image rep with the image rep's scale factor. | 34 // Creates a bitmap shader for the image rep with the image rep's scale factor. |
34 // Sets the created shader's local matrix such that it displays the image rep at | 35 // Sets the created shader's local matrix such that it displays the image rep at |
35 // the correct scale factor. | 36 // the correct scale factor. |
36 // The shader's local matrix should not be changed after the shader is created. | 37 // The shader's local matrix should not be changed after the shader is created. |
37 // TODO(pkotwicz): Allow shader's local matrix to be changed after the shader | 38 // TODO(pkotwicz): Allow shader's local matrix to be changed after the shader |
38 // is created. | 39 // is created. |
39 // Example usage to avoid leaks: | |
40 // SkSafeUnref(paint.setShader(gfx::CreateImageRepShader(image_rep, | |
41 // tile_mode, matrix))); | |
42 // | 40 // |
43 // (The old shader in the paint, if any, needs to be freed, and SkSafeUnref will | 41 UI_EXPORT skia::RefPtr<SkShader> CreateImageRepShader( |
44 // handle the NULL case.) | 42 const gfx::ImageSkiaRep& image_rep, |
45 UI_EXPORT SkShader* CreateImageRepShader(const gfx::ImageSkiaRep& image_rep, | 43 SkShader::TileMode tile_mode, |
46 SkShader::TileMode tile_mode, | 44 const SkMatrix& local_matrix); |
47 const SkMatrix& local_matrix); | |
48 | 45 |
49 // Creates a vertical gradient shader. The caller owns the shader. | 46 // Creates a vertical gradient shader. The caller owns the shader. |
50 // Example usage to avoid leaks: | 47 // Example usage to avoid leaks: |
51 // SkSafeUnref(paint.setShader(gfx::CreateGradientShader(0, 10, red, blue))); | 48 UI_EXPORT skia::RefPtr<SkShader> CreateGradientShader(int start_point, |
52 // | 49 int end_point, |
53 // (The old shader in the paint, if any, needs to be freed, and SkSafeUnref will | 50 SkColor start_color, |
54 // handle the NULL case.) | 51 SkColor end_color); |
55 UI_EXPORT SkShader* CreateGradientShader(int start_point, | |
56 int end_point, | |
57 SkColor start_color, | |
58 SkColor end_color); | |
59 | 52 |
60 // Creates a draw looper to generate |shadows|. The caller owns the draw looper. | 53 // Creates a draw looper to generate |shadows|. The caller owns the draw looper. |
61 // NULL is returned if |shadows| is empty since no draw looper is needed in | 54 // NULL is returned if |shadows| is empty since no draw looper is needed in |
62 // this case. | 55 // this case. |
63 // Example usage to avoid leaks: | 56 UI_EXPORT skia::RefPtr<SkDrawLooper> CreateShadowDrawLooper( |
64 // SkSafeUnref(paint.setDrawLooper(gfx::CreateShadowDrawLooper(shadows))); | |
65 UI_EXPORT SkDrawLooper* CreateShadowDrawLooper( | |
66 const std::vector<ShadowValue>& shadows); | 57 const std::vector<ShadowValue>& shadows); |
67 | 58 |
68 // Returns true if the two bitmaps contain the same pixels. | 59 // Returns true if the two bitmaps contain the same pixels. |
69 UI_EXPORT bool BitmapsAreEqual(const SkBitmap& bitmap1, | 60 UI_EXPORT bool BitmapsAreEqual(const SkBitmap& bitmap1, |
70 const SkBitmap& bitmap2); | 61 const SkBitmap& bitmap2); |
71 | 62 |
72 // Converts Skia ARGB format pixels in |skia| to RGBA. | 63 // Converts Skia ARGB format pixels in |skia| to RGBA. |
73 UI_EXPORT void ConvertSkiaToRGBA(const unsigned char* skia, | 64 UI_EXPORT void ConvertSkiaToRGBA(const unsigned char* skia, |
74 int pixel_width, | 65 int pixel_width, |
75 unsigned char* rgba); | 66 unsigned char* rgba); |
76 | 67 |
77 } // namespace gfx | 68 } // namespace gfx |
78 | 69 |
79 #endif // UI_GFX_SKIA_UTIL_H_ | 70 #endif // UI_GFX_SKIA_UTIL_H_ |
OLD | NEW |