Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
formats.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 <sstream>
8
12
13namespace impeller {
14
16 switch (action) {
19 return false;
22 return true;
23 }
24}
25
26bool Attachment::IsValid() const {
27 if (!texture || !texture->IsValid()) {
28 VALIDATION_LOG << "Attachment has no texture.";
29 return false;
30 }
31
33 if (!resolve_texture || !resolve_texture->IsValid()) {
34 VALIDATION_LOG << "Store action needs resolve but no valid resolve "
35 "texture specified.";
36 return false;
37 }
38 }
39
40 if (resolve_texture) {
43 VALIDATION_LOG << "A resolve texture was specified, but the store action "
44 "doesn't include multisample resolve.";
45 return false;
46 }
47
48 if (texture->GetTextureDescriptor().storage_mode ==
52 << "The multisample texture cannot be transient when "
53 "specifying the StoreAndMultisampleResolve StoreAction.";
54 }
55 }
56
57 auto storage_mode = resolve_texture
58 ? resolve_texture->GetTextureDescriptor().storage_mode
59 : texture->GetTextureDescriptor().storage_mode;
60
61 if (storage_mode == StorageMode::kDeviceTransient) {
63 VALIDATION_LOG << "The LoadAction cannot be Load when attaching a device "
64 "transient " +
65 std::string(resolve_texture ? "resolve texture."
66 : "texture.");
67 return false;
68 }
70 VALIDATION_LOG << "The StoreAction must be DontCare when attaching a "
71 "device transient " +
72 std::string(resolve_texture ? "resolve texture."
73 : "texture.");
74 return false;
75 }
76 }
77
78 return true;
79}
80
82 std::vector<TextureUsage> usages;
83 if (mask & TextureUsage::kShaderRead) {
84 usages.push_back(TextureUsage::kShaderRead);
85 }
86 if (mask & TextureUsage::kShaderWrite) {
87 usages.push_back(TextureUsage::kShaderWrite);
88 }
89 if (mask & TextureUsage::kRenderTarget) {
90 usages.push_back(TextureUsage::kRenderTarget);
91 }
92 std::stringstream stream;
93 stream << "{ ";
94 for (size_t i = 0; i < usages.size(); i++) {
95 stream << TextureUsageToString(usages[i]);
96 if (i != usages.size() - 1u) {
97 stream << ", ";
98 }
99 }
100 stream << " }";
101 return stream.str();
102}
103
104std::string AttachmentToString(const Attachment& attachment) {
105 std::stringstream stream;
106 if (attachment.texture) {
107 stream << "Texture=("
109 attachment.texture->GetTextureDescriptor())
110 << "),";
111 }
112 if (attachment.resolve_texture) {
113 stream << "ResolveTexture=("
115 attachment.resolve_texture->GetTextureDescriptor())
116 << "),";
117 }
118 stream << "LoadAction=" << LoadActionToString(attachment.load_action) << ",";
119 stream << "StoreAction=" << StoreActionToString(attachment.store_action);
120 return stream.str();
121}
122
124 std::stringstream stream;
125 stream << AttachmentToString(color) << ",";
126 stream << "ClearColor=(" << ColorToString(color.clear_color) << ")";
127 return stream.str();
128}
129
130std::string DepthAttachmentToString(const DepthAttachment& depth) {
131 std::stringstream stream;
132 stream << AttachmentToString(depth) << ",";
133 stream << "ClearDepth=" << SPrintF("%.2f", depth.clear_depth);
134 return stream.str();
135}
136
137std::string StencilAttachmentToString(const StencilAttachment& stencil) {
138 std::stringstream stream;
139 stream << AttachmentToString(stencil) << ",";
140 stream << "ClearStencil=" << stencil.clear_stencil;
141 return stream.str();
142}
143
144} // namespace impeller
SkColor4f color
std::string TextureDescriptorToString(const TextureDescriptor &desc)
std::string DepthAttachmentToString(const DepthAttachment &depth)
Definition formats.cc:130
std::string ColorAttachmentToString(const ColorAttachment &color)
Definition formats.cc:123
std::string StencilAttachmentToString(const StencilAttachment &stencil)
Definition formats.cc:137
std::string TextureUsageMaskToString(TextureUsageMask mask)
Definition formats.cc:81
std::string AttachmentToString(const Attachment &attachment)
Definition formats.cc:104
std::string SPrintF(const char *format,...)
Definition strings.cc:12
constexpr const char * LoadActionToString(LoadAction action)
Definition formats.h:216
constexpr const char * StoreActionToString(StoreAction action)
Definition formats.h:227
constexpr bool StoreActionNeedsResolveTexture(StoreAction action)
Definition formats.cc:15
std::string ColorToString(const Color &color)
Definition color.cc:410
constexpr const char * TextureUsageToString(TextureUsage usage)
Definition formats.h:311
std::shared_ptr< Texture > resolve_texture
Definition formats.h:640
bool IsValid() const
Definition formats.cc:26
LoadAction load_action
Definition formats.h:641
std::shared_ptr< Texture > texture
Definition formats.h:639
StoreAction store_action
Definition formats.h:642
#define VALIDATION_LOG
Definition validation.h:73