summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjqdeng <Emily.Deng@amd.com>2016-07-05 15:43:37 +0800
committerQiang Yu <Qiang.Yu@amd.com>2017-05-17 11:10:47 +0800
commitaddc5d713867c81d13dbef16327cf927f132bf0a (patch)
tree2813eba26e322727bf686974aa1a472afda2f01c
parentcdea4e508e185c33fd22480397e53c6676fd69fa (diff)
amdgpu: Add interface amdgpu_get_fb_id v2
The amdgpu_get_fb_id is used to export the crtc's framebuffer's buffer id to OpenGL driver for capturing desktop to OpenGL texture. This is for linux rapidfire server. v2: c73ce6e5a9df8827b480f9104de6c28b5f9bc6f0 Fix memory leak in amdgpu_get_fb_id Change-Id: I336fab1585bbdcf6f789c4bab533e4d1f01842ec Signed-off-by: jqdeng <Emily.Deng@amd.com> Reviewed-by: Chunming Zhou <David1.Zhou@amd.com>
-rwxr-xr-xamdgpu/amdgpu-symbol-check1
-rw-r--r--amdgpu/amdgpu.h15
-rw-r--r--amdgpu/amdgpu_bo.c52
3 files changed, 68 insertions, 0 deletions
diff --git a/amdgpu/amdgpu-symbol-check b/amdgpu/amdgpu-symbol-check
index 81ef9b4e..b18bf39b 100755
--- a/amdgpu/amdgpu-symbol-check
+++ b/amdgpu/amdgpu-symbol-check
@@ -52,6 +52,7 @@ amdgpu_read_mm_registers
amdgpu_va_range_alloc
amdgpu_va_range_free
amdgpu_va_range_query
+amdgpu_get_fb_id
EOF
done)
diff --git a/amdgpu/amdgpu.h b/amdgpu/amdgpu.h
index 3f98e1de..0b908616 100644
--- a/amdgpu/amdgpu.h
+++ b/amdgpu/amdgpu.h
@@ -642,6 +642,21 @@ int amdgpu_bo_import(amdgpu_device_handle dev,
struct amdgpu_bo_import_result *output);
/**
+ * Allow others to get access to crtc's framebuffer
+ *
+ * \param dev - \c [in] Device handle.
+ * See #amdgpu_device_initialize()
+ * \param fb_id - \c [out] the first crtc's framebuffer's buffer_id
+ *
+ * \return 0 on success\n
+ * <0 - Negative POSIX Error code
+ *
+ * \sa amdgpu_get_fb_id()
+ *
+*/
+int amdgpu_get_fb_id(amdgpu_device_handle dev, unsigned int *fb_id);
+
+/**
* Request GPU access to user allocated memory e.g. via "malloc"
*
* \param dev - [in] Device handle. See #amdgpu_device_initialize()
diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c
index 0760be9a..aa374624 100644
--- a/amdgpu/amdgpu_bo.c
+++ b/amdgpu/amdgpu_bo.c
@@ -43,6 +43,7 @@
#include "amdgpu_internal.h"
#include "util_hash_table.h"
#include "util_math.h"
+#include "xf86drmMode.h"
static void amdgpu_close_kms_handle(amdgpu_device_handle dev,
uint32_t handle)
@@ -417,6 +418,57 @@ int amdgpu_bo_import(amdgpu_device_handle dev,
return 0;
}
+/* Get the first use crtc's frame buffer's buffer_id. */
+int amdgpu_get_fb_id(amdgpu_device_handle dev, unsigned int *fb_id)
+{
+ drmModeResPtr mode_res;
+ int count_crtcs;
+ drmModeCrtcPtr mode_crtc;
+ int current_id = 0;
+ drmModeFBPtr fbcur;
+ struct drm_amdgpu_gem_create_in bo_info = {};
+ struct drm_amdgpu_gem_op gem_op = {};
+ int r = 0;
+ int i;
+ struct amdgpu_bo *bo = NULL;
+ int flag_auth = 0;
+ int fd = dev->fd;
+
+ amdgpu_get_auth(dev->fd, &flag_auth);
+ if (flag_auth) {
+ fd = dev->fd;
+ } else {
+ amdgpu_get_auth(dev->flink_fd, &flag_auth);
+ if (flag_auth) {
+ fd = dev->flink_fd;
+ } else {
+ fprintf(stderr, "amdgpu: amdgpu_get_fb_id, couldn't get the auth fd\n");
+ return EINVAL;
+ }
+ }
+
+ mode_res = drmModeGetResources(fd);
+ if (!mode_res)
+ return EFAULT;
+
+ count_crtcs = mode_res->count_crtcs;
+ for (i = 0; i < mode_res->count_crtcs; i++) {
+ mode_crtc = drmModeGetCrtc(fd, mode_res->crtcs[i]);
+ if (mode_crtc) {
+ if (mode_crtc->buffer_id) {
+ current_id = mode_crtc->buffer_id;
+ drmModeFreeCrtc(mode_crtc);
+ break;
+ }
+ drmModeFreeCrtc(mode_crtc);
+ }
+ }
+ *fb_id = current_id;
+ drmModeFreeResources(mode_res);
+
+ return r;
+}
+
int amdgpu_bo_free(amdgpu_bo_handle buf_handle)
{
/* Just drop the reference. */