| 1 |
|
| 2 |
d |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#include "glamor_priv.h" |
| 24 |
#include "glamor_prepare.h" |
| 25 |
#include "glamor_transfer.h" |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
static Bool |
| 34 |
glamor_prep_drawable_box(DrawablePtr drawable, glamor_access_t access, BoxPtr box) |
| 35 |
{ |
| 36 |
ScreenPtr screen = drawable->pScreen; |
| 37 |
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen); |
| 38 |
PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable); |
| 39 |
glamor_pixmap_private *priv = glamor_get_pixmap_private(pixmap); |
| 40 |
int gl_access, gl_usage; |
| 41 |
RegionRec region; |
| 42 |
int off_x, off_y; |
| 43 |
|
| 44 |
if (priv->type == GLAMOR_DRM_ONLY) |
| 45 |
return FALSE; |
| 46 |
|
| 47 |
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(priv)) |
| 48 |
return TRUE; |
| 49 |
|
| 50 |
glamor_make_current(glamor_priv); |
| 51 |
|
| 52 |
glamor_get_drawable_deltas(drawable, pixmap, &off_x, &off_y); |
| 53 |
box->x1 += off_x; |
| 54 |
box->x2 += off_x; |
| 55 |
box->y1 += off_y; |
| 56 |
box->y2 += off_y; |
| 57 |
RegionInit(®ion, box, 1); |
| 58 |
|
| 59 |
|
| 60 |
if (pixmap->devPrivate.ptr) { |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
if (!priv->prepared) |
| 67 |
return TRUE; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
RegionSubtract(®ion, ®ion, &priv->prepare_region); |
| 78 |
if (!RegionNotEmpty(®ion)) |
| 79 |
return TRUE; |
| 80 |
|
| 81 |
if (access == GLAMOR_ACCESS_RW) |
| 82 |
FatalError("attempt to remap buffer as writable"); |
| 83 |
|
| 84 |
if (priv->pbo) { |
| 85 |
glBindBuffer(GL_PIXEL_PACK_BUFFER, priv->pbo); |
| 86 |
glUnmapBuffer(GL_PIXEL_PACK_BUFFER); |
| 87 |
pixmap->devPrivate.ptr = NULL; |
| 88 |
} |
| 89 |
} else { |
| 90 |
RegionInit(&priv->prepare_region, box, 1); |
| 91 |
|
| 92 |
if (glamor_priv->has_rw_pbo) { |
| 93 |
if (priv->pbo == 0) |
| 94 |
glGenBuffers(1, &priv->pbo); |
| 95 |
|
| 96 |
gl_usage = GL_STREAM_READ; |
| 97 |
|
| 98 |
glamor_priv->suppress_gl_out_of_memory_logging = true; |
| 99 |
|
| 100 |
glBindBuffer(GL_PIXEL_PACK_BUFFER, priv->pbo); |
| 101 |
glBufferData(GL_PIXEL_PACK_BUFFER, |
| 102 |
pixmap->devKind * pixmap->drawable.height, NULL, |
| 103 |
gl_usage); |
| 104 |
|
| 105 |
glamor_priv->suppress_gl_out_of_memory_logging = false; |
| 106 |
|
| 107 |
if (glGetError() == GL_OUT_OF_MEMORY) { |
| 108 |
if (!glamor_priv->logged_any_pbo_allocation_failure) { |
| 109 |
LogMessageVerb(X_WARNING, 0, "glamor: Failed to allocate %d " |
| 110 |
"bytes PBO due to GL_OUT_OF_MEMORY.\n", |
| 111 |
pixmap->devKind * pixmap->drawable.height); |
| 112 |
glamor_priv->logged_any_pbo_allocation_failure = true; |
| 113 |
} |
| 114 |
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); |
| 115 |
glDeleteBuffers(1, &priv->pbo); |
| 116 |
priv->pbo = 0; |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
if (!priv->pbo) { |
| 121 |
pixmap->devPrivate.ptr = xallocarray(pixmap->devKind, |
| 122 |
pixmap->drawable.height); |
| 123 |
if (!pixmap->devPrivate.ptr) |
| 124 |
return FALSE; |
| 125 |
} |
| 126 |
priv->map_access = access; |
| 127 |
} |
| 128 |
|
| 129 |
glamor_download_boxes(drawable, RegionRects(®ion), RegionNumRects(®ion), |
| 130 |
0, 0, 0, 0, pixmap->devPrivate.ptr, pixmap->devKind); |
| 131 |
|
| 132 |
RegionUninit(®ion); |
| 133 |
|
| 134 |
if (priv->pbo) { |
| 135 |
if (priv->map_access == GLAMOR_ACCESS_RW) |
| 136 |
gl_access = GL_READ_WRITE; |
| 137 |
else |
| 138 |
gl_access = GL_READ_ONLY; |
| 139 |
|
| 140 |
pixmap->devPrivate.ptr = glMapBuffer(GL_PIXEL_PACK_BUFFER, gl_access); |
| 141 |
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); |
| 142 |
} |
| 143 |
|
| 144 |
priv->prepared = TRUE; |
| 145 |
return TRUE; |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
void |
| 154 |
glamor_finish_access(DrawablePtr drawable) |
| 155 |
{ |
| 156 |
PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable); |
| 157 |
glamor_pixmap_private *priv = glamor_get_pixmap_private(pixmap); |
| 158 |
|
| 159 |
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(priv)) |
| 160 |
return; |
| 161 |
|
| 162 |
if (!priv->prepared) |
| 163 |
return; |
| 164 |
|
| 165 |
if (priv->pbo && |
| 166 |
!(glamor_drawable_effective_depth(drawable) == 24 && pixmap->drawable.depth == 32)) { |
| 167 |
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, priv->pbo); |
| 168 |
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); |
| 169 |
pixmap->devPrivate.ptr = NULL; |
| 170 |
} |
| 171 |
|
| 172 |
if (priv->map_access == GLAMOR_ACCESS_RW) { |
| 173 |
glamor_upload_boxes(drawable, |
| 174 |
RegionRects(&priv->prepare_region), |
| 175 |
RegionNumRects(&priv->prepare_region), |
| 176 |
0, 0, 0, 0, pixmap->devPrivate.ptr, pixmap->devKind); |
| 177 |
} |
| 178 |
|
| 179 |
RegionUninit(&priv->prepare_region); |
| 180 |
|
| 181 |
if (priv->pbo) { |
| 182 |
if (glamor_drawable_effective_depth(drawable) == 24 && pixmap->drawable.depth == 32) |
| 183 |
pixmap->devPrivate.ptr = NULL; |
| 184 |
else |
| 185 |
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); |
| 186 |
|
| 187 |
glDeleteBuffers(1, &priv->pbo); |
| 188 |
priv->pbo = 0; |
| 189 |
} else { |
| 190 |
free(pixmap->devPrivate.ptr); |
| 191 |
pixmap->devPrivate.ptr = NULL; |
| 192 |
} |
| 193 |
|
| 194 |
priv->prepared = FALSE; |
| 195 |
} |
| 196 |
|
| 197 |
Bool |
| 198 |
glamor_prepare_access(DrawablePtr drawable, glamor_access_t access) |
| 199 |
{ |
| 200 |
BoxRec box; |
| 201 |
|
| 202 |
box.x1 = drawable->x; |
| 203 |
box.x2 = box.x1 + drawable->width; |
| 204 |
box.y1 = drawable->y; |
| 205 |
box.y2 = box.y1 + drawable->height; |
| 206 |
return glamor_prep_drawable_box(drawable, access, &box); |
| 207 |
} |
| 208 |
|
| 209 |
Bool |
| 210 |
glamor_prepare_access_box(DrawablePtr drawable, glamor_access_t access, |
| 211 |
int x, int y, int w, int h) |
| 212 |
{ |
| 213 |
BoxRec box; |
| 214 |
|
| 215 |
box.x1 = drawable->x + x; |
| 216 |
box.x2 = box.x1 + w; |
| 217 |
box.y1 = drawable->y + y; |
| 218 |
box.y2 = box.y1 + h; |
| 219 |
return glamor_prep_drawable_box(drawable, access, &box); |
| 220 |
} |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
Bool |
| 227 |
glamor_prepare_access_picture(PicturePtr picture, glamor_access_t access) |
| 228 |
{ |
| 229 |
if (!picture || !picture->pDrawable) |
| 230 |
return TRUE; |
| 231 |
|
| 232 |
return glamor_prepare_access(picture->pDrawable, access); |
| 233 |
} |
| 234 |
|
| 235 |
Bool |
| 236 |
glamor_prepare_access_picture_box(PicturePtr picture, glamor_access_t access, |
| 237 |
int x, int y, int w, int h) |
| 238 |
{ |
| 239 |
if (!picture || !picture->pDrawable) |
| 240 |
return TRUE; |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
if (picture->transform) { |
| 249 |
return glamor_prepare_access_box(picture->pDrawable, access, |
| 250 |
0, 0, |
| 251 |
picture->pDrawable->width, |
| 252 |
picture->pDrawable->height); |
| 253 |
} else { |
| 254 |
return glamor_prepare_access_box(picture->pDrawable, access, |
| 255 |
x, y, w, h); |
| 256 |
} |
| 257 |
} |
| 258 |
|
| 259 |
void |
| 260 |
glamor_finish_access_picture(PicturePtr picture) |
| 261 |
{ |
| 262 |
if (!picture || !picture->pDrawable) |
| 263 |
return; |
| 264 |
|
| 265 |
glamor_finish_access(picture->pDrawable); |
| 266 |
} |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
Bool |
| 275 |
glamor_prepare_access_gc(GCPtr gc) |
| 276 |
{ |
| 277 |
switch (gc->fillStyle) { |
| 278 |
case FillTiled: |
| 279 |
return glamor_prepare_access(&gc->tile.pixmap->drawable, |
| 280 |
GLAMOR_ACCESS_RO); |
| 281 |
case FillStippled: |
| 282 |
case FillOpaqueStippled: |
| 283 |
return glamor_prepare_access(&gc->stipple->drawable, GLAMOR_ACCESS_RO); |
| 284 |
} |
| 285 |
return TRUE; |
| 286 |
} |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
void |
| 292 |
glamor_finish_access_gc(GCPtr gc) |
| 293 |
{ |
| 294 |
switch (gc->fillStyle) { |
| 295 |
case FillTiled: |
| 296 |
glamor_finish_access(&gc->tile.pixmap->drawable); |
| 297 |
break; |
| 298 |
case FillStippled: |
| 299 |
case FillOpaqueStippled: |
| 300 |
glamor_finish_access(&gc->stipple->drawable); |
| 301 |
break; |
| 302 |
} |
| 303 |
} |