Flutter Engine
The Flutter Engine
impeller
renderer
backend
metal
texture_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"
6
#include "
impeller/core/formats.h
"
7
#include "
impeller/core/texture_descriptor.h
"
8
#include "
impeller/renderer/backend/metal/formats_mtl.h
"
9
#include "
impeller/renderer/backend/metal/lazy_drawable_holder.h
"
10
#include "
impeller/renderer/backend/metal/texture_mtl.h
"
11
#include "
impeller/renderer/capabilities.h
"
12
13
#include <QuartzCore/CAMetalLayer.h>
14
#include <thread>
15
16
#include "gtest/gtest.h"
17
18
namespace
impeller
{
19
namespace
testing {
20
21
TEST
(
TextureMTL
, CreateFromDrawable) {
22
auto
device
= MTLCreateSystemDefaultDevice();
23
auto
layer = [[CAMetalLayer alloc]
init
];
24
layer.device =
device
;
25
layer.drawableSize = CGSize{100, 100};
26
layer.pixelFormat =
ToMTLPixelFormat
(
PixelFormat::kB8G8R8A8UNormInt
);
27
28
TextureDescriptor
desc
;
29
desc
.size = {100, 100};
30
desc
.format =
PixelFormat::kB8G8R8A8UNormInt
;
31
auto
drawable_future =
GetDrawableDeferred
(layer);
32
auto
drawable_texture =
33
CreateTextureFromDrawableFuture
(
desc
, drawable_future);
34
35
ASSERT_TRUE(drawable_texture->IsValid());
36
EXPECT_TRUE
(drawable_texture->IsDrawable());
37
38
// Spawn a thread and acquire the drawable in the thread.
39
auto
thread = std::thread([&drawable_texture]() {
40
// Force the drawable to be acquired.
41
drawable_texture->GetMTLTexture();
42
});
43
thread.join();
44
// Block until drawable is acquired.
45
EXPECT_TRUE
(drawable_future.get() != nil);
46
// Drawable is cached.
47
EXPECT_TRUE
(drawable_texture->GetMTLTexture() != nil);
48
// Once more for good measure.
49
EXPECT_TRUE
(drawable_texture->GetMTLTexture() != nil);
50
}
51
52
}
// namespace testing
53
}
// namespace impeller
capabilities.h
impeller::TextureMTL
Definition:
texture_mtl.h:16
device
VkDevice device
Definition:
main.cc:53
formats_mtl.h
formats.h
lazy_drawable_holder.h
SkOpts::init
static bool init()
Definition:
SkBitmapProcState_opts.cpp:26
impeller::testing::TEST
TEST(AiksCanvasTest, EmptyCullRect)
Definition:
canvas_unittests.cc:18
impeller
Definition:
texture.h:18
impeller::CreateTextureFromDrawableFuture
std::shared_ptr< TextureMTL > CreateTextureFromDrawableFuture(TextureDescriptor desc, const std::shared_future< id< CAMetalDrawable > > &drawble_future)
Create a TextureMTL from a deferred drawable.
Definition:
lazy_drawable_holder.mm:41
impeller::PixelFormat::kB8G8R8A8UNormInt
@ kB8G8R8A8UNormInt
impeller::ToMTLPixelFormat
constexpr MTLPixelFormat ToMTLPixelFormat(PixelFormat format)
Definition:
formats_mtl.h:76
impeller::GetDrawableDeferred
std::shared_future< id< CAMetalDrawable > > GetDrawableDeferred(CAMetalLayer *layer)
Create a deferred drawable from a CAMetalLayer.
Definition:
lazy_drawable_holder.mm:23
import_conformance_tests.desc
desc
Definition:
import_conformance_tests.py:63
impeller::TextureDescriptor
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
Definition:
texture_descriptor.h:37
texture_descriptor.h
texture_mtl.h
EXPECT_TRUE
#define EXPECT_TRUE(handle)
Definition:
unit_test.h:678
Generated on Sun Jun 23 2024 21:55:03 for Flutter Engine by
1.9.4