Flutter Engine
 
Loading...
Searching...
No Matches
allocator_mtl_unittests.mm
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
15
16#include <QuartzCore/CAMetalLayer.h>
17#include <memory>
18#include <thread>
19
20#include "gtest/gtest.h"
21
22namespace impeller {
23namespace testing {
24
27
28TEST_P(AllocatorMTLTest, DebugTraceMemoryStatistics) {
29 auto& context_mtl = ContextMTL::Cast(*GetContext());
30 const auto& allocator = context_mtl.GetResourceAllocator();
31
32 EXPECT_EQ(allocator->DebugGetHeapUsage().ConvertTo<MebiBytes>().GetSize(),
33 0u);
34
35 // Memoryless texture does not increase allocated size.
36 {
40 desc.size = {1024, 1024};
41 auto texture_1 = allocator->CreateTexture(desc);
42
43 // Private storage texture increases allocated size.
45 auto texture_2 = allocator->CreateTexture(desc);
46
47#ifdef IMPELLER_DEBUG
48 EXPECT_EQ(allocator->DebugGetHeapUsage().ConvertTo<MebiBytes>().GetSize(),
49 4u);
50#else
51 EXPECT_EQ(allocator->DebugGetHeapUsage().ConvertTo<MebiBytes>().GetSize(),
52 0u);
53#endif // IMPELLER_DEBUG
54
55 // Host storage texture increases allocated size.
57 auto texture_3 = allocator->CreateTexture(desc);
58
59#ifdef IMPELLER_DEBUG
60 EXPECT_EQ(allocator->DebugGetHeapUsage().ConvertTo<MebiBytes>().GetSize(),
61 8u);
62#else
63 EXPECT_EQ(allocator->DebugGetHeapUsage().ConvertTo<MebiBytes>().GetSize(),
64 0u);
65#endif // IMPELLER_DEBUG
66 }
67
68 // After all textures are out of scope, memory has been decremented.
69 EXPECT_EQ(allocator->DebugGetHeapUsage().ConvertTo<MebiBytes>().GetSize(),
70 0u);
71}
72
73TEST_P(AllocatorMTLTest, ManagedMemory) {
74 auto& context_mtl = ContextMTL::Cast(*GetContext());
75 auto allocator = std::make_unique<AllocatorMTL>(context_mtl.GetMTLDevice(),
76 "test-allocator");
77 allocator->DebugSetSupportsUMA(false);
78
80 desc.size = 100;
82
83 auto buffer = allocator->CreateBuffer(desc);
84 ASSERT_TRUE(buffer);
85
86 EXPECT_NE(buffer->OnGetContents(), nullptr);
87}
88
89} // namespace testing
90} // namespace impeller
static ContextMTL & Cast(Context &base)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set profile Make the profiler discard new samples once the profiler sample buffer is full When this flag is not the profiler sample buffer is used as a ring buffer
Definition switch_defs.h:98
TEST_P(AiksTest, DrawAtlasNoColor)
AllocationSize< 1 '024u *1 '024u > MebiBytes
#define INSTANTIATE_METAL_PLAYGROUND_SUITE(playground)
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...