Bug 227530 - [Model] [macOS] Add support for rendering model resources
Summary: [Model] [macOS] Add support for rendering model resources
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:
 
Reported: 2021-06-30 08:26 PDT by Antoine Quint
Modified: 2021-07-01 10:24 PDT (History)
16 users (show)

See Also:


Attachments
Patch (64.08 KB, patch)
2021-06-30 08:36 PDT, Antoine Quint
no flags Details | Formatted Diff | Diff
Patch (64.21 KB, patch)
2021-06-30 08:42 PDT, Antoine Quint
no flags Details | Formatted Diff | Diff
Patch (39.29 KB, patch)
2021-06-30 13:48 PDT, Antoine Quint
dino: review+
ews-feeder: commit-queue-
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-06-30 08:26:37 PDT
[Model] [macOS] Add support for rendering model resources
Comment 1 Antoine Quint 2021-06-30 08:36:28 PDT
Created attachment 432598 [details]
Patch
Comment 2 Radar WebKit Bug Importer 2021-06-30 08:37:45 PDT
<rdar://problem/79968206>
Comment 3 Antoine Quint 2021-06-30 08:42:12 PDT
Created attachment 432599 [details]
Patch
Comment 4 Sam Weinig 2021-06-30 10:34:34 PDT
Comment on attachment 432599 [details]
Patch

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

> Source/WebCore/Modules/model-element/HTMLModelElement.mm:29
> +#if ENABLE(MODEL_ELEMENT)

We shouldn't use .mm for cross platform code like this. Please keep this a .cpp file and factor out the objective-c bits into their own classes.
Comment 5 Antoine Quint 2021-06-30 11:51:12 PDT
(In reply to Sam Weinig from comment #4)
> Comment on attachment 432599 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=432599&action=review
> 
> > Source/WebCore/Modules/model-element/HTMLModelElement.mm:29
> > +#if ENABLE(MODEL_ELEMENT)
> 
> We shouldn't use .mm for cross platform code like this. Please keep this a
> .cpp file and factor out the objective-c bits into their own classes.

Right, so add a Source/WebCore/Modules/model-element/HTMLModelElementCocoa.mm with these bits?
Comment 6 Antoine Quint 2021-06-30 13:48:25 PDT
Created attachment 432623 [details]
Patch
Comment 7 Dean Jackson 2021-06-30 17:31:20 PDT
Comment on attachment 432623 [details]
Patch

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

No test?

> Source/WebCore/ChangeLog:12
> +        <model> element is created and message the UIProcess through the ChromeClient provinding the UUID generated for it. When

Typo provinding

> Source/WebCore/Modules/model-element/HTMLModelElementCocoa.mm:43
> +#include <wtf/UUID.h>
> +SOFT_LINK_PRIVATE_FRAMEWORK(AssetViewer);

Add a space between these lines.

> Source/WebCore/Modules/model-element/HTMLModelElementCocoa.mm:66
> +    auto fileName = FileSystem::encodeForFileName(createCanonicalUUIDString()) + ".usdz";

What about if it is a .reality file?

> Source/WebCore/Modules/model-element/HTMLModelElementCocoa.mm:74
> +    auto file = FileSystem::openFile(filePath, FileSystem::FileOpenMode::Write);
> +    if (file <= 0)
> +        return;
> +
> +    FileSystem::writeToFile(file, m_data->data(), m_data->size());
> +    FileSystem::closeFile(file);
> +    m_filePath = filePath;

Can you put a note in here that this is a temporary solution and we don't want to write to files?

> Source/WebCore/Modules/model-element/HTMLModelElementCocoa.mm:92
> +    FloatSize size;
> +    if (auto* renderer = this->renderer())
> +        size = renderer->absoluteBoundingBoxRect(false).size();

If there isn't a renderer you probably just want to exit.

if (!this->renderer())
  return;

auto size = this->renderer()->aBB...

> Source/WebKit/UIProcess/Cocoa/ModelElementControllerCocoa.mm:134
> +    else
> +        iterator->value = preview;

I didn't know you could do this! Very nice.
Comment 8 Antoine Quint 2021-06-30 23:25:28 PDT
(In reply to Dean Jackson from comment #7)
> Comment on attachment 432623 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=432623&action=review
> 
> > Source/WebCore/Modules/model-element/HTMLModelElementCocoa.mm:66
> > +    auto fileName = FileSystem::encodeForFileName(createCanonicalUUIDString()) + ".usdz";
> 
> What about if it is a .reality file?

Filed bug 227568, will add a reference to it in the commit.

> > Source/WebCore/Modules/model-element/HTMLModelElementCocoa.mm:74
> > +    auto file = FileSystem::openFile(filePath, FileSystem::FileOpenMode::Write);
> > +    if (file <= 0)
> > +        return;
> > +
> > +    FileSystem::writeToFile(file, m_data->data(), m_data->size());
> > +    FileSystem::closeFile(file);
> > +    m_filePath = filePath;
> 
> Can you put a note in here that this is a temporary solution and we don't
> want to write to files?

Filed bug 227567 and adding a reference to it in the commit.
Comment 9 Antoine Quint 2021-06-30 23:32:23 PDT
Committed r279451 (239307@main): <https://commits.webkit.org/239307@main>
Comment 10 Sam Weinig 2021-07-01 10:24:14 PDT
(In reply to Antoine Quint from comment #5)
> (In reply to Sam Weinig from comment #4)
> > Comment on attachment 432599 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=432599&action=review
> > 
> > > Source/WebCore/Modules/model-element/HTMLModelElement.mm:29
> > > +#if ENABLE(MODEL_ELEMENT)
> > 
> > We shouldn't use .mm for cross platform code like this. Please keep this a
> > .cpp file and factor out the objective-c bits into their own classes.
> 
> Right, so add a
> Source/WebCore/Modules/model-element/HTMLModelElementCocoa.mm with these
> bits?

I usually try to add some c++ wrapper class in its own files instead to avoid having multiple implementation files for the same header which is not something that is very understandable.