Skip to content

Commit c34c0dc

Browse files
authored
Move static methods to anonymous namespace (flutter#137)
1 parent 254db27 commit c34c0dc

File tree

1 file changed

+58
-54
lines changed

1 file changed

+58
-54
lines changed

impeller/renderer/backend/metal/command_buffer_mtl.mm

+58-54
Original file line numberDiff line numberDiff line change
@@ -7,55 +7,11 @@
77
#include "impeller/renderer/backend/metal/render_pass_mtl.h"
88

99
namespace impeller {
10-
11-
id<MTLCommandBuffer> CreateCommandBuffer(id<MTLCommandQueue> queue) {
12-
if (@available(iOS 14.0, macOS 11.0, *)) {
13-
auto desc = [[MTLCommandBufferDescriptor alloc] init];
14-
// Degrades CPU performance slightly but is well worth the cost for typical
15-
// Impeller workloads.
16-
desc.errorOptions = MTLCommandBufferErrorOptionEncoderExecutionStatus;
17-
return [queue commandBufferWithDescriptor:desc];
18-
}
19-
return [queue commandBuffer];
20-
}
21-
22-
CommandBufferMTL::CommandBufferMTL(id<MTLCommandQueue> queue)
23-
: buffer_(CreateCommandBuffer(queue)) {
24-
if (!buffer_) {
25-
return;
26-
}
27-
is_valid_ = true;
28-
}
29-
30-
CommandBufferMTL::~CommandBufferMTL() = default;
31-
32-
bool CommandBufferMTL::IsValid() const {
33-
return is_valid_;
34-
}
35-
36-
void CommandBufferMTL::SetLabel(const std::string& label) const {
37-
if (label.empty()) {
38-
return;
39-
}
40-
41-
[buffer_ setLabel:@(label.data())];
42-
}
43-
44-
static CommandBuffer::Status ToCommitResult(MTLCommandBufferStatus status) {
45-
switch (status) {
46-
case MTLCommandBufferStatusCompleted:
47-
return CommandBufferMTL::Status::kCompleted;
48-
case MTLCommandBufferStatusEnqueued:
49-
return CommandBufferMTL::Status::kPending;
50-
default:
51-
break;
52-
}
53-
return CommandBufferMTL::Status::kError;
54-
}
55-
10+
namespace {
5611
// TODO(dnfield): remove this declaration when we no longer need to build on
57-
// machines with lower SDK versions than 11.0.s
58-
#if !defined(MAC_OS_VERSION_11_0) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_VERSION_11_0
12+
// machines with lower SDK versions than 11.0.
13+
#if !defined(MAC_OS_VERSION_11_0) || \
14+
MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_VERSION_11_0
5915
typedef NS_ENUM(NSInteger, MTLCommandEncoderErrorState) {
6016
MTLCommandEncoderErrorStateUnknown = 0,
6117
MTLCommandEncoderErrorStateCompleted = 1,
@@ -65,12 +21,6 @@ typedef NS_ENUM(NSInteger, MTLCommandEncoderErrorState) {
6521
} API_AVAILABLE(macos(11.0), ios(14.0));
6622
#endif
6723

68-
69-
#if !defined(MAC_OS_VERSION_12_0) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_VERSION_12_0
70-
constexpr int MTLCommandBufferErrorAccessRevoked = 4;
71-
constexpr int MTLCommandBufferErrorStackOverflow = 12;
72-
#endif
73-
7424
API_AVAILABLE(ios(14.0), macos(11.0))
7525
NSString* MTLCommandEncoderErrorStateToString(
7626
MTLCommandEncoderErrorState state) {
@@ -89,6 +39,14 @@ typedef NS_ENUM(NSInteger, MTLCommandEncoderErrorState) {
8939
return @"unknown";
9040
}
9141

42+
// TODO(dnfield): This can be removed when all bots have been sufficiently
43+
// upgraded for MAC_OS_VERSION_12_0.
44+
#if !defined(MAC_OS_VERSION_12_0) || \
45+
MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_VERSION_12_0
46+
constexpr int MTLCommandBufferErrorAccessRevoked = 4;
47+
constexpr int MTLCommandBufferErrorStackOverflow = 12;
48+
#endif
49+
9250
static NSString* MTLCommandBufferErrorToString(MTLCommandBufferError code) {
9351
switch (code) {
9452
case MTLCommandBufferErrorNone:
@@ -173,6 +131,52 @@ static void LogMTLCommandBufferErrorIfPresent(id<MTLCommandBuffer> buffer) {
173131
stream << "<<<<<<<";
174132
VALIDATION_LOG << stream.str();
175133
}
134+
} // namespace
135+
136+
id<MTLCommandBuffer> CreateCommandBuffer(id<MTLCommandQueue> queue) {
137+
if (@available(iOS 14.0, macOS 11.0, *)) {
138+
auto desc = [[MTLCommandBufferDescriptor alloc] init];
139+
// Degrades CPU performance slightly but is well worth the cost for typical
140+
// Impeller workloads.
141+
desc.errorOptions = MTLCommandBufferErrorOptionEncoderExecutionStatus;
142+
return [queue commandBufferWithDescriptor:desc];
143+
}
144+
return [queue commandBuffer];
145+
}
146+
147+
CommandBufferMTL::CommandBufferMTL(id<MTLCommandQueue> queue)
148+
: buffer_(CreateCommandBuffer(queue)) {
149+
if (!buffer_) {
150+
return;
151+
}
152+
is_valid_ = true;
153+
}
154+
155+
CommandBufferMTL::~CommandBufferMTL() = default;
156+
157+
bool CommandBufferMTL::IsValid() const {
158+
return is_valid_;
159+
}
160+
161+
void CommandBufferMTL::SetLabel(const std::string& label) const {
162+
if (label.empty()) {
163+
return;
164+
}
165+
166+
[buffer_ setLabel:@(label.data())];
167+
}
168+
169+
static CommandBuffer::Status ToCommitResult(MTLCommandBufferStatus status) {
170+
switch (status) {
171+
case MTLCommandBufferStatusCompleted:
172+
return CommandBufferMTL::Status::kCompleted;
173+
case MTLCommandBufferStatusEnqueued:
174+
return CommandBufferMTL::Status::kPending;
175+
default:
176+
break;
177+
}
178+
return CommandBufferMTL::Status::kError;
179+
}
176180

177181
bool CommandBufferMTL::SubmitCommands(CompletionCallback callback) {
178182
if (!buffer_) {

0 commit comments

Comments
 (0)