Tuning Graphics


During the installation, Ubuntu detects the graphics card and installs a usable driver. The detection is done using the ddcprobe and xresprobe commands. For example, to list all of the resolution information about my video card and monitor, I can use:

 $ sudo ddcprobe -? vbe: VESA 3.0 detected. oem: NVIDIA vendor: NVIDIA Corporation product: NV18 Board - p160nz Chip Rev A4 memory: 131072kb mode: 640x400x256 mode: 640x480x256 mode: 800x600x16 mode: 800x600x256 mode: 1024x768x16 ... $ sudo xresprobe any id: L1780U res: 1280x1024 1024x768 800x600 720x400 640x480 freq: 30-83 56-75 disptype: crt 
Note 

For xresprobe, you may also need to specify the type of driver. For example, sudo xre- sprobe ati works for the ATI driver. Other drivers include vesa, nvidia, nv, and i810.

These commands identify the video card and monitor. During the desktop install, they are used to identify the maximum resolution and to configure the /etc/X11/xorg.conf file.

Unfortunately, ddcprobe does not always know about your monitor, especially if you are using old equipment. If your graphics card supports 1280 × 1024 but your monitor supports only 1024 × 768, then you won't be able to see the display at 1280 × 1024. Unless you have a really old CRT monitor, your display probably supports 1024 × 768. Thus, this is usually the default resolution. To change the default resolution, use the System image from book Preferences image from book Screen Resolution applet (see Figure 9-1). From here, you can select the desired resolution and refresh rate. You can also choose to set new resolution for your login account or make it a system-wide change.

image from book
Figure 9-1: The Screen Resolution applet

Changing Screen Resolution (xrandr)

The System image from book Preferences image from book Screen Resolution applet does not list all of your available screen resolutions and settings. The full list of supported screen resolutions can be found with the X-Windows rotate and reflection command: xrandr. For example, to list the screen resolutions supported by the video driver, you would use:

 $ xrandr -q   SZ:    Pixels          Physical       Refresh *0   1280 x 1024    ( 342mm x 271mm )  *75   60   1   1024 x 768    ( 342mm x 271mm )   75   70   60   2    800 x 600    ( 342mm x 271mm )   75   72   60    56   3    640 x 480    ( 342mm x 271mm )   75   73   60   4   1280 x 960    ( 342mm x 271mm )   60   5   1280 x 800    ( 342mm x 271mm )   60   6   1152 x 864    ( 342mm x 271mm )   75   7   1280 x 768    ( 342mm x 271mm )   60   8    832 x 624    ( 342mm x 271mm )   75   9    640 x 512    ( 342mm x 271mm )   75   60   10   720 x 450    ( 342mm x 271mm )   60   11   640 x 400    ( 342mm x 271mm )   60   12   576 x 432    ( 342mm x 271mm )   75   13   640 x 384    ( 342mm x 271mm )   60   14   512 x 384    ( 342mm x 271mm )   75   70   60   15   416 x 312    ( 342mm x 271mm )   75   16   400 x 300    ( 342mm x 271mm )   75   72   60    56   17   320 x 240    ( 342mm x 271mm )   75   73   60 

In this example, my video driver supports 18 different screen resolutions, and up to 4 different refresh rates. These resolutions are not necessarily the same as the ones listed in /etc/X11/ xorg.conf (for X-Windows), and may not be supported by your monitor.

Warning 

Your video card, video driver, and monitor many not all support the same resolutions. The xrandr command shows your video driver resolutions and allows you to set a screen resolution that is not supported by your montior. This could damage your monitor and video card!

You can use xrandr to change resolutions by specifying one of the listed sizes. Using the example, you can set the screen to 1024 × 768 with any of these commands:

 xrandr -s 1               # screen size 1 is 1024x768 xrandr -s 1024x768        # specify by dimensions xrandr -s 1024x768 -r 70  # for 70 Hz (default listed is 75 Hz) xrandr -s 1 -r 70         # screen size 1 at 70 Hz 

Note 

If you specify an invalid screen resolution or refresh rate, then xrandr will fail with a cryptic error message. However, it won't make any screen changes.

Thinking Safety

When the Screen Resolution applet makes changes, it gives you 20 seconds to undo the change. This way, if the resolution is not supported and the display becomes dark or unreadable, then you just need to wait 20 seconds for it to switch back. Unfortunately, with xrandr, you do not have that luxury. The xrandr command will change the resolution immediately and it assumes you know what you are doing.

If you want to test a screen change with xrandr, use a small script (see Listing 9-1) to save the current resolution, change the screen, and then change back. If you like the resolution, you can press Ctrl+C to kill the script, or run xrandr without the test script to set the resolution.

Listing 9-1: Script to Test a Screen Resolution

image from book
 #!/bin/sh # Temporarily change resolutions (great for testing) # Example usage: ./testres -s 1   (to set to xrandr screen setting #1) # Save current resolution Resolution=`xrandr -q | grep '*' |  awk -F'*'             awk '{print $2 $3 $4}'` Rate=`xrandr -q | grep '*' |  awk -F'*' echo "Old: Resolution: $Resolution  Refresh rate: $Rate Hz" # Set the resolution using the command-line options. xrandr $* echo "New: `xrandr -q | grep '*'`" # Wait 20 seconds, then change back sleep 20 xrandr -s $Resolution -r $Rate echo "Switching back" echo "Current: `xrandr -q | grep '*'`" 
image from book

Flipping Cool!

Some video drivers support flipping the screen. If your video driver supports this, then you can use xrandr -x to flip the screen horizontally, making a mirror reflection. The xrandr -y command flips the screen vertically, and xrandr -x -y flips both. Similarly, the -o option can change the orientation from normal (-o normal) to rotated 90 degrees (-o right), 180 degrees (-o inverted), and 270 degrees (-o left).

However, not every video driver supports flipping and rotation. If your driver does not support these commands, then xrandr will give you a cryptic error message such as:

 X Error of failed request:  BadMatch (invalid parameter attributes)   Major opcode of failed request:  155 (RANDR)   Minor opcode of failed request:  2 (RRSetScreenConfig)   Serial number of failed request:  12   Current serial number in output stream:  12 

Practical Uses for xrandr

By now you're probably thinking, "xrandr is cool, but it has no long-term practical use." Most people set the display and that's it. However, sometimes there is a need to switch between display resolutions. For example, web designers may want to quickly switch screen resolutions to see what their web pages look like with different settings. This is important since not everyone uses 1280 × 1024. On the laptop that I use for presentations, I use xrandr to quickly change the display to something that will work with the overhead projector; I've seen too many conferences where people spend more time fighting with the projector rather than actually presenting. And for this book, I used a quick script (see Listing 9-2) to change the screen resolution, set the background, colors, etc. to match the publisher's guidelines for screen shots. This script ensures that every screen shot is taken the same way.

Listing 9-2: The setbg Script for Taking Hacking Ubuntu Screen Shots

image from book
 #!/bin/sh # Set background to white for a screenshot, then put it back. # Publisher requirements: #   - White background (so hide my background) #   - 1024x768 (so lower the resolution from my normal 1280x1024) # Wait for a key press, then put it all back. # Save current settings (background colors, settings, and image) RES=`gconftool-2 --get /desktop/gnome/screen/default/0/resolution` BG1=`gconftool-2 --get /desktop/gnome/background/primary_color` BG2=`gconftool-2 --get /desktop/gnome/background/secondary_color` BG=`gconftool-2 --get /desktop/gnome/background/draw_background` BGI=`gconftool-2 --get /desktop/gnome/background/picture_filename` # Set change xrandr -s 1024x768 gconftool-2 -t str --set /desktop/gnome/screen/default/0/resolution "1024x768" gconftool-2 -t str --set /desktop/gnome/background/primary_color "#ffffff" gconftool-2 -t str --set /desktop/gnome/background/secondary_color "#ffffff" gconftool-2 -t boolean --set /desktop/gnome/background/draw_background "False" gconftool-2 -t str --set /desktop/gnome/background/picture_filename "" # Wait echo "Use Control-Alt-D to hide all windows (and later restore)" read # Put it back xrandr -s 0  # this is my default resolution gconftool-2 -t str --set /desktop/gnome/screen/default/0/resolution "$RES" gconftool-2 -t str --set /desktop/gnome/background/primary_color "$BG1" gconftool-2 -t str --set /desktop/gnome/background/secondary_color "$BG2" gconftool-2 -t boolean --set /desktop/gnome/background/draw_background "$BG" gconftool-2 -t str --set /desktop/gnome/background/picture_filename "$BGI" 
image from book

Changing Video Drivers

X-Windows supports dozens of graphics cards. For a quick list, use apt-cache search video driver. Most of these video drivers are installed on the system during the default Ubuntu installation and are found in /usr/lib/xorg/modules/drivers/. The enabled graphic card is listed in the /etc/X11/xorg.conf file, under the "Device" section. For example:

 Section "Device"         Identifier      "ATI Technologies, Inc. Rage 128 RL/VR AGP"         Driver          "ati"         Option          "UseFBDev"              "true" EndSection 

This specifies the use of the ati driver found in /usr/lib/xorg/modules/drivers/ati_drv.so. If you want to change the driver, then you will need to change the xorg.conf configuration and restart the X-server.

Tip 

You can restart the X-server by either rebooting or pressing Ctrl+Alt+Backspace. Since this will kill all your X-Window applications, you should logout before restarting the server.

Warning 

If you install the wrong video driver, then X-Windows will fail to start. Be sure to make a backup of the xorg.conf file before making modifications. This way, if X-Windows breaks, then you will have a working configuration that you can put back.

Enabling OpenGL

The Open Graphics Library (OpenGL) provides a set of extensions for accelerated 2D and 3D rendering. Without this extension, some graphics must be explicitly drawn by each application, leading to slower graphic rendering.

Some video card drivers support OpenGL without any additional steps. For example, if you have an Intel, SiS, or Matrox video card, then OpenGL may already be supported and enabled. However, if you have an NVIDIA or ATI video card, then you will need to change drivers and install the accelerated graphics extensions.

To tell if you need to enable OpenGL, use the glxinfo command:

 $ glxinfo | grep "direct rendering" direct rendering: No 

If it says yes, then OpenGL is already enabled. However, if it says no, then either OpenGL is not supported, or you need to enable it.

  1. To enable OpenGL, make sure your video card is either NVIDIA or ATI. Use the lspci command to list your video cards. If the result does not say "nVidia" or "ATI" (in lowercase, uppercase, or mixed case), then you do not need these steps.

     $ lspci | grep -i -e Display -e VGA # on an iMac 0000:00:10.0 Display controller: ATI Technologies Inc Rage 128 RL/VR AGP $ lspci | grep -i -e Display -e VGA # on a PC 0000:01:00.0 VGA compatible controller: nVidia Corporation NV18 [GeForce4 MX 4000 AGP 8x] (rev c1) 

    Not every ATI and NVIDIA card is supported. Make sure the model listed by the lspci command matches a supported card:

    • ATI must be a 9xxx series, 9500 series (or higher), or have TV-out support. Your monitor must also support at least 60 Hz.

    • NVIDIA supports GeForce, nForce and Quadro models with AGP, TV-out, and flat panel displays.

    • NVIDIA supports older TNT, TNT2, and GeForce models with legacy drivers.

    Note 

    The two example lspci commands show an ATI Rage 128 video card in an iMac system that is not supported, and a NVIDIA GeForce4 MX 4000 card in a PC system with AGP that is supported.

  2. Back up your xorg.conf file. If anything does not work, you'll need this backup copy to return to a working display.

     sudo cp /etc/X11/xorg.conf /etc/X11/xorg.conf.bak 
  3. Regardless of your video card, you will need to install the restricted drivers for your kernel (if they are not already installed).

     sudo apt-get install linux-restricted-modules-`uname -r` 

At this point, you must perform some card-specific configurations.

If you have an ATI video card

  1. Install the ATI drivers:

     sudo apt-get install xorg-driver-fglrx fglrx-control 
  2. Run these commands to configure your xorg.conf file:

     sudo aticonfig --initial sudo aticonfig --overlay-type=Xv 
  3. Reconfigure the X-server:

     sudo dpkg-reconfigure xserver-xorg 

    This auto-detects your video card. Be sure to select fglrx and not ATI. For the remaining prompts (and there are a lot of prompts), you can just press enter and select the default values. (Since you're already running the X-server, the default values work.)

  4. Check your /etc/X11/xorg.conf settings and make sure the driver in the "Device" section says: Driver "fglrx".

  5. Restart your X-server. You can do this by rebooting or by logging out and then pressing Ctrl+Alt+Backspace.

If all goes well, then your display will start. Otherwise, you should be stuck at a text prompt- skip to the "Debugging X-Windows" section for resolving the problem.

If you have an NVIDIA card

  1. Install the NVIDIA drivers for the current or legacy card. Do not install both. (Actually, apt-get will not allow you to install both.)

     sudo apt-get install nvidia-glx nvidia-kernel-common 

    If you have a legacy card, use:

     sudo apt-get install nvidia-glx-legacy nvidia-kernel-common 
  2. If you previously made changes to your xorg.conf file, then make sure it is archived:

     md5sum /etc/X11/xorg.conf | sudo tee /var/lib/x11/xorg.conf 
    Note 

    While archiving xorg.conf is always a good thing, the NVIDIA configuration script will not continue if it is not archived.

  3. Configure the driver:

     sudo nvidia-glx-config enable 
  4. Edit xorg.conf and check the "Device" section. The driver should be nvidia and not nv. If it says nv, then change it to nvidia.

  5. When you are editing xorg.conf, add the following line to the "Device" section to disable the NVIDIA splash screen (and speed up the boot time):

     Option "NoLogo" "true" 

    The full Device section should look something similar to this example (although your video card model and BusID may be different):

     Section "Device"     Identifier  "NVIDIA Corporation NV18 [GeForce4 MX 4000 AGP 8x]"     Driver      "nvidia"     BusID       "PCI:1:0:0"     Option      "NoLogo"        "true" EndSection 

  6. Restart your X-server. You can do this by rebooting or by logging out and then pressing Ctrl+Alt+Backspace.

If all goes well, then your display will start. Otherwise, you should be stuck at a text prompt- skip to the next section, "Debugging X-Windows", for resolving the problem.

Debugging X-Windows

When X-Windows fails, it either drops you at a text prompt, or leaves the screen blank. In the worst case, you will need to reboot the computer in order to get to a text login prompt. The X- Windows system logs everything-including cryptic error messages-in /var/log/Xorg.0.log. Check the log for a place to start debugging. Fortunately, problems usually fall into one of four categories:

  1. Human error. Make sure you didn't type something wrong. The xorg.conf file is not very forgiving of typographical errors.

  2. Your card is not supported.

  3. You installed multiple, conflicting drivers.

  4. Your card was not recognized properly.

The first problem can be resolved by checking everything that you entered into the xorg.conf file. The other items are a little more complicated and are covered in the next subsections.

Putting Things Back

If your card is not supported or your changes were not correct, then put back your xorg.conf file. You should be able to run startx from the command line. This will start the graphics system and let you know if you put it back correctly.

Tip 

Hopefully you made a backup of /etc/X11/xorg.conf. If you didn't, then all is not lost. Some drivers make backups automatically when they install. Look in the /etc/X11/ directory for files like xorg.conf˜ and xorg.conf.backup. These are probably functional configuration files. In the worst case, you can run sudo dpkg-reconfigure xserver-xorg to generate a new configuration file.

Although startx is good for running the server and debugging the xorg.conf file, it runs the server from your text login. This means that logging out or shutting down from the graphical desktop will return you to your text command prompt; it will not actually log you out or reboot the system. To get the automatic login working, use:

 sudo /etc/init.d/gdm restart 

Debugging the Wrong Driver

Usually people will blindly install one driver and, if it does not work, then try the other. (Ok, I admit that I've done that.) If you're going to do this, be sure to remove the unused driver first; otherwise, neither driver will work.

  • To remove the ATI drivers, use:

     sudo apt-get remove xorg-driver-fglrx fglrx-control 
  • To unconfigure the NVIDIA drivers, use:

     sudo /usr/bin/nvidia-installer --uninstall sudo apt-get remove nvidia-glx        # for current cards sudo apt-get remove nvidia-glx-legacy # for legacy cards 
  • To copy back your xorg.conf file, use:

     sudo cp /etc/X11/xorg.conf.bak /etc/X11/xorg.conf 
  • Restart your X-Windows system by either rebooting or logging out and pressing Ctrl+Alt+Backspace.

Forcing Drivers to Install

For ATI, some cards are claimed to be unsupported even through they will work. For example, the Radeon Mobility 9600 (found in laptops) is reported as unsupported by the ATI drivers. You can change the PCI ID and try to fake the driver into thinking the card is supported. For example, the Radeon Mobility 9600 uses PCI ID 4e53 (found using the lspci -n command). You can add a line to the xorg.conf "Device" section to specify a supported ID (for example, 4e50-the Radeon 9600 M10-is supported and seems to be compatible with the 4e53). For example:

 Section "Device"   Identifier "ATI"   Driver     "fglrx"   ChipID     0x4e50   ... EndSection 

The full list of PCI IDs is found in /usr/share/misc/pci.ids. Vendors usually follow a consistent ID convention, so the 4e50, 4e51, 4e52, and 4e53 are all ATI Radeon cards. If one does not work, try another. However, forcing an ATI ID onto a non-ATI card (for example, Cirrus GD 5440) has virtually no chance of working.

Adjusting with xvidtune

Many newer computers come with flat LCD displays. This means the picture is usually centered. (And if it isn't, then there should be an auto or manual adjustment setting.) However, CRT monitors are not always centered. The desktop may appear slightly cut off at the top, bottom, left, or right. (In the case of some monitors, the desktop may be cut off by more than a little.) The xvidtune program allows you to adjust the screen width, height, and position by tuning the horizontal and vertical scan frequencies.

The xvidtune program does not actually perform the system changes (although it does allow you to test the settings). Instead, it generates code that can be inserted into /etc/X11/xorg.conf for adjusting the monitor automatically.

  1. Open a terminal and run the xvidtune program. This will display a warning about possible damage to your monitor (see Figure 9-2). Take this warning seriously, then smile, and click OK.

    image from book
    Figure 9-2: The xvidtune warning screen

    Note 

    You will need to run xvidtune from a terminal window (for example, Applications image from book Accessories image from book Terminal). This is because the final output from xvidtune will be printed in the terminal window.

  2. The xvidtune menu may not be pretty, but it is functional (see Figure 9-3). At the top of the window are the actual horizontal and vertical scan synchronization values used to denote the start of an analog video scan. I usually ignore these. The more important items are the buttons. These enable you to adjust the screen.

    image from book
    Figure 9-3: The xvidtune configuration settings

    The xvidtune adjustment options are:

    • Left, Right, Up, Down-These shift the screen's position.

    • Wider, Narrower, Shorter, Taller-These options adjust the screen's width and height.

    • Test-This temporarily applies the changes to the screen so you can see what it looks like.

    • Auto-Rather than making adjustments and clicking Test, you can click Auto to automatically apply the changes as you make them. These changes are not permanent, but they allow you to see what they will look like.

    • Restore-If you think you really screwed up, you can click this button to return to the current settings.

    • Show-This displays the current settings in the text console where you started running xvidtune.

    • Quit-This exits the program. You can also type q to quit.

  3. Make your adjustments. Use Test or Auto to view your changes.

    Tip 

    On some monitors, clicking Left or Right may really swing the display over to the side. Before making adjustments, move the xvidtune window into the middle of the screen. This way, it will not accidentally go out of view.

  4. After finding a good adjustment setting, click Show. The terminal window should display a line with your settings. It should look similar to:

     "1024x768"  78.80   1024 1040 1136 1304   768 769 772 796 +hsync +vsync 

    This line lists the resolution (in quotes) and the scan settings.

  5. Edit /etc/X11/xorg.conf and scroll down to the Monitor section. Add a ModeLine option that includes the output from xvidtune. For example, mine (including a very long line that wraps on the screen) looks like:

     Section "Monitor"         Identifier       "iMac"         Option           "DPMS"         HorizSync        60-60         VertRefresh      75-117         ModeLine         "1024x768"     78.80   1024 1040 1136 1308 768  769  772  796 +hsync +vsync EndSection 

  6. Save your changes, log out, and restart the X-server using Ctrl+Alt+Backspace.

Tip 

If you use multiple screen resolutions, then run xvidtune after changing each resolution. You can have multiple ModeLine entries in the xorg.conf file-as long as they all have different resolutions. Don't change screen resolutions while running xvidtune since it will not detect changes.

Improving Performance

When you have a slow display, everything else can seem to be slow. Much of this may be because the display is consuming CPU and memory resources. Fortunately, there are a few things you can do to improve the display's performance.

  • Install the accelerated drivers-The NVIDIA and ATI accelerated 3D drivers (mentioned in the Enabling OpenGL section) significantly improve performance. If you have the option to install either of these, then do it!

  • Disable the Nautilus background-Nautilus is used to place icons on the background (see Chapter 2). If this is disabled, then memory and CPU resources are freed up. Otherwise, Nautilus may need to redraw the background every time something on the screen changes. To disable it, use:

     gconftool-2 --type bool \   --set /apps/nautilus/preferences/show_desktop FALSE 
  • Disable Gnome background images-Drawing a background takes time and memory. If you don't need a background image, then turn it off. This can either be done by the background applet (System image from book Preferences image from book Desktop Background, select No Wallpaper) or with gconftool-2.

     gconftool-2 --type string \   --set /desktop/gnome/background/picture_options none 
  • Disable thumbnails-Nautilus can generate thumbnail icons and preview audio. If Nautilus opens a directory with lots of images in it, the overhead from creating thumbnails can be very noticeable (especially on slow systems). To disable previews, use:

     gconftool-2 --type string \   --set /apps/nautilus/preferences/show_image_thumbnails never 

    Tip 

    If you want some thumbnail icons, use local_only instead of never. This gives you icons in local folders, but disables it for networked file systems. This way, you don't need to wait for the network to transfer all of the images-an action required for making thumbnail images.

  • Disable icons in menus-By default, every menu items includes an icon. While these icons are cached, they can take time to load (especially on a slow system). You can disable the icons using:

     gconftool-2 --type bool \   --set /desktop/gnome/interface/menus_have_icons FALSE 

image from book
Accessibility

Not everyone optimizes the display for cool graphics and speed. People with sight disabilities can optimize the display for their own needs. By default, Ubuntu includes many themes for addressing accessibility. For example, under System image from book Preferences image from book Theme, you can select High Contrast Large Print, Low Contrast Large Print, Large Print, Low Contrast, and so on. Even without my glasses, I can read the screen using the High Contrast Large Print theme without being inches from the monitor.

For people who have little or no sight, the default Ubuntu installation supports Braille displays. This is done using brltty. The brltty driver supports many different Braille displays and input devices. You can start it by opening a terminal window and running sudo brltty.

After you connect your Braille terminal, you can use Orca to map specific events, such as window actions, to the Braille terminal.

  1. Install Orca using sudo apt-get install gnome-orca.

  2. Configure it in a terminal by running orca-setup. It will ask you questions such as:

     Use key echo? Enter y or n: 

    Orca supports some text-to-speech systems. If you have more than one speech server installed, it will ask you to select one of them.

  3. After it is configured, Orca will finish tuning Gnome and create a $HOME/.orca directory. You will need to log out and log back in for the changes to take affect.

  4. (Optional) You may also want to change the default init level in /etc/inittab from run-level 2 to run level 3.

     id:3:initdefault: 

    Run level 3 is intended for accessibility needs and automatically starts the Braille display. See Chapter 3 for modifying init scripts and the run level.

image from book



Hacking Ubuntu
Hacking Ubuntu: Serious Hacks Mods and Customizations (ExtremeTech)
ISBN: 047010872X
EAN: 2147483647
Year: 2004
Pages: 124
Authors: Neal Krawetz

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net