Skip to content

Commit

Permalink
cherry-pick: AOT: add jsb interface type (cocos#14368) (cocos#14544)
Browse files Browse the repository at this point in the history
* cherry-pick: AOT: add jsb interface type (cocos#14368)
  • Loading branch information
PPpro authored Mar 15, 2023
1 parent 2d02a9d commit cddfa8c
Show file tree
Hide file tree
Showing 38 changed files with 1,102 additions and 953 deletions.
3 changes: 1 addition & 2 deletions cc.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@
"cocos/render-scene/core/pass.ts": "cocos/render-scene/core/pass.jsb.ts",
"cocos/render-scene/core/program-lib.ts": "cocos/render-scene/core/program-lib.jsb.ts",
"cocos/render-scene/core/render-window.ts": "cocos/render-scene/core/render-window.jsb.ts",
"cocos/render-scene/core/sampler-lib.ts": "cocos/render-scene/core/sampler.jsb.ts",
"cocos/render-scene/scene/camera.ts": "cocos/render-scene/scene/camera.jsb.ts",
"cocos/render-scene/scene/model.ts": "cocos/render-scene/scene/model.jsb.ts",
"cocos/render-scene/core/render-scene.ts": "cocos/render-scene/core/render-scene.jsb.ts",
Expand All @@ -233,6 +232,7 @@
"cocos/render-scene/scene/reflection-probe.ts": "cocos/render-scene/scene/reflection-probe.jsb.ts",
"cocos/2d/renderer/native-2d.ts": "cocos/2d/renderer/native-2d.jsb.ts",
"cocos/gfx/base/pipeline-state.ts": "cocos/gfx/base/pipeline-state.jsb.ts",
"cocos/gfx/base/pipeline-sub-state.ts": "cocos/gfx/base/pipeline-sub-state.jsb.ts",
"cocos/gfx/index.ts": "cocos/gfx/index.jsb.ts",
"cocos/spine/index.ts": "cocos/spine/index.jsb.ts",
"cocos/dragon-bones/index.ts": "cocos/dragon-bones/index.jsb.ts",
Expand All @@ -252,7 +252,6 @@
"cocos/asset/assets/effect-asset.ts": "cocos/asset/assets/effect-asset.jsb.ts",
"cocos/asset/assets/image-asset.ts": "cocos/asset/assets/image-asset.jsb.ts",
"cocos/asset/assets/texture-base.ts": "cocos/asset/assets/texture-base.jsb.ts",
"cocos/asset/assets/texture-asset.ts": "cocos/asset/assets/texture-asset.jsb.ts",
"cocos/asset/assets/texture-2d.ts": "cocos/asset/assets/texture-2d.jsb.ts",
"cocos/asset/assets/texture-cube.ts": "cocos/asset/assets/texture-cube.jsb.ts",
"cocos/asset/assets/material.ts": "cocos/asset/assets/material.jsb.ts",
Expand Down
26 changes: 20 additions & 6 deletions cocos/2d/renderer/native-2d.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,27 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import type {
NativeRenderDrawInfo as N2dNativeRenderDrawInfo,
NativeBatcher2d as N2dNativeBatcher2d,
NativeUIMeshBuffer as N2dNativeUIMeshBuffer,
NativeRenderEntity as N2dNativeRenderEntity,
NativeUIModelProxy as N2dNativeUIModelProxy,
NativeStencilManager as N2dNativeStencilManager,
} from './native-2d';

// 2d
declare const n2d: any;

export const NativeRenderDrawInfo = n2d.RenderDrawInfo;
export const NativeBatcher2d = n2d.Batcher2d;
export const NativeUIMeshBuffer = n2d.UIMeshBuffer;
export const NativeRenderEntity = n2d.RenderEntity;
export const NativeUIModelProxy = n2d.UIModelProxy;
export const NativeStencilManager = n2d.StencilManager;
export const NativeRenderDrawInfo: typeof N2dNativeRenderDrawInfo = n2d.RenderDrawInfo;
export type NativeRenderDrawInfo = N2dNativeRenderDrawInfo;
export const NativeBatcher2d: typeof N2dNativeBatcher2d = n2d.Batcher2d;
export type NativeBatcher2d = N2dNativeBatcher2d;
export const NativeUIMeshBuffer: typeof N2dNativeUIMeshBuffer = n2d.UIMeshBuffer;
export type NativeUIMeshBuffer = N2dNativeUIMeshBuffer;
export const NativeRenderEntity: typeof N2dNativeRenderEntity = n2d.RenderEntity;
export type NativeRenderEntity = N2dNativeRenderEntity;
export const NativeUIModelProxy: typeof N2dNativeUIModelProxy = n2d.UIModelProxy;
export type NativeUIModelProxy = N2dNativeUIModelProxy;
export const NativeStencilManager: typeof N2dNativeStencilManager = n2d.StencilManager;
export type NativeStencilManager = N2dNativeStencilManager;
17 changes: 9 additions & 8 deletions cocos/3d/assets/mesh.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
import { cclegacy, Vec3 } from '../../core';
import { patch_cc_Mesh } from '../../native-binding/decorators';
import type { Mesh as JsbMesh } from './mesh';

declare const jsb: any;

Expand All @@ -33,15 +34,15 @@ export declare namespace Mesh {
count: number;
stride: number;
}
export type IVertexBundle = jsb.Mesh.IVertexBundle;
export type ISubMesh = jsb.Mesh.ISubMesh;
export type IDynamicInfo = jsb.Mesh.IDynamicInfo;
export type IDynamicStruct = jsb.Mesh.IDynamicStruct;
export type IStruct = jsb.Mesh.IStruct;
export type ICreateInfo = jsb.Mesh.ICreateInfo;
export type IVertexBundle = JsbMesh.IVertexBundle;
export type ISubMesh = JsbMesh.ISubMesh;
export type IDynamicInfo = JsbMesh.IDynamicInfo;
export type IDynamicStruct = JsbMesh.IDynamicStruct;
export type IStruct = JsbMesh.IStruct;
export type ICreateInfo = JsbMesh.ICreateInfo;
}
export type Mesh = jsb.Mesh;
export const Mesh = jsb.Mesh;
export type Mesh = JsbMesh;
export const Mesh: typeof JsbMesh = jsb.Mesh;

const IStructProto: any = jsb.Mesh.IStruct.prototype;

Expand Down
7 changes: 5 additions & 2 deletions cocos/3d/assets/skeleton.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ import { CCString, cclegacy, Mat4 } from '../../core';
import { DataPoolManager } from '../skeletal-animation/data-pool-manager';
import { Asset } from '../../asset/assets/asset';
import { patch_cc_Skeleton } from '../../native-binding/decorators';
import type { Skeleton as JsbSkeleton } from './skeleton';

export const Skeleton = jsb.Skeleton;
export type Skeleton = jsb.Skeleton;
declare const jsb: any;

export const Skeleton: typeof JsbSkeleton = jsb.Skeleton;
export type Skeleton = JsbSkeleton;
cclegacy.Skeleton = Skeleton;
const skeletonProto: any = Skeleton.prototype;

Expand Down
6 changes: 5 additions & 1 deletion cocos/3d/misc/create-mesh.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@
THE SOFTWARE.
*/
import { cclegacy } from "../../core";
import type { MeshUtils as JsbMeshUtils } from './create-mesh';

export const MeshUtils = jsb.MeshUtils;
declare const jsb: any;

export const MeshUtils: typeof JsbMeshUtils = jsb.MeshUtils;
export type MeshUtils = JsbMeshUtils;
export const createMesh = MeshUtils.createMesh;
export const createDynamicMesh = MeshUtils.createDynamicMesh;
cclegacy.MeshUtils = jsb.MeshUtils;
Expand Down
6 changes: 5 additions & 1 deletion cocos/3d/models/baked-skinning-model.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ import { Mesh } from '../assets/mesh';
import { Node } from '../../scene-graph/node'
import { AnimationClip } from "../../animation";
import { IJointTextureHandle } from '../skeletal-animation/skeletal-animation-utils';
import type { BakedSkinningModel as JsbBakedSkinningModel } from './baked-skinning-model';

export const BakedSkinningModel = jsb.BakedSkinningModel;
declare const jsb: any;

export const BakedSkinningModel: typeof JsbBakedSkinningModel = jsb.BakedSkinningModel;
export type BakedSkinningModel = JsbBakedSkinningModel;
cclegacy.BakedSkinningModel = jsb.BakedSkinningModel;
const MorphModel = jsb.MorphModel;

Expand Down
6 changes: 5 additions & 1 deletion cocos/3d/models/morph-model.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
*/

import { cclegacy } from "../../core";
import type { MorphModel as JsbMorphModel } from './morph-model';

export const MorphModel = jsb.MorphModel;
declare const jsb: any;

export const MorphModel: typeof JsbMorphModel = jsb.MorphModel;
export type MorphModel = JsbMorphModel;
cclegacy.MorphModel = jsb.MorphModel;
6 changes: 5 additions & 1 deletion cocos/3d/models/skinning-model.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
*/

import { cclegacy } from "../../core";
import type { SkinningModel as JsbSkinningModel } from './skinning-model';

export const SkinningModel = jsb.SkinningModel;
declare const jsb: any;

export const SkinningModel: typeof JsbSkinningModel = jsb.SkinningModel;
export type SkinningModel = JsbSkinningModel;
cclegacy.SkinningModel = jsb.SkinningModel;
5 changes: 3 additions & 2 deletions cocos/asset/asset-manager/builtin-res-mgr.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
THE SOFTWARE.
*/

import { TEST, EDITOR } from 'internal:constants';
import { SpriteFrame } from '../../2d/assets/sprite-frame';
import type { ImageSource } from '../assets/image-asset';
import assetManager from '../asset-manager/asset-manager';
import { BuiltinBundleName } from '../asset-manager/shared';
import { TEST, EDITOR } from 'internal:constants';
import Bundle from '../asset-manager/bundle';
import { Settings, settings, cclegacy } from '../../core';
import releaseManager from '../asset-manager/release-manager';
import type { BuiltinResMgr as JsbBuiltinResMgr } from './builtin-res-mgr';

declare const jsb: any;

Expand Down Expand Up @@ -152,5 +153,5 @@ builtinResMgrProto.loadBuiltinAssets = function () {
});
}

const builtinResMgr = cclegacy.builtinResMgr = BuiltinResMgr.getInstance();
const builtinResMgr = cclegacy.builtinResMgr = BuiltinResMgr.getInstance() as JsbBuiltinResMgr;
export { builtinResMgr };
2 changes: 1 addition & 1 deletion cocos/asset/asset-manager/builtin-res-mgr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { Settings, settings, cclegacy } from '../../core';
import releaseManager from './release-manager';
import { Material } from '../assets';

class BuiltinResMgr {
export class BuiltinResMgr {
protected _resources: Record<string, Asset> = {};
protected _materialsToBeCompiled: Material[] = [];

Expand Down
6 changes: 3 additions & 3 deletions cocos/asset/assets/asset.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import { cclegacy, js, _decorator, path, jsbUtils, CallbacksInvoker, applyMixins } from '../../core';
import { getUrlWithUuid } from '../asset-manager/helper';
import { patch_cc_Asset } from '../../native-binding/decorators';
import type { Asset as JsbAsset } from './asset';

declare const jsb: any;

Expand Down Expand Up @@ -114,9 +115,8 @@ assetProto.toString = function () {

assetProto.createNode = null!;

// @ts-ignore
export type Asset = jsb.Asset;
export const Asset = jsb.Asset;
export type Asset = JsbAsset;
export const Asset: typeof JsbAsset = jsb.Asset;

cclegacy.Asset = jsb.Asset;

Expand Down
10 changes: 7 additions & 3 deletions cocos/asset/assets/image-asset.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import { ALIPAY, XIAOMI, JSB, TEST, BAIDU } from 'internal:constants';

import { ALIPAY, XIAOMI, JSB, TEST, BAIDU, EDITOR } from 'internal:constants';
import { Format, FormatFeatureBit, deviceManager } from '../../gfx';
import { PixelFormat } from './asset-enum';
import { sys, macro, warnID, cclegacy } from '../../core';
import { patch_cc_ImageAsset } from '../../native-binding/decorators';
import './asset';
import type { ImageAsset as JsbImageAsset } from './image-asset';

declare const jsb: any;

export type ImageAsset = jsb.ImageAsset;
export const ImageAsset = jsb.ImageAsset;
export type ImageAsset = JsbImageAsset;
export const ImageAsset: typeof JsbImageAsset = jsb.ImageAsset;
const jsbWindow = jsb.window;

export interface IMemoryImageSource {
Expand Down
6 changes: 3 additions & 3 deletions cocos/asset/assets/material.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { PassOverrides, MacroRecord, MaterialProperty } from '../../render-scene
import { Color, Mat3, Mat4, Quat, Vec2, Vec3, Vec4, cclegacy } from '../../core';
import './asset';
import { patch_cc_Material } from '../../native-binding/decorators';
import type { Material as JsbMaterial } from './material';

/**
* @en The basic infos for material initialization.
Expand Down Expand Up @@ -254,9 +255,8 @@ matProto.getProperty = function (name: string, passIdx?: number) {
return ret || val;
};

// @ts-ignore
export type Material = jsb.Material;
export const Material = jsb.Material;
export type Material = JsbMaterial;
export const Material: typeof JsbMaterial = jsb.Material;
cclegacy.Material = Material;

const materialProto: any = Material.prototype;
Expand Down
6 changes: 3 additions & 3 deletions cocos/asset/assets/render-texture.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ import { cclegacy } from '../../core';
import { Filter, PixelFormat, WrapMode } from './asset-enum';
import './asset';
import { patch_cc_RenderTexture } from '../../native-binding/decorators';
import type { RenderTexture as JsbRenderTexture } from './render-texture';

declare const jsb: any;
const renderTextureProto: any = jsb.RenderTexture.prototype;
const textureBaseProto: any = jsb.TextureBase.prototype;

renderTextureProto.createNode = null!;

// @ts-ignore
export type RenderTexture = jsb.RenderTexture;
export const RenderTexture: any = jsb.RenderTexture;
export type RenderTexture = JsbRenderTexture;
export const RenderTexture: typeof JsbRenderTexture = jsb.RenderTexture;

RenderTexture.Filter = Filter;
RenderTexture.PixelFormat = PixelFormat;
Expand Down
7 changes: 5 additions & 2 deletions cocos/asset/assets/rendering-sub-mesh.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

import { Vec3 } from "../../core";
import { Attribute, PrimitiveMode, Buffer } from "../../gfx";
import type { RenderingSubMesh as JsbRenderingSubMesh } from './rendering-sub-mesh';

declare const jsb: any;

/**
* @en Array views for index buffer
Expand Down Expand Up @@ -71,8 +74,8 @@ export interface IFlatBuffer {
buffer: Uint8Array;
}

export type RenderingSubMesh = jsb.RenderingSubMesh;
export const RenderingSubMesh = jsb.RenderingSubMesh;
export type RenderingSubMesh = JsbRenderingSubMesh;
export const RenderingSubMesh: typeof JsbRenderingSubMesh = jsb.RenderingSubMesh;

const renderingSubMeshProto = RenderingSubMesh.prototype;

Expand Down
7 changes: 5 additions & 2 deletions cocos/asset/assets/scene-asset.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@
import { cclegacy } from '../../core';
import { patch_cc_SceneAsset } from '../../native-binding/decorators';
import './asset';
import type { SceneAsset as JsbSceneAsset } from './scene-asset';

export const SceneAsset = jsb.SceneAsset;
export type SceneAsset = jsb.SceneAsset;
declare const jsb: any;

export const SceneAsset: typeof JsbSceneAsset = jsb.SceneAsset;
export type SceneAsset = JsbSceneAsset;

cclegacy.SceneAsset = SceneAsset;

Expand Down
6 changes: 3 additions & 3 deletions cocos/asset/assets/simple-texture.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import dependUtil from '../asset-manager/depend-util';
import { js, macro, cclegacy } from '../../core';
import './texture-base';
import { patch_cc_SimpleTexture } from '../../native-binding/decorators';
import type { SimpleTexture as JsbSimpleTexture } from './simple-texture';

declare const jsb: any;

// @ts-ignore
export type SimpleTexture = jsb.SimpleTexture;
export const SimpleTexture: any = jsb.SimpleTexture;
export type SimpleTexture = JsbSimpleTexture;
export const SimpleTexture: typeof JsbSimpleTexture = jsb.SimpleTexture;

const jsbWindow = jsb.window;

Expand Down
8 changes: 6 additions & 2 deletions cocos/asset/assets/texture-2d.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,24 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

import { EDITOR, TEST } from 'internal:constants'
import { ImageAsset } from './image-asset';
import { SimpleTexture } from './simple-texture';
import { TextureBase } from './texture-base.jsb';
import { js, cclegacy } from '../../core';
import { Filter, PixelFormat, WrapMode } from './asset-enum';
import './simple-texture';
import { patch_cc_Texture2D } from '../../native-binding/decorators';
import type { Texture2D as JsbTexture2D } from './texture-2d';

declare const jsb: any;
const texture2DProto: any = jsb.Texture2D.prototype;

texture2DProto.createNode = null!;

export type Texture2D = jsb.Texture2D;
export const Texture2D: any = jsb.Texture2D;
export type Texture2D = JsbTexture2D;
export const Texture2D: typeof JsbTexture2D = jsb.Texture2D;

Texture2D.Filter = Filter;
Texture2D.PixelFormat = PixelFormat;
Expand Down
8 changes: 6 additions & 2 deletions cocos/asset/assets/texture-base.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

import { TEST, EDITOR } from 'internal:constants';
import { deviceManager } from '../../gfx';
import { cclegacy } from '../../core';
import { Filter, PixelFormat, WrapMode } from './asset-enum';
import './asset';
import { patch_cc_TextureBase } from '../../native-binding/decorators';
import type { TextureBase as JsbTextureBase } from './texture-base';

declare const jsb: any;

const textureBaseProto: any = jsb.TextureBase.prototype;

Expand Down Expand Up @@ -78,8 +82,8 @@ textureBaseProto._getGFXPixelFormat = function (format) {

textureBaseProto.createNode = null!;

export type TextureBase = jsb.TextureBase;
export const TextureBase: any = jsb.TextureBase;
export type TextureBase = JsbTextureBase;
export const TextureBase: typeof JsbTextureBase = jsb.TextureBase;

TextureBase.Filter = Filter;
TextureBase.PixelFormat = PixelFormat;
Expand Down
Loading

0 comments on commit cddfa8c

Please sign in to comment.