Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

ADPF bindings #16445

Merged
merged 4 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 93 additions & 83 deletions @types/jsb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ declare namespace jsb {
wheelDeltaX: number,
wheelDeltaY: number,
}
type MouseWheelEventCallback = (mouseEvent: MouseWheelEvent) => void;
type MouseWheelEventCallback = (mouseEvent: MouseWheelEvent) => void;
export let onMouseDown: MouseEventCallback | undefined;
export let onMouseMove: MouseEventCallback | undefined;
export let onMouseUp: MouseEventCallback | undefined;
export let onMouseWheel: MouseWheelEventCallback | undefined;

type TouchEventCallback = (touchList: TouchList, windowId?: number) => void;
type TouchEventCallback = (touchList: TouchList, windowId?: number) => void;
export let onTouchStart: TouchEventCallback | undefined;
export let onTouchMove: TouchEventCallback | undefined;
export let onTouchEnd: TouchEventCallback | undefined;
Expand Down Expand Up @@ -129,7 +129,7 @@ declare namespace jsb {
}
type KeyboardEventCallback = (keyboardEvent: KeyboardEvent) => void;
export let onKeyDown: KeyboardEventCallback | undefined;
export let onKeyUp: KeyboardEventCallback| undefined;
export let onKeyUp: KeyboardEventCallback | undefined;

export interface WindowEvent {
windowId: number;
Expand All @@ -142,7 +142,7 @@ declare namespace jsb {
* @zh WindowEvent.width 和 WindowEvent.height 都已乘以 DPR
*/
export let onResize: (event: WindowEvent) => void | undefined;
export let onOrientationChanged: (event: {orientation: number}) => void | undefined; // TODO: enum orientation type
export let onOrientationChanged: (event: { orientation: number }) => void | undefined; // TODO: enum orientation type
export let onResume: () => void | undefined;
export let onPause: () => void | undefined;
export let onClose: () => void | undefined;
Expand All @@ -167,43 +167,43 @@ declare namespace jsb {
channelCount: number;
}
export namespace AudioEngine {
export function preload (url: string, cb: (isSuccess: boolean) => void);

export function play2d (url: string, loop: boolean, volume: number): number;
export function pause (id: number);
export function pauseAll ();
export function resume (id: number);
export function resumeAll ();
export function stop (id: number);
export function stopAll ();

export function getPlayingAudioCount (): number;
export function getMaxAudioInstance (): number;
export function getState (id: number): any;
export function getDuration (id: number): number;
export function getVolume (id: number): number;
export function isLoop (id: number): boolean;
export function getCurrentTime (id: number): number;

export function setVolume (id: number, val: number);
export function setLoop (id: number, val: boolean);
export function setCurrentTime (id: number, val: number);

export function uncache (url: string);
export function uncacheAll ();
export function setErrorCallback (id: number, cb: (err: any) => void);
export function setFinishCallback (id: number, cb: () => void);
export function preload(url: string, cb: (isSuccess: boolean) => void);

export function play2d(url: string, loop: boolean, volume: number): number;
export function pause(id: number);
export function pauseAll();
export function resume(id: number);
export function resumeAll();
export function stop(id: number);
export function stopAll();

export function getPlayingAudioCount(): number;
export function getMaxAudioInstance(): number;
export function getState(id: number): any;
export function getDuration(id: number): number;
export function getVolume(id: number): number;
export function isLoop(id: number): boolean;
export function getCurrentTime(id: number): number;

export function setVolume(id: number, val: number);
export function setLoop(id: number, val: boolean);
export function setCurrentTime(id: number, val: number);

export function uncache(url: string);
export function uncacheAll();
export function setErrorCallback(id: number, cb: (err: any) => void);
export function setFinishCallback(id: number, cb: () => void);

/**
* Get PCM header without pcm data. if you want to get pcm data, use getOriginalPCMBuffer instead
*/
export function getPCMHeader (url: string): PCMHeader;
export function getPCMHeader(url: string): PCMHeader;
/**
* Get PCM Data in decode format for example Int16Array, the format information is written in PCMHeader.
* @param url: file relative path, for example player._path
* @param channelID: ChannelID which should smaller than channel count, start from 0
*/
export function getOriginalPCMBuffer (url: string, channelID: number): ArrayBuffer | undefined;
export function getOriginalPCMBuffer(url: string, channelID: number): ArrayBuffer | undefined;
}

class NativePOD {
Expand Down Expand Up @@ -236,22 +236,22 @@ declare namespace jsb {
}

export class Manifest {
constructor (manifestUrl: string);
constructor (content: string, manifestRoot: string);
parseFile (manifestUrl: string): void;
parseJSONString (content: string, manifestRoot: string): void;
constructor(manifestUrl: string);
constructor(content: string, manifestRoot: string);
parseFile(manifestUrl: string): void;
parseJSONString(content: string, manifestRoot: string): void;

getManifestRoot (): string;
getManifestFileUrl (): string;
getVersionFileUrl (): string;
getSearchPaths (): [string];
getVersion (): string;
getPackageUrl (): boolean;
getManifestRoot(): string;
getManifestFileUrl(): string;
getVersionFileUrl(): string;
getSearchPaths(): [string];
getVersion(): string;
getPackageUrl(): boolean;

setUpdating (isUpdating: boolean): void;
isUpdating (): boolean;
isVersionLoaded (): boolean;
isLoaded (): boolean;
setUpdating(isUpdating: boolean): void;
isUpdating(): boolean;
isVersionLoaded(): boolean;
isLoaded(): boolean;
}

export class EventAssetsManager {
Expand All @@ -268,23 +268,23 @@ declare namespace jsb {
static UPDATE_FAILED: number;
static ERROR_DECOMPRESS: number;

constructor (eventName: string, manager: AssetsManager, eventCode: number,
constructor(eventName: string, manager: AssetsManager, eventCode: number,
assetId?: string, message?: string, curleCode?: number, curlmCode?: number);
getAssetsManagerEx (): AssetsManager;
isResuming (): boolean;
getAssetsManagerEx(): AssetsManager;
isResuming(): boolean;

getDownloadedFiles (): number;
getDownloadedBytes (): number;
getTotalFiles (): number;
getTotalBytes (): number;
getPercent (): number;
getPercentByFile (): number;
getDownloadedFiles(): number;
getDownloadedBytes(): number;
getTotalFiles(): number;
getTotalBytes(): number;
getPercent(): number;
getPercentByFile(): number;

getEventCode (): number;
getMessage (): string;
getAssetId (): string;
getCURLECode (): number;
getCURLMCode (): number;
getEventCode(): number;
getMessage(): string;
getAssetId(): string;
getCURLECode(): number;
getCURLMCode(): number;
}

export namespace AssetsManager {
Expand All @@ -307,44 +307,54 @@ declare namespace jsb {
}

export class AssetsManager {
constructor (manifestUrl: string, storagePath: string, versionCompareHandle?: (versionA: string, versionB: string) => number);
static create (manifestUrl: string, storagePath: string): AssetsManager;
constructor(manifestUrl: string, storagePath: string, versionCompareHandle?: (versionA: string, versionB: string) => number);
static create(manifestUrl: string, storagePath: string): AssetsManager;

getState (): AssetsManager.State;
getStoragePath (): string
getMaxConcurrentTask (): number;
getState(): AssetsManager.State;
getStoragePath(): string
getMaxConcurrentTask(): number;
// setMaxConcurrentTask (max: number): void; // actually not supported

checkUpdate (): void;
prepareUpdate (): void;
update (): void;
isResuming (): boolean;
checkUpdate(): void;
prepareUpdate(): void;
update(): void;
isResuming(): boolean;

getDownloadedFiles (): number;
getDownloadedBytes (): number;
getTotalFiles (): number;
getTotalBytes (): number;
downloadFailedAssets (): void;
getDownloadedFiles(): number;
getDownloadedBytes(): number;
getTotalFiles(): number;
getTotalBytes(): number;
downloadFailedAssets(): void;

getLocalManifest (): Manifest;
loadLocalManifest (manifestUrl: string): boolean;
loadLocalManifest (localManifest: Manifest, storagePath: string): boolean;
getRemoteManifest (): Manifest;
loadRemoteManifest (remoteManifest: Manifest): boolean;
getLocalManifest(): Manifest;
loadLocalManifest(manifestUrl: string): boolean;
loadLocalManifest(localManifest: Manifest, storagePath: string): boolean;
getRemoteManifest(): Manifest;
loadRemoteManifest(remoteManifest: Manifest): boolean;

/**
* Setup your own version compare handler, versionA and B is versions in string.
* if the return value greater than 0, versionA is greater than B,
* if the return value equals 0, versionA equals to B,
* if the return value smaller than 0, versionA is smaller than B.
*/
setVersionCompareHandle (versionCompareHandle?: (versionA: string, versionB: string) => number): void;
setVersionCompareHandle(versionCompareHandle?: (versionA: string, versionB: string) => number): void;
/**
* Setup the verification callback, Return true if the verification passed, otherwise return false
*/
setVerifyCallback (verifyCallback: (path: string, asset: ManifestAsset) => boolean): void;
setEventCallback (eventCallback: (event: EventAssetsManager) => void): void;
}
setVerifyCallback(verifyCallback: (path: string, asset: ManifestAsset) => boolean): void;
setEventCallback(eventCallback: (event: EventAssetsManager) => void): void;
}

// Android ADPF module
const adpf: {
readonly thermalHeadroom: number;
readonly thermalStatus: number;
readonly thermalStatusMin: number;
readonly thermalStatusMax: number;
readonly thermalStatusNormalized: number;
onThermalStatusChanged?: (previousStatus: number, newStatus: number, statusMin: number, statusMax: number) => void;
} | undefined;
}

declare namespace ns {
Expand Down
1 change: 1 addition & 0 deletions cocos/native-binding/impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,5 @@ export const native = {
Manifest: globalJsb.Manifest,
saveImageData: globalJsb.saveImageData,
process: globalJsb.process,
adpf: globalJsb.adpf,
};
54 changes: 52 additions & 2 deletions cocos/native-binding/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@
* @param storagePath @en Storage path for downloaded file @zh 下载文件存储路径
* @param identifier @en identifier @zh 标识符
*/
export type DownloadTask = { requestURL: string, storagePath: string, identifier: string };
export interface DownloadTask { requestURL: string, storagePath: string, identifier: string }

/**
* @en DownloaderTask @zh 下载任务对象
Expand All @@ -390,7 +390,7 @@
* @param identifier @en identifier @zh 标识符
* @deprecated since v3.7.0, please use `DownloadTask` to instead.
*/
export type DownloaderTask = { requestURL: string, storagePath: string, identifier: string };
export interface DownloaderTask { requestURL: string, storagePath: string, identifier: string }

/**
* @en DownloaderHints @zh 下载任务的配置接口
Expand Down Expand Up @@ -1401,4 +1401,54 @@
*/
export const argv: Readonly<string[]>;
}

/**
* @en This object provides properties related to thermal characteristics and an optional callback function to track changes in thermal status.
* It is supported only on Android platforms with an API level of 31 or higher.
* @zh 该对象提供与热特性相关的属性以及用于跟踪热状态变化的可选回调函数。仅支持 API 等级为 31 或更高的 Android 平台。
*
* @see https://developer.android.com/ndk/reference/group/thermal#group___thermal_1ga1055f6c8d5910a1904162bea75807314
*/
const adpf: {
/**
* @en Provides an estimate of how much thermal headroom the device currently has before hitting severe throttling. The value range is a non-negative float, where 0.0 represents a fixed distance from overheating, 1.0 indicates the device will be severely throttled, and values greater than 1.0 may imply even heavier throttling.

Check warning on line 1414 in cocos/native-binding/index.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 336. Maximum allowed is 150
* @zh 提供设备在达到严重节流之前当前有多少热余量的估计值。值的范围是非负浮点数,其中0.0表示距离过热的固定距离,1.0表示设备将被严重限制,而大于1.0的值可能表示更重的限制。
* @see https://developer.android.com/ndk/reference/group/thermal#group___thermal_1ga1055f6c8d5910a1904162bea75807314
*/
readonly thermalHeadroom: number;
/**
* @en A number indicating the current thermal status
* @zh 表示当前热状态的数字
*/
readonly thermalStatus: number;
/**
* @en A number indicating the minimum threshold for thermal status
* @zh 表示热状态的最大阈值的数字
*/
readonly thermalStatusMin: number;
/**
* @en A number indicating the maximum threshold for thermal status
* @zh 表示热状态的最大阈值的数字
*/
readonly thermalStatusMax: number;
/**
* @en A normalized value of the current thermal status. It's computed based on the formula:
* (thermalStatus - thermalStatusMin) / thermalStatusMax.
* This value ranges between 0 and 1, giving a relative measure of the current thermal status against its minimum and maximum thresholds.
* @zh 当前热状态的归一化值,范围在 0 到 1 之间. 它是基于以下公式计算的: (thermalStatus - thermalStatusMin) / thermalStatusMax.
* 提供了当前热状态相对于其最小和最大阈值的相对测量。
*/
readonly thermalStatusNormalized: number;
/**
* @en An optional callback function that is triggered when the thermal status changes
* @zh 该对象提供与热特性相关的属性以及用于跟踪热状态变化的可选回调函数
*
* @param previousStatus @zh 之前的热状态 @en The previous thermal status
* @param newStatus @zh 更改后的新热状态 @en The new thermal status after the change
* @param statusMin @zh 热状态的最小阈值 @en The minimum threshold for thermal status
* @param statusMax @zh 热状态的最大阈值 @en The maximum threshold for thermal status
* @returns
*/
onThermalStatusChanged?: (previousStatus: number, newStatus: number, statusMin: number, statusMax: number) => void;
} | undefined;
}
3 changes: 3 additions & 0 deletions native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,8 @@ elseif(ANDROID)
cocos/platform/android/AndroidPlatform.cpp
cocos/platform/android/AndroidPlatform.h
cocos/platform/android/AndroidKeyCodes.cpp
cocos/platform/android/adpf_manager.h
cocos/platform/android/adpf_manager.cpp
)
elseif(OPENHARMONY)
cocos_source_files(
Expand Down Expand Up @@ -2529,6 +2531,7 @@ cocos_source_files(
cocos/bindings/manual/jsb_xmlhttprequest.h
cocos/bindings/manual/jsb_pipeline_manual.h
cocos/bindings/manual/jsb_pipeline_manual.cpp
cocos/bindings/manual/jsb_adpf.cpp
)
if(USE_AUDIO)
cocos_source_files(
Expand Down
7 changes: 7 additions & 0 deletions native/cocos/application/BaseGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include "platform/interfaces/modules/ISystemWindowManager.h"
#include "renderer/pipeline/GlobalDescriptorSetManager.h"

#if CC_PLATFORM == CC_PLATFORM_ANDROID
#include "platform/android/adpf_manager.h"
#endif
extern "C" void cc_load_all_plugins(); // NOLINT

namespace cc {
Expand All @@ -36,6 +39,10 @@ int BaseGame::init() {

cc_load_all_plugins();

#if (CC_PLATFORM == CC_PLATFORM_ANDROID) && CC_SUPPORT_ADPF
ADPFManager::getInstance().Initialize();
#endif

#if CC_PLATFORM == CC_PLATFORM_WINDOWS || CC_PLATFORM == CC_PLATFORM_LINUX || CC_PLATFORM == CC_PLATFORM_QNX || CC_PLATFORM == CC_PLATFORM_MACOS
// override default value
//_windowInfo.x = _windowInfo.x == -1 ? 0 : _windowInfo.x;
Expand Down
Loading
Loading