5 #import <Metal/Metal.h>
6 #import <QuartzCore/QuartzCore.h>
7 #import <XCTest/XCTest.h>
9 #include "flutter/fml/logging.h"
46 - (void)commitTransaction {
47 IOSurfaceRef surface = (__bridge IOSurfaceRef)
self->_layer.contents;
48 if (
self->_presentedSurface) {
49 IOSurfaceDecrementUseCount(
self->_presentedSurface);
51 IOSurfaceIncrementUseCount(surface);
52 self->_presentedSurface = surface;
56 if (
self->_presentedSurface) {
57 IOSurfaceDecrementUseCount(
self->_presentedSurface);
78 #define BAIL_IF_NO_DRAWABLE(drawable) \
79 if (drawable == nil) { \
80 FML_LOG(ERROR) << "Could not allocate drawable"; \
88 id<MTLTexture> t1, t2, t3;
92 t1 = drawable.texture;
94 [compositor commitTransaction];
98 t2 = drawable.texture;
100 [compositor commitTransaction];
104 t3 = drawable.texture;
106 [compositor commitTransaction];
112 XCTAssertEqual(drawable.texture, t1);
115 [compositor commitTransaction];
118 XCTAssertEqual(drawable.texture, t2);
120 [compositor commitTransaction];
123 XCTAssertEqual(drawable.texture, t3);
125 [compositor commitTransaction];
128 XCTAssertEqual(drawable.texture, t1);
131 [
self removeMetalLayer:layer];
134 - (void)testFlipWithDroppedFrame {
138 id<MTLTexture> t1, t2, t3;
142 t1 = drawable.texture;
144 [compositor commitTransaction];
145 XCTAssertTrue(IOSurfaceIsInUse(t1.iosurface));
149 t2 = drawable.texture;
151 [compositor commitTransaction];
155 t3 = drawable.texture;
157 [compositor commitTransaction];
160 IOSurfaceIncrementUseCount(t3.iosurface);
166 XCTAssertEqual(drawable.texture, t1);
167 XCTAssertFalse(IOSurfaceIsInUse(drawable.texture.iosurface));
171 XCTAssertEqual(drawable.texture, t2);
173 [compositor commitTransaction];
177 XCTAssertEqual(drawable.texture, t1);
179 IOSurfaceDecrementUseCount(t3.iosurface);
181 [
self removeMetalLayer:layer];
184 - (void)testDroppedDrawableReturnsTextureToPool {
188 for (
int i = 0; i < 3; ++i) {
193 id<MTLTexture> texture;
197 XCTAssertNotNil(drawable);
198 texture = (id<MTLTexture>)drawable.texture;
205 XCTAssertEqual(texture, drawable.texture);
208 [
self removeMetalLayer:layer];
211 - (void)testLayerLimitsDrawableCount {
236 [
self removeMetalLayer:layer];