| Flutter Impeller |

swapchain_transients_vk.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "impeller/renderer/backend/vulkan/swapchain/swapchain_transients_vk.h"
6
7 #include "flutter/fml/trace_event.h"
8
9 namespace impeller {
10
11 SwapchainTransientsVK::SwapchainTransientsVK(std::weak_ptr<Context> context,
12 TextureDescriptor desc,
13 bool enable_msaa)
14 : context_(std::move(context)), desc_(desc), enable_msaa_(enable_msaa) {}
15
16 SwapchainTransientsVK::~SwapchainTransientsVK() = default;
17
18 const std::shared_ptr<Texture>& SwapchainTransientsVK::GetMSAATexture() {
19 if (cached_msaa_texture_) {
20 return cached_msaa_texture_;
21 }
22 cached_msaa_texture_ = CreateMSAATexture();
23 return cached_msaa_texture_;
24 }
25
26 const std::shared_ptr<Texture>&
27 SwapchainTransientsVK::GetDepthStencilTexture() {
28 if (cached_depth_stencil_) {
29 return cached_depth_stencil_;
30 }
31 cached_depth_stencil_ = CreateDepthStencilTexture();
32 return cached_depth_stencil_;
33 }
34
35 std::shared_ptr<Texture> SwapchainTransientsVK::CreateMSAATexture() const {
36 TRACE_EVENT0("impeller", __FUNCTION__);
37 if (!enable_msaa_) {
38 return nullptr;
39 }
40 TextureDescriptor msaa_desc;
41 msaa_desc.storage_mode = StorageMode::kDeviceTransient;
42 msaa_desc.type = TextureType::kTexture2DMultisample;
43 msaa_desc.sample_count = SampleCount::kCount4;
44 msaa_desc.format = desc_.format;
45 msaa_desc.size = desc_.size;
46 msaa_desc.usage = TextureUsage::kRenderTarget;
47
48 auto context = context_.lock();
49 if (!context) {
50 return nullptr;
51 }
52 auto texture = context->GetResourceAllocator()->CreateTexture(msaa_desc);
53 if (!texture) {
54 return nullptr;
55 }
56 texture->SetLabel("SwapchainMSAA");
57 return texture;
58 }
59
60 std::shared_ptr<Texture> SwapchainTransientsVK::CreateDepthStencilTexture()
61 const {
62 TRACE_EVENT0("impeller", __FUNCTION__);
63 auto context = context_.lock();
64 if (!context) {
65 return nullptr;
66 }
67 TextureDescriptor depth_stencil_desc;
68 depth_stencil_desc.storage_mode = StorageMode::kDeviceTransient;
69 if (enable_msaa_) {
70 depth_stencil_desc.type = TextureType::kTexture2DMultisample;
71 depth_stencil_desc.sample_count = SampleCount::kCount4;
72 } else {
73 depth_stencil_desc.type = TextureType::kTexture2D;
74 depth_stencil_desc.sample_count = SampleCount::kCount1;
75 }
76 depth_stencil_desc.format =
77 context->GetCapabilities()->GetDefaultDepthStencilFormat();
78 depth_stencil_desc.size = desc_.size;
79 depth_stencil_desc.usage = TextureUsage::kRenderTarget;
80
81 auto texture =
82 context->GetResourceAllocator()->CreateTexture(depth_stencil_desc);
83 if (!texture) {
84 return nullptr;
85 }
86 texture->SetLabel("SwapchainDepthStencil");
87 return texture;
88 }
89
90 bool SwapchainTransientsVK::IsMSAAEnabled() const {
91 return enable_msaa_;
92 }
93
94 const std::weak_ptr<Context>& SwapchainTransientsVK::GetContext() const {
95 return context_;
96 }
97
98 } // namespace impeller
impeller::TextureDescriptor::format
PixelFormat format
Definition: texture_descriptor.h:41
impeller::SwapchainTransientsVK::~SwapchainTransientsVK
~SwapchainTransientsVK()
swapchain_transients_vk.h
impeller::TextureUsage::kRenderTarget
@ kRenderTarget
impeller::SwapchainTransientsVK::GetMSAATexture
const std::shared_ptr< Texture > & GetMSAATexture()
Definition: swapchain_transients_vk.cc:18
impeller::SwapchainTransientsVK::GetContext
const std::weak_ptr< Context > & GetContext() const
Definition: swapchain_transients_vk.cc:94
impeller::TextureType::kTexture2DMultisample
@ kTexture2DMultisample
impeller::StorageMode::kDeviceTransient
@ kDeviceTransient
impeller::TextureType::kTexture2D
@ kTexture2D
impeller::TextureDescriptor::size
ISize size
Definition: texture_descriptor.h:42
std
Definition: comparable.h:95
impeller::SampleCount::kCount1
@ kCount1
impeller::SampleCount::kCount4
@ kCount4
impeller::SwapchainTransientsVK::IsMSAAEnabled
bool IsMSAAEnabled() const
Definition: swapchain_transients_vk.cc:90
impeller::TextureDescriptor
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
Definition: texture_descriptor.h:38
impeller
Definition: allocation.cc:12
impeller::SwapchainTransientsVK::GetDepthStencilTexture
const std::shared_ptr< Texture > & GetDepthStencilTexture()
Definition: swapchain_transients_vk.cc:27
impeller::SwapchainTransientsVK::SwapchainTransientsVK
SwapchainTransientsVK(std::weak_ptr< Context > context, TextureDescriptor desc, bool enable_msaa)
Definition: swapchain_transients_vk.cc:11