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