Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Instance Methods | List of all members
FlutterMetalLayerTest Class Reference
Inheritance diagram for FlutterMetalLayerTest:

Instance Methods

(FlutterMetalLayer *) - addMetalLayer [implementation]
 
(void) - removeMetalLayer: [implementation]
 
(void) - testFlip [implementation]
 
(void) - testFlipWithDroppedFrame [implementation]
 
(void) - testDroppedDrawableReturnsTextureToPool [implementation]
 
(void) - testLayerLimitsDrawableCount [implementation]
 
(void) - testTimeout [implementation]
 

Detailed Description

Definition at line 13 of file FlutterMetalLayerTest.mm.

Method Documentation

◆ addMetalLayer

- (FlutterMetalLayer *) addMetalLayer
implementation

Definition at line 31 of file FlutterMetalLayerTest.mm.

66 {
68 [[TestFlutterMetalLayerView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
69 FlutterMetalLayer* layer = (FlutterMetalLayer*)view.layer;
70 layer.drawableSize = CGSizeMake(100, 100);
71 return layer;
72}

◆ removeMetalLayer:

- (void) removeMetalLayer: (FlutterMetalLayer*)  layer
implementation

Definition at line 31 of file FlutterMetalLayerTest.mm.

74 :(FlutterMetalLayer*)layer {
75}

◆ testDroppedDrawableReturnsTextureToPool

- (void) testDroppedDrawableReturnsTextureToPool
implementation

Definition at line 31 of file FlutterMetalLayerTest.mm.

185 {
186 FlutterMetalLayer* layer = [self addMetalLayer];
187 // FlutterMetalLayer will keep creating new textures until it has 3.
188 @autoreleasepool {
189 for (int i = 0; i < 3; ++i) {
190 id<CAMetalDrawable> drawable = [layer nextDrawable];
191 BAIL_IF_NO_DRAWABLE(drawable);
192 }
193 }
194 id<MTLTexture> texture;
195 {
196 @autoreleasepool {
197 id<CAMetalDrawable> drawable = [layer nextDrawable];
198 XCTAssertNotNil(drawable);
199 texture = (id<MTLTexture>)drawable.texture;
200 // Dropping the drawable must return texture to pool, so
201 // next drawable should return the same texture.
202 }
203 }
204 {
205 id<CAMetalDrawable> drawable = [layer nextDrawable];
206 XCTAssertEqual(texture, drawable.texture);
207 }
208
209 [self removeMetalLayer:layer];
210}
#define BAIL_IF_NO_DRAWABLE(drawable)
nullable id< CAMetalDrawable > nextDrawable()
FlTexture * texture

◆ testFlip

- (void) testFlip
implementation

Definition at line 31 of file FlutterMetalLayerTest.mm.

85 {
86 FlutterMetalLayer* layer = [self addMetalLayer];
87 TestCompositor* compositor = [[TestCompositor alloc] initWithLayer:layer];
88
89 id<MTLTexture> t1, t2, t3;
90
91 id<CAMetalDrawable> drawable = [layer nextDrawable];
92 BAIL_IF_NO_DRAWABLE(drawable);
93 t1 = drawable.texture;
94 [drawable present];
95 [compositor commitTransaction];
96
97 drawable = [layer nextDrawable];
98 BAIL_IF_NO_DRAWABLE(drawable);
99 t2 = drawable.texture;
100 [drawable present];
101 [compositor commitTransaction];
102
103 drawable = [layer nextDrawable];
104 BAIL_IF_NO_DRAWABLE(drawable);
105 t3 = drawable.texture;
106 [drawable present];
107 [compositor commitTransaction];
108
109 // If there was no frame drop, layer should return oldest presented
110 // texture.
111
112 drawable = [layer nextDrawable];
113 XCTAssertEqual(drawable.texture, t1);
114
115 [drawable present];
116 [compositor commitTransaction];
117
118 drawable = [layer nextDrawable];
119 XCTAssertEqual(drawable.texture, t2);
120 [drawable present];
121 [compositor commitTransaction];
122
123 drawable = [layer nextDrawable];
124 XCTAssertEqual(drawable.texture, t3);
125 [drawable present];
126 [compositor commitTransaction];
127
128 drawable = [layer nextDrawable];
129 XCTAssertEqual(drawable.texture, t1);
130 [drawable present];
131
132 [self removeMetalLayer:layer];
133}

◆ testFlipWithDroppedFrame

- (void) testFlipWithDroppedFrame
implementation

Definition at line 31 of file FlutterMetalLayerTest.mm.

135 {
136 FlutterMetalLayer* layer = [self addMetalLayer];
137 TestCompositor* compositor = [[TestCompositor alloc] initWithLayer:layer];
138
139 id<MTLTexture> t1, t2, t3;
140
141 id<CAMetalDrawable> drawable = [layer nextDrawable];
142 BAIL_IF_NO_DRAWABLE(drawable);
143 t1 = drawable.texture;
144 [drawable present];
145 [compositor commitTransaction];
146 XCTAssertTrue(IOSurfaceIsInUse(t1.iosurface));
147
148 drawable = [layer nextDrawable];
149 BAIL_IF_NO_DRAWABLE(drawable);
150 t2 = drawable.texture;
151 [drawable present];
152 [compositor commitTransaction];
153
154 drawable = [layer nextDrawable];
155 BAIL_IF_NO_DRAWABLE(drawable);
156 t3 = drawable.texture;
157 [drawable present];
158 [compositor commitTransaction];
159
160 // Simulate compositor holding on to t3 for a while.
161 IOSurfaceIncrementUseCount(t3.iosurface);
162
163 // Here the drawable is presented, but immediately replaced by another drawable
164 // (before the compositor has a chance to pick it up). This should result
165 // in same drawable returned in next call to nextDrawable.
166 drawable = [layer nextDrawable];
167 XCTAssertEqual(drawable.texture, t1);
168 XCTAssertFalse(IOSurfaceIsInUse(drawable.texture.iosurface));
169 [drawable present];
170
171 drawable = [layer nextDrawable];
172 XCTAssertEqual(drawable.texture, t2);
173 [drawable present];
174 [compositor commitTransaction];
175
176 // Next drawable should be t1, since it was never picked up by compositor.
177 drawable = [layer nextDrawable];
178 XCTAssertEqual(drawable.texture, t1);
179
180 IOSurfaceDecrementUseCount(t3.iosurface);
181
182 [self removeMetalLayer:layer];
183}

◆ testLayerLimitsDrawableCount

- (void) testLayerLimitsDrawableCount
implementation

Definition at line 31 of file FlutterMetalLayerTest.mm.

212 {
213 FlutterMetalLayer* layer = [self addMetalLayer];
214
215 id<CAMetalDrawable> d1 = [layer nextDrawable];
217 id<CAMetalDrawable> d2 = [layer nextDrawable];
219 id<CAMetalDrawable> d3 = [layer nextDrawable];
221 XCTAssertNotNil(d3);
222
223 // Layer should not return more than 3 drawables.
224 id<CAMetalDrawable> d4 = [layer nextDrawable];
225 XCTAssertNil(d4);
226
227 [d1 present];
228
229 // Still no drawable, until the front buffer returns to pool
230 id<CAMetalDrawable> d5 = [layer nextDrawable];
231 XCTAssertNil(d5);
232
233 [d2 present];
234 id<CAMetalDrawable> d6 = [layer nextDrawable];
235 XCTAssertNotNil(d6);
236
237 [self removeMetalLayer:layer];
238}

◆ testTimeout

- (void) testTimeout
implementation

Definition at line 31 of file FlutterMetalLayerTest.mm.

240 {
241 FlutterMetalLayer* layer = [self addMetalLayer];
242 TestCompositor* compositor = [[TestCompositor alloc] initWithLayer:layer];
243
244 id<CAMetalDrawable> drawable = [layer nextDrawable];
245 BAIL_IF_NO_DRAWABLE(drawable);
246
247 __block MTLCommandBufferHandler handler;
248
249 id<MTLCommandBuffer> mockCommandBuffer = OCMProtocolMock(@protocol(MTLCommandBuffer));
250 OCMStub([mockCommandBuffer addCompletedHandler:OCMOCK_ANY]).andDo(^(NSInvocation* invocation) {
251 MTLCommandBufferHandler handlerOnStack;
252 [invocation getArgument:&handlerOnStack atIndex:2];
253 // Required to copy stack block to heap.
254 handler = handlerOnStack;
255 });
256
257 [(id<FlutterMetalDrawable>)drawable flutterPrepareForPresent:mockCommandBuffer];
258 [drawable present];
259 [compositor commitTransaction];
260
261 // Drawable will not be available until the command buffer completes.
262 drawable = [layer nextDrawable];
263 XCTAssertNil(drawable);
264
265 handler(mockCommandBuffer);
266
267 drawable = [layer nextDrawable];
268 XCTAssertNotNil(drawable);
269
270 [self removeMetalLayer:layer];
271}

The documentation for this class was generated from the following file: