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

Add support for building Apple Silicon. #79

Merged
merged 2 commits into from
Jan 28, 2022
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
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
cmake_minimum_required(VERSION 3.1)
project(PAG)

if (APPLE AND NOT IOS)
SET(CMAKE_SYSTEM_PROCESSOR x86_64)
SET(CMAKE_OSX_ARCHITECTURES x86_64)
endif ()
# Uncomment the next 4 lines to build libpag for Intel cpus.
#if (APPLE AND NOT IOS)
# SET(CMAKE_SYSTEM_PROCESSOR x86_64)
# SET(CMAKE_OSX_ARCHITECTURES x86_64)
#endif ()

#set(CMAKE_VERBOSE_MAKEFILE ON)
include(./vendor_tools/vendor.cmake)
Expand Down
6 changes: 3 additions & 3 deletions DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"common": [
{
"url": "${PAG_GROUP}/vendor_tools.git",
"commit": "27837194cf1834bcdf2bc2643655bdebcf2a67e9",
"commit": "24aaeef49c7daffcc4446bd0795143c66f3223e6",
"dir": "vendor_tools"
},
{
Expand All @@ -22,12 +22,12 @@
},
{
"url": "${PAG_GROUP}/libavc.git",
"commit": "dfc550bc75eef789eae8f0b0bfb954e11f7740e4",
"commit": "c2bf4c84a6d39788929e59514417e819185af98e",
"dir": "third_party/libavc"
},
{
"url": "${PAG_GROUP}/swiftshader.git",
"commit": "8d781475d99e8c1582f4c0da44b54ba105f8b79a",
"commit": "040ee43bfeba9b6b532dbd8222df737aac2d55b1",
"dir": "third_party/swiftshader"
},
{
Expand Down
4 changes: 2 additions & 2 deletions libpag.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ end

if ENV["PLATFORM"] == "mac"
system("depsync mac")
system("node build_vendor #{vendorNames} -o #{PAG_ROOT}/mac/Pods/pag-vendor -p mac")
system("node build_vendor #{vendorNames} -o #{PAG_ROOT}/mac/Pods/pag-vendor -p mac --fatLib")
else
system("depsync ios")
system("node build_vendor #{vendorNames} -o #{PAG_ROOT}/ios/Pods/pag-vendor -p ios --fatLib")
Expand Down Expand Up @@ -91,6 +91,6 @@ Pod::Spec.new do |s|
s.ios.xcconfig = {"OTHER_CFLAGS" => commonCFlags.join(" "),"EXPORTED_SYMBOLS_FILE" => "${PODS_ROOT}/../libpag.lds","OTHER_LDFLAGS" => "-w","VALIDATE_WORKSPACE_SKIPPED_SDK_FRAMEWORKS" => "OpenGLES"}
s.osx.xcconfig = {"OTHER_CFLAGS" => commonCFlags.join(" ")}
s.ios.vendored_libraries = 'ios/Pods/pag-vendor/libpag-vendor.a'
s.osx.vendored_libraries = 'mac/Pods/pag-vendor/x64/libpag-vendor.a'
s.osx.vendored_libraries = 'mac/Pods/pag-vendor/libpag-vendor.a'

end
2 changes: 0 additions & 2 deletions mac/PAGViewer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,6 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
EXCLUDED_ARCHS = arm64;
INFOPLIST_FILE = PAGViewer/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -596,7 +595,6 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
EXCLUDED_ARCHS = arm64;
INFOPLIST_FILE = PAGViewer/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand Down
12 changes: 7 additions & 5 deletions test/PAGCompareFrameTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class CompareFrameTask : public Executor {
bool success = false;

void execute() override {
success = Baseline::Compare(pixelBuffer, "PAGCompareFrameTest/" + fileName + "/" +
std::to_string(_currentFrame));
success = Baseline::Compare(
pixelBuffer, "PAGCompareFrameTest/" + fileName + "/" + std::to_string(_currentFrame));
}
};

Expand Down Expand Up @@ -102,6 +102,9 @@ void CompareFileFrames(Semaphore* semaphore, std::string pagPath) {
std::shared_ptr<Task> lastTask = nullptr;

auto CompareFrame = [&](Frame currentFrame) {
if (lastTask == nullptr) {
return;
}
auto startTime = GetTimer();
auto task = static_cast<CompareFrameTask*>(lastTask->wait());
auto compareCost = GetTimer() - startTime;
Expand All @@ -113,6 +116,7 @@ void CompareFileFrames(Semaphore* semaphore, std::string pagPath) {
if (!task->isSuccess()) {
errorMsg += (std::to_string(currentFrame) + ";");
}
lastTask = nullptr;
};

while (currentFrame < totalFrames) {
Expand All @@ -127,9 +131,7 @@ void CompareFileFrames(Semaphore* semaphore, std::string pagPath) {
cost.performance = cache->getPerformanceString();
performanceMap[currentFrame] = cost;
}
if (currentFrame > 0) {
CompareFrame(currentFrame - 1);
}
CompareFrame(currentFrame - 1);
if (changed) {
auto executor = new CompareFrameTask(fileName, currentFrame, currentSnapshot);
lastTask = Task::Make(std::unique_ptr<CompareFrameTask>(executor));
Expand Down
62 changes: 23 additions & 39 deletions test/framework/utils/Baseline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,8 @@ namespace pag {
#define OUT_BASELINE_ROOT "../test/out/baseline/"
#define OUT_COMPARE_ROOT "../test/out/compare/"
#define COMPRESS_FILE_EXT ".lzma2"

static std::unordered_set<std::string> clearedFolders = {};

static void ClearPreviousOutput(const std::string& key) {
std::filesystem::path folder = key;
while (!folder.parent_path().empty()) {
folder = folder.parent_path();
}
if (clearedFolders.count(folder) > 0) {
return;
}
clearedFolders.insert(folder);
std::filesystem::remove_all(OUT_BASELINE_ROOT + folder.string());
std::filesystem::remove_all(OUT_COMPARE_ROOT + folder.string());
}
#define MAX_DIFF_COUNT 10
#define MAX_DIFF_VALUE 5

static ImageInfo MakeInfo(int with, int height) {
return ImageInfo::Make(with, height, ColorType::RGBA_8888, AlphaType::Premultiplied);
Expand Down Expand Up @@ -85,25 +72,38 @@ static void SaveImage(const ImageInfo& info, const std::shared_ptr<Data>& imageD
SaveData(compareImage, OUT_COMPARE_ROOT + key + "_new.webp");
}

bool ComparePixelData(const std::shared_ptr<Data>& pixelData, const std::string& key) {
ClearPreviousOutput(key);
static void ClearPreviousOutput(const std::string& key) {
std::filesystem::remove(OUT_BASELINE_ROOT + key + COMPRESS_FILE_EXT);
std::filesystem::remove(OUT_COMPARE_ROOT + key + "_baseline.webp");
std::filesystem::remove(OUT_COMPARE_ROOT + key + "_new.webp");
}

static bool ComparePixelData(const std::shared_ptr<Data>& pixelData, const std::string& key,
const ImageInfo& info) {
if (pixelData == nullptr) {
return false;
}
auto baselineData = LoadImageData(key);
if (baselineData == nullptr || pixelData->size() != baselineData->size()) {
return false;
}
size_t diffCount = 0;
auto baseline = baselineData->bytes();
auto pixels = pixelData->bytes();
auto byteSize = pixelData->size();
for (size_t index = 0; index < byteSize; index++) {
auto pixelA = pixels[index];
auto pixelB = baseline[index];
if (abs(pixelA - pixelB) > 3) {
return false;
if (abs(pixelA - pixelB) > MAX_DIFF_VALUE) {
diffCount++;
}
}
// We assume that the two images are the same if the number of different pixels is less than 10.
if (diffCount > MAX_DIFF_COUNT) {
lvpengwei marked this conversation as resolved.
Show resolved Hide resolved
SaveImage(info, pixelData, key);
return false;
}
ClearPreviousOutput(key);
return true;
}

Expand All @@ -121,11 +121,7 @@ bool Baseline::Compare(const std::shared_ptr<PixelBuffer>& pixelBuffer, const st
if (!result) {
return false;
}
result = ComparePixelData(data, key);
if (!result) {
SaveImage(info, data, key);
}
return result;
return ComparePixelData(data, key, info);
}

bool Baseline::Compare(const Bitmap& bitmap, const std::string& key) {
Expand All @@ -139,11 +135,7 @@ bool Baseline::Compare(const Bitmap& bitmap, const std::string& key) {
if (!result) {
return false;
}
result = ComparePixelData(data, key);
if (!result) {
SaveImage(info, data, key);
}
return result;
return ComparePixelData(data, key, info);
}

bool Baseline::Compare(const PixelMap& pixelMap, const std::string& key) {
Expand All @@ -157,11 +149,7 @@ bool Baseline::Compare(const PixelMap& pixelMap, const std::string& key) {
if (!result) {
return false;
}
result = ComparePixelData(data, key);
if (!result) {
SaveImage(info, data, key);
}
return result;
return ComparePixelData(data, key, info);
}

bool Baseline::Compare(const std::shared_ptr<PAGSurface>& surface, const std::string& key) {
Expand All @@ -176,10 +164,6 @@ bool Baseline::Compare(const std::shared_ptr<PAGSurface>& surface, const std::st
if (!result) {
return false;
}
result = ComparePixelData(data, key);
if (!result) {
SaveImage(info, data, key);
}
return result;
return ComparePixelData(data, key, info);
}
} // namespace pag
3 changes: 2 additions & 1 deletion vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@
"${BUILD_DIR}/pnglibconf.h"
],
"platforms": [
"ios"
"ios",
"mac"
]
}
},
Expand Down
3 changes: 3 additions & 0 deletions vendor/ffavc/mac/arm64/libffavc.dylib
Git LFS file not shown
3 changes: 3 additions & 0 deletions vendor/swiftshader/mac/arm64/libEGL.dylib
Git LFS file not shown
3 changes: 3 additions & 0 deletions vendor/swiftshader/mac/arm64/libGLESv2.dylib
Git LFS file not shown