Skia
2D Graphics Library
SkTiledImageUtils.h
Go to the documentation of this file.
1 /*
2  * Copyright 2023 Google LLC
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkTiledImageUtils_DEFINED
9 #define SkTiledImageUtils_DEFINED
10 
11 #include "include/core/SkCanvas.h"
12 #include "include/core/SkImage.h"
13 #include "include/core/SkRect.h"
14 #include "include/core/SkRefCnt.h"
16 #include "include/core/SkScalar.h"
17 #include "include/private/base/SkAPI.h"
18 
19 #include <cstdint>
20 
21 class SkPaint;
22 
30 namespace SkTiledImageUtils {
31 
32 SK_API void DrawImageRect(SkCanvas* canvas,
33  const SkImage* image,
34  const SkRect& src,
35  const SkRect& dst,
36  const SkSamplingOptions& sampling = {},
37  const SkPaint* paint = nullptr,
38  SkCanvas::SrcRectConstraint constraint =
40 
41 inline void DrawImageRect(SkCanvas* canvas,
42  const sk_sp<SkImage>& image,
43  const SkRect& src,
44  const SkRect& dst,
45  const SkSamplingOptions& sampling = {},
46  const SkPaint* paint = nullptr,
47  SkCanvas::SrcRectConstraint constraint =
49  DrawImageRect(canvas, image.get(), src, dst, sampling, paint, constraint);
50 }
51 
52 inline void DrawImageRect(SkCanvas* canvas,
53  const SkImage* image,
54  const SkRect& dst,
55  const SkSamplingOptions& sampling = {},
56  const SkPaint* paint = nullptr,
57  SkCanvas::SrcRectConstraint constraint =
59  if (!image) {
60  return;
61  }
62 
63  SkRect src = SkRect::MakeIWH(image->width(), image->height());
64 
65  DrawImageRect(canvas, image, src, dst, sampling, paint, constraint);
66 }
67 
68 inline void DrawImageRect(SkCanvas* canvas,
69  const sk_sp<SkImage>& image,
70  const SkRect& dst,
71  const SkSamplingOptions& sampling = {},
72  const SkPaint* paint = nullptr,
73  SkCanvas::SrcRectConstraint constraint =
75  DrawImageRect(canvas, image.get(), dst, sampling, paint, constraint);
76 }
77 
78 inline void DrawImage(SkCanvas* canvas,
79  const SkImage* image,
80  SkScalar x, SkScalar y,
81  const SkSamplingOptions& sampling = {},
82  const SkPaint* paint = nullptr,
83  SkCanvas::SrcRectConstraint constraint =
85  if (!image) {
86  return;
87  }
88 
89  SkRect src = SkRect::MakeIWH(image->width(), image->height());
90  SkRect dst = SkRect::MakeXYWH(x, y, image->width(), image->height());
91 
92  DrawImageRect(canvas, image, src, dst, sampling, paint, constraint);
93 }
94 
95 inline void DrawImage(SkCanvas* canvas,
96  const sk_sp<SkImage>& image,
97  SkScalar x, SkScalar y,
98  const SkSamplingOptions& sampling = {},
99  const SkPaint* paint = nullptr,
100  SkCanvas::SrcRectConstraint constraint =
102  DrawImage(canvas, image.get(), x, y, sampling, paint, constraint);
103 }
104 
105 static constexpr int kNumImageKeyValues = 6;
106 
121 SK_API void GetImageKeyValues(const SkImage* image, uint32_t keyValues[kNumImageKeyValues]);
122 
123 } // namespace SkTiledImageUtils
124 
125 #endif // SkTiledImageUtils_DEFINED
float SkScalar
Definition: SkScalar.h:14
SkCanvas provides an interface for drawing, and how the drawing is clipped and transformed.
Definition: SkCanvas.h:99
SrcRectConstraint
Definition: SkCanvas.h:1468
@ kFast_SrcRectConstraint
sample outside bounds; faster
Definition: SkCanvas.h:1470
SkImage describes a two dimensional array of pixels to draw.
Definition: SkImage.h:270
int width() const
Returns pixel count in each row.
Definition: SkImage.h:283
int height() const
Returns pixel row count.
Definition: SkImage.h:289
SkPaint controls options applied when drawing.
Definition: SkPaint.h:44
T * get() const
Definition: SkRefCnt.h:303
SkTiledImageUtils' DrawImage/DrawImageRect methods are intended to be direct replacements for their S...
Definition: SkTiledImageUtils.h:21
SK_API void DrawImageRect(SkCanvas *canvas, const SkImage *image, const SkRect &src, const SkRect &dst, const SkSamplingOptions &sampling={}, const SkPaint *paint=nullptr, SkCanvas::SrcRectConstraint constraint=SkCanvas::kFast_SrcRectConstraint)
void DrawImage(SkCanvas *canvas, const SkImage *image, SkScalar x, SkScalar y, const SkSamplingOptions &sampling={}, const SkPaint *paint=nullptr, SkCanvas::SrcRectConstraint constraint=SkCanvas::kFast_SrcRectConstraint)
Definition: SkTiledImageUtils.h:78
static constexpr int kNumImageKeyValues
Definition: SkTiledImageUtils.h:105
SK_API void GetImageKeyValues(const SkImage *image, uint32_t keyValues[kNumImageKeyValues])
Retrieves a set of values that can be used as part of a cache key for the provided image.
SkRect holds four float coordinates describing the upper and lower bounds of a rectangle.
Definition: SkRect.h:582
static SkRect MakeIWH(int w, int h)
Returns constructed SkRect set to integer values (0, 0, w, h).
Definition: SkRect.h:623
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Returns constructed SkRect set to (x, y, x + w, y + h).
Definition: SkRect.h:659
Definition: SkSamplingOptions.h:58