no message

This commit is contained in:
gem
2025-02-18 15:21:31 +08:00
commit 2d133e56d7
1980 changed files with 465595 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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 "BufferAllocator.h"
#include "base/Log.h"
#include "base/memory/Memory.h"
namespace se {
BufferAllocator::BufferAllocator(PoolType type)
: _type(type) {
}
BufferAllocator::~BufferAllocator() {
for (auto buffer : _buffers) {
buffer.second->decRef();
}
_buffers.clear();
}
se::Object *BufferAllocator::alloc(uint32_t index, uint32_t bytes) {
if (_buffers.count(index)) {
se::Object *oldObj = _buffers[index];
oldObj->decRef();
}
se::Object *obj = se::Object::createArrayBufferObject(nullptr, bytes);
_buffers[index] = obj;
uint8_t *ret = nullptr;
size_t len;
obj->getArrayBufferData(static_cast<uint8_t **>(&ret), &len);
return obj;
}
void BufferAllocator::free(uint32_t index) {
if (_buffers.count(index)) {
se::Object *oldObj = _buffers[index];
oldObj->decRef();
_buffers.erase(index);
}
}
} // namespace se

View File

@@ -0,0 +1,49 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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
#include "PoolType.h"
#include "cocos/base/Macros.h"
#include "cocos/base/std/container/unordered_map.h"
#include "cocos/bindings/jswrapper/Object.h"
namespace se {
class CC_DLL BufferAllocator final {
public:
explicit BufferAllocator(PoolType type);
~BufferAllocator();
se::Object *alloc(uint32_t index, uint32_t bytes);
void free(uint32_t index);
private:
static constexpr uint32_t BUFFER_MASK = ~(1 << 30);
ccstd::unordered_map<uint32_t, se::Object *> _buffers;
PoolType _type = PoolType::UNKNOWN;
};
} // namespace se

View File

@@ -0,0 +1,56 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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 "BufferPool.h"
#include "base/Macros.h"
#include "base/memory/Memory.h"
namespace se {
BufferPool::BufferPool(PoolType type, uint32_t entryBits, uint32_t bytesPerEntry)
: _allocator(type),
_entryBits(entryBits),
_bytesPerEntry(bytesPerEntry),
_type(type) {
_entriesPerChunk = 1 << entryBits;
_entryMask = _entriesPerChunk - 1;
_chunkMask = 0xffffffff & ~(_entryMask | POOL_FLAG);
_bytesPerChunk = _bytesPerEntry * _entriesPerChunk;
}
BufferPool::~BufferPool() = default;
se::Object *BufferPool::allocateNewChunk() {
se::Object *jsObj = _allocator.alloc(static_cast<uint32_t>(_chunks.size()), _bytesPerChunk);
uint8_t *realPtr = nullptr;
size_t len = 0;
jsObj->getArrayBufferData(&realPtr, &len);
_chunks.push_back(realPtr);
return jsObj;
}
} // namespace se

View File

@@ -0,0 +1,68 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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
#include "BufferAllocator.h"
#include "PoolType.h"
#include "base/std/container/vector.h"
#include "cocos/base/Macros.h"
#include "cocos/bindings/jswrapper/Object.h"
namespace se {
class CC_DLL BufferPool final {
public:
using Chunk = uint8_t *;
inline static uint32_t getPoolFlag() { return POOL_FLAG; }
BufferPool(PoolType type, uint32_t entryBits, uint32_t bytesPerEntry);
~BufferPool();
template <class T>
T *getTypedObject(uint32_t id) const {
uint32_t chunk = (_chunkMask & id) >> _entryBits;
uint32_t entry = _entryMask & id;
CC_ASSERT(chunk < _chunks.size() && entry < _entriesPerChunk);
return reinterpret_cast<T *>(_chunks[chunk] + (entry * _bytesPerEntry));
}
se::Object *allocateNewChunk();
private:
static constexpr uint32_t POOL_FLAG{1 << 30};
BufferAllocator _allocator;
ccstd::vector<Chunk> _chunks;
uint32_t _entryBits{1 << 8};
uint32_t _chunkMask{0};
uint32_t _entryMask{0};
uint32_t _bytesPerChunk{0};
uint32_t _entriesPerChunk{0};
uint32_t _bytesPerEntry{0};
PoolType _type{PoolType::UNKNOWN};
};
} // namespace se

View File

@@ -0,0 +1,37 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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
namespace se {
#define CAST_POOL_TYPE(type) static_cast<uint32_t>(type)
#define GET_BUFFER_POOL_ID(type) CAST_POOL_TYPE(type)
enum class PoolType {
// Buffers
NODE,
UNKNOWN
};
} // namespace se

View File

@@ -0,0 +1,185 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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 "jsb_dop.h"
#include "BufferAllocator.h"
#include "BufferPool.h"
#include "cocos/bindings/manual/jsb_classtype.h"
#include "cocos/bindings/manual/jsb_conversions.h"
#include "cocos/bindings/manual/jsb_global.h"
/********************************************************
BufferPool binding
*******************************************************/
se::Class *jsb_BufferPool_class = nullptr; // NOLINT
static bool jsb_BufferPool_allocateNewChunk(se::State &s) { // NOLINT
auto *pool = static_cast<se::BufferPool *>(s.nativeThisObject());
SE_PRECONDITION2(pool, false, "Invalid Native Object");
s.rval().setObject(pool->allocateNewChunk());
return true;
}
SE_BIND_FUNC(jsb_BufferPool_allocateNewChunk);
SE_DECLARE_FINALIZE_FUNC(jsb_BufferPool_finalize)
static bool jsb_BufferPool_constructor(se::State &s) { // NOLINT
const auto &args = s.args();
size_t argc = args.size();
if (argc == 3) {
uint32_t poolType{0};
uint32_t entryBits{0};
uint32_t bytesPerEntry{0};
bool ok = true;
ok &= sevalue_to_native(args[0], &poolType);
ok &= sevalue_to_native(args[1], &entryBits);
ok &= sevalue_to_native(args[2], &bytesPerEntry);
if (!ok) {
SE_REPORT_ERROR("jsb_BufferPool_constructor: argument convertion error");
return false;
}
auto *pool = JSB_ALLOC(se::BufferPool, (se::PoolType)poolType, entryBits, bytesPerEntry);
s.thisObject()->setPrivateData(pool);
return true;
}
SE_REPORT_ERROR("jsb_BufferPool_constructor: wrong number of arguments: %d", (int)argc);
return false;
}
SE_BIND_CTOR(jsb_BufferPool_constructor, jsb_BufferPool_class, jsb_BufferPool_finalize) // NOLINT
static bool jsb_BufferPool_finalize(se::State &s) { // NOLINT
return true;
}
SE_BIND_FINALIZE_FUNC(jsb_BufferPool_finalize)
static bool js_register_se_BufferPool(se::Object *obj) { // NOLINT
se::Class *cls = se::Class::create("NativeBufferPool", obj, nullptr, _SE(jsb_BufferPool_constructor));
cls->defineFunction("allocateNewChunk", _SE(jsb_BufferPool_allocateNewChunk));
cls->install();
JSBClassType::registerClass<se::BufferPool>(cls);
jsb_BufferPool_class = cls; // NOLINT
se::ScriptEngine::getInstance()->clearException();
return true;
}
/*****************************************************
Array binding
******************************************************/
static se::Class *jsb_BufferAllocator_class = nullptr; // NOLINT
SE_DECLARE_FINALIZE_FUNC(jsb_BufferAllocator_finalize)
static bool jsb_BufferAllocator_constructor(se::State &s) { // NOLINT
const auto &args = s.args();
size_t argc = args.size();
if (argc == 1) {
uint32_t type{0};
auto *bufferAllocator = JSB_ALLOC(se::BufferAllocator, static_cast<se::PoolType>(type));
s.thisObject()->setPrivateData(bufferAllocator);
return true;
}
SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc);
return false;
}
SE_BIND_CTOR(jsb_BufferAllocator_constructor, jsb_BufferAllocator_class, jsb_BufferAllocator_finalize)
static bool jsb_BufferAllocator_finalize(se::State &s) { // NOLINT
return true;
}
SE_BIND_FINALIZE_FUNC(jsb_BufferAllocator_finalize)
static bool jsb_BufferAllocator_alloc(se::State &s) { // NOLINT
auto *bufferAllocator = static_cast<se::BufferAllocator *>(s.nativeThisObject());
SE_PRECONDITION2(bufferAllocator, false, "Invalid Native Object");
const auto &args = s.args();
size_t argc = args.size();
if (argc == 2) {
uint32_t index{0};
sevalue_to_native(args[0], &index);
uint32_t bytes{0};
sevalue_to_native(args[1], &bytes);
s.rval().setObject(bufferAllocator->alloc(index, bytes));
return true;
}
SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc);
return false;
}
SE_BIND_FUNC(jsb_BufferAllocator_alloc);
static bool jsb_BufferAllocator_free(se::State &s) { // NOLINT
auto *bufferAllocator = static_cast<se::BufferAllocator *>(s.nativeThisObject());
SE_PRECONDITION2(bufferAllocator, false, "Invalid Native Object");
const auto &args = s.args();
size_t argc = args.size();
if (argc == 1) {
uint32_t index{0};
sevalue_to_native(args[0], &index);
bufferAllocator->free(index);
return true;
}
SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc);
return false;
}
SE_BIND_FUNC(jsb_BufferAllocator_free);
static bool js_register_se_BufferAllocator(se::Object *obj) { // NOLINT
se::Class *cls = se::Class::create("NativeBufferAllocator", obj, nullptr, _SE(jsb_BufferAllocator_constructor));
cls->defineFunction("alloc", _SE(jsb_BufferAllocator_alloc));
cls->defineFunction("free", _SE(jsb_BufferAllocator_free));
cls->install();
JSBClassType::registerClass<se::BufferAllocator>(cls);
jsb_BufferAllocator_class = cls; // NOLINT
se::ScriptEngine::getInstance()->clearException();
return true;
}
bool register_all_dop_bindings(se::Object *obj) { // NOLINT
// TODO(liuhang): Don't make dop into jsb namespace. Currently put it into jsb namesapce just to test codes.
se::Value nsVal;
if (!obj->getProperty("jsb", &nsVal)) {
se::HandleObject jsobj(se::Object::createPlainObject());
nsVal.setObject(jsobj);
obj->setProperty("jsb", nsVal);
}
se::Object *ns = nsVal.toObject();
js_register_se_BufferAllocator(ns); // NOLINT
js_register_se_BufferPool(ns); // NOLINT
return true;
}

View File

@@ -0,0 +1,31 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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
namespace se {
class Object;
}
bool register_all_dop_bindings(se::Object *obj); // NOLINT