ntk 4.2.0 → 4.3.0
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.
- package/lib/window.js +60 -0
- package/package.json +1 -1
package/lib/window.js
CHANGED
|
@@ -693,6 +693,66 @@ export default class Window extends Drawable {
|
|
|
693
693
|
});
|
|
694
694
|
}
|
|
695
695
|
|
|
696
|
+
/**
|
|
697
|
+
* Scroll the pixels of `rect` (window coordinates, `{x, y, width, height}`)
|
|
698
|
+
* by (dx, dy) within the retained backing store, server-side: one CopyArea
|
|
699
|
+
* of the band that survives the shift, in place of the caller re-drawing
|
|
700
|
+
* everything that merely moved. Returns true when the blit was issued;
|
|
701
|
+
* false means "not possible here", and the caller repaints `rect` exactly
|
|
702
|
+
* as it would have without this method — every refusal is the status quo.
|
|
703
|
+
*
|
|
704
|
+
* Refused when there is no (valid) backing store, when the delta is
|
|
705
|
+
* fractional (a sub-pixel shift changes every pixel, so there is nothing
|
|
706
|
+
* to copy), when it is zero, or when nothing of `rect` survives the shift
|
|
707
|
+
* after clamping to window ∩ backing.
|
|
708
|
+
*
|
|
709
|
+
* Backing-store only, deliberately: pixmap contents cannot be occluded, so
|
|
710
|
+
* an overlapping self-copy is fully defined (the server fetches the source
|
|
711
|
+
* region before storing) and the GraphicsExpose handling a window-drawable
|
|
712
|
+
* scroll would need never exists. The copy goes out with the present GC —
|
|
713
|
+
* graphicsExposures: 0, where the 2d context's GC would emit a NoExposure
|
|
714
|
+
* packet per copy — and in-order with the caller's follow-up drawing of
|
|
715
|
+
* the exposed strip on the same connection.
|
|
716
|
+
*
|
|
717
|
+
* The whole of `rect` is marked dirty, so the next present shows the
|
|
718
|
+
* scrolled band through the normal fence-aware path; the caller only has
|
|
719
|
+
* to draw the strip the shift exposed, plus any chrome that moved with
|
|
720
|
+
* the content (a scrollbar thumb, say).
|
|
721
|
+
*/
|
|
722
|
+
scrollRegion(rect, dx, dy) {
|
|
723
|
+
if (!this._backing || !this._backingValid) return false;
|
|
724
|
+
if (!Number.isInteger(dx) || !Number.isInteger(dy) || (dx === 0 && dy === 0)) return false;
|
|
725
|
+
// clamp like a present: the backing is grow-only, so it can be larger
|
|
726
|
+
// than the window after a shrink
|
|
727
|
+
const w = Math.min(this.width, this._backing.width);
|
|
728
|
+
const h = Math.min(this.height, this._backing.height);
|
|
729
|
+
const x0 = Math.max(0, Math.floor(rect.x));
|
|
730
|
+
const y0 = Math.max(0, Math.floor(rect.y));
|
|
731
|
+
const x1 = Math.min(w, Math.ceil(rect.x + rect.width));
|
|
732
|
+
const y1 = Math.min(h, Math.ceil(rect.y + rect.height));
|
|
733
|
+
// the band that survives: dest = clamped rect ∩ (clamped rect + delta)
|
|
734
|
+
const dstX0 = Math.max(x0, x0 + dx);
|
|
735
|
+
const dstY0 = Math.max(y0, y0 + dy);
|
|
736
|
+
const dstX1 = Math.min(x1, x1 + dx);
|
|
737
|
+
const dstY1 = Math.min(y1, y1 + dy);
|
|
738
|
+
if (dstX1 <= dstX0 || dstY1 <= dstY0) return false;
|
|
739
|
+
safeRelease(this.X, () => {
|
|
740
|
+
this.X.CopyArea(
|
|
741
|
+
this._backing.id,
|
|
742
|
+
this._backing.id,
|
|
743
|
+
this._presentGc,
|
|
744
|
+
dstX0 - dx,
|
|
745
|
+
dstY0 - dy,
|
|
746
|
+
dstX0,
|
|
747
|
+
dstY0,
|
|
748
|
+
dstX1 - dstX0,
|
|
749
|
+
dstY1 - dstY0
|
|
750
|
+
);
|
|
751
|
+
});
|
|
752
|
+
this._markDirty({ x: x0, y: y0, w: x1 - x0, h: y1 - y0 });
|
|
753
|
+
return true;
|
|
754
|
+
}
|
|
755
|
+
|
|
696
756
|
/*
|
|
697
757
|
* Frame clock. Noisy events (see events_map coalesce), synthetic redraws
|
|
698
758
|
* and requestAnimationFrame callbacks are delivered in "frames", paced by
|