aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/vk/GrVkTextureRenderTarget.h
blob: e888397cddbbaa036fceb2471e48ec3b9b1b8e73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */


#ifndef GrVkTextureRenderTarget_DEFINED
#define GrVkTextureRenderTarget_DEFINED

#include "GrVkTexture.h"
#include "GrVkRenderTarget.h"
#include "GrVkGpu.h"

#ifdef SK_BUILD_FOR_WIN
// Windows gives bogus warnings about inheriting asTexture/asRenderTarget via dominance.
#pragma warning(push)
#pragma warning(disable: 4250)
#endif

class GrVkImageView;
struct GrVkTextureInfo;

class GrVkTextureRenderTarget: public GrVkTexture, public GrVkRenderTarget {
public:
    static GrVkTextureRenderTarget* CreateNewTextureRenderTarget(GrVkGpu*, SkBudgeted,
                                                                 const GrSurfaceDesc&,
                                                                 const GrVkImage::ImageDesc&);

    static GrVkTextureRenderTarget* CreateWrappedTextureRenderTarget(GrVkGpu*,
                                                                     const GrSurfaceDesc&,
                                                                     GrWrapOwnership,
                                                                     VkFormat,
                                                                     const GrVkTextureInfo*);

protected:
    void onAbandon() override {
        GrVkRenderTarget::onAbandon();
        GrVkTexture::onAbandon();
    }

    void onRelease() override {
        GrVkRenderTarget::onRelease();
        GrVkTexture::onRelease();
    }

private:
    GrVkTextureRenderTarget(GrVkGpu* gpu,
                            SkBudgeted budgeted,
                            const GrSurfaceDesc& desc,
                            const GrVkImage::Resource* imageResource,
                            const GrVkImageView* texView,
                            const GrVkImage::Resource* msaaResource,
                            const GrVkImageView* colorAttachmentView,
                            const GrVkImageView* resolveAttachmentView)
        : GrSurface(gpu, desc)
        , GrVkImage(imageResource)
        , GrVkTexture(gpu, desc, imageResource, texView)
        , GrVkRenderTarget(gpu, desc, imageResource, msaaResource, colorAttachmentView,
                           resolveAttachmentView) {
        this->registerWithCache(budgeted);
    }

    GrVkTextureRenderTarget(GrVkGpu* gpu,
                            SkBudgeted budgeted,
                            const GrSurfaceDesc& desc,
                            const GrVkImage::Resource* imageResource,
                            const GrVkImageView* texView,
                            const GrVkImageView* colorAttachmentView)
        : GrSurface(gpu, desc)
        , GrVkImage(imageResource)
        , GrVkTexture(gpu, desc, imageResource, texView)
        , GrVkRenderTarget(gpu, desc, imageResource, colorAttachmentView) {
        this->registerWithCache(budgeted);
    }
    enum Wrapped { kWrapped };
    GrVkTextureRenderTarget(GrVkGpu* gpu,
                            Wrapped,
                            const GrSurfaceDesc& desc,
                            const GrVkImage::Resource* imageResource,
                            const GrVkImageView* texView,
                            const GrVkImage::Resource* msaaResource,
                            const GrVkImageView* colorAttachmentView,
                            const GrVkImageView* resolveAttachmentView)
        : GrSurface(gpu, desc)
        , GrVkImage(imageResource)
        , GrVkTexture(gpu, desc, imageResource, texView)
        , GrVkRenderTarget(gpu, desc, imageResource, msaaResource, colorAttachmentView,
                           resolveAttachmentView) {
        this->registerWithCacheWrapped();
    }

    GrVkTextureRenderTarget(GrVkGpu* gpu,
                            Wrapped,
                            const GrSurfaceDesc& desc,
                            const GrVkImage::Resource* imageResource,
                            const GrVkImageView* texView,
                            const GrVkImageView* colorAttachmentView)
        : GrSurface(gpu, desc)
        , GrVkImage(imageResource)
        , GrVkTexture(gpu, desc, imageResource, texView)
        , GrVkRenderTarget(gpu, desc, imageResource, colorAttachmentView) {
        this->registerWithCacheWrapped();
    }

    template <typename ResourceType>
    static GrVkTextureRenderTarget* Create(GrVkGpu*,
                                           ResourceType,
                                           const GrSurfaceDesc&,
                                           VkFormat,
                                           const GrVkImage::Resource* imageResource);

    // GrGLRenderTarget accounts for the texture's memory and any MSAA renderbuffer's memory.
    size_t onGpuMemorySize() const override {
        return GrVkRenderTarget::onGpuMemorySize();
    }
};

#endif