• 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 GrVkTextureRenderTarget_DEFINED
10 #define GrVkTextureRenderTarget_DEFINED
11 
12 #include "include/gpu/vk/GrVkTypes.h"
13 #include "src/gpu/vk/GrVkRenderTarget.h"
14 #include "src/gpu/vk/GrVkTexture.h"
15 
16 class GrVkGpu;
17 
18 #ifdef SK_BUILD_FOR_WIN
19 // Windows gives bogus warnings about inheriting asTexture/asRenderTarget via dominance.
20 #pragma warning(push)
21 #pragma warning(disable: 4250)
22 #endif
23 
24 class GrVkImageView;
25 struct GrVkImageInfo;
26 
27 class GrVkTextureRenderTarget: public GrVkTexture, public GrVkRenderTarget {
28 public:
29     static sk_sp<GrVkTextureRenderTarget> MakeNewTextureRenderTarget(GrVkGpu*, SkBudgeted,
30                                                                      const GrSurfaceDesc&,
31                                                                      int sampleCnt,
32                                                                      const GrVkImage::ImageDesc&,
33                                                                      GrMipMapsStatus);
34 
35     static sk_sp<GrVkTextureRenderTarget> MakeWrappedTextureRenderTarget(GrVkGpu*,
36                                                                          const GrSurfaceDesc&,
37                                                                          int sampleCnt,
38                                                                          GrWrapOwnership,
39                                                                          GrWrapCacheable,
40                                                                          const GrVkImageInfo&,
41                                                                          sk_sp<GrVkImageLayout>);
42 
backendFormat()43     GrBackendFormat backendFormat() const override { return this->getBackendFormat(); }
44 
45 protected:
onAbandon()46     void onAbandon() override {
47         // In order to correctly handle calling texture idle procs, GrVkTexture must go first.
48         GrVkTexture::onAbandon();
49         GrVkRenderTarget::onAbandon();
50     }
51 
onRelease()52     void onRelease() override {
53         // In order to correctly handle calling texture idle procs, GrVkTexture must go first.
54         GrVkTexture::onRelease();
55         GrVkRenderTarget::onRelease();
56     }
57 
58 private:
59     // MSAA, not-wrapped
60     GrVkTextureRenderTarget(GrVkGpu* gpu,
61                             SkBudgeted budgeted,
62                             const GrSurfaceDesc& desc,
63                             int sampleCnt,
64                             const GrVkImageInfo& info,
65                             sk_sp<GrVkImageLayout> layout,
66                             const GrVkImageView* texView,
67                             const GrVkImageInfo& msaaInfo,
68                             sk_sp<GrVkImageLayout> msaaLayout,
69                             const GrVkImageView* colorAttachmentView,
70                             const GrVkImageView* resolveAttachmentView,
71                             GrMipMapsStatus);
72 
73     // non-MSAA, not-wrapped
74     GrVkTextureRenderTarget(GrVkGpu* gpu,
75                             SkBudgeted budgeted,
76                             const GrSurfaceDesc& desc,
77                             const GrVkImageInfo& info,
78                             sk_sp<GrVkImageLayout> layout,
79                             const GrVkImageView* texView,
80                             const GrVkImageView* colorAttachmentView,
81                             GrMipMapsStatus);
82 
83     // MSAA, wrapped
84     GrVkTextureRenderTarget(GrVkGpu* gpu,
85                             const GrSurfaceDesc& desc,
86                             int sampleCnt,
87                             const GrVkImageInfo& info,
88                             sk_sp<GrVkImageLayout> layout,
89                             const GrVkImageView* texView,
90                             const GrVkImageInfo& msaaInfo,
91                             sk_sp<GrVkImageLayout> msaaLayout,
92                             const GrVkImageView* colorAttachmentView,
93                             const GrVkImageView* resolveAttachmentView,
94                             GrMipMapsStatus,
95                             GrBackendObjectOwnership,
96                             GrWrapCacheable);
97 
98     // non-MSAA, wrapped
99     GrVkTextureRenderTarget(GrVkGpu* gpu,
100                             const GrSurfaceDesc& desc,
101                             const GrVkImageInfo& info,
102                             sk_sp<GrVkImageLayout> layout,
103                             const GrVkImageView* texView,
104                             const GrVkImageView* colorAttachmentView,
105                             GrMipMapsStatus,
106                             GrBackendObjectOwnership,
107                             GrWrapCacheable);
108 
109     // GrGLRenderTarget accounts for the texture's memory and any MSAA renderbuffer's memory.
110     size_t onGpuMemorySize() const override;
111 
112     // In Vulkan we call the release proc after we are finished with the underlying
113     // GrVkImage::Resource object (which occurs after the GPU has finished all work on it).
onSetRelease(sk_sp<GrRefCntedCallback> releaseHelper)114     void onSetRelease(sk_sp<GrRefCntedCallback> releaseHelper) override {
115         // Forward the release proc on to GrVkImage
116         this->setResourceRelease(std::move(releaseHelper));
117     }
118 };
119 
120 #endif
121