File: SkTiledImageUtils.h

package info (click to toggle)
webkit2gtk 2.48.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 429,764 kB
  • sloc: cpp: 3,697,587; javascript: 194,444; ansic: 169,997; python: 46,499; asm: 19,295; ruby: 18,528; perl: 16,602; xml: 4,650; yacc: 2,360; sh: 2,098; java: 1,993; lex: 1,327; pascal: 366; makefile: 298
file content (125 lines) | stat: -rw-r--r-- 5,191 bytes parent folder | download | duplicates (29)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
 * Copyright 2023 Google LLC
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SkTiledImageUtils_DEFINED
#define SkTiledImageUtils_DEFINED

#include "include/core/SkCanvas.h"
#include "include/core/SkImage.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSamplingOptions.h"
#include "include/core/SkScalar.h"
#include "include/private/base/SkAPI.h"

#include <cstdint>

class SkPaint;

/** \namespace SkTiledImageUtils
    SkTiledImageUtils' DrawImage/DrawImageRect methods are intended to be direct replacements
    for their SkCanvas equivalents. The SkTiledImageUtils calls will break SkBitmap-backed
    SkImages into smaller tiles and draw them if the original image is too large to be
    uploaded to the GPU. If the original image doesn't need tiling or is already gpu-backed
    the DrawImage/DrawImageRect calls will fall through to the matching SkCanvas call.
*/
namespace SkTiledImageUtils {

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);

inline void DrawImageRect(SkCanvas* canvas,
                          const sk_sp<SkImage>& image,
                          const SkRect& src,
                          const SkRect& dst,
                          const SkSamplingOptions& sampling = {},
                          const SkPaint* paint = nullptr,
                          SkCanvas::SrcRectConstraint constraint =
                                  SkCanvas::kFast_SrcRectConstraint) {
    DrawImageRect(canvas, image.get(), src, dst, sampling, paint, constraint);
}

inline void DrawImageRect(SkCanvas* canvas,
                          const SkImage* image,
                          const SkRect& dst,
                          const SkSamplingOptions& sampling = {},
                          const SkPaint* paint = nullptr,
                          SkCanvas::SrcRectConstraint constraint =
                                  SkCanvas::kFast_SrcRectConstraint) {
    if (!image) {
        return;
    }

    SkRect src = SkRect::MakeIWH(image->width(), image->height());

    DrawImageRect(canvas, image, src, dst, sampling, paint, constraint);
}

inline void DrawImageRect(SkCanvas* canvas,
                          const sk_sp<SkImage>& image,
                          const SkRect& dst,
                          const SkSamplingOptions& sampling = {},
                          const SkPaint* paint = nullptr,
                          SkCanvas::SrcRectConstraint constraint =
                                  SkCanvas::kFast_SrcRectConstraint) {
    DrawImageRect(canvas, image.get(), dst, sampling, paint, constraint);
}

inline void DrawImage(SkCanvas* canvas,
                      const SkImage* image,
                      SkScalar x, SkScalar y,
                      const SkSamplingOptions& sampling = {},
                      const SkPaint* paint = nullptr,
                      SkCanvas::SrcRectConstraint constraint =
                              SkCanvas::kFast_SrcRectConstraint) {
    if (!image) {
        return;
    }

    SkRect src = SkRect::MakeIWH(image->width(), image->height());
    SkRect dst = SkRect::MakeXYWH(x, y, image->width(), image->height());

    DrawImageRect(canvas, image, src, dst, sampling, paint, constraint);
}

inline void DrawImage(SkCanvas* canvas,
                      const sk_sp<SkImage>& image,
                      SkScalar x, SkScalar y,
                      const SkSamplingOptions& sampling = {},
                      const SkPaint* paint = nullptr,
                      SkCanvas::SrcRectConstraint constraint =
                              SkCanvas::kFast_SrcRectConstraint) {
    DrawImage(canvas, image.get(), x, y, sampling, paint, constraint);
}

static constexpr int kNumImageKeyValues = 6;

/** Retrieves a set of values that can be used as part of a cache key for the provided image.

    Unfortunately, SkImage::uniqueID isn't sufficient as an SkImage cache key. In particular,
    SkBitmap-backed SkImages can share a single SkBitmap and refer to different subsets of it.
    In this situation the optimal key is based on the SkBitmap's generation ID and the subset
    rectangle.
    For Picture-backed images this method will attempt to generate a concise internally-based
    key (i.e., containing picture ID, matrix translation, width and height, etc.). For complicated
    Picture-backed images (i.e., those w/ a paint or a full matrix) it will fall back to
    using 'image's unique key.

    @param image     The image for which key values are desired
    @param keyValues The resulting key values
*/
SK_API void GetImageKeyValues(const SkImage* image, uint32_t keyValues[kNumImageKeyValues]);

}  // namespace SkTiledImageUtils

#endif // SkTiledImageUtils_DEFINED