xref: /aosp_15_r20/external/skia/src/gpu/ganesh/image/SkImage_GaneshBase.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2018 Google Inc.
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 SkImage_GaneshBase_DEFINED
9 #define SkImage_GaneshBase_DEFINED
10 
11 #include "include/core/SkRefCnt.h"
12 #include "include/core/SkSamplingOptions.h"
13 #include "include/gpu/ganesh/GrRecordingContext.h"
14 #include "include/private/chromium/SkImageChromium.h"
15 #include "include/private/gpu/ganesh/GrImageContext.h"
16 #include "src/image/SkImage_Base.h"
17 
18 #include <memory>
19 #include <tuple>
20 #include <cstddef>
21 #include <cstdint>
22 
23 class GrBackendFormat;
24 class GrBackendTexture;
25 class GrCaps;
26 class GrContextThreadSafeProxy;
27 class GrDirectContext;
28 class GrFragmentProcessor;
29 class GrSurfaceProxyView;
30 class GrTextureProxy;
31 class SkBitmap;
32 class SkColorSpace;
33 class SkImage;
34 class SkMatrix;
35 class SkSurface;
36 enum GrSurfaceOrigin : int;
37 enum SkAlphaType : int;
38 enum SkColorType : int;
39 enum class GrColorType;
40 enum class GrImageTexGenPolicy : int;
41 enum class GrSemaphoresSubmitted : bool;
42 enum class SkTileMode;
43 struct GrFlushInfo;
44 struct SkIRect;
45 struct SkISize;
46 struct SkImageInfo;
47 struct SkRect;
48 namespace skgpu {
49 enum class Mipmapped : bool;
50 class RefCntedCallback;
51 }  // namespace skgpu
52 
53 namespace skgpu { namespace graphite { class Recorder; } }
54 
55 class SkImage_GaneshBase : public SkImage_Base {
56 public:
57     // From SkImage.h
58     bool isValid(GrRecordingContext*) const final;
59     sk_sp<SkImage> makeColorTypeAndColorSpace(GrDirectContext* dContext,
60                                               SkColorType targetColorType,
61                                               sk_sp<SkColorSpace> targetCS) const final;
62     sk_sp<SkImage> makeSubset(GrDirectContext* direct, const SkIRect& subset) const final;
63 
64     // From SkImage_Base.h
context()65     GrImageContext* context() const final { return fContext.get(); }
directContext()66     GrDirectContext* directContext() const final { return GrAsDirectContext(this->context()); }
67 
68     bool getROPixels(GrDirectContext*, SkBitmap*, CachingHint) const final;
69 
70     sk_sp<SkImage> onMakeSubset(GrDirectContext*, const SkIRect& subset) const final;
71 
72     sk_sp<SkSurface> onMakeSurface(skgpu::graphite::Recorder*, const SkImageInfo&) const override;
73 
74     bool onReadPixels(GrDirectContext* dContext,
75                       const SkImageInfo& dstInfo,
76                       void* dstPixels,
77                       size_t dstRB,
78                       int srcX,
79                       int srcY,
80                       CachingHint) const override;
81 
82     // From SkImage_GaneshBase.h
83     virtual GrSemaphoresSubmitted flush(GrDirectContext*, const GrFlushInfo&) const = 0;
84 
85     static bool ValidateBackendTexture(const GrCaps*,
86                                        const GrBackendTexture& tex,
87                                        GrColorType grCT,
88                                        SkColorType ct,
89                                        SkAlphaType at,
90                                        sk_sp<SkColorSpace> cs);
91     static bool ValidateCompressedBackendTexture(const GrCaps*,
92                                                  const GrBackendTexture& tex,
93                                                  SkAlphaType);
94 
95     // Helper for making a lazy proxy for a promise image.
96     // PromiseImageTextureFulfillProc must not be null.
97     static sk_sp<GrTextureProxy> MakePromiseImageLazyProxy(
98             GrContextThreadSafeProxy*,
99             SkISize dimensions,
100             const GrBackendFormat&,
101             skgpu::Mipmapped,
102             SkImages::PromiseImageTextureFulfillProc,
103             sk_sp<skgpu::RefCntedCallback> releaseHelper);
104 
105     virtual std::tuple<GrSurfaceProxyView, GrColorType> asView(GrRecordingContext*,
106                                                                skgpu::Mipmapped,
107                                                                GrImageTexGenPolicy) const = 0;
108 
109     virtual std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(GrRecordingContext*,
110                                                                      SkSamplingOptions,
111                                                                      const SkTileMode[2],
112                                                                      const SkMatrix&,
113                                                                      const SkRect*,
114                                                                      const SkRect*) const = 0;
115 
116     virtual GrSurfaceOrigin origin() const = 0;
117 
118 protected:
119     SkImage_GaneshBase(sk_sp<GrImageContext>, SkImageInfo, uint32_t uniqueID);
120 
121     sk_sp<SkImage> onMakeSubset(skgpu::graphite::Recorder*,
122                                 const SkIRect& subset,
123                                 RequiredProperties) const final;
124     using SkImage_Base::onMakeColorTypeAndColorSpace;
125     sk_sp<SkImage> makeColorTypeAndColorSpace(skgpu::graphite::Recorder*,
126                                               SkColorType,
127                                               sk_sp<SkColorSpace>,
128                                               RequiredProperties) const final;
129 
130     sk_sp<GrImageContext> fContext;
131 };
132 
133 #endif
134