Clear out gfxterm's virtual text_buffer - fixes junk at end of lines
PATCH 1/1 Clear out gfxterm's virtual text_buffer - fixes junk at end of lines
Hi,
My first patch! Please be nice.
* src/term/gfxterm.c (grub_virtual_screen_setup): Clear out text_buffer instead of leaving it uninitialized.
This fixes a 100% reproducible and very annoying bug I've found: Switch to gfxterm and until your clear the screen or scroll, the last position of every line has a random junk character in random foreground and background color. I believe the root cause is that the virtual_screen's text_buffer is uninitialized; as the cursor reaches a new position, the uninitialized junk data is drawn to the screen. Really, the entire screen is junk, but it's never marked dirty so it's never drawn. So let's just clear out the whole text_buffer when we set up the screen.
-joe
-=-=-=-=-=-=-=-=-=-=-=-=-
term/gfxterm.c +0 -0
@@ -225,6 +225,17 @@ grub_video_set_active_render_target
(GRUB_VIDEO_RENDER_TARGET_DISPLAY);
+ /* Clear out text buffer */
+ unsigned int i;
+ for(i = 0; i < virtual_screen.columns * virtual_screen.rows; i++)
+ {
+ virtual_screen.text_buffer[i].code = ' ';
+ virtual_screen.text_buffer[i].fg_color = virtual_screen.fg_color;
+ virtual_screen.text_buffer[i].bg_color = virtual_screen.bg_color;
+ virtual_screen.text_buffer[i].width = 0;
+ virtual_screen.text_buffer[i].index = 0;+ }
+
return grub_errno;
}
Quoted 7 lines · Joe Auricchio
Hi,
My first patch! Please be nice.
*
src/term/gfxterm.c(grub_virtual_screen_setup): Clear outtext_bufferinstead of leaving it uninitialized.
Quoted 8 lines
This fixes a 100% reproducible and very annoying bug I've found: Switch to gfxterm and until your clear the screen or scroll, the last position of every line has a random junk character in random foreground and background color. I believe the root cause is that the virtual_screen's
text_bufferis uninitialized; as the cursor reaches a new position, the uninitialized junk data is drawn to the screen. Really, the entire screen is junk, but it's never marked dirty so it's never drawn. So let's just clear out the wholetext_bufferwhen we set up the screen.
But grub_virtual_screen_free() already set the whole structure to 0 at the beginning of grub_virtual_screen_setup().
Does a zero-filled screen result in garbage, or is something else overwriting it?
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 11 lines · Robert Millan
Quoted 9 lines · Joe Auricchio
This fixes a 100% reproducible and very annoying bug I've found: Switch to gfxterm and until your clear the screen or scroll, the last position of every line has a random junk character in random foreground and background color. I believe the root cause is that the virtual_screen's
text_bufferis uninitialized; as the cursor reaches a new position, the uninitialized junk data is drawn to the screen. Really, the entire screen is junk, but it's never marked dirty so it's never drawn. So let's just clear out the wholetext_bufferwhen we set up the screen.
Quoted 5 lines
But
grub_virtual_screen_free()already set the whole structure to 0 at the beginning ofgrub_virtual_screen_setup().Does a zero-filled screen result in garbage, or is something else overwriting it?
grub_virtual_screen_free sets all of virtual_screen to 0, but not virtual_screen.text_buffer. text_buffer just gets grub_freed. Later in grub_virtual_screen_setup, a new text_buffer is grub_malloced. It's this new text_buffer that my patch clears out.
-joe
Quoted 23 lines · Joe Auricchio
Quoted 21 lines · Robert Millan
Quoted 15 lines · Joe Auricchio
This fixes a 100% reproducible and very annoying bug I've found:
Switch
to gfxterm and until your clear the screen or scroll, the last position
of every line has a random junk character in random foreground and background color. I believe the root cause is that the virtual_screen'stext_bufferis uninitialized; as the cursor reaches a new position, the
uninitialized junk data is drawn to the screen. Really, the entire screen
is junk, but it's never marked dirty so it's never drawn. So let's just
clear out the wholetext_bufferwhen we set up the screen.But
grub_virtual_screen_free()already set the whole structure to 0 at the
beginning ofgrub_virtual_screen_setup().
Quoted 8 lines
Quoted 3 lines
Does a zero-filled screen result in garbage, or is something else overwriting
it?
grub_virtual_screen_freesets all ofvirtual_screento 0, but not virtual_screen.text_buffer.text_bufferjust getsgrub_freed. Later ingrub_virtual_screen_setup, a newtext_bufferisgrub_malloced. It's this newtext_bufferthat my patch clears out.
So perhaps this can be solved simpler by replacing grub_malloc with grub_zalloc ?
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 28 lines · Robert Millan
Quoted 27 lines · Joe Auricchio
Quoted 24 lines · Robert Millan
Quoted 15 lines · Joe Auricchio
This fixes a 100% reproducible and very annoying bug I've found:
Switch
to gfxterm and until your clear the screen or scroll, the last position
of every line has a random junk character in random foreground and background color. I believe the root cause is that the virtual_screen'stext_bufferis uninitialized; as the cursor reaches a new position, the
uninitialized junk data is drawn to the screen. Really, the entire screen
is junk, but it's never marked dirty so it's never drawn. So let's just
clear out the wholetext_bufferwhen we set up the screen.But
grub_virtual_screen_free()already set the whole structure to 0 at the
beginning ofgrub_virtual_screen_setup().Does a zero-filled screen result in garbage, or is something else overwriting
it?
Quoted 7 lines
Quoted 4 lines
grub_virtual_screen_freesets all ofvirtual_screento 0, but not virtual_screen.text_buffer.text_bufferjust getsgrub_freed. Later ingrub_virtual_screen_setup, a newtext_bufferisgrub_malloced. It's this newtext_bufferthat my patch clears out.So perhaps this can be solved simpler by replacing
grub_mallocwithgrub_zalloc?
I saw the zalloc commit and thought the same thing! :D I'll test it. But fg_color and bg_color must be set to the screen's current colors, which may not be zero.
I just discovered that
- this patch to grub_virtual_screen_setup()
- scroll_up() line 579 /* Clear last line in text buffer. */, and
- grub_virtual_screen_cls()
do the same thing.
An opportunity to refactor? I'll look into this.
-joe
Quoted 46 lines · Joe Auricchio
Quoted 36 lines · Robert Millan
Quoted 28 lines · Joe Auricchio
Quoted 17 lines · Robert Millan
Quoted 15 lines · Joe Auricchio
This fixes a 100% reproducible and very annoying bug I've found:
Switch
to gfxterm and until your clear the screen or scroll, the last position
of every line has a random junk character in random foreground and background color. I believe the root cause is that the virtual_screen'stext_bufferis uninitialized; as the cursor reaches a new position, the
uninitialized junk data is drawn to the screen. Really, the entire screen
is junk, but it's never marked dirty so it's never drawn. So let's just
clear out the wholetext_bufferwhen we set up the screen.Quoted 8 lines
But
grub_virtual_screen_free()already set the whole structure to 0 at
the
beginning ofgrub_virtual_screen_setup().Does a zero-filled screen result in garbage, or is something else overwriting
it?Quoted 6 lines
grub_virtual_screen_freesets all ofvirtual_screento 0, but not virtual_screen.text_buffer.text_bufferjust getsgrub_freed. Later ingrub_virtual_screen_setup, a newtext_bufferisgrub_malloced. It's this
newtext_bufferthat my patch clears out.Quoted 2 lines
So perhaps this can be solved simpler by replacing
grub_mallocwithgrub_zalloc?I saw the zalloc commit and thought the same thing! :D I'll test it. But
fg_colorandbg_colormust be set to the screen's current colors, which may not be zero.
Quoted 7 lines
I just discovered that
- this patch togrub_virtual_screen_setup()
-scroll_up()line 579 /* Clear last line in text buffer. */, and
-grub_virtual_screen_cls()
do the same thing.An opportunity to refactor? I'll look into this.
Please do. We're very interested in code cleanup.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 8 lines · Joe Auricchio
Quoted 3 lines
So perhaps this can be solved simpler by replacing
grub_mallocwithgrub_zalloc?I saw the zalloc commit and thought the same thing! :D I'll test it. But
fg_colorandbg_colormust be set to the screen's current colors, which may not be zero.
Quoted 7 lines
I just discovered that
- this patch togrub_virtual_screen_setup()
-scroll_up()line 579 /* Clear last line in text buffer. */, and
-grub_virtual_screen_cls()
do the same thing.An opportunity to refactor? I'll look into this.
Hi,
Note that the initial patch was committed due to lack of coordination (there's been a period in which we've been sloppy due to lack of leadership, but this won't happen again).
Nevertheless, the initial approach is probably not correct; my impression is that it should be using grub_zalloc() instead. If you're still interested, I'd appreciate if you could fix that.
Thanks
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 19 lines · Robert Millan
Quoted 8 lines · Joe Auricchio
Quoted 3 lines
So perhaps this can be solved simpler by replacing
grub_mallocwithgrub_zalloc?I saw the zalloc commit and thought the same thing! :D I'll test it. But
fg_colorandbg_colormust be set to the screen's current colors, which may not be zero.Quoted 7 lines
I just discovered that
- this patch togrub_virtual_screen_setup()
-scroll_up()line 579 /* Clear last line in text buffer. */, and
-grub_virtual_screen_cls()
do the same thing.An opportunity to refactor? I'll look into this.
Hi,
Quoted 7 lines
Note that the initial patch was committed due to lack of coordination (there's been a period in which we've been sloppy due to lack of leadership, but this won't happen again).
Nevertheless, the initial approach is probably not correct; my impression is that it should be using
grub_zalloc()instead. If you're still interested, I'd appreciate if you could fix that.
Using zalloc only makes sense in grub_virtual_screen_setup, when the buffer is allocated. But the clear_chars loop is used thrice: in _setup, in grub_virtual_screen_cls, and in scroll_up.
Freeing and allocating a new buffer for each cls or scroll is clearly insane. So the zalloc can't be in the common function.
The goal of this refactor was to centralize the code for visually clearing the text buffer. So it doesn't make sense to have _setup use zalloc but have _cls and scroll_up use a loop without zalloc: then what has been refactored?
It seemed like a nice idea to use zalloc, but this code isn't the right nail for that hammer. :)
Let me know how you want to proceed. If you'd still like to use zalloc I can adjust the patch.
Quoted 40 lines · Joe Auricchio
Quoted 19 lines · Robert Millan
Quoted 8 lines · Joe Auricchio
Quoted 3 lines
So perhaps this can be solved simpler by replacing
grub_mallocwithgrub_zalloc?I saw the zalloc commit and thought the same thing! :D I'll test it. But
fg_colorandbg_colormust be set to the screen's current colors, which may not be zero.Quoted 7 lines
I just discovered that
- this patch togrub_virtual_screen_setup()
-scroll_up()line 579 /* Clear last line in text buffer. */, and
-grub_virtual_screen_cls()
do the same thing.An opportunity to refactor? I'll look into this.
Hi,
Quoted 7 lines
Note that the initial patch was committed due to lack of coordination (there's been a period in which we've been sloppy due to lack of leadership, but this won't happen again).
Nevertheless, the initial approach is probably not correct; my impression is that it should be using
grub_zalloc()instead. If you're still interested, I'd appreciate if you could fix that.Using zalloc only makes sense in
grub_virtual_screen_setup, when the buffer is allocated. But theclear_charsloop is used thrice: in_setup, ingrub_virtual_screen_cls, and inscroll_up.Freeing and allocating a new buffer for each cls or scroll is clearly insane. So the zalloc can't be in the common function.
The goal of this refactor was to centralize the code for visually clearing the text buffer. So it doesn't make sense to have
_setupuse zalloc but have_clsandscroll_upuse a loop without zalloc: then what has been refactored?
Quoted 5 lines
It seemed like a nice idea to use zalloc, but this code isn't the right nail for that hammer. :)
Let me know how you want to proceed. If you'd still like to use zalloc I can adjust the patch.
No. When I suggested zalloc I hadn't looked at this in detail (and I still haven't). I was under the impression that you considered zalloc was suitable.
If that's not the case, then there's nothing more to say. Thanks for your explanation!
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 3 lines · Joe Auricchio
Hi,
My first patch! Please be nice.
Welcome aboard
Quoted 4 lines
*
src/term/gfxterm.c(grub_virtual_screen_setup): Clear outtext_bufferinstead of leaving it uninitialized.
No needfor "src" part
Quoted 20 lines
This fixes a 100% reproducible and very annoying bug I've found: Switch to gfxterm and until your clear the screen or scroll, the last position of every line has a random junk character in random foreground and background color. I believe the root cause is that the virtual_screen's
text_bufferis uninitialized; as the cursor reaches a new position, the uninitialized junk data is drawn to the screen. Really, the entire screen is junk, but it's never marked dirty so it's never drawn. So let's just clear out the wholetext_bufferwhen we set up the screen.(quoted diff) +0
-2-joe -=-=-=-=-=-=-=-=-=-=-=-=-term/gfxterm.c 2009-07-16 15:22:13.000000000 -0700 renamed from term/gfxterm.c 2009-07-07 16:58:06.000000000 -0700 +0
-0@@ -225,6 +225,17 @@grub_video_set_active_render_target
(GRUB_VIDEO_RENDER_TARGET_DISPLAY);
Quoted 14 lines
+ /* Clear out text buffer */
+ unsigned int i;
+ for(i = 0; i < virtual_screen.columns * virtual_screen.rows; i++)
+ {
+ virtual_screen.text_buffer[i].code = ' ';
+ virtual_screen.text_buffer[i].fg_color = virtual_screen.fg_color;
+ virtual_screen.text_buffer[i].bg_color = virtual_screen.bg_color;
+ virtual_screen.text_buffer[i].width = 0;
+ virtual_screen.text_buffer[i].index = 0;
+ }
+
returngrub_errno;
}
don't mix declarations and statements. Let 2 spaces before '{' and '}'. Other than this patch is good. Committed
Quoted 7 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 4 lines
Regards Vladimir 'phcoder' Serbinenko Personal git repository: http://repo.or.cz/w/grub2/phcoder.git