ntk 8.9.0 → 8.9.1

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.
Files changed (2) hide show
  1. package/lib/glswapchain.js +51 -5
  2. package/package.json +1 -1
@@ -108,23 +108,69 @@ export class GLSwapchain {
108
108
  const gen = this.generation;
109
109
  if (gen && gen.width === w && gen.height === h) return gen.surface;
110
110
  this._retire(gen);
111
- // a generation that had to go linear keeps that layout: whatever made the
112
- // server refuse the tiled buffer has not changed since
111
+ // a generation that had to go linear keeps that layout: whatever refused
112
+ // the tiled buffer — the server, or EGL itself — has not changed since
113
113
  return this._newGeneration(w, h, gen ? gen.linear : false);
114
114
  }
115
115
 
116
+ /** A GBM surface at this size, in the layout asked for. */
117
+ _createSurface(w, h, linear) {
118
+ return linear
119
+ ? this.gpu.createSurface(w, h, this.dri.GBM_USE.RENDERING | this.dri.GBM_USE.LINEAR)
120
+ : this.gpu.createSurface(w, h);
121
+ }
122
+
116
123
  _newGeneration(w, h, linear) {
117
- const use = linear ? this.dri.GBM_USE.RENDERING | this.dri.GBM_USE.LINEAR : undefined;
118
124
  let surface;
119
125
  try {
120
- surface = use === undefined ? this.gpu.createSurface(w, h) : this.gpu.createSurface(w, h, use);
126
+ surface = this._createSurface(w, h, linear);
121
127
  } catch (err) {
122
- throw glError(GLError.CONTEXT_FAILED, `could not create a ${w}x${h} GPU surface: ${err.message}`, null, err);
128
+ // Some drivers will not give EGL a window surface over a render-only
129
+ // GBM buffer at all: NVIDIA's answers eglCreateWindowSurface with
130
+ // EGL_BAD_MATCH, and takes the very same size and format once the
131
+ // buffer is linear. That is the retry an import refusal gets below,
132
+ // one step earlier — there the server would not read the buffer, here
133
+ // EGL would not draw into it, and a linear layout is what both of them
134
+ // accept. Cheap to try: the alternative is no direct rendering at all.
135
+ if (linear || !this.policy.linearFallback) {
136
+ throw this._surfaceError(w, h, linear ? 'linear' : 'tiled', err.message, err);
137
+ }
138
+ try {
139
+ surface = this._createSurface(w, h, true);
140
+ } catch (retryErr) {
141
+ throw this._surfaceError(
142
+ w,
143
+ h,
144
+ 'tiled or linear',
145
+ `${err.message}; linear: ${retryErr.message}`,
146
+ err
147
+ );
148
+ }
149
+ linear = true;
123
150
  }
124
151
  this.generation = new Generation(surface, w, h, linear);
125
152
  return surface;
126
153
  }
127
154
 
155
+ /** No surface, naming the layouts that were refused and what to change. */
156
+ _surfaceError(w, h, tried, detail, cause) {
157
+ const hint =
158
+ tried === 'tiled'
159
+ ? 'A driver that will not draw into a tiled buffer (NVIDIA) takes a linear one,\n' +
160
+ 'which is the retry glPolicy: { linearFallback: true } — the default — makes.\n' +
161
+ 'See docs/context-gles.md#buffer-layout.'
162
+ : 'No layout this device offers can back a window surface for this driver.\n' +
163
+ "Another render node may: glPolicy: { devicePath: '/dev/dri/renderD###' }.\n" +
164
+ "Failing that, glPolicy: 'indirect' draws with no GPU buffer at all.\n" +
165
+ 'See docs/context-gles.md#buffer-layout.';
166
+ return glError(
167
+ GLError.CONTEXT_FAILED,
168
+ `could not create a ${w}x${h} GPU surface (${tried}): ${detail}`,
169
+ hint,
170
+ cause
171
+ );
172
+ }
173
+
128
174
  /** Can a frame be drawn and presented right now? */
129
175
  canRender() {
130
176
  if (this.destroyed || this.error) return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ntk",
3
- "version": "8.9.0",
3
+ "version": "8.9.1",
4
4
  "description": "Desktop UI toolkit for X11 with canvas-like 2d and OpenGL rendering",
5
5
  "author": "Andrey Sidorov <sidorares@yandex.ru>",
6
6
  "license": "MIT",