1 /*
2 * Copyright 2022 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 skgpu_graphite_TextureUtils_DEFINED
9 #define skgpu_graphite_TextureUtils_DEFINED
10
11 #include "include/core/SkImage.h"
12 #include "include/core/SkRefCnt.h"
13 #include "include/gpu/GpuTypes.h"
14 #include "include/gpu/graphite/Image.h"
15 #include "src/gpu/graphite/TextureProxyView.h"
16
17 #include <functional>
18 #include <tuple>
19 #include <utility>
20
21 class SkBitmap;
22 enum SkColorType : int;
23 class SkImage;
24 struct SkImageInfo;
25 struct SkSamplingOptions;
26
27 namespace skgpu {
28 class RefCntedCallback;
29 }
30
31 namespace skgpu::graphite {
32
33 class Caps;
34 class Context;
35 class Image;
36 class Recorder;
37 class TextureProxyView;
38
39 // Create TextureProxyView and SkColorType pair using pixel data in SkBitmap,
40 // adding any necessary copy commands to Recorder
41 std::tuple<TextureProxyView, SkColorType> MakeBitmapProxyView(Recorder*,
42 const SkBitmap&,
43 sk_sp<SkMipmap>,
44 Mipmapped,
45 skgpu::Budgeted,
46 std::string_view label);
47
48 sk_sp<TextureProxy> MakePromiseImageLazyProxy(const Caps*,
49 SkISize dimensions,
50 TextureInfo,
51 Volatile,
52 sk_sp<skgpu::RefCntedCallback> releaseHelper,
53 SkImages::GraphitePromiseTextureFulfillProc,
54 SkImages::GraphitePromiseTextureFulfillContext,
55 SkImages::GraphitePromiseTextureReleaseProc,
56 std::string_view label);
57
58 sk_sp<SkImage> MakeFromBitmap(Recorder*,
59 const SkColorInfo&,
60 const SkBitmap&,
61 sk_sp<SkMipmap>,
62 skgpu::Budgeted,
63 SkImage::RequiredProperties,
64 std::string_view label);
65
66 size_t ComputeSize(SkISize dimensions, const TextureInfo&);
67
68 sk_sp<Image> CopyAsDraw(Recorder*,
69 const SkImage* image,
70 const SkIRect& subset,
71 const SkColorInfo& dstColorInfo,
72 Budgeted,
73 Mipmapped,
74 SkBackingFit,
75 std::string_view label);
76
77 sk_sp<SkImage> RescaleImage(Recorder*,
78 const SkImage* srcImage,
79 SkIRect srcIRect,
80 const SkImageInfo& dstInfo,
81 SkImage::RescaleGamma rescaleGamma,
82 SkImage::RescaleMode rescaleMode);
83
84 bool GenerateMipmaps(Recorder*, sk_sp<TextureProxy>, const SkColorInfo&);
85
86 // Returns the underlying TextureProxyView if it's a non-YUVA Graphite-backed image.
87 TextureProxyView AsView(const SkImage*);
AsView(sk_sp<SkImage> image)88 inline TextureProxyView AsView(sk_sp<SkImage> image) { return AsView(image.get()); }
89
90 std::pair<sk_sp<SkImage>, SkSamplingOptions> GetGraphiteBacked(Recorder*,
91 const SkImage*,
92 SkSamplingOptions);
93
94 // Return the color format used for coverage mask textures that are rendered by a GPU
95 // compute program.
96 SkColorType ComputeShaderCoverageMaskTargetFormat(const Caps*);
97
98 } // namespace skgpu::graphite
99
100 namespace skif {
101
102 class Backend;
103
104 sk_sp<Backend> MakeGraphiteBackend(skgpu::graphite::Recorder* recorder,
105 const SkSurfaceProps&,
106 SkColorType);
107
108 } // namespace skif
109
110 #endif // skgpu_graphite_TextureUtils_DEFINED
111