@geastack/engine 0.1.13 → 0.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,8 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  #pragma once
3
3
 
4
+ #include <memory>
5
+
4
6
  #include "canvas.h"
5
7
  #include "node.h"
6
8
 
@@ -87,6 +89,45 @@ void canvasPerfStatsReset();
87
89
  CanvasPerfStats canvasPerfStatsRead();
88
90
  void canvasTotalsRead(int *begin, int *end, int *fillRect, int *drawImage, int *nullPixels, int *presentOk);
89
91
 
92
+ // Everything a 2D context carries between calls: the open batch and its
93
+ // recorded commands, styles, the current path. One per canvas, shared by every
94
+ // CanvasRenderingContext2D for it -- `getContext('2d')` hands back the same
95
+ // object each time, so a context passed to a helper (a by-value copy in
96
+ // generated code) must draw into, and style, the same batch as the original.
97
+ struct CanvasContextState {
98
+ gea::framework::graphics::Canvas *batchCanvas_ = nullptr;
99
+ std::vector<CanvasPresentCommand> presentCommands_;
100
+ std::size_t presentCommandCount_ = 0;
101
+ gea::framework::graphics::pixel::native_t fillStyle_ = gea::framework::graphics::pixel::nativeColor(255, 255, 255);
102
+ gea::framework::graphics::pixel::native_t strokeStyle_ = gea::framework::graphics::pixel::nativeColor(255, 255, 255);
103
+ std::string fillStyleSource_;
104
+ std::string strokeStyleSource_;
105
+ double arcX_ = 0.0;
106
+ double arcY_ = 0.0;
107
+ double arcRadius_ = 0.0;
108
+ std::vector<double> pathX_;
109
+ std::vector<double> pathY_;
110
+ // Start index in pathX_/pathY_ of each subpath (one per moveTo), so a path
111
+ // can hold MULTIPLE rings/contours — required for concave polygons with
112
+ // holes (even-odd fill) and multi-part strokes.
113
+ std::vector<int> pathStarts_;
114
+ double lineWidth_ = 1.0;
115
+ float fontScale_ = 1.0f;
116
+ int fontFamilyId_ = -1;
117
+ int fontSizePx_ = 16;
118
+ // Cache the last CSS font string so setFont can skip the parse + FontRegistry
119
+ // lookups when an app re-sets the same font every frame (e.g. an FPS readout).
120
+ std::string lastFontStr_;
121
+ std::uint8_t globalAlpha_ = 255;
122
+ int batchDepth_ = 0;
123
+ bool fillStyleCached_ = false;
124
+ bool strokeStyleCached_ = false;
125
+ bool hasArc_ = false;
126
+ bool pathClosed_ = false;
127
+ bool presentRecording_ = false;
128
+ bool batchDirty_ = false;
129
+ };
130
+
90
131
  class CanvasRenderingContext2D {
91
132
  public:
92
133
  // A non-explicit default ctor is required so this type can be a by-value
@@ -95,8 +136,12 @@ public:
95
136
  // which copy-`{}`-initializes each field — and copy-init cannot select an
96
137
  // `explicit` constructor. `explicit` is kept on the int form so a bare
97
138
  // `int` still can't implicitly convert to a context.
98
- CanvasRenderingContext2D() : nodeId_(-1) {}
99
- explicit CanvasRenderingContext2D(int nodeId) : nodeId_(nodeId) {}
139
+ CanvasRenderingContext2D() : nodeId_(-1), state_(stateFor(-1)) {}
140
+ explicit CanvasRenderingContext2D(int nodeId) : nodeId_(nodeId), state_(stateFor(nodeId)) {}
141
+ // The shared state of canvas `nodeId`; -1 is the direct-canvas display.
142
+ static std::shared_ptr<CanvasContextState> stateFor(int nodeId);
143
+ // Drops canvas `nodeId`'s state, so a node id reused later starts clean.
144
+ static void releaseState(int nodeId);
100
145
 
101
146
  bool valid() const { return nodeId_ >= 0; }
102
147
  // The absence state `valid()` already answers, in the spelling a test uses.
@@ -197,6 +242,14 @@ public:
197
242
  void fillText(const std::string &text, int x, int y);
198
243
  void fillText(const std::string &text, double x, double y);
199
244
  void drawImage(int imageId, int dx, int dy);
245
+ // drawImage at full opacity whatever globalAlpha is: putImageData.
246
+ void putImage(int imageId, int dx, int dy);
247
+ // Draws `height` rows of `width` opaque pixels, row r read from
248
+ // `pixels + r * stride`, at (dx, dy). The rows must stay valid until the
249
+ // frame is presented: they are recorded, not copied. This is a sub-rectangle
250
+ // of a larger buffer -- putImageData's dirty rectangle -- without a copy.
251
+ // Like putImageData, it ignores globalAlpha.
252
+ void drawPixelRows(const gea::framework::graphics::pixel::native_t *pixels, int stride, int width, int height, int dx, int dy);
200
253
  void drawImage(int imageId, double dx, double dy);
201
254
  void drawImage(int imageId, int dx, int dy, int dw, int dh);
202
255
  void drawImage(int imageId, double dx, double dy, double dw, double dh);
@@ -310,37 +363,7 @@ private:
310
363
  void markDrawDirty();
311
364
 
312
365
  int nodeId_;
313
- gea::framework::graphics::Canvas *batchCanvas_ = nullptr;
314
- std::vector<CanvasPresentCommand> presentCommands_;
315
- std::size_t presentCommandCount_ = 0;
316
- gea::framework::graphics::pixel::native_t fillStyle_ = gea::framework::graphics::pixel::nativeColor(255, 255, 255);
317
- gea::framework::graphics::pixel::native_t strokeStyle_ = gea::framework::graphics::pixel::nativeColor(255, 255, 255);
318
- std::string fillStyleSource_;
319
- std::string strokeStyleSource_;
320
- double arcX_ = 0.0;
321
- double arcY_ = 0.0;
322
- double arcRadius_ = 0.0;
323
- std::vector<double> pathX_;
324
- std::vector<double> pathY_;
325
- // Start index in pathX_/pathY_ of each subpath (one per moveTo), so a path
326
- // can hold MULTIPLE rings/contours — required for concave polygons with
327
- // holes (even-odd fill) and multi-part strokes.
328
- std::vector<int> pathStarts_;
329
- double lineWidth_ = 1.0;
330
- float fontScale_ = 1.0f;
331
- int fontFamilyId_ = -1;
332
- int fontSizePx_ = 16;
333
- // Cache the last CSS font string so setFont can skip the parse + FontRegistry
334
- // lookups when an app re-sets the same font every frame (e.g. an FPS readout).
335
- std::string lastFontStr_;
336
- std::uint8_t globalAlpha_ = 255;
337
- int batchDepth_ = 0;
338
- bool fillStyleCached_ = false;
339
- bool strokeStyleCached_ = false;
340
- bool hasArc_ = false;
341
- bool pathClosed_ = false;
342
- bool presentRecording_ = false;
343
- bool batchDirty_ = false;
366
+ std::shared_ptr<CanvasContextState> state_;
344
367
  };
345
368
 
346
369
  class CanvasElement : public NodeHandle {
package/ui/layout.cpp CHANGED
@@ -4293,14 +4293,18 @@ bool LayoutEngine::layoutNodeScoped(int scope, int treeRoot)
4293
4293
 
4294
4294
  // Absolute descendants positioned against a containing block OUTSIDE the
4295
4295
  // scope mix coordinate spaces (the global containing-block pass runs in
4296
- // pre-resolve relative space) — those trees must take the full path.
4296
+ // pre-resolve relative space) — those trees must take the full path. The
4297
+ // scope itself is exempt: its own position is restored below, never
4298
+ // recomputed, and a size change is rejected by the dims check. Testing it
4299
+ // here refused every absolutely placed scope (Ember's temperature readout,
4300
+ // then its screen), so each tick of a number fell back to a full relayout.
4297
4301
  for (int i = 0; i < nodeCount; ++i) {
4298
4302
  const Node &n = nodes[i];
4303
+ if (i == scope) continue;
4299
4304
  if (n.parent < 0 || !isOutOfFlowPosition(n.computedStyle().position) || isDisplayNone(n.computedStyle())) continue;
4300
4305
  if (!inScope(i)) continue;
4301
4306
  const int containing = containingBlockForAbsoluteNode(i, treeRoot, nodes);
4302
4307
  if (containing >= 0 && !inScope(containing)) {
4303
- GEA_REFRESH_PERF(refreshPerfStatsMutable().treeScopedRejectReason = 3);
4304
4308
  GEA_REFRESH_PERF(refreshPerfStatsMutable().treeScopedRejectNode = i);
4305
4309
  return false;
4306
4310
  }