rename capture interface

This commit is contained in:
Lily Tsuru 2024-11-30 01:24:50 -05:00
parent 3521879ced
commit 26fca2525c
4 changed files with 22 additions and 19 deletions

View file

@ -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<IFramebufferCapture> CreateFramebufferCapture(DisplayCaptureInterface type) {
IFramebufferCapture* pCapture = nullptr;
std::unique_ptr<DisplayCaptureBase> 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<IFramebufferCapture>(pCapture);
return std::unique_ptr<DisplayCaptureBase>(pCapture);
}
} // namespace hazelnut

View file

@ -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<IFramebufferCapture> 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<DisplayCaptureBase> CreateDisplayCapture(DisplayCaptureInterface type);
} // namespace hazelnut

View file

@ -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

View file

@ -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<tileRect> tiles {};
hazelnut::FramebufferInformation framebuffer {};