[PATCH xf86-video-amdgpu 07/11] Factor out amdgpu_bo_get_handle helper
Michel Dänzer
michel at daenzer.net
Wed Jun 10 02:04:22 PDT 2015
From: Michel Dänzer <michel.daenzer at amd.com>
The helper transparently handles BOs allocated from GBM and
libdrm_amdgpu.
Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
---
src/amdgpu_bo_helper.c | 11 +++++++++++
src/amdgpu_bo_helper.h | 2 ++
src/amdgpu_glamor.c | 18 ++++++++++--------
src/drmmode_display.c | 32 ++++++++++----------------------
4 files changed, 33 insertions(+), 30 deletions(-)
diff --git a/src/amdgpu_bo_helper.c b/src/amdgpu_bo_helper.c
index 54270c6..47cd9eb 100644
--- a/src/amdgpu_bo_helper.c
+++ b/src/amdgpu_bo_helper.c
@@ -118,6 +118,17 @@ struct amdgpu_buffer *amdgpu_alloc_pixmap_bo(ScrnInfoPtr pScrn, int width,
return pixmap_buffer;
}
+Bool amdgpu_bo_get_handle(struct amdgpu_buffer *bo, uint32_t *handle)
+{
+ if (bo->flags & AMDGPU_BO_FLAGS_GBM) {
+ *handle = gbm_bo_get_handle(bo->bo.gbm).u32;
+ return TRUE;
+ }
+
+ return amdgpu_bo_export(bo->bo.amdgpu, amdgpu_bo_handle_type_kms,
+ handle) == 0;
+}
+
int amdgpu_bo_map(ScrnInfoPtr pScrn, struct amdgpu_buffer *bo)
{
AMDGPUInfoPtr info = AMDGPUPTR(pScrn);
diff --git a/src/amdgpu_bo_helper.h b/src/amdgpu_bo_helper.h
index 8270d39..4dae200 100644
--- a/src/amdgpu_bo_helper.h
+++ b/src/amdgpu_bo_helper.h
@@ -29,6 +29,8 @@ extern struct amdgpu_buffer *amdgpu_alloc_pixmap_bo(ScrnInfoPtr pScrn, int width
int height, int depth, int usage_hint,
int bitsPerPixel, int *new_pitch);
+extern Bool amdgpu_bo_get_handle(struct amdgpu_buffer *bo, uint32_t *handle);
+
extern int amdgpu_bo_map(ScrnInfoPtr pScrn, struct amdgpu_buffer *bo);
extern void amdgpu_bo_unmap(struct amdgpu_buffer *bo);
diff --git a/src/amdgpu_glamor.c b/src/amdgpu_glamor.c
index 7c45f34..d91effc 100644
--- a/src/amdgpu_glamor.c
+++ b/src/amdgpu_glamor.c
@@ -55,7 +55,7 @@ Bool amdgpu_glamor_create_screen_resources(ScreenPtr screen)
{
ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
AMDGPUInfoPtr info = AMDGPUPTR(scrn);
- union gbm_bo_handle bo_handle;
+ uint32_t bo_handle;
if (!info->use_glamor)
return TRUE;
@@ -65,9 +65,9 @@ Bool amdgpu_glamor_create_screen_resources(ScreenPtr screen)
return FALSE;
#endif
- bo_handle = gbm_bo_get_handle(info->front_buffer->bo.gbm);
- if (!glamor_egl_create_textured_screen_ext(screen,
- bo_handle.u32,
+ if (!amdgpu_bo_get_handle(info->front_buffer, &bo_handle) ||
+ !glamor_egl_create_textured_screen_ext(screen,
+ bo_handle,
scrn->displayWidth *
info->pixel_bytes, NULL)) {
return FALSE;
@@ -131,7 +131,7 @@ amdgpu_glamor_create_textured_pixmap(PixmapPtr pixmap, struct amdgpu_pixmap *pri
{
ScrnInfoPtr scrn = xf86ScreenToScrn(pixmap->drawable.pScreen);
AMDGPUInfoPtr info = AMDGPUPTR(scrn);
- union gbm_bo_handle bo_handle;
+ uint32_t bo_handle;
if ((info->use_glamor) == 0)
return TRUE;
@@ -139,9 +139,11 @@ amdgpu_glamor_create_textured_pixmap(PixmapPtr pixmap, struct amdgpu_pixmap *pri
if (!priv->stride)
priv->stride = pixmap->devKind;
- bo_handle = gbm_bo_get_handle(priv->bo->bo.gbm);
- return glamor_egl_create_textured_pixmap(pixmap, bo_handle.u32,
- priv->stride);
+ if (!amdgpu_bo_get_handle(priv->bo, &bo_handle))
+ return FALSE;
+
+ return glamor_egl_create_textured_pixmap(pixmap, bo_handle,
+ pixmap->devKind);
}
#ifndef CREATE_PIXMAP_USAGE_SHARED
diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index d855787..1fcf901 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -420,18 +420,12 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
int i;
int fb_id;
drmModeModeInfo kmode;
- union gbm_bo_handle bo_handle;
+ uint32_t bo_handle;
if (drmmode->fb_id == 0) {
- if (info->gbm) {
- bo_handle = gbm_bo_get_handle(info->front_buffer->bo.gbm);
- } else {
- if (amdgpu_bo_export(info->front_buffer->bo.amdgpu,
- amdgpu_bo_handle_type_kms,
- &bo_handle.u32)) {
- ErrorF("failed to get BO handle for FB\n");
- return FALSE;
- }
+ if (!amdgpu_bo_get_handle(info->front_buffer, &bo_handle)) {
+ ErrorF("failed to get BO handle for FB\n");
+ return FALSE;
}
ret = drmModeAddFB(drmmode->fd,
@@ -439,7 +433,7 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
pScrn->virtualY,
pScrn->depth, pScrn->bitsPerPixel,
pScrn->displayWidth * info->pixel_bytes,
- bo_handle.u32, &drmmode->fb_id);
+ bo_handle, &drmmode->fb_id);
if (ret < 0) {
ErrorF("failed to add fb\n");
return FALSE;
@@ -595,20 +589,14 @@ static void drmmode_show_cursor(xf86CrtcPtr crtc)
AMDGPUInfoPtr info = AMDGPUPTR(pScrn);
drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
drmmode_ptr drmmode = drmmode_crtc->drmmode;
- union gbm_bo_handle bo_handle;
+ uint32_t bo_handle;
- if (info->gbm) {
- bo_handle = gbm_bo_get_handle(drmmode_crtc->cursor_buffer->bo.gbm);
- } else {
- if (amdgpu_bo_export(drmmode_crtc->cursor_buffer->bo.amdgpu,
- amdgpu_bo_handle_type_kms,
- &bo_handle.u32)) {
- ErrorF("failed to get BO handle for cursor\n");
- return;
- }
+ if (!amdgpu_bo_get_handle(drmmode_crtc->cursor_buffer, &bo_handle)) {
+ ErrorF("failed to get BO handle for cursor\n");
+ return;
}
- drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, bo_handle.u32,
+ drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, bo_handle,
info->cursor_w, info->cursor_h);
}
--
2.1.4
More information about the xorg-driver-ati
mailing list