├── .gitattributes
├── .gitignore
├── BasicCaptureSample.sln
├── BasicCaptureSample
├── Assets
│ └── Tiles
│ │ ├── LockScreenLogo.scale-200.png
│ │ ├── SplashScreen.scale-200.png
│ │ ├── Square150x150Logo.scale-200.png
│ │ ├── Square44x44Logo.scale-200.png
│ │ ├── Square44x44Logo.targetsize-24_altform-unplated.png
│ │ ├── StoreLogo.png
│ │ └── Wide310x150Logo.scale-200.png
├── BasicCaptureSample.csproj
├── Capture.cs
├── DoubleTapHelper.cs
├── Package.appxmanifest
├── Properties
│ ├── AssemblyInfo.cs
│ └── Default.rd.xml
└── main.cs
├── LICENSE
└── README.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | project.fragment.lock.json
46 | artifacts/
47 |
48 | *_i.c
49 | *_p.c
50 | *_i.h
51 | *.ilk
52 | *.meta
53 | *.obj
54 | *.pch
55 | *.pdb
56 | *.pgc
57 | *.pgd
58 | *.rsp
59 | *.sbr
60 | *.tlb
61 | *.tli
62 | *.tlh
63 | *.tmp
64 | *.tmp_proj
65 | *.log
66 | *.vspscc
67 | *.vssscc
68 | .builds
69 | *.pidb
70 | *.svclog
71 | *.scc
72 |
73 | # Chutzpah Test files
74 | _Chutzpah*
75 |
76 | # Visual C++ cache files
77 | ipch/
78 | *.aps
79 | *.ncb
80 | *.opendb
81 | *.opensdf
82 | *.sdf
83 | *.cachefile
84 | *.VC.db
85 | *.VC.VC.opendb
86 |
87 | # Visual Studio profiler
88 | *.psess
89 | *.vsp
90 | *.vspx
91 | *.sap
92 |
93 | # TFS 2012 Local Workspace
94 | $tf/
95 |
96 | # Guidance Automation Toolkit
97 | *.gpState
98 |
99 | # ReSharper is a .NET coding add-in
100 | _ReSharper*/
101 | *.[Rr]e[Ss]harper
102 | *.DotSettings.user
103 |
104 | # JustCode is a .NET coding add-in
105 | .JustCode
106 |
107 | # TeamCity is a build add-in
108 | _TeamCity*
109 |
110 | # DotCover is a Code Coverage Tool
111 | *.dotCover
112 |
113 | # NCrunch
114 | _NCrunch_*
115 | .*crunch*.local.xml
116 | nCrunchTemp_*
117 |
118 | # MightyMoose
119 | *.mm.*
120 | AutoTest.Net/
121 |
122 | # Web workbench (sass)
123 | .sass-cache/
124 |
125 | # Installshield output folder
126 | [Ee]xpress/
127 |
128 | # DocProject is a documentation generator add-in
129 | DocProject/buildhelp/
130 | DocProject/Help/*.HxT
131 | DocProject/Help/*.HxC
132 | DocProject/Help/*.hhc
133 | DocProject/Help/*.hhk
134 | DocProject/Help/*.hhp
135 | DocProject/Help/Html2
136 | DocProject/Help/html
137 |
138 | # Click-Once directory
139 | publish/
140 |
141 | # Publish Web Output
142 | *.[Pp]ublish.xml
143 | *.azurePubxml
144 | # TODO: Comment the next line if you want to checkin your web deploy settings
145 | # but database connection strings (with potential passwords) will be unencrypted
146 | #*.pubxml
147 | *.publishproj
148 |
149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
150 | # checkin your Azure Web App publish settings, but sensitive information contained
151 | # in these scripts will be unencrypted
152 | PublishScripts/
153 |
154 | # NuGet Packages
155 | *.nupkg
156 | # The packages folder can be ignored because of Package Restore
157 | **/packages/*
158 | # except build/, which is used as an MSBuild target.
159 | !**/packages/build/
160 | # Uncomment if necessary however generally it will be regenerated when needed
161 | #!**/packages/repositories.config
162 | # NuGet v3's project.json files produces more ignoreable files
163 | *.nuget.props
164 | *.nuget.targets
165 |
166 | # Microsoft Azure Build Output
167 | csx/
168 | *.build.csdef
169 |
170 | # Microsoft Azure Emulator
171 | ecf/
172 | rcf/
173 |
174 | # Windows Store app package directories and files
175 | AppPackages/
176 | BundleArtifacts/
177 | Package.StoreAssociation.xml
178 | _pkginfo.txt
179 |
180 | # Visual Studio cache files
181 | # files ending in .cache can be ignored
182 | *.[Cc]ache
183 | # but keep track of directories ending in .cache
184 | !*.[Cc]ache/
185 |
186 | # Others
187 | ClientBin/
188 | ~$*
189 | *~
190 | *.dbmdl
191 | *.dbproj.schemaview
192 | *.jfm
193 | *.pfx
194 | *.publishsettings
195 | node_modules/
196 | orleans.codegen.cs
197 |
198 | # Since there are multiple workflows, uncomment next line to ignore bower_components
199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
200 | #bower_components/
201 |
202 | # RIA/Silverlight projects
203 | Generated_Code/
204 |
205 | # Backup & report files from converting an old project file
206 | # to a newer Visual Studio version. Backup files are not needed,
207 | # because we have git ;-)
208 | _UpgradeReport_Files/
209 | Backup*/
210 | UpgradeLog*.XML
211 | UpgradeLog*.htm
212 |
213 | # SQL Server files
214 | *.mdf
215 | *.ldf
216 |
217 | # Business Intelligence projects
218 | *.rdl.data
219 | *.bim.layout
220 | *.bim_*.settings
221 |
222 | # Microsoft Fakes
223 | FakesAssemblies/
224 |
225 | # GhostDoc plugin setting file
226 | *.GhostDoc.xml
227 |
228 | # Node.js Tools for Visual Studio
229 | .ntvs_analysis.dat
230 |
231 | # Visual Studio 6 build log
232 | *.plg
233 |
234 | # Visual Studio 6 workspace options file
235 | *.opt
236 |
237 | # Visual Studio LightSwitch build output
238 | **/*.HTMLClient/GeneratedArtifacts
239 | **/*.DesktopClient/GeneratedArtifacts
240 | **/*.DesktopClient/ModelManifest.xml
241 | **/*.Server/GeneratedArtifacts
242 | **/*.Server/ModelManifest.xml
243 | _Pvt_Extensions
244 |
245 | # Paket dependency manager
246 | .paket/paket.exe
247 | paket-files/
248 |
249 | # FAKE - F# Make
250 | .fake/
251 |
252 | # JetBrains Rider
253 | .idea/
254 | *.sln.iml
255 |
256 | # CodeRush
257 | .cr/
258 |
259 | # Python Tools for Visual Studio (PTVS)
260 | __pycache__/
261 | *.pyc
--------------------------------------------------------------------------------
/BasicCaptureSample.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.30406.217
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicCaptureSample", "BasicCaptureSample\BasicCaptureSample.csproj", "{09DFAA71-B4C8-43F3-B7A6-DA42E289199F}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|ARM = Debug|ARM
11 | Debug|ARM64 = Debug|ARM64
12 | Debug|x64 = Debug|x64
13 | Debug|x86 = Debug|x86
14 | Release|ARM = Release|ARM
15 | Release|ARM64 = Release|ARM64
16 | Release|x64 = Release|x64
17 | Release|x86 = Release|x86
18 | EndGlobalSection
19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
20 | {09DFAA71-B4C8-43F3-B7A6-DA42E289199F}.Debug|ARM.ActiveCfg = Debug|ARM
21 | {09DFAA71-B4C8-43F3-B7A6-DA42E289199F}.Debug|ARM.Build.0 = Debug|ARM
22 | {09DFAA71-B4C8-43F3-B7A6-DA42E289199F}.Debug|ARM.Deploy.0 = Debug|ARM
23 | {09DFAA71-B4C8-43F3-B7A6-DA42E289199F}.Debug|ARM64.ActiveCfg = Debug|ARM64
24 | {09DFAA71-B4C8-43F3-B7A6-DA42E289199F}.Debug|ARM64.Build.0 = Debug|ARM64
25 | {09DFAA71-B4C8-43F3-B7A6-DA42E289199F}.Debug|ARM64.Deploy.0 = Debug|ARM64
26 | {09DFAA71-B4C8-43F3-B7A6-DA42E289199F}.Debug|x64.ActiveCfg = Debug|x64
27 | {09DFAA71-B4C8-43F3-B7A6-DA42E289199F}.Debug|x64.Build.0 = Debug|x64
28 | {09DFAA71-B4C8-43F3-B7A6-DA42E289199F}.Debug|x64.Deploy.0 = Debug|x64
29 | {09DFAA71-B4C8-43F3-B7A6-DA42E289199F}.Debug|x86.ActiveCfg = Debug|x86
30 | {09DFAA71-B4C8-43F3-B7A6-DA42E289199F}.Debug|x86.Build.0 = Debug|x86
31 | {09DFAA71-B4C8-43F3-B7A6-DA42E289199F}.Debug|x86.Deploy.0 = Debug|x86
32 | {09DFAA71-B4C8-43F3-B7A6-DA42E289199F}.Release|ARM.ActiveCfg = Release|ARM
33 | {09DFAA71-B4C8-43F3-B7A6-DA42E289199F}.Release|ARM.Build.0 = Release|ARM
34 | {09DFAA71-B4C8-43F3-B7A6-DA42E289199F}.Release|ARM.Deploy.0 = Release|ARM
35 | {09DFAA71-B4C8-43F3-B7A6-DA42E289199F}.Release|ARM64.ActiveCfg = Release|ARM64
36 | {09DFAA71-B4C8-43F3-B7A6-DA42E289199F}.Release|ARM64.Build.0 = Release|ARM64
37 | {09DFAA71-B4C8-43F3-B7A6-DA42E289199F}.Release|ARM64.Deploy.0 = Release|ARM64
38 | {09DFAA71-B4C8-43F3-B7A6-DA42E289199F}.Release|x64.ActiveCfg = Release|x64
39 | {09DFAA71-B4C8-43F3-B7A6-DA42E289199F}.Release|x64.Build.0 = Release|x64
40 | {09DFAA71-B4C8-43F3-B7A6-DA42E289199F}.Release|x64.Deploy.0 = Release|x64
41 | {09DFAA71-B4C8-43F3-B7A6-DA42E289199F}.Release|x86.ActiveCfg = Release|x86
42 | {09DFAA71-B4C8-43F3-B7A6-DA42E289199F}.Release|x86.Build.0 = Release|x86
43 | {09DFAA71-B4C8-43F3-B7A6-DA42E289199F}.Release|x86.Deploy.0 = Release|x86
44 | EndGlobalSection
45 | GlobalSection(SolutionProperties) = preSolution
46 | HideSolutionNode = FALSE
47 | EndGlobalSection
48 | GlobalSection(ExtensibilityGlobals) = postSolution
49 | SolutionGuid = {3C9F494A-D5F6-4D77-AD50-7964BC62C1DB}
50 | EndGlobalSection
51 | EndGlobal
52 |
--------------------------------------------------------------------------------
/BasicCaptureSample/Assets/Tiles/LockScreenLogo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/robmikh/BasicCaptureSample/c4bfa0eb1829f93e42c13adee2e0567f435a524b/BasicCaptureSample/Assets/Tiles/LockScreenLogo.scale-200.png
--------------------------------------------------------------------------------
/BasicCaptureSample/Assets/Tiles/SplashScreen.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/robmikh/BasicCaptureSample/c4bfa0eb1829f93e42c13adee2e0567f435a524b/BasicCaptureSample/Assets/Tiles/SplashScreen.scale-200.png
--------------------------------------------------------------------------------
/BasicCaptureSample/Assets/Tiles/Square150x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/robmikh/BasicCaptureSample/c4bfa0eb1829f93e42c13adee2e0567f435a524b/BasicCaptureSample/Assets/Tiles/Square150x150Logo.scale-200.png
--------------------------------------------------------------------------------
/BasicCaptureSample/Assets/Tiles/Square44x44Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/robmikh/BasicCaptureSample/c4bfa0eb1829f93e42c13adee2e0567f435a524b/BasicCaptureSample/Assets/Tiles/Square44x44Logo.scale-200.png
--------------------------------------------------------------------------------
/BasicCaptureSample/Assets/Tiles/Square44x44Logo.targetsize-24_altform-unplated.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/robmikh/BasicCaptureSample/c4bfa0eb1829f93e42c13adee2e0567f435a524b/BasicCaptureSample/Assets/Tiles/Square44x44Logo.targetsize-24_altform-unplated.png
--------------------------------------------------------------------------------
/BasicCaptureSample/Assets/Tiles/StoreLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/robmikh/BasicCaptureSample/c4bfa0eb1829f93e42c13adee2e0567f435a524b/BasicCaptureSample/Assets/Tiles/StoreLogo.png
--------------------------------------------------------------------------------
/BasicCaptureSample/Assets/Tiles/Wide310x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/robmikh/BasicCaptureSample/c4bfa0eb1829f93e42c13adee2e0567f435a524b/BasicCaptureSample/Assets/Tiles/Wide310x150Logo.scale-200.png
--------------------------------------------------------------------------------
/BasicCaptureSample/BasicCaptureSample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | x86
7 | {09DFAA71-B4C8-43F3-B7A6-DA42E289199F}
8 | AppContainerExe
9 | Properties
10 | BasicCaptureSample
11 | BasicCaptureSample
12 | en-US
13 | UAP
14 | 10.0.19041.0
15 | 10.0.17134.0
16 | 14
17 | 512
18 | {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
19 | true
20 | B9831570352C134C5D7816F36FF6D73B747991B8
21 | BasicCaptureSample_TemporaryKey.pfx
22 | True
23 |
24 |
25 | true
26 | bin\x86\Debug\
27 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP
28 | ;2008
29 | full
30 | x86
31 | false
32 | prompt
33 | true
34 |
35 |
36 | bin\x86\Release\
37 | TRACE;NETFX_CORE;WINDOWS_UWP
38 | true
39 | ;2008
40 | pdbonly
41 | x86
42 | false
43 | prompt
44 | true
45 | true
46 |
47 |
48 | true
49 | bin\ARM\Debug\
50 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP
51 | ;2008
52 | full
53 | ARM
54 | false
55 | prompt
56 | true
57 |
58 |
59 | bin\ARM\Release\
60 | TRACE;NETFX_CORE;WINDOWS_UWP
61 | true
62 | ;2008
63 | pdbonly
64 | ARM
65 | false
66 | prompt
67 | true
68 | true
69 |
70 |
71 | true
72 | bin\x64\Debug\
73 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP
74 | ;2008
75 | full
76 | x64
77 | false
78 | prompt
79 | true
80 | false
81 |
82 |
83 | bin\x64\Release\
84 | TRACE;NETFX_CORE;WINDOWS_UWP
85 | true
86 | ;2008
87 | pdbonly
88 | x64
89 | false
90 | prompt
91 | true
92 | true
93 |
94 |
95 | PackageReference
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 | Designer
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 | 6.2.10
121 |
122 |
123 | 1.25.0
124 |
125 |
126 |
127 |
128 |
129 |
130 | 14.0
131 |
132 |
133 | true
134 | bin\ARM64\Debug\
135 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP;CODE_ANALYSIS
136 | ;2008
137 | true
138 | full
139 | ARM64
140 | false
141 | 7.3
142 | prompt
143 | MinimumRecommendedRules.ruleset
144 | true
145 |
146 |
147 | bin\ARM64\Release\
148 | TRACE;NETFX_CORE;WINDOWS_UWP;CODE_ANALYSIS
149 | true
150 | ;2008
151 | true
152 | pdbonly
153 | ARM64
154 | false
155 | 7.3
156 | prompt
157 | MinimumRecommendedRules.ruleset
158 | true
159 |
160 |
161 |
168 |
--------------------------------------------------------------------------------
/BasicCaptureSample/Capture.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Graphics.Canvas;
2 | using Microsoft.Graphics.Canvas.UI.Composition;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading;
8 | using System.Threading.Tasks;
9 | using Windows.Graphics;
10 | using Windows.Graphics.Capture;
11 | using Windows.Graphics.DirectX;
12 | using Windows.System;
13 | using Windows.UI;
14 | using Windows.UI.Composition;
15 |
16 | namespace BasicCaptureSample
17 | {
18 | class Capture : IDisposable
19 | {
20 | public Capture(CanvasDevice device, GraphicsCaptureItem item)
21 | {
22 | _item = item;
23 | _device = device;
24 |
25 | // TODO: Dpi?
26 | _swapChain = new CanvasSwapChain(_device, item.Size.Width, item.Size.Height, 96);
27 |
28 | _dispatcherQueueController = DispatcherQueueController.CreateOnDedicatedThread();
29 | _dispatcherQueue = _dispatcherQueueController.DispatcherQueue;
30 |
31 | // We don't want to return from the constructor untill the frame pool and
32 | // the capture session are both initialized. We could do this on the UI thread,
33 | // but you really shouldn't. This will update as fast as the screen refresh rate,
34 | // so it would cause performance issues on the UI thread.
35 | var wait = new AutoResetEvent(false);
36 | var success = _dispatcherQueue.TryEnqueue(() =>
37 | {
38 | _framePool = Direct3D11CaptureFramePool.Create(
39 | _device,
40 | DirectXPixelFormat.B8G8R8A8UIntNormalized,
41 | 2,
42 | item.Size);
43 | _session = _framePool.CreateCaptureSession(item);
44 | _lastSize = item.Size;
45 |
46 | _framePool.FrameArrived += OnFrameArrived;
47 |
48 | wait.Set();
49 | });
50 |
51 | if (!success)
52 | {
53 | throw new Exception("Could not enqueue work!");
54 | }
55 |
56 | wait.WaitOne();
57 | }
58 |
59 | public void StartCapture()
60 | {
61 | _session.StartCapture();
62 | }
63 |
64 | public ICompositionSurface CreateSurface(Compositor compositor)
65 | {
66 | return CanvasComposition.CreateCompositionSurfaceForSwapChain(compositor, _swapChain);
67 | }
68 |
69 | public void Dispose()
70 | {
71 | _session?.Dispose();
72 | _framePool?.Dispose();
73 | _swapChain?.Dispose();
74 |
75 | _swapChain = null;
76 | _framePool = null;
77 | _session = null;
78 | _item = null;
79 |
80 | if (_dispatcherQueueController != null)
81 | {
82 | var ignored = _dispatcherQueueController.ShutdownQueueAsync();
83 | _dispatcherQueueController = null;
84 | _dispatcherQueue = null;
85 | }
86 | }
87 |
88 | private void OnFrameArrived(Direct3D11CaptureFramePool sender, object args)
89 | {
90 | var newSize = false;
91 |
92 | using (var frame = sender.TryGetNextFrame())
93 | {
94 | if (frame.ContentSize.Width != _lastSize.Width ||
95 | frame.ContentSize.Height != _lastSize.Height)
96 | {
97 | // The thing we have been capturing has changed size.
98 | // We need to resize our swap chain first, then blit the pixels.
99 | // After we do that, retire the frame and then recreate our frame pool.
100 | newSize = true;
101 | _lastSize = frame.ContentSize;
102 | _swapChain.ResizeBuffers(_lastSize.Width, _lastSize.Height);
103 | }
104 |
105 | using (var bitmap = CanvasBitmap.CreateFromDirect3D11Surface(_device, frame.Surface))
106 | using (var drawingSession = _swapChain.CreateDrawingSession(Colors.Transparent))
107 | {
108 | drawingSession.DrawImage(bitmap);
109 | }
110 |
111 | } // retire the frame
112 |
113 | _swapChain.Present();
114 |
115 | if (newSize)
116 | {
117 | _framePool.Recreate(
118 | _device,
119 | DirectXPixelFormat.B8G8R8A8UIntNormalized,
120 | 2,
121 | _lastSize);
122 | }
123 | }
124 |
125 | private GraphicsCaptureItem _item;
126 | private Direct3D11CaptureFramePool _framePool;
127 | private GraphicsCaptureSession _session;
128 | private SizeInt32 _lastSize;
129 |
130 | private CanvasDevice _device;
131 | private CanvasSwapChain _swapChain;
132 |
133 | private DispatcherQueueController _dispatcherQueueController;
134 | private DispatcherQueue _dispatcherQueue;
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/BasicCaptureSample/DoubleTapHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using Windows.UI.Core;
7 | using Windows.UI.Input;
8 |
9 | namespace BasicCaptureSample
10 | {
11 | class DoubleTapHelper
12 | {
13 | public DoubleTapHelper(CoreWindow window)
14 | {
15 | _window = window;
16 |
17 | _gestureRecognizer = new GestureRecognizer();
18 | _gestureRecognizer.GestureSettings = GestureSettings.DoubleTap;
19 |
20 | window.PointerMoved += Window_PointerMoved;
21 | window.PointerPressed += Window_PointerPressed;
22 | window.PointerReleased += Window_PointerReleased;
23 |
24 | _gestureRecognizer.Tapped += OnTapped;
25 | }
26 |
27 | public event EventHandler DoubleTapped;
28 |
29 | private void OnTapped(GestureRecognizer sender, TappedEventArgs args)
30 | {
31 | if (args.TapCount == 2)
32 | {
33 | _gestureRecognizer.CompleteGesture();
34 | DoubleTapped?.Invoke(_window, new EventArgs());
35 | }
36 | }
37 |
38 | private void Window_PointerReleased(CoreWindow sender, PointerEventArgs args)
39 | {
40 | _gestureRecognizer.ProcessUpEvent(args.CurrentPoint);
41 | }
42 |
43 | private void Window_PointerPressed(CoreWindow sender, PointerEventArgs args)
44 | {
45 | _gestureRecognizer.ProcessDownEvent(args.CurrentPoint);
46 | }
47 |
48 | private void Window_PointerMoved(CoreWindow sender, PointerEventArgs args)
49 | {
50 | _gestureRecognizer.ProcessMoveEvents(args.GetIntermediatePoints());
51 | }
52 |
53 | private CoreWindow _window;
54 | private GestureRecognizer _gestureRecognizer;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/BasicCaptureSample/Package.appxmanifest:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 | BasicCaptureSample
12 | romikh
13 | Assets\Tiles\StoreLogo.png
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/BasicCaptureSample/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("BasicCaptureSample")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("BasicCaptureSample")]
13 | [assembly: AssemblyCopyright("Copyright © 2018")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Version information for an assembly consists of the following four values:
18 | //
19 | // Major Version
20 | // Minor Version
21 | // Build Number
22 | // Revision
23 | //
24 | // You can specify all the values or you can default the Build and Revision Numbers
25 | // by using the '*' as shown below:
26 | // [assembly: AssemblyVersion("1.0.*")]
27 | [assembly: AssemblyVersion("1.0.0.0")]
28 | [assembly: AssemblyFileVersion("1.0.0.0")]
29 | [assembly: ComVisible(false)]
--------------------------------------------------------------------------------
/BasicCaptureSample/Properties/Default.rd.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/BasicCaptureSample/main.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Graphics.Canvas;
2 | using System;
3 | using System.Numerics;
4 | using System.Threading.Tasks;
5 | using Windows.ApplicationModel.Core;
6 | using Windows.Graphics.Capture;
7 | using Windows.UI;
8 | using Windows.UI.Composition;
9 | using Windows.UI.Core;
10 | using Windows.UI.Popups;
11 |
12 | namespace BasicCaptureSample
13 | {
14 | public class MainView : IFrameworkView
15 | {
16 | public void Initialize(CoreApplicationView applicationView)
17 | {
18 | _view = applicationView;
19 | }
20 |
21 | public void SetWindow(CoreWindow window)
22 | {
23 | _window = window;
24 | }
25 |
26 | public void Load(string entryPoint) { }
27 |
28 | public void Run()
29 | {
30 | _compositor = new Compositor();
31 | _target = _compositor.CreateTargetForCurrentView();
32 | _root = _compositor.CreateSpriteVisual();
33 | _content = _compositor.CreateSpriteVisual();
34 | _brush = _compositor.CreateSurfaceBrush();
35 |
36 | _root.Brush = _compositor.CreateColorBrush(Colors.White);
37 | _root.RelativeSizeAdjustment = Vector2.One;
38 | _target.Root = _root;
39 |
40 | if (GraphicsCaptureSession.IsSupported())
41 | {
42 | _content.AnchorPoint = new Vector2(0.5f, 0.5f);
43 | _content.RelativeOffsetAdjustment = new Vector3(0.5f, 0.5f, 0);
44 | _content.RelativeSizeAdjustment = Vector2.One;
45 | _content.Size = new Vector2(-80, -80);
46 | _content.Brush = _brush;
47 | _brush.HorizontalAlignmentRatio = 0.5f;
48 | _brush.VerticalAlignmentRatio = 0.5f;
49 | _brush.Stretch = CompositionStretch.Uniform;
50 | var shadow = _compositor.CreateDropShadow();
51 | shadow.Mask = _brush;
52 | _content.Shadow = shadow;
53 | _root.Children.InsertAtTop(_content);
54 |
55 | _device = new CanvasDevice();
56 |
57 | // We can't just call the picker here, because no one is pumping messages yet.
58 | // By asking the dispatcher for our UI thread to run this, we ensure that the
59 | // message pump is pumping messages by the time this runs.
60 | var ignored = _window.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
61 | {
62 | var ignoredTask = StartCaptureAsync();
63 | });
64 |
65 | _doubleTapHelper = new DoubleTapHelper(_window);
66 | _doubleTapHelper.DoubleTapped += OnDoubleTapped;
67 | }
68 | else
69 | {
70 | var ignored = _window.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
71 | {
72 | var dialog = new MessageDialog("Screen capture is not supported on this device for this release of Windows!");
73 |
74 | await dialog.ShowAsync();
75 | });
76 | }
77 |
78 | _window.Activate();
79 | _window.Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessUntilQuit);
80 | }
81 |
82 | private void OnDoubleTapped(object sender, EventArgs e)
83 | {
84 | StopCapture();
85 | var ignored = StartCaptureAsync();
86 | }
87 |
88 | public void Uninitialize()
89 | {
90 | StopCapture();
91 | _compositor.Dispose();
92 | }
93 |
94 | private async Task StartCaptureAsync()
95 | {
96 | var picker = new GraphicsCapturePicker();
97 | var item = await picker.PickSingleItemAsync();
98 |
99 | if (item != null)
100 | {
101 | _capture = new Capture(_device, item);
102 |
103 | var surface = _capture.CreateSurface(_compositor);
104 | _brush.Surface = surface;
105 |
106 | _capture.StartCapture();
107 | }
108 | }
109 |
110 | private void StopCapture()
111 | {
112 | _capture?.Dispose();
113 | _brush.Surface = null;
114 | }
115 |
116 | private CoreWindow _window;
117 | private CoreApplicationView _view;
118 |
119 | private Compositor _compositor;
120 | private CompositionTarget _target;
121 | private SpriteVisual _root;
122 | private SpriteVisual _content;
123 | private CompositionSurfaceBrush _brush;
124 |
125 | private CanvasDevice _device;
126 | private Capture _capture;
127 | private DoubleTapHelper _doubleTapHelper;
128 | }
129 |
130 | public class MainViewFactory : IFrameworkViewSource
131 | {
132 | public IFrameworkView CreateView()
133 | {
134 | return new MainView();
135 | }
136 |
137 | public static void Main(string[] args)
138 | {
139 | CoreApplication.Run(new MainViewFactory());
140 | }
141 | }
142 | }
143 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Robert Mikhayelyan
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # BasicCaptureSample
2 | Basic sample using the Windows.Graphics.Capture API along with Win2D.
3 |
--------------------------------------------------------------------------------