mirror of
https://github.com/penpot/penpot.git
synced 2025-04-06 20:11:29 -05:00
wip: 20_000 test
This commit is contained in:
parent
cd63fb78d2
commit
4939bc06ac
3 changed files with 121 additions and 22 deletions
|
@ -2,6 +2,28 @@
|
|||
(function (Renderer) {
|
||||
console.log("preamble", Renderer);
|
||||
|
||||
const LCG_MULTIPLIER = 1103515245;
|
||||
const LCG_INCREMENT = 12345;
|
||||
const LCG_MODULUS = Math.pow(2, 31);
|
||||
const LCG_MASK = (LCG_MODULUS - 1);
|
||||
|
||||
function lcg(x, a, c, m) {
|
||||
return (x * a + c) % m;
|
||||
}
|
||||
|
||||
class Random {
|
||||
constructor(seed) {
|
||||
this._seed = seed;
|
||||
}
|
||||
|
||||
value() {
|
||||
this._seed = lcg(this._seed, LCG_MULTIPLIER, LCG_INCREMENT, LCG_MODULUS);
|
||||
return (this._seed & LCG_MASK) / LCG_MODULUS;
|
||||
}
|
||||
}
|
||||
|
||||
const random = new Random(0)
|
||||
|
||||
// Sets canvas.
|
||||
Renderer.setCanvas = function setCanvas(canvas, attrs) {
|
||||
const context = GL.createContext(canvas, attrs);
|
||||
|
@ -19,19 +41,29 @@
|
|||
};
|
||||
|
||||
Renderer.setObjects = function setObjects(vbox, zoom, objects) {
|
||||
this._SetObjects(objects.cnt);
|
||||
for (let index = 0; index < objects.cnt; index++) {
|
||||
const object = objects.arr[index * 2 + 1];
|
||||
this._SetObject(
|
||||
// this._SetObjects(objects.cnt);
|
||||
const numObjects = 20_000;
|
||||
this._SetObjects(numObjects);
|
||||
for (let index = 0; index < numObjects; index++) {
|
||||
// const object = objects.arr[index * 2 + 1];
|
||||
this._SetObjectRect(
|
||||
index,
|
||||
object.selrect.x,
|
||||
object.selrect.y,
|
||||
object.selrect.width,
|
||||
object.selrect.height,
|
||||
// object.selrect.x,
|
||||
random.value() * 2000,
|
||||
// object.selrect.y,
|
||||
random.value() * 2000,
|
||||
// object.selrect.width,
|
||||
random.value() * 200,
|
||||
// object.selrect.height,
|
||||
random.value() * 200
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
Renderer.drawCanvas = function drawCanvas(vbox, zoom, objects) {
|
||||
performance.mark('draw-canvas:start');
|
||||
this._DrawCanvas(vbox.x, vbox.y, zoom);
|
||||
performance.mark('draw-canvas:end');
|
||||
const { duration } = performance.measure('draw-canvas', 'draw-canvas:start', 'draw-canvas:end');
|
||||
console.log('draw-canvas', `${duration}ms`);
|
||||
};
|
||||
|
|
|
@ -139,6 +139,40 @@ struct PenpotObject {
|
|||
|
||||
std::vector<PenpotObject> objects(0);
|
||||
|
||||
constexpr uint32_t LCG_MULTIPLIER = 1103515245;
|
||||
constexpr uint32_t LCG_INCREMENT = 12345;
|
||||
constexpr uint32_t LCG_MODULUS = 0x80000000;
|
||||
constexpr uint32_t LCG_MASK = 0x7FFFFFFF;
|
||||
|
||||
uint32_t lcg(uint32_t x, uint32_t a, uint32_t c, uint32_t m)
|
||||
{
|
||||
return (x * a + c) % m;
|
||||
}
|
||||
|
||||
class Random {
|
||||
private:
|
||||
uint32_t _seed;
|
||||
|
||||
public:
|
||||
Random(uint32_t seed) : _seed(seed) {};
|
||||
|
||||
void reset(uint32_t new_seed) {
|
||||
_seed = new_seed;
|
||||
}
|
||||
|
||||
float value() {
|
||||
_seed = lcg(_seed, LCG_MULTIPLIER, LCG_INCREMENT, LCG_MODULUS);
|
||||
return (float)(_seed & LCG_MASK) / (float)LCG_MODULUS;
|
||||
}
|
||||
|
||||
uint8_t byte() {
|
||||
_seed = lcg(_seed, LCG_MULTIPLIER, LCG_INCREMENT, LCG_MODULUS);
|
||||
return (_seed & LCG_MASK) % 0xFF;
|
||||
}
|
||||
};
|
||||
|
||||
Random lcg_random(0);
|
||||
|
||||
// Initializes all the structures and elements needed to start rendering things.
|
||||
void InitCanvas(int width, int height)
|
||||
{
|
||||
|
@ -201,12 +235,13 @@ void DrawCanvas(float x, float y, float zoom)
|
|||
canvas->save();
|
||||
canvas->scale(zoom, zoom);
|
||||
canvas->translate(-x, -y);
|
||||
lcg_random.reset(0);
|
||||
emscripten_log(EM_LOG_CONSOLE, "Clearing canvas");
|
||||
for (auto object : objects) {
|
||||
emscripten_log(EM_LOG_CONSOLE, "Drawing object");
|
||||
// emscripten_log(EM_LOG_CONSOLE, "Drawing object");
|
||||
|
||||
SkPaint paint;
|
||||
paint.setARGB(255, 255, 0, 0);
|
||||
paint.setARGB(255, lcg_random.byte(), lcg_random.byte(), lcg_random.byte());
|
||||
paint.setStyle(SkPaint::Style::kFill_Style);
|
||||
|
||||
SkRect rect = SkRect::MakeXYWH(object.selRect.x, object.selRect.y, object.selRect.width, object.selRect.height);
|
||||
|
@ -219,12 +254,12 @@ void DrawCanvas(float x, float y, float zoom)
|
|||
}
|
||||
|
||||
void SetObjects(int num_objects) {
|
||||
emscripten_log(EM_LOG_CONSOLE, "Resizing objects vector capacity %d", num_objects);
|
||||
// emscripten_log(EM_LOG_CONSOLE, "Resizing objects vector capacity %d", num_objects);
|
||||
objects.resize(num_objects);
|
||||
}
|
||||
|
||||
void SetObject(int index, float x, float y, float width, float height) {
|
||||
emscripten_log(EM_LOG_CONSOLE, "Setting object at %d %f %f %f %f", index, x, y, width, height);
|
||||
void SetObjectRect(int index, float x, float y, float width, float height) {
|
||||
// emscripten_log(EM_LOG_CONSOLE, "Setting object at %d %f %f %f %f", index, x, y, width, height);
|
||||
objects[index].selRect.x = x;
|
||||
objects[index].selRect.y = y;
|
||||
objects[index].selRect.width = width;
|
||||
|
@ -236,5 +271,5 @@ EMSCRIPTEN_BINDINGS(Renderer)
|
|||
function("_InitCanvas", InitCanvas);
|
||||
function("_DrawCanvas", DrawCanvas);
|
||||
function("_SetObjects", SetObjects);
|
||||
function("_SetObject", SetObject);
|
||||
function("_SetObjectRect", SetObjectRect);
|
||||
}
|
||||
|
|
|
@ -64,6 +64,28 @@ Module['ready'] = new Promise(function(resolve, reject) {
|
|||
(function (Renderer) {
|
||||
console.log("preamble", Renderer);
|
||||
|
||||
const LCG_MULTIPLIER = 1103515245;
|
||||
const LCG_INCREMENT = 12345;
|
||||
const LCG_MODULUS = Math.pow(2, 31);
|
||||
const LCG_MASK = (LCG_MODULUS - 1);
|
||||
|
||||
function lcg(x, a, c, m) {
|
||||
return (x * a + c) % m;
|
||||
}
|
||||
|
||||
class Random {
|
||||
constructor(seed) {
|
||||
this._seed = seed;
|
||||
}
|
||||
|
||||
value() {
|
||||
this._seed = lcg(this._seed, LCG_MULTIPLIER, LCG_INCREMENT, LCG_MODULUS);
|
||||
return (this._seed & LCG_MASK) / LCG_MODULUS;
|
||||
}
|
||||
}
|
||||
|
||||
const random = new Random(0)
|
||||
|
||||
// Sets canvas.
|
||||
Renderer.setCanvas = function setCanvas(canvas, attrs) {
|
||||
const context = GL.createContext(canvas, attrs);
|
||||
|
@ -81,21 +103,31 @@ Module['ready'] = new Promise(function(resolve, reject) {
|
|||
};
|
||||
|
||||
Renderer.setObjects = function setObjects(vbox, zoom, objects) {
|
||||
this._SetObjects(objects.cnt);
|
||||
for (let index = 0; index < objects.cnt; index++) {
|
||||
const object = objects.arr[index * 2 + 1];
|
||||
this._SetObject(
|
||||
// this._SetObjects(objects.cnt);
|
||||
const numObjects = 20_000;
|
||||
this._SetObjects(numObjects);
|
||||
for (let index = 0; index < numObjects; index++) {
|
||||
// const object = objects.arr[index * 2 + 1];
|
||||
this._SetObjectRect(
|
||||
index,
|
||||
object.selrect.x,
|
||||
object.selrect.y,
|
||||
object.selrect.width,
|
||||
object.selrect.height,
|
||||
// object.selrect.x,
|
||||
random.value() * 2000,
|
||||
// object.selrect.y,
|
||||
random.value() * 2000,
|
||||
// object.selrect.width,
|
||||
random.value() * 200,
|
||||
// object.selrect.height,
|
||||
random.value() * 200
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
Renderer.drawCanvas = function drawCanvas(vbox, zoom, objects) {
|
||||
performance.mark('draw-canvas:start');
|
||||
this._DrawCanvas(vbox.x, vbox.y, zoom);
|
||||
performance.mark('draw-canvas:end');
|
||||
const { duration } = performance.measure('draw-canvas', 'draw-canvas:start', 'draw-canvas:end');
|
||||
console.log('draw-canvas', `${duration}ms`);
|
||||
};
|
||||
|
||||
console.log("postamble");
|
||||
|
|
Loading…
Add table
Reference in a new issue