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