Flutter Impeller
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 
5 #include "flutter/testing/testing.h"
15 
16 #include <QuartzCore/CAMetalLayer.h>
17 #include <memory>
18 #include <thread>
19 
20 #include "gtest/gtest.h"
21 
22 namespace impeller {
23 namespace testing {
24 
27 
28 TEST_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  {
37  TextureDescriptor desc;
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 
73 } // namespace testing
74 } // namespace impeller
context_mtl.h
playground_test.h
impeller::TextureDescriptor::format
PixelFormat format
Definition: texture_descriptor.h:41
impeller::PixelFormat::kR8G8B8A8UNormInt
@ kR8G8B8A8UNormInt
texture_descriptor.h
allocator_mtl.h
formats_mtl.h
formats.h
impeller::testing::INSTANTIATE_METAL_PLAYGROUND_SUITE
INSTANTIATE_METAL_PLAYGROUND_SUITE(AllocatorMTLTest)
impeller::StorageMode::kHostVisible
@ kHostVisible
impeller::StorageMode::kDeviceTransient
@ kDeviceTransient
impeller::StorageMode::kDevicePrivate
@ kDevicePrivate
capabilities.h
impeller::AllocationSize
Represents the size of an allocation in different units.
Definition: allocation_size.h:29
impeller::testing::TEST_P
TEST_P(AiksTest, DrawAtlasNoColor)
Definition: aiks_dl_atlas_unittests.cc:78
impeller::TextureDescriptor::size
ISize size
Definition: texture_descriptor.h:42
lazy_drawable_holder.h
texture_mtl.h
impeller::BackendCast< ContextMTL, Context >::Cast
static ContextMTL & Cast(Context &base)
Definition: backend_cast.h:13
impeller::TextureDescriptor::storage_mode
StorageMode storage_mode
Definition: texture_descriptor.h:39
impeller::PlaygroundTest
Definition: playground_test.h:21
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::AllocationSize::GetSize
constexpr double GetSize() const
Definition: allocation_size.h:76