amdgpu_glamor.c revision 504d986f
1d6c0b56eSmrg/* 2d6c0b56eSmrg * Copyright © 2011 Intel Corporation. 3d6c0b56eSmrg * 2012 Advanced Micro Devices, Inc. 4d6c0b56eSmrg * 5d6c0b56eSmrg * Permission is hereby granted, free of charge, to any person 6d6c0b56eSmrg * obtaining a copy of this software and associated documentation 7d6c0b56eSmrg * files (the "Software"), to deal in the Software without 8d6c0b56eSmrg * restriction, including without limitation the rights to use, copy, 9d6c0b56eSmrg * modify, merge, publish, distribute, sublicense, and/or sell copies 10d6c0b56eSmrg * of the Software, and to permit persons to whom the Software is 11d6c0b56eSmrg * furnished to do so, subject to the following conditions: 12d6c0b56eSmrg * 13d6c0b56eSmrg * The above copyright notice and this permission notice (including 14d6c0b56eSmrg * the next paragraph) shall be included in all copies or substantial 15d6c0b56eSmrg * portions of the Software. 16d6c0b56eSmrg * 17d6c0b56eSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18d6c0b56eSmrg * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19d6c0b56eSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20d6c0b56eSmrg * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21d6c0b56eSmrg * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22d6c0b56eSmrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23d6c0b56eSmrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24d6c0b56eSmrg * DEALINGS IN THE SOFTWARE. 25d6c0b56eSmrg */ 26d6c0b56eSmrg 27d6c0b56eSmrg#ifdef HAVE_CONFIG_H 28d6c0b56eSmrg#include "config.h" 29d6c0b56eSmrg#endif 30d6c0b56eSmrg 31d6c0b56eSmrg#include <xf86.h> 32d6c0b56eSmrg 33d6c0b56eSmrg#include "amdgpu_bo_helper.h" 34d6c0b56eSmrg#include "amdgpu_pixmap.h" 35d6c0b56eSmrg#include "amdgpu_glamor.h" 36d6c0b56eSmrg 37d6c0b56eSmrg#include <gbm.h> 38d6c0b56eSmrg 39d6c0b56eSmrg#include <GL/gl.h> 40d6c0b56eSmrg 41d6c0b56eSmrgDevPrivateKeyRec amdgpu_pixmap_index; 42d6c0b56eSmrg 43d6c0b56eSmrgvoid amdgpu_glamor_exchange_buffers(PixmapPtr src, PixmapPtr dst) 44d6c0b56eSmrg{ 45d6c0b56eSmrg AMDGPUInfoPtr info = AMDGPUPTR(xf86ScreenToScrn(dst->drawable.pScreen)); 46d6c0b56eSmrg 47d6c0b56eSmrg if (!info->use_glamor) 48d6c0b56eSmrg return; 49d6c0b56eSmrg glamor_egl_exchange_buffers(src, dst); 50d6c0b56eSmrg} 51d6c0b56eSmrg 52d6c0b56eSmrgBool amdgpu_glamor_create_screen_resources(ScreenPtr screen) 53d6c0b56eSmrg{ 54d6c0b56eSmrg ScrnInfoPtr scrn = xf86ScreenToScrn(screen); 55d6c0b56eSmrg AMDGPUInfoPtr info = AMDGPUPTR(scrn); 56d6c0b56eSmrg uint32_t bo_handle; 57d6c0b56eSmrg 58d6c0b56eSmrg if (!info->use_glamor) 59d6c0b56eSmrg return TRUE; 60d6c0b56eSmrg 61d6c0b56eSmrg#ifdef HAVE_GLAMOR_GLYPHS_INIT 62d6c0b56eSmrg if (!glamor_glyphs_init(screen)) 63d6c0b56eSmrg return FALSE; 64d6c0b56eSmrg#endif 65d6c0b56eSmrg 66d6c0b56eSmrg if (!amdgpu_bo_get_handle(info->front_buffer, &bo_handle) || 67d6c0b56eSmrg !glamor_egl_create_textured_screen_ext(screen, 68d6c0b56eSmrg bo_handle, 69d6c0b56eSmrg scrn->displayWidth * 70d6c0b56eSmrg info->pixel_bytes, NULL)) { 71d6c0b56eSmrg return FALSE; 72d6c0b56eSmrg } 73d6c0b56eSmrg 74d6c0b56eSmrg return TRUE; 75d6c0b56eSmrg} 76d6c0b56eSmrg 77d6c0b56eSmrgBool amdgpu_glamor_pre_init(ScrnInfoPtr scrn) 78d6c0b56eSmrg{ 79d6c0b56eSmrg AMDGPUInfoPtr info = AMDGPUPTR(scrn); 80d6c0b56eSmrg pointer glamor_module; 81d6c0b56eSmrg CARD32 version; 82d6c0b56eSmrg 83d6c0b56eSmrg if (!info->dri2.available) 84d6c0b56eSmrg return FALSE; 85d6c0b56eSmrg 86d6c0b56eSmrg if (scrn->depth < 24) { 87d6c0b56eSmrg xf86DrvMsg(scrn->scrnIndex, X_ERROR, 88d6c0b56eSmrg "glamor requires depth >= 24, disabling.\n"); 89d6c0b56eSmrg return FALSE; 90d6c0b56eSmrg } 91d6c0b56eSmrg#if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(1,15,0,0,0) 92d6c0b56eSmrg if (!xf86LoaderCheckSymbol("glamor_egl_init")) { 93d6c0b56eSmrg xf86DrvMsg(scrn->scrnIndex, X_ERROR, 94d6c0b56eSmrg "glamor requires Load \"glamoregl\" in " 95d6c0b56eSmrg "Section \"Module\", disabling.\n"); 96d6c0b56eSmrg return FALSE; 97d6c0b56eSmrg } 98d6c0b56eSmrg#endif 99d6c0b56eSmrg 100d6c0b56eSmrg /* Load glamor module */ 101d6c0b56eSmrg if ((glamor_module = xf86LoadSubModule(scrn, GLAMOR_EGL_MODULE_NAME))) { 102d6c0b56eSmrg version = xf86GetModuleVersion(glamor_module); 103d6c0b56eSmrg if (version < MODULE_VERSION_NUMERIC(0, 3, 1)) { 104d6c0b56eSmrg xf86DrvMsg(scrn->scrnIndex, X_ERROR, 105d6c0b56eSmrg "Incompatible glamor version, required >= 0.3.0.\n"); 106d6c0b56eSmrg return FALSE; 107d6c0b56eSmrg } else { 108d6c0b56eSmrg AMDGPUEntPtr pAMDGPUEnt = AMDGPUEntPriv(scrn); 109d6c0b56eSmrg 110d6c0b56eSmrg if (glamor_egl_init(scrn, pAMDGPUEnt->fd)) { 111d6c0b56eSmrg xf86DrvMsg(scrn->scrnIndex, X_INFO, 112d6c0b56eSmrg "glamor detected, initialising EGL layer.\n"); 113d6c0b56eSmrg } else { 114d6c0b56eSmrg xf86DrvMsg(scrn->scrnIndex, X_ERROR, 115d6c0b56eSmrg "glamor detected, failed to initialize EGL.\n"); 116d6c0b56eSmrg return FALSE; 117d6c0b56eSmrg } 118d6c0b56eSmrg } 119d6c0b56eSmrg } else { 120d6c0b56eSmrg xf86DrvMsg(scrn->scrnIndex, X_ERROR, "glamor not available\n"); 121d6c0b56eSmrg return FALSE; 122d6c0b56eSmrg } 123d6c0b56eSmrg 124d6c0b56eSmrg info->use_glamor = TRUE; 125d6c0b56eSmrg 126d6c0b56eSmrg return TRUE; 127d6c0b56eSmrg} 128d6c0b56eSmrg 129d6c0b56eSmrgBool 130504d986fSmrgamdgpu_glamor_create_textured_pixmap(PixmapPtr pixmap, struct amdgpu_buffer *bo) 131d6c0b56eSmrg{ 132d6c0b56eSmrg ScrnInfoPtr scrn = xf86ScreenToScrn(pixmap->drawable.pScreen); 133d6c0b56eSmrg AMDGPUInfoPtr info = AMDGPUPTR(scrn); 134d6c0b56eSmrg uint32_t bo_handle; 135d6c0b56eSmrg 136d6c0b56eSmrg if ((info->use_glamor) == 0) 137d6c0b56eSmrg return TRUE; 138d6c0b56eSmrg 139504d986fSmrg if (!amdgpu_bo_get_handle(bo, &bo_handle)) 140d6c0b56eSmrg return FALSE; 141d6c0b56eSmrg 142d6c0b56eSmrg return glamor_egl_create_textured_pixmap(pixmap, bo_handle, 143d6c0b56eSmrg pixmap->devKind); 144d6c0b56eSmrg} 145d6c0b56eSmrg 146d6c0b56eSmrgstatic Bool amdgpu_glamor_destroy_pixmap(PixmapPtr pixmap) 147d6c0b56eSmrg{ 148d6c0b56eSmrg#ifndef HAVE_GLAMOR_EGL_DESTROY_TEXTURED_PIXMAP 149d6c0b56eSmrg ScreenPtr screen = pixmap->drawable.pScreen; 150d6c0b56eSmrg AMDGPUInfoPtr info = AMDGPUPTR(xf86ScreenToScrn(screen)); 151d6c0b56eSmrg Bool ret; 152d6c0b56eSmrg#endif 153d6c0b56eSmrg 154d6c0b56eSmrg if (pixmap->refcnt == 1) { 155d6c0b56eSmrg if (pixmap->devPrivate.ptr) { 156d6c0b56eSmrg struct amdgpu_buffer *bo = amdgpu_get_pixmap_bo(pixmap); 157d6c0b56eSmrg 158d6c0b56eSmrg if (bo) 159d6c0b56eSmrg amdgpu_bo_unmap(bo); 160d6c0b56eSmrg } 161d6c0b56eSmrg 162d6c0b56eSmrg#ifdef HAVE_GLAMOR_EGL_DESTROY_TEXTURED_PIXMAP 163d6c0b56eSmrg glamor_egl_destroy_textured_pixmap(pixmap); 164d6c0b56eSmrg#endif 165d6c0b56eSmrg amdgpu_set_pixmap_bo(pixmap, NULL); 166d6c0b56eSmrg } 167d6c0b56eSmrg 168d6c0b56eSmrg#ifdef HAVE_GLAMOR_EGL_DESTROY_TEXTURED_PIXMAP 169d6c0b56eSmrg fbDestroyPixmap(pixmap); 170d6c0b56eSmrg return TRUE; 171d6c0b56eSmrg#else 172d6c0b56eSmrg screen->DestroyPixmap = info->glamor.SavedDestroyPixmap; 173d6c0b56eSmrg ret = screen->DestroyPixmap(pixmap); 174d6c0b56eSmrg info->glamor.SavedDestroyPixmap = screen->DestroyPixmap; 175d6c0b56eSmrg screen->DestroyPixmap = amdgpu_glamor_destroy_pixmap; 176d6c0b56eSmrg 177d6c0b56eSmrg return ret; 178d6c0b56eSmrg#endif 179d6c0b56eSmrg} 180d6c0b56eSmrg 181d6c0b56eSmrgstatic PixmapPtr 182d6c0b56eSmrgamdgpu_glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth, 183d6c0b56eSmrg unsigned usage) 184d6c0b56eSmrg{ 185d6c0b56eSmrg ScrnInfoPtr scrn = xf86ScreenToScrn(screen); 186d6c0b56eSmrg AMDGPUInfoPtr info = AMDGPUPTR(scrn); 187d6c0b56eSmrg struct amdgpu_pixmap *priv; 188d6c0b56eSmrg PixmapPtr pixmap, new_pixmap = NULL; 189d6c0b56eSmrg 190d6c0b56eSmrg if (!AMDGPU_CREATE_PIXMAP_SHARED(usage)) { 191d6c0b56eSmrg if (info->shadow_primary) { 192d6c0b56eSmrg if (usage != CREATE_PIXMAP_USAGE_BACKING_PIXMAP) 193d6c0b56eSmrg return fbCreatePixmap(screen, w, h, depth, usage); 194d6c0b56eSmrg 195d6c0b56eSmrg usage |= AMDGPU_CREATE_PIXMAP_LINEAR | 196d6c0b56eSmrg AMDGPU_CREATE_PIXMAP_GTT; 197d6c0b56eSmrg } else { 198d6c0b56eSmrg pixmap = glamor_create_pixmap(screen, w, h, depth, usage); 199d6c0b56eSmrg if (pixmap) 200d6c0b56eSmrg return pixmap; 201d6c0b56eSmrg } 202d6c0b56eSmrg } 203d6c0b56eSmrg 204d6c0b56eSmrg if (w > 32767 || h > 32767) 205d6c0b56eSmrg return NullPixmap; 206d6c0b56eSmrg 207d6c0b56eSmrg if (depth == 1) 208d6c0b56eSmrg return fbCreatePixmap(screen, w, h, depth, usage); 209d6c0b56eSmrg 210d6c0b56eSmrg if (usage == CREATE_PIXMAP_USAGE_GLYPH_PICTURE && w <= 32 && h <= 32) 211d6c0b56eSmrg return fbCreatePixmap(screen, w, h, depth, usage); 212d6c0b56eSmrg 213d6c0b56eSmrg pixmap = fbCreatePixmap(screen, 0, 0, depth, usage); 214d6c0b56eSmrg if (pixmap == NullPixmap) 215d6c0b56eSmrg return pixmap; 216d6c0b56eSmrg 217d6c0b56eSmrg if (w && h) { 218d6c0b56eSmrg int stride; 219d6c0b56eSmrg 220d6c0b56eSmrg priv = calloc(1, sizeof(struct amdgpu_pixmap)); 221d6c0b56eSmrg if (priv == NULL) 222d6c0b56eSmrg goto fallback_pixmap; 223d6c0b56eSmrg 224d6c0b56eSmrg priv->bo = amdgpu_alloc_pixmap_bo(scrn, w, h, depth, usage, 225d6c0b56eSmrg pixmap->drawable.bitsPerPixel, 226d6c0b56eSmrg &stride); 227d6c0b56eSmrg if (!priv->bo) 228d6c0b56eSmrg goto fallback_priv; 229d6c0b56eSmrg 230d6c0b56eSmrg amdgpu_set_pixmap_private(pixmap, priv); 231d6c0b56eSmrg 232d6c0b56eSmrg screen->ModifyPixmapHeader(pixmap, w, h, 0, 0, stride, NULL); 233d6c0b56eSmrg 234d6c0b56eSmrg pixmap->devPrivate.ptr = NULL; 235d6c0b56eSmrg 236504d986fSmrg if (!amdgpu_glamor_create_textured_pixmap(pixmap, priv->bo)) 237d6c0b56eSmrg goto fallback_glamor; 238d6c0b56eSmrg } 239d6c0b56eSmrg 240d6c0b56eSmrg return pixmap; 241d6c0b56eSmrg 242d6c0b56eSmrgfallback_glamor: 243d6c0b56eSmrg if (AMDGPU_CREATE_PIXMAP_SHARED(usage)) { 244d6c0b56eSmrg /* XXX need further work to handle the DRI2 failure case. 245d6c0b56eSmrg * Glamor don't know how to handle a BO only pixmap. Put 246d6c0b56eSmrg * a warning indicator here. 247d6c0b56eSmrg */ 248d6c0b56eSmrg xf86DrvMsg(scrn->scrnIndex, X_WARNING, 249d6c0b56eSmrg "Failed to create textured DRI2/PRIME pixmap."); 250d6c0b56eSmrg 251d6c0b56eSmrg amdgpu_glamor_destroy_pixmap(pixmap); 252d6c0b56eSmrg return NullPixmap; 253d6c0b56eSmrg } 254d6c0b56eSmrg /* Create textured pixmap failed means glamor failed to 255d6c0b56eSmrg * create a texture from current BO for some reasons. We turn 256d6c0b56eSmrg * to create a new glamor pixmap and clean up current one. 257d6c0b56eSmrg * One thing need to be noted, this new pixmap doesn't 258d6c0b56eSmrg * has a priv and bo attached to it. It's glamor's responsbility 259d6c0b56eSmrg * to take care of it. Glamor will mark this new pixmap as a 260d6c0b56eSmrg * texture only pixmap and will never fallback to DDX layer 261d6c0b56eSmrg * afterwards. 262d6c0b56eSmrg */ 263d6c0b56eSmrg new_pixmap = glamor_create_pixmap(screen, w, h, depth, usage); 264d6c0b56eSmrg amdgpu_bo_unref(&priv->bo); 265d6c0b56eSmrgfallback_priv: 266d6c0b56eSmrg free(priv); 267d6c0b56eSmrgfallback_pixmap: 268d6c0b56eSmrg fbDestroyPixmap(pixmap); 269d6c0b56eSmrg if (new_pixmap) 270d6c0b56eSmrg return new_pixmap; 271d6c0b56eSmrg else 272d6c0b56eSmrg return fbCreatePixmap(screen, w, h, depth, usage); 273d6c0b56eSmrg} 274d6c0b56eSmrg 275504d986fSmrgPixmapPtr 276504d986fSmrgamdgpu_glamor_set_pixmap_bo(DrawablePtr drawable, PixmapPtr pixmap) 277504d986fSmrg{ 278504d986fSmrg PixmapPtr old = get_drawable_pixmap(drawable); 279504d986fSmrg ScreenPtr screen = drawable->pScreen; 280504d986fSmrg struct amdgpu_pixmap *priv = amdgpu_get_pixmap_private(pixmap); 281504d986fSmrg GCPtr gc; 282504d986fSmrg 283504d986fSmrg /* With a glamor pixmap, 2D pixmaps are created in texture 284504d986fSmrg * and without a static BO attached to it. To support DRI, 285504d986fSmrg * we need to create a new textured-drm pixmap and 286504d986fSmrg * need to copy the original content to this new textured-drm 287504d986fSmrg * pixmap, and then convert the old pixmap to a coherent 288504d986fSmrg * textured-drm pixmap which has a valid BO attached to it 289504d986fSmrg * and also has a valid texture, thus both glamor and DRI2 290504d986fSmrg * can access it. 291504d986fSmrg * 292504d986fSmrg */ 293504d986fSmrg 294504d986fSmrg /* Copy the current contents of the pixmap to the bo. */ 295504d986fSmrg gc = GetScratchGC(drawable->depth, screen); 296504d986fSmrg if (gc) { 297504d986fSmrg ValidateGC(&pixmap->drawable, gc); 298504d986fSmrg gc->ops->CopyArea(&old->drawable, &pixmap->drawable, 299504d986fSmrg gc, 300504d986fSmrg 0, 0, 301504d986fSmrg old->drawable.width, 302504d986fSmrg old->drawable.height, 0, 0); 303504d986fSmrg FreeScratchGC(gc); 304504d986fSmrg } 305504d986fSmrg 306504d986fSmrg /* And redirect the pixmap to the new bo (for 3D). */ 307504d986fSmrg glamor_egl_exchange_buffers(old, pixmap); 308504d986fSmrg amdgpu_set_pixmap_private(pixmap, amdgpu_get_pixmap_private(old)); 309504d986fSmrg amdgpu_set_pixmap_private(old, priv); 310504d986fSmrg 311504d986fSmrg screen->ModifyPixmapHeader(old, 312504d986fSmrg old->drawable.width, 313504d986fSmrg old->drawable.height, 314504d986fSmrg 0, 0, pixmap->devKind, NULL); 315504d986fSmrg old->devPrivate.ptr = NULL; 316504d986fSmrg 317504d986fSmrg screen->DestroyPixmap(pixmap); 318504d986fSmrg 319504d986fSmrg return old; 320504d986fSmrg} 321504d986fSmrg 322d6c0b56eSmrg#ifdef AMDGPU_PIXMAP_SHARING 323d6c0b56eSmrg 324d6c0b56eSmrgstatic Bool 325d6c0b56eSmrgamdgpu_glamor_share_pixmap_backing(PixmapPtr pixmap, ScreenPtr slave, 326d6c0b56eSmrg void **handle_p) 327d6c0b56eSmrg{ 328504d986fSmrg ScreenPtr screen = pixmap->drawable.pScreen; 329504d986fSmrg uint64_t tiling_info; 330504d986fSmrg CARD16 stride; 331504d986fSmrg CARD32 size; 332504d986fSmrg int fd; 333504d986fSmrg 334504d986fSmrg tiling_info = amdgpu_pixmap_get_tiling_info(pixmap); 335504d986fSmrg if (AMDGPU_TILING_GET(tiling_info, ARRAY_MODE) != 0) { 336504d986fSmrg PixmapPtr linear; 337504d986fSmrg 338504d986fSmrg /* We don't want to re-allocate the screen pixmap as 339504d986fSmrg * linear, to avoid trouble with page flipping 340504d986fSmrg */ 341504d986fSmrg if (screen->GetScreenPixmap(screen) == pixmap) 342504d986fSmrg return FALSE; 343d6c0b56eSmrg 344504d986fSmrg linear = screen->CreatePixmap(screen, pixmap->drawable.width, 345504d986fSmrg pixmap->drawable.height, 346504d986fSmrg pixmap->drawable.depth, 347504d986fSmrg CREATE_PIXMAP_USAGE_SHARED); 348504d986fSmrg if (!linear) 349504d986fSmrg return FALSE; 350504d986fSmrg 351504d986fSmrg amdgpu_glamor_set_pixmap_bo(&pixmap->drawable, linear); 352504d986fSmrg } 353504d986fSmrg 354504d986fSmrg fd = glamor_fd_from_pixmap(screen, pixmap, &stride, &size); 355504d986fSmrg if (fd < 0) 356d6c0b56eSmrg return FALSE; 357d6c0b56eSmrg 358504d986fSmrg *handle_p = (void *)(long)fd; 359504d986fSmrg return TRUE; 360d6c0b56eSmrg} 361d6c0b56eSmrg 362d6c0b56eSmrgstatic Bool 363d6c0b56eSmrgamdgpu_glamor_set_shared_pixmap_backing(PixmapPtr pixmap, void *handle) 364d6c0b56eSmrg{ 365d6c0b56eSmrg ScreenPtr screen = pixmap->drawable.pScreen; 366d6c0b56eSmrg ScrnInfoPtr scrn = xf86ScreenToScrn(screen); 367d6c0b56eSmrg struct amdgpu_pixmap *priv; 368d6c0b56eSmrg 369d6c0b56eSmrg if (!amdgpu_set_shared_pixmap_backing(pixmap, handle)) 370d6c0b56eSmrg return FALSE; 371d6c0b56eSmrg 372d6c0b56eSmrg priv = amdgpu_get_pixmap_private(pixmap); 373d6c0b56eSmrg 374504d986fSmrg if (!amdgpu_glamor_create_textured_pixmap(pixmap, priv->bo)) { 375d6c0b56eSmrg xf86DrvMsg(scrn->scrnIndex, X_ERROR, 376d6c0b56eSmrg "Failed to get PRIME drawable for glamor pixmap.\n"); 377d6c0b56eSmrg return FALSE; 378d6c0b56eSmrg } 379d6c0b56eSmrg 380d6c0b56eSmrg screen->ModifyPixmapHeader(pixmap, 381d6c0b56eSmrg pixmap->drawable.width, 382d6c0b56eSmrg pixmap->drawable.height, 383d6c0b56eSmrg 0, 0, 0, NULL); 384d6c0b56eSmrg 385d6c0b56eSmrg return TRUE; 386d6c0b56eSmrg} 387d6c0b56eSmrg 388d6c0b56eSmrg#endif /* AMDGPU_PIXMAP_SHARING */ 389d6c0b56eSmrg 390d6c0b56eSmrgBool amdgpu_glamor_init(ScreenPtr screen) 391d6c0b56eSmrg{ 392d6c0b56eSmrg ScrnInfoPtr scrn = xf86ScreenToScrn(screen); 393d6c0b56eSmrg AMDGPUInfoPtr info = AMDGPUPTR(scrn); 394d6c0b56eSmrg#ifdef RENDER 395d6c0b56eSmrg#ifdef HAVE_FBGLYPHS 396d6c0b56eSmrg UnrealizeGlyphProcPtr SavedUnrealizeGlyph = NULL; 397d6c0b56eSmrg#endif 398d6c0b56eSmrg PictureScreenPtr ps = NULL; 399d6c0b56eSmrg 400d6c0b56eSmrg if (info->shadow_primary) { 401d6c0b56eSmrg ps = GetPictureScreenIfSet(screen); 402d6c0b56eSmrg 403d6c0b56eSmrg if (ps) { 404d6c0b56eSmrg#ifdef HAVE_FBGLYPHS 405d6c0b56eSmrg SavedUnrealizeGlyph = ps->UnrealizeGlyph; 406d6c0b56eSmrg#endif 407d6c0b56eSmrg info->glamor.SavedGlyphs = ps->Glyphs; 408d6c0b56eSmrg info->glamor.SavedTriangles = ps->Triangles; 409d6c0b56eSmrg info->glamor.SavedTrapezoids = ps->Trapezoids; 410d6c0b56eSmrg } 411d6c0b56eSmrg } 412d6c0b56eSmrg#endif /* RENDER */ 413d6c0b56eSmrg 414d6c0b56eSmrg if (!glamor_init(screen, GLAMOR_USE_EGL_SCREEN | GLAMOR_USE_SCREEN | 415d6c0b56eSmrg GLAMOR_USE_PICTURE_SCREEN | GLAMOR_INVERTED_Y_AXIS | 416d6c0b56eSmrg GLAMOR_NO_DRI3)) { 417d6c0b56eSmrg xf86DrvMsg(scrn->scrnIndex, X_ERROR, 418d6c0b56eSmrg "Failed to initialize glamor.\n"); 419d6c0b56eSmrg return FALSE; 420d6c0b56eSmrg } 421d6c0b56eSmrg 422d6c0b56eSmrg if (!glamor_egl_init_textured_pixmap(screen)) { 423d6c0b56eSmrg xf86DrvMsg(scrn->scrnIndex, X_ERROR, 424d6c0b56eSmrg "Failed to initialize textured pixmap of screen for glamor.\n"); 425d6c0b56eSmrg return FALSE; 426d6c0b56eSmrg } 427d6c0b56eSmrg if (!dixRegisterPrivateKey(&amdgpu_pixmap_index, PRIVATE_PIXMAP, 0)) 428d6c0b56eSmrg return FALSE; 429d6c0b56eSmrg 430d6c0b56eSmrg if (info->shadow_primary) 431d6c0b56eSmrg amdgpu_glamor_screen_init(screen); 432d6c0b56eSmrg 433d6c0b56eSmrg#if defined(RENDER) && defined(HAVE_FBGLYPHS) 434d6c0b56eSmrg /* For ShadowPrimary, we need fbUnrealizeGlyph instead of 435d6c0b56eSmrg * glamor_unrealize_glyph 436d6c0b56eSmrg */ 437d6c0b56eSmrg if (ps) 438d6c0b56eSmrg ps->UnrealizeGlyph = SavedUnrealizeGlyph; 439d6c0b56eSmrg#endif 440d6c0b56eSmrg 441d6c0b56eSmrg info->glamor.SavedCreatePixmap = screen->CreatePixmap; 442d6c0b56eSmrg screen->CreatePixmap = amdgpu_glamor_create_pixmap; 443d6c0b56eSmrg info->glamor.SavedDestroyPixmap = screen->DestroyPixmap; 444d6c0b56eSmrg screen->DestroyPixmap = amdgpu_glamor_destroy_pixmap; 445d6c0b56eSmrg#ifdef AMDGPU_PIXMAP_SHARING 446d6c0b56eSmrg info->glamor.SavedSharePixmapBacking = screen->SharePixmapBacking; 447d6c0b56eSmrg screen->SharePixmapBacking = amdgpu_glamor_share_pixmap_backing; 448d6c0b56eSmrg info->glamor.SavedSetSharedPixmapBacking = screen->SetSharedPixmapBacking; 449d6c0b56eSmrg screen->SetSharedPixmapBacking = 450d6c0b56eSmrg amdgpu_glamor_set_shared_pixmap_backing; 451d6c0b56eSmrg#endif 452d6c0b56eSmrg 453d6c0b56eSmrg xf86DrvMsg(scrn->scrnIndex, X_INFO, "Use GLAMOR acceleration.\n"); 454d6c0b56eSmrg return TRUE; 455d6c0b56eSmrg} 456d6c0b56eSmrg 457d6c0b56eSmrgvoid amdgpu_glamor_flush(ScrnInfoPtr pScrn) 458d6c0b56eSmrg{ 459d6c0b56eSmrg AMDGPUInfoPtr info = AMDGPUPTR(pScrn); 460d6c0b56eSmrg 461d6c0b56eSmrg if (info->use_glamor) { 462d6c0b56eSmrg glamor_block_handler(pScrn->pScreen); 463d6c0b56eSmrg } 464504d986fSmrg 465504d986fSmrg info->gpu_flushed++; 466d6c0b56eSmrg} 467d6c0b56eSmrg 468d6c0b56eSmrgvoid amdgpu_glamor_finish(ScrnInfoPtr pScrn) 469d6c0b56eSmrg{ 470d6c0b56eSmrg AMDGPUInfoPtr info = AMDGPUPTR(pScrn); 471d6c0b56eSmrg 472d6c0b56eSmrg if (info->use_glamor) { 473d6c0b56eSmrg amdgpu_glamor_flush(pScrn); 474d6c0b56eSmrg glFinish(); 475d6c0b56eSmrg } 476d6c0b56eSmrg} 477d6c0b56eSmrg 478d6c0b56eSmrgvoid 479d6c0b56eSmrgamdgpu_glamor_fini(ScreenPtr screen) 480d6c0b56eSmrg{ 481d6c0b56eSmrg AMDGPUInfoPtr info = AMDGPUPTR(xf86ScreenToScrn(screen)); 482d6c0b56eSmrg 483d6c0b56eSmrg if (!info->use_glamor) 484d6c0b56eSmrg return; 485d6c0b56eSmrg 486d6c0b56eSmrg screen->CreatePixmap = info->glamor.SavedCreatePixmap; 487d6c0b56eSmrg screen->DestroyPixmap = info->glamor.SavedDestroyPixmap; 488d6c0b56eSmrg#ifdef AMDGPU_PIXMAP_SHARING 489d6c0b56eSmrg screen->SharePixmapBacking = info->glamor.SavedSharePixmapBacking; 490d6c0b56eSmrg screen->SetSharedPixmapBacking = info->glamor.SavedSetSharedPixmapBacking; 491d6c0b56eSmrg#endif 492d6c0b56eSmrg} 493d6c0b56eSmrg 494d6c0b56eSmrgXF86VideoAdaptorPtr amdgpu_glamor_xv_init(ScreenPtr pScreen, int num_adapt) 495d6c0b56eSmrg{ 496d6c0b56eSmrg return glamor_xv_init(pScreen, num_adapt); 497d6c0b56eSmrg} 498