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 // NOTE: This estimates a GPU size assuming the texture is not actually memoryless.
67 size_t ComputeSize(SkISize dimensions, const TextureInfo&);
68
69 sk_sp<Image> CopyAsDraw(Recorder*,
70 const SkImage* image,
71 const SkIRect& subset,
72 const SkColorInfo& dstColorInfo,
73 Budgeted,
74 Mipmapped,
75 SkBackingFit,
76 std::string_view label);
77
78 sk_sp<SkImage> RescaleImage(Recorder*,
79 const SkImage* srcImage,
80 SkIRect srcIRect,
81 const SkImageInfo& dstInfo,
82 SkImage::RescaleGamma rescaleGamma,
83 SkImage::RescaleMode rescaleMode);
84
85 bool GenerateMipmaps(Recorder*, sk_sp<TextureProxy>, const SkColorInfo&);
86
87 // Returns the underlying TextureProxyView if it's a non-YUVA Graphite-backed image.
88 TextureProxyView AsView(const SkImage*);
AsView(sk_sp<SkImage> image)89 inline TextureProxyView AsView(sk_sp<SkImage> image) { return AsView(image.get()); }
90
91 std::pair<sk_sp<SkImage>, SkSamplingOptions> GetGraphiteBacked(Recorder*,
92 const SkImage*,
93 SkSamplingOptions);
94
95 // Return the color format used for coverage mask textures that are rendered by a GPU
96 // compute program.
97 SkColorType ComputeShaderCoverageMaskTargetFormat(const Caps*);
98
99 } // namespace skgpu::graphite
100
101 namespace skif {
102
103 class Backend;
104
105 sk_sp<Backend> MakeGraphiteBackend(skgpu::graphite::Recorder* recorder,
106 const SkSurfaceProps&,
107 SkColorType);
108
109 } // namespace skif
110
111 #endif // skgpu_graphite_TextureUtils_DEFINED
112