| 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 "third_party/skia/include/core/SkColor.h" | 11 #include "third_party/skia/include/core/SkColor.h" |
| 12 #include "third_party/skia/include/core/SkRect.h" | 12 #include "third_party/skia/include/core/SkRect.h" |
| 13 #include "third_party/skia/include/core/SkShader.h" | 13 #include "third_party/skia/include/core/SkShader.h" |
| 14 #include "ui/gfx/geometry/quad_f.h" | 14 #include "ui/gfx/geometry/quad_f.h" |
| 15 #include "ui/gfx/geometry/size.h" | 15 #include "ui/gfx/geometry/size.h" |
| 16 #include "ui/gfx/gfx_export.h" | 16 #include "ui/gfx/gfx_export.h" |
| 17 | 17 |
| 18 class SkBitmap; | 18 class SkBitmap; |
| 19 class SkDrawLooper; | 19 class SkMatrix; |
| 20 | 20 |
| 21 namespace gfx { | 21 namespace gfx { |
| 22 | 22 |
| 23 class ImageSkiaRep; | |
| 24 class Point; | 23 class Point; |
| 25 class PointF; | 24 class PointF; |
| 26 class Rect; | 25 class Rect; |
| 27 class RectF; | 26 class RectF; |
| 28 class ShadowValue; | |
| 29 class Transform; | 27 class Transform; |
| 30 | 28 |
| 31 // Convert between Skia and gfx types. | 29 // Convert between Skia and gfx types. |
| 32 GFX_EXPORT SkPoint PointToSkPoint(const Point& point); | 30 GFX_EXPORT SkPoint PointToSkPoint(const Point& point); |
| 33 GFX_EXPORT SkIPoint PointToSkIPoint(const Point& point); | 31 GFX_EXPORT SkIPoint PointToSkIPoint(const Point& point); |
| 34 GFX_EXPORT SkPoint PointFToSkPoint(const PointF& point); | 32 GFX_EXPORT SkPoint PointFToSkPoint(const PointF& point); |
| 35 GFX_EXPORT SkRect RectToSkRect(const Rect& rect); | 33 GFX_EXPORT SkRect RectToSkRect(const Rect& rect); |
| 36 GFX_EXPORT SkIRect RectToSkIRect(const Rect& rect); | 34 GFX_EXPORT SkIRect RectToSkIRect(const Rect& rect); |
| 37 GFX_EXPORT Rect SkIRectToRect(const SkIRect& rect); | 35 GFX_EXPORT Rect SkIRectToRect(const SkIRect& rect); |
| 38 GFX_EXPORT SkRect RectFToSkRect(const RectF& rect); | 36 GFX_EXPORT SkRect RectFToSkRect(const RectF& rect); |
| 39 GFX_EXPORT RectF SkRectToRectF(const SkRect& rect); | 37 GFX_EXPORT RectF SkRectToRectF(const SkRect& rect); |
| 40 GFX_EXPORT SkSize SizeFToSkSize(const SizeF& size); | 38 GFX_EXPORT SkSize SizeFToSkSize(const SizeF& size); |
| 41 GFX_EXPORT SizeF SkSizeToSizeF(const SkSize& size); | 39 GFX_EXPORT SizeF SkSizeToSizeF(const SkSize& size); |
| 42 GFX_EXPORT Size SkISizeToSize(const SkISize& size); | 40 GFX_EXPORT Size SkISizeToSize(const SkISize& size); |
| 43 | 41 |
| 44 GFX_EXPORT void QuadFToSkPoints(const gfx::QuadF& quad, SkPoint points[4]); | 42 GFX_EXPORT void QuadFToSkPoints(const gfx::QuadF& quad, SkPoint points[4]); |
| 45 | 43 |
| 46 GFX_EXPORT void TransformToFlattenedSkMatrix(const gfx::Transform& transform, | 44 GFX_EXPORT void TransformToFlattenedSkMatrix(const gfx::Transform& transform, |
| 47 SkMatrix* flattened); | 45 SkMatrix* flattened); |
| 48 | 46 |
| 49 // Creates a bitmap shader for the image rep with the image rep's scale factor. | |
| 50 // Sets the created shader's local matrix such that it displays the image rep at | |
| 51 // the correct scale factor. | |
| 52 // The shader's local matrix should not be changed after the shader is created. | |
| 53 // TODO(pkotwicz): Allow shader's local matrix to be changed after the shader | |
| 54 // is created. | |
| 55 // | |
| 56 GFX_EXPORT sk_sp<SkShader> CreateImageRepShader( | |
| 57 const gfx::ImageSkiaRep& image_rep, | |
| 58 SkShader::TileMode tile_mode, | |
| 59 const SkMatrix& local_matrix); | |
| 60 | |
| 61 // Creates a bitmap shader for the image rep with the passed in scale factor. | |
| 62 GFX_EXPORT sk_sp<SkShader> CreateImageRepShaderForScale( | |
| 63 const gfx::ImageSkiaRep& image_rep, | |
| 64 SkShader::TileMode tile_mode, | |
| 65 const SkMatrix& local_matrix, | |
| 66 SkScalar scale); | |
| 67 | |
| 68 // Creates a vertical gradient shader. The caller owns the shader. | |
| 69 // Example usage to avoid leaks: | |
| 70 GFX_EXPORT sk_sp<SkShader> CreateGradientShader(int start_point, | |
| 71 int end_point, | |
| 72 SkColor start_color, | |
| 73 SkColor end_color); | |
| 74 | |
| 75 // Creates a draw looper to generate |shadows|. The caller owns the draw looper. | |
| 76 // NULL is returned if |shadows| is empty since no draw looper is needed in | |
| 77 // this case. | |
| 78 // DEPRECATED: See below. TODO(estade): remove this: crbug.com/624175 | |
| 79 GFX_EXPORT sk_sp<SkDrawLooper> CreateShadowDrawLooper( | |
| 80 const std::vector<ShadowValue>& shadows); | |
| 81 | |
| 82 // Creates a draw looper to generate |shadows|. This creates a looper with the | |
| 83 // correct amount of blur. Callers of the existing CreateShadowDrawLooper may | |
| 84 // rely on the wrong amount of blur being applied but new code should use this | |
| 85 // function. | |
| 86 GFX_EXPORT sk_sp<SkDrawLooper> CreateShadowDrawLooperCorrectBlur( | |
| 87 const std::vector<ShadowValue>& shadows); | |
| 88 | |
| 89 // Returns true if the two bitmaps contain the same pixels. | 47 // Returns true if the two bitmaps contain the same pixels. |
| 90 GFX_EXPORT bool BitmapsAreEqual(const SkBitmap& bitmap1, | 48 GFX_EXPORT bool BitmapsAreEqual(const SkBitmap& bitmap1, |
| 91 const SkBitmap& bitmap2); | 49 const SkBitmap& bitmap2); |
| 92 | 50 |
| 93 // Converts Skia ARGB format pixels in |skia| to RGBA. | 51 // Converts Skia ARGB format pixels in |skia| to RGBA. |
| 94 GFX_EXPORT void ConvertSkiaToRGBA(const unsigned char* skia, | 52 GFX_EXPORT void ConvertSkiaToRGBA(const unsigned char* skia, |
| 95 int pixel_width, | 53 int pixel_width, |
| 96 unsigned char* rgba); | 54 unsigned char* rgba); |
| 97 | 55 |
| 98 // Converts a Skia floating-point value to an int appropriate for hb_position_t. | 56 // Converts a Skia floating-point value to an int appropriate for hb_position_t. |
| 99 GFX_EXPORT int SkiaScalarToHarfBuzzUnits(SkScalar value); | 57 GFX_EXPORT int SkiaScalarToHarfBuzzUnits(SkScalar value); |
| 100 | 58 |
| 101 // Converts an hb_position_t to a Skia floating-point value. | 59 // Converts an hb_position_t to a Skia floating-point value. |
| 102 GFX_EXPORT SkScalar HarfBuzzUnitsToSkiaScalar(int value); | 60 GFX_EXPORT SkScalar HarfBuzzUnitsToSkiaScalar(int value); |
| 103 | 61 |
| 104 // Converts an hb_position_t to a float. | 62 // Converts an hb_position_t to a float. |
| 105 GFX_EXPORT float HarfBuzzUnitsToFloat(int value); | 63 GFX_EXPORT float HarfBuzzUnitsToFloat(int value); |
| 106 | 64 |
| 107 } // namespace gfx | 65 } // namespace gfx |
| 108 | 66 |
| 109 #endif // UI_GFX_SKIA_UTIL_H_ | 67 #endif // UI_GFX_SKIA_UTIL_H_ |
| OLD | NEW |