Bug 233265 - [Model] add support for getting and setting the camera
Summary: [Model] add support for getting and setting the camera
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Antoine Quint
URL:
Keywords: InRadar
Depends on:
Blocks: 233319
  Show dependency treegraph
 
Reported: 2021-11-17 11:25 PST by Antoine Quint
Modified: 2021-11-18 12:58 PST (History)
17 users (show)

See Also:


Attachments
Patch (59.74 KB, patch)
2021-11-17 11:41 PST, Antoine Quint
darin: review+
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch for EWS (63.02 KB, patch)
2021-11-18 00:57 PST, Antoine Quint
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch for EWS (63.59 KB, patch)
2021-11-18 01:21 PST, Antoine Quint
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch for EWS (63.61 KB, patch)
2021-11-18 02:21 PST, Antoine Quint
no flags Details | Formatted Diff | Diff
Patch for EWS (63.61 KB, patch)
2021-11-18 02:23 PST, Antoine Quint
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch for EWS (65.31 KB, patch)
2021-11-18 04:25 PST, Antoine Quint
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch for landing (65.67 KB, patch)
2021-11-18 09:05 PST, Antoine Quint
no flags Details | Formatted Diff | Diff
Patch for landing (65.93 KB, patch)
2021-11-18 09:13 PST, Antoine Quint
no flags Details | Formatted Diff | Diff
Patch for landing (65.49 KB, patch)
2021-11-18 10:38 PST, Antoine Quint
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Antoine Quint 2021-11-17 11:25:45 PST
[Model] add support for getting and setting the camera
Comment 1 Antoine Quint 2021-11-17 11:41:26 PST
Created attachment 444544 [details]
Patch
Comment 2 Antoine Quint 2021-11-17 11:42:21 PST
<rdar://problem/85426290>
Comment 3 Darin Adler 2021-11-17 16:14:24 PST
Comment on attachment 444544 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=444544&action=review

> Source/WebCore/Modules/model-element/HTMLModelElement.cpp:304
> +    m_modelPlayer->getCamera([protectedThis = Ref { *this }, promise = WTFMove(promise)] (std::optional<HTMLModelElementCamera> camera) mutable {

I don’t fully understand why protectedThis is helpful. Why is extending the lifetime of the HTMLModelElement valuable, given we do nothing with that element pointer?

> Source/WebCore/Modules/model-element/HTMLModelElement.cpp:319
> +    m_modelPlayer->setCamera(camera, [protectedThis = Ref { *this }, promise = WTFMove(promise)] (bool success) mutable {

Ditto.

> Source/WebCore/Modules/model-element/HTMLModelElementCamera.h:67
> +    return { {
> +        WTFMove(*pitch),
> +        WTFMove(*yaw),
> +        WTFMove(*scale),
> +    } };

Moving a double isn’t valuable.

    return { { *pitch, *yaw, *scale } };

> Source/WebCore/Modules/model-element/HTMLModelElementCamera.idl:33
> +    double yaw;
> +    double pitch;
> +    double scale;

This says "yaw, pitch, scale", but the C++ says "pitch, yaw, scale". Does the order matter? Could we be consistent?

> Source/WebKit/Shared/ModelIdentifier.h:69
> +    return { { WTFMove(*layerIdentifier) } };

No need to move a layer ID:

    return { { *layerIdentifier } };

> Source/WebKit/UIProcess/Cocoa/ModelElementControllerCocoa.mm:58
> +WKModelView* ModelElementController::modelViewForModelIdentifier(ModelIdentifier modelIdentifier)

WKModelView * with a space before the *?

> Source/WebKit/UIProcess/Cocoa/ModelElementControllerCocoa.mm:61
> +        return nullptr;

nil is preferred over nullptr for Objective-C object pointers, I think

> Source/WebKit/UIProcess/Cocoa/ModelElementControllerCocoa.mm:64
> +        return nullptr;

Ditto.

> Source/WebKit/UIProcess/Cocoa/ModelElementControllerCocoa.mm:68
> +        return nullptr;

Ditto.

> Source/WebKit/UIProcess/Cocoa/ModelElementControllerCocoa.mm:77
>      auto *view = node->uiView();
>      if (!view)
> -        return;
> +        return nullptr;
>  
> -    if (![view isKindOfClass:[WKModelView class]])
> -        return;
> +    if ([view isKindOfClass:[WKModelView class]])
> +        return (WKModelView *)view;
> +
> +    return nullptr;

WebKit has a function template for this that collapses these 8 lines into one:

    return dynamic_objc_cast<WKModelView>(node->uiView());

> Source/WebKit/UIProcess/Cocoa/ModelElementControllerCocoa.mm:84
> +    if (auto *modelView = modelViewForModelIdentifier(modelIdentifier))
> +        return [modelView preview];
> +    return nullptr;

Objective-C has the nil handling that simplifies this. Can write one of these instead:

    return modelViewForModelIdentifier(modelIdentifier).preview;

    return [modelViewForModelIdentifier(modelIdentifier) preview];

> Source/WebKit/UIProcess/Cocoa/ModelElementControllerCocoa.mm:93
> +    auto *modelView = modelViewForModelIdentifier(modelIdentifier);

I suggest auto here. I don’t think "auto *" is helpful. Or you could use "auto*" or "WKModelView *".

> Source/WebKit/UIProcess/Cocoa/ModelElementControllerCocoa.mm:152
> +    if (auto preview = m_inlinePreviews.get(modelIdentifier.uuid))
> +        return preview.get();
> +
> +    return nullptr;

No need for an if here:

    return m_inlinePreviews.get(modelIdentifier.uuid).get();

But this makes me realize we have an unsafe-looking thing here. Normally it would not be safe to call get() on a smart pointer and then just return the raw pointer. The ".get()" here looks unsafe.

What makes it safe is the whole "peek" situation where the map itself holds a RetainPtr, but it seems we didn’t implement PeekType for RetainPtr the way we did for RefPtr. If we had, then HashMap::get would return a raw pointer and we would not need "get()".
Comment 4 Antoine Quint 2021-11-18 00:17:59 PST
Thanks for all the feedback Darin, this taught me a few Obj-C trick. I'll integrate all of this in the patch for landing. There's one question I can answer:

(In reply to Darin Adler from comment #3)
> Comment on attachment 444544 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=444544&action=review
> 
> > Source/WebCore/Modules/model-element/HTMLModelElementCamera.idl:33
> > +    double yaw;
> > +    double pitch;
> > +    double scale;
> 
> This says "yaw, pitch, scale", but the C++ says "pitch, yaw, scale". Does
> the order matter? Could we be consistent?

The order doesn't matter because there is no constructor for an IDL dictionary per-se, instead in JS the author will have to write something like { yaw: 1, pitch: 1, scale: 1 }. But consistency doesn't hurt so I moved the members around to match HTMLModelElementCamera.h.
Comment 5 Antoine Quint 2021-11-18 00:57:30 PST
Created attachment 444646 [details]
Patch for EWS
Comment 6 Antoine Quint 2021-11-18 01:21:18 PST
Created attachment 444648 [details]
Patch for EWS
Comment 7 Antoine Quint 2021-11-18 02:21:38 PST
Created attachment 444651 [details]
Patch for EWS
Comment 8 Antoine Quint 2021-11-18 02:23:28 PST
Created attachment 444653 [details]
Patch for EWS
Comment 9 Antoine Quint 2021-11-18 04:25:21 PST
Created attachment 444659 [details]
Patch for EWS
Comment 10 Antoine Quint 2021-11-18 09:05:20 PST
Created attachment 444687 [details]
Patch for landing
Comment 11 Antoine Quint 2021-11-18 09:13:51 PST
Created attachment 444691 [details]
Patch for landing
Comment 12 Antoine Quint 2021-11-18 10:38:51 PST
Created attachment 444698 [details]
Patch for landing
Comment 13 Antoine Quint 2021-11-18 11:38:15 PST
Committed r286019 (244408@main): <https://commits.webkit.org/244408@main>
Comment 14 Chris Dumez 2021-11-18 12:25:00 PST
This seems to have broken the build for me:
```
In file included from /Volumes/Data/WebKit/OpenSource/WebKitBuild/Debug/DerivedSources/WebKit2/unified-sources/UnifiedSource34-mm.mm:4:
/Volumes/Data/WebKit/OpenSource/Source/WebKit/UIProcess/Cocoa/ModelElementControllerCocoa.mm:256:14: error: instance method '-getCameraTransform:' not found (return type defaults to 'id') [-Werror,-Wobjc-method-access]
    [preview getCameraTransform:makeBlockPtr([weakThis = WeakPtr { *this }, completionHandler = WTFMove(completionHandler)] (simd_float3 cameraTransform, NSError *error) mutable {
             ^~~~~~~~~~~~~~~~~~
In file included from /Volumes/Data/WebKit/OpenSource/WebKitBuild/Debug/DerivedSources/WebKit2/unified-sources/UnifiedSource34-mm.mm:4:
In file included from /Volumes/Data/WebKit/OpenSource/Source/WebKit/UIProcess/Cocoa/ModelElementControllerCocoa.mm:51:
In file included from /Volumes/Data/WebKit/OpenSource/WebKitBuild/Debug/usr/local/include/pal/spi/mac/SystemPreviewSPI.h:29:
/Volumes/Xcode13A6201j_m20A2411_m21C29_i19C35_FastSim_Boost_Encrypted_54GB/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.Internal.sdk/System/Library/PrivateFrameworks/AssetViewer.framework/PrivateHeaders/ASVInlinePreview.h:39:12: note: receiver is instance of class declared here
@interface ASVInlinePreview : NSObject
           ^
In file included from /Volumes/Data/WebKit/OpenSource/WebKitBuild/Debug/DerivedSources/WebKit2/unified-sources/UnifiedSource34-mm.mm:4:
/Volumes/Data/WebKit/OpenSource/Source/WebKit/UIProcess/Cocoa/ModelElementControllerCocoa.mm:283:14: error: instance method '-setCameraTransform:' not found (return type defaults to 'id') [-Werror,-Wobjc-method-access]
    [preview setCameraTransform:simd_make_float3(camera.pitch, camera.yaw, camera.scale)];
             ^~~~~~~~~~~~~~~~~~
In file included from /Volumes/Data/WebKit/OpenSource/WebKitBuild/Debug/DerivedSources/WebKit2/unified-sources/UnifiedSource34-mm.mm:4:
In file included from /Volumes/Data/WebKit/OpenSource/Source/WebKit/UIProcess/Cocoa/ModelElementControllerCocoa.mm:51:
In file included from /Volumes/Data/WebKit/OpenSource/WebKitBuild/Debug/usr/local/include/pal/spi/mac/SystemPreviewSPI.h:29:
/Volumes/Xcode13A6201j_m20A2411_m21C29_i19C35_FastSim_Boost_Encrypted_54GB/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.Internal.sdk/System/Library/PrivateFrameworks/AssetViewer.framework/PrivateHeaders/ASVInlinePreview.h:39:12: note: receiver is instance of class declared here
@interface ASVInlinePreview : NSObject
           ^
2 errors generated.
```
Comment 15 Antoine Quint 2021-11-18 12:58:13 PST
Committed r286023 (244412@main): <https://commits.webkit.org/244412@main>