Flutter Engine
The Flutter Engine
GrVkFramebuffer.h
Go to the documentation of this file.
1/*
2* Copyright 2016 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 GrVkFramebuffer_DEFINED
9#define GrVkFramebuffer_DEFINED
10
11#include "include/gpu/GrTypes.h"
15
16#include <cinttypes>
17
18class GrVkGpu;
19class GrVkImage;
20class GrVkImageView;
21class GrVkRenderPass;
22
24public:
26 SkISize dimensions,
31 GrVkResourceProvider::CompatibleRPHandle);
32
33 // Used for wrapped external secondary command buffers
34 GrVkFramebuffer(const GrVkGpu* gpu,
37 std::unique_ptr<GrVkSecondaryCommandBuffer>);
38
39 VkFramebuffer framebuffer() const {
40 SkASSERT(!this->isExternal());
41 return fFramebuffer;
42 }
43
44 bool isExternal() const { return fExternalRenderPass.get(); }
45 const GrVkRenderPass* externalRenderPass() const { return fExternalRenderPass.get(); }
46 std::unique_ptr<GrVkSecondaryCommandBuffer> externalCommandBuffer();
47
48 // When we wrap a secondary command buffer, we will record GrManagedResources onto it which need
49 // to be kept alive till the command buffer gets submitted and the GPU has finished. However, in
50 // the wrapped case, we don't know when the command buffer gets submitted and when it is
51 // finished on the GPU since the client is in charge of that. However, we do require that the
52 // client keeps the GrVkSecondaryCBDrawContext alive and call releaseResources on it once the
53 // GPU is finished all the work. Thus we can use this to manage the lifetime of our
54 // GrVkSecondaryCommandBuffers. By storing them on the external GrVkFramebuffer owned by the
55 // GrVkRenderTarget, which is owned by the SkGpuDevice on the GrVkSecondaryCBDrawContext, we
56 // assure that the GrManagedResources held by the GrVkSecondaryCommandBuffer don't get deleted
57 // before they are allowed to.
58 void returnExternalGrSecondaryCommandBuffer(std::unique_ptr<GrVkSecondaryCommandBuffer>);
59
60#ifdef SK_TRACE_MANAGED_RESOURCES
61 void dumpInfo() const override {
62 SkDebugf("GrVkFramebuffer: %" PRIdPTR " (%d refs)\n",
63 (intptr_t)fFramebuffer, this->getRefCnt());
64 }
65#endif
66
67 const GrVkRenderPass* compatibleRenderPass() const { return fCompatibleRenderPass.get(); }
68
69 GrVkResourceProvider::CompatibleRPHandle compatibleRenderPassHandle() const {
70 return fCompatibleRenderPassHandle;
71 }
72
73 GrVkImage* colorAttachment() { return fColorAttachment.get(); }
74 GrVkImage* resolveAttachment() { return fResolveAttachment.get(); }
75 GrVkImage* stencilAttachment() { return fStencilAttachment.get(); }
76
77private:
78 GrVkFramebuffer(const GrVkGpu* gpu,
79 VkFramebuffer framebuffer,
84 GrVkResourceProvider::CompatibleRPHandle);
85
86 ~GrVkFramebuffer() override;
87
88 void freeGPUData() const override;
89 void releaseResources();
90
91 VkFramebuffer fFramebuffer = VK_NULL_HANDLE;
92
93 sk_sp<GrVkImage> fColorAttachment;
94 sk_sp<GrVkImage> fResolveAttachment;
95 sk_sp<GrVkImage> fStencilAttachment;
96
97 sk_sp<const GrVkRenderPass> fCompatibleRenderPass;
98 GrVkResourceProvider::CompatibleRPHandle fCompatibleRenderPassHandle;
99
100 sk_sp<const GrVkRenderPass> fExternalRenderPass;
101 std::unique_ptr<GrVkSecondaryCommandBuffer> fExternalCommandBuffer;
102};
103
104#endif
#define SkASSERT(cond)
Definition: SkAssert.h:116
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
const GrVkRenderPass * compatibleRenderPass() const
void returnExternalGrSecondaryCommandBuffer(std::unique_ptr< GrVkSecondaryCommandBuffer >)
GrVkResourceProvider::CompatibleRPHandle compatibleRenderPassHandle() const
const GrVkRenderPass * externalRenderPass() const
GrVkFramebuffer(const GrVkGpu *gpu, sk_sp< GrVkImage > colorAttachment, sk_sp< const GrVkRenderPass > renderPass, std::unique_ptr< GrVkSecondaryCommandBuffer >)
GrVkImage * resolveAttachment()
GrVkImage * colorAttachment()
static sk_sp< const GrVkFramebuffer > Make(GrVkGpu *gpu, SkISize dimensions, sk_sp< const GrVkRenderPass > compatibleRenderPass, GrVkImage *colorAttachment, GrVkImage *resolveAttachment, GrVkImage *stencilAttachment, GrVkResourceProvider::CompatibleRPHandle)
VkFramebuffer framebuffer() const
std::unique_ptr< GrVkSecondaryCommandBuffer > externalCommandBuffer()
GrVkImage * stencilAttachment()
bool isExternal() const
T * get() const
Definition: SkRefCnt.h:303
Definition: SkSize.h:16
#define VK_NULL_HANDLE
Definition: vulkan_core.h:46