| .. | .. |
|---|
| 20 | 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|---|
| 21 | 21 | */ |
|---|
| 22 | 22 | |
|---|
| 23 | +#include <drm/drm_fourcc.h> |
|---|
| 24 | + |
|---|
| 23 | 25 | #include "qxl_drv.h" |
|---|
| 24 | 26 | #include "qxl_object.h" |
|---|
| 25 | 27 | |
|---|
| 26 | 28 | static int alloc_clips(struct qxl_device *qdev, |
|---|
| 27 | 29 | struct qxl_release *release, |
|---|
| 28 | | - unsigned num_clips, |
|---|
| 30 | + unsigned int num_clips, |
|---|
| 29 | 31 | struct qxl_bo **clips_bo) |
|---|
| 30 | 32 | { |
|---|
| 31 | 33 | int size = sizeof(struct qxl_clip_rects) + sizeof(struct qxl_rect) * num_clips; |
|---|
| .. | .. |
|---|
| 37 | 39 | * the qxl_clip_rects. This is *not* the same as the memory allocated |
|---|
| 38 | 40 | * on the device, it is offset to qxl_clip_rects.chunk.data */ |
|---|
| 39 | 41 | static struct qxl_rect *drawable_set_clipping(struct qxl_device *qdev, |
|---|
| 40 | | - unsigned num_clips, |
|---|
| 42 | + unsigned int num_clips, |
|---|
| 41 | 43 | struct qxl_bo *clips_bo) |
|---|
| 42 | 44 | { |
|---|
| 43 | 45 | struct qxl_clip_rects *dev_clips; |
|---|
| .. | .. |
|---|
| 109 | 111 | return 0; |
|---|
| 110 | 112 | } |
|---|
| 111 | 113 | |
|---|
| 112 | | -static int alloc_palette_object(struct qxl_device *qdev, |
|---|
| 113 | | - struct qxl_release *release, |
|---|
| 114 | | - struct qxl_bo **palette_bo) |
|---|
| 115 | | -{ |
|---|
| 116 | | - return qxl_alloc_bo_reserved(qdev, release, |
|---|
| 117 | | - sizeof(struct qxl_palette) + sizeof(uint32_t) * 2, |
|---|
| 118 | | - palette_bo); |
|---|
| 119 | | -} |
|---|
| 120 | | - |
|---|
| 121 | | -static int qxl_palette_create_1bit(struct qxl_bo *palette_bo, |
|---|
| 122 | | - struct qxl_release *release, |
|---|
| 123 | | - const struct qxl_fb_image *qxl_fb_image) |
|---|
| 124 | | -{ |
|---|
| 125 | | - const struct fb_image *fb_image = &qxl_fb_image->fb_image; |
|---|
| 126 | | - uint32_t visual = qxl_fb_image->visual; |
|---|
| 127 | | - const uint32_t *pseudo_palette = qxl_fb_image->pseudo_palette; |
|---|
| 128 | | - struct qxl_palette *pal; |
|---|
| 129 | | - int ret; |
|---|
| 130 | | - uint32_t fgcolor, bgcolor; |
|---|
| 131 | | - static uint64_t unique; /* we make no attempt to actually set this |
|---|
| 132 | | - * correctly globaly, since that would require |
|---|
| 133 | | - * tracking all of our palettes. */ |
|---|
| 134 | | - ret = qxl_bo_kmap(palette_bo, (void **)&pal); |
|---|
| 135 | | - if (ret) |
|---|
| 136 | | - return ret; |
|---|
| 137 | | - pal->num_ents = 2; |
|---|
| 138 | | - pal->unique = unique++; |
|---|
| 139 | | - if (visual == FB_VISUAL_TRUECOLOR || visual == FB_VISUAL_DIRECTCOLOR) { |
|---|
| 140 | | - /* NB: this is the only used branch currently. */ |
|---|
| 141 | | - fgcolor = pseudo_palette[fb_image->fg_color]; |
|---|
| 142 | | - bgcolor = pseudo_palette[fb_image->bg_color]; |
|---|
| 143 | | - } else { |
|---|
| 144 | | - fgcolor = fb_image->fg_color; |
|---|
| 145 | | - bgcolor = fb_image->bg_color; |
|---|
| 146 | | - } |
|---|
| 147 | | - pal->ents[0] = bgcolor; |
|---|
| 148 | | - pal->ents[1] = fgcolor; |
|---|
| 149 | | - qxl_bo_kunmap(palette_bo); |
|---|
| 150 | | - return 0; |
|---|
| 151 | | -} |
|---|
| 152 | | - |
|---|
| 153 | | -void qxl_draw_opaque_fb(const struct qxl_fb_image *qxl_fb_image, |
|---|
| 154 | | - int stride /* filled in if 0 */) |
|---|
| 155 | | -{ |
|---|
| 156 | | - struct qxl_device *qdev = qxl_fb_image->qdev; |
|---|
| 157 | | - struct qxl_drawable *drawable; |
|---|
| 158 | | - struct qxl_rect rect; |
|---|
| 159 | | - const struct fb_image *fb_image = &qxl_fb_image->fb_image; |
|---|
| 160 | | - int x = fb_image->dx; |
|---|
| 161 | | - int y = fb_image->dy; |
|---|
| 162 | | - int width = fb_image->width; |
|---|
| 163 | | - int height = fb_image->height; |
|---|
| 164 | | - const char *src = fb_image->data; |
|---|
| 165 | | - int depth = fb_image->depth; |
|---|
| 166 | | - struct qxl_release *release; |
|---|
| 167 | | - struct qxl_image *image; |
|---|
| 168 | | - int ret; |
|---|
| 169 | | - struct qxl_drm_image *dimage; |
|---|
| 170 | | - struct qxl_bo *palette_bo = NULL; |
|---|
| 171 | | - if (stride == 0) |
|---|
| 172 | | - stride = depth * width / 8; |
|---|
| 173 | | - |
|---|
| 174 | | - ret = alloc_drawable(qdev, &release); |
|---|
| 175 | | - if (ret) |
|---|
| 176 | | - return; |
|---|
| 177 | | - |
|---|
| 178 | | - ret = qxl_image_alloc_objects(qdev, release, |
|---|
| 179 | | - &dimage, |
|---|
| 180 | | - height, stride); |
|---|
| 181 | | - if (ret) |
|---|
| 182 | | - goto out_free_drawable; |
|---|
| 183 | | - |
|---|
| 184 | | - if (depth == 1) { |
|---|
| 185 | | - ret = alloc_palette_object(qdev, release, &palette_bo); |
|---|
| 186 | | - if (ret) |
|---|
| 187 | | - goto out_free_image; |
|---|
| 188 | | - } |
|---|
| 189 | | - |
|---|
| 190 | | - /* do a reservation run over all the objects we just allocated */ |
|---|
| 191 | | - ret = qxl_release_reserve_list(release, true); |
|---|
| 192 | | - if (ret) |
|---|
| 193 | | - goto out_free_palette; |
|---|
| 194 | | - |
|---|
| 195 | | - rect.left = x; |
|---|
| 196 | | - rect.right = x + width; |
|---|
| 197 | | - rect.top = y; |
|---|
| 198 | | - rect.bottom = y + height; |
|---|
| 199 | | - |
|---|
| 200 | | - ret = make_drawable(qdev, 0, QXL_DRAW_COPY, &rect, release); |
|---|
| 201 | | - if (ret) { |
|---|
| 202 | | - qxl_release_backoff_reserve_list(release); |
|---|
| 203 | | - goto out_free_palette; |
|---|
| 204 | | - } |
|---|
| 205 | | - |
|---|
| 206 | | - ret = qxl_image_init(qdev, release, dimage, |
|---|
| 207 | | - (const uint8_t *)src, 0, 0, |
|---|
| 208 | | - width, height, depth, stride); |
|---|
| 209 | | - if (ret) { |
|---|
| 210 | | - qxl_release_backoff_reserve_list(release); |
|---|
| 211 | | - qxl_release_free(qdev, release); |
|---|
| 212 | | - return; |
|---|
| 213 | | - } |
|---|
| 214 | | - |
|---|
| 215 | | - if (depth == 1) { |
|---|
| 216 | | - void *ptr; |
|---|
| 217 | | - ret = qxl_palette_create_1bit(palette_bo, release, qxl_fb_image); |
|---|
| 218 | | - |
|---|
| 219 | | - ptr = qxl_bo_kmap_atomic_page(qdev, dimage->bo, 0); |
|---|
| 220 | | - image = ptr; |
|---|
| 221 | | - image->u.bitmap.palette = |
|---|
| 222 | | - qxl_bo_physical_address(qdev, palette_bo, 0); |
|---|
| 223 | | - qxl_bo_kunmap_atomic_page(qdev, dimage->bo, ptr); |
|---|
| 224 | | - } |
|---|
| 225 | | - |
|---|
| 226 | | - drawable = (struct qxl_drawable *)qxl_release_map(qdev, release); |
|---|
| 227 | | - |
|---|
| 228 | | - drawable->u.copy.src_area.top = 0; |
|---|
| 229 | | - drawable->u.copy.src_area.bottom = height; |
|---|
| 230 | | - drawable->u.copy.src_area.left = 0; |
|---|
| 231 | | - drawable->u.copy.src_area.right = width; |
|---|
| 232 | | - |
|---|
| 233 | | - drawable->u.copy.rop_descriptor = SPICE_ROPD_OP_PUT; |
|---|
| 234 | | - drawable->u.copy.scale_mode = 0; |
|---|
| 235 | | - drawable->u.copy.mask.flags = 0; |
|---|
| 236 | | - drawable->u.copy.mask.pos.x = 0; |
|---|
| 237 | | - drawable->u.copy.mask.pos.y = 0; |
|---|
| 238 | | - drawable->u.copy.mask.bitmap = 0; |
|---|
| 239 | | - |
|---|
| 240 | | - drawable->u.copy.src_bitmap = |
|---|
| 241 | | - qxl_bo_physical_address(qdev, dimage->bo, 0); |
|---|
| 242 | | - qxl_release_unmap(qdev, release, &drawable->release_info); |
|---|
| 243 | | - |
|---|
| 244 | | - qxl_release_fence_buffer_objects(release); |
|---|
| 245 | | - qxl_push_command_ring_release(qdev, release, QXL_CMD_DRAW, false); |
|---|
| 246 | | - |
|---|
| 247 | | -out_free_palette: |
|---|
| 248 | | - if (palette_bo) |
|---|
| 249 | | - qxl_bo_unref(&palette_bo); |
|---|
| 250 | | -out_free_image: |
|---|
| 251 | | - qxl_image_free_objects(qdev, dimage); |
|---|
| 252 | | -out_free_drawable: |
|---|
| 253 | | - if (ret) |
|---|
| 254 | | - free_drawable(qdev, release); |
|---|
| 255 | | -} |
|---|
| 256 | | - |
|---|
| 257 | 114 | /* push a draw command using the given clipping rectangles as |
|---|
| 258 | 115 | * the sources from the shadow framebuffer. |
|---|
| 259 | 116 | * |
|---|
| .. | .. |
|---|
| 262 | 119 | * by treating them differently in the server. |
|---|
| 263 | 120 | */ |
|---|
| 264 | 121 | void qxl_draw_dirty_fb(struct qxl_device *qdev, |
|---|
| 265 | | - struct qxl_framebuffer *qxl_fb, |
|---|
| 122 | + struct drm_framebuffer *fb, |
|---|
| 266 | 123 | struct qxl_bo *bo, |
|---|
| 267 | | - unsigned flags, unsigned color, |
|---|
| 124 | + unsigned int flags, unsigned int color, |
|---|
| 268 | 125 | struct drm_clip_rect *clips, |
|---|
| 269 | | - unsigned num_clips, int inc) |
|---|
| 126 | + unsigned int num_clips, int inc, |
|---|
| 127 | + uint32_t dumb_shadow_offset) |
|---|
| 270 | 128 | { |
|---|
| 271 | 129 | /* |
|---|
| 272 | 130 | * TODO: if flags & DRM_MODE_FB_DIRTY_ANNOTATE_FILL then we should |
|---|
| .. | .. |
|---|
| 281 | 139 | struct qxl_drawable *drawable; |
|---|
| 282 | 140 | struct qxl_rect drawable_rect; |
|---|
| 283 | 141 | struct qxl_rect *rects; |
|---|
| 284 | | - int stride = qxl_fb->base.pitches[0]; |
|---|
| 142 | + int stride = fb->pitches[0]; |
|---|
| 285 | 143 | /* depth is not actually interesting, we don't mask with it */ |
|---|
| 286 | | - int depth = qxl_fb->base.format->cpp[0] * 8; |
|---|
| 144 | + int depth = fb->format->cpp[0] * 8; |
|---|
| 287 | 145 | uint8_t *surface_base; |
|---|
| 288 | 146 | struct qxl_release *release; |
|---|
| 289 | 147 | struct qxl_bo *clips_bo; |
|---|
| .. | .. |
|---|
| 293 | 151 | ret = alloc_drawable(qdev, &release); |
|---|
| 294 | 152 | if (ret) |
|---|
| 295 | 153 | return; |
|---|
| 154 | + |
|---|
| 155 | + clips->x1 += dumb_shadow_offset; |
|---|
| 156 | + clips->x2 += dumb_shadow_offset; |
|---|
| 296 | 157 | |
|---|
| 297 | 158 | left = clips->x1; |
|---|
| 298 | 159 | right = clips->x2; |
|---|
| .. | .. |
|---|
| 340 | 201 | if (ret) |
|---|
| 341 | 202 | goto out_release_backoff; |
|---|
| 342 | 203 | |
|---|
| 343 | | - |
|---|
| 344 | 204 | ret = qxl_image_init(qdev, release, dimage, surface_base, |
|---|
| 345 | | - left, top, width, height, depth, stride); |
|---|
| 205 | + left - dumb_shadow_offset, |
|---|
| 206 | + top, width, height, depth, stride); |
|---|
| 346 | 207 | qxl_bo_kunmap(bo); |
|---|
| 347 | 208 | if (ret) |
|---|
| 348 | 209 | goto out_release_backoff; |
|---|
| .. | .. |
|---|
| 397 | 258 | if (ret) |
|---|
| 398 | 259 | free_drawable(qdev, release); |
|---|
| 399 | 260 | |
|---|
| 400 | | -} |
|---|
| 401 | | - |
|---|
| 402 | | -void qxl_draw_copyarea(struct qxl_device *qdev, |
|---|
| 403 | | - u32 width, u32 height, |
|---|
| 404 | | - u32 sx, u32 sy, |
|---|
| 405 | | - u32 dx, u32 dy) |
|---|
| 406 | | -{ |
|---|
| 407 | | - struct qxl_drawable *drawable; |
|---|
| 408 | | - struct qxl_rect rect; |
|---|
| 409 | | - struct qxl_release *release; |
|---|
| 410 | | - int ret; |
|---|
| 411 | | - |
|---|
| 412 | | - ret = alloc_drawable(qdev, &release); |
|---|
| 413 | | - if (ret) |
|---|
| 414 | | - return; |
|---|
| 415 | | - |
|---|
| 416 | | - /* do a reservation run over all the objects we just allocated */ |
|---|
| 417 | | - ret = qxl_release_reserve_list(release, true); |
|---|
| 418 | | - if (ret) |
|---|
| 419 | | - goto out_free_release; |
|---|
| 420 | | - |
|---|
| 421 | | - rect.left = dx; |
|---|
| 422 | | - rect.top = dy; |
|---|
| 423 | | - rect.right = dx + width; |
|---|
| 424 | | - rect.bottom = dy + height; |
|---|
| 425 | | - ret = make_drawable(qdev, 0, QXL_COPY_BITS, &rect, release); |
|---|
| 426 | | - if (ret) { |
|---|
| 427 | | - qxl_release_backoff_reserve_list(release); |
|---|
| 428 | | - goto out_free_release; |
|---|
| 429 | | - } |
|---|
| 430 | | - |
|---|
| 431 | | - drawable = (struct qxl_drawable *)qxl_release_map(qdev, release); |
|---|
| 432 | | - drawable->u.copy_bits.src_pos.x = sx; |
|---|
| 433 | | - drawable->u.copy_bits.src_pos.y = sy; |
|---|
| 434 | | - qxl_release_unmap(qdev, release, &drawable->release_info); |
|---|
| 435 | | - |
|---|
| 436 | | - qxl_release_fence_buffer_objects(release); |
|---|
| 437 | | - qxl_push_command_ring_release(qdev, release, QXL_CMD_DRAW, false); |
|---|
| 438 | | - |
|---|
| 439 | | -out_free_release: |
|---|
| 440 | | - if (ret) |
|---|
| 441 | | - free_drawable(qdev, release); |
|---|
| 442 | | -} |
|---|
| 443 | | - |
|---|
| 444 | | -void qxl_draw_fill(struct qxl_draw_fill *qxl_draw_fill_rec) |
|---|
| 445 | | -{ |
|---|
| 446 | | - struct qxl_device *qdev = qxl_draw_fill_rec->qdev; |
|---|
| 447 | | - struct qxl_rect rect = qxl_draw_fill_rec->rect; |
|---|
| 448 | | - uint32_t color = qxl_draw_fill_rec->color; |
|---|
| 449 | | - uint16_t rop = qxl_draw_fill_rec->rop; |
|---|
| 450 | | - struct qxl_drawable *drawable; |
|---|
| 451 | | - struct qxl_release *release; |
|---|
| 452 | | - int ret; |
|---|
| 453 | | - |
|---|
| 454 | | - ret = alloc_drawable(qdev, &release); |
|---|
| 455 | | - if (ret) |
|---|
| 456 | | - return; |
|---|
| 457 | | - |
|---|
| 458 | | - /* do a reservation run over all the objects we just allocated */ |
|---|
| 459 | | - ret = qxl_release_reserve_list(release, true); |
|---|
| 460 | | - if (ret) |
|---|
| 461 | | - goto out_free_release; |
|---|
| 462 | | - |
|---|
| 463 | | - ret = make_drawable(qdev, 0, QXL_DRAW_FILL, &rect, release); |
|---|
| 464 | | - if (ret) { |
|---|
| 465 | | - qxl_release_backoff_reserve_list(release); |
|---|
| 466 | | - goto out_free_release; |
|---|
| 467 | | - } |
|---|
| 468 | | - |
|---|
| 469 | | - drawable = (struct qxl_drawable *)qxl_release_map(qdev, release); |
|---|
| 470 | | - drawable->u.fill.brush.type = SPICE_BRUSH_TYPE_SOLID; |
|---|
| 471 | | - drawable->u.fill.brush.u.color = color; |
|---|
| 472 | | - drawable->u.fill.rop_descriptor = rop; |
|---|
| 473 | | - drawable->u.fill.mask.flags = 0; |
|---|
| 474 | | - drawable->u.fill.mask.pos.x = 0; |
|---|
| 475 | | - drawable->u.fill.mask.pos.y = 0; |
|---|
| 476 | | - drawable->u.fill.mask.bitmap = 0; |
|---|
| 477 | | - |
|---|
| 478 | | - qxl_release_unmap(qdev, release, &drawable->release_info); |
|---|
| 479 | | - |
|---|
| 480 | | - qxl_release_fence_buffer_objects(release); |
|---|
| 481 | | - qxl_push_command_ring_release(qdev, release, QXL_CMD_DRAW, false); |
|---|
| 482 | | - |
|---|
| 483 | | -out_free_release: |
|---|
| 484 | | - if (ret) |
|---|
| 485 | | - free_drawable(qdev, release); |
|---|
| 486 | 261 | } |
|---|