Skip to content

Commit c8dc1d7

Browse files
authored
Add support for building Apple Silicon.
1 parent f81c0c8 commit c8dc1d7

File tree

10 files changed

+51
-56
lines changed

10 files changed

+51
-56
lines changed

Diff for: CMakeLists.txt

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
cmake_minimum_required(VERSION 3.1)
22
project(PAG)
33

4-
if (APPLE AND NOT IOS)
5-
SET(CMAKE_SYSTEM_PROCESSOR x86_64)
6-
SET(CMAKE_OSX_ARCHITECTURES x86_64)
7-
endif ()
4+
# Uncomment the next 4 lines to build libpag for Intel cpus.
5+
#if (APPLE AND NOT IOS)
6+
# SET(CMAKE_SYSTEM_PROCESSOR x86_64)
7+
# SET(CMAKE_OSX_ARCHITECTURES x86_64)
8+
#endif ()
89

910
#set(CMAKE_VERBOSE_MAKEFILE ON)
1011
include(./vendor_tools/vendor.cmake)

Diff for: DEPS

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"common": [
88
{
99
"url": "${PAG_GROUP}/vendor_tools.git",
10-
"commit": "27837194cf1834bcdf2bc2643655bdebcf2a67e9",
10+
"commit": "24aaeef49c7daffcc4446bd0795143c66f3223e6",
1111
"dir": "vendor_tools"
1212
},
1313
{
@@ -22,12 +22,12 @@
2222
},
2323
{
2424
"url": "${PAG_GROUP}/libavc.git",
25-
"commit": "dfc550bc75eef789eae8f0b0bfb954e11f7740e4",
25+
"commit": "c2bf4c84a6d39788929e59514417e819185af98e",
2626
"dir": "third_party/libavc"
2727
},
2828
{
2929
"url": "${PAG_GROUP}/swiftshader.git",
30-
"commit": "8d781475d99e8c1582f4c0da44b54ba105f8b79a",
30+
"commit": "040ee43bfeba9b6b532dbd8222df737aac2d55b1",
3131
"dir": "third_party/swiftshader"
3232
},
3333
{

Diff for: libpag.podspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ end
2222

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

9696
end

Diff for: mac/PAGViewer.xcodeproj/project.pbxproj

-2
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,6 @@
574574
CODE_SIGN_IDENTITY = "-";
575575
CODE_SIGN_STYLE = Automatic;
576576
COMBINE_HIDPI_IMAGES = YES;
577-
EXCLUDED_ARCHS = arm64;
578577
INFOPLIST_FILE = PAGViewer/Info.plist;
579578
LD_RUNPATH_SEARCH_PATHS = (
580579
"$(inherited)",
@@ -596,7 +595,6 @@
596595
CODE_SIGN_IDENTITY = "-";
597596
CODE_SIGN_STYLE = Automatic;
598597
COMBINE_HIDPI_IMAGES = YES;
599-
EXCLUDED_ARCHS = arm64;
600598
INFOPLIST_FILE = PAGViewer/Info.plist;
601599
LD_RUNPATH_SEARCH_PATHS = (
602600
"$(inherited)",

Diff for: test/PAGCompareFrameTest.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ class CompareFrameTask : public Executor {
6565
bool success = false;
6666

6767
void execute() override {
68-
success = Baseline::Compare(pixelBuffer, "PAGCompareFrameTest/" + fileName + "/" +
69-
std::to_string(_currentFrame));
68+
success = Baseline::Compare(
69+
pixelBuffer, "PAGCompareFrameTest/" + fileName + "/" + std::to_string(_currentFrame));
7070
}
7171
};
7272

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

104104
auto CompareFrame = [&](Frame currentFrame) {
105+
if (lastTask == nullptr) {
106+
return;
107+
}
105108
auto startTime = GetTimer();
106109
auto task = static_cast<CompareFrameTask*>(lastTask->wait());
107110
auto compareCost = GetTimer() - startTime;
@@ -113,6 +116,7 @@ void CompareFileFrames(Semaphore* semaphore, std::string pagPath) {
113116
if (!task->isSuccess()) {
114117
errorMsg += (std::to_string(currentFrame) + ";");
115118
}
119+
lastTask = nullptr;
116120
};
117121

118122
while (currentFrame < totalFrames) {
@@ -127,9 +131,7 @@ void CompareFileFrames(Semaphore* semaphore, std::string pagPath) {
127131
cost.performance = cache->getPerformanceString();
128132
performanceMap[currentFrame] = cost;
129133
}
130-
if (currentFrame > 0) {
131-
CompareFrame(currentFrame - 1);
132-
}
134+
CompareFrame(currentFrame - 1);
133135
if (changed) {
134136
auto executor = new CompareFrameTask(fileName, currentFrame, currentSnapshot);
135137
lastTask = Task::Make(std::unique_ptr<CompareFrameTask>(executor));

Diff for: test/framework/utils/Baseline.cpp

+23-39
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,8 @@ namespace pag {
3030
#define OUT_BASELINE_ROOT "../test/out/baseline/"
3131
#define OUT_COMPARE_ROOT "../test/out/compare/"
3232
#define COMPRESS_FILE_EXT ".lzma2"
33-
34-
static std::unordered_set<std::string> clearedFolders = {};
35-
36-
static void ClearPreviousOutput(const std::string& key) {
37-
std::filesystem::path folder = key;
38-
while (!folder.parent_path().empty()) {
39-
folder = folder.parent_path();
40-
}
41-
if (clearedFolders.count(folder) > 0) {
42-
return;
43-
}
44-
clearedFolders.insert(folder);
45-
std::filesystem::remove_all(OUT_BASELINE_ROOT + folder.string());
46-
std::filesystem::remove_all(OUT_COMPARE_ROOT + folder.string());
47-
}
33+
#define MAX_DIFF_COUNT 10
34+
#define MAX_DIFF_VALUE 5
4835

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

88-
bool ComparePixelData(const std::shared_ptr<Data>& pixelData, const std::string& key) {
89-
ClearPreviousOutput(key);
75+
static void ClearPreviousOutput(const std::string& key) {
76+
std::filesystem::remove(OUT_BASELINE_ROOT + key + COMPRESS_FILE_EXT);
77+
std::filesystem::remove(OUT_COMPARE_ROOT + key + "_baseline.webp");
78+
std::filesystem::remove(OUT_COMPARE_ROOT + key + "_new.webp");
79+
}
80+
81+
static bool ComparePixelData(const std::shared_ptr<Data>& pixelData, const std::string& key,
82+
const ImageInfo& info) {
9083
if (pixelData == nullptr) {
9184
return false;
9285
}
9386
auto baselineData = LoadImageData(key);
9487
if (baselineData == nullptr || pixelData->size() != baselineData->size()) {
9588
return false;
9689
}
90+
size_t diffCount = 0;
9791
auto baseline = baselineData->bytes();
9892
auto pixels = pixelData->bytes();
9993
auto byteSize = pixelData->size();
10094
for (size_t index = 0; index < byteSize; index++) {
10195
auto pixelA = pixels[index];
10296
auto pixelB = baseline[index];
103-
if (abs(pixelA - pixelB) > 3) {
104-
return false;
97+
if (abs(pixelA - pixelB) > MAX_DIFF_VALUE) {
98+
diffCount++;
10599
}
106100
}
101+
// We assume that the two images are the same if the number of different pixels is less than 10.
102+
if (diffCount > MAX_DIFF_COUNT) {
103+
SaveImage(info, pixelData, key);
104+
return false;
105+
}
106+
ClearPreviousOutput(key);
107107
return true;
108108
}
109109

@@ -121,11 +121,7 @@ bool Baseline::Compare(const std::shared_ptr<PixelBuffer>& pixelBuffer, const st
121121
if (!result) {
122122
return false;
123123
}
124-
result = ComparePixelData(data, key);
125-
if (!result) {
126-
SaveImage(info, data, key);
127-
}
128-
return result;
124+
return ComparePixelData(data, key, info);
129125
}
130126

131127
bool Baseline::Compare(const Bitmap& bitmap, const std::string& key) {
@@ -139,11 +135,7 @@ bool Baseline::Compare(const Bitmap& bitmap, const std::string& key) {
139135
if (!result) {
140136
return false;
141137
}
142-
result = ComparePixelData(data, key);
143-
if (!result) {
144-
SaveImage(info, data, key);
145-
}
146-
return result;
138+
return ComparePixelData(data, key, info);
147139
}
148140

149141
bool Baseline::Compare(const PixelMap& pixelMap, const std::string& key) {
@@ -157,11 +149,7 @@ bool Baseline::Compare(const PixelMap& pixelMap, const std::string& key) {
157149
if (!result) {
158150
return false;
159151
}
160-
result = ComparePixelData(data, key);
161-
if (!result) {
162-
SaveImage(info, data, key);
163-
}
164-
return result;
152+
return ComparePixelData(data, key, info);
165153
}
166154

167155
bool Baseline::Compare(const std::shared_ptr<PAGSurface>& surface, const std::string& key) {
@@ -176,10 +164,6 @@ bool Baseline::Compare(const std::shared_ptr<PAGSurface>& surface, const std::st
176164
if (!result) {
177165
return false;
178166
}
179-
result = ComparePixelData(data, key);
180-
if (!result) {
181-
SaveImage(info, data, key);
182-
}
183-
return result;
167+
return ComparePixelData(data, key, info);
184168
}
185169
} // namespace pag

Diff for: vendor.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@
120120
"${BUILD_DIR}/pnglibconf.h"
121121
],
122122
"platforms": [
123-
"ios"
123+
"ios",
124+
"mac"
124125
]
125126
}
126127
},

Diff for: vendor/ffavc/mac/arm64/libffavc.dylib

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:953fd50fb98d44de54f13908e99df7145f5a4cecdf9f1b6b4689e69905b0bfc1
3+
size 1784635

Diff for: vendor/swiftshader/mac/arm64/libEGL.dylib

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:6e787fd91ff325db711cd3f4eca1e667e7a88f83e571c100c496ebb35c229ef0
3+
size 106841

Diff for: vendor/swiftshader/mac/arm64/libGLESv2.dylib

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:3560c1919c50ba0d272bfbd3fd457d085c00258b5eb49efcf1b3c9c77cd25343
3+
size 31171340

0 commit comments

Comments
 (0)