Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrImageUtils.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#ifndef GrImageUtils_DEFINED
8#define GrImageUtils_DEFINED
9
11
14#include "src/gpu/ganesh/GrFragmentProcessor.h" // IWYU pragma: keep
15#include "src/gpu/ganesh/GrSurfaceProxyView.h" // IWYU pragma: keep
16#include "src/gpu/ganesh/SkGr.h"
17
18#include <cstdint>
19#include <memory>
20#include <string_view>
21#include <tuple>
22
23class GrCaps;
24class GrImageContext;
26class SkImage;
27class SkImage_Lazy;
28class SkImage_Raster;
29class SkMatrix;
30class SkSurfaceProps;
31enum GrSurfaceOrigin : int;
32enum SkAlphaType : int;
33enum SkColorType : int;
34enum class GrColorType;
35enum class SkTileMode;
36namespace skgpu { enum class Mipmapped : bool; }
37struct SkRect;
38
39namespace skgpu::ganesh {
40// Returns a GrSurfaceProxyView representation of the image, if possible. This also returns
41// a color type. This may be different than the image's color type when the image is not
42// texture-backed and the capabilities of the GPU require a data type conversion to put
43// the data in a texture.
44std::tuple<GrSurfaceProxyView, GrColorType> AsView(
46 const SkImage*,
49
50inline std::tuple<GrSurfaceProxyView, GrColorType> AsView(
52 const sk_sp<const SkImage>& img,
55 return AsView(ctx, img.get(), mm, policy);
56}
57
58std::tuple<GrSurfaceProxyView, GrColorType> RasterAsView(
60 const SkImage_Raster*,
63
64// Utility for making a copy of an existing view when the GrImageTexGenPolicy is not kDraw.
69 std::string_view label);
70
71// Returns the texture proxy. CachingHint refers to whether the generator's output should be
72// cached in CPU memory. We will always cache the generated texture on success.
74 const SkImage_Lazy*,
77
78// Returns the GrColorType to use with the GrTextureProxy returned from lockTextureProxy. This
79// may be different from the color type on the image in the case where we need up upload CPU
80// data to a texture but the GPU doesn't support the format of CPU data. In this case we convert
81// the data to RGBA_8888 unorm on the CPU then upload that.
83
84/**
85 * Returns a GrFragmentProcessor that can be used with the passed GrRecordingContext to
86 * draw the image. SkSamplingOptions indicates the filter and SkTileMode[] indicates the x and
87 * y tile modes. The passed matrix is applied to the coordinates before sampling the image.
88 * Optional 'subset' indicates whether the tile modes should be applied to a subset of the image
89 * Optional 'domain' is a bound on the coordinates of the image that will be required and can be
90 * used to optimize the shader if 'subset' is also specified.
91 */
92std::unique_ptr<GrFragmentProcessor> AsFragmentProcessor(GrRecordingContext*,
93 const SkImage*,
95 const SkTileMode[2],
96 const SkMatrix&,
97 const SkRect* subset = nullptr,
98 const SkRect* domain = nullptr);
99
100inline std::unique_ptr<GrFragmentProcessor> AsFragmentProcessor(GrRecordingContext* ctx,
101 const sk_sp<const SkImage>& img,
103 const SkTileMode tm[2],
104 const SkMatrix& m,
105 const SkRect* subset = nullptr,
106 const SkRect* domain = nullptr) {
107 return AsFragmentProcessor(ctx, img.get(), opt, tm, m, subset, domain);
108}
109
110std::unique_ptr<GrFragmentProcessor> MakeFragmentProcessorFromView(GrRecordingContext*,
114 const SkTileMode[2],
115 const SkMatrix&,
116 const SkRect* subset,
117 const SkRect* domain);
118
119/**
120 * Returns input view if it is already mipmapped. Otherwise, attempts to make a mipmapped view
121 * with the same contents. If the mipmapped copy is successfully created it will be cached
122 * using the image unique ID. A subsequent call with the same unique ID will return the cached
123 * view if it has not been purged. The view is cached with a key domain specific to this
124 * function.
125 */
128 uint32_t imageUniqueID);
129
130/** Init based on texture formats supported by the context. */
132
133} // namespace skgpu::ganesh
134
135namespace skif {
136
137class Backend;
138
140 GrSurfaceOrigin origin,
141 const SkSurfaceProps& surfaceProps,
143
144} // namespace skif
145
146#endif
GrColorType
GrSurfaceOrigin
Definition GrTypes.h:147
SkAlphaType
Definition SkAlphaType.h:26
SkColorType
Definition SkColorType.h:19
GrImageTexGenPolicy
Definition SkGr.h:141
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
SkTileMode
Definition SkTileMode.h:13
Type::kYUV Type::kRGBA() int(0.7 *637)
T * get() const
Definition SkRefCnt.h:303
std::unique_ptr< GrFragmentProcessor > AsFragmentProcessor(GrRecordingContext *rContext, const SkImage *img, SkSamplingOptions sampling, const SkTileMode tileModes[2], const SkMatrix &m, const SkRect *subset, const SkRect *domain)
std::tuple< GrSurfaceProxyView, GrColorType > RasterAsView(GrRecordingContext *rContext, const SkImage_Raster *raster, skgpu::Mipmapped mipmapped, GrImageTexGenPolicy policy)
GrColorType ColorTypeOfLockTextureProxy(const GrCaps *caps, SkColorType sct)
GrSurfaceProxyView FindOrMakeCachedMipmappedView(GrRecordingContext *rContext, GrSurfaceProxyView view, uint32_t imageUniqueID)
GrSurfaceProxyView LockTextureProxyView(GrRecordingContext *rContext, const SkImage_Lazy *img, GrImageTexGenPolicy texGenPolicy, skgpu::Mipmapped mipmapped)
GrSurfaceProxyView CopyView(GrRecordingContext *context, GrSurfaceProxyView src, skgpu::Mipmapped mipmapped, GrImageTexGenPolicy policy, std::string_view label)
std::tuple< GrSurfaceProxyView, GrColorType > AsView(GrRecordingContext *rContext, const SkImage *img, skgpu::Mipmapped mipmapped, GrImageTexGenPolicy policy)
std::unique_ptr< GrFragmentProcessor > MakeFragmentProcessorFromView(GrRecordingContext *rContext, GrSurfaceProxyView view, SkAlphaType at, SkSamplingOptions sampling, const SkTileMode tileModes[2], const SkMatrix &m, const SkRect *subset, const SkRect *domain)
SkYUVAPixmapInfo::SupportedDataTypes SupportedTextureFormats(const GrImageContext &context)
Mipmapped
Definition GpuTypes.h:53
sk_sp< Backend > MakeGaneshBackend(sk_sp< GrRecordingContext > context, GrSurfaceOrigin origin, const SkSurfaceProps &surfaceProps, SkColorType colorType)