-
Notifications
You must be signed in to change notification settings - Fork 467
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
Update tgfx to the latest version. #2612
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5ad579a
Update tgfx to the latest version。
Hparty 002504e
update version.jon
Hparty e54f277
Fix pipeline issues
Hparty d9d8a78
Fix the window demo when building with mutlple versions of Visual Stu…
domchen afacadf
Delete export functions and create result in c++
Hparty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,26 @@ | |
using namespace emscripten; | ||
|
||
namespace pag { | ||
|
||
std::unique_ptr<ByteData> CopyDataFromUint8Array(const val& emscriptenData) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 从js拷贝内存到c++都统一用这个方法就行,不需要后面的buffer.ts |
||
if (!emscriptenData.as<bool>()) { | ||
return nullptr; | ||
} | ||
auto length = emscriptenData["length"].as<size_t>(); | ||
if (length == 0) { | ||
return nullptr; | ||
} | ||
auto buffer = ByteData::Make(length); | ||
if (!buffer) { | ||
return nullptr; | ||
} | ||
auto memory = val::module_property("HEAPU8")["buffer"]; | ||
auto memoryView = | ||
val::global("Uint8Array").new_(memory, reinterpret_cast<uintptr_t>(buffer->data()), length); | ||
memoryView.call<void>("set", emscriptenData); | ||
return buffer; | ||
} | ||
|
||
bool PAGBindInit() { | ||
class_<PAGLayer>("_PAGLayer") | ||
.smart_ptr<std::shared_ptr<PAGLayer>>("_PAGLayer") | ||
|
@@ -215,8 +235,13 @@ bool PAGBindInit() { | |
class_<PAGFile, base<PAGComposition>>("_PAGFile") | ||
.smart_ptr<std::shared_ptr<PAGFile>>("_PAGFile") | ||
.class_function("_MaxSupportedTagLevel", PAGFile::MaxSupportedTagLevel) | ||
.class_function("_Load", optional_override([](uintptr_t bytes, size_t length) { | ||
return PAGFile::Load(reinterpret_cast<void*>(bytes), length); | ||
.class_function("_Load", | ||
optional_override([](const val& emscriptenData) -> std::shared_ptr<PAGFile> { | ||
auto data = CopyDataFromUint8Array(emscriptenData); | ||
if (data == nullptr) { | ||
return nullptr; | ||
} | ||
return PAGFile::Load(data->data(), data->length()); | ||
})) | ||
.function("_tagLevel", &PAGFile::tagLevel) | ||
.function("_numTexts", &PAGFile::numTexts) | ||
|
@@ -284,20 +309,31 @@ bool PAGBindInit() { | |
|
||
class_<PAGImage>("_PAGImage") | ||
.smart_ptr<std::shared_ptr<PAGImage>>("_PAGImage") | ||
.class_function("_FromBytes", optional_override([](uintptr_t bytes, size_t length) { | ||
return PAGImage::FromBytes(reinterpret_cast<void*>(bytes), length); | ||
.class_function("_FromBytes", | ||
optional_override([](const val& emscriptenData) -> std::shared_ptr<PAGImage> { | ||
auto data = CopyDataFromUint8Array(emscriptenData); | ||
if (data == nullptr) { | ||
return nullptr; | ||
} | ||
return PAGImage::FromBytes(reinterpret_cast<void*>(data->data()), | ||
data->length()); | ||
})) | ||
.class_function("_FromNativeImage", optional_override([](val nativeImage) { | ||
auto image = tgfx::Image::MakeFrom(nativeImage); | ||
return std::static_pointer_cast<PAGImage>(StillImage::MakeFrom(image)); | ||
})) | ||
.class_function("_FromPixels", | ||
optional_override([](uintptr_t pixels, int width, int height, size_t rowBytes, | ||
int colorType, int alphaType) { | ||
return PAGImage::FromPixels(reinterpret_cast<void*>(pixels), width, height, | ||
rowBytes, static_cast<ColorType>(colorType), | ||
static_cast<AlphaType>(alphaType)); | ||
})) | ||
.class_function( | ||
"_FromPixels", | ||
optional_override([](const val& pixels, int width, int height, size_t rowBytes, | ||
int colorType, int alphaType) -> std::shared_ptr<PAGImage> { | ||
auto data = CopyDataFromUint8Array(pixels); | ||
if (data == nullptr) { | ||
return nullptr; | ||
} | ||
return PAGImage::FromPixels(reinterpret_cast<void*>(data->data()), width, height, | ||
rowBytes, static_cast<ColorType>(colorType), | ||
static_cast<AlphaType>(alphaType)); | ||
})) | ||
.class_function("_FromTexture", | ||
optional_override([](int textureID, int width, int height, bool flipY) { | ||
GLTextureInfo glInfo = {}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 参考一下tgfx的写法,已经不需要这个类了。这个类会多拷贝一次。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
///////////////////////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Tencent is pleased to support the open source community by making tgfx available. | ||
// | ||
// Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved. | ||
// | ||
// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except | ||
// in compliance with the License. You may obtain a copy of the License at | ||
// | ||
// https://opensource.org/licenses/BSD-3-Clause | ||
// | ||
// unless required by applicable law or agreed to in writing, software distributed under the | ||
// license is distributed on an "as is" basis, without warranties or conditions of any kind, | ||
// either express or implied. see the license for the specific language governing permissions | ||
// and limitations under the license. | ||
// | ||
///////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
export const readBufferFromWasm = ( | ||
module: EmscriptenModule, | ||
data: ArrayLike<number> | ArrayBufferLike, | ||
handle: (byteOffset: number, length: number) => boolean, | ||
) => { | ||
const uint8Array = new Uint8Array(data); | ||
const dataPtr = module._malloc(uint8Array.byteLength); | ||
if (!handle(dataPtr, uint8Array.byteLength)) return { | ||
data: null, | ||
free: () => module._free(dataPtr) | ||
}; | ||
const dataOnHeap = new Uint8Array(module.HEAPU8.buffer, dataPtr, uint8Array.byteLength); | ||
uint8Array.set(dataOnHeap); | ||
return {data: uint8Array, free: () => module._free(dataPtr)}; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不需要增加这个接口导出,后面的buffer.ts也不需要