• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2015 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 
9 #ifndef GrVkRenderTarget_DEFINED
10 #define GrVkRenderTarget_DEFINED
11 
12 #include "GrVkImage.h"
13 #include "GrRenderTarget.h"
14 
15 #include "GrVkRenderPass.h"
16 #include "GrVkResourceProvider.h"
17 
18 class GrVkCommandBuffer;
19 class GrVkFramebuffer;
20 class GrVkGpu;
21 class GrVkImageView;
22 class GrVkStencilAttachment;
23 
24 struct GrVkImageInfo;
25 
26 #ifdef SK_BUILD_FOR_WIN
27 // Windows gives bogus warnings about inheriting asTexture/asRenderTarget via dominance.
28 #pragma warning(push)
29 #pragma warning(disable: 4250)
30 #endif
31 
32 class GrVkRenderTarget: public GrRenderTarget, public virtual GrVkImage {
33 public:
34     static GrVkRenderTarget* CreateNewRenderTarget(GrVkGpu*, SkBudgeted, const GrSurfaceDesc&,
35                                                    const GrVkImage::ImageDesc&);
36 
37     static sk_sp<GrVkRenderTarget> MakeWrappedRenderTarget(GrVkGpu*, const GrSurfaceDesc&,
38                                                            const GrVkImageInfo*);
39 
40     ~GrVkRenderTarget() override;
41 
framebuffer()42     const GrVkFramebuffer* framebuffer() const { return fFramebuffer; }
colorAttachmentView()43     const GrVkImageView* colorAttachmentView() const { return fColorAttachmentView; }
msaaImageResource()44     const GrVkResource* msaaImageResource() const {
45         if (fMSAAImage) {
46             return fMSAAImage->fResource;
47         }
48         return nullptr;
49     }
msaaImage()50     GrVkImage* msaaImage() { return fMSAAImage.get(); }
resolveAttachmentView()51     const GrVkImageView* resolveAttachmentView() const { return fResolveAttachmentView; }
52     const GrVkResource* stencilImageResource() const;
53     const GrVkImageView* stencilAttachmentView() const;
54 
simpleRenderPass()55     const GrVkRenderPass* simpleRenderPass() const { return fCachedSimpleRenderPass; }
compatibleRenderPassHandle()56     GrVkResourceProvider::CompatibleRPHandle compatibleRenderPassHandle() const {
57         return fCompatibleRPHandle;
58     }
59 
60     // override of GrRenderTarget
getResolveType()61     ResolveType getResolveType() const override {
62         if (this->numColorSamples() > 1) {
63             return kCanResolve_ResolveType;
64         }
65         return kAutoResolves_ResolveType;
66     }
67 
canAttemptStencilAttachment()68     bool canAttemptStencilAttachment() const override {
69         return true;
70     }
71 
72     GrBackendObject getRenderTargetHandle() const override;
73 
74     void getAttachmentsDescriptor(GrVkRenderPass::AttachmentsDescriptor* desc,
75                                   GrVkRenderPass::AttachmentFlags* flags) const;
76 
77     void addResources(GrVkCommandBuffer& commandBuffer) const;
78 
79 protected:
80     GrVkRenderTarget(GrVkGpu* gpu,
81                      const GrSurfaceDesc& desc,
82                      const GrVkImageInfo& info,
83                      const GrVkImageInfo& msaaInfo,
84                      const GrVkImageView* colorAttachmentView,
85                      const GrVkImageView* resolveAttachmentView,
86                      GrVkImage::Wrapped wrapped);
87 
88     GrVkRenderTarget(GrVkGpu* gpu,
89                      const GrSurfaceDesc& desc,
90                      const GrVkImageInfo& info,
91                      const GrVkImageView* colorAttachmentView,
92                      GrVkImage::Wrapped wrapped);
93 
94     GrVkGpu* getVkGpu() const;
95 
96     void onAbandon() override;
97     void onRelease() override;
98 
99     // This accounts for the texture's memory and any MSAA renderbuffer's memory.
onGpuMemorySize()100     size_t onGpuMemorySize() const override {
101         // The plus 1 is to account for the resolve texture.
102         // TODO: is this still correct?
103         int numColorSamples = this->numColorSamples() + 1;
104         return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
105                                       numColorSamples, false);
106     }
107 
108     void createFramebuffer(GrVkGpu* gpu);
109 
110     const GrVkImageView*       fColorAttachmentView;
111     std::unique_ptr<GrVkImage> fMSAAImage;
112     const GrVkImageView*       fResolveAttachmentView;
113 
114 private:
115     GrVkRenderTarget(GrVkGpu* gpu,
116                      SkBudgeted,
117                      const GrSurfaceDesc& desc,
118                      const GrVkImageInfo& info,
119                      const GrVkImageInfo& msaaInfo,
120                      const GrVkImageView* colorAttachmentView,
121                      const GrVkImageView* resolveAttachmentView,
122                      GrVkImage::Wrapped wrapped);
123 
124     GrVkRenderTarget(GrVkGpu* gpu,
125                      SkBudgeted,
126                      const GrSurfaceDesc& desc,
127                      const GrVkImageInfo& info,
128                      const GrVkImageView* colorAttachmentView,
129                      GrVkImage::Wrapped wrapped);
130 
131     static GrVkRenderTarget* Create(GrVkGpu*, SkBudgeted, const GrSurfaceDesc&,
132                                     const GrVkImageInfo&, GrVkImage::Wrapped wrapped);
133 
134     bool completeStencilAttachment() override;
135 
136     void releaseInternalObjects();
137     void abandonInternalObjects();
138 
139     const GrVkFramebuffer*     fFramebuffer;
140 
141     // This is a cached pointer to a simple render pass. The render target should unref it
142     // once it is done with it.
143     const GrVkRenderPass*      fCachedSimpleRenderPass;
144     // This is a handle to be used to quickly get compatible GrVkRenderPasses for this render target
145     GrVkResourceProvider::CompatibleRPHandle fCompatibleRPHandle;
146 };
147 
148 #endif
149