Jump to content

  • Log In with Google      Sign In   
  • Create Account

Shawn Hargreaves' Blog



Win2D / ANGLE team engineering process

  Posted by , 04 September 2015 - - - - - - · 205 views

<p>Attached to the wall outside my office:</p>
<p>&nbsp;</p>
<p><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/2148.WP_5F00_20150904_5F00_006.jpg"><img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/2148.WP_5F00_20150904_5F00_006.jpg" alt="" width="576" height="1024" /></a></p><div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10639774" width="1" height="1">

Source


Win2D / ANGLE team engineering process

  Posted by , 04 September 2015 - - - - - - · 54 views

<p>Attached to the wall outside my office:
<p>&nbsp;</p>
<p><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/2148.WP_5F00_20150904_5F00_006.jpg"><img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/2148.WP_5F00_20150904_5F00_006.jpg" alt="" width="576" height="1024"></a></p></p>


<a href="https://blogs.msdn.microsoft.com/shawnhar/2015/09/04/win2d-angle-team-engineering-process/" class='bbc_url' rel='nofollow external'>Source</a>




Channel 9 - OpenGLES on Windows with ANGLE

  Posted by , 26 August 2015 - - - - - - · 273 views

<p><a href="https://channel9.msdn.com/Shows/C9-GoingNative/Going-Native-41-OpenGLES-on-Windows-with-ANGLE">My colleague Cooper is on Channel 9 today</a>.</p><div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10637661" width="1" height="1">

Source



Stuart: Shawn's Terrific Universal App for photogRaph Tweaking

  Posted by , 07 August 2015 - - - - - - · 233 views

<p>Stuart is a contrivedly acronymed Windows 10 photo editing app which I wrote during a recent <a href="http://blogs.msdn.com/b/win2d/archive/2015/08/05/win2d-app-building-samples.aspx">Win2D app building exercise</a>.&nbsp; I&rsquo;m posting it here because I&rsquo;m pleased with how it turned out.&nbsp; XAML + Win2D makes it really easy to do this sort of thing!</p>
<p>&nbsp;</p>
<h2>Where to get it</h2>
<ul>
<li><a href="https://www.microsoft.com/store/apps/9NBLGGH1XSQK">Download from the Store</a></li>
<li><a href="https://github.com/shawnhar/stuart">Or clone the source from github</a></li>
</ul>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<h2>Features</h2>
<ul>
<li>Use a rich set of image effects to tweak your photos</li>
<li>Apply effects to the whole image or just selected parts of it</li>
<li>Feather selected regions for smooth transitions</li>
<li>Runs on Windows 10 PCs and phones</li>
</ul>
<p>&nbsp;</p>
<h2>Screenshots</h2>
<p>Starting with this photo from a dawn hike on Mount Rainier:</p>
<p><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/5428.original.jpg"><img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/5428.original.jpg" alt="" border="0" /></a>&nbsp;</p>
<p>&nbsp;</p>
<p>Stuart can make the colors more intense:</p>
<p>&nbsp;<a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/8875.adjusted.jpg"><img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/8875.adjusted.jpg" alt="" border="0" /></a></p>
<p>&nbsp;</p>
<p>Or brighten the foreground rocks and trees without changing the sky:</p>
<p>&nbsp;<a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/0245.regionEdit.jpg"><img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/0245.regionEdit.jpg" alt="" border="0" /></a></p>
<p>&nbsp;</p>
<p>Or we can go retro:</p>
<p>&nbsp;<a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/6266.retro.jpg"><img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/6266.retro.jpg" alt="" border="0" /></a></p>
<p>&nbsp;</p>
<p>Or completely stylized:</p>
<p>&nbsp;<a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/3771.stylize.jpg"><img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/3771.stylize.jpg" alt="" border="0" /></a></p><div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10633838" width="1" height="1">

Source


Stuart: Shawn’s Terrific Universal App for photogRaph Tweaking

  Posted by , 07 August 2015 - - - - - - · 41 views

<p>Stuart is a contrivedly acronymed Windows 10 photo editing app which I wrote during a recent <a href="http://blogs.msdn.com/b/win2d/archive/2015/08/05/win2d-app-building-samples.aspx">Win2D app building exercise</a>.&nbsp; I&rsquo;m posting it here because I&rsquo;m pleased with how it turned out.&nbsp; XAML + Win2D makes it really easy to do this sort of thing!
<p>&nbsp;</p>
<h2>Where to get it</h2>
<ul>
<li><a href="https://www.microsoft.com/store/apps/9NBLGGH1XSQK">Download from the Store</a></li>
<li><a href="https://github.com/shawnhar/stuart">Or clone the source from github</a></li>
</ul>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<h2>Features</h2>
<ul>
<li>Use a rich set of image effects to tweak your photos</li>
<li>Apply effects to the whole image or just selected parts of it</li>
<li>Feather selected regions for smooth transitions</li>
<li>Runs on Windows 10 PCs and phones</li>
</ul>
<p>&nbsp;</p>
<h2>Screenshots</h2>
<p>Starting with this photo from a dawn hike on Mount Rainier:</p>
<p><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/5428.original.jpg"><img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/5428.original.jpg" alt="" border="0"></a>&nbsp;</p>
<p>&nbsp;</p>
<p>Stuart can make the colors more intense:</p>
<p>&nbsp;<a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/8875.adjusted.jpg"><img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/8875.adjusted.jpg" alt="" border="0"></a></p>
<p>&nbsp;</p>
<p>Or brighten the foreground rocks and trees without changing the sky:</p>
<p>&nbsp;<a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/0245.regionEdit.jpg"><img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/0245.regionEdit.jpg" alt="" border="0"></a></p>
<p>&nbsp;</p>
<p>Or we can go retro:</p>
<p>&nbsp;<a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/6266.retro.jpg"><img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/6266.retro.jpg" alt="" border="0"></a></p>
<p>&nbsp;</p>
<p>Or completely stylized:</p>
<p>&nbsp;<a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/3771.stylize.jpg"><img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/3771.stylize.jpg" alt="" border="0"></a></p></p>


<a href="https://blogs.msdn.microsoft.com/shawnhar/2015/08/07/stuart-shawns-terrific-universal-app-for-photograph-tweaking/" class='bbc_url' rel='nofollow external'>Source</a>




Visual Studio template for cross-platform OpenGL development

  Posted by , 29 July 2015 - - - - - - · 349 views

<p>Today the Visual Studio team shipped a project template for <a href="https://visualstudiogallery.msdn.microsoft.com/61b15204-e6ae-4f9a-a59a-b3d916e1bb3f">cross-platform graphics development</a>.&nbsp; This uses the Visual Studio shared project mechanism to target the Windows Universal Platform, Android, and iOS, with identical OpenGL ES 2.0 rendering code shared across all three platforms.</p>
<p>I'm posting this here partly because I think it is cool, but more importantly because I had a hand in making it happen.&nbsp; In order to run portable GL rendering code on Windows, this template uses a <a href="https://github.com/MSOpenTech/angle">version of ANGLE that is maintained by my team</a>.&nbsp; When you compile it for Windows, Visual Studio will automatically pull down our <a href="https://www.nuget.org/packages/ANGLE.WindowsStore">ANGLE binaries from NuGet</a>.</p>
<p>&nbsp;</p>
<p>The Visual Studio project looks like so:</p>
<p>&nbsp;<a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/7356.SimpleRenderer_2D00_ClassView_5B00_1_5D00_.png"><img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/7356.SimpleRenderer_2D00_ClassView_5B00_1_5D00_.png" alt="" width="352" height="275" /></a></p>
<p>&nbsp;</p>
<p>Let's be honest, this is not the most visually exciting graphics demo ever :-)&nbsp; But hey, just insert some different draw calls, different GLSL shaders, different vertices, maybe a few textures, and you could make it draw something far more interesting!</p>
<p><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/7457.Cube_2D00_Windows_5B00_1_5D00_.png"><img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/7457.Cube_2D00_Windows_5B00_1_5D00_.png" alt="" width="515" height="885" /></a></p><div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10631653" width="1" height="1">

Source


Visual Studio template for cross-platform OpenGL development

  Posted by , 29 July 2015 - - - - - - · 22 views

<p>Today the Visual Studio team shipped a project template for <a href="https://visualstudiogallery.msdn.microsoft.com/61b15204-e6ae-4f9a-a59a-b3d916e1bb3f">cross-platform graphics development</a>.&nbsp; This uses the Visual Studio shared project mechanism to target the Windows Universal Platform, Android, and iOS, with identical OpenGL ES 2.0 rendering code shared across all three platforms.</p>
<p>I’m posting this here partly because I think it is cool, but more importantly because I had a hand in making it happen.&nbsp; In order to run portable GL rendering code on Windows, this template uses a <a href="https://github.com/MSOpenTech/angle">version of ANGLE that is maintained by my team</a>.&nbsp; When you compile it for Windows, Visual Studio will automatically pull down our <a href="https://www.nuget.org/packages/ANGLE.WindowsStore">ANGLE binaries from NuGet</a>.</p>
<p>&nbsp;</p>
<p>The Visual Studio project looks like so:</p>
<p>&nbsp;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/70/20/7356.SimpleRenderer-ClassView[1].png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/7356.SimpleRenderer_2D00_ClassView_5B00_1_5D00_.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/70/20/7356.SimpleRenderer-ClassView[1].png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/7356.SimpleRenderer_2D00_ClassView_5B00_1_5D00_.png" alt="" width="352" height="275"></a></p>
<p>&nbsp;</p>
<p>Let’s be honest, this is not the most visually exciting graphics demo ever <img src="https://blogs.msdn.microsoft.com/shawnhar/wp-includes/images/smilies/icon_smile.gif" alt=":-)" class="wp-smiley" />&nbsp; But hey, just insert some different draw calls, different GLSL shaders, different vertices, maybe a few textures, and you could make it draw something far more interesting!</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/70/20/7457.Cube-Windows[1].png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/7457.Cube_2D00_Windows_5B00_1_5D00_.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/70/20/7457.Cube-Windows[1].png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/7457.Cube_2D00_Windows_5B00_1_5D00_.png" alt="" width="515" height="885"></a></p>


<a href="https://blogs.msdn.microsoft.com/shawnhar/2015/07/29/visual-studio-template-for-cross-platform-opengl-development/" class='bbc_url' rel='nofollow external'>Source</a>




WRL implementations of IVector and IAsyncOperation

  Posted by , 10 November 2014 - - - - - - · 638 views

<p><em>tl; dr</em></p> <p>If you are developing your own Windows Runtime component using WRL, you might be interested in borrowing these implementations of standard interfaces:</p> <ul> <li><a title="https://github.com/Microsoft/Win2D/blob/master/winrt/inc/Vector.h" href="https://github.com/Microsoft/Win2D/blob/master/winrt/inc/Vector.h">https://github.com/Microsoft/Win2D/blob/master/winrt/inc/Vector.h</a> </li> <li><a title="https://github.com/Microsoft/Win2D/blob/master/winrt/inc/AsyncOperation.h" href="https://github.com/Microsoft/Win2D/blob/master/winrt/inc/AsyncOperation.h">https://github.com/Microsoft/Win2D/blob/master/winrt/inc/AsyncOperation.h</a> </li> </ul> <p><em></em></p> <p><em>More detail:</em></p> <p>Windows Runtime components can be implemented using .NET, C++/CX, or standard C++ with <a href="http://msdn.microsoft.com/en-us/library/hh438466.aspx" target="_blank">WRL</a>. We chose WRL for the <a href="https://github.com/Microsoft/Win2D" target="_blank">Win2D project</a>, because it’s the lowest level option and gives the most control over every detail of the implementation. Of course, this also means it is the hardest to work with and requires us to do the most work!</p> <p>The Windows Runtime defines standard interfaces representing collections (<a href="http://msdn.microsoft.com/en-us/library/windows/apps/br206631.aspx" target="_blank">IVector</a>) and asynchronous computations (<a href="http://msdn.microsoft.com/en-us/library/windows/apps/br206598.aspx" target="_blank">IAsyncOperation</a>). Both .NET and C++/CX provide rich language projections on top of these interfaces, mapping them to specialized APIs that make it easy to create and consume them. WRL, not so much :-)</p> <p>We looked around for existing WRL vector and async implementations that we could use in Win2D, but could not find anything that met all our requirements (complete, robust, well tested, under a suitable open source license, and not too badly tangled up with other code). So we rolled our own. Each interface is implemented in a single header with no dependencies on the rest of Win2D, so we hope these will prove suitable for anyone else who finds themselves needing the same thing in future.</p> <p> </p> <h3><a href="https://github.com/Microsoft/Win2D/blob/master/winrt/inc/Vector.h" target="_blank">Vector.h</a></h3> <p>This header provides the class Vector&lt;T&gt;, which implements the Windows Runtime interfaces <a href="http://msdn.microsoft.com/en-us/library/windows/apps/br206631.aspx" target="_blank">IVector&lt;T&gt;</a>, <a href="http://msdn.microsoft.com/en-us/library/windows/apps/br226058.aspx" target="_blank">IVectorView&lt;T&gt;</a>, <a href="http://msdn.microsoft.com/en-us/library/windows/apps/br226024.aspx" target="_blank">IIterable&lt;T&gt;</a>, and <a href="http://msdn.microsoft.com/en-us/library/windows/apps/br226026.aspx" target="_blank">IIterator&lt;T&gt;</a>. The vector can be fixed size or dynamically resizable, and tracks a dirty flag so you can efficiently check if its contents have changed. T may be any value type, interface, or runtime class, but strings are not currently supported.</p> <p>Usage example (error handling skipped for brevity):</p> <pre class="csharpcode"> <font color="#9b00d3">IFACEMETHODIMP</font> CreateVectorOfInts(<font color="#4f81bd">IVector</font>&lt;<span class="kwrd">int</span>&gt;** <font color="#a5a5a5">returnValue</font>)
{
<font color="#4f81bd">ComPtr</font>&lt;<font color="#4f81bd">Vector</font>&lt;<span class="kwrd">int</span>&gt;&gt; v = Make&lt;<font color="#4f81bd">Vector</font>&lt;<span class="kwrd">int</span>&gt;&gt;(initialSize, isFixedSize);

<span class="rem">// Access the vector using Windows Runtime interface methods.</span>
v-&gt;Append(42);
v-&gt;InsertAt(0, 23);

<span class="rem">// Internally to your implementation module, it is also possible</span>
<span class="rem">// to get direct access to the underlying STL collection.</span>
std::<font color="#4f81bd">vector</font>&lt;<span class="kwrd">int</span>&gt;&amp; raw = v-&gt;InternalVector();
std::sort(raw.begin(), raw.end());

v.CopyTo(<font color="#a5a5a5">returnValue</font>);<br /> <font color="#0000ff">return </font>S_OK;
}</pre>


<p> </p>

<h3><a href="https://github.com/Microsoft/Win2D/blob/master/winrt/inc/AsyncOperation.h" target="_blank">AsyncOperation.h</a></h3>

<p>This header provides the classes AsyncOperation&lt;T&gt; and AsyncAction, which implement the Windows Runtime interfaces <a href="http://msdn.microsoft.com/en-us/library/windows/apps/br206598.aspx" target="_blank">IAsyncOperation&lt;T*&gt;</a> and <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.foundation.iasyncaction.aspx" target="_blank">IAsyncAction</a> respectively. It runs arbitrary code on the system threadpool, and reports the result or error status through standard async interfaces. It is also possible to register one async operation to run as the continuation of another.</p>

<p>Example (error handling skipped for brevity) which uses an asynchronous thread pool task to add two integers:</p>

<pre class="csharpcode"> <font color="#9b00d3">IFACEMETHODIMP</font> AddAsync(<span class="kwrd">int</span> a, <span class="kwrd">int</span> b, <font color="#4f81bd">IAsyncOperation</font>&lt;<span class="kwrd">int</span>&gt;** <font color="#a5a5a5">returnValue</font>)
{
<font color="#0000ff">auto</font> asyncOperation = Make&lt;<font color="#4f81bd">AsyncOperation</font>&lt;<span class="kwrd">int</span>&gt;&gt;([=]
{
<span class="kwrd">return</span> a + b;
});

asyncOperation.CopyTo(<font color="#a5a5a5">returnValue</font>);
<font color="#0000ff"> return </font>S_OK; <br /> }</pre>

<p>Even sillier example, which runs an asynchronous multiply task as the continuation of an asynchronous addition:</p>

<pre class="csharpcode"> <font color="#9b00d3">IFACEMETHODIMP</font> AddAndThenMultiplyAsync(<span class="kwrd">int</span> a, <span class="kwrd">int</span> b, <span class="kwrd">int</span> c, IAsyncOperation&lt;<span class="kwrd">int</span>&gt;** <font color="#a5a5a5">returnValue</font>)
{
<span class="rem">// Start the first asynchronous computation.<br /> // This computes a + b.</span>
<font color="#4f81bd">ComPtr</font>&lt;<font color="#4f81bd">IAsyncOperation</font>&lt;<span class="kwrd">int</span>&gt;&gt; addOperation;
AddAsync(<font color="#a5a5a5">a</font>, <font color="#a5a5a5">b</font>, &amp;addOperation);

<span class="rem">// Register a second asynchronous computation to run as the continuation of the first.<br /> // This computes &lt;previous async result&gt; * c.</span>
<font color="#0000ff">auto</font> multiplyOperation = Make&lt;<font color="#4f81bd">AsyncOperation</font>&lt;<span class="kwrd">int</span>&gt;&gt;(addOperation, [=]
{
<span class="kwrd">int</span> addResult;
addOperation-&gt;GetResults(&amp;addResult);
<span class="kwrd">return</span> addResult * c;
});

multiplyOperation.CopyTo(<font color="#a5a5a5">returnValue</font>);<br /> <font color="#0000ff">return </font>S_OK;
}</pre>
<div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10571125" width="1" height="1">

Source


WRL implementations of IVector and IAsyncOperation

  Posted by , 10 November 2014 - - - - - - · 28 views

<p><em>tl; dr</em>
<p>If you are developing your own Windows Runtime component using WRL, you might be interested in borrowing these implementations of standard interfaces:</p>
<ul>
<li><a title="https://github.com/Microsoft/Win2D/blob/master/winrt/inc/Vector.h" href="https://github.com/Microsoft/Win2D/blob/master/winrt/inc/Vector.h">https://github.com/Microsoft/Win2D/blob/master/winrt/inc/Vector.h</a> </li>
<li><a title="https://github.com/Microsoft/Win2D/blob/master/winrt/inc/AsyncOperation.h" href="https://github.com/Microsoft/Win2D/blob/master/winrt/inc/AsyncOperation.h">https://github.com/Microsoft/Win2D/blob/master/winrt/inc/AsyncOperation.h</a> </li>
</ul>
<p><em></em></p>
<p><em>More detail:</em></p>
<p>Windows Runtime components can be implemented using .NET, C++/CX, or standard C++ with <a href="http://msdn.microsoft.com/en-us/library/hh438466.aspx" target="_blank">WRL</a>.&nbsp; We chose WRL for the <a href="https://github.com/Microsoft/Win2D" target="_blank">Win2D project</a>, because it&rsquo;s the lowest level option and gives the most control over every detail of the implementation.&nbsp; Of course, this also means it is the hardest to work with and requires us to do the most work!</p>
<p>The Windows Runtime defines standard interfaces representing collections (<a href="http://msdn.microsoft.com/en-us/library/windows/apps/br206631.aspx" target="_blank">IVector</a>) and asynchronous computations (<a href="http://msdn.microsoft.com/en-us/library/windows/apps/br206598.aspx" target="_blank">IAsyncOperation</a>).&nbsp; Both .NET and C++/CX provide rich language projections on top of these interfaces, mapping them to specialized APIs that make it easy to create and consume them.&nbsp; WRL, not so much <img src="https://blogs.msdn.microsoft.com/shawnhar/wp-includes/images/smilies/icon_smile.gif" alt=":-)" class="wp-smiley" /></p>
<p>We looked around for existing WRL vector and async implementations that we could use in Win2D, but could not find anything that met all our requirements&nbsp; (complete, robust, well tested, under a suitable open source license, and not too badly tangled up with other code).&nbsp; So we rolled our own.&nbsp; Each interface is implemented in a single header with no dependencies on the rest of Win2D, so we hope these will prove suitable for anyone else who finds themselves needing the same thing in future.</p>
<p>&nbsp;</p>
<h3><a href="https://github.com/Microsoft/Win2D/blob/master/winrt/inc/Vector.h" target="_blank">Vector.h</a></h3>
<p>This header provides the class Vector&lt;T&gt;, which implements the Windows Runtime interfaces <a href="http://msdn.microsoft.com/en-us/library/windows/apps/br206631.aspx" target="_blank">IVector&lt;T&gt;</a>, <a href="http://msdn.microsoft.com/en-us/library/windows/apps/br226058.aspx" target="_blank">IVectorView&lt;T&gt;</a>, <a href="http://msdn.microsoft.com/en-us/library/windows/apps/br226024.aspx" target="_blank">IIterable&lt;T&gt;</a>, and <a href="http://msdn.microsoft.com/en-us/library/windows/apps/br226026.aspx" target="_blank">IIterator&lt;T&gt;</a>.&nbsp; The vector can be fixed size or dynamically resizable, and tracks a dirty flag so you can efficiently check if its contents have changed.&nbsp; T may be any value type, interface, or runtime class, but strings are not currently supported.</p>
<p>Usage example (error handling skipped for brevity):</p>
<pre class="csharpcode"> <font color="#9b00d3">IFACEMETHODIMP</font> CreateVectorOfInts(<font color="#4f81bd">IVector</font>&lt;<span class="kwrd">int</span>&gt;** <font color="#a5a5a5">returnValue</font>)
{
<font color="#4f81bd">ComPtr</font>&lt;<font color="#4f81bd">Vector</font>&lt;<span class="kwrd">int</span>&gt;&gt; v = Make&lt;<font color="#4f81bd">Vector</font>&lt;<span class="kwrd">int</span>&gt;&gt;(initialSize, isFixedSize);

 

<span class="rem">// Access the vector using Windows Runtime interface methods.</span>
v-&gt;Append(42);
v-&gt;InsertAt(0, 23);

 

<span class="rem">// Internally to your implementation module, it is also possible</span>
<span class="rem">// to get direct access to the underlying STL collection.</span>
std::<font color="#4f81bd">vector</font>&lt;<span class="kwrd">int</span>&gt;&amp; raw = v-&gt;InternalVector();
std::sort(raw.begin(), raw.end());

 

v.CopyTo(<font color="#a5a5a5">returnValue</font>);<br /> <font color="#0000ff">return </font>S_OK;
}</pre>
<p>&nbsp;</p>
<h3><a href="https://github.com/Microsoft/Win2D/blob/master/winrt/inc/AsyncOperation.h" target="_blank">AsyncOperation.h</a></h3>
<p>This header provides the classes AsyncOperation&lt;T&gt; and AsyncAction, which implement the Windows Runtime interfaces <a href="http://msdn.microsoft.com/en-us/library/windows/apps/br206598.aspx" target="_blank">IAsyncOperation&lt;T*&gt;</a> and <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.foundation.iasyncaction.aspx" target="_blank">IAsyncAction</a> respectively.&nbsp; It runs arbitrary code on the system threadpool, and reports the result or error status through standard async interfaces.&nbsp; It is also possible to register one async operation to run as the continuation of another.</p>
<p>Example (error handling skipped for brevity) which uses an asynchronous thread pool task to add two integers:</p>
<pre class="csharpcode"> <font color="#9b00d3">IFACEMETHODIMP</font> AddAsync(<span class="kwrd">int</span> a, <span class="kwrd">int</span> b, <font color="#4f81bd">IAsyncOperation</font>&lt;<span class="kwrd">int</span>&gt;** <font color="#a5a5a5">returnValue</font>)
{
<font color="#0000ff">auto</font> asyncOperation = Make&lt;<font color="#4f81bd">AsyncOperation</font>&lt;<span class="kwrd">int</span>&gt;&gt;([=]
{
<span class="kwrd">return</span> a + b;
});

 

asyncOperation.CopyTo(<font color="#a5a5a5">returnValue</font>);
<font color="#0000ff"> return </font>S_OK; <br /> }</pre>
<p>Even sillier example, which runs an asynchronous multiply task as the continuation of an asynchronous addition:</p>
<pre class="csharpcode"> <font color="#9b00d3">IFACEMETHODIMP</font> AddAndThenMultiplyAsync(<span class="kwrd">int</span> a, <span class="kwrd">int</span> b, <span class="kwrd">int</span> c, IAsyncOperation&lt;<span class="kwrd">int</span>&gt;** <font color="#a5a5a5">returnValue</font>)
{
<span class="rem">// Start the first asynchronous computation.<br /> // This computes a + b.</span>
<font color="#4f81bd">ComPtr</font>&lt;<font color="#4f81bd">IAsyncOperation</font>&lt;<span class="kwrd">int</span>&gt;&gt; addOperation;
AddAsync(<font color="#a5a5a5">a</font>, <font color="#a5a5a5">b</font>, &amp;addOperation);

 

<span class="rem">// Register a second asynchronous computation to run as the continuation of the first.<br /> // This computes &lt;previous async result&gt; * c.</span>
<font color="#0000ff">auto</font> multiplyOperation = Make&lt;<font color="#4f81bd">AsyncOperation</font>&lt;<span class="kwrd">int</span>&gt;&gt;(addOperation, [=]
{
<span class="kwrd">int</span> addResult;
addOperation-&gt;GetResults(&amp;addResult);
<span class="kwrd">return</span> addResult * c;
});

 

multiplyOperation.CopyTo(<font color="#a5a5a5">returnValue</font>);<br /> <font color="#0000ff">return </font>S_OK;
}</pre></p>


<a href="https://blogs.msdn.microsoft.com/shawnhar/2014/11/10/wrl-implementations-of-ivector-and-iasyncoperation/" class='bbc_url' rel='nofollow external'>Source</a>








August 2016 »

S M T W T F S
 123456
78910111213
14151617181920
21222324252627
28 29 3031   


PARTNERS