Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrVkFramebuffer.cpp
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
9
15
17 GrVkGpu* gpu,
18 SkISize dimensions,
19 sk_sp<const GrVkRenderPass> compatibleRenderPass,
20 GrVkImage* colorAttachment,
21 GrVkImage* resolveAttachment,
22 GrVkImage* stencilAttachment,
23 GrVkResourceProvider::CompatibleRPHandle compatibleRenderPassHandle) {
24 // At the very least we need a renderPass and a colorAttachment
27
28 VkImageView attachments[3];
29 attachments[0] = colorAttachment->framebufferView()->imageView();
30 int numAttachments = 1;
32 attachments[numAttachments++] = resolveAttachment->framebufferView()->imageView();
33 }
35 attachments[numAttachments++] = stencilAttachment->framebufferView()->imageView();
36 }
37
38 VkFramebufferCreateInfo createInfo;
39 memset(&createInfo, 0, sizeof(VkFramebufferCreateInfo));
41 createInfo.pNext = nullptr;
42 createInfo.flags = 0;
44 createInfo.attachmentCount = numAttachments;
45 createInfo.pAttachments = attachments;
46 createInfo.width = dimensions.width();
47 createInfo.height = dimensions.height();
48 createInfo.layers = 1;
49
50 VkFramebuffer framebuffer;
51 VkResult err;
52 GR_VK_CALL_RESULT(gpu, err, CreateFramebuffer(gpu->device(), &createInfo, nullptr,
53 &framebuffer));
54 if (err) {
55 return nullptr;
56 }
57
62}
63
65 VkFramebuffer framebuffer,
66 sk_sp<GrVkImage> colorAttachment,
67 sk_sp<GrVkImage> resolveAttachment,
68 sk_sp<GrVkImage> stencilAttachment,
69 sk_sp<const GrVkRenderPass> compatibleRenderPass,
70 GrVkResourceProvider::CompatibleRPHandle compatibleRPHandle)
72 , fFramebuffer(framebuffer)
73 , fColorAttachment(std::move(colorAttachment))
74 , fResolveAttachment(std::move(resolveAttachment))
75 , fStencilAttachment(std::move(stencilAttachment))
76 , fCompatibleRenderPass(std::move(compatibleRenderPass))
77 , fCompatibleRenderPassHandle(compatibleRPHandle) {
78 SkASSERT(fCompatibleRenderPassHandle.isValid());
79}
80
82 sk_sp<GrVkImage> colorAttachment,
84 std::unique_ptr<GrVkSecondaryCommandBuffer> externalCommandBuffer)
86 , fColorAttachment(std::move(colorAttachment))
87 , fExternalRenderPass(std::move(renderPass))
88 , fExternalCommandBuffer(std::move(externalCommandBuffer)) {}
89
91
93 SkASSERT(this->isExternal() || fFramebuffer != VK_NULL_HANDLE);
94 if (!this->isExternal()) {
95 GR_VK_CALL(fGpu->vkInterface(), DestroyFramebuffer(fGpu->device(), fFramebuffer, nullptr));
96 }
97
98 // TODO: having freeGPUData virtual on GrManagedResource be const seems like a bad restriction
99 // since we are changing the internal objects of these classes when it is called. We should go
100 // back a revisit how much of a headache it would be to make this function non-const
101 GrVkFramebuffer* nonConstThis = const_cast<GrVkFramebuffer*>(this);
102 nonConstThis->releaseResources();
103}
104
105void GrVkFramebuffer::releaseResources() {
106 if (fExternalCommandBuffer) {
107 fExternalCommandBuffer->releaseResources();
108 fExternalCommandBuffer.reset();
109 }
110}
111
113 std::unique_ptr<GrVkSecondaryCommandBuffer> cmdBuffer) {
114 SkASSERT(!fExternalCommandBuffer);
115 fExternalCommandBuffer = std::move(cmdBuffer);
116}
117
118std::unique_ptr<GrVkSecondaryCommandBuffer> GrVkFramebuffer::externalCommandBuffer() {
119 SkASSERT(fExternalCommandBuffer);
120 return std::move(fExternalCommandBuffer);
121}
#define GR_VK_CALL(IFACE, X)
Definition GrVkUtil.h:24
#define GR_VK_CALL_RESULT(GPU, RESULT, X)
Definition GrVkUtil.h:35
#define SkASSERT(cond)
Definition SkAssert.h:116
sk_sp< T > sk_ref_sp(T *obj)
Definition SkRefCnt.h:381
const GrVkRenderPass * compatibleRenderPass() const
void freeGPUData() const override
void returnExternalGrSecondaryCommandBuffer(std::unique_ptr< GrVkSecondaryCommandBuffer >)
GrVkResourceProvider::CompatibleRPHandle compatibleRenderPassHandle() const
GrVkFramebuffer(const GrVkGpu *gpu, sk_sp< GrVkImage > colorAttachment, sk_sp< const GrVkRenderPass > renderPass, std::unique_ptr< GrVkSecondaryCommandBuffer >)
GrVkImage * resolveAttachment()
GrVkImage * colorAttachment()
~GrVkFramebuffer() override
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
const skgpu::VulkanInterface * vkInterface() const
Definition GrVkGpu.h:60
VkDevice device() const
Definition GrVkGpu.h:71
VkImageView imageView() const
const GrVkImageView * framebufferView() const
Definition GrVkImage.h:105
VkRenderPass vkRenderPass() const
Definition ref_ptr.h:256
constexpr int32_t width() const
Definition SkSize.h:36
constexpr int32_t height() const
Definition SkSize.h:37
const VkImageView * pAttachments
VkStructureType sType
VkFramebufferCreateFlags flags
VkResult
#define VK_NULL_HANDLE
Definition vulkan_core.h:46
@ VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO