• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/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 enum GrSurfaceOrigin : int;
36 enum SkAlphaType : int;
37 enum SkColorType : int;
38 enum class GrColorType;
39 enum class GrImageTexGenPolicy : int;
40 enum class GrSemaphoresSubmitted : bool;
41 enum class SkTileMode;
42 struct GrFlushInfo;
43 struct SkIRect;
44 struct SkISize;
45 struct SkImageInfo;
46 struct SkRect;
47 namespace skgpu {
48 enum class Mipmapped : bool;
49 class RefCntedCallback;
50 }  // namespace skgpu
51 
52 namespace skgpu { namespace graphite { class Recorder; } }
53 
54 class SkImage_GaneshBase : public SkImage_Base {
55 public:
56     // From SkImage.h
57     bool isValid(GrRecordingContext*) const final;
58     sk_sp<SkImage> makeColorTypeAndColorSpace(GrDirectContext* dContext,
59                                               SkColorType targetColorType,
60                                               sk_sp<SkColorSpace> targetCS) const final;
61     sk_sp<SkImage> makeSubset(GrDirectContext* direct, const SkIRect& subset) const final;
62 
63     // From SkImage_Base.h
context()64     GrImageContext* context() const final { return fContext.get(); }
directContext()65     GrDirectContext* directContext() const final { return GrAsDirectContext(this->context()); }
66 
67     bool getROPixels(GrDirectContext*, SkBitmap*, CachingHint) const final;
68 
69     sk_sp<SkImage> onMakeSubset(GrDirectContext*, const SkIRect& subset) const final;
70 
71     bool onReadPixels(GrDirectContext* dContext,
72                       const SkImageInfo& dstInfo,
73                       void* dstPixels,
74                       size_t dstRB,
75                       int srcX,
76                       int srcY,
77                       CachingHint) const override;
78 
79     // From SkImage_GaneshBase.h
80     virtual GrSemaphoresSubmitted flush(GrDirectContext*, const GrFlushInfo&) const = 0;
81 
82     static bool ValidateBackendTexture(const GrCaps*,
83                                        const GrBackendTexture& tex,
84                                        GrColorType grCT,
85                                        SkColorType ct,
86                                        SkAlphaType at,
87                                        sk_sp<SkColorSpace> cs);
88     static bool ValidateCompressedBackendTexture(const GrCaps*,
89                                                  const GrBackendTexture& tex,
90                                                  SkAlphaType);
91 
92     // Helper for making a lazy proxy for a promise image.
93     // PromiseImageTextureFulfillProc must not be null.
94     static sk_sp<GrTextureProxy> MakePromiseImageLazyProxy(
95             GrContextThreadSafeProxy*,
96             SkISize dimensions,
97             const GrBackendFormat&,
98             skgpu::Mipmapped,
99             SkImages::PromiseImageTextureFulfillProc,
100             sk_sp<skgpu::RefCntedCallback> releaseHelper);
101 
102     virtual std::tuple<GrSurfaceProxyView, GrColorType> asView(GrRecordingContext*,
103                                                                skgpu::Mipmapped,
104                                                                GrImageTexGenPolicy) const = 0;
105 
106     virtual std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(GrRecordingContext*,
107                                                                      SkSamplingOptions,
108                                                                      const SkTileMode[2],
109                                                                      const SkMatrix&,
110                                                                      const SkRect*,
111                                                                      const SkRect*) const = 0;
112 
113     virtual GrSurfaceOrigin origin() const = 0;
114 
115 protected:
116     SkImage_GaneshBase(sk_sp<GrImageContext>, SkImageInfo, uint32_t uniqueID);
117 
118     sk_sp<SkImage> onMakeSubset(skgpu::graphite::Recorder*,
119                                 const SkIRect& subset,
120                                 RequiredProperties) const final;
121     using SkImage_Base::onMakeColorTypeAndColorSpace;
122     sk_sp<SkImage> makeColorTypeAndColorSpace(skgpu::graphite::Recorder*,
123                                               SkColorType,
124                                               sk_sp<SkColorSpace>,
125                                               RequiredProperties) const final;
126 
127     sk_sp<GrImageContext> fContext;
128 };
129 
130 #endif
131