Просмотр исходного кода

Follow the primary plane's gamma in the Intel cursor

The Ironlake display palette sits after the plane blender.  We forced
CURSOR_GAMMA_ENABLE on the cursor plane even when the VBE primary plane
bypasses the palette, so the cursor's premultiplied antialiased edge
pixels went through the LUT alone and appeared as a white halo on any
non-black background (the X201).

Read the matching DSPxCNTR gamma-enable bit and mirror it, and drop the
pipe-select field: Gen5 has one cursor register per pipe, so bits 29:28
are reserved (Linux skips them for Gen5).

Verified on the X201: the halo is gone and the pointer looks correct
over both light and dark windows.
Johannes Zellner 2 дней назад
Родитель
Сommit
ed2d7f479a
3 измененных файлов с 31 добавлено и 9 удалено
  1. 8 3
      AGENTS.md
  2. 1 1
      docs/graphics.html
  3. 22 5
      kernel/intel.c

+ 8 - 3
AGENTS.md

@@ -1103,9 +1103,14 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   (decoding RGB565 or BGR from the saved background); a shape change
   (decoding RGB565 or BGR from the saved background); a shape change
   presents the union of the old and new rectangles at once.  Intel
   presents the union of the old and new rectangles at once.  Intel
   Ironlake and Radeon copy the image into their 64x64 ARGB planes (Intel's
   Ironlake and Radeon copy the image into their 64x64 ARGB planes (Intel's
-  CURPOS takes sign-magnitude negatives; Radeon clamps the position at 0
-  and skips the hidden part with `HORZ_VERT_OFF` and a `CUR_OFFSET` shifted
-  by 256 bytes per row, like Linux's legacy path); Cirrus thresholds alpha
+  CURPOS takes sign-magnitude negatives; the Intel cursor gamma enable
+  follows the matching primary plane's `DSPxCNTR` gamma enable, because the
+  display palette sits after the plane blender and forcing cursor gamma on
+  in a VBE mode whose primary bypasses it sends only the cursor through the
+  palette and gives its antialiased edges a bright halo; Radeon clamps the
+  position at 0 and skips the hidden part with `HORZ_VERT_OFF` and a
+  `CUR_OFFSET` shifted by 256 bytes per row, like Linux's legacy path);
+  Cirrus thresholds alpha
   at 50% into its AND/XOR planes (white/black by luminance) and clamps the
   at 50% into its AND/XOR planes (white/black by luminance) and clamps the
   position at 0.  An image upload never runs from IRQ12, which only moves.
   position at 0.  An image upload never runs from IRQ12, which only moves.
   Animated shapes advance from `mouse_poll_update()`.  Scroll from every backend accumulates in
   Animated shapes advance from `mouse_poll_update()`.  Scroll from every backend accumulates in

+ 1 - 1
docs/graphics.html

@@ -496,7 +496,7 @@
 			<li><strong>Loading.</strong> <span class="file">cursor.c</span> copies the bundle out of the ramfs into its own pages after <code>ramfs_init()</code> and after every <code>ramfs_replace()</code> (the old pack is freed), then tells <span class="file">mouse.c</span> to re-fetch its image.</li>
 			<li><strong>Loading.</strong> <span class="file">cursor.c</span> copies the bundle out of the ramfs into its own pages after <code>ramfs_init()</code> and after every <code>ramfs_replace()</code> (the old pack is freed), then tells <span class="file">mouse.c</span> to re-fetch its image.</li>
 			<li><strong>Selection.</strong> On every <code>SYS_WM_POLL</code> the window server resolves the shape: the WM's override (<code>SYS_WM_SET_CURSOR</code>: resize arrows on the grip and while resizing, the move cross during a title-bar drag, a hand over launchers and the status area), else the cursor of the window holding the pointer capture, else the content cursor (<code>SYS_WIN_SET_CURSOR</code>) of the window under the pointer, else the arrow.</li>
 			<li><strong>Selection.</strong> On every <code>SYS_WM_POLL</code> the window server resolves the shape: the WM's override (<code>SYS_WM_SET_CURSOR</code>: resize arrows on the grip and while resizing, the move cross during a title-bar drag, a hand over launchers and the status area), else the cursor of the window holding the pointer capture, else the content cursor (<code>SYS_WIN_SET_CURSOR</code>) of the window under the pointer, else the arrow.</li>
 			<li><strong>Clients.</strong> ngui resets the cursor to the arrow for each redrawn frame, a hovered text field asks for the I-beam, <code>ngui_cursor_rect()</code>/<code>ngui_set_cursor()</code> serve apps, and <code>ngui_end_ex()</code> sends it when it changed.  The terminal uses the I-beam; the browser maps the inherited CSS <code>cursor</code> property and, for <code>auto</code>, a hand over links, an I-beam over text fields and the progress arrow while a page loads.  The gallery's Cursors section shows every shape.</li>
 			<li><strong>Clients.</strong> ngui resets the cursor to the arrow for each redrawn frame, a hovered text field asks for the I-beam, <code>ngui_cursor_rect()</code>/<code>ngui_set_cursor()</code> serve apps, and <code>ngui_end_ex()</code> sends it when it changed.  The terminal uses the I-beam; the browser maps the inherited CSS <code>cursor</code> property and, for <code>auto</code>, a hand over links, an I-beam over text fields and the progress arrow while a page loads.  The gallery's Cursors section shows every shape.</li>
-			<li><strong>Drawing.</strong> <code>cur_x</code>/<code>cur_y</code> stay the hotspot; the image's top-left is the hotspot minus the image's hotspot and may be off-screen.  The software cursor saves up to 32&times;32 pixels under it and blends the premultiplied pixels over them.  Intel Ironlake and Radeon copy the ARGB image into their 64&times;64 planes (Intel uses CURPOS sign bits for negative positions, Radeon <code>HORZ_VERT_OFF</code> plus a shifted <code>CUR_OFFSET</code>); Cirrus reduces it to its two colours and clamps the position at 0.  Animated frames advance from <code>mouse_poll_update()</code>.</li>
+			<li><strong>Drawing.</strong> <code>cur_x</code>/<code>cur_y</code> stay the hotspot; the image's top-left is the hotspot minus the image's hotspot and may be off-screen.  The software cursor saves up to 32&times;32 pixels under it and blends the premultiplied pixels over them.  Intel Ironlake and Radeon copy the ARGB image into their 64&times;64 planes (Intel uses CURPOS sign bits for negative positions and follows the matching primary plane's gamma enable, because the display palette is after the plane blender and a cursor-only gamma pass brightens its antialiased edges on a VBE mode whose primary bypasses the palette; Radeon uses <code>HORZ_VERT_OFF</code> plus a shifted <code>CUR_OFFSET</code>); Cirrus reduces it to its two colours and clamps the position at 0.  Animated frames advance from <code>mouse_poll_update()</code>.</li>
 		</ul>
 		</ul>
 	</section>
 	</section>
 
 

+ 22 - 5
kernel/intel.c

@@ -12,8 +12,10 @@
  *  - 64x64 ARGB8888 cursor, MSB A:R:G:B, hotspot at (0,0); the mouse code
  *  - 64x64 ARGB8888 cursor, MSB A:R:G:B, hotspot at (0,0); the mouse code
  *    positions the image's top-left, so CURPOS takes negative values in
  *    positions the image's top-left, so CURPOS takes negative values in
  *    sign-magnitude form (bit 15 = X sign, bit 31 = Y sign).
  *    sign-magnitude form (bit 15 = X sign, bit 31 = Y sign).
- *  - CURCNTR bit 31 enables, mode 0x27 is 64x64 ARGB, bits 29:28 hold the
- *    pipe select.  CURBASE is written after CURPOS to arm the update.
+ *  - CURCNTR bit 31 enables, mode 0x27 is 64x64 ARGB.  Gen5 has one cursor
+ *    register per pipe, so bits 29:28 (the old pipe select) are reserved.
+ *    The cursor gamma enable follows the matching primary plane's gamma
+ *    enable; CURBASE is written after CURPOS to arm the update.
  *  - The GTT PTE is the physical page, its bits 35:32 in PTE bits 7:4, the
  *  - The GTT PTE is the physical page, its bits 35:32 in PTE bits 7:4, the
  *    uncached mapping type (0) and the valid bit (1).
  *    uncached mapping type (0) and the valid bit (1).
  */
  */
@@ -48,10 +50,10 @@
 #define CUR_PIPE_B       0x40
 #define CUR_PIPE_B       0x40
 
 
 #define DSP_PLANE_ENABLE       (1u << 31)
 #define DSP_PLANE_ENABLE       (1u << 31)
+#define DSP_PLANE_GAMMA_ENABLE (1u << 30)
 #define CURSOR_ENABLE          (1u << 31)
 #define CURSOR_ENABLE          (1u << 31)
 #define CURSOR_GAMMA_ENABLE    (1u << 26)
 #define CURSOR_GAMMA_ENABLE    (1u << 26)
 #define CURSOR_MODE_64_ARGB    0x27u
 #define CURSOR_MODE_64_ARGB    0x27u
-#define CURSOR_PIPE_SEL_SHIFT  28
 
 
 #define CUR_SIZE   64
 #define CUR_SIZE   64
 #define CUR_BYTES  (CUR_SIZE * CUR_SIZE * 4)
 #define CUR_BYTES  (CUR_SIZE * CUR_SIZE * 4)
@@ -222,10 +224,21 @@ static int intel_map_cursor(unsigned int slot)
 	return 0;
 	return 0;
 }
 }
 
 
+/* The display palette (gamma LUT) sits after the plane blender on
+ * Ironlake.  Enabling the cursor's gamma while the primary plane bypasses
+ * it sends only the cursor through the palette; on a VBE mode whose
+ * primary plane has gamma disabled that turns the antialiased cursor
+ * edges into a bright halo.  Follow the matching primary plane's gamma
+ * enable instead.  Gen5 has one cursor register per pipe, so the old
+ * (pre-Gen5) pipe-select field is reserved and must stay zero. */
 static unsigned int cursor_ctrl(unsigned int pipe)
 static unsigned int cursor_ctrl(unsigned int pipe)
 {
 {
-	return CURSOR_ENABLE | CURSOR_GAMMA_ENABLE |
-	       CURSOR_MODE_64_ARGB | (pipe << CURSOR_PIPE_SEL_SHIFT);
+	unsigned int dsp = pipe ? DSPBCNTR : DSPACNTR;
+	unsigned int ctrl = CURSOR_ENABLE | CURSOR_MODE_64_ARGB;
+
+	if (mmio_read(dsp) & DSP_PLANE_GAMMA_ENABLE)
+		ctrl |= CURSOR_GAMMA_ENABLE;
+	return ctrl;
 }
 }
 
 
 void intel_init(unsigned int bus, unsigned int dev, unsigned int device_id)
 void intel_init(unsigned int bus, unsigned int dev, unsigned int device_id)
@@ -332,6 +345,10 @@ void intel_init(unsigned int bus, unsigned int dev, unsigned int device_id)
 	serial_puthex(SERIAL_COM1, intel_pipe_mask);
 	serial_puthex(SERIAL_COM1, intel_pipe_mask);
 	serial_puts(SERIAL_COM1, ", cursor ");
 	serial_puts(SERIAL_COM1, ", cursor ");
 	serial_puthex(SERIAL_COM1, intel_cursor_gtt);
 	serial_puthex(SERIAL_COM1, intel_cursor_gtt);
+	serial_puts(SERIAL_COM1, ", dspa ");
+	serial_puthex(SERIAL_COM1, dspa);
+	serial_puts(SERIAL_COM1, ", dspb ");
+	serial_puthex(SERIAL_COM1, dspb);
 	serial_puts(SERIAL_COM1, "\n");
 	serial_puts(SERIAL_COM1, "\n");
 
 
 	intel_probe_ok = 1;
 	intel_probe_ok = 1;