Skip to content

Commit 585a9c5

Browse files
committed
Impl sheet maps
1 parent 7063bc0 commit 585a9c5

File tree

8 files changed

+239
-65
lines changed

8 files changed

+239
-65
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ mnt/
1010
*.o
1111
*.dat
1212
*.log
13+
*.tmp
1314
cc_cache.gen.mk
1415
prebuilt/

src/command.cc

+12-8
Original file line numberDiff line numberDiff line change
@@ -655,17 +655,21 @@ void Run(TextBox& tbox) {
655655
Virtio::Net& net = Virtio::Net::GetInstance();
656656
auto ip_addr = net.GetSelfIPv4Addr();
657657
auto mac_addr = net.GetSelfEtherAddr();
658-
ip_addr.Print();
659-
PutString(" eth ");
660-
mac_addr.Print();
658+
661659
auto& network = Network::GetInstance();
662-
PutString(" mask ");
663660
auto mask = network.GetIPv4NetMask();
664-
mask.Print();
665-
PutString(" gateway ");
666661
auto gateway_ip = network.GetIPv4DefaultGateway();
667-
gateway_ip.Print();
668-
PutString("\n");
662+
663+
StringBuffer<128> line;
664+
ip_addr.WriteString(line);
665+
line.WriteString(" eth ");
666+
mac_addr.WriteString(line);
667+
line.WriteString(" mask ");
668+
mask.WriteString(line);
669+
line.WriteString(" gateway ");
670+
gateway_ip.WriteString(line);
671+
line.WriteChar('\n');
672+
PutString(line.GetString());
669673
return;
670674
}
671675
if (IsEqualString(args.GetArg(0), "arp")) {

src/kernel.cc

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <vector>
77

88
#include "corefunc.h"
9+
#include "kernel.h"
910
#include "liumos.h"
1011
#include "panic_printer.h"
1112
#include "pci.h"
@@ -104,6 +105,8 @@ void InitializeVRAMForKernel() {
104105
virtual_vram_.Init(reinterpret_cast<uint32_t*>(kernel_virtual_vram_base),
105106
xsize, ysize, ppsl);
106107
liumos->vram_sheet = &virtual_vram_;
108+
virtual_vram_.SetMap(AllocKernelMemory<Sheet**>(
109+
virtual_vram_.GetXSize() * virtual_vram_.GetYSize() * sizeof(Sheet*)));
107110

108111
constexpr uint64_t kernel_virtual_screen_base = 0xFFFF'FFFF'8800'0000ULL;
109112
CreatePageMapping(

src/network.cc

+9-15
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,21 @@
44
#include "virtio_net.h"
55

66
void Network::IPv4Addr::Print() const {
7-
for (int i = 0; i < 4; i++) {
8-
PutDecimal64(addr[i]);
9-
if (i != 3)
10-
PutChar('.');
11-
}
7+
StringBuffer<128> line;
8+
WriteString(line);
9+
PutString(line.GetString());
1210
}
1311

1412
void Network::IPv4NetMask::Print() const {
15-
for (int i = 0; i < 4; i++) {
16-
PutDecimal64(mask[i]);
17-
if (i != 3)
18-
PutChar('.');
19-
}
13+
StringBuffer<128> line;
14+
WriteString(line);
15+
PutString(line.GetString());
2016
}
2117

2218
void Network::EtherAddr::Print() const {
23-
for (int i = 0; i < 6; i++) {
24-
PutHex8ZeroFilled(mac[i]);
25-
if (i != 5)
26-
PutChar(':');
27-
}
19+
StringBuffer<128> line;
20+
WriteString(line);
21+
PutString(line.GetString());
2822
}
2923

3024
Network* Network::network_;

src/network.h

+29
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "generic.h"
88
#include "ring_buffer.h"
99

10+
#include "string_buffer.h"
11+
1012
class Network {
1113
public:
1214
//
@@ -23,6 +25,15 @@ class Network {
2325
}
2426
bool operator==(const EtherAddr& rhs) const { return IsEqualTo(rhs); }
2527
void Print() const;
28+
29+
template <typename T>
30+
void WriteString(T & string_buf) const {
31+
for (int i = 0; i < 6; i++) {
32+
string_buf.WriteHex8ZeroFilled(mac[i]);
33+
if (i != 5)
34+
string_buf.WriteChar(':');
35+
}
36+
}
2637
};
2738
static constexpr EtherAddr kBroadcastEtherAddr = {0xFF, 0xFF, 0xFF,
2839
0xFF, 0xFF, 0xFF};
@@ -79,6 +90,15 @@ class Network {
7990
packed_struct IPv4NetMask {
8091
uint8_t mask[4];
8192
void Print() const;
93+
94+
template <typename T>
95+
void WriteString(T & string_buf) const {
96+
for (int i = 0; i < 4; i++) {
97+
string_buf.WriteDecimal64(mask[i]);
98+
if (i != 3)
99+
string_buf.WriteChar('.');
100+
}
101+
}
82102
};
83103
packed_struct IPv4Addr {
84104
uint8_t addr[4];
@@ -107,6 +127,15 @@ class Network {
107127
*reinterpret_cast<const uint32_t*>(another.addr)) &
108128
*reinterpret_cast<const uint32_t*>(mask.mask)) == 0;
109129
}
130+
131+
template <typename T>
132+
void WriteString(T & string_buf) const {
133+
for (int i = 0; i < 4; i++) {
134+
string_buf.WriteDecimal64(addr[i]);
135+
if (i != 3)
136+
string_buf.WriteChar('.');
137+
}
138+
}
110139
};
111140
struct IPv4AddrHash {
112141
std::size_t operator()(const IPv4Addr& v) const {

src/sheet.cc

+16-7
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,24 @@ void Sheet::Flush(int rx, int ry, int rw, int rh) {
6161
for (int y = ty; y < ty + th; y++) {
6262
int tbegin = tx;
6363
for (int x = tx; x < tx + tw; x++) {
64-
bool is_covered = false;
65-
for (Sheet* s = parent_->children_; s && s != this; s = s->below_) {
66-
if (s->IsInRectOnParent(x, y)) {
67-
is_covered = true;
68-
break;
64+
if (parent_->map_) {
65+
// Fast path
66+
if (parent_->map_[y * parent_->GetXSize() + x] == this) {
67+
continue;
68+
}
69+
} else {
70+
// Slow path (should be removed)
71+
bool is_covered = false;
72+
for (Sheet* s = parent_->children_; s && s != this; s = s->below_) {
73+
if (s->IsInRectOnParent(x, y)) {
74+
is_covered = true;
75+
break;
76+
}
77+
}
78+
if (!is_covered) {
79+
continue;
6980
}
7081
}
71-
if (!is_covered)
72-
continue;
7382
parent_->TransferLineFrom(*this, y, tbegin, x - tbegin);
7483
tbegin = x + 1;
7584
}

src/sheet.h

+31-1
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,45 @@ class Sheet {
2626
pixels_per_scan_line_ = pixels_per_scan_line;
2727
rect_.x = x;
2828
rect_.y = y;
29+
map_ = nullptr;
30+
}
31+
void SetMap(Sheet** map) {
32+
map_ = map;
33+
UpdateMap();
34+
}
35+
void UpdateMap() {
36+
if (!map_) {
37+
return;
38+
}
39+
for (int y = 0; y < GetYSize(); y++) {
40+
for (int x = 0; x < GetXSize(); x++) {
41+
map_[y * GetXSize() + x] = nullptr;
42+
}
43+
}
44+
Rect client_rect = GetClientRect();
45+
for (Sheet* s = children_; s; s = s->below_) {
46+
Rect in_view = client_rect.GetIntersectionWith(s->GetRect());
47+
for (int y = in_view.y; y < in_view.y + in_view.ysize; y++) {
48+
for (int x = in_view.x; x < in_view.x + in_view.xsize; x++) {
49+
if (map_[y * GetXSize() + x]) {
50+
continue;
51+
}
52+
map_[y * GetXSize() + x] = s;
53+
}
54+
}
55+
}
2956
}
3057
void SetParent(Sheet* parent) {
3158
// Insert at front
3259
below_ = parent->children_;
3360
parent_ = parent;
34-
parent->children_ = this;
61+
parent_->children_ = this;
62+
parent_->UpdateMap();
3563
}
3664
void SetPosition(int x, int y) {
3765
rect_.x = x;
3866
rect_.y = y;
67+
parent_->UpdateMap();
3968
}
4069
void MoveRelative(int dx, int dy) {
4170
SetPosition(GetX() + dx, GetY() + dy);
@@ -70,6 +99,7 @@ class Sheet {
7099
void TransferLineFrom(Sheet& src, int py, int px, int w);
71100
Sheet *parent_, *below_, *children_;
72101
uint32_t* buf_;
102+
Sheet** map_;
73103
Rect rect_;
74104
int pixels_per_scan_line_;
75105
};

0 commit comments

Comments
 (0)