-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
175 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include "pch.h" | ||
#include "DirtyRegionVisualizer.h" | ||
|
||
namespace winrt | ||
{ | ||
using namespace Windows::Foundation; | ||
using namespace Windows::Foundation::Numerics; | ||
using namespace Windows::Graphics; | ||
using namespace Windows::Graphics::Capture; | ||
using namespace Windows::Graphics::DirectX; | ||
using namespace Windows::Graphics::DirectX::Direct3D11; | ||
using namespace Windows::System; | ||
using namespace Windows::UI; | ||
using namespace Windows::UI::Composition; | ||
} | ||
|
||
namespace util | ||
{ | ||
using namespace robmikh::common::uwp; | ||
} | ||
|
||
DirtyRegionVisualizer::DirtyRegionVisualizer(winrt::com_ptr<ID3D11Device> const& d3dDevice) | ||
{ | ||
m_d2dFactory = util::CreateD2DFactory(); | ||
m_d2dDevice = util::CreateD2DDevice(m_d2dFactory, d3dDevice); | ||
|
||
winrt::check_hresult(m_d2dDevice->CreateDeviceContext(D2D1_DEVICE_CONTEXT_OPTIONS_NONE, m_d2dContext.put())); | ||
|
||
D2D1_COLOR_F color = { 1.0f, 0.0f, 0.0f, 0.6f }; | ||
winrt::check_hresult(m_d2dContext->CreateSolidColorBrush(color, m_brush.put())); | ||
} | ||
|
||
void DirtyRegionVisualizer::Render( | ||
winrt::com_ptr<ID3D11Texture2D> const& renderTargetTexture, | ||
winrt::Direct3D11CaptureFrame const& captureFrame) | ||
{ | ||
auto dirtyRegion = captureFrame.DirtyRegions(); | ||
if (dirtyRegion.Size() > 0) | ||
{ | ||
auto dxgiTexture = renderTargetTexture.as<IDXGISurface>(); | ||
winrt::com_ptr<ID2D1Bitmap1> d2dBitmap; | ||
winrt::check_hresult(m_d2dContext->CreateBitmapFromDxgiSurface(dxgiTexture.get(), nullptr, d2dBitmap.put())); | ||
|
||
m_d2dContext->SetTarget(d2dBitmap.get()); | ||
auto unsetTarget = wil::scope_exit([d2dContext = m_d2dContext]() | ||
{ | ||
d2dContext->SetTarget(nullptr); | ||
}); | ||
|
||
m_d2dContext->BeginDraw(); | ||
auto endDraw = wil::scope_exit([d2dContext = m_d2dContext]() | ||
{ | ||
winrt::check_hresult(d2dContext->EndDraw()); | ||
}); | ||
|
||
for (auto&& dirtyRegion : dirtyRegion) | ||
{ | ||
D2D1_RECT_F rect = | ||
{ | ||
static_cast<float>(dirtyRegion.X), | ||
static_cast<float>(dirtyRegion.Y), | ||
static_cast<float>(dirtyRegion.X + dirtyRegion.Width), | ||
static_cast<float>(dirtyRegion.Y + dirtyRegion.Height), | ||
}; | ||
|
||
m_d2dContext->FillRectangle( | ||
rect, | ||
m_brush.get()); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
|
||
class DirtyRegionVisualizer | ||
{ | ||
public: | ||
DirtyRegionVisualizer( | ||
winrt::com_ptr<ID3D11Device> const& d3dDevice); | ||
~DirtyRegionVisualizer() {} | ||
|
||
void Render( | ||
winrt::com_ptr<ID3D11Texture2D> const& renderTargetTexture, | ||
winrt::Windows::Graphics::Capture::Direct3D11CaptureFrame const& captureFrame); | ||
|
||
private: | ||
winrt::com_ptr<ID2D1Device> m_d2dDevice{ nullptr }; | ||
winrt::com_ptr<ID2D1Factory1> m_d2dFactory{ nullptr }; | ||
winrt::com_ptr<ID2D1DeviceContext> m_d2dContext{ nullptr }; | ||
winrt::com_ptr<ID2D1SolidColorBrush> m_brush{ nullptr }; | ||
}; |
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
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
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
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
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
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