Commit 5feca50f authored by Alexey Ershov's avatar Alexey Ershov

changed device detection procedure, added resizing surface to bigger size

removed unused context_id2; changed blur size 7x7 to 3x3; added short comments
removed unnecessary call to convertFromVASurface()
replaced dumpSurface() with writeImage()
added infile cmdline parameter, input image loaded by imread()
parent 95339827
...@@ -12,7 +12,7 @@ endif() ...@@ -12,7 +12,7 @@ endif()
if(VA_INCLUDE_DIR) if(VA_INCLUDE_DIR)
set(HAVE_VA TRUE) set(HAVE_VA TRUE)
set(VA_LIBRARIES "-lva" "-lva-x11") set(VA_LIBRARIES "-lva" "-lva-drm")
else() else()
set(HAVE_VA FALSE) set(HAVE_VA FALSE)
message(WARNING "libva installation is not found.") message(WARNING "libva installation is not found.")
......
...@@ -10,27 +10,16 @@ ...@@ -10,27 +10,16 @@
#include "cvconfig.h" #include "cvconfig.h"
#include <va/va.h> #include <va/va.h>
#if defined(HAVE_VA_INTEL)
# include <va/va_drm.h> # include <va/va_drm.h>
#elif defined(HAVE_VA)
# include <va/va_x11.h>
# include <X11/Xlib.h>
#endif //HAVE_VA_INTEL / HAVE_VA
namespace va { namespace va {
#if defined(HAVE_VA_INTEL) || defined(HAVE_VA)
bool openDisplay(); bool openDisplay();
void closeDisplay(); void closeDisplay();
VADisplay display = NULL; VADisplay display = NULL;
bool initialized = false; bool initialized = false;
#endif //HAVE_VA_INTEL || HAVE_VA
#if defined(HAVE_VA_INTEL)
#define VA_INTEL_PCI_DIR "/sys/bus/pci/devices" #define VA_INTEL_PCI_DIR "/sys/bus/pci/devices"
#define VA_INTEL_DRI_DIR "/dev/dri/" #define VA_INTEL_DRI_DIR "/dev/dri/"
#define VA_INTEL_PCI_DISPLAY_CONTROLLER_CLASS 0x03 #define VA_INTEL_PCI_DISPLAY_CONTROLLER_CLASS 0x03
...@@ -161,93 +150,74 @@ private: ...@@ -161,93 +150,74 @@ private:
char* paths[NUM_NODES]; char* paths[NUM_NODES];
}; };
bool openDisplay() static bool openDeviceIntel();
static bool openDeviceGeneric();
static bool openDeviceIntel()
{ {
if (!initialized) const unsigned IntelVendorID = 0x8086;
{
const unsigned IntelVendorID = 0x8086;
drmfd = -1; int adapterIndex = findAdapter(IntelVendorID);
display = 0; if (adapterIndex >= 0)
{
NodeInfo nodes(adapterIndex);
int adapterIndex = findAdapter(IntelVendorID); for (int i = 0; i < nodes.count(); ++i)
if (adapterIndex >= 0)
{ {
NodeInfo nodes(adapterIndex); drmfd = open(nodes.path(i), O_RDWR);
if (drmfd >= 0)
for (int i = 0; i < nodes.count(); ++i)
{ {
drmfd = open(nodes.path(i), O_RDWR); display = vaGetDisplayDRM(drmfd);
if (drmfd >= 0) if (display)
{ return true;
display = vaGetDisplayDRM(drmfd); close(drmfd);
if (display) drmfd = -1;
{
int majorVersion = 0, minorVersion = 0;
if (vaInitialize(display, &majorVersion, &minorVersion) == VA_STATUS_SUCCESS)
{
initialized = true;
return true;
}
display = 0;
}
close(drmfd);
drmfd = -1;
}
} }
} }
if (adapterIndex < 0)
return false; // Can't find Intel display adapter
if ((drmfd < 0) || !display)
return false; // Can't load VA display
} }
return true; return false;
} }
void closeDisplay() static bool openDeviceGeneric()
{ {
if (initialized) static const char* device_paths[] = { "/dev/dri/renderD128", "/dev/dri/card0" };
static const int num_devices = sizeof(device_paths) / sizeof(device_paths[0]);
for (int i = 0; i < num_devices; ++i)
{ {
if (display) drmfd = open(device_paths[i], O_RDWR);
vaTerminate(display);
if (drmfd >= 0) if (drmfd >= 0)
{
display = vaGetDisplayDRM(drmfd);
if (display)
return true;
close(drmfd); close(drmfd);
display = 0; drmfd = -1;
drmfd = -1; }
initialized = false;
} }
return false;
} }
#elif defined(HAVE_VA)
static Display* x11Display = 0;
bool openDisplay() bool openDisplay()
{ {
if (!initialized) if (!initialized)
{ {
drmfd = -1;
display = 0; display = 0;
x11Display = XOpenDisplay(""); if (openDeviceIntel() || openDeviceGeneric())
if (x11Display != 0)
{ {
display = vaGetDisplay(x11Display); int majorVersion = 0, minorVersion = 0;
if (display) if (vaInitialize(display, &majorVersion, &minorVersion) == VA_STATUS_SUCCESS)
{ {
int majorVersion = 0, minorVersion = 0; initialized = true;
if (vaInitialize(display, &majorVersion, &minorVersion) == VA_STATUS_SUCCESS) return true;
{
initialized = true;
return true;
}
display = 0;
} }
XCloseDisplay(x11Display); close(drmfd);
x11Display = 0; display = 0;
drmfd = -1;
} }
return false; // Can't open VA display
return false; // Can't initialize X11/VA display
} }
return true; return true;
} }
...@@ -258,14 +228,12 @@ void closeDisplay() ...@@ -258,14 +228,12 @@ void closeDisplay()
{ {
if (display) if (display)
vaTerminate(display); vaTerminate(display);
if (x11Display) if (drmfd >= 0)
XCloseDisplay(x11Display); close(drmfd);
display = 0; display = 0;
x11Display = 0; drmfd = -1;
initialized = false; initialized = false;
} }
} }
#endif // HAVE_VA_INTEL / HAVE_VA
} // namespace va } // namespace va
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment