Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[macOS] Change view ID to signed #39958

Merged
merged 6 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/ui/platform_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,8 @@ class PlatformDispatcher {
// If this value changes, update the encoding code in the following files:
//
// * pointer_data.cc
// * pointer.dart
// * AndroidTouchProcessor.java
static const int _kPointerDataFieldCount = 36;
static const int _kPointerDataFieldCount = 37;

static PointerDataPacket _unpackPointerDataPacket(ByteData packet) {
const int kStride = Int64List.bytesPerElement;
Expand Down Expand Up @@ -438,6 +437,7 @@ class PlatformDispatcher {
panDeltaY: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
scale: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
rotation: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
viewId: packet.getInt64(kStride * offset++, _kFakeHostEndian),
preferredStylusAuxiliaryAction: PointerPreferredStylusAuxiliaryAction.values[packet.getInt64(kStride * offset++, _kFakeHostEndian)],
));
assert(offset == (i + 1) * _kPointerDataFieldCount);
Expand Down
5 changes: 5 additions & 0 deletions lib/ui/pointer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ class PointerData {
this.panDeltaY = 0.0,
this.scale = 0.0,
this.rotation = 0.0,
this.viewId = 0,
this.preferredStylusAuxiliaryAction = PointerPreferredStylusAuxiliaryAction.ignore,
});

Expand Down Expand Up @@ -396,6 +397,9 @@ class PointerData {
/// The current angle of the pan/zoom in radians, with 0.0 as the initial angle.
final double rotation;

/// The ID of the view that this event took place.
final int viewId;

/// For events with signal kind of stylusAuxiliaryAction
///
/// The current preferred action for stylusAuxiliaryAction, with ignore as the default.
Expand Down Expand Up @@ -441,6 +445,7 @@ class PointerData {
'panDeltaY: $panDeltaY, '
'scale: $scale, '
'rotation: $rotation, '
'viewId: $viewId, '
'preferredStylusAuxiliaryAction: $preferredStylusAuxiliaryAction'
')';
}
Expand Down
7 changes: 4 additions & 3 deletions lib/ui/window/pointer_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

namespace flutter {

// If this value changes, update the pointer data unpacking code in
// platform_dispatcher.dart.
static constexpr int kPointerDataFieldCount = 36;
// If this value changes, other places need changing too. See
// _kPointerDataFieldCount in platform_dispatcher.dart.
static constexpr int kPointerDataFieldCount = 37;
static constexpr int kBytesPerField = sizeof(int64_t);
// Must match the button constants in events.dart.
enum PointerButtonMouse : int64_t {
Expand Down Expand Up @@ -110,6 +110,7 @@ struct alignas(8) PointerData {
double pan_delta_y;
double scale;
double rotation;
int64_t view_id;
PreferredStylusAuxiliaryAction preferred_auxiliary_stylus_action;

void Clear();
Expand Down
3 changes: 3 additions & 0 deletions lib/web_ui/lib/pointer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class PointerData {
this.panDeltaY = 0.0,
this.scale = 0.0,
this.rotation = 0.0,
this.viewId = 0,
this.preferredStylusAuxiliaryAction = PointerPreferredStylusAuxiliaryAction.ignore,
});
final int embedderId;
Expand Down Expand Up @@ -126,6 +127,7 @@ class PointerData {
final double panDeltaY;
final double scale;
final double rotation;
final int viewId;
final PointerPreferredStylusAuxiliaryAction preferredStylusAuxiliaryAction;

@override
Expand Down Expand Up @@ -166,6 +168,7 @@ class PointerData {
'panDeltaY: $panDeltaY, '
'scale: $scale, '
'rotation: $rotation, '
'viewId: $viewId, '
'preferredStylusAuxiliaryAction: $preferredStylusAuxiliaryAction'
')';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ public class AndroidTouchProcessor {
int UNKNOWN = 4;
}

// Must match the unpacking code in hooks.dart.
private static final int POINTER_DATA_FIELD_COUNT = 36;
// If this value changes, other places need changing too. See
// _kPointerDataFieldCount in platform_dispatcher.dart.
private static final int POINTER_DATA_FIELD_COUNT = 37;
@VisibleForTesting static final int BYTES_PER_FIELD = 8;

// This value must match the value in framework's platform_view.dart.
Expand Down Expand Up @@ -238,6 +239,8 @@ private void addPointerForIndex(
int pointerData,
Matrix transformMatrix,
ByteBuffer packet) {
// TODO(dkwingsmt): Get the source view ID from event data.
int viewId = 0;
if (pointerChange == -1) {
return;
}
Expand Down Expand Up @@ -373,6 +376,8 @@ private void addPointerForIndex(
packet.putDouble(1.0); // scale
packet.putDouble(0.0); // rotation

packet.putLong(viewId); // viewId

packet.putLong(PointerPreferredStylusAuxiliaryAction.IGNORE); // preferred stylus action

if (isTrackpadPan && getPointerChangeForPanZoom(pointerChange) == PointerChange.PAN_ZOOM_END) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* backward compatibility, single-view APIs will always operate on the view with
* this ID. Also, the first view assigned to the engine will also have this ID.
*/
extern const uint64_t kFlutterDefaultViewId;
extern const int64_t kFlutterDefaultViewId;

@class FlutterViewController;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@

#import <Cocoa/Cocoa.h>

#include <stdint.h>

#import "FlutterBinaryMessenger.h"
#import "FlutterChannels.h"
#import "FlutterMacros.h"
#import "FlutterPlatformViews.h"
#import "FlutterPluginMacOS.h"
#import "FlutterTexture.h"

typedef int64_t FlutterViewId;
constexpr int64_t kFlutterDefaultViewId = 0;

// TODO: Merge this file and FlutterPluginMacOS.h with the iOS FlutterPlugin.h, sharing all but
// the platform-specific methods.

Expand Down Expand Up @@ -47,7 +52,7 @@ FLUTTER_DARWIN_EXPORT
/**
* The `NSView` associated with the given view ID, if any.
*/
- (nullable NSView*)viewForId:(uint64_t)viewId;
- (nullable NSView*)viewForId:(int64_t)viewId;

/**
* Registers |delegate| to receive handleMethodCall:result: callbacks for the given |channel|.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ FLUTTER_DARWIN_EXPORT
* If the view controller is unattached (see FlutterViewController#attached),
* reading this property throws an assertion.
*/
@property(nonatomic, readonly) uint64_t viewId;
@property(nonatomic, readonly) int64_t viewId;

/**
* The style of mouse tracking to use for the view. Defaults to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class FlutterCompositor {

// Presents the FlutterLayers by updating the FlutterView specified by
// `view_id` using the layer content. Sets frame_started_ to false.
bool Present(uint64_t view_id, const FlutterLayer** layers, size_t layers_count);
bool Present(int64_t view_id, const FlutterLayer** layers, size_t layers_count);

private:
void PresentPlatformViews(FlutterView* default_base_view,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@
return true;
}

bool FlutterCompositor::Present(uint64_t view_id,
const FlutterLayer** layers,
size_t layers_count) {
bool FlutterCompositor::Present(int64_t view_id, const FlutterLayer** layers, size_t layers_count) {
FlutterView* view = [view_provider_ viewForId:view_id];
if (!view) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewProvider.h"
#import "flutter/testing/testing.h"

extern const uint64_t kFlutterDefaultViewId;
extern const int64_t kFlutterDefaultViewId;

@interface FlutterViewMockProvider : NSObject <FlutterViewProvider> {
FlutterView* _defaultView;
Expand All @@ -32,7 +32,7 @@ - (nonnull instancetype)initWithDefaultView:(nonnull FlutterView*)view {
return self;
}

- (nullable FlutterView*)viewForId:(uint64_t)viewId {
- (nullable FlutterView*)viewForId:(int64_t)viewId {
if (viewId == kFlutterDefaultViewId) {
return _defaultView;
}
Expand Down
16 changes: 7 additions & 9 deletions shell/platform/darwin/macos/framework/Source/FlutterEngine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h"
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProvider.h"

const uint64_t kFlutterDefaultViewId = 0;

NSString* const kFlutterPlatformChannel = @"flutter/platform";

/**
Expand Down Expand Up @@ -90,15 +88,15 @@ @interface FlutterEngine () <FlutterBinaryMessenger>
*/
@property(nonatomic, strong) NSMutableArray<NSNumber*>* isResponseValid;

- (nullable FlutterViewController*)viewControllerForId:(uint64_t)viewId;
- (nullable FlutterViewController*)viewControllerForId:(int64_t)viewId;

/**
* An internal method that adds the view controller with the given ID.
*
* This method assigns the controller with the ID, puts the controller into the
* map, and does assertions related to the default view ID.
*/
- (void)registerViewController:(FlutterViewController*)controller forId:(uint64_t)viewId;
- (void)registerViewController:(FlutterViewController*)controller forId:(int64_t)viewId;

/**
* An internal method that removes the view controller with the given ID.
Expand All @@ -107,7 +105,7 @@ - (void)registerViewController:(FlutterViewController*)controller forId:(uint64_
* map. This is an no-op if the view ID is not associated with any view
* controllers.
*/
- (void)deregisterViewControllerForId:(uint64_t)viewId;
- (void)deregisterViewControllerForId:(int64_t)viewId;

/**
* Shuts down the engine if view requirement is not met, and headless execution
Expand Down Expand Up @@ -294,7 +292,7 @@ - (NSView*)view {
return [self viewForId:kFlutterDefaultViewId];
}

- (NSView*)viewForId:(uint64_t)viewId {
- (NSView*)viewForId:(int64_t)viewId {
FlutterViewController* controller = [_flutterEngine viewControllerForId:viewId];
if (controller == nil) {
return nil;
Expand Down Expand Up @@ -573,7 +571,7 @@ - (void)loadAOTData:(NSString*)assetsDir {
}
}

- (void)registerViewController:(FlutterViewController*)controller forId:(uint64_t)viewId {
- (void)registerViewController:(FlutterViewController*)controller forId:(int64_t)viewId {
NSAssert(controller != nil, @"The controller must not be nil.");
NSAssert(![controller attached],
@"The incoming view controller is already attached to an engine.");
Expand All @@ -583,7 +581,7 @@ - (void)registerViewController:(FlutterViewController*)controller forId:(uint64_
[_viewControllers setObject:controller forKey:@(viewId)];
}

- (void)deregisterViewControllerForId:(uint64_t)viewId {
- (void)deregisterViewControllerForId:(int64_t)viewId {
FlutterViewController* oldController = [self viewControllerForId:viewId];
if (oldController != nil) {
[oldController detachFromEngine];
Expand All @@ -597,7 +595,7 @@ - (void)shutDownIfNeeded {
}
}

- (FlutterViewController*)viewControllerForId:(uint64_t)viewId {
- (FlutterViewController*)viewControllerForId:(int64_t)viewId {
FlutterViewController* controller = [_viewControllers objectForKey:@(viewId)];
NSAssert(controller == nil || controller.viewId == viewId,
@"The stored controller has unexpected view ID.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable
@autoreleasepool {
// Create FVC1.
viewController1 = [[FlutterViewController alloc] initWithProject:project];
EXPECT_EQ(viewController1.viewId, 0ull);
EXPECT_EQ(viewController1.viewId, 0ll);

engine = viewController1.engine;
engine.viewController = nil;
Expand All @@ -664,7 +664,7 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable

engine.viewController = viewController1;
EXPECT_EQ(engine.viewController, viewController1);
EXPECT_EQ(viewController1.viewId, 0ull);
EXPECT_EQ(viewController1.viewId, 0ll);
}

TEST_F(FlutterEngineTest, ManageControllersIfInitiatedByEngine) {
Expand All @@ -678,15 +678,15 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable

@autoreleasepool {
viewController1 = [[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil];
EXPECT_EQ(viewController1.viewId, 0ull);
EXPECT_EQ(viewController1.viewId, 0ll);
EXPECT_EQ(engine.viewController, viewController1);

engine.viewController = nil;

FlutterViewController* viewController2 = [[FlutterViewController alloc] initWithEngine:engine
nibName:nil
bundle:nil];
EXPECT_EQ(viewController2.viewId, 0ull);
EXPECT_EQ(viewController2.viewId, 0ll);
EXPECT_EQ(engine.viewController, viewController2);
}
// FVC2 is deallocated but FVC1 is retained.
Expand All @@ -695,7 +695,7 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable

engine.viewController = viewController1;
EXPECT_EQ(engine.viewController, viewController1);
EXPECT_EQ(viewController1.viewId, 0ull);
EXPECT_EQ(viewController1.viewId, 0ll);
}

TEST_F(FlutterEngineTest, HandlesTerminationRequest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ typedef NS_ENUM(NSInteger, FlutterAppExitResponse) {
/**
* The |FlutterViewController| associated with the given view ID, if any.
*/
- (nullable FlutterViewController*)viewControllerForId:(uint64_t)viewId;
- (nullable FlutterViewController*)viewControllerForId:(int64_t)viewId;

/**
* Informs the engine that the specified view controller's window metrics have changed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@

// Set up embedder API mock.
FlutterSemanticsAction called_action;
uint64_t called_id;
int64_t called_id;

engine.embedderAPI.DispatchSemanticsAction = MOCK_ENGINE_PROC(
DispatchSemanticsAction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
/**
* Called by the engine when the given view's buffers should be swapped.
*/
- (BOOL)present:(uint64_t)viewId texture:(nonnull const FlutterMetalTexture*)texture;
- (BOOL)present:(int64_t)viewId texture:(nonnull const FlutterMetalTexture*)texture;

/**
* Creates a Metal texture for the given view with the given size.
*/
- (FlutterMetalTexture)createTextureForView:(uint64_t)viewId size:(CGSize)size;
- (FlutterMetalTexture)createTextureForView:(int64_t)viewId size:(CGSize)size;

/**
* Populates the texture registry with the provided metalTexture.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static FlutterMetalTexture OnGetNextDrawableForDefaultView(FlutterEngine* engine
// TODO(dkwingsmt): This callback only supports single-view, therefore it only
// operates on the default view. To support multi-view, we need a new callback
// that also receives a view ID, or pass the ID via FlutterFrameInfo.
uint64_t viewId = kFlutterDefaultViewId;
int64_t viewId = kFlutterDefaultViewId;
CGSize size = CGSizeMake(frameInfo->size.width, frameInfo->size.height);
return [engine.renderer createTextureForView:viewId size:size];
}
Expand All @@ -27,7 +27,7 @@ static bool OnPresentDrawableOfDefaultView(FlutterEngine* engine,
// TODO(dkwingsmt): This callback only supports single-view, therefore it only
// operates on the default view. To support multi-view, we need a new callback
// that also receives a view ID.
uint64_t viewId = kFlutterDefaultViewId;
int64_t viewId = kFlutterDefaultViewId;
return [engine.renderer present:viewId texture:texture];
}

Expand Down Expand Up @@ -88,7 +88,7 @@ - (FlutterRendererConfig)createRendererConfig {

#pragma mark - Embedder callback implementations.

- (FlutterMetalTexture)createTextureForView:(uint64_t)viewId size:(CGSize)size {
- (FlutterMetalTexture)createTextureForView:(int64_t)viewId size:(CGSize)size {
FlutterView* view = [_viewProvider viewForId:viewId];
NSAssert(view != nil, @"Can't create texture on a non-existent view 0x%llx.", viewId);
if (view == nil) {
Expand All @@ -98,7 +98,7 @@ - (FlutterMetalTexture)createTextureForView:(uint64_t)viewId size:(CGSize)size {
return [view.surfaceManager surfaceForSize:size].asFlutterMetalTexture;
}

- (BOOL)present:(uint64_t)viewId texture:(const FlutterMetalTexture*)texture {
- (BOOL)present:(int64_t)viewId texture:(const FlutterMetalTexture*)texture {
FlutterView* view = [_viewProvider viewForId:viewId];
if (view == nil) {
return NO;
Expand Down
Loading