Skip to content

Commit

Permalink
add adpf bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
PatriceJiang committed Oct 27, 2023
1 parent 1e3155b commit 6b4ad91
Show file tree
Hide file tree
Showing 11 changed files with 737 additions and 119 deletions.
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 @@ -123,7 +123,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 @@ -136,7 +136,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 @@ -161,43 +161,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 @@ -230,22 +230,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 @@ -262,23 +262,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 @@ -301,44 +301,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 @@ export declare namespace native {
* @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 @@ export declare namespace native {
* @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 declare namespace native {
*/
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 A number indicating the current thermal headroom. The value can exceed 1.
* @zh 表示当前热头寸余量数字。该值可以超过1
* @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 - thermalStatusMax) / 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 - thermalStatusMax) / 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;
}
2 changes: 2 additions & 0 deletions native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,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
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

0 comments on commit 6b4ad91

Please sign in to comment.