This source file includes following definitions.
- alloc_clips
 
- drawable_set_clipping
 
- alloc_drawable
 
- free_drawable
 
- make_drawable
 
- qxl_draw_dirty_fb
 
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 
  14 
  15 
  16 
  17 
  18 
  19 
  20 
  21 
  22 
  23 #include <drm/drm_fourcc.h>
  24 
  25 #include "qxl_drv.h"
  26 #include "qxl_object.h"
  27 
  28 static int alloc_clips(struct qxl_device *qdev,
  29                        struct qxl_release *release,
  30                        unsigned int num_clips,
  31                        struct qxl_bo **clips_bo)
  32 {
  33         int size = sizeof(struct qxl_clip_rects) + sizeof(struct qxl_rect) * num_clips;
  34 
  35         return qxl_alloc_bo_reserved(qdev, release, size, clips_bo);
  36 }
  37 
  38 
  39 
  40 
  41 static struct qxl_rect *drawable_set_clipping(struct qxl_device *qdev,
  42                                               unsigned int num_clips,
  43                                               struct qxl_bo *clips_bo)
  44 {
  45         struct qxl_clip_rects *dev_clips;
  46         int ret;
  47 
  48         ret = qxl_bo_kmap(clips_bo, (void **)&dev_clips);
  49         if (ret) {
  50                 return NULL;
  51         }
  52         dev_clips->num_rects = num_clips;
  53         dev_clips->chunk.next_chunk = 0;
  54         dev_clips->chunk.prev_chunk = 0;
  55         dev_clips->chunk.data_size = sizeof(struct qxl_rect) * num_clips;
  56         return (struct qxl_rect *)dev_clips->chunk.data;
  57 }
  58 
  59 static int
  60 alloc_drawable(struct qxl_device *qdev, struct qxl_release **release)
  61 {
  62         return qxl_alloc_release_reserved(qdev, sizeof(struct qxl_drawable),
  63                                           QXL_RELEASE_DRAWABLE, release, NULL);
  64 }
  65 
  66 static void
  67 free_drawable(struct qxl_device *qdev, struct qxl_release *release)
  68 {
  69         qxl_release_free(qdev, release);
  70 }
  71 
  72 
  73 static int
  74 make_drawable(struct qxl_device *qdev, int surface, uint8_t type,
  75               const struct qxl_rect *rect,
  76               struct qxl_release *release)
  77 {
  78         struct qxl_drawable *drawable;
  79         int i;
  80 
  81         drawable = (struct qxl_drawable *)qxl_release_map(qdev, release);
  82         if (!drawable)
  83                 return -ENOMEM;
  84 
  85         drawable->type = type;
  86 
  87         drawable->surface_id = surface;         
  88         drawable->effect = QXL_EFFECT_OPAQUE;
  89         drawable->self_bitmap = 0;
  90         drawable->self_bitmap_area.top = 0;
  91         drawable->self_bitmap_area.left = 0;
  92         drawable->self_bitmap_area.bottom = 0;
  93         drawable->self_bitmap_area.right = 0;
  94         
  95         drawable->clip.type = SPICE_CLIP_TYPE_NONE;
  96 
  97         
  98 
  99 
 100 
 101 
 102 
 103         for (i = 0; i < 3; ++i)
 104                 drawable->surfaces_dest[i] = -1;
 105 
 106         if (rect)
 107                 drawable->bbox = *rect;
 108 
 109         drawable->mm_time = qdev->rom->mm_clock;
 110         qxl_release_unmap(qdev, release, &drawable->release_info);
 111         return 0;
 112 }
 113 
 114 
 115 
 116 
 117 
 118 
 119 
 120 
 121 void qxl_draw_dirty_fb(struct qxl_device *qdev,
 122                        struct drm_framebuffer *fb,
 123                        struct qxl_bo *bo,
 124                        unsigned int flags, unsigned int color,
 125                        struct drm_clip_rect *clips,
 126                        unsigned int num_clips, int inc,
 127                        uint32_t dumb_shadow_offset)
 128 {
 129         
 130 
 131 
 132 
 133 
 134 
 135         struct drm_clip_rect *clips_ptr;
 136         int i;
 137         int left, right, top, bottom;
 138         int width, height;
 139         struct qxl_drawable *drawable;
 140         struct qxl_rect drawable_rect;
 141         struct qxl_rect *rects;
 142         int stride = fb->pitches[0];
 143         
 144         int depth = fb->format->cpp[0] * 8;
 145         uint8_t *surface_base;
 146         struct qxl_release *release;
 147         struct qxl_bo *clips_bo;
 148         struct qxl_drm_image *dimage;
 149         int ret;
 150 
 151         ret = alloc_drawable(qdev, &release);
 152         if (ret)
 153                 return;
 154 
 155         clips->x1 += dumb_shadow_offset;
 156         clips->x2 += dumb_shadow_offset;
 157 
 158         left = clips->x1;
 159         right = clips->x2;
 160         top = clips->y1;
 161         bottom = clips->y2;
 162 
 163         
 164         for (i = 1, clips_ptr = clips + inc;
 165              i < num_clips; i++, clips_ptr += inc) {
 166                 left = min_t(int, left, (int)clips_ptr->x1);
 167                 right = max_t(int, right, (int)clips_ptr->x2);
 168                 top = min_t(int, top, (int)clips_ptr->y1);
 169                 bottom = max_t(int, bottom, (int)clips_ptr->y2);
 170         }
 171 
 172         width = right - left;
 173         height = bottom - top;
 174 
 175         ret = alloc_clips(qdev, release, num_clips, &clips_bo);
 176         if (ret)
 177                 goto out_free_drawable;
 178 
 179         ret = qxl_image_alloc_objects(qdev, release,
 180                                       &dimage,
 181                                       height, stride);
 182         if (ret)
 183                 goto out_free_clips;
 184 
 185         
 186         ret = qxl_release_reserve_list(release, true);
 187         if (ret)
 188                 goto out_free_image;
 189 
 190         drawable_rect.left = left;
 191         drawable_rect.right = right;
 192         drawable_rect.top = top;
 193         drawable_rect.bottom = bottom;
 194 
 195         ret = make_drawable(qdev, 0, QXL_DRAW_COPY, &drawable_rect,
 196                             release);
 197         if (ret)
 198                 goto out_release_backoff;
 199 
 200         ret = qxl_bo_kmap(bo, (void **)&surface_base);
 201         if (ret)
 202                 goto out_release_backoff;
 203 
 204         ret = qxl_image_init(qdev, release, dimage, surface_base,
 205                              left - dumb_shadow_offset,
 206                              top, width, height, depth, stride);
 207         qxl_bo_kunmap(bo);
 208         if (ret)
 209                 goto out_release_backoff;
 210 
 211         rects = drawable_set_clipping(qdev, num_clips, clips_bo);
 212         if (!rects) {
 213                 ret = -EINVAL;
 214                 goto out_release_backoff;
 215         }
 216         drawable = (struct qxl_drawable *)qxl_release_map(qdev, release);
 217 
 218         drawable->clip.type = SPICE_CLIP_TYPE_RECTS;
 219         drawable->clip.data = qxl_bo_physical_address(qdev,
 220                                                       clips_bo, 0);
 221 
 222         drawable->u.copy.src_area.top = 0;
 223         drawable->u.copy.src_area.bottom = height;
 224         drawable->u.copy.src_area.left = 0;
 225         drawable->u.copy.src_area.right = width;
 226 
 227         drawable->u.copy.rop_descriptor = SPICE_ROPD_OP_PUT;
 228         drawable->u.copy.scale_mode = 0;
 229         drawable->u.copy.mask.flags = 0;
 230         drawable->u.copy.mask.pos.x = 0;
 231         drawable->u.copy.mask.pos.y = 0;
 232         drawable->u.copy.mask.bitmap = 0;
 233 
 234         drawable->u.copy.src_bitmap = qxl_bo_physical_address(qdev, dimage->bo, 0);
 235         qxl_release_unmap(qdev, release, &drawable->release_info);
 236 
 237         clips_ptr = clips;
 238         for (i = 0; i < num_clips; i++, clips_ptr += inc) {
 239                 rects[i].left   = clips_ptr->x1;
 240                 rects[i].right  = clips_ptr->x2;
 241                 rects[i].top    = clips_ptr->y1;
 242                 rects[i].bottom = clips_ptr->y2;
 243         }
 244         qxl_bo_kunmap(clips_bo);
 245 
 246         qxl_release_fence_buffer_objects(release);
 247         qxl_push_command_ring_release(qdev, release, QXL_CMD_DRAW, false);
 248 
 249 out_release_backoff:
 250         if (ret)
 251                 qxl_release_backoff_reserve_list(release);
 252 out_free_image:
 253         qxl_image_free_objects(qdev, dimage);
 254 out_free_clips:
 255         qxl_bo_unref(&clips_bo);
 256 out_free_drawable:
 257         
 258         if (ret)
 259                 free_drawable(qdev, release);
 260 
 261 }