• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/GrSurface.h"
13 
14 class GrRenderTarget;
15 class GrResourceKey;
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     GrMipmapped 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                                                  GrMipmapped mipmapped,
56                                                  GrProtected isProtected,
57                                                  GrUniqueKey* 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                                   GrScratchKey* key);
69 
70 protected:
GrAttachment(GrGpu * gpu,SkISize dimensions,UsageFlags supportedUsages,int sampleCnt,GrMipmapped mipmapped,GrProtected isProtected)71     GrAttachment(GrGpu* gpu, SkISize dimensions, UsageFlags supportedUsages, int sampleCnt,
72                  GrMipmapped mipmapped, GrProtected isProtected)
73             : INHERITED(gpu, dimensions, isProtected)
74             , fSupportedUsages(supportedUsages)
75             , fSampleCnt(sampleCnt)
76             , fMipmapped(mipmapped) {}
77 
78 private:
79     size_t onGpuMemorySize() const final;
80 
81     void computeScratchKey(GrScratchKey*) const final;
82 
getResourceType()83     const char* getResourceType() const override {
84         if (fSupportedUsages == UsageFlags::kStencilAttachment) {
85             return "StencilAttachment";
86         }
87 
88         // This is a general grouping of all textures and color attachments.
89         return "Surface";
90     }
91 
92     UsageFlags fSupportedUsages;
93     int fSampleCnt;
94     GrMipmapped fMipmapped;
95     bool fHasPerformedInitialClear = false;
96 
97     using INHERITED = GrSurface;
98 };
99 
100 GR_MAKE_BITFIELD_CLASS_OPS(GrAttachment::UsageFlags);
101 
102 #endif
103