Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix sevalue_to_native function support JSBNativeDataHolder convert #16452

Merged
merged 3 commits into from
Nov 15, 2023

Conversation

xbpiao
Copy link
Contributor

@xbpiao xbpiao commented Oct 30, 2023

Re: #

Changelog

  • fix sevalue_to_native function support JSBNativeDataHolder convert

Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

test case :

        let url = "test";   // test.png
        let callback = (err: Error | null, asset: Asset) => {

            if (err)
                console.warn(err);

                if (asset instanceof ImageAsset) {
                let tex = new Texture2D();
                tex.reset({
                    width: asset.width,
                    height: asset.height,
                });
                tex.uploadData(asset.data);   // fix this line , in native code asset.data is JSBNativeDataHolder
                let sp = new SpriteFrame();
                sp.texture = tex;
                // use this SpriteFrame
            }
        };

        resources.load(url, Asset, callback);

@github-actions
Copy link

Interface Check Report

This pull request does not change any public interfaces !

@xbpiao
Copy link
Contributor Author

xbpiao commented Oct 30, 2023

test code :

        let url = "test";   // test.png
        let callback = (err: Error | null, asset: Asset) => {

            if (err)
                console.warn(err);

                if (asset instanceof ImageAsset) {
                let tex = new Texture2D();
                tex.reset({
                    width: asset.width,
                    height: asset.height,
                });
                tex.uploadData(asset.data);   // fix this line , in native code asset.data._data is JSBNativeDataHolder
                let sp = new SpriteFrame();
                sp.texture = tex;
                // use this SpriteFrame
            }
        };

        resources.load(url, Asset, callback);

read simple-texture.jsb.ts:

simpleTextureProto.uploadData = function (source, level = 0, arrayIndex = 0) {
    let data;
    if (source instanceof jsbWindow.HTMLCanvasElement) {
        // @ts-ignore
        data = source.data;
    } else if (source instanceof jsbWindow.HTMLImageElement) {
        // @ts-ignore
        data = source._data;                              // <------- JSBNativeDataHolder
    } else if (ArrayBuffer.isView(source)) {
        data = source.buffer;
    }
    oldUpdateDataFunc.call(this, data, level, arrayIndex);    // <------- call jsb_conversions.h  sevalue_to_native function convert
};

@minggo minggo requested a review from dumganhar November 9, 2023 02:16
@dumganhar
Copy link
Contributor

@cocos-robot run test cases

@dumganhar dumganhar merged commit 330b92a into cocos:v3.8.2 Nov 15, 2023
22 checks passed
@dumganhar
Copy link
Contributor

Merged. Thanks for the patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants