I have been working on getting our new Mac Mini (macmini4,1) machines ready to become Mac OS X 10.6 testing machines. One of the last things needed before I start testing on a larger scale is a program to set the resolution on the command line. We need this because our tests depend on having a specific resolution set. Even if there was no dependency on a specific resolution, the GPU could perform differently depending on the size of the display it is working on. As well, we run these minis without a real display so its really important that we have active confirmation that the desired resolution is set.
Previously, we used cscreen. This is a utility that has fallen off the internet and was only ever released as a PowerPC binary. I needed to decide between finding a replacement for cscreen and installing Rosetta. While we currently have Rosetta on our testing slaves, I didn’t want us to depend on this. This is because partly because I just don’t think its good hygiene and partly because I want to prepare for OS X 10.7, where Rosetta has been removed. I searched the internet for a tool to do this, and sadly, there was nothing that fit the bill. I tried alternatives like modifying the com.apple.Boot.plist file to specify resolution, but it didn’t work. I also found some binary plist files that I could have edited and might have worked, but it seemed like a really flaky solution that would break *all* *the* *time*. I decided that I’d have to write something to do this.
I did find a program that looked like it would be a good starting point, however, this program lacked any error checking. Furthermore, when I investigated the APIs used, it looked like many of the important APIs were deprecated in 10.6 and would not be available in 10.7. One particularly annoying deprecation was CGDisplayBestModeForParameters, because it takes the exact data I have (height, width and bit depth) and picked the best mode available. In the end, I think I have a better solution that iterates through all modes and picks one that matches my inputs exactly. I also noticed that CGDisplayBestModeForParameters doesn’t always return a mode that matches exactly to what was requestion, though, it does have facilities to deal with this case.
Alas, I started writing an application called screenresolution. This program can be used to query the current and available resolutions as well as setting the resolution on one or more screens attached to the system. This is my first C project in quite some time and I was never a C rockstar to begin with. If you have a desire for Mozilla testing infrastructure to not suck and know C and CoreGraphics please slide on over to the source to check for issues! I know that I could organize the code better and write a better command line interface, but I don’t think the benefits of that outweigh the cost of waiting even longer for these new machines.
I have posted thecode on my github account and have licensed it with the GPL v2 license in hopes that no one ever go through the search engine hell that was Friday Aug 26, 2011. Below is a build of verison 1.3. Why not 1.0? Even though I wrote a test for the program, I neglected to actually run it. Multiple times
Once I started to actually run the tests, I started finding issues before bumping version numbers, gasp!
Update: Thanks Josh Aas and Richard Newman for reviewing my code and the great suggestions! I have a new version posted
screenresolution-1.4.dmg
Because this is a command line application, I recorded a video of my machine running the test suite.
