amdgpu_pixmap.h revision 504d986f
1/* 2 * Copyright © 2014 Advanced Micro Devices, Inc. 3 * 4 * Permission is hereby granted, free of charge, to any person 5 * obtaining a copy of this software and associated documentation 6 * files (the "Software"), to deal in the Software without 7 * restriction, including without limitation the rights to use, copy, 8 * modify, merge, publish, distribute, sublicense, and/or sell copies 9 * of the Software, and to permit persons to whom the Software is 10 * furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice (including 13 * the next paragraph) shall be included in all copies or substantial 14 * portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 * DEALINGS IN THE SOFTWARE. 24 */ 25 26#ifndef AMDGPU_PIXMAP_H 27#define AMDGPU_PIXMAP_H 28 29#include "amdgpu_drv.h" 30 31struct amdgpu_pixmap { 32 uint_fast32_t gpu_read; 33 uint_fast32_t gpu_write; 34 35 uint64_t tiling_info; 36 37 struct amdgpu_buffer *bo; 38 39 /* GEM handle for pixmaps shared via DRI2/3 */ 40 Bool handle_valid; 41 uint32_t handle; 42}; 43 44extern DevPrivateKeyRec amdgpu_pixmap_index; 45 46static inline struct amdgpu_pixmap *amdgpu_get_pixmap_private(PixmapPtr pixmap) 47{ 48 return dixGetPrivate(&pixmap->devPrivates, &amdgpu_pixmap_index); 49} 50 51static inline void amdgpu_set_pixmap_private(PixmapPtr pixmap, 52 struct amdgpu_pixmap *priv) 53{ 54 dixSetPrivate(&pixmap->devPrivates, &amdgpu_pixmap_index, priv); 55} 56 57static inline Bool amdgpu_set_pixmap_bo(PixmapPtr pPix, struct amdgpu_buffer *bo) 58{ 59 struct amdgpu_pixmap *priv; 60 61 priv = amdgpu_get_pixmap_private(pPix); 62 if (priv == NULL && bo == NULL) 63 return TRUE; 64 65 if (priv) { 66 if (priv->bo) { 67 if (priv->bo == bo) 68 return TRUE; 69 70 amdgpu_bo_unref(&priv->bo); 71 priv->handle_valid = FALSE; 72 } 73 74 if (!bo) { 75 free(priv); 76 priv = NULL; 77 } 78 } 79 80 if (bo) { 81 if (!priv) { 82 priv = calloc(1, sizeof(struct amdgpu_pixmap)); 83 if (!priv) 84 return FALSE; 85 } 86 amdgpu_bo_ref(bo); 87 priv->bo = bo; 88 } 89 90 amdgpu_set_pixmap_private(pPix, priv); 91 return TRUE; 92} 93 94static inline struct amdgpu_buffer *amdgpu_get_pixmap_bo(PixmapPtr pPix) 95{ 96 struct amdgpu_pixmap *priv; 97 priv = amdgpu_get_pixmap_private(pPix); 98 return priv ? priv->bo : NULL; 99} 100 101enum { 102 AMDGPU_CREATE_PIXMAP_DRI2 = 0x08000000, 103 AMDGPU_CREATE_PIXMAP_LINEAR = 0x04000000, 104 AMDGPU_CREATE_PIXMAP_SCANOUT = 0x02000000, 105 AMDGPU_CREATE_PIXMAP_GTT = 0x01000000, 106}; 107 108extern Bool amdgpu_pixmap_init(ScreenPtr screen); 109 110#endif /* AMDGPU_PIXMAP_H */ 111