1 /* 2 * Copyright 2011 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 GrAttachment_DEFINED 9 #define GrAttachment_DEFINED 10 11 #include "src/core/SkClipStack.h" 12 #include "src/gpu/ganesh/GrSurface.h" 13 14 class GrRenderTarget; 15 16 /** 17 * This is a generic attachment class for out GrSurfaces. It always represents a single gpu 18 * allocation. It contains usage flags so that we know what the attachment can be used for. 19 * 20 * TODO: Once we can pull out GrRenderTarget to be more of a framebuffer and break apart our 21 * texture render target diamond, we will merge this class with GrSurface. Until then this will 22 * act as the staging class for the new surface and framebuffer world. 23 */ 24 class GrAttachment : public GrSurface { 25 public: 26 enum class UsageFlags : uint8_t { 27 kStencilAttachment = 0x1, 28 kColorAttachment = 0x2, 29 kTexture = 0x4, 30 }; 31 GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(UsageFlags); 32 ~GrAttachment()33 ~GrAttachment() override {} 34 supportedUsages()35 UsageFlags supportedUsages() const { return fSupportedUsages; } 36 numSamples()37 int numSamples() const { return fSampleCnt; } 38 mipmapped()39 GrMipmapped mipmapped() const { return fMipmapped; } 40 hasPerformedInitialClear()41 bool hasPerformedInitialClear() const { return fHasPerformedInitialClear; } markHasPerformedInitialClear()42 void markHasPerformedInitialClear() { fHasPerformedInitialClear = true; } 43 44 // This unique key is used for attachments of the same dimensions, usage, and sample cnt which 45 // are shared between multiple render targets at the same time. Only one usage flag may be 46 // passed in. 47 // TODO: Once attachments start having multiple usages, we'll need to figure out how to search 48 // the cache for an attachment that simply contains the requested usage instead of equaling it. 49 static void ComputeSharedAttachmentUniqueKey(const GrCaps& caps, 50 const GrBackendFormat& format, 51 SkISize dimensions, 52 UsageFlags requiredUsage, 53 int sampleCnt, 54 GrMipmapped mipmapped, 55 GrProtected isProtected, 56 GrMemoryless memoryless, 57 skgpu::UniqueKey* key); 58 59 // TODO: Once attachments start having multiple usages, we'll need to figure out how to search 60 // the cache for an attachment that simply contains the requested usage instead of equaling it. 61 static void ComputeScratchKey(const GrCaps& caps, 62 const GrBackendFormat& format, 63 SkISize dimensions, 64 UsageFlags requiredUsage, 65 int sampleCnt, 66 GrMipmapped mipmapped, 67 GrProtected, 68 GrMemoryless, 69 skgpu::ScratchKey* key); 70 71 protected: 72 GrAttachment(GrGpu* gpu, SkISize dimensions, UsageFlags supportedUsages, int sampleCnt, 73 GrMipmapped mipmapped, GrProtected isProtected, std::string_view label, 74 GrMemoryless memoryless = GrMemoryless::kNo) INHERITED(gpu,dimensions,isProtected,label)75 : INHERITED(gpu, dimensions, isProtected, label) 76 , fSupportedUsages(supportedUsages) 77 , fSampleCnt(sampleCnt) 78 , fMipmapped(mipmapped) 79 , fMemoryless(memoryless) {} 80 81 private: 82 size_t onGpuMemorySize() const final; 83 onSetLabel()84 void onSetLabel() override{} 85 86 void computeScratchKey(skgpu::ScratchKey*) const final; 87 getResourceType()88 const char* getResourceType() const override { 89 if (fSupportedUsages == UsageFlags::kStencilAttachment) { 90 return "StencilAttachment"; 91 } 92 93 // This is a general grouping of all textures and color attachments. 94 return "Surface"; 95 } 96 97 UsageFlags fSupportedUsages; 98 int fSampleCnt; 99 GrMipmapped fMipmapped; 100 bool fHasPerformedInitialClear = false; 101 GrMemoryless fMemoryless; 102 103 using INHERITED = GrSurface; 104 }; 105 106 GR_MAKE_BITFIELD_CLASS_OPS(GrAttachment::UsageFlags) 107 108 #endif 109