8#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterSurface.h"
9#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h"
11#include "flutter/testing/testing.h"
12#include "gtest/gtest.h"
17- (nonnull instancetype)
init;
24 self = [
super initWithFrame:NSZeroRect];
26 [
self setWantsLayer:YES];
27 self.layer.contentsScale = 2.0;
32- (void)onPresent:(CGSize)frameSize withBlock:(nonnull dispatch_block_t)block {
33 self.presentedFrameSize = frameSize;
42 id<MTLDevice>
device = MTLCreateSystemDefaultDevice();
43 id<MTLCommandQueue> commandQueue = [device newCommandQueue];
44 CALayer* layer =
reinterpret_cast<CALayer*
>(testView.layer);
46 commandQueue:commandQueue
53 CGPoint
offset = CGPointZero,
55 const std::vector<FlutterRect>& paintRegion = {}) {
71 id<MTLTexture> metalTexture = (__bridge
id)
texture.texture;
72 EXPECT_EQ(metalTexture.width, 100ul);
73 EXPECT_EQ(metalTexture.height, 50ul);
90 EXPECT_EQ(surface1, nil);
101 auto surface1 = [surfaceManager
surfaceForSize:CGSizeMake(100, 100)];
106 auto surface2 = [surfaceManager
surfaceForSize:CGSizeMake(110, 110)];
111 auto surface3 = [surfaceManager
surfaceForSize:CGSizeMake(120, 120)];
117 auto surfaceFromCache = [surfaceManager
surfaceForSize:CGSizeMake(110, 110)];
118 EXPECT_EQ(surfaceFromCache, surface2);
123 for (
int i = 0;
i < 30 ; ++
i) {
140 auto surface1 = [surfaceManager
surfaceForSize:CGSizeMake(100, 100)];
141 EXPECT_TRUE(CGSizeEqualToSize(surface1.size, CGSizeMake(100, 100)));
150 EXPECT_EQ(testView.layer.sublayers.count, 1ul);
154 auto surface2 = [surfaceManager
surfaceForSize:CGSizeMake(100, 100)];
155 EXPECT_TRUE(CGSizeEqualToSize(surface2.size, CGSizeMake(100, 100)));
164 EXPECT_EQ(testView.layer.sublayers.count, 1ull);
167 auto surface3 = [surfaceManager
surfaceForSize:CGSizeMake(100, 100)];
168 EXPECT_EQ(surface3, surface1);
175 auto surface1 = [surfaceManager
surfaceForSize:CGSizeMake(100, 100)];
180 surface1.isInUseOverride = YES;
182 auto surface2 = [surfaceManager
surfaceForSize:CGSizeMake(100, 100)];
186 for (
int i = 0;
i < 30 - 1; ++
i) {
187 auto surface3 = [surfaceManager
surfaceForSize:CGSizeMake(100, 100)];
192 auto surface4 = [surfaceManager
surfaceForSize:CGSizeMake(100, 100)];
198inline bool operator==(
const CGRect& lhs,
const CGRect& rhs) {
199 return CGRectEqualToRect(lhs, rhs);
206 EXPECT_EQ(testView.layer.sublayers.count, 0ul);
208 auto surface1_1 = [surfaceManager
surfaceForSize:CGSizeMake(50, 30)];
209 [surfaceManager
presentSurfaces:@[ CreatePresentInfo(surface1_1, CGPointMake(20, 10)) ]
213 EXPECT_EQ(testView.layer.sublayers.count, 1ul);
216 auto surface2_1 = [surfaceManager
surfaceForSize:CGSizeMake(50, 30)];
217 auto surface2_2 = [surfaceManager
surfaceForSize:CGSizeMake(20, 20)];
219 CreatePresentInfo(surface2_1, CGPointMake(20, 10), 1),
220 CreatePresentInfo(surface2_2, CGPointMake(40, 50), 2,
223 FlutterRect{40, 0, 60, 20},
229 EXPECT_EQ(testView.layer.sublayers.count, 2ul);
230 EXPECT_EQ(testView.layer.sublayers[0].zPosition, 1.0);
231 EXPECT_EQ(testView.layer.sublayers[1].zPosition, 2.0);
232 CALayer* firstOverlaySublayer;
234 NSArray<CALayer*>* sublayers = testView.layer.sublayers[1].sublayers;
235 EXPECT_EQ(sublayers.count, 2ul);
236 EXPECT_TRUE(CGRectEqualToRect(sublayers[0].
frame, CGRectMake(0, 0, 10, 10)));
237 EXPECT_TRUE(CGRectEqualToRect(sublayers[1].
frame, CGRectMake(20, 0, 10, 10)));
238 EXPECT_TRUE(CGRectEqualToRect(sublayers[0].contentsRect, CGRectMake(0, 0, 1, 1)));
239 EXPECT_TRUE(CGRectEqualToRect(sublayers[1].contentsRect, CGRectMake(2, 0, 1, 1)));
240 EXPECT_EQ(sublayers[0].contents, sublayers[1].contents);
241 firstOverlaySublayer = sublayers[0];
247 CreatePresentInfo(surface2_1, CGPointMake(20, 10), 1),
248 CreatePresentInfo(surface2_2, CGPointMake(40, 50), 2,
255 EXPECT_EQ(testView.layer.sublayers.count, 2ul);
257 NSArray<CALayer*>* sublayers = testView.layer.sublayers[1].sublayers;
258 EXPECT_EQ(sublayers.count, 1ul);
259 EXPECT_EQ(sublayers[0], firstOverlaySublayer);
260 EXPECT_TRUE(CGRectEqualToRect(sublayers[0].
frame, CGRectMake(0, 5, 10, 5)));
265 CreatePresentInfo(surface2_1, CGPointMake(20, 10), 1),
266 CreatePresentInfo(surface2_2, CGPointMake(40, 50), 2,
269 FlutterRect{40, 0, 60, 20},
275 EXPECT_EQ(testView.layer.sublayers.count, 2ul);
277 NSArray<CALayer*>* sublayers = testView.layer.sublayers[1].sublayers;
278 EXPECT_EQ(sublayers.count, 2ul);
279 EXPECT_EQ(sublayers[0], firstOverlaySublayer);
280 EXPECT_TRUE(CGRectEqualToRect(sublayers[0].
frame, CGRectMake(0, 0, 10, 10)));
281 EXPECT_TRUE(CGRectEqualToRect(sublayers[1].
frame, CGRectMake(20, 0, 10, 10)));
282 EXPECT_EQ(sublayers[0].contents, sublayers[1].contents);
285 auto surface3_1 = [surfaceManager
surfaceForSize:CGSizeMake(50, 30)];
286 [surfaceManager
presentSurfaces:@[ CreatePresentInfo(surface3_1, CGPointMake(20, 10)) ]
290 EXPECT_EQ(testView.layer.sublayers.count, 1ul);
295 EXPECT_EQ(testView.layer.sublayers.count, 0ul);
nonnull FlutterSurface * surfaceForSize:(CGSize size)
NSArray * frontSurfaces()
void presentSurfaces:atTime:notify:(nonnull NSArray< FlutterSurfacePresentInfo * > *surfaces,[atTime] CFTimeInterval presentationTime,[notify] nullable dispatch_block_t notify)
FlutterBackBufferCache * backBufferCache()
std::vector< FlutterRect > paintRegion
nullable FlutterSurface * fromFlutterMetalTexture:(nonnull const FlutterMetalTexture *texture)
CGSize presentedFrameSize
nonnull instancetype init()
TEST(FlutterSurfaceManager, LayerManagement)
static FlutterSurfacePresentInfo * CreatePresentInfo(FlutterSurface *surface, CGPoint offset=CGPointZero, size_t index=0, const std::vector< FlutterRect > &paintRegion={})
bool operator==(const CGRect &lhs, const CGRect &rhs)
static FlutterSurfaceManager * CreateSurfaceManager(TestView *testView)
A structure to represent a rectangle.
#define EXPECT_TRUE(handle)