-
Notifications
You must be signed in to change notification settings - Fork 6k
PlatformViewsController: clear composition_order_ in the beginning of each frame. #22574
Changes from 5 commits
f620cb8
0c02873
77df228
83bf1b1
d83d986
782e34e
2d22e2d
319e87c
d01fc48
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -869,6 +869,61 @@ - (void)testFlutterPlatformViewControllerSubmitFrameWithoutFlutterViewNotCrashin | |
| XCTAssertNil(gMockPlatformView); | ||
| } | ||
|
|
||
| - (void)testFlutterPlatformViewControllerBeginFrameShouldResetCompisitionOrder { | ||
| flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; | ||
| auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); | ||
| flutter::TaskRunners runners(/*label=*/self.name.UTF8String, | ||
| /*platform=*/thread_task_runner, | ||
| /*raster=*/thread_task_runner, | ||
| /*ui=*/thread_task_runner, | ||
| /*io=*/thread_task_runner); | ||
| auto flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>(); | ||
| auto platform_view = std::make_unique<flutter::PlatformViewIOS>( | ||
| /*delegate=*/mock_delegate, | ||
| /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, | ||
| /*platform_views_controller=*/flutterPlatformViewsController, | ||
| /*task_runners=*/runners); | ||
|
|
||
| UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease]; | ||
| flutterPlatformViewsController->SetFlutterView(mockFlutterView); | ||
|
|
||
| FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = | ||
| [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; | ||
| flutterPlatformViewsController->RegisterViewFactory( | ||
| factory, @"MockFlutterPlatformView", | ||
| FlutterPlatformViewGestureRecognizersBlockingPolicyEager); | ||
| FlutterResult result = ^(id result) { | ||
| }; | ||
|
|
||
| flutterPlatformViewsController->OnMethodCall( | ||
| [FlutterMethodCall | ||
| methodCallWithMethodName:@"create" | ||
| arguments:@{@"id" : @0, @"viewType" : @"MockFlutterPlatformView"}], | ||
| result); | ||
|
|
||
| // First frame, |GetCurrentCanvases| is not empty after composite. | ||
| flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); | ||
| flutter::MutatorsStack stack; | ||
| SkMatrix finalMatrix; | ||
| auto embeddedViewParams1 = | ||
| std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack); | ||
| flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams1)); | ||
| flutterPlatformViewsController->CompositeEmbeddedView(0); | ||
| XCTAssertEqual(flutterPlatformViewsController->GetCurrentCanvases().size(), (unsigned long)1); | ||
|
|
||
| // Second frame, |GetCurrentCanvases| should be empty at the start | ||
| flutterPlatformViewsController->BeginFrame(SkISize::Make(300, 300)); | ||
| XCTAssertEqual(flutterPlatformViewsController->GetCurrentCanvases().size(), (unsigned long)0); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done! |
||
|
|
||
| auto embeddedViewParams2 = | ||
| std::make_unique<flutter::EmbeddedViewParams>(finalMatrix, SkSize::Make(300, 300), stack); | ||
| flutterPlatformViewsController->PrerollCompositeEmbeddedView(0, std::move(embeddedViewParams2)); | ||
| flutterPlatformViewsController->CompositeEmbeddedView(0); | ||
| XCTAssertEqual(flutterPlatformViewsController->GetCurrentCanvases().size(), (unsigned long)1); | ||
|
|
||
| flutterPlatformViewsController->Reset(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this needed?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, removed |
||
| } | ||
|
|
||
| - (int)alphaOfPoint:(CGPoint)point onView:(UIView*)view { | ||
| unsigned char pixel[4] = {0}; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // 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 <Flutter/Flutter.h> | ||
| #import <Foundation/Foundation.h> | ||
|
|
||
| NS_ASSUME_NONNULL_BEGIN | ||
|
|
||
| // A texture plugin that ready textures continuously. | ||
| @interface ContinuousTexture : NSObject <FlutterPlugin> | ||
|
|
||
| @end | ||
|
|
||
| // The testing texture used by |ContinuousTexture| | ||
| @interface FlutterScenarioTestTexture : NSObject <FlutterTexture> | ||
|
|
||
| @end | ||
|
|
||
| NS_ASSUME_NONNULL_END |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| // 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 | ||
|
|
||
| @interface FlutterScenarioTestTexture () | ||
|
|
||
| @property(strong, nonatomic) UIImage* image; | ||
|
|
||
| @end | ||
|
|
||
| @implementation FlutterScenarioTestTexture | ||
|
|
||
| - (instancetype)init { | ||
| self = [super init]; | ||
| if (self) { | ||
| UIGraphicsBeginImageContext(CGSizeMake(100, 100)); | ||
| [[UIColor yellowColor] setFill]; | ||
| UIRectFill(CGRectMake(0, 0, 100, 100)); | ||
| self.image = UIGraphicsGetImageFromCurrentImageContext(); | ||
| UIGraphicsEndImageContext(); | ||
| } | ||
| return self; | ||
| } | ||
|
|
||
| - (CVPixelBufferRef _Nullable)copyPixelBuffer { | ||
| return [self pixelBuffer]; | ||
| } | ||
|
|
||
| - (CVPixelBufferRef)pixelBuffer { | ||
| NSDictionary* options = @{ | ||
| // This key is required to convert CGImage to CVPixelBufferRef. | ||
| (NSString*)kCVPixelBufferCGImageCompatibilityKey : @YES, | ||
| // This key is required to generate SKPicture with CVPixelBufferRef in metal. | ||
| (NSString*)kCVPixelBufferMetalCompatibilityKey : @YES | ||
| }; | ||
| size_t width = CGImageGetWidth(self.image.CGImage); | ||
| size_t height = CGImageGetHeight(self.image.CGImage); | ||
| CVPixelBufferRef pxbuffer = NULL; | ||
| CVReturn status = | ||
| CVPixelBufferCreate(kCFAllocatorDefault, width, height, kCVPixelFormatType_32BGRA, | ||
| (__bridge CFDictionaryRef)options, &pxbuffer); | ||
| if (status != kCVReturnSuccess) { | ||
| NSLog(@"Operation failed"); | ||
| } | ||
| NSParameterAssert(status == kCVReturnSuccess && pxbuffer != NULL); | ||
|
|
||
| CVPixelBufferLockBaseAddress(pxbuffer, 0); | ||
| void* pxdata = CVPixelBufferGetBaseAddress(pxbuffer); | ||
|
|
||
| CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB(); | ||
| CGContextRef context = CGBitmapContextCreate(pxdata, width, height, 8, 4 * width, rgbColorSpace, | ||
| kCGImageAlphaNoneSkipFirst); | ||
| NSParameterAssert(context); | ||
|
|
||
| CGContextDrawImage(context, CGRectMake(0, 0, width, height), self.image.CGImage); | ||
| CGColorSpaceRelease(rgbColorSpace); | ||
| CGContextRelease(context); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What parts of this method are essential to test and why?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not required. removed. |
||
|
|
||
| CVPixelBufferUnlockBaseAddress(pxbuffer, 0); | ||
| return pxbuffer; | ||
| } | ||
|
|
||
| @end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -579,6 +579,23 @@ class PlatformViewForTouchIOSScenario extends Scenario | |
| } | ||
| } | ||
|
|
||
| /// A simple platform view for testing platform view with a continuous texture layer. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does continuous texture mean? Does it mean a texture that simulates a video being played? |
||
| /// For example, it simulates a video being played. | ||
| class PlatformViewWithContinuousTexture extends PlatformViewScenario { | ||
| /// Constructs a platform view with continuous texture layer. | ||
| PlatformViewWithContinuousTexture(PlatformDispatcher dispatcher, String text, { int id = 0 }) | ||
| : super(dispatcher, text, id: id); | ||
|
|
||
| @override | ||
| void onBeginFrame(Duration duration) { | ||
| final SceneBuilder builder = SceneBuilder(); | ||
|
|
||
| builder.addTexture(0, width: 300, height: 300, offset: const Offset(200, 200)); | ||
|
|
||
| finishBuilderByAddingPlatformViewAndPicture(builder, id); | ||
| } | ||
| } | ||
|
|
||
| mixin _BasePlatformViewScenarioMixin on Scenario { | ||
| int _textureId; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does
1ULwork here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, updated