Merge remote-tracking branch 'remotes/official/v3.8.7' into v3.8.8

This commit is contained in:
Zhou Zhenglong
2025-08-06 15:50:28 +08:00
62 changed files with 1315 additions and 647 deletions
@@ -6,7 +6,7 @@ on:
vulkan_sdk_version:
description: 'Vulkan SDK version'
type: string
default: '1.2.189.0'
default: '1.3.243.0'
required: true
jobs:
+23 -7
View File
@@ -17,7 +17,7 @@ jobs:
name: "Windows"
if:
(! contains(github.event.pull_request.body, '[X] does not change any runtime related code or build configuration'))
runs-on: windows-2019
runs-on: windows-2022
strategy:
fail-fast: false
matrix:
@@ -35,7 +35,7 @@ jobs:
- name: Install deps
uses: humbletim/setup-vulkan-sdk@523828e49cd4afabce369c39c7ee6543a2b7a735
with:
vulkan-query-version: 1.2.189.0
vulkan-query-version: 1.3.243.0
vulkan-components: Vulkan-Headers, Vulkan-Loader
vulkan-use-cache: false
- name: Compile win64
@@ -60,7 +60,7 @@ jobs:
cd build-win64
RES_DIR=${GITHUB_WORKSPACE//\\//}/templates/windows/build-win64
COCOS_X_PATH=${GITHUB_WORKSPACE//\\//}/native
cmake ../ -G"Visual Studio 16 2019" -DRES_DIR=$RES_DIR -DCOCOS_X_PATH=$COCOS_X_PATH -Ax64
cmake ../ -G"Visual Studio 17 2022" -DRES_DIR=$RES_DIR -DCOCOS_X_PATH=$COCOS_X_PATH -Ax64
cmake --build . --config ${{ matrix.config.buildtype }}
echo "Compile Win64 ${{ matrix.config.buildtype }} Done!"
@@ -258,7 +258,10 @@ jobs:
fail-fast: false
matrix:
config:
- { arch: arm64-v8a }
- { arch: arm64-v8a, jsEngine: V8 }
- { arch: arm64-v8a, jsEngine: ARK }
- { arch: arm64-v8a, jsEngine: JSVM }
steps:
- name: Show PATH env
run: |
@@ -391,9 +394,22 @@ jobs:
echo "set(CMAKE_CXX_STANDARD_REQUIRED ON)" >> build-oh/proj/cfg.cmake
echo "set(COCOS_X_PATH $NATIVE_ROOT)" >> build-oh/proj/cfg.cmake
echo "set(CC_EXECUTABLE_NAME \"\")" >> build-oh/proj/cfg.cmake
echo "set(USE_SE_V8 ON)" >> build-oh/proj/cfg.cmake
echo "set(USE_SE_NAPI OFF)" >> build-oh/proj/cfg.cmake
echo "set(USE_SE_JSVM OFF)" >> build-oh/proj/cfg.cmake
if [ "${{ matrix.config.jsEngine }}" = "V8" ]; then
echo "=============== JsEngine: V8 ==============="
echo "set(USE_SE_V8 ON)" >> build-oh/proj/cfg.cmake
echo "set(USE_SE_NAPI OFF)" >> build-oh/proj/cfg.cmake
echo "set(USE_SE_JSVM OFF)" >> build-oh/proj/cfg.cmake
elif [ "${{ matrix.config.jsEngine }}" = "JSVM" ]; then
echo "=============== JsEngine: JSVM ==============="
echo "set(USE_SE_V8 OFF)" >> build-oh/proj/cfg.cmake
echo "set(USE_SE_NAPI OFF)" >> build-oh/proj/cfg.cmake
echo "set(USE_SE_JSVM ON)" >> build-oh/proj/cfg.cmake
else
echo "=============== JsEngine: ARK ==============="
echo "set(USE_SE_V8 OFF)" >> build-oh/proj/cfg.cmake
echo "set(USE_SE_NAPI ON)" >> build-oh/proj/cfg.cmake
echo "set(USE_SE_JSVM OFF)" >> build-oh/proj/cfg.cmake
fi
echo "=============== cat build-oh/proj/cfg.cmake ==============="
cat build-oh/proj/cfg.cmake
@@ -62,7 +62,7 @@ jobs:
- name: Install deps
uses: humbletim/setup-vulkan-sdk@523828e49cd4afabce369c39c7ee6543a2b7a735
with:
vulkan-query-version: 1.2.189.0
vulkan-query-version: 1.3.243.0
vulkan-components: Vulkan-Headers, Vulkan-Loader
vulkan-use-cache: false
- name: gen simulator
+2 -2
View File
@@ -14,7 +14,7 @@ concurrency:
jobs:
win_gen_simulator:
runs-on: windows-2019
runs-on: windows-2022
if:
(! contains(github.event.pull_request.body, '[X] does not change any runtime related code or build configuration'))
name: Windows
@@ -36,7 +36,7 @@ jobs:
- name: Install deps
uses: humbletim/setup-vulkan-sdk@523828e49cd4afabce369c39c7ee6543a2b7a735
with:
vulkan-query-version: 1.2.189.0
vulkan-query-version: 1.3.243.0
vulkan-components: Vulkan-Headers, Vulkan-Loader
vulkan-use-cache: false
- name: gen simulator
+1 -1
View File
@@ -1875,7 +1875,7 @@ We don't currently support conversion of \`CubicSplineQuatValue\`.
### 3936
Instancing/Batching enabled for non-baked skinning model '%s', this may result in unexpected rendering artifacts. Consider turning it off in the material if you do not intend to do this.
Instancing/Batching enabled for non-baked skinning model or used AnimationController '%s', this may result in unexpected rendering artifacts. Consider turning it off in the material if you do not intend to do this.
### 3937
+4 -4
View File
@@ -26,7 +26,7 @@ import { Node } from '../../scene-graph/node';
import { Input, input } from '../../input';
import { Event, EventMouse, EventTouch } from '../../input/types';
import { DispatcherEventType, NodeEventProcessor } from '../../scene-graph/node-event-processor';
import { js } from '../../core';
import { CCObjectFlags, js } from '../../core';
import { InputEventType } from '../../input/types/event-enum';
import { EventDispatcherPriority, IEventDispatcher } from '../../input/input';
@@ -44,7 +44,7 @@ const touchEvents = [
InputEventType.TOUCH_END,
InputEventType.TOUCH_CANCEL,
];
const isDestroy = (node: Node): boolean => !!((node._objFlags & CCObjectFlags.Destroying) || (node._objFlags & CCObjectFlags.Destroyed));
class PointerEventDispatcher implements IEventDispatcher {
public priority: EventDispatcherPriority = EventDispatcherPriority.UI;
@@ -227,9 +227,9 @@ class PointerEventDispatcher implements IEventDispatcher {
private _sortByPriority (p1: NodeEventProcessor, p2: NodeEventProcessor): number {
const node1: Node = p1.node;
const node2: Node = p2.node;
if (!p2 || !node2 || !node2.activeInHierarchy || !node2._getUITransformComp()) {
if (!p2 || !node2 || isDestroy(node2) || !node2.activeInHierarchy || !node2._getUITransformComp()) {
return -1;
} else if (!p1 || !node1 || !node1.activeInHierarchy || !node1._getUITransformComp()) {
} else if (!p1 || !node1 || isDestroy(node1) || !node1.activeInHierarchy || !node1._getUITransformComp()) {
return 1;
}
+56 -16
View File
@@ -22,6 +22,60 @@
THE SOFTWARE.
*/
/**
* bin package format example.
|PACK_BIN_TYPE - 4bytes|
|VERSION - 4bytes|
|FILES_COUNT - 4bytes|
|FILE_1_OFFSET - 4bytes|
|FILE_1_SIZE - 4bytes|
|FILE_2_OFFSET - 4bytes|
|FILE_2_SIZE - 4bytes|
...
|FILE_N_OFFSET - 4bytes|
|FILE_N_SIZE - 4bytes|
|PACKED_BIN|
*/
const PACK_BIN_TYPE = 'BINP';
const VERSION = 2;
const UNIT_SIZE = 4;
const LITTLE_ENDIAN = true;
type UnpackFunc = (arrayBuffer: ArrayBuffer, dataView: DataView) => Uint8Array[];
export function binPackageUnpack (arrayBuffer: ArrayBuffer): Uint8Array[] {
const dataView = new DataView(arrayBuffer, 0, arrayBuffer.byteLength);
const packBinType = String.fromCharCode(...new Uint8Array(arrayBuffer.slice(0, UNIT_SIZE)));
if (packBinType !== PACK_BIN_TYPE) {
throw new Error('Invalid bin package format');
}
const version = dataView.getUint32(UNIT_SIZE, LITTLE_ENDIAN);
if (version !== VERSION) {
return compatibleOlderVersion(arrayBuffer, dataView, version);
}
const filesCount = dataView.getUint32(UNIT_SIZE * 2, LITTLE_ENDIAN);
const filesPosition: { offset: number, size: number }[] = [];
const headOffset = UNIT_SIZE * (3 + filesCount * 2);
for (let i = 0; i < filesCount; i++) {
const offset = dataView.getUint32(UNIT_SIZE * (3 + i * 2), LITTLE_ENDIAN) + headOffset;
const size = dataView.getUint32(UNIT_SIZE * (3 + i * 2 + 1), LITTLE_ENDIAN);
filesPosition.push({ offset, size });
}
return filesPosition.map(({ offset, size }) => new Uint8Array(arrayBuffer, offset, size));
}
function compatibleOlderVersion (arrayBuffer: ArrayBuffer, dataView: DataView, version: number): Uint8Array[] {
const map: Record<number, UnpackFunc> = {
1: unpack_v1,
};
return map[version](arrayBuffer, dataView);
}
/**
* bin package format example.
|PACK_BIN_TYPE - 4bytes|
@@ -33,23 +87,9 @@
|FILE_N_SIZE - 4bytes|
|PACKED_BIN|
*/
const PACK_BIN_TYPE = 'BINP';
const VERSION = 1;
const UNIT_SIZE = 4;
const LITTLE_ENDIAN = true;
export function binPackageUnpack (arrayBuffer: ArrayBuffer): Uint8Array[] {
const dataView = new DataView(arrayBuffer, 0, arrayBuffer.byteLength);
const packBinType = String.fromCharCode(...new Uint8Array(arrayBuffer.slice(0, UNIT_SIZE)));
const version = dataView.getUint32(UNIT_SIZE, LITTLE_ENDIAN);
if (packBinType !== PACK_BIN_TYPE || version !== VERSION) {
throw new Error('Invalid bin package format');
}
function unpack_v1 (arrayBuffer: ArrayBuffer, dataView: DataView): Uint8Array[] {
const filesCount = dataView.getUint32(UNIT_SIZE * 2, LITTLE_ENDIAN);
const filesPosition: {offset: number, size: number}[] = [];
const filesPosition: { offset: number, size: number }[] = [];
let offset = UNIT_SIZE * (3 + filesCount);
for (let i = 0; i < filesCount; i++) {
+14 -6
View File
@@ -69,18 +69,26 @@ const downloadArrayBuffer = (url: string, options: Record<string, any>, onComple
};
const downloadCCONB = (url: string, options: Record<string, any>, onComplete: ((err: Error | null, data?: CCON | null) => void)): void => {
url = url.replace('.cconb', '.bin');
downloader._downloadArrayBuffer(url, options, (err, arrayBuffer: ArrayBuffer): void => {
if (err) {
onComplete(err);
return;
}
const handleArrayBuffer = (arrayBuffer: ArrayBuffer, onComplete: ((err: Error | null, data?: CCON | null) => void)): void => {
try {
const ccon = decodeCCONBinary(new Uint8Array(arrayBuffer));
onComplete(null, ccon);
} catch (err) {
onComplete(err as Error);
}
};
downloader._downloadArrayBuffer(url.replace('.cconb', '.bin'), options, (err, arrayBuffer: ArrayBuffer): void => {
if (err) {
downloader._downloadArrayBuffer(url, options, (err, arrayBuffer: ArrayBuffer): void => {
if (err) {
onComplete(err);
return;
}
handleArrayBuffer(arrayBuffer, onComplete);
});
return;
}
handleArrayBuffer(arrayBuffer, onComplete);
});
};
-8
View File
@@ -891,14 +891,6 @@ export function genHashValue (pass: RasterPass): void {
hashCode += hashCombineKey(compute.shaderStageFlags);
}
}
hashCode += hashCombineKey(pass.width);
hashCode += hashCombineKey(pass.height);
hashCode += hashCombineKey(pass.viewport.left);
hashCode += hashCombineKey(pass.viewport.top);
hashCode += hashCombineKey(pass.viewport.width);
hashCode += hashCombineKey(pass.viewport.height);
hashCode += hashCombineKey(pass.viewport.minDepth);
hashCode += hashCombineKey(pass.viewport.maxDepth);
hashCode += hashCombineKey(pass.showStatistics ? 1 : 0);
pass.hashValue = hashCombineStr(hashCode);
}
+10 -32
View File
@@ -256,30 +256,9 @@ export class WebRenderQueueBuilder extends WebSetter implements RenderQueueBuild
addSceneOfCamera (camera: Camera, light: LightInfo, sceneFlags = SceneFlags.NONE, name = 'Camera'): void {
const lightTarget = light.light;
const sceneData = renderGraphPool.createSceneData(
camera.scene,
camera,
sceneFlags,
lightTarget && !(sceneFlags & SceneFlags.SHADOW_CASTER) ? CullingFlags.CAMERA_FRUSTUM | CullingFlags.LIGHT_BOUNDS : CullingFlags.CAMERA_FRUSTUM,
lightTarget,
);
this._renderGraph.addVertex<RenderGraphValue.Scene>(RenderGraphValue.Scene, sceneData, name, '', renderGraphPool.createRenderData(), !DEBUG, this._vertID);
const layoutName = this.getParentLayout();
const scene: Scene = cclegacy.director.getScene();
setCameraUBOValues(
this,
camera,
this._pipeline,
camera.scene || (scene ? scene.renderScene : null),
layoutName,
);
if (sceneFlags & SceneFlags.SHADOW_CASTER || (lightTarget && lightTarget.type !== LightType.DIRECTIONAL)) {
setShadowUBOLightView(this, camera, lightTarget!, light.level, layoutName);
} else {
setShadowUBOView(this, camera, layoutName);
}
this.addScene(camera, sceneFlags, lightTarget);
}
addScene (camera: Camera, sceneFlags = SceneFlags.NONE, light: Light | undefined = undefined, scene: RenderScene | undefined = undefined): SceneBuilder {
addScene (camera: Camera, sceneFlags = SceneFlags.NONE, light: Light | undefined | null = null, scene: RenderScene | undefined = undefined): SceneBuilder {
const sceneData = renderGraphPool.createSceneData(
scene || camera.scene,
camera,
@@ -407,6 +386,14 @@ export class WebRenderQueueBuilder extends WebSetter implements RenderQueueBuild
}
}
addDraw2D (camera: Camera): void {
const layoutName = this.getParentLayout();
setCameraUBOValues(
this,
camera,
this._pipeline,
camera.scene,
layoutName,
);
this._renderGraph.addVertex<RenderGraphValue.Blit>(
RenderGraphValue.Blit,
renderGraphPool.createBlit(emptyMaterial, this._renderGraph.N, SceneFlags.NONE, camera, BlitType.DRAW_2D),
@@ -419,15 +406,6 @@ export class WebRenderQueueBuilder extends WebSetter implements RenderQueueBuild
}
addProfiler (camera: Camera): void {
const passOrSubpassId = this._renderGraph.getParent(this._vertID);
this._renderGraph.addVertex<RenderGraphValue.Blit>(
RenderGraphValue.Blit,
renderGraphPool.createBlit(emptyMaterial, this._renderGraph.N, SceneFlags.NONE, camera, BlitType.DRAW_PROFILE),
'DrawProfiler',
'',
emptyRenderData,
!DEBUG,
this._vertID,
);
const queueId = this._renderGraph.addVertex<RenderGraphValue.Queue>(
RenderGraphValue.Queue,
this._queue,
+1
View File
@@ -61,6 +61,7 @@ export class UIPhase {
for (let j = 0; j < count; j++) {
const pass = batch.passes[j];
if (pass.phase !== this._phaseID) continue;
if (pass.passID !== 0xFFFFFFFF) continue;
const shader = batch.shaders[j];
const inputAssembler = batch.inputAssembler!;
const pso = PipelineStateManager.getOrCreatePipelineState(device, pass, shader, renderPass, inputAssembler);
+19 -5
View File
@@ -26,7 +26,7 @@ import { getError, cclegacy } from '../core';
import { notepackDecode } from '../../external/deserialize/notepack_decode';
import { notepackEncode } from '../../external/deserialize/notepack_encode';
const VERSION = 1;
const VERSION = 2;
const MAGIC = 0x4E4F4343;
@@ -100,9 +100,6 @@ export function decodeCCONBinary (bytes: Uint8Array): CCON {
}
const version = dataView.getUint32(4, true);
if (version !== VERSION) {
throw new InvalidCCONError(getError(13101, version));
}
const dataByteLength = dataView.getUint32(8, true);
if (dataByteLength !== dataView.byteLength) {
@@ -117,7 +114,12 @@ export function decodeCCONBinary (bytes: Uint8Array): CCON {
chunksStart += jsonDataLength;
let json: unknown;
try {
json = notepackDecode(jsonData);
if (version === 1) {
const jsonString = decodeJson(jsonData);
json = JSON.parse(jsonString);
} else if (version === 2) {
json = notepackDecode(jsonData);
}
} catch (err) {
throw new InvalidCCONError(err as string);
}
@@ -157,6 +159,18 @@ interface BufferConstructor {
from(buffer: ArrayBuffer, byteOffset?: number, byteLength?: number): Buffer;
}
function decodeJson (data: Uint8Array): string {
if (typeof TextDecoder !== 'undefined') {
return new TextDecoder().decode(data);
} else if ('Buffer' in globalThis) {
const { Buffer } = (globalThis as unknown as { Buffer: BufferConstructor });
// eslint-disable-next-line no-buffer-constructor
return Buffer.from(data.buffer, data.byteOffset, data.byteLength).toString();
} else {
throw new Error(getError(13104));
}
}
export class InvalidCCONError extends Error { }
export class BufferBuilder {
+16 -5
View File
@@ -36,6 +36,13 @@ import { Color, EPSILON, Vec3 } from '../../core';
import type { MaterialInstance } from '../../render-scene';
import type { IBatcher } from '../../2d/renderer/i-batcher';
/**
* If Spine instance counts exceeding thresholds cause issues, first adjust the ADJUST_SIZE_RATE value.
Going forward, we need to implement independent memory management for Spine that bypasses the chunk approach.
Similar to native IOBuffers where populated content transfers directly to GPU buffers without going through static_vb_accessor.
For now, provide the minimal viable change.
*/
const ADJUST_SIZE_RATE = 1.1;
const _slotColor = new Color(0, 0, 255, 255);
const _boneColor = new Color(255, 0, 0, 255);
const _originColor = new Color(0, 255, 0, 255);
@@ -151,10 +158,12 @@ function realTimeTraverse (comp: Skeleton): void {
if (!rd || vc < 1 || ic < 1) return;
if (rd.vertexCount !== vc || rd.indexCount !== ic) {
rd.resize(vc, ic);
if (rd.vertexCount < vc || rd.indexCount < ic) {
rd.resize(Math.ceil(vc * ADJUST_SIZE_RATE), Math.ceil(ic * ADJUST_SIZE_RATE));
}
rd.indices = new Uint16Array(ic);
comp._vLength = vc * Float32Array.BYTES_PER_ELEMENT * floatStride;
comp._vBuffer = new Uint8Array(rd.chunk.vb.buffer, rd.chunk.vb.byteOffset, Float32Array.BYTES_PER_ELEMENT * rd.chunk.vb.length);
comp._vBuffer = new Uint8Array(rd.chunk.vb.buffer, rd.chunk.vb.byteOffset, comp._vLength);
comp._iLength = Uint16Array.BYTES_PER_ELEMENT * ic;
comp._iBuffer = new Uint8Array(rd.indices.buffer);
}
@@ -178,7 +187,7 @@ function realTimeTraverse (comp: Skeleton): void {
for (let i = 0; i < count; i += 5) {
indexCount = data.get(i + 3);
const material = _getSlotMaterial(data.get(i + 4) as number, comp);
comp.requestDrawData(material, textures.get(i / 5), indexOffset, indexCount);
comp.requestDrawData(material, textures.get(i / 5) as string, indexOffset, indexCount);
indexOffset += indexCount;
}
@@ -272,7 +281,9 @@ function cacheTraverse (comp: Skeleton): void {
const rd = comp.renderData;
if (!rd || vc < 1 || ic < 1) return;
if (rd.vertexCount !== vc || rd.indexCount !== ic) {
rd.resize(vc, ic);
if (rd.vertexCount < vc || rd.indexCount < ic) {
rd.resize(Math.ceil(vc * ADJUST_SIZE_RATE), Math.ceil(ic * ADJUST_SIZE_RATE));
}
rd.indices = new Uint16Array(ic);
}
@@ -323,7 +334,7 @@ function cacheTraverse (comp: Skeleton): void {
const material = _getSlotMaterial(mesh.blendMode as number, comp);
const textureID = mesh.textureID;
indexCount = mesh.iCount;
comp.requestDrawData(material, textureID, indexOffset, indexCount);
comp.requestDrawData(material, textureID as string, indexOffset, indexCount);
indexOffset += indexCount;
}
+7
View File
@@ -647,6 +647,13 @@ export class Skeleton extends UIRenderer {
this._markForUpdateRenderData();
}
/**
* @deprecated Since v3.8.7, it will be removed in the future.
* We are deprecating the `customMaterialInstance` field because it leads to shared material state across all slots,
* causing unexpected behavior (like the last blendMode change affecting all slots).
* Workaround:
* Switch to customMaterial. Whenever its value is modified, immediately call updateMaterial at the exact point of change.
*/
get customMaterialInstance (): MaterialInstance | null {
if (!this._customMaterial) {
return null;
+4 -4
View File
@@ -457,8 +457,8 @@ export class TiledLayer extends UIRenderer {
this.node.on(NodeEventType.SIZE_CHANGED, this.updateCulling, this);
this.node.parent!.on(NodeEventType.TRANSFORM_CHANGED, this.updateCulling, this);
this.node.parent!.on(NodeEventType.SIZE_CHANGED, this.updateCulling, this);
View.instance.on('canvas-resize', this._resize);
screenAdapter.on('window-resize', this._resize);
View.instance.on('canvas-resize', this._resize, this);
screenAdapter.on('window-resize', this._resize, this);
this._markForUpdateRenderData();
// delay 1 frame, since camera's matrix data is dirty
this.scheduleOnce(this.updateCulling.bind(this));
@@ -471,8 +471,8 @@ export class TiledLayer extends UIRenderer {
this.node.off(NodeEventType.SIZE_CHANGED, this.updateCulling, this);
this.node.off(NodeEventType.TRANSFORM_CHANGED, this.updateCulling, this);
this.node.off(NodeEventType.ANCHOR_CHANGED, this._syncAnchorPoint, this);
View.instance.off('canvas-resize', this._resize);
screenAdapter.off('window-resize', this._resize);
View.instance.off('canvas-resize', this._resize, this);
screenAdapter.off('window-resize', this._resize, this);
this._uninstallCamera();
}
@@ -42,6 +42,9 @@ vec4 vert () {
CC_TRANSFER_FOG(pos);
CC_TRANSFER_SHADOW(pos);
return cc_matProj * (cc_matView * matWorld) * In.position;
#if CC_USE_2D
return cc_matProj * cc_matView * In.position;
#else
return cc_matProj * (cc_matView * matWorld) * In.position;
#endif
}
@@ -15,10 +15,13 @@ void main()
// World Space
CCSurfacesVertexWorldTransform(In);
In.worldPos = SurfacesVertexModifyWorldPos(In);
// Clip Space
In.clipPos = cc_matProj * cc_matView * vec4(In.worldPos, 1.0);
In.clipPos = SurfacesVertexModifyClipPos(In);
#if CC_USE_2D
In.clipPos = cc_matProj * cc_matView * vec4(In.position.xyz, 1.0);
#else
In.clipPos = cc_matProj * cc_matView * vec4(In.worldPos, 1.0);
In.clipPos = SurfacesVertexModifyClipPos(In);
#endif
// Other Surfaces Function
vec3 viewDirect = normalize(cc_cameraPos.xyz - In.worldPos);
@@ -24,7 +24,7 @@
import {
_decorator, Camera, CCBoolean, CCFloat, CCInteger, Component,
Material, rendering, Texture2D, visible,
Material, rendering, Texture2D,
} from 'cc';
import { EDITOR } from 'cc/env';
@@ -55,6 +55,7 @@ export class BuiltinPipelineSettings extends Component {
const cameraComponent = this.getComponent(Camera)!;
const camera = cameraComponent.camera;
camera.pipelineSettings = this._settings;
if (EDITOR) {
this._tryEnableEditorPreview();
}
@@ -62,8 +63,9 @@ export class BuiltinPipelineSettings extends Component {
onDisable(): void {
const cameraComponent = this.getComponent(Camera)!;
const camera = cameraComponent.camera;
camera.pipelineSettings = null;
if (camera) {
camera.pipelineSettings = null;
}
if (EDITOR) {
this._disableEditorPreview();
}
@@ -392,6 +394,7 @@ export class BuiltinPipelineSettings extends Component {
type: CCBoolean,
})
set fsrEnable(value: boolean) {
this._settings.fsr.enabled = value;
if (EDITOR) {
this._tryEnableEditorPreview();
}
@@ -28,7 +28,7 @@
* ========================= !DO NOT CHANGE THE FOLLOWING SECTION MANUALLY! =========================
*/
/* eslint-disable max-len */
import { Material, Texture2D, gfx, ccenum } from 'cc';
import { Material, Texture2D, ccenum, gfx } from 'cc';
const { SampleCount } = gfx;
@@ -38,14 +38,6 @@ export interface MSAA {
[name: string]: unknown;
}
export interface ForwardPassConfigs {
enableMainLightShadowMap: boolean;
enableMainLightPlanarShadowMap: boolean;
enablePlanarReflectionProbe: boolean;
enableMSAA: boolean;
enableSingleForwardPass: boolean;
}
export function makeMSAA(): MSAA {
return {
enabled: false,
@@ -62,6 +54,15 @@ export function fillRequiredMSAA(value: MSAA): void {
}
}
export interface ForwardPassConfigs {
enableMainLightShadowMap: boolean; /* false */
enableMainLightPlanarShadowMap: boolean; /* false */
enablePlanarReflectionProbe: boolean; /* false */
enableMSAA: boolean; /* false */
enableSingleForwardPass: boolean; /* false */
[name: string]: unknown;
}
export interface HBAO {
enabled: boolean; /* false */
radiusScale: number; /* 1 */
@@ -109,12 +110,13 @@ export enum BloomType {
MipmapFilter,
}
ccenum(BloomType);
export interface Bloom {
enabled: boolean; /* false */
type: BloomType;
material: Material | null;
type: BloomType; /* BloomType.KawaseDualFilter */
/* refcount */ material: Material | null;
/* refcount */ kawaseFilterMaterial: Material | null;
mipmapFilterMaterial: Material | null;
/* refcount */ mipmapFilterMaterial: Material | null;
enableAlphaMask: boolean; /* false */
iterations: number; /* 3 */
threshold: number; /* 0.8 */
@@ -143,13 +145,16 @@ export function fillRequiredBloom(value: Bloom): void {
if (value.type === undefined) {
value.type = BloomType.KawaseDualFilter;
}
if (!value.kawaseFilterMaterial) {
if (value.material === undefined) {
value.material = null;
}
if (value.kawaseFilterMaterial === undefined) {
value.kawaseFilterMaterial = value.material || null;
}
if (!value.mipmapFilterMaterial) {
if (value.mipmapFilterMaterial === undefined) {
value.mipmapFilterMaterial = null;
}
if (!value.enableAlphaMask) {
if (value.enableAlphaMask === undefined) {
value.enableAlphaMask = false;
}
if (value.iterations === undefined) {
File diff suppressed because it is too large Load Diff
+5 -1
View File
@@ -154,7 +154,11 @@ CCProgram unlit-vs %{
#endif
CC_TRANSFER_FOG(matWorld * position);
return cc_matProj * (cc_matView * matWorld) * position;
#if CC_USE_2D
return cc_matProj * cc_matView * position;
#else
return cc_matProj * (cc_matView * matWorld) * position;
#endif
}
}%
+5 -2
View File
@@ -221,8 +221,11 @@ CCProgram standard-vs %{
#if CC_USE_LIGHTMAP && !CC_FORWARD_ADD
CCLightingMapCaclUV();
#endif
gl_Position = cc_matProj * (cc_matView * matWorld) * In.position;
#if CC_USE_2D
gl_Position = cc_matProj * cc_matView * In.position;
#else
gl_Position = cc_matProj * (cc_matView * matWorld) * In.position;
#endif
}
}%
+5 -2
View File
@@ -171,8 +171,11 @@ CCProgram toon-vs %{
#endif
CC_TRANSFER_SHADOW(pos);
return cc_matProj * (cc_matView * matWorld) * In.position;
#if CC_USE_2D
return cc_matProj * cc_matView * In.position;
#else
return cc_matProj * (cc_matView * matWorld) * In.position;
#endif
}
}%
@@ -9,35 +9,42 @@ techniques:
- passes:
- vert: base-vs:vert
frag: prefilter-fs:frag
pass: cc-bloom-prefilter
pass: cc-bloom-mipmap-prefilter
depthStencilState:
depthTest: false
depthWrite: false
- vert: downsample-vs:vert
frag: downsample-fs:frag
pass: cc-bloom-downsample
pass: cc-bloom-mipmap-downsample
depthStencilState:
depthTest: false
depthWrite: false
- vert: upsample-vs:vert
frag: upsample-fs:frag
pass: cc-bloom-upsample
pass: cc-bloom-mipmap-upsample
depthStencilState:
depthTest: false
depthWrite: false
- vert: base-vs:vert
frag: combine-fs:frag
pass: cc-bloom-combine
pass: cc-bloom-mipmap-combine
depthStencilState:
depthTest: false
depthWrite: false
blendState:
targets:
- blend: true
blendSrc: one
blendDst: one
blendSrcAlpha: zero
blendDstAlpha: one
}%
CCProgram base-vs %{
precision mediump float;
#include <legacy/decode>
#include <builtin/uniforms/cc-global>
#include <legacy/decode-standard>
#include <post-process/pipeline>
out vec2 vUv;
out vec2 vUv00;
@@ -49,19 +56,21 @@ out vec2 vUv04;
vec4 vert() {
vUv = a_texCoord;
vec4 position;
CCDecode(position);
return position;
StandardVertInput In;
CCDecode(In);
FLIP_VULKAN_NDC(In.position);
return In.position;
}
}%
CCProgram prefilter-fs %{
precision mediump float;
#include <builtin/uniforms/cc-global>
#define bloomParams cc_debug_view_mode
#pragma rate BloomUBO pass
uniform BloomUBO {
mediump vec4 bloomParams; // x: useHDRIlluminance z: threshold, w: enableAlphaMask
};
in vec2 vUv;
#pragma rate mainTexture pass
@@ -81,10 +90,13 @@ vec4 frag() {
CCProgram downsample-vs %{
precision mediump float;
#include <legacy/decode>
#include <builtin/uniforms/cc-global>
#include <legacy/decode-standard>
#include <post-process/pipeline>
#define bloomParams cc_debug_view_mode
#pragma rate BloomUBO pass
uniform BloomUBO {
mediump vec4 bloomParams; // x: useHDRIlluminance z: threshold, w: enableAlphaMask
};
out vec2 vUv;
out vec2 vUv00;
@@ -118,19 +130,19 @@ vec4 vert() {
vUv10 = vUv + bloomParams.xy * vec2(0.0, - 2.0);
vUv11 = vUv + bloomParams.xy * vec2(2.0, - 2.0);
vec4 position;
CCDecode(position);
return position;
StandardVertInput In;
CCDecode(In);
FLIP_VULKAN_NDC(In.position);
return In.position;
}
}%
CCProgram downsample-fs %{
precision mediump float;
// (1 / 4) * 0.5 = 0.125
// (1 / 4) * 0.5 = 0.125
#define WEIGHT_INNER 0.125
// (1 / 9) * 0.5 = 0.0555555
// (1 / 9) * 0.5 = 0.0555555
#define WEIGHT_OUTER 0.0555555
in vec2 vUv;
@@ -201,10 +213,13 @@ vec4 frag() {
CCProgram upsample-vs %{
precision mediump float;
#include <legacy/decode>
#include <builtin/uniforms/cc-global>
#include <legacy/decode-standard>
#include <post-process/pipeline>
#define bloomParams cc_debug_view_mode
#pragma rate BloomUBO pass
uniform BloomUBO {
mediump vec4 bloomParams; // x: useHDRIlluminance z: threshold, w: enableAlphaMask
};
out vec2 vUv;
out vec2 vUv0;
@@ -230,16 +245,15 @@ vec4 vert() {
vUv6 = vUv + bloomParams.xy * vec2(0.0, - 1.0);
vUv7 = vUv + bloomParams.xy * vec2(1.0, - 1.0);
vec4 position;
CCDecode(position);
return position;
StandardVertInput In;
CCDecode(In);
FLIP_VULKAN_NDC(In.position);
return In.position;
}
}%
CCProgram upsample-fs %{
precision mediump float;
#include <builtin/uniforms/cc-global>
in vec2 vUv;
in vec2 vUv0;
@@ -276,21 +290,20 @@ vec4 frag() {
CCProgram combine-fs %{
precision mediump float;
#include <builtin/uniforms/cc-global>
#define bloomParams cc_debug_view_mode
#pragma rate BloomUBO pass
uniform BloomUBO {
mediump vec4 bloomParams; // x: useHDRIlluminance z: threshold, w: enableAlphaMask
};
in vec2 vUv;
#pragma rate bloomTexture pass
uniform lowp sampler2D bloomTexture;
#pragma rate mainTexture pass
uniform sampler2D mainTexture;
uniform sampler2D bloomTexture;
vec4 frag() {
vec4 baseColor = texture(mainTexture, vUv);
vec4 bloomColor = texture(bloomTexture, vUv);
vec3 color = baseColor.rgb + bloomColor.rgb * bloomParams.w;
return vec4(color, baseColor.a);
vec3 color = bloomColor.rgb * bloomParams.w;
return vec4(color, 1);
}
}%
+2 -2
View File
@@ -431,8 +431,8 @@ module.exports = {
},
},
animationBakeRate: {
name: 'Animation Bake Rate',
title: 'Specify the animation bake rate in frames per second (fps).',
name: 'Animation Bake Sample Rate',
title: 'Specify the animation bake sample rate in frames per second (fps).',
auto: 'Auto',
},
promoteSingleRootNode: {
+1
View File
@@ -1361,6 +1361,7 @@ module.exports = link(mixin({
require('./modules/physics'),
require('./modules/rendering'),
require('./modules/ui.js'),
require('./modules/terrain.js'),
require('./animation'),
));
+34
View File
@@ -0,0 +1,34 @@
module.exports = {
classes: {
cc: {
Terrain: {
properties: {
_asset: {
tooltip: 'The terrain asset.',
},
effectAsset: {
tooltip: 'The terrain effect asset.',
},
lightmapInfos: {
tooltip: 'The terrain info.',
},
receiveShadow: {
tooltip: 'Receive shadow.',
},
useNormalMap: {
tooltip: 'Use normal map.',
},
usePBR: {
tooltip: 'Use pbr material.',
},
lodEnable: {
tooltip: 'Enable lod.',
},
LodBias: {
tooltip: 'Lod bias.',
},
},
},
},
},
};
+2 -2
View File
@@ -426,8 +426,8 @@ module.exports = {
},
},
animationBakeRate: {
name: '动画烘焙速率',
title: '指定动画烘焙速率,单位为帧每秒(FPS)',
name: '动画烘焙采样率',
title: '指定动画烘焙每秒采集多少次数据,单位为帧每秒(FPS)',
auto: '自动',
},
promoteSingleRootNode: {
+1
View File
@@ -1339,6 +1339,7 @@ module.exports = link(mixin({
require('./modules/physics'),
require('./modules/rendering'),
require('./modules/ui.js'),
require('./modules/terrain.js'),
require('./animation'),
));
+34
View File
@@ -0,0 +1,34 @@
module.exports = {
classes: {
cc: {
Terrain: {
properties: {
_asset: {
tooltip: '地形所使用的资源。',
},
effectAsset: {
tooltip: '地形特效资源。',
},
lightmapInfos: {
tooltip: '地形信息。',
},
receiveShadow: {
tooltip: '是否接受阴影。',
},
useNormalMap: {
tooltip: '是否使用法线贴图。',
},
usePBR: {
tooltip: '是否使用物理材质。',
},
lodEnable: {
tooltip: '是否允许 lod。',
},
LodBias: {
tooltip: 'Lod 偏移距离。',
},
},
},
},
},
};
+21 -18
View File
@@ -4,7 +4,7 @@ const { updateElementReadonly } = require('../../utils/assets');
const { extname } = require('path');
const { ParseAtlasFile } = require('./parse-atlas');
exports.template = /* html */`
exports.template = /* html */ `
<div class="asset-texture">
<!-- dont delete, for insert -->
<div class="content">
@@ -62,7 +62,7 @@ exports.template = /* html */`
</div>
`;
exports.style = /* css */`
exports.style = /* css */ `
.asset-texture {
display: flex;
flex: 1;
@@ -395,9 +395,10 @@ const Elements = {
panel.$.mipfilterSelect.innerHTML = optionsHtml;
panel.$.mipfilterSelect.value = panel.userData.mipfilter || 'nearest';
panel.metaList && panel.metaList.forEach((meta) => {
Editor.Profile.setTemp('inspector', `${meta.uuid}.texture.mipfilter`, panel.userData.mipfilter);
});
panel.metaList &&
panel.metaList.forEach((meta) => {
Editor.Profile.setTemp('inspector', `${meta.uuid}.texture.mipfilter`, panel.userData.mipfilter);
});
panel.updateInvalid(panel.$.mipfilterSelect, 'mipfilter');
updateElementReadonly.call(panel, panel.$.mipfilterSelect);
},
@@ -589,9 +590,13 @@ const Elements = {
},
checkAtlasFileConfig: {
async ready() {
this.$.atlasFileName.addEventListener('click', () => {
Editor.Message.send('assets', 'twinkle', this.$.atlasFileName.getAttribute('data-uuid'));
}, false);
this.$.atlasFileName.addEventListener(
'click',
() => {
Editor.Message.send('assets', 'twinkle', this.$.atlasFileName.getAttribute('data-uuid'));
},
false,
);
},
async update() {
try {
@@ -600,17 +605,13 @@ const Elements = {
return;
}
const parentPath = this.parentAssetList[0].path.replace(/\/[^/]+$/, '/*');
let assets = await Editor.Message.request(
'asset-db',
'query-assets',
{ pattern: parentPath, ccType: "cc.Asset" }
);
assets = assets.filter(v => extname(v.file) === '.atlas');
let assets = await Editor.Message.request('asset-db', 'query-assets', { pattern: parentPath, ccType: 'cc.Asset' });
assets = assets.filter((v) => extname(v.file) === '.atlas');
let matchedAsset;
let matchedAtlasJson;
for (const asset of assets) {
const json = await (new ParseAtlasFile()).parse(asset.file);
const json = await new ParseAtlasFile().parse(asset.file);
// the asset.displayName is not a full name, miss the extname
// so, we should use RegExp to get the extname
@@ -626,7 +627,6 @@ const Elements = {
}
}
if (matchedAsset) {
let atlasFileFilter = matchedAtlasJson.filter;
if (Array.isArray(atlasFileFilter)) {
atlasFileFilter = atlasFileFilter.join();
@@ -635,9 +635,12 @@ const Elements = {
}
const userDataFilter = `${this.meta.userData.minfilter},${this.meta.userData.magfilter}`;
if (atlasFileFilter.toLowerCase() !== userDataFilter.toLowerCase()) {
if (atlasFileFilter && atlasFileFilter.toLowerCase() !== userDataFilter.toLowerCase()) {
this.$.filterDifferent.style.display = 'block';
const tipHtml = Editor.I18n.t('ENGINE.assets.texture.filterDiffenent').replace('{atlasFile}', `<span>${matchedAsset.name}</span>`);
const tipHtml = Editor.I18n.t('ENGINE.assets.texture.filterDiffenent').replace(
'{atlasFile}',
`<span>${matchedAsset.name}</span>`,
);
this.$.atlasFileName.innerHTML = tipHtml;
this.$.atlasFileName.setAttribute('data-uuid', matchedAsset.uuid);
} else {
+7
View File
@@ -101,6 +101,11 @@ if(NOT WINDOWS)
add_definitions(-DBOOST_NO_CXX98_FUNCTION_BASE)
endif()
# https://stackoverflow.com/questions/78598141/first-stdmutexlock-crashes-in-application-built-with-latest-visual-studio
if(WINDOWS)
add_definitions(-D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR)
endif()
add_definitions(-DCC_NETMODE_CLIENT=0)
add_definitions(-DCC_NETMODE_LISTEN_SERVER=1)
add_definitions(-DCC_NETMODE_HOST_SERVER=2)
@@ -577,6 +582,8 @@ elseif(OPENHARMONY)
cocos/platform/openharmony/napi/NapiHelper.h
cocos/platform/openharmony/napi/NapiValueConverter.cpp
cocos/platform/openharmony/napi/NapiValueConverter.h
cocos/platform/openharmony/napi/NapiPromiseBridge.cpp
cocos/platform/openharmony/napi/NapiPromiseBridge.h
cocos/platform/openharmony/napi/native_common.h
cocos/platform/openharmony/WorkerMessageQueue.cpp
cocos/platform/openharmony/WorkerMessageQueue.h
@@ -169,6 +169,12 @@ private:
if (kls != nullptr && kls != itr->second->_getClass()) {
continue;
}
// JS object may be null when it is obtained on zhe JSVM brach of the 5.1 ROMS
#if SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_JSVM
if(itr->second->_getJSObject() == nullptr) {
continue;
}
#endif
eleCount++;
CC_ASSERT_LT(eleCount, 2);
eachCallback(itr->second);
@@ -52,6 +52,15 @@
} \
} while (0)
#define NODE_API_CALL_RESULT(status, env, the_call, ret_val) \
do { \
status = the_call; \
if (status != JSVM_OK) { \
se::internal::logJsException((env), __FILE_NAME__, __LINE__); \
return ret_val; \
} \
} while (0)
// Returns nullptr if the_call doesn't return JSVM_OK.
#define NODE_API_CALL(status, env, the_call) \
do { \
+111 -64
View File
@@ -64,7 +64,10 @@ Object* Object::createObjectWithClass(Class* cls) {
bool Object::setProperty(const char* name, const Value& data) {
JSVM_Status status;
JSVM_Value jsVal;
internal::seToJsValue(data, &jsVal);
bool ret = internal::seToJsValue(data, &jsVal);
if(!ret) {
return false;
}
NODE_API_CALL(status, _env, OH_JSVM_SetNamedProperty(_env, _objRef.getValue(_env), name, jsVal));
return status == JSVM_OK;
}
@@ -125,26 +128,23 @@ void Object::setPrivateObject(PrivateObjectBase* data) {
bool Object::deleteProperty(const char* name) {
JSVM_Status status;
JSVM_Value key;
NODE_API_CALL(status, _env, OH_JSVM_GetNamedProperty(_env, _objRef.getValue(_env), name, &key));
if (status != JSVM_OK) {
return false;
}
NODE_API_CALL_RESULT(status, _env, OH_JSVM_GetNamedProperty(_env, _objRef.getValue(_env), name, &key), false);
bool ret = false;
NODE_API_CALL(status, _env, OH_JSVM_DeleteProperty(_env, _objRef.getValue(_env), key, &ret));
NODE_API_CALL_RESULT(status, _env, OH_JSVM_DeleteProperty(_env, _objRef.getValue(_env), key, &ret), false);
return ret;
}
bool Object::isArray() const {
JSVM_Status status;
bool ret = false;
NODE_API_CALL(status, _env, OH_JSVM_IsArray(_env, _objRef.getValue(_env), &ret));
NODE_API_CALL_RESULT(status, _env, OH_JSVM_IsArray(_env, _objRef.getValue(_env), &ret), false);
return ret;
}
bool Object::getArrayLength(uint32_t* length) const {
JSVM_Status status;
uint32_t len = 0;
NODE_API_CALL(status, _env, OH_JSVM_GetArrayLength(_env, _objRef.getValue(_env), &len));
NODE_API_CALL_RESULT(status, _env, OH_JSVM_GetArrayLength(_env, _objRef.getValue(_env), &len), false);
if (length) {
*length = len;
}
@@ -154,7 +154,7 @@ bool Object::getArrayLength(uint32_t* length) const {
bool Object::getArrayElement(uint32_t index, Value* data) const {
JSVM_Status status;
JSVM_Value val;
NODE_API_CALL(status, _env, OH_JSVM_GetElement(_env, _objRef.getValue(_env), index, &val));
NODE_API_CALL_RESULT(status, _env, OH_JSVM_GetElement(_env, _objRef.getValue(_env), index, &val), false);
internal::jsToSeValue(val, data);
return true;
}
@@ -162,15 +162,18 @@ bool Object::getArrayElement(uint32_t index, Value* data) const {
bool Object::setArrayElement(uint32_t index, const Value& data) {
JSVM_Status status;
JSVM_Value val;
internal::seToJsValue(data, &val);
NODE_API_CALL(status, _env, OH_JSVM_SetElement(_env, _objRef.getValue(_env), index, val));
bool ret = internal::seToJsValue(data, &val);
if(!ret) {
return false;
}
NODE_API_CALL_RESULT(status, _env, OH_JSVM_SetElement(_env, _objRef.getValue(_env), index, val), false);
return true;
}
bool Object::isTypedArray() const {
JSVM_Status status;
bool ret = false;
NODE_API_CALL(status, _env, OH_JSVM_IsTypedarray(_env, _objRef.getValue(_env), &ret));
NODE_API_CALL_RESULT(status, _env, OH_JSVM_IsTypedarray(_env, _objRef.getValue(_env), &ret), false);
return ret;
}
@@ -236,7 +239,7 @@ bool Object::getTypedArrayData(uint8_t** ptr, size_t* length) const {
size_t byteOffset;
size_t arrayLength;
void* data = nullptr;
NODE_API_CALL(status, _env, OH_JSVM_GetTypedarrayInfo(_env, _objRef.getValue(_env), &type, &arrayLength, &data, &inputBuffer, &byteOffset));
NODE_API_CALL_RESULT(status, _env, OH_JSVM_GetTypedarrayInfo(_env, _objRef.getValue(_env), &type, &arrayLength, &data, &inputBuffer, &byteOffset), false);
*ptr = (uint8_t*)(data);
if (length) {
size_t bytesOfElement = 1;
@@ -266,14 +269,14 @@ bool Object::getTypedArrayData(uint8_t** ptr, size_t* length) const {
bool Object::isArrayBuffer() const {
bool ret = false;
JSVM_Status status;
NODE_API_CALL(status, _env, OH_JSVM_IsArraybuffer(_env, _objRef.getValue(_env), &ret));
NODE_API_CALL_RESULT(status, _env, OH_JSVM_IsArraybuffer(_env, _objRef.getValue(_env), &ret), false);
return ret;
}
bool Object::getArrayBufferData(uint8_t** ptr, size_t* length) const {
JSVM_Status status;
size_t len = 0;
NODE_API_CALL(status, _env, OH_JSVM_GetArraybufferInfo(_env, _objRef.getValue(_env), reinterpret_cast<void**>(ptr), &len));
NODE_API_CALL_RESULT(status, _env, OH_JSVM_GetArraybufferInfo(_env, _objRef.getValue(_env), reinterpret_cast<void**>(ptr), &len), false);
if (length) {
*length = len;
}
@@ -290,7 +293,7 @@ Object* Object::createTypedArray(Object::TypedArrayType type, const void* data,
JSVM_TypedarrayType jsvmType;
JSVM_Value outputBuffer;
void* outputPtr = nullptr;
NODE_API_CALL(status, ScriptEngine::getEnv(), OH_JSVM_CreateArraybuffer(ScriptEngine::getEnv(), byteLength, &outputPtr, &outputBuffer));
NODE_API_CALL_RESULT(status, ScriptEngine::getEnv(), OH_JSVM_CreateArraybuffer(ScriptEngine::getEnv(), byteLength, &outputPtr, &outputBuffer), nullptr);
if (outputPtr && data && byteLength > 0) {
memcpy(outputPtr, data, byteLength);
}
@@ -346,8 +349,7 @@ Object* Object::createTypedArray(Object::TypedArrayType type, const void* data,
}
size_t eleCounts = byteLength / sizeOfEle;
JSVM_Value outputArray;
NODE_API_CALL(status, ScriptEngine::getEnv(), OH_JSVM_CreateTypedarray(ScriptEngine::getEnv(), jsvmType, eleCounts, outputBuffer, 0, &outputArray));
NODE_API_CALL_RESULT(status, ScriptEngine::getEnv(), OH_JSVM_CreateTypedarray(ScriptEngine::getEnv(), jsvmType, eleCounts, outputBuffer, 0, &outputArray), nullptr);
Object* obj = Object::_createJSObject(ScriptEngine::getEnv(), outputArray, nullptr);
return obj;
}
@@ -373,7 +375,10 @@ Object* Object::createTypedArrayWithBuffer(TypedArrayType type, const Object* ob
SE_LOGE("Don't pass se::Object::TypedArrayType::NONE to createTypedArray API!");
return nullptr;
}
if (!obj->_getJSObject()) {
SE_LOGE("Failed to create typed array: underlying ArrayBuffer is invalid (possibly released)");
return nullptr;
}
assert(obj->isArrayBuffer());
JSVM_Status status;
JSVM_Value outputBuffer = obj->_getJSObject();
@@ -427,8 +432,7 @@ Object* Object::createTypedArrayWithBuffer(TypedArrayType type, const Object* ob
}
size_t eleCounts = byteLength / sizeOfEle;
JSVM_Value outputArray;
NODE_API_CALL(status, ScriptEngine::getEnv(), OH_JSVM_CreateTypedarray(ScriptEngine::getEnv(), jsvmType, eleCounts, outputBuffer, offset, &outputArray));
NODE_API_CALL_RESULT(status, ScriptEngine::getEnv(), OH_JSVM_CreateTypedarray(ScriptEngine::getEnv(), jsvmType, eleCounts, outputBuffer, offset, &outputArray), nullptr);
return Object::_createJSObject(ScriptEngine::getEnv(), outputArray, nullptr);
}
@@ -436,7 +440,7 @@ Object* Object::createExternalArrayBufferObject(void* contents, size_t byteLengt
JSVM_Status status;
JSVM_Value result;
// JSVM does not support the napi_create_external_arraybuffer interface like in NAPI.
NODE_API_CALL(status, ScriptEngine::getEnv(), OH_JSVM_CreateArrayBufferFromBackingStoreData(ScriptEngine::getEnv(), contents, byteLength, 0, byteLength, &result));
NODE_API_CALL_RESULT(status, ScriptEngine::getEnv(), OH_JSVM_CreateArrayBufferFromBackingStoreData(ScriptEngine::getEnv(), contents, byteLength, 0, byteLength, &result), nullptr);
Object* obj = Object::_createJSObject(ScriptEngine::getEnv(), result, nullptr);
return obj;
}
@@ -444,15 +448,15 @@ Object* Object::createExternalArrayBufferObject(void* contents, size_t byteLengt
bool Object::isFunction() const {
JSVM_ValueType valuetype0;
JSVM_Status status;
NODE_API_CALL(status, _env, OH_JSVM_Typeof(_env, _objRef.getValue(_env), &valuetype0));
NODE_API_CALL_RESULT(status, _env, OH_JSVM_Typeof(_env, _objRef.getValue(_env), &valuetype0), false);
return (valuetype0 == JSVM_ValueType::JSVM_FUNCTION);
}
bool Object::defineFunction(const char* funcName, JSVM_Callback func) {
JSVM_Value fn;
JSVM_Status status;
NODE_API_CALL(status, _env, OH_JSVM_CreateFunction(_env, funcName, JSVM_AUTO_LENGTH, func, &fn));
NODE_API_CALL(status, _env, OH_JSVM_SetNamedProperty(_env, _objRef.getValue(_env), funcName, fn));
NODE_API_CALL_RESULT(status, _env, OH_JSVM_CreateFunction(_env, funcName, JSVM_AUTO_LENGTH, func, &fn), false);
NODE_API_CALL_RESULT(status, _env, OH_JSVM_SetNamedProperty(_env, _objRef.getValue(_env), funcName, fn), false);
return true;
}
@@ -478,7 +482,7 @@ Object* Object::_createJSObject(JSVM_Env env, JSVM_Value js_object, Class* cls)
Object* Object::createPlainObject() {
JSVM_Value result;
JSVM_Status status;
NODE_API_CALL(status, ScriptEngine::getEnv(), OH_JSVM_CreateObject(ScriptEngine::getEnv(), &result));
NODE_API_CALL_RESULT(status, ScriptEngine::getEnv(), OH_JSVM_CreateObject(ScriptEngine::getEnv(), &result), nullptr);
Object* obj = _createJSObject(ScriptEngine::getEnv(), result, nullptr);
return obj;
}
@@ -486,7 +490,7 @@ Object* Object::createPlainObject() {
Object* Object::createArrayObject(size_t length) {
JSVM_Value result;
JSVM_Status status;
NODE_API_CALL(status, ScriptEngine::getEnv(), OH_JSVM_CreateArrayWithLength(ScriptEngine::getEnv(), length, &result));
NODE_API_CALL_RESULT(status, ScriptEngine::getEnv(), OH_JSVM_CreateArrayWithLength(ScriptEngine::getEnv(), length, &result), nullptr);
Object* obj = _createJSObject(ScriptEngine::getEnv(), result, nullptr);
return obj;
}
@@ -496,13 +500,11 @@ Object* Object::createArrayBufferObject(const void* data, size_t byteLength) {
JSVM_Status status;
void* retData;
Object* obj = nullptr;
NODE_API_CALL(status, ScriptEngine::getEnv(), OH_JSVM_CreateArraybuffer(ScriptEngine::getEnv(), byteLength, &retData, &result));
if (status == JSVM_OK) {
if (data) {
memcpy(retData, data, byteLength);
}
obj = _createJSObject(ScriptEngine::getEnv(), result, nullptr);
NODE_API_CALL_RESULT(status, ScriptEngine::getEnv(), OH_JSVM_CreateArraybuffer(ScriptEngine::getEnv(), byteLength, &retData, &result), nullptr);
if (data) {
memcpy(retData, data, byteLength);
}
obj = _createJSObject(ScriptEngine::getEnv(), result, nullptr);
return obj;
}
@@ -510,21 +512,22 @@ bool Object::getAllKeys(std::vector<std::string>* allKeys) const {
JSVM_Status status;
JSVM_Value names;
NODE_API_CALL(status, _env, OH_JSVM_GetPropertyNames(_env, _objRef.getValue(_env), &names));
if (status != JSVM_OK) {
return false;
}
NODE_API_CALL_RESULT(status, _env, OH_JSVM_GetPropertyNames(_env, _objRef.getValue(_env), &names), false);
uint32_t name_len = 0;
NODE_API_CALL(status, _env, OH_JSVM_GetArrayLength(_env, names, &name_len));
NODE_API_CALL_RESULT(status, _env, OH_JSVM_GetArrayLength(_env, names, &name_len), false);
for (uint32_t i = 0; i < name_len; i++) {
JSVM_Value val;
NODE_API_CALL(status, _env, OH_JSVM_GetElement(_env, names, i, &val));
if (status == JSVM_OK) {
char buffer[MAX_STRING_LEN];
size_t result = 0;
NODE_API_CALL(status, _env, OH_JSVM_GetValueStringUtf8(_env, val, buffer, MAX_STRING_LEN, &result));
if (result > 0) {
allKeys->push_back(buffer);
NODE_API_CALL(status, _env, OH_JSVM_GetValueStringUtf8(_env, val, nullptr, 0, &result));
if(status == JSVM_OK){
result += 1;
char buffer[result];
NODE_API_CALL(status, _env, OH_JSVM_GetValueStringUtf8(_env, val, buffer, sizeof(buffer), &result));
if (result > 0) {
allKeys->push_back(buffer);
}
}
}
}
@@ -546,28 +549,37 @@ bool Object::init(JSVM_Env env, JSVM_Value js_object, Class* cls) {
}
bool Object::call(const ValueArray& args, Object* thisObject, Value* rval) {
if (_getJSObject() == nullptr) {
SE_LOGE("Attempted to call function on invalid JS object (possibly released or uninitialized)");
return false;
}
size_t argc = 0;
std::vector<JSVM_Value> argv;
argv.reserve(10);
argc = args.size();
internal::seToJsArgs(_env, args, &argv);
bool valid = internal::seToJsArgs(_env, args, &argv);
if(!valid) {
SE_LOGE("Failed to convert arguments from se::Value to JSVM_Value");
return false;
}
JSVM_Value return_val;
JSVM_Status status;
assert(isFunction());
if(thisObject != nullptr && !thisObject->_getJSObject()) {
SE_LOGE("Invalid 'this' object passed to function call (JS object is invalid or released)");
return false;
}
JSVM_Value thisObj = thisObject ? thisObject->_getJSObject() : ({
JSVM_Value undefinedValue;
OH_JSVM_GetUndefined(_env, &undefinedValue);
undefinedValue;
});
NODE_API_CALL(status, _env,
OH_JSVM_CallFunction(_env, thisObj, _getJSObject(), argc, argv.data(), &return_val));
if (status == JSVM_OK) {
if (rval) {
internal::jsToSeValue(return_val, rval);
}
return true;
NODE_API_CALL_RESULT(status, _env,
OH_JSVM_CallFunction(_env, thisObj, _getJSObject(), argc, argv.data(), &return_val), false);
if (rval) {
internal::jsToSeValue(return_val, rval);
}
return false;
return true;
}
void Object::_setFinalizeCallback(JSVM_Finalize finalizeCb) {
@@ -630,10 +642,12 @@ std::string Object::toString() const {
JSVM_Status status;
if (isFunction() || isArray() || isTypedArray()) {
JSVM_Value result;
NODE_API_CALL(status, _env, OH_JSVM_CoerceToString(_env, _objRef.getValue(_env), &result));
char buffer[MAX_STRING_LEN];
NODE_API_CALL_RESULT(status, _env, OH_JSVM_CoerceToString(_env, _objRef.getValue(_env), &result), ret);
size_t result_t = 0;
NODE_API_CALL(status, _env, OH_JSVM_GetValueStringUtf8(_env, result, buffer, MAX_STRING_LEN, &result_t));
NODE_API_CALL_RESULT(status, _env, OH_JSVM_GetValueStringUtf8(_env, result, nullptr, 0, &result_t), ret);
result_t += 1;
char buffer[result_t];
NODE_API_CALL_RESULT(status, _env, OH_JSVM_GetValueStringUtf8(_env, result, buffer, sizeof(buffer), &result_t), ret);
ret = buffer;
} else if (isArrayBuffer()) {
ret = "[object ArrayBuffer]";
@@ -789,11 +803,9 @@ Object* Object::createJSONObject(const std::string& jsonStr) {
JSVM_Status status = JSVM_OK;
JSVM_Value jsJsonStr = nullptr;
NODE_API_CALL(status, _env, OH_JSVM_CreateStringUtf8(_env, jsonStr.c_str(), jsonStr.length(), &jsJsonStr));
NODE_API_CALL_RESULT(status, _env, OH_JSVM_CreateStringUtf8(_env, jsonStr.c_str(), jsonStr.length(), &jsJsonStr), nullptr);
JSVM_Value jsObj = nullptr;
NODE_API_CALL(status, _env, OH_JSVM_JsonParse(_env, jsJsonStr, &jsObj));
NODE_API_CALL_RESULT(status, _env, OH_JSVM_JsonParse(_env, jsJsonStr, &jsObj), nullptr);
return Object::_createJSObject(_env, jsObj, nullptr);
}
@@ -802,11 +814,9 @@ Object* Object::createJSONObject(std::u16string&& jsonStr) {
JSVM_Status status = JSVM_OK;
JSVM_Value jsJsonStr = nullptr;
NODE_API_CALL(status, _env, OH_JSVM_CreateStringUtf16(_env, jsonStr.c_str(), jsonStr.length(), &jsJsonStr));
NODE_API_CALL_RESULT(status, _env, OH_JSVM_CreateStringUtf16(_env, jsonStr.c_str(), jsonStr.length(), &jsJsonStr), nullptr);
JSVM_Value jsObj = nullptr;
NODE_API_CALL(status, _env, OH_JSVM_JsonParse(_env, jsJsonStr, &jsObj));
NODE_API_CALL_RESULT(status, _env, OH_JSVM_JsonParse(_env, jsJsonStr, &jsObj), nullptr);
return Object::_createJSObject(_env, jsObj, nullptr);
}
@@ -839,11 +849,47 @@ void Object::clearPrivateData(bool clearMapping) {
Object* Object::createUTF8String(const std::string& str) {
JSVM_Status status;
JSVM_Value result;
NODE_API_CALL(status, ScriptEngine::getEnv(), OH_JSVM_CreateStringUtf8(ScriptEngine::getEnv(), str.c_str(), JSVM_AUTO_LENGTH, &result));
NODE_API_CALL_RESULT(status, ScriptEngine::getEnv(), OH_JSVM_CreateStringUtf8(ScriptEngine::getEnv(), str.c_str(), JSVM_AUTO_LENGTH, &result), nullptr);
Object* obj = _createJSObject(ScriptEngine::getEnv(), result, nullptr);
return obj;
}
std::unordered_map<Object*, JSVM_Deferred> Object::resolverMap;
void Object::resolverPromise(Object* object, const Value& value) {
auto it = resolverMap.find(object);
if (it != resolverMap.end()) {
auto* resolver = it->second;
JSVM_Value jsvmValue;
se::internal::seToJsValue(value, &jsvmValue);
OH_JSVM_ResolveDeferred(ScriptEngine::getEnv(), resolver, jsvmValue);
resolverMap.erase(it);
}
}
void Object::rejectPromise(Object* object, const Value& value) {
auto it = resolverMap.find(object);
if (it != resolverMap.end()) {
auto* resolver = it->second;
JSVM_Value jsvmValue;
se::internal::seToJsValue(value, &jsvmValue);
OH_JSVM_ResolveDeferred(ScriptEngine::getEnv(), resolver, jsvmValue);
resolverMap.erase(it);
}
}
Object* Object::createPromise() {
JSVM_Deferred deferred = nullptr;
JSVM_Value promise = nullptr;
JSVM_Status createStatus = OH_JSVM_CreatePromise(ScriptEngine::getEnv(), &deferred, &promise);
if (createStatus != JSVM_OK) {
return nullptr;
}
Object* object = Object::_createJSObject(ScriptEngine::getEnv(), promise, nullptr);
resolverMap[object] = deferred;
return object;
}
ObjectRef::ObjectRef(Object *parent)
: _parent(parent) {
@@ -872,7 +918,8 @@ void ObjectRef::init(JSVM_Env env, JSVM_Value obj) {
JSVM_Value ObjectRef::getValue(JSVM_Env env) const {
JSVM_Value r = nullptr;
OH_JSVM_GetReferenceValue(_env, _ref, &r);
JSVM_Status status;
NODE_API_CALL_RESULT(status, _env, OH_JSVM_GetReferenceValue(_env, _ref, &r), nullptr);
return r;
}
@@ -33,6 +33,7 @@
#include "CommonHeader.h"
#include "HelperMacros.h"
#include "Utils.h"
#include <unordered_map>
namespace se {
class Class;
@@ -433,6 +434,10 @@ public:
static Object *createUTF8String(const std::string &str);
static Object *createPromise();
static void rejectPromise(Object *object, const Value &value);
static void resolverPromise(Object *object, const Value &value);
private:
// Object();
// virtual ~Object();
@@ -453,7 +458,9 @@ private:
uint32_t _rootCount = 0;
bool _onCleaingPrivateData = false;
internal::PrivateData *_internalData;
static std::unordered_map<Object*, JSVM_Deferred> resolverMap;
friend class ObjectRef;
friend class ScriptEngine;
};
@@ -334,7 +334,8 @@ bool ScriptEngine::start() {
} else {
OH_JSVM_OpenInspector(_env, _debuggerServerAddr.c_str(), _debuggerServerPort);
}
SE_LOGD("Debugger listening..., visit [ http://localhost:6068/json ] to configuration debugging information and copy the devtoolsFrontendUrl value to the browser!");
SE_LOGD("Debugger listening..., visit [ http://localhost:%d/json ] to configuration debugging information and copy the devtoolsFrontendUrl value to the browser!", _debuggerServerPort);
if(_isWaitForConnect) {
OH_JSVM_WaitForDebugger(_env, true);
}
@@ -173,13 +173,15 @@ bool seToJsValue(const Value& v, target_value* outJsVal) {
return ret;
}
void seToJsArgs(JSVM_Env env, const ValueArray& args, std::vector<target_value>* outArr) {
bool seToJsArgs(JSVM_Env env, const ValueArray& args, std::vector<target_value>* outArr) {
bool ret = true;
assert(outArr != nullptr);
for (const auto& data : args) {
JSVM_Value jsval;
seToJsValue(data, &jsval);
ret = ret && seToJsValue(data, &jsval);
outArr->push_back(jsval);
}
return ret;
}
bool setReturnValue(const Value& data, target_value& argv) {
@@ -188,6 +190,9 @@ bool setReturnValue(const Value& data, target_value& argv) {
auto env = ScriptEngine::getEnv();
JSVM_Status status;
NODE_API_CALL(status, env, OH_JSVM_CreateDouble(env, data.toDouble(), &argv));
if (status != JSVM_OK) {
return false;
}
return true;
}
+1 -1
View File
@@ -41,7 +41,7 @@ bool setReturnValue(const Value &data, target_value &argv);
void jsToSeValue(const target_value &value, Value *v);
void jsToSeArgs(size_t argc, target_value *argv, ValueArray *outArr);
bool seToJsValue(const Value &v, target_value *jsval);
void seToJsArgs(JSVM_Env env, const ValueArray &args, std::vector<target_value> *outArr);
bool seToJsArgs(JSVM_Env env, const ValueArray &args, std::vector<target_value> *outArr);
std::string jsToString(const target_value &value);
void logJsException(JSVM_Env env, const char *file, int line);
+49 -2
View File
@@ -25,6 +25,7 @@
#include "Object.h"
#include "v8/HelperMacros.h"
#include "application/ApplicationManager.h"
// Use node::Buffer to replace v8 api,to avoid link err in editor platform.
#if CC_EDITOR && CC_PLATFORM == CC_PLATFORM_WINDOWS
@@ -163,6 +164,54 @@ Object *Object::createPlainObject() {
return obj;
}
std::unordered_map<Object*, v8::Persistent<v8::Promise::Resolver>*> Object::resolverMap;
void Object::resolverPromise(Object *object, const Value &value) {
auto it = resolverMap.find(object);
if (it != resolverMap.end()) {
v8::Isolate *isolate = __isolate;
v8::HandleScope scope(isolate);
v8::Local<v8::Context> context = isolate->GetCurrentContext();
auto* resolver = it->second;
v8::Local<v8::Value> v8Val;
se::internal::seToJsValue(__isolate, value, &v8Val);
resolver->Get(isolate)->Resolve(context, v8Val).ToChecked();
resolver->Reset();
delete resolver;
resolverMap.erase(it);
}
}
void Object::rejectPromise(Object *object, const Value &value) {
auto it = resolverMap.find(object);
if (it != resolverMap.end()) {
v8::Isolate *isolate = __isolate;
v8::HandleScope scope(isolate);
v8::Local<v8::Context> context = isolate->GetCurrentContext();
auto* resolver = it->second;
v8::Local<v8::Value> v8Val;
se::internal::seToJsValue(isolate, value, &v8Val);
resolver->Get(isolate)->Reject(context, v8Val).ToChecked();
resolver->Reset();
delete resolver;
resolverMap.erase(it);
}
}
Object *Object::createPromise() {
v8::Isolate *isolate = __isolate;
v8::HandleScope handleScope(isolate);
v8::Local<v8::Promise::Resolver> resolver = v8::Promise::Resolver::New(isolate->GetCurrentContext()).ToLocalChecked();
v8::Local<v8::Promise> v8Promise = resolver->GetPromise();
auto *persistentResolver = new v8::Persistent<v8::Promise::Resolver>(isolate, resolver);
v8::Local<v8::Object> jsobj = v8::Local<v8::Object>::Cast(v8Promise);
auto *obj = Object::_createJSObject(nullptr, jsobj);
resolverMap[obj] = persistentResolver;
return obj;
}
Object *Object::createMapObject() {
v8::Local<v8::Map> jsobj = v8::Map::New(__isolate);
return _createJSObject(nullptr, jsobj);
@@ -409,10 +458,8 @@ Object *Object::createJSONObject(std::u16string &&jsonStr) {
v8::Local<v8::Context> context = __isolate->GetCurrentContext();
v8::MaybeLocal<v8::Value> ret = v8::JSON::Parse(context, v8Str.ToLocalChecked());
// After v8::JSON::Parse, the memory of u16string could be freed.
external->freeMemory();
if (ret.IsEmpty()) {
return nullptr;
}
+6 -1
View File
@@ -85,6 +85,9 @@ public:
*/
static Object *createArrayObject(size_t length);
static Object *createPromise();
static void rejectPromise(Object *object, const Value &value);
static void resolverPromise(Object *object, const Value &value);
/**
* @brief Creates a JavaScript Typed Array Object with uint8 format from an existing pointer.
* @param[in] bytes A pointer to the byte buffer to be used as the backing store of the Typed Array object.
@@ -152,7 +155,7 @@ public:
* @note The return value (non-null) has to be released manually.
*/
static Object *createJSONObject(const ccstd::string &jsonStr);
/**
* @brief Creates a JavaScript Object from a JSON formatted string.
* @param[in] jsonStr The utf-16 string containing the JSON string to be parsed.
@@ -705,6 +708,8 @@ private:
ccstd::string _objectCreationStackFrame;
#endif
static std::unordered_map<Object*, v8::Persistent<v8::Promise::Resolver>*> resolverMap;
friend class ScriptEngine;
friend class JSBPersistentHandleVisitor;
};
+4 -11
View File
@@ -52,8 +52,9 @@
#include "platform/java/jni/JniImp.h"
#endif
#if CC_PLATFORM == CC_PLATFORM_OPENHARMONY && SCRIPT_ENGINE_TYPE != SCRIPT_ENGINE_NAPI
#if CC_PLATFORM == CC_PLATFORM_OPENHARMONY
#include "platform/openharmony/napi/NapiHelper.h"
#include "platform/openharmony/napi/NapiPromiseBridge.h"
#endif
extern void jsb_register_ADPF(se::Object *); // NOLINT
@@ -1433,7 +1434,7 @@ static bool JSB_process_get_argv(se::State &s) // NOLINT(readability-identifier-
}
SE_BIND_PROP_GET(JSB_process_get_argv)
#if CC_PLATFORM == CC_PLATFORM_OPENHARMONY && SCRIPT_ENGINE_TYPE != SCRIPT_ENGINE_NAPI
#if CC_PLATFORM == CC_PLATFORM_OPENHARMONY
static bool sevalue_to_napivalue(const se::Value &seVal, Napi::Value *napiVal, Napi::Env env);
@@ -1537,14 +1538,8 @@ static bool JSB_openharmony_postSyncMessage(se::State &s) { // NOLINT(readabilit
SE_REPORT_ERROR("postMessage, Unsupported type");
return false;
}
Napi::Value napiPromise = NapiHelper::postSyncMessageToUIThread(msgType.c_str(), napiArg1);
// TODO(cjh): Implement Promise for se
se::HandleObject retObj(se::Object::createPlainObject());
retObj->defineFunction("then", _SE(JSB_empty_promise_then));
s.rval().setObject(retObj);
//
s.rval().setObject(NapiPromiseBridge::createPromise(napiPromise));
return true;
}
@@ -1619,12 +1614,10 @@ bool jsb_register_global_variables(se::Object *global) { // NOLINT
global->setProperty("performance", se::Value(performanceObj));
#if CC_PLATFORM == CC_PLATFORM_OPENHARMONY
#if SCRIPT_ENGINE_TYPE != SCRIPT_ENGINE_NAPI
se::HandleObject ohObj(se::Object::createPlainObject());
global->setProperty("oh", se::Value(ohObj));
ohObj->defineFunction("postMessage", _SE(JSB_openharmony_postMessage));
ohObj->defineFunction("postSyncMessage", _SE(JSB_openharmony_postSyncMessage));
#endif
#endif
jsb_register_TextEncoder(global);
+1 -1
View File
@@ -218,7 +218,7 @@ ccstd::unordered_map<uint32_t, ccstd::string> debugInfos = {
{ 3933, "Each curve that has common target should be numeric curve and targets string property." },
{ 3934, "Misconfigured legacy curve: the first keyframe value is number but others aren't." },
{ 3935, "We don't currently support conversion of `CubicSplineQuatValue`." },
{ 3936, "Instancing/Batching enabled for non-baked skinning model '%s', this may result in unexpected rendering artifacts. Consider turning it off in the material if you do not intend to do this." },
{ 3936, "Instancing/Batching enabled for non-baked skinning model or used AnimationController '%s', this may result in unexpected rendering artifacts. Consider turning it off in the material if you do not intend to do this." },
{ 3937, "Previous error occurred when instantiating animation clip %s on node %s." },
{ 3938, "'%s' is not found from '%s'. It's specified as the root node to play animation clip '%s'." },
{ 3940, "Error when animation attempted to bind material uniform target: target %s is not a material." },
@@ -16,6 +16,21 @@ using namespace spine;
extern HashMap<SkeletonData *, HashMap<Attachment *, AttachmentVertices *>*> spineAttachmentVerticesMap;
extern HashMap<SkeletonData *, HashMap<spine::String, spine::String>*> spineTexturesMap;
/**
* The slot-associated attachment may exist on different skeletonData, so setSlotTexture needs to traverse all skeletonData.
*/
AttachmentVertices *getAttachmentVertices(Attachment *attachment) {
auto entries = spineAttachmentVerticesMap.getEntries();
while (entries.hasNext()) {
auto entry = entries.next();
auto *skeletonData = entry.key;
auto *attachmentVerticesMap = entry.value;
if (attachmentVerticesMap->containsKey(attachment)) {
return (*attachmentVerticesMap)[attachment];
}
}
return nullptr;
}
template<typename VertexType, typename UVArrayType>
void loopUVCoords(VertexType* tmp, const UVArrayType& uvs, int count) {
@@ -621,11 +636,6 @@ void SpineSkeletonInstance::onAnimationStateEvent(TrackEntry *entry, EventType t
void SpineSkeletonInstance::resizeSlotRegion(const spine::String &slotName, uint32_t width, uint32_t height, bool createNew) {
if (!_skeleton) return;
HashMap<Attachment *, AttachmentVertices *> *attachmentVerticesMap = nullptr;
if (spineAttachmentVerticesMap.containsKey(_skeletonData)) {
attachmentVerticesMap = spineAttachmentVerticesMap[_skeletonData];
}
if (!attachmentVerticesMap) return;
auto* slot = _skeleton->findSlot(slotName);
if (!slot) return;
auto *attachment = slot->getAttachment();
@@ -674,10 +684,7 @@ void SpineSkeletonInstance::resizeSlotRegion(const spine::String &slotName, uint
region->updateRegion();
#endif
AttachmentVertices *attachmentVertices = nullptr;
if (attachmentVerticesMap->containsKey(attachment)) {
attachmentVertices = (*attachmentVerticesMap)[attachment];
}
auto *attachmentVertices = getAttachmentVertices(slot->getAttachment());
if (!attachmentVertices) return;
if (createNew) {
attachmentVertices = attachmentVertices->copy();
@@ -723,10 +730,7 @@ void SpineSkeletonInstance::resizeSlotRegion(const spine::String &slotName, uint
mesh->updateRegion();
#endif
AttachmentVertices *attachmentVertices = nullptr;
if (attachmentVerticesMap->containsKey(attachment)) {
attachmentVertices = (*attachmentVerticesMap)[attachment];
}
auto *attachmentVertices = getAttachmentVertices(slot->getAttachment());
if (!attachmentVertices) return;
if (createNew) {
attachmentVertices = attachmentVertices->copy();
@@ -206,6 +206,11 @@ void CanvasRenderingContext2DDelegate::fillText(const ccstd::string &text, float
return;
}
Size textSize = {0, 0};
uint8_t r = static_cast<uint8_t>(_fillStyle[0]);
uint8_t g = static_cast<uint8_t>(_fillStyle[1]);
uint8_t b = static_cast<uint8_t>(_fillStyle[2]);
uint8_t a = static_cast<uint8_t>(_fillStyle[3]);
OH_Drawing_SetTextStyleColor(_textStyle, OH_Drawing_ColorSetArgb(a, r, g, b));
Point offsetPoint = convertDrawPoint(Point{x, y}, text, _textStyle);
drawText(text, (int)offsetPoint[0], (int)offsetPoint[1]);
if (!_premultiply) {
@@ -308,7 +313,6 @@ void CanvasRenderingContext2DDelegate::setTextBaseline(TextBaseline baseline) {
void CanvasRenderingContext2DDelegate::setFillStyle(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
_fillStyle = {static_cast<float>(r), static_cast<float>(g), static_cast<float>(b), static_cast<float>(a)};
OH_Drawing_SetTextStyleColor(_textStyle, OH_Drawing_ColorSetArgb(a, r, g, b));
}
void CanvasRenderingContext2DDelegate::setStrokeStyle(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
@@ -31,6 +31,7 @@
#include "platform/openharmony/FileUtils-OpenHarmony.h"
#include "platform/openharmony/OpenHarmonyPlatform.h"
#include "platform/openharmony/modules/SystemWindow.h"
#include <thread>
#if CC_USE_EDITBOX
#include "ui/edit-box/EditBox-openharmony.h"
@@ -63,6 +64,7 @@ enum ContextType {
static Napi::Env gWorkerEnv(nullptr);
static Napi::FunctionReference *gPostMessageToUIThreadFunc = nullptr;
static Napi::FunctionReference *gPostSyncMessageToUIThreadFunc = nullptr;
static std::thread::id gMainThreadId;
#define DEFINE_FUNCTION_CALLBACK(functionName, cachedFunctionRefPtr) \
static void functionName(const Napi::CallbackInfo &info) { \
@@ -498,17 +500,32 @@ Napi::Value evalString(const Napi::CallbackInfo &info){
return env.Undefined();
}
se::AutoHandleScope hs;
size_t length = value.length();
char* cValue = new char[length + 1];
strcpy(cValue, value.c_str());
se::Value ret;
se::ScriptEngine::getInstance()->evalString(cValue, length, &ret);
delete[] cValue;
Napi::Value result;
sevalue_to_napivalue(ret, &result, env);
BaseEngine::SchedulerPtr scheduler =
CC_CURRENT_APPLICATION() ? CC_CURRENT_APPLICATION()->getEngine()->getScheduler() : nullptr;
if (!scheduler) {
delete[] cValue;
return env.Undefined();
}
Napi::Value result = env.Undefined();
if(gMainThreadId == std::this_thread::get_id()) {
scheduler->performFunctionInCocosThread([cValue, length]() {
se::AutoHandleScope hs;
se::Value ret;
se::ScriptEngine::getInstance()->evalString(cValue, length, &ret);
delete[] cValue;
});
} else {
se::AutoHandleScope hs;
se::Value ret;
se::ScriptEngine::getInstance()->evalString(cValue, length, &ret);
delete[] cValue;
sevalue_to_napivalue(ret, &result, env);
}
return result;
}
@@ -519,7 +536,10 @@ Napi::Object NapiHelper::init(Napi::Env env, Napi::Object exports) {
bool ret = exportFunctions(exports);
if (!ret) {
CC_LOG_ERROR("NapiHelper init failed");
} else {
gMainThreadId = std::this_thread::get_id();
}
return exports;
}
@@ -0,0 +1,96 @@
/****************************************************************************
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "cocos/platform/openharmony/napi/NapiPromiseBridge.h"
#include "cocos/platform/openharmony/napi/NapiHelper.h"
#include "cocos/bindings/jswrapper/SeApi.h"
namespace cc {
struct CallbackData {
se::Object* object;
};
se::Object* NapiPromiseBridge::createPromise(Napi::Value napiPromise) {
bool isPromise{false};
auto env = NapiHelper::getWorkerEnv();
napi_status status = napi_is_promise(env, napiPromise, &isPromise);
if (status != napi_ok) {
SE_REPORT_ERROR("The returned type is not a promise");
return nullptr;
}
#if (SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_JSVM) || (SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_V8)
se::Object* sePromise = se::Object::createPromise();
bindArkPromise(napiPromise, sePromise);
return sePromise;
#else
return se::Object::_createJSObject(env, napiPromise, nullptr);
#endif
}
#if (SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_JSVM) || (SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_V8)
void NapiPromiseBridge::bindArkPromise(Napi::Value napiPromise, se::Object* sePromise) {
auto cbData = new CallbackData{sePromise};
auto env = NapiHelper::getWorkerEnv();
napi_value onFulfilled;
napi_create_function(env, "onFulfilled", -1, [](napi_env env, napi_callback_info info) -> napi_value {
se::AutoHandleScope hs;
size_t argc = 1;
napi_value argv[1];
void* data;
napi_get_cb_info(env, info, &argc, argv, nullptr, &data);
se::Value seArg;
NapiValueConverter::NapiValueToSeValue(env, argv[0], &seArg);
auto cbData = static_cast<CallbackData*>(data);
se::Object::resolverPromise(cbData->object, seArg);
napi_value undefined;
napi_get_undefined(env, &undefined);
delete cbData;
return undefined; }, cbData, &onFulfilled);
napi_value onRejected;
napi_create_function(env, "onRejected", -1, [](napi_env env, napi_callback_info info) -> napi_value {
se::AutoHandleScope hs;
size_t argc = 1;
napi_value argv[1];
void* data;
napi_get_cb_info(env, info, &argc, argv, nullptr, &data);
se::Value seArg;
NapiValueConverter::NapiValueToSeValue(env, argv[0], &seArg);
auto cbData = static_cast<CallbackData*>(data);
se::Object::rejectPromise(cbData->object, seArg);
napi_value undefined;
napi_get_undefined(env, &undefined);
delete cbData;
return undefined; }, cbData, &onRejected);
napi_value thenFunc;
napi_get_named_property(env, napiPromise, "then", &thenFunc);
napi_value argvThen[2] = {onFulfilled, onRejected};
napi_value thenResult;
napi_call_function(env, napiPromise, thenFunc, 2, argvThen, &thenResult);
}
#endif
} // namespace cc
@@ -0,0 +1,47 @@
/****************************************************************************
Copyright (c) 2025 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#pragma once
#define NODE_ADDON_API_ENABLE_TYPE_CHECK_ON_AS 1
#define NAPI_DISABLE_CPP_EXCEPTIONS 1
#define NODE_ADDON_API_DISABLE_DEPRECATED 1
#include "cocos/platform/openharmony/napi/napi.h"
#include "cocos/bindings/jswrapper/config.h"
namespace se {
class Object;
}
namespace cc {
class NapiPromiseBridge {
public:
static se::Object* createPromise(Napi::Value napiPromise);
private:
#if (SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_JSVM) || (SCRIPT_ENGINE_TYPE == SCRIPT_ENGINE_V8)
static void bindArkPromise(Napi::Value napiPromise, se::Object* sePromise);
#endif
};
} // namespace cc
@@ -1,5 +1,7 @@
#include "NapiValueConverter.h"
#include <stdexcept>
#include "cocos/bindings/jswrapper/Value.h"
#include "base/Log.h"
napi_valuetype GetNapiValueType(napi_env env, napi_value value) {
napi_valuetype type;
@@ -86,4 +88,78 @@ napi_value NapiValueConverter::ToNapiValue(napi_env env, const char* value) {
napi_value NapiValueConverter::ToNapiValue(napi_env env, std::string value) {
return ToNapiValue(env, value.c_str());
}
}
bool NapiValueConverter::NapiValueToSeValue(napi_env env, napi_value value, se::Value* v) {
napi_status status;
napi_valuetype valType;
int64_t iRet = 0;
double dRet = 0.0;
bool bRet = false;
bool lossless = false;
size_t len = 0;
if (!value) {
valType = napi_valuetype::napi_undefined;
} else {
status = napi_typeof(env, value, &valType);
if (status != napi_ok) {
CC_LOG_WARNING("warning:%d", status);
return false;
}
}
switch (valType) {
case napi_valuetype::napi_undefined:
v->setUndefined();
break;
case napi_valuetype::napi_null:
v->setNull();
break;
case napi_valuetype::napi_number:
status = napi_get_value_double(env, value, &dRet);
if (status == napi_ok) {
v->setDouble(dRet);
} else {
CC_LOG_WARNING("warning:%d", status);
v->setUndefined();
}
break;
case napi_valuetype::napi_bigint:
status = napi_get_value_bigint_int64(env, value, &iRet, &lossless);
if (lossless) {
v->setInt64(iRet);
} else {
v->setUndefined();
}
break;
case napi_valuetype::napi_string:
status = napi_get_value_string_utf8(env, value, nullptr, 0, &len);
if (status == napi_ok) {
std::string valueStr;
len += 1;
valueStr.resize(len);
status = napi_get_value_string_utf8(env, value, const_cast<char*>(valueStr.data()), valueStr.size(), &len);
if (valueStr.length() != len) {
valueStr.resize(len);
}
v->setString(valueStr);
} else {
CC_LOG_WARNING("warning:%d", status);
v->setUndefined();
}
break;
case napi_valuetype::napi_boolean:
status = napi_get_value_bool(env, value, &bRet);
if (status == napi_ok) {
v->setBoolean(bRet);
} else {
CC_LOG_WARNING("warning:%d", status);
v->setUndefined();
}
break;
default:
break;
}
return true;
}
@@ -1,6 +1,9 @@
#include <napi/native_api.h>
#include <string>
namespace se {
class Value;
}
class NapiValueConverter {
public:
template<typename ReturnType>
@@ -13,4 +16,5 @@ public:
static napi_value ToNapiValue(napi_env env, const char* value);
static napi_value ToNapiValue(napi_env env, std::string value);
static bool NapiValueToSeValue(napi_env env, napi_value value, se::Value *v);
};
+12 -4
View File
@@ -63,9 +63,13 @@ glslang::EShTargetClientVersion getClientVersion(int vulkanMinorVersion) {
case 1: return glslang::EShTargetVulkan_1_1;
case 2: return glslang::EShTargetVulkan_1_2;
#if CC_GLSLANG_VERSION_GREATOR_OR_EQUAL_TO(11, 10, 0)
case 3: return glslang::EShTargetVulkan_1_3;
case 3:
case 4:
return glslang::EShTargetVulkan_1_3;
#else
case 3: return glslang::EShTargetVulkan_1_2;
case 3:
case 4:
return glslang::EShTargetVulkan_1_2;
#endif
default: {
CC_ABORT();
@@ -80,9 +84,13 @@ glslang::EShTargetLanguageVersion getTargetVersion(int vulkanMinorVersion) {
case 1: return glslang::EShTargetSpv_1_3;
case 2: return glslang::EShTargetSpv_1_5;
#if CC_GLSLANG_VERSION_GREATOR_OR_EQUAL_TO(11, 10, 0)
case 3: return glslang::EShTargetSpv_1_6;
case 3:
case 4:
return glslang::EShTargetSpv_1_6;
#else
case 3: return glslang::EShTargetSpv_1_5;
case 3:
case 4:
return glslang::EShTargetSpv_1_5;
#endif
default: {
CC_ABORT();
@@ -542,7 +542,6 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
ResourceGraph::vertex_descriptor srcID,
ResourceGraph::vertex_descriptor dstID) const {
auto& resg = ctx.resourceGraph;
std::vector<gfx::TextureCopy> copyInfos(copy.mipLevels, gfx::TextureCopy{});
gfx::Texture* srcTexture = resg.getTexture(srcID);
gfx::Texture* dstTexture = resg.getTexture(dstID);
@@ -551,13 +550,21 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
if (!srcTexture || !dstTexture) {
return;
}
const auto& srcInfo = srcTexture->getInfo();
const auto& dstInfo = dstTexture->getInfo();
CC_ENSURES(srcInfo.width == dstInfo.width);
CC_ENSURES(srcInfo.height == dstInfo.height);
CC_ENSURES(srcInfo.depth == dstInfo.depth);
CC_ENSURES(srcInfo.levelCount == dstInfo.levelCount);
for (uint32_t i = 0; i < copy.mipLevels; ++i) {
const uint32_t mipLevels = std::min(
copy.mipLevels,
srcTexture->getInfo().levelCount);
std::vector<gfx::TextureCopy> copyInfos(mipLevels, gfx::TextureCopy{});
for (uint32_t i = 0; i < mipLevels; ++i) {
auto& copyInfo = copyInfos[i];
copyInfo.srcSubres.mipLevel = copy.sourceMostDetailedMip + i;
copyInfo.srcSubres.baseArrayLayer = copy.sourceFirstSlice;
-1
View File
@@ -104,7 +104,6 @@ void ReflectionProbe::syncCameraParams(const Camera* camera) {
_camera->setClearFlag(camera->getClearFlag());
_camera->setClearColor(camera->getClearColor());
_camera->setPriority(camera->getPriority() - 1);
_camera->changeTargetWindow(_realtimePlanarTexture->getWindow());
_camera->resize(camera->getWidth(), camera->getHeight());
}
+1 -1
View File
@@ -3,6 +3,6 @@
"type": "github",
"owner": "cocos",
"name": "cocos-engine-external",
"checkout": "v3.8.7-15"
"checkout": "v3.8.7-17"
}
}
+1 -1
View File
@@ -75,7 +75,7 @@ gulp.task('gen-simulator', async function () {
var args = [];
args.push('-G');
if (isWin32) {
args.push('Visual Studio 16 2019','-A','x64');
args.push('Visual Studio 17 2022','-A','x64');
}
else {
args.push('Xcode');
+4 -4
View File
@@ -11,7 +11,7 @@
"license": "MIT",
"dependencies": {
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@cocos/box2d": "1.0.1",
"@cocos/box2d": "1.0.2",
"@cocos/cannon": "1.2.8",
"@cocos/ccbuild": "^2.3.16",
"@cocos/dragonbones-js": "^1.0.1",
@@ -2048,9 +2048,9 @@
}
},
"node_modules/@cocos/box2d": {
"version": "1.0.1",
"resolved": "https://registry.npmmirror.com/@cocos/box2d/-/box2d-1.0.1.tgz",
"integrity": "sha512-qNPK0KZEnEwMMtrj1f/p71FuuutmzXD0n1z6jLU3ntULk7EyNfnlsKUkAZEDVtr9nPmUvQozt/XquZ+biGxTCg==",
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/@cocos/box2d/-/box2d-1.0.2.tgz",
"integrity": "sha512-5XTWfbSCuv9SoWaT0Xa3/jrKMWVd+txI8A/KfgCEyzQzLG0QckzfEC+7nb8cwOnzGWUI/cA0O0FnNr8V2Z/AZw==",
"dependencies": {
"@types/systemjs": "^0.20.6"
}
+1 -1
View File
@@ -77,7 +77,7 @@
},
"dependencies": {
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@cocos/box2d": "1.0.1",
"@cocos/box2d": "1.0.2",
"@cocos/cannon": "1.2.8",
"@cocos/ccbuild": "^2.3.16",
"@cocos/dragonbones-js": "^1.0.1",
@@ -31,7 +31,7 @@ const fsUtils = {
fs,
isOutOfStorage (errorCode) {
return errorCode.toString() === outOfStorageErrorCode;
return errorCode != null && String(errorCode) === outOfStorageErrorCode;
},
getUserDataPath () {
@@ -31,4 +31,7 @@ export interface context {
}
export const getContext: (type: ContextType) => context;
// This function is thread-safe and can be called on the main thread.
// However, there is no return value when calling it on the main thread.
export const evalString: (value: string) => boolean | number | string;
@@ -112,6 +112,8 @@ export struct CocosVideoPlayer {
videoTag: this.videoInfo.viewTag,
videoEvent: EventType.COMPLETED
} as param);
//make it playable again.
this.videoInfo.controller.setCurrentTime(0, SeekMode.Accurate);
})
.onPrepared((event): void => {
this.videoInfo.isPreparedStart && this.videoInfo.controller.start();
@@ -307,7 +307,7 @@ struct Index {
let index = this.videoIndexMap.get(tag) as number;
this.videoArray[index].controller.pause();
});
this.workPort?.on("pauseVideo",(tag: number) => {
this.workPort?.on("stopVideo",(tag: number) => {
let index = this.videoIndexMap.get(tag) as number;
this.videoArray[index].controller.stop();
});
@@ -110,8 +110,8 @@ uiPort.on("onErrorReceive", (viewTag: number, url: string) => {
nativeWebView.failLoading(viewTag, url);
})
uiPort.on("onVideoEvent", (videoTag: number, videoEvent: number, arg?: AnyType ) => {
nativeVideo.onVideoEvent(JSON.stringify({videoTag: videoTag, videoEvent: videoEvent, arg: arg ?? null}));
uiPort.on("onVideoEvent", (videoTag: number, videoEvent: number, args?: AnyType ) => {
nativeVideo.onVideoEvent(JSON.stringify({videoTag: videoTag, videoEvent: videoEvent, args: args ?? null}));
})
uiPort.on("backPress", () => {