Flutter Engine
The Flutter Engine
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
6
7#include "flutter/fml/trace_event.h"
8
9namespace impeller {
10
11SwapchainTransientsVK::SwapchainTransientsVK(std::weak_ptr<Context> context,
13 bool enable_msaa)
14 : context_(std::move(context)), desc_(desc), enable_msaa_(enable_msaa) {}
15
17
18const 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
26const std::shared_ptr<Texture>&
28 if (cached_depth_stencil_) {
29 return cached_depth_stencil_;
30 }
31 cached_depth_stencil_ = CreateDepthStencilTexture();
32 return cached_depth_stencil_;
33}
34
35std::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;
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
60std::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
91 return enable_msaa_;
92}
93
94const std::weak_ptr<Context>& SwapchainTransientsVK::GetContext() const {
95 return context_;
96}
97
98} // namespace impeller
const std::weak_ptr< Context > & GetContext() const
const std::shared_ptr< Texture > & GetMSAATexture()
const std::shared_ptr< Texture > & GetDepthStencilTexture()
SwapchainTransientsVK(std::weak_ptr< Context > context, TextureDescriptor desc, bool enable_msaa)
FlTexture * texture
Definition: ref_ptr.h:256
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:131