Created
January 31, 2012 07:29
-
-
Save anaisbetts/1709357 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static readonly string[] videoCardBlacklist = {"8086:0116"}; | |
static void DisableHwRenderingForCrapVideoCards() | |
{ | |
if (!String.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("MY_VIDEO_CARD_REALLY_WORKS"))) | |
{ | |
return; | |
} | |
int osVersion = Environment.OSVersion.Version.Major * 100 + Environment.OSVersion.Version.Minor; | |
if (osVersion < 601) | |
{ | |
log.Warn("Hardware acceleration is much more prolematic on OS's earlier than Vista"); | |
log.Warn("If you believe this isn't the case, set the MY_VIDEO_CARD_REALLY_WORKS environment variable"); | |
RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; | |
return; | |
} | |
var re = new Regex(@"VEN_([0-9A-Z]{4})&DEV_([0-9A-Z]{4})"); | |
var wmiSearch = new ManagementObjectSearcher("root\\cimv2", "SELECT * FROM win32_videocontroller"); | |
var items = wmiSearch.Get(); | |
foreach (var item in items) | |
{ | |
var val = (string)item.GetPropertyValue("PNPDeviceID"); | |
var m = re.Match(val); | |
if (!m.Success || m.Captures.Count != 3) continue; | |
var pnpId = String.Format("{0}:{1}", m.Groups[1].Value, m.Groups[2].Value); | |
if (videoCardBlacklist.Contains(pnpId)) | |
{ | |
log.Warn("Your video card is known to cause graphical glitches, so we have disabled hardware rendering"); | |
log.Warn("If you believe this isn't the case, set the MY_VIDEO_CARD_REALLY_WORKS environment variable"); | |
RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment