1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
#include "core_widget.hpp"
core_widget::core_widget() {
clear_all();
}
void core_widget::clear_all() {
for (int i = 0; i < LIB94_CORE_SIZE; ++i) {
if (write_values[i] != 0)
to_draw_write.insert(i);
write_values[i] = 0;
if (read_values[i] != 0)
to_draw_read.insert(i);
read_values[i] = 0;
if (execute_values[i] != 0)
to_draw_execute.insert(i);
execute_values[i] = 0;
}
}
void core_widget::age_all() {
for (int i = 0; i < LIB94_CORE_SIZE; ++i) {
if (write_values[i] != 0) {
to_draw_write.insert(i);
write_values[i] = (uint8_t)((float)write_values[i] * age_scale);
}
if (read_values[i] != 0) {
to_draw_read.insert(i);
read_values[i] = (uint8_t)((float)read_values[i] * age_scale);
}
if (execute_values[i] != 0) {
to_draw_execute.insert(i);
execute_values[i] = (uint8_t)((float)execute_values[i] * age_scale);
}
}
}
void core_widget::add_new_writes(const std::set<lib94::number_t> &writes) {
for (lib94::number_t n : writes) {
write_values[n] = 255;
to_draw_write.insert(n);
}
}
void core_widget::add_new_reads(const std::set<lib94::number_t> &reads) {
for (lib94::number_t n : reads) {
read_values[n] = 255;
to_draw_read.insert(n);
}
}
void core_widget::add_new_executions(const std::set<lib94::number_t> &executions) {
for (lib94::number_t n : executions) {
execute_values[n] = 255;
to_draw_execute.insert(n);
}
}
void core_widget::measure_vfunc(Gtk::Orientation, int for_size, int &minimum, int &natural, int &minimum_baseline, int &natural_baseline) const {
minimum = (LIB94_CORE_SIZE - 1) / for_size + 1;
natural = (LIB94_CORE_SIZE - 1) / for_size + 1;
minimum_baseline = -1;
natural_baseline = -1;
}
void core_widget::draw(int width, int height) {
mut.lock();
if (width == last_width && height == last_height) {
uint8_t *buffer = (uint8_t *)pixbuf->property_pixels().get_value();
for (lib94::number_t i : to_draw_write) {
int cy = i / cpr * scale + ypad;
int cx = i % cpr * scale + xpad;
for (int dy = 0; dy < scale; ++dy)
for (int dx = 0; dx < scale; ++dx)
buffer[(cy + dy) * pixbuf->property_rowstride() + (cx + dx) * 4] = write_values[i];
}
for (lib94::number_t i : to_draw_read) {
int cy = i / cpr * scale + ypad;
int cx = i % cpr * scale + xpad;
for (int dy = 0; dy < scale; ++dy)
for (int dx = 0; dx < scale; ++dx)
buffer[(cy + dy) * pixbuf->property_rowstride() + (cx + dx) * 4 + 2] = read_values[i];
}
for (lib94::number_t i : to_draw_execute) {
int cy = i / cpr * scale + ypad;
int cx = i % cpr * scale + xpad;
for (int dy = 0; dy < scale; ++dy)
for (int dx = 0; dx < scale; ++dx)
buffer[(cy + dy) * pixbuf->property_rowstride() + (cx + dx) * 4 + 1] = execute_values[i];
}
}
else {
pixbuf = Gdk::Pixbuf::create(Gdk::Colorspace::RGB, true, 8, width, height);
last_width = width;
last_height = height;
scale = 1;
while (true) {
++scale;
if ((width / scale) * (height / scale) < LIB94_CORE_SIZE) {
--scale;
break;
}
}
cpr = width / scale + 1;
xpad = INT_MAX;
ypad = 0;
while (cpr >= 1) {
--cpr;
int rows = (LIB94_CORE_SIZE - 1) / cpr + 1;
int new_xpad = (width - cpr * scale) / 2;
int new_ypad = (height - rows * scale) / 2;
if (abs(new_xpad - new_ypad) < abs(xpad - ypad)) {
xpad = new_xpad;
ypad = new_ypad;
}
else {
++cpr;
break;
}
}
uint8_t *buffer = (uint8_t *)pixbuf->property_pixels().get_value();
for (lib94::number_t i = 0; i < LIB94_CORE_SIZE; ++i) {
int cy = i / cpr * scale + ypad;
int cx = i % cpr * scale + xpad;
for (int dy = 0; dy < scale; ++dy)
for (int dx = 0; dx < scale; ++dx) {
buffer[(cy + dy) * pixbuf->property_rowstride() + (cx + dx) * 4] = write_values[i];
buffer[(cy + dy) * pixbuf->property_rowstride() + (cx + dx) * 4 + 2] = read_values[i];
buffer[(cy + dy) * pixbuf->property_rowstride() + (cx + dx) * 4 + 1] = execute_values[i];
buffer[(cy + dy) * pixbuf->property_rowstride() + (cx + dx) * 4 + 3] = 255;
}
}
}
to_draw_write.clear();
to_draw_read.clear();
to_draw_execute.clear();
mut.unlock();
}
void core_widget::snapshot_vfunc(const Glib::RefPtr<Gtk::Snapshot> &snapshot) {
auto start_time = std::chrono::system_clock::now();
Gtk::Allocation allocation = get_allocation();
Gdk::Rectangle allocation_rect(0, 0, allocation.get_width(), allocation.get_height());
draw(allocation.get_width(), allocation.get_height());
auto texture = Gdk::Texture::create_for_pixbuf(pixbuf);
snapshot->append_texture(texture, allocation_rect);
auto end_time = std::chrono::system_clock::now();
last_draw_time = end_time - start_time;
}
|