diff --git a/agent-vs2022/src/capture.cpp b/agent-vs2022/src/capture.cpp index 1693efc..f332bc1 100644 --- a/agent-vs2022/src/capture.cpp +++ b/agent-vs2022/src/capture.cpp @@ -3,26 +3,29 @@ namespace hazelnut { // capture_nvfbc.cpp - IFramebufferCapture* CreateFramebufferCapture_NVFBC(); + DisplayCaptureBase* CreateNVFBCDisplayCapture(); DisplayCaptureInterface GuessBestCaptureInterface() { // The only one we support. return DisplayCaptureInterface::NVFBC; } - std::unique_ptr CreateFramebufferCapture(DisplayCaptureInterface type) { - IFramebufferCapture* pCapture = nullptr; + std::unique_ptr CreateDisplayCapture(DisplayCaptureInterface type) { + DisplayCaptureBase* pCapture = nullptr; switch(type) { - case DisplayCaptureInterface::NVFBC: pCapture = CreateFramebufferCapture_NVFBC(); break; + case DisplayCaptureInterface::NVFBC: pCapture = CreateNVFBCDisplayCapture(); break; default: return nullptr; } - // Initalize capture. - if(!pCapture->Initialize()) + // Initalize capture. Upon failure to capture we destroy the capture interface + // and then return a null pointer. + if(!pCapture->Initialize()) { + delete pCapture; return nullptr; + } - return std::unique_ptr(pCapture); + return std::unique_ptr(pCapture); } } // namespace hazelnut \ No newline at end of file diff --git a/agent-vs2022/src/capture.hpp b/agent-vs2022/src/capture.hpp index 124a005..fa0e872 100644 --- a/agent-vs2022/src/capture.hpp +++ b/agent-vs2022/src/capture.hpp @@ -25,9 +25,8 @@ namespace hazelnut { }; /// Interface used for framebuffer capture independence. - class IFramebufferCapture { - public: - virtual ~IFramebufferCapture() = default; + struct DisplayCaptureBase { + virtual ~DisplayCaptureBase() = default; virtual bool Initialize() = 0; @@ -51,11 +50,11 @@ namespace hazelnut { /// On a NVIDIA GPU on Windows < 8.1, we prefer NVFBC. /// Otherwise, we should prefer DXGI. /// - /// If no API works Invalid is returned. + /// If no API is supported on the running system, Invalid is returned. DisplayCaptureInterface GuessBestCaptureInterface(); - /// Creates a instance of the framebuffer capture interface for a particular interface. - /// Returns a null pointer on failure to create. - std::unique_ptr CreateFramebufferCapture(DisplayCaptureInterface type); + /// Creates a instance of the display capture interface for a particular interface. + /// Returns a null pointer upon failure to create, a valid pointer otherwise. + std::unique_ptr CreateDisplayCapture(DisplayCaptureInterface type); } // namespace hazelnut \ No newline at end of file diff --git a/agent-vs2022/src/capture_nvfbc.cpp b/agent-vs2022/src/capture_nvfbc.cpp index faf29be..3676c98 100644 --- a/agent-vs2022/src/capture_nvfbc.cpp +++ b/agent-vs2022/src/capture_nvfbc.cpp @@ -55,7 +55,7 @@ namespace hazelnut { return (((srcDim) + (1 << (blockShift)) - 1) >> (blockShift)); } - class FramebufferCapture_NVFBC final : public IFramebufferCapture { + struct NVFBCDisplayCapture final : public DisplayCaptureBase { NVFBCRESULT nvfbcStatus; NvFBCLibrary nvfbcLib; @@ -75,7 +75,7 @@ namespace hazelnut { u32 diffmapHeight; public: - virtual ~FramebufferCapture_NVFBC() { Shutdown(); } + virtual ~NVFBCDisplayCapture() { Shutdown(); } void Shutdown() { NvfbcDestroyInstance(); @@ -233,7 +233,7 @@ namespace hazelnut { } }; - IFramebufferCapture* CreateFramebufferCapture_NVFBC() { - return new FramebufferCapture_NVFBC(); + DisplayCaptureBase* CreateNVFBCDisplayCapture() { + return new NVFBCDisplayCapture(); } } // namespace hazelnut diff --git a/agent-vs2022/src/main.cpp b/agent-vs2022/src/main.cpp index e418a5e..1e9033d 100755 --- a/agent-vs2022/src/main.cpp +++ b/agent-vs2022/src/main.cpp @@ -178,7 +178,7 @@ int main(int argc, char** argv) { printf("Hazelnut agent\n"); // Create a capture interface - auto capture = hazelnut::CreateFramebufferCapture(hazelnut::GuessBestCaptureInterface()); + auto capture = hazelnut::CreateDisplayCapture(hazelnut::GuessBestCaptureInterface()); if(!capture) { printf("Failed to create a capture interface\n"); return 1; @@ -186,6 +186,7 @@ int main(int argc, char** argv) { printf("Successfully created a framebuffer capture interface\n"); + bool firstFrame = true; std::vector tiles {}; hazelnut::FramebufferInformation framebuffer {};