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