title: DirectX Firefox Plugin rendering artifacts
body: <blockquote>
    <p><strong>QUICK ANSWER</strong>: For those of you who reach this page via Google looking for
    a solution to the same problem, try
    this quick fix (suggested by Goz) -
    Add <strong>D3DCREATE_FPU_PRESERVE</strong> to the
    behavior flags on your CreateDevice()
    call. That cleared it up for me!</p>
  </blockquote>
  
  <p>I'm creating a DirectX 9-based NPAPI plugin. It seems to be working well in Chrome and Opera, but in Firefox I get strange rendering artifacts. Upon initializing DirectX (no rendering needs to be done for the artifact to appear) all or parts of the Firefox UI will turn black. Resizing the window (IE: Initiating a repaint) clears up the artifacts and the plugin seems to work properly at that point, but this is obviously not a desirable "feature". I have found that several others online have mentioned this issue, most claiming that it began with Firefox 3. Only <a href="http://www.nabble.com/Using-Direct3D9-in-FF3-Gecko1.9-plugin-ts19519493.html" rel="nofollow noreferrer">one post</a> mentions any solution being found, but the author doesn't seem to keen on divulging how.</p>
  
  <p>Is anyone familiar with this issue and a possible solution? From the linked post it would seem to be related to the way DX is initialized, but I've yet to find a combination that prevents the issue.</p>
  
  <p>This is the DX Initialization code I'm using (Error Handling removed for clarity):</p>
  
  <pre><code>RECT rc;
  GetClientRect(pluginHwnd, &amp;rc);
  
  D3DPRESENT_PARAMETERS d3d9PresentParams;
  ZeroMemory(&amp;d3d9PresentParams, sizeof(D3DPRESENT_PARAMETERS));    
  
  d3d9PresentParams.hDeviceWindow = pluginHwnd;
  d3d9PresentParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
  d3d9PresentParams.Flags = D3DPRESENTFLAG_DEVICECLIP; // Failed attempt to solve FF issue
  d3d9PresentParams.EnableAutoDepthStencil = FALSE; // No depth testing
  d3d9PresentParams.PresentationInterval = D3DPRESENT_INTERVAL_ONE; // Use Vsync
  
  d3d9PresentParams.MultiSampleType = D3DMULTISAMPLE_NONE; // Don't care about Multisampling
  d3d9PresentParams.MultiSampleQuality = 0;
  
  d3d9PresentParams.BackBufferCount = 1; 
  d3d9PresentParams.BackBufferWidth = rc.right - rc.left; 
  d3d9PresentParams.BackBufferHeight = rc.bottom - rc.top;  
  d3d9PresentParams.BackBufferFormat = D3DFMT_UNKNOWN; // Use the same color format as windows 
  
  d3d9PresentParams.Windowed = TRUE; // Explicitly windowed
  d3d9PresentParams.FullScreen_RefreshRateInHz = 0;
  
  d3d9-&gt;CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, pluginHwnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &amp;d3d9PresentParams, &amp;d3d9Device );
  </code></pre>