blob: 0211062a283b5590614c66dbbd4c7ff45bd6b301 [file] [log] [blame]
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ContinuousTexture.h"
@implementation ContinuousTexture
+ (void)registerWithRegistrar:(nonnull NSObject<FlutterPluginRegistrar>*)registrar {
NSObject<FlutterTextureRegistry>* textureRegistry = [registrar textures];
FlutterScenarioTestTexture* texture = [[FlutterScenarioTestTexture alloc] init];
int64_t textureId = [textureRegistry registerTexture:texture];
[NSTimer scheduledTimerWithTimeInterval:0.05
repeats:YES
block:^(NSTimer* _Nonnull timer) {
[textureRegistry textureFrameAvailable:textureId];
}];
}
@end
@implementation FlutterScenarioTestTexture
- (CVPixelBufferRef _Nullable)copyPixelBuffer {
return [self pixelBuffer];
}
- (CVPixelBufferRef)pixelBuffer {
NSDictionary* options = @{
// This key is required to generate SKPicture with CVPixelBufferRef in metal.
(NSString*)kCVPixelBufferMetalCompatibilityKey : @YES
};
CVPixelBufferRef pxbuffer = NULL;
CVReturn status = CVPixelBufferCreate(kCFAllocatorDefault, 200, 200, kCVPixelFormatType_32BGRA,
(__bridge CFDictionaryRef)options, &pxbuffer);
NSParameterAssert(status == kCVReturnSuccess && pxbuffer != NULL);
CVPixelBufferLockBaseAddress(pxbuffer, 0);
return pxbuffer;
}
@end