<div dir="ltr"><div>This behaviour is a result of an incompatibility between the Direct3D 9 API (DirectX SDK March 2009) and Cairo Graphics API (1.10.2).</div><div><br></div><div>The following mailing list thread from 2006-10-16 details how creating a Direct3D 9 device alters the FPU to single-precision mode, and that this version of the Cairo API assumed a higher level of precision when making its colour calculations:</div><div><br></div><div><a href="http://cairo.cairographics.narkive.com/L9XYWFkQ/cairo-direct3d-interaction-bug-and-fix-x86-fpu-precision">http://cairo.cairographics.narkive.com/L9XYWFkQ/cairo-direct3d-interaction-bug-and-fix-x86-fpu-precision</a></div><div><br></div><div>A fix for this bug was introduced immediately:</div><div><br></div><div><a href="https://bugs.freedesktop.org/show_bug.cgi?id=7497">https://bugs.freedesktop.org/show_bug.cgi?id=7497</a></div><div><br></div><div>Cairo v1.10.2 was released 2010-12-25, which postdates this fix by 4 years, but the erroneous behaviour is still present.</div><div><br></div><div>However, the fix must have made it into the Cairo code base at some point, as there is no evidence of the bug in Cairo v1.14.6, which can be downloaded from the HexChat project:</div><div><br></div><div><a href="https://github.com/hexchat/gtk-win32">https://github.com/hexchat/gtk-win32</a></div><div><br></div><div>A massive thank you to the mystery friend who used their search-fu to find the original thread concerning the Cairo bug.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 1 February 2017 at 18:12, Jeffrey Sheen <span dir="ltr"><<a href="mailto:jeffrey.sheen00@alumni.imperial.ac.uk" target="_blank">jeffrey.sheen00@alumni.imperial.ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span style="font-size:12.8px">After trying different VS 2015 Solution configurations (and abundant breakpointing), I have established that it is not the .EXE->.LIB->Cairo API call structure that is breaking Cairo surface rendering in my project.</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">The black test square can be rendered before, but not directly after, this D3D9 API call:</span><br style="font-size:12.8px"><br style="font-size:12.8px"><blockquote style="font-size:12.8px;margin:0px 0px 0px 40px;border:none;padding:0px">Direct3DCreate9(D3D_SDK_VERSIO<wbr>N)->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, WindowHandle, D3DCREATE_HARDWARE_VERTEXPROCE<wbr>SSING, &PresentParameters, &PDevice);<br><br></blockquote><span style="font-size:12.8px">N.B. The object parameters are as follows:</span><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div>WindowHandle<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">       </span>0x001b07f8 {unused=13111204 }<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">      </span>HWND__ *</div><div><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">            </span>unused<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">     </span>13111204<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">   </span>int</div></div><div><br></div><div><div>PresentParameters<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>{BackBufferWidth=0 BackBufferHeight=0 BackBufferFormat=D3DFMT_UNKNOW<wbr>N (0) ...}<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">  </span>_D3DPRESENT_PARAMETERS_</div><div><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">             </span>BackBufferWidth<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">    </span>0<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">  </span>unsigned int</div><div><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>BackBufferHeight<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">   </span>0<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">  </span>unsigned int</div><div><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>BackBufferFormat<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">   </span>D3DFMT_UNKNOWN (0)<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>_D3DFORMAT</div><div><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">          </span>BackBufferCount<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">    </span>1<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">  </span>unsigned int</div><div><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>MultiSampleType<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">    </span>D3DMULTISAMPLE_NONE (0)<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">    </span>_D3DMULTISAMPLE_TYPE</div><div><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>MultiSampleQuality<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>0<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">  </span>unsigned long</div><div><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">               </span>SwapEffect<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>D3DSWAPEFFECT_DISCARD (1)<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">  </span>_D3DSWAPEFFECT</div><div>+<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">             </span>hDeviceWindow<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">      </span>0x001b07f8 {unused=13111204 }<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">      </span>HWND__ *</div><div><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">            </span>Windowed<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">   </span>1<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">  </span>int</div><div><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">         </span>EnableAutoDepthStencil<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">     </span>0<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">  </span>int</div><div><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">         </span>AutoDepthStencilFormat<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">     </span>D3DFMT_UNKNOWN (0)<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>_D3DFORMAT</div><div><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">          </span>Flags<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">      </span>1<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">  </span>unsigned long</div><div><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">               </span>FullScreen_RefreshRateInHz<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>0<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">  </span>unsigned int</div><div><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">                </span>PresentationInterval<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">       </span>0<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">  </span>unsigned int</div></div><div><br></div><div><div>PDevice<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>0x00000000 <NULL><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">    </span>IDirect3DDevice9 *</div><div>+<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">         </span>IUnknown<span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">   </span><struct at NULL><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">     </span>IUnknown</div></div><div><br></div></blockquote>As a reminder, the code for rendering the black test square is as below, and the status of each Cairo API call returns "no error has occurred":<br></div><div style="font-size:12.8px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><br></div><div>cairo_surface_t *surface;</div></blockquote><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">  </span>cairo_t *cr;<br><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">     </span>cairo_status_t status;<span class=""><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-im"><br><span style="white-space:pre-wrap">        </span><br><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>surface = cairo_image_surface_create(CAI<wbr>RO_FORMAT_ARGB32, 390, 60);<br><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">   </span></span></span>status = cairo_surface_status(surface);<br><br><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">      </span>cr = cairo_create(surface);<br><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">      </span>status = cairo_status(cr);<span class=""><br><br><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">      </span>cairo_set_source_rgba(cr, 0, 0, 0, 1);<br><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">   </span></span>status = cairo_status(cr);<br><br><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>cairo_rectangle(cr, 175, 10, 40, 40);<br><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">    </span>status = cairo_status(cr);<br><br><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">     </span>cairo_fill(cr);<br><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">  </span>status = cairo_status(cr);<br><br><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">     </span>cairo_surface_flush(surface);<br><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">    </span>status = cairo_surface_write_to_png(sur<wbr>face, "f:\\cairo_test_pos_lib_member<wbr>_function.png");<br><br><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">    </span>cairo_destroy(cr);<br><div><span class="m_-5504820426978967894gmail-m_-5951130960844852703gmail-m_-3510321035837171654gmail-Apple-tab-span" style="white-space:pre-wrap">    </span>cairo_surface_destroy(surface)<wbr>;</div></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Can anyone suggest how to proceed from here?<br><br><span style="font-size:12.8px">N.B. I have removed the original Stack Overflow question, and created a new question with this new information:</span><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><a href="http://stackoverflow.com/questions/41986105/idirect3d9createdevice-prevents-gtk-2-cairo-rendering" target="_blank">http://stackoverflow.com/quest<wbr>ions/41986105/idirect3d9create<wbr>device-prevents-gtk-2-cairo-<wbr>rendering</a></div></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Cheers,</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Jeff.</div><div><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On 24 January 2017 at 00:37,  <span dir="ltr"><<a href="mailto:fanc999@yahoo.com.tw" target="_blank">fanc999@yahoo.com.tw</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="ZH-TW"><div class="m_-5504820426978967894gmail-m_-5951130960844852703m_-6283766736287525577WordSection1"><p class="MsoNormal"><span lang="EN-US">Hi Jeff,</span></p><p class="MsoNormal"><span lang="EN-US">(sorry it the formatting does not look nice—I am replying on my phone)</span></p><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US">Only add the .lib’s to the “additional dependencies” to the .exe/.dll that will built in your project, not the static lib’s.  This should removed the warnings.</span></p><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US">Hope this helps.</span></p><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US">With blessings, and cheers!</span></p><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:pmingliu">從</span><span lang="EN-US"> Windows 10 </span><span style="font-family:pmingliu">手機傳送</span><span lang="EN-US"><u></u><u></u></span></p><span><div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(225,225,225);padding:3pt 0cm 0cm"><p class="MsoNormal" style="border:none;padding:0cm"><span lang="EN-US" style="font-family:pmingliu"> I have the same GTK-related parameters in both VS projects' settings (as per <a href="http://stackoverflow.com/questions/15906580/how-to-configure-gtk-on-visual-studio-2010" target="_blank">http://stackoverflow.com/quest<wbr>ions/15906580/how-to-configure<wbr>-gtk-on-visual-studio-2010</a>).</span><span lang="EN-US"><u></u><u></u></span></p></div><div><div><p class="MsoNormal"><span lang="EN-US" style="font-family:pmingliu"><u></u> <u></u></span></p></div><div><p class="MsoNormal" style="margin-bottom:12pt"><span lang="EN-US" style="font-family:pmingliu">The only difference in output when building each is that I get a dozen linker warnings for my main project, all of the form:<u></u><u></u></span></p><blockquote style="margin-left:30pt;margin-right:0cm"><div><div><p class="MsoNormal"><span lang="EN-US" style="font-family:pmingliu">1>gdk-win32-2.0.lib(libgdk-win<wbr>32-2.0-0.dll) : warning LNK4006: __NULL_IMPORT_DESCRIPTOR already defined in gtk-win32-2.0.lib(libgtk-win32<wbr>-2.0-0.dll); second definition ignored<u></u><u></u></span></p></div><div><p class="MsoNormal" style="margin-bottom:12pt"><span lang="EN-US" style="font-family:pmingliu">1>gdk-win32-2.0.lib(libgdk-win<wbr>32-2.0-0.dll) : warning LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library<u></u><u></u></span></p></div></div></blockquote><p class="MsoNormal"><span lang="EN-US" style="font-family:pmingliu">I'd appreciate any advice.<u></u><u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US" style="font-family:pmingliu"><u></u> <u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US" style="font-family:pmingliu">Jeff.<u></u><u></u></span></p></div></div><p class="MsoNormal"><span lang="EN-US" style="font-family:pmingliu"><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:11pt"><u></u> <u></u></span></p></span></div></div></blockquote></div><br></div></div></div></div>
</blockquote></div><br></div>