xref: /aosp_15_r20/external/skia/include/private/chromium/GrSurfaceCharacterization.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1*c8dee2aaSAndroid Build Coastguard Worker /*
2*c8dee2aaSAndroid Build Coastguard Worker  * Copyright 2023 Google LLC
3*c8dee2aaSAndroid Build Coastguard Worker  *
4*c8dee2aaSAndroid Build Coastguard Worker  * Use of this source code is governed by a BSD-style license that can be
5*c8dee2aaSAndroid Build Coastguard Worker  * found in the LICENSE file.
6*c8dee2aaSAndroid Build Coastguard Worker  */
7*c8dee2aaSAndroid Build Coastguard Worker 
8*c8dee2aaSAndroid Build Coastguard Worker #ifndef GrSurfaceCharacterization_DEFINED
9*c8dee2aaSAndroid Build Coastguard Worker #define GrSurfaceCharacterization_DEFINED
10*c8dee2aaSAndroid Build Coastguard Worker 
11*c8dee2aaSAndroid Build Coastguard Worker #include "include/core/SkColorSpace.h" // IWYU pragma: keep
12*c8dee2aaSAndroid Build Coastguard Worker #include "include/core/SkColorType.h"
13*c8dee2aaSAndroid Build Coastguard Worker #include "include/core/SkImageInfo.h"
14*c8dee2aaSAndroid Build Coastguard Worker #include "include/core/SkRefCnt.h"
15*c8dee2aaSAndroid Build Coastguard Worker #include "include/core/SkSize.h"
16*c8dee2aaSAndroid Build Coastguard Worker #include "include/core/SkSurfaceProps.h"
17*c8dee2aaSAndroid Build Coastguard Worker #include "include/core/SkTypes.h"
18*c8dee2aaSAndroid Build Coastguard Worker #include "include/gpu/GpuTypes.h"
19*c8dee2aaSAndroid Build Coastguard Worker #include "include/gpu/ganesh/GrBackendSurface.h"
20*c8dee2aaSAndroid Build Coastguard Worker #include "include/gpu/ganesh/GrContextThreadSafeProxy.h"
21*c8dee2aaSAndroid Build Coastguard Worker #include "include/gpu/ganesh/GrTypes.h"
22*c8dee2aaSAndroid Build Coastguard Worker #include "include/private/base/SkDebug.h"
23*c8dee2aaSAndroid Build Coastguard Worker 
24*c8dee2aaSAndroid Build Coastguard Worker #include <cstddef>
25*c8dee2aaSAndroid Build Coastguard Worker #include <utility>
26*c8dee2aaSAndroid Build Coastguard Worker 
27*c8dee2aaSAndroid Build Coastguard Worker /** \class GrSurfaceCharacterization
28*c8dee2aaSAndroid Build Coastguard Worker     A surface characterization contains all the information Ganesh requires to makes its internal
29*c8dee2aaSAndroid Build Coastguard Worker     rendering decisions. When passed into a GrDeferredDisplayListRecorder it will copy the
30*c8dee2aaSAndroid Build Coastguard Worker     data and pass it on to the GrDeferredDisplayList if/when it is created. Note that both of
31*c8dee2aaSAndroid Build Coastguard Worker     those objects (the Recorder and the DisplayList) will take a ref on the
32*c8dee2aaSAndroid Build Coastguard Worker     GrContextThreadSafeProxy and SkColorSpace objects.
33*c8dee2aaSAndroid Build Coastguard Worker */
34*c8dee2aaSAndroid Build Coastguard Worker class SK_API GrSurfaceCharacterization {
35*c8dee2aaSAndroid Build Coastguard Worker public:
36*c8dee2aaSAndroid Build Coastguard Worker     enum class Textureable : bool { kNo = false, kYes = true };
37*c8dee2aaSAndroid Build Coastguard Worker     enum class UsesGLFBO0 : bool { kNo = false, kYes = true };
38*c8dee2aaSAndroid Build Coastguard Worker     // This flag indicates that the backing VkImage for this Vulkan surface will have the
39*c8dee2aaSAndroid Build Coastguard Worker     // VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set. This bit allows skia to handle advanced blends
40*c8dee2aaSAndroid Build Coastguard Worker     // more optimally in a shader by being able to directly read the dst values.
41*c8dee2aaSAndroid Build Coastguard Worker     enum class VkRTSupportsInputAttachment : bool { kNo = false, kYes = true };
42*c8dee2aaSAndroid Build Coastguard Worker     // This flag indicates if the surface is wrapping a raw Vulkan secondary command buffer.
43*c8dee2aaSAndroid Build Coastguard Worker     enum class VulkanSecondaryCBCompatible : bool { kNo = false, kYes = true };
44*c8dee2aaSAndroid Build Coastguard Worker 
GrSurfaceCharacterization()45*c8dee2aaSAndroid Build Coastguard Worker     GrSurfaceCharacterization()
46*c8dee2aaSAndroid Build Coastguard Worker             : fCacheMaxResourceBytes(0)
47*c8dee2aaSAndroid Build Coastguard Worker             , fOrigin(kBottomLeft_GrSurfaceOrigin)
48*c8dee2aaSAndroid Build Coastguard Worker             , fSampleCnt(0)
49*c8dee2aaSAndroid Build Coastguard Worker             , fIsTextureable(Textureable::kYes)
50*c8dee2aaSAndroid Build Coastguard Worker             , fIsMipmapped(skgpu::Mipmapped::kYes)
51*c8dee2aaSAndroid Build Coastguard Worker             , fUsesGLFBO0(UsesGLFBO0::kNo)
52*c8dee2aaSAndroid Build Coastguard Worker             , fVulkanSecondaryCBCompatible(VulkanSecondaryCBCompatible::kNo)
53*c8dee2aaSAndroid Build Coastguard Worker             , fIsProtected(skgpu::Protected::kNo)
54*c8dee2aaSAndroid Build Coastguard Worker             , fSurfaceProps() {}
55*c8dee2aaSAndroid Build Coastguard Worker 
56*c8dee2aaSAndroid Build Coastguard Worker     GrSurfaceCharacterization(GrSurfaceCharacterization&&) = default;
57*c8dee2aaSAndroid Build Coastguard Worker     GrSurfaceCharacterization& operator=(GrSurfaceCharacterization&&) = default;
58*c8dee2aaSAndroid Build Coastguard Worker 
59*c8dee2aaSAndroid Build Coastguard Worker     GrSurfaceCharacterization(const GrSurfaceCharacterization&) = default;
60*c8dee2aaSAndroid Build Coastguard Worker     GrSurfaceCharacterization& operator=(const GrSurfaceCharacterization& other) = default;
61*c8dee2aaSAndroid Build Coastguard Worker     bool operator==(const GrSurfaceCharacterization& other) const;
62*c8dee2aaSAndroid Build Coastguard Worker     bool operator!=(const GrSurfaceCharacterization& other) const {
63*c8dee2aaSAndroid Build Coastguard Worker         return !(*this == other);
64*c8dee2aaSAndroid Build Coastguard Worker     }
65*c8dee2aaSAndroid Build Coastguard Worker 
66*c8dee2aaSAndroid Build Coastguard Worker     /*
67*c8dee2aaSAndroid Build Coastguard Worker      * Return a new surface characterization with the only difference being a different width
68*c8dee2aaSAndroid Build Coastguard Worker      * and height
69*c8dee2aaSAndroid Build Coastguard Worker      */
70*c8dee2aaSAndroid Build Coastguard Worker     GrSurfaceCharacterization createResized(int width, int height) const;
71*c8dee2aaSAndroid Build Coastguard Worker 
72*c8dee2aaSAndroid Build Coastguard Worker     /*
73*c8dee2aaSAndroid Build Coastguard Worker      * Return a new surface characterization with only a replaced color space
74*c8dee2aaSAndroid Build Coastguard Worker      */
75*c8dee2aaSAndroid Build Coastguard Worker     GrSurfaceCharacterization createColorSpace(sk_sp<SkColorSpace>) const;
76*c8dee2aaSAndroid Build Coastguard Worker 
77*c8dee2aaSAndroid Build Coastguard Worker     /*
78*c8dee2aaSAndroid Build Coastguard Worker      * Return a new surface characterization with the backend format replaced. A colorType
79*c8dee2aaSAndroid Build Coastguard Worker      * must also be supplied to indicate the interpretation of the new format.
80*c8dee2aaSAndroid Build Coastguard Worker      */
81*c8dee2aaSAndroid Build Coastguard Worker     GrSurfaceCharacterization createBackendFormat(SkColorType colorType,
82*c8dee2aaSAndroid Build Coastguard Worker                                                   const GrBackendFormat& backendFormat) const;
83*c8dee2aaSAndroid Build Coastguard Worker 
84*c8dee2aaSAndroid Build Coastguard Worker     /*
85*c8dee2aaSAndroid Build Coastguard Worker      * Return a new surface characterization with just a different use of FBO0 (in GL)
86*c8dee2aaSAndroid Build Coastguard Worker      */
87*c8dee2aaSAndroid Build Coastguard Worker     GrSurfaceCharacterization createFBO0(bool usesGLFBO0) const;
88*c8dee2aaSAndroid Build Coastguard Worker 
contextInfo()89*c8dee2aaSAndroid Build Coastguard Worker     GrContextThreadSafeProxy* contextInfo() const { return fContextInfo.get(); }
refContextInfo()90*c8dee2aaSAndroid Build Coastguard Worker     sk_sp<GrContextThreadSafeProxy> refContextInfo() const { return fContextInfo; }
cacheMaxResourceBytes()91*c8dee2aaSAndroid Build Coastguard Worker     size_t cacheMaxResourceBytes() const { return fCacheMaxResourceBytes; }
92*c8dee2aaSAndroid Build Coastguard Worker 
isValid()93*c8dee2aaSAndroid Build Coastguard Worker     bool isValid() const { return kUnknown_SkColorType != fImageInfo.colorType(); }
94*c8dee2aaSAndroid Build Coastguard Worker 
imageInfo()95*c8dee2aaSAndroid Build Coastguard Worker     const SkImageInfo& imageInfo() const { return fImageInfo; }
backendFormat()96*c8dee2aaSAndroid Build Coastguard Worker     const GrBackendFormat& backendFormat() const { return fBackendFormat; }
origin()97*c8dee2aaSAndroid Build Coastguard Worker     GrSurfaceOrigin origin() const { return fOrigin; }
dimensions()98*c8dee2aaSAndroid Build Coastguard Worker     SkISize dimensions() const { return fImageInfo.dimensions(); }
width()99*c8dee2aaSAndroid Build Coastguard Worker     int width() const { return fImageInfo.width(); }
height()100*c8dee2aaSAndroid Build Coastguard Worker     int height() const { return fImageInfo.height(); }
colorType()101*c8dee2aaSAndroid Build Coastguard Worker     SkColorType colorType() const { return fImageInfo.colorType(); }
sampleCount()102*c8dee2aaSAndroid Build Coastguard Worker     int sampleCount() const { return fSampleCnt; }
isTextureable()103*c8dee2aaSAndroid Build Coastguard Worker     bool isTextureable() const { return Textureable::kYes == fIsTextureable; }
isMipMapped()104*c8dee2aaSAndroid Build Coastguard Worker     bool isMipMapped() const { return skgpu::Mipmapped::kYes == fIsMipmapped; }
usesGLFBO0()105*c8dee2aaSAndroid Build Coastguard Worker     bool usesGLFBO0() const { return UsesGLFBO0::kYes == fUsesGLFBO0; }
vkRTSupportsInputAttachment()106*c8dee2aaSAndroid Build Coastguard Worker     bool vkRTSupportsInputAttachment() const {
107*c8dee2aaSAndroid Build Coastguard Worker         return VkRTSupportsInputAttachment::kYes == fVkRTSupportsInputAttachment;
108*c8dee2aaSAndroid Build Coastguard Worker     }
vulkanSecondaryCBCompatible()109*c8dee2aaSAndroid Build Coastguard Worker     bool vulkanSecondaryCBCompatible() const {
110*c8dee2aaSAndroid Build Coastguard Worker         return VulkanSecondaryCBCompatible::kYes == fVulkanSecondaryCBCompatible;
111*c8dee2aaSAndroid Build Coastguard Worker     }
isProtected()112*c8dee2aaSAndroid Build Coastguard Worker     skgpu::Protected isProtected() const { return fIsProtected; }
colorSpace()113*c8dee2aaSAndroid Build Coastguard Worker     SkColorSpace* colorSpace() const { return fImageInfo.colorSpace(); }
refColorSpace()114*c8dee2aaSAndroid Build Coastguard Worker     sk_sp<SkColorSpace> refColorSpace() const { return fImageInfo.refColorSpace(); }
surfaceProps()115*c8dee2aaSAndroid Build Coastguard Worker     const SkSurfaceProps& surfaceProps()const { return fSurfaceProps; }
116*c8dee2aaSAndroid Build Coastguard Worker 
117*c8dee2aaSAndroid Build Coastguard Worker private:
118*c8dee2aaSAndroid Build Coastguard Worker     friend class SkSurface_Ganesh;           // for 'set' & 'config'
119*c8dee2aaSAndroid Build Coastguard Worker     friend class GrVkSecondaryCBDrawContext; // for 'set' & 'config'
120*c8dee2aaSAndroid Build Coastguard Worker     friend class GrContextThreadSafeProxy; // for private ctor
121*c8dee2aaSAndroid Build Coastguard Worker     friend class GrVkContextThreadSafeProxy;    // for private ctor
122*c8dee2aaSAndroid Build Coastguard Worker     friend class GrDeferredDisplayListRecorder; // for 'config'
123*c8dee2aaSAndroid Build Coastguard Worker     friend class SkSurface; // for 'config'
124*c8dee2aaSAndroid Build Coastguard Worker 
125*c8dee2aaSAndroid Build Coastguard Worker     SkDEBUGCODE(void validate() const;)
126*c8dee2aaSAndroid Build Coastguard Worker 
GrSurfaceCharacterization(sk_sp<GrContextThreadSafeProxy> contextInfo,size_t cacheMaxResourceBytes,const SkImageInfo & ii,const GrBackendFormat & backendFormat,GrSurfaceOrigin origin,int sampleCnt,Textureable isTextureable,skgpu::Mipmapped isMipmapped,UsesGLFBO0 usesGLFBO0,VkRTSupportsInputAttachment vkRTSupportsInputAttachment,VulkanSecondaryCBCompatible vulkanSecondaryCBCompatible,skgpu::Protected isProtected,const SkSurfaceProps & surfaceProps)127*c8dee2aaSAndroid Build Coastguard Worker             GrSurfaceCharacterization(sk_sp<GrContextThreadSafeProxy> contextInfo,
128*c8dee2aaSAndroid Build Coastguard Worker                                       size_t cacheMaxResourceBytes,
129*c8dee2aaSAndroid Build Coastguard Worker                                       const SkImageInfo& ii,
130*c8dee2aaSAndroid Build Coastguard Worker                                       const GrBackendFormat& backendFormat,
131*c8dee2aaSAndroid Build Coastguard Worker                                       GrSurfaceOrigin origin,
132*c8dee2aaSAndroid Build Coastguard Worker                                       int sampleCnt,
133*c8dee2aaSAndroid Build Coastguard Worker                                       Textureable isTextureable,
134*c8dee2aaSAndroid Build Coastguard Worker                                       skgpu::Mipmapped isMipmapped,
135*c8dee2aaSAndroid Build Coastguard Worker                                       UsesGLFBO0 usesGLFBO0,
136*c8dee2aaSAndroid Build Coastguard Worker                                       VkRTSupportsInputAttachment vkRTSupportsInputAttachment,
137*c8dee2aaSAndroid Build Coastguard Worker                                       VulkanSecondaryCBCompatible vulkanSecondaryCBCompatible,
138*c8dee2aaSAndroid Build Coastguard Worker                                       skgpu::Protected isProtected,
139*c8dee2aaSAndroid Build Coastguard Worker                                       const SkSurfaceProps& surfaceProps)
140*c8dee2aaSAndroid Build Coastguard Worker             : fContextInfo(std::move(contextInfo))
141*c8dee2aaSAndroid Build Coastguard Worker             , fCacheMaxResourceBytes(cacheMaxResourceBytes)
142*c8dee2aaSAndroid Build Coastguard Worker             , fImageInfo(ii)
143*c8dee2aaSAndroid Build Coastguard Worker             , fBackendFormat(std::move(backendFormat))
144*c8dee2aaSAndroid Build Coastguard Worker             , fOrigin(origin)
145*c8dee2aaSAndroid Build Coastguard Worker             , fSampleCnt(sampleCnt)
146*c8dee2aaSAndroid Build Coastguard Worker             , fIsTextureable(isTextureable)
147*c8dee2aaSAndroid Build Coastguard Worker             , fIsMipmapped(isMipmapped)
148*c8dee2aaSAndroid Build Coastguard Worker             , fUsesGLFBO0(usesGLFBO0)
149*c8dee2aaSAndroid Build Coastguard Worker             , fVkRTSupportsInputAttachment(vkRTSupportsInputAttachment)
150*c8dee2aaSAndroid Build Coastguard Worker             , fVulkanSecondaryCBCompatible(vulkanSecondaryCBCompatible)
151*c8dee2aaSAndroid Build Coastguard Worker             , fIsProtected(isProtected)
152*c8dee2aaSAndroid Build Coastguard Worker             , fSurfaceProps(surfaceProps) {
153*c8dee2aaSAndroid Build Coastguard Worker         if (fSurfaceProps.flags() & SkSurfaceProps::kDynamicMSAA_Flag) {
154*c8dee2aaSAndroid Build Coastguard Worker             // Dynamic MSAA is not currently supported with DDL.
155*c8dee2aaSAndroid Build Coastguard Worker             *this = {};
156*c8dee2aaSAndroid Build Coastguard Worker         }
157*c8dee2aaSAndroid Build Coastguard Worker         SkDEBUGCODE(this->validate());
158*c8dee2aaSAndroid Build Coastguard Worker     }
159*c8dee2aaSAndroid Build Coastguard Worker 
set(sk_sp<GrContextThreadSafeProxy> contextInfo,size_t cacheMaxResourceBytes,const SkImageInfo & ii,const GrBackendFormat & backendFormat,GrSurfaceOrigin origin,int sampleCnt,Textureable isTextureable,skgpu::Mipmapped isMipmapped,UsesGLFBO0 usesGLFBO0,VkRTSupportsInputAttachment vkRTSupportsInputAttachment,VulkanSecondaryCBCompatible vulkanSecondaryCBCompatible,skgpu::Protected isProtected,const SkSurfaceProps & surfaceProps)160*c8dee2aaSAndroid Build Coastguard Worker     void set(sk_sp<GrContextThreadSafeProxy> contextInfo,
161*c8dee2aaSAndroid Build Coastguard Worker              size_t cacheMaxResourceBytes,
162*c8dee2aaSAndroid Build Coastguard Worker              const SkImageInfo& ii,
163*c8dee2aaSAndroid Build Coastguard Worker              const GrBackendFormat& backendFormat,
164*c8dee2aaSAndroid Build Coastguard Worker              GrSurfaceOrigin origin,
165*c8dee2aaSAndroid Build Coastguard Worker              int sampleCnt,
166*c8dee2aaSAndroid Build Coastguard Worker              Textureable isTextureable,
167*c8dee2aaSAndroid Build Coastguard Worker              skgpu::Mipmapped isMipmapped,
168*c8dee2aaSAndroid Build Coastguard Worker              UsesGLFBO0 usesGLFBO0,
169*c8dee2aaSAndroid Build Coastguard Worker              VkRTSupportsInputAttachment vkRTSupportsInputAttachment,
170*c8dee2aaSAndroid Build Coastguard Worker              VulkanSecondaryCBCompatible vulkanSecondaryCBCompatible,
171*c8dee2aaSAndroid Build Coastguard Worker              skgpu::Protected isProtected,
172*c8dee2aaSAndroid Build Coastguard Worker              const SkSurfaceProps& surfaceProps) {
173*c8dee2aaSAndroid Build Coastguard Worker         if (surfaceProps.flags() & SkSurfaceProps::kDynamicMSAA_Flag) {
174*c8dee2aaSAndroid Build Coastguard Worker             // Dynamic MSAA is not currently supported with DDL.
175*c8dee2aaSAndroid Build Coastguard Worker             *this = {};
176*c8dee2aaSAndroid Build Coastguard Worker         } else {
177*c8dee2aaSAndroid Build Coastguard Worker             fContextInfo = std::move(contextInfo);
178*c8dee2aaSAndroid Build Coastguard Worker             fCacheMaxResourceBytes = cacheMaxResourceBytes;
179*c8dee2aaSAndroid Build Coastguard Worker 
180*c8dee2aaSAndroid Build Coastguard Worker             fImageInfo = ii;
181*c8dee2aaSAndroid Build Coastguard Worker             fBackendFormat = std::move(backendFormat);
182*c8dee2aaSAndroid Build Coastguard Worker             fOrigin = origin;
183*c8dee2aaSAndroid Build Coastguard Worker             fSampleCnt = sampleCnt;
184*c8dee2aaSAndroid Build Coastguard Worker             fIsTextureable = isTextureable;
185*c8dee2aaSAndroid Build Coastguard Worker             fIsMipmapped = isMipmapped;
186*c8dee2aaSAndroid Build Coastguard Worker             fUsesGLFBO0 = usesGLFBO0;
187*c8dee2aaSAndroid Build Coastguard Worker             fVkRTSupportsInputAttachment = vkRTSupportsInputAttachment;
188*c8dee2aaSAndroid Build Coastguard Worker             fVulkanSecondaryCBCompatible = vulkanSecondaryCBCompatible;
189*c8dee2aaSAndroid Build Coastguard Worker             fIsProtected = isProtected;
190*c8dee2aaSAndroid Build Coastguard Worker             fSurfaceProps = surfaceProps;
191*c8dee2aaSAndroid Build Coastguard Worker         }
192*c8dee2aaSAndroid Build Coastguard Worker         SkDEBUGCODE(this->validate());
193*c8dee2aaSAndroid Build Coastguard Worker     }
194*c8dee2aaSAndroid Build Coastguard Worker 
195*c8dee2aaSAndroid Build Coastguard Worker     sk_sp<GrContextThreadSafeProxy> fContextInfo;
196*c8dee2aaSAndroid Build Coastguard Worker     size_t                          fCacheMaxResourceBytes;
197*c8dee2aaSAndroid Build Coastguard Worker 
198*c8dee2aaSAndroid Build Coastguard Worker     SkImageInfo                     fImageInfo;
199*c8dee2aaSAndroid Build Coastguard Worker     GrBackendFormat                 fBackendFormat;
200*c8dee2aaSAndroid Build Coastguard Worker     GrSurfaceOrigin                 fOrigin;
201*c8dee2aaSAndroid Build Coastguard Worker     int                             fSampleCnt;
202*c8dee2aaSAndroid Build Coastguard Worker     Textureable                     fIsTextureable;
203*c8dee2aaSAndroid Build Coastguard Worker     skgpu::Mipmapped                fIsMipmapped;
204*c8dee2aaSAndroid Build Coastguard Worker     UsesGLFBO0                      fUsesGLFBO0;
205*c8dee2aaSAndroid Build Coastguard Worker     VkRTSupportsInputAttachment     fVkRTSupportsInputAttachment;
206*c8dee2aaSAndroid Build Coastguard Worker     VulkanSecondaryCBCompatible     fVulkanSecondaryCBCompatible;
207*c8dee2aaSAndroid Build Coastguard Worker     skgpu::Protected                fIsProtected;
208*c8dee2aaSAndroid Build Coastguard Worker     SkSurfaceProps                  fSurfaceProps;
209*c8dee2aaSAndroid Build Coastguard Worker };
210*c8dee2aaSAndroid Build Coastguard Worker 
211*c8dee2aaSAndroid Build Coastguard Worker #endif
212