Skip to content

Commit 0547bcc

Browse files
committed
Add OBPath and OBPathStorage
1 parent ad6f8a6 commit 0547bcc

File tree

9 files changed

+474
-4
lines changed

9 files changed

+474
-4
lines changed

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ let includePath = SDKPath.appending("/usr/lib/swift")
3030

3131
let sharedCSettings: [CSetting] = [
3232
.unsafeFlags(["-I", includePath], .when(platforms: .nonDarwinPlatforms)),
33+
.unsafeFlags(["-fmodules"]),
34+
.define("__COREFOUNDATION_FORSWIFTFOUNDATIONONLY__", to: "1", .when(platforms: .nonDarwinPlatforms)),
35+
]
36+
let sharedCxxSettings: [CXXSetting] = [
37+
.unsafeFlags(["-I", includePath], .when(platforms: .nonDarwinPlatforms)),
38+
.unsafeFlags(["-fcxx-modules"]),
3339
.define("__COREFOUNDATION_FORSWIFTFOUNDATIONONLY__", to: "1", .when(platforms: .nonDarwinPlatforms)),
3440
]
3541
let sharedSwiftSettings: [SwiftSetting] = [
@@ -40,7 +46,8 @@ let sharedSwiftSettings: [SwiftSetting] = [
4046

4147
let openBoxTarget = Target.target(
4248
name: "OpenBox",
43-
cSettings: sharedCSettings
49+
cSettings: sharedCSettings,
50+
cxxSettings: sharedCxxSettings
4451
)
4552
let openBoxShimsTarget = Target.target(
4653
name: "OpenBoxShims",
@@ -69,7 +76,7 @@ let package = Package(
6976
name: "OpenBox",
7077
products: [
7178
.library(name: "OpenBox", type: .dynamic, targets: ["OpenBox"]),
72-
.library(name: "OpenBoxShims", targets: ["OpenBoxShims"]),
79+
.library(name: "OpenBoxShims", type: .dynamic, targets: ["OpenBoxShims"]),
7380
],
7481
dependencies: [
7582
.package(url: "https://github.com/apple/swift-numerics", from: "1.0.2"),

Sources/OpenBox/Path/OBPath.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// OBPath.cpp
3+
// OpenBox
4+
//
5+
// Created by Kyle on 2025/3/25.
6+
//
7+
8+
#include "OBPath.h"
9+
10+
void OBPathRetain(OBPath path) {
11+
// TODO
12+
}
13+
14+
void OBPathRelease(OBPath path) {
15+
// TODO
16+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// OBPathStorage.cpp
3+
// OpenBox
4+
5+
#include "OBPathStorage.h"
6+
#include "PathStorage.hpp"
7+
#include "../Util/assert.hpp"
8+
9+
using namespace OB;
10+
11+
void OBPathStorageInit(OBPathStorage* dst, uint32_t capacity, OBPathStorage* source) {
12+
if (source != nullptr) {
13+
dst->storage = OB::Path::Storage(capacity, source->storage);
14+
} else {
15+
dst->storage = OB::Path::Storage(capacity);
16+
}
17+
}
18+
19+
void OBPathStorageDestroy(OBPathStorage storage) {
20+
storage.storage.~Storage();
21+
}
22+
23+
void OBPathStorageClear(OBPathStorage storage) {
24+
storage.storage.clear();
25+
}
26+
27+
// ...
28+
29+
bool OBPathStorageIsEmpty(OBPathStorage storage) {
30+
return storage.storage.isEmpty();
31+
}
32+
33+
bool OBPathStorageEqualToStorage(OBPathStorage lhs, OBPathStorage rhs) {
34+
return lhs.storage == rhs.storage;
35+
}
36+
37+
bool OBPathStorageIsSingleElement(OBPathStorage storage) {
38+
return storage.storage.flags().isSingleElement();
39+
}
40+
41+
uint32_t OBPathStorageGetBezierOrder(OBPathStorage storage) {
42+
return storage.storage.flags().bezierOrder();
43+
}
44+
45+
#if OB_TARGET_OS_DARWIN
46+
47+
CGRect OBPathStorageGetBoundingRect(OBPathStorage storage) {
48+
precondition_failure("TODO");
49+
}
50+
51+
CGPathRef OBPathStorageGetCGPath(OBPathStorage storage) {
52+
precondition_failure("TODO");
53+
}
54+
#endif

Sources/OpenBox/Path/PathStorage.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//
2+
// PathStorage.cpp
3+
// OpenBox
4+
5+
#include "PathStorage.hpp"
6+
#include "../Util/assert.hpp"
7+
8+
namespace OB {
9+
namespace Path {
10+
atomic_long Storage::_last_identifier;
11+
12+
Storage::Storage(uint32_t capacity, const Storage &storage): Storage(capacity) {
13+
uint32_t originalCapity = flags().capacity();
14+
StorageFlags sourceFlags = storage.flags();
15+
16+
_flags = _flags
17+
.withExternal(false)
18+
.withQuadBezierOrder(sourceFlags.isQuadBezierOrder())
19+
.withCubicBezierOrder(sourceFlags.isCubicBezierOrder())
20+
.withSingleElement(sourceFlags.isSingleElement())
21+
// bit 4 and 5 is from sourceFlags
22+
// bit 6 and bit 7 is zero
23+
.withCapacity(sourceFlags.capacity());
24+
25+
const Storage* sourceStorage = storage.actual_storage();
26+
uint64_t sourceSize = storage.actual_size();
27+
28+
if (originalCapity < sourceSize) {
29+
// reserve_slow(sourceSize);
30+
sourceStorage = external_storage();
31+
if (flags().isExternal()) {
32+
// sourceStorage = external_storage()->0;
33+
}
34+
}
35+
memcpy((void *)external_storage(), (const void *)sourceStorage, sourceSize);
36+
// // Update our capacity info with the size
37+
// if (!(flags() & 0x1)) {
38+
// // Inline storage - update size bits
39+
// _flags = (flags() & ~(0xFFF << 8)) | (sourceSize << 8);
40+
// } else {
41+
// // External storage - store size externally
42+
// *reinterpret_cast<uint64_t*>(this + 0x18) = sourceSize;
43+
// }
44+
}
45+
46+
Storage::~Storage() {
47+
if (_unknonw != nullptr) {
48+
_unknonw = nullptr;
49+
// TODO
50+
}
51+
}
52+
53+
bool Storage::operator==(const Storage &other) const OB_NOEXCEPT {
54+
// TODO
55+
return false;
56+
}
57+
58+
void Storage::clear() {
59+
// TODO
60+
}
61+
62+
} /* Path */
63+
} /* OB */

0 commit comments

Comments
 (0)