Linux Audio

Check our new training course

Loading...
v6.13.7
  1/*
  2 * Copyright 2011 Red Hat, Inc.
  3 *
  4 * Permission is hereby granted, free of charge, to any person obtaining a
  5 * copy of this software and associated documentation files (the "Software"),
  6 * to deal in the Software without restriction, including without limitation
  7 * on the rights to use, copy, modify, merge, publish, distribute, sub
  8 * license, and/or sell copies of the Software, and to permit persons to whom
  9 * the Software is furnished to do so, subject to the following conditions:
 10 *
 11 * The above copyright notice and this permission notice (including the next
 12 * paragraph) shall be included in all copies or substantial portions of the
 13 * Software.
 14 *
 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
 18 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 21 */
 22
 23#include <linux/iosys-map.h>
 24
 25#include <drm/drm_fourcc.h>
 26#include <drm/drm_framebuffer.h>
 27
 28#include "qxl_drv.h"
 29#include "qxl_object.h"
 30
 31static int alloc_clips(struct qxl_device *qdev,
 32		       struct qxl_release *release,
 33		       unsigned int num_clips,
 34		       struct qxl_bo **clips_bo)
 35{
 36	int size = sizeof(struct qxl_clip_rects) + sizeof(struct qxl_rect) * num_clips;
 37
 38	return qxl_alloc_bo_reserved(qdev, release, size, clips_bo);
 39}
 40
 41/* returns a pointer to the already allocated qxl_rect array inside
 42 * the qxl_clip_rects. This is *not* the same as the memory allocated
 43 * on the device, it is offset to qxl_clip_rects.chunk.data */
 44static struct qxl_rect *drawable_set_clipping(struct qxl_device *qdev,
 45					      unsigned int num_clips,
 46					      struct qxl_bo *clips_bo)
 47{
 48	struct iosys_map map;
 49	struct qxl_clip_rects *dev_clips;
 50	int ret;
 51
 52	ret = qxl_bo_vmap_locked(clips_bo, &map);
 53	if (ret)
 54		return NULL;
 55	dev_clips = map.vaddr; /* TODO: Use mapping abstraction properly */
 56
 57	dev_clips->num_rects = num_clips;
 58	dev_clips->chunk.next_chunk = 0;
 59	dev_clips->chunk.prev_chunk = 0;
 60	dev_clips->chunk.data_size = sizeof(struct qxl_rect) * num_clips;
 61	return (struct qxl_rect *)dev_clips->chunk.data;
 62}
 63
 64static int
 65alloc_drawable(struct qxl_device *qdev, struct qxl_release **release)
 66{
 67	return qxl_alloc_release_reserved(qdev, sizeof(struct qxl_drawable),
 68					  QXL_RELEASE_DRAWABLE, release, NULL);
 69}
 70
 71static void
 72free_drawable(struct qxl_device *qdev, struct qxl_release *release)
 73{
 74	qxl_release_free(qdev, release);
 75}
 76
 77/* release needs to be reserved at this point */
 78static int
 79make_drawable(struct qxl_device *qdev, int surface, uint8_t type,
 80	      const struct qxl_rect *rect,
 81	      struct qxl_release *release)
 82{
 83	struct qxl_drawable *drawable;
 84	int i;
 85
 86	drawable = (struct qxl_drawable *)qxl_release_map(qdev, release);
 87	if (!drawable)
 88		return -ENOMEM;
 89
 90	drawable->type = type;
 91
 92	drawable->surface_id = surface;		/* Only primary for now */
 93	drawable->effect = QXL_EFFECT_OPAQUE;
 94	drawable->self_bitmap = 0;
 95	drawable->self_bitmap_area.top = 0;
 96	drawable->self_bitmap_area.left = 0;
 97	drawable->self_bitmap_area.bottom = 0;
 98	drawable->self_bitmap_area.right = 0;
 99	/* FIXME: add clipping */
100	drawable->clip.type = SPICE_CLIP_TYPE_NONE;
101
102	/*
103	 * surfaces_dest[i] should apparently be filled out with the
104	 * surfaces that we depend on, and surface_rects should be
105	 * filled with the rectangles of those surfaces that we
106	 * are going to use.
107	 */
108	for (i = 0; i < 3; ++i)
109		drawable->surfaces_dest[i] = -1;
110
111	if (rect)
112		drawable->bbox = *rect;
113
114	drawable->mm_time = qdev->rom->mm_clock;
115	qxl_release_unmap(qdev, release, &drawable->release_info);
116	return 0;
117}
118
119/* push a draw command using the given clipping rectangles as
120 * the sources from the shadow framebuffer.
121 *
122 * Right now implementing with a single draw and a clip list. Clip
123 * lists are known to be a problem performance wise, this can be solved
124 * by treating them differently in the server.
125 */
126void qxl_draw_dirty_fb(struct qxl_device *qdev,
127		       struct drm_framebuffer *fb,
128		       struct qxl_bo *bo,
129		       unsigned int flags, unsigned int color,
130		       struct drm_clip_rect *clips,
131		       unsigned int num_clips, int inc,
132		       uint32_t dumb_shadow_offset)
133{
134	/*
135	 * TODO: if flags & DRM_MODE_FB_DIRTY_ANNOTATE_FILL then we should
136	 * send a fill command instead, much cheaper.
137	 *
138	 * See include/drm/drm_mode.h
139	 */
140	struct drm_clip_rect *clips_ptr;
141	int i;
142	int left, right, top, bottom;
143	int width, height;
144	struct qxl_drawable *drawable;
145	struct qxl_rect drawable_rect;
146	struct qxl_rect *rects;
147	int stride = fb->pitches[0];
148	/* depth is not actually interesting, we don't mask with it */
149	int depth = fb->format->cpp[0] * 8;
150	struct iosys_map surface_map;
151	uint8_t *surface_base;
152	struct qxl_release *release;
153	struct qxl_bo *clips_bo;
154	struct qxl_drm_image *dimage;
155	int ret;
156
157	ret = alloc_drawable(qdev, &release);
158	if (ret)
159		return;
160
161	clips->x1 += dumb_shadow_offset;
162	clips->x2 += dumb_shadow_offset;
163
164	left = clips->x1;
165	right = clips->x2;
166	top = clips->y1;
167	bottom = clips->y2;
168
169	/* skip the first clip rect */
170	for (i = 1, clips_ptr = clips + inc;
171	     i < num_clips; i++, clips_ptr += inc) {
172		left = min_t(int, left, (int)clips_ptr->x1);
173		right = max_t(int, right, (int)clips_ptr->x2);
174		top = min_t(int, top, (int)clips_ptr->y1);
175		bottom = max_t(int, bottom, (int)clips_ptr->y2);
176	}
177
178	width = right - left;
179	height = bottom - top;
180
181	ret = alloc_clips(qdev, release, num_clips, &clips_bo);
182	if (ret)
183		goto out_free_drawable;
184
185	ret = qxl_image_alloc_objects(qdev, release,
186				      &dimage,
187				      height, stride);
188	if (ret)
189		goto out_free_clips;
190
191	/* do a reservation run over all the objects we just allocated */
192	ret = qxl_release_reserve_list(release, true);
193	if (ret)
194		goto out_free_image;
195
196	drawable_rect.left = left;
197	drawable_rect.right = right;
198	drawable_rect.top = top;
199	drawable_rect.bottom = bottom;
200
201	ret = make_drawable(qdev, 0, QXL_DRAW_COPY, &drawable_rect,
202			    release);
203	if (ret)
204		goto out_release_backoff;
205
206	ret = qxl_bo_vmap_locked(bo, &surface_map);
207	if (ret)
208		goto out_release_backoff;
209	surface_base = surface_map.vaddr; /* TODO: Use mapping abstraction properly */
210
211	ret = qxl_image_init(qdev, release, dimage, surface_base,
212			     left - dumb_shadow_offset,
213			     top, width, height, depth, stride);
214	qxl_bo_vunmap_locked(bo);
215	if (ret)
216		goto out_release_backoff;
217
218	rects = drawable_set_clipping(qdev, num_clips, clips_bo);
219	if (!rects) {
220		ret = -EINVAL;
221		goto out_release_backoff;
222	}
223	drawable = (struct qxl_drawable *)qxl_release_map(qdev, release);
224
225	drawable->clip.type = SPICE_CLIP_TYPE_RECTS;
226	drawable->clip.data = qxl_bo_physical_address(qdev,
227						      clips_bo, 0);
228
229	drawable->u.copy.src_area.top = 0;
230	drawable->u.copy.src_area.bottom = height;
231	drawable->u.copy.src_area.left = 0;
232	drawable->u.copy.src_area.right = width;
233
234	drawable->u.copy.rop_descriptor = SPICE_ROPD_OP_PUT;
235	drawable->u.copy.scale_mode = 0;
236	drawable->u.copy.mask.flags = 0;
237	drawable->u.copy.mask.pos.x = 0;
238	drawable->u.copy.mask.pos.y = 0;
239	drawable->u.copy.mask.bitmap = 0;
240
241	drawable->u.copy.src_bitmap = qxl_bo_physical_address(qdev, dimage->bo, 0);
242	qxl_release_unmap(qdev, release, &drawable->release_info);
243
244	clips_ptr = clips;
245	for (i = 0; i < num_clips; i++, clips_ptr += inc) {
246		rects[i].left   = clips_ptr->x1;
247		rects[i].right  = clips_ptr->x2;
248		rects[i].top    = clips_ptr->y1;
249		rects[i].bottom = clips_ptr->y2;
250	}
251	qxl_bo_vunmap_locked(clips_bo);
252
253	qxl_release_fence_buffer_objects(release);
254	qxl_push_command_ring_release(qdev, release, QXL_CMD_DRAW, false);
 
255
256out_release_backoff:
257	if (ret)
258		qxl_release_backoff_reserve_list(release);
259out_free_image:
260	qxl_image_free_objects(qdev, dimage);
261out_free_clips:
262	qxl_bo_unref(&clips_bo);
263out_free_drawable:
264	/* only free drawable on error */
265	if (ret)
266		free_drawable(qdev, release);
267
268}
v5.4
  1/*
  2 * Copyright 2011 Red Hat, Inc.
  3 *
  4 * Permission is hereby granted, free of charge, to any person obtaining a
  5 * copy of this software and associated documentation files (the "Software"),
  6 * to deal in the Software without restriction, including without limitation
  7 * on the rights to use, copy, modify, merge, publish, distribute, sub
  8 * license, and/or sell copies of the Software, and to permit persons to whom
  9 * the Software is furnished to do so, subject to the following conditions:
 10 *
 11 * The above copyright notice and this permission notice (including the next
 12 * paragraph) shall be included in all copies or substantial portions of the
 13 * Software.
 14 *
 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
 18 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 21 */
 22
 
 
 23#include <drm/drm_fourcc.h>
 
 24
 25#include "qxl_drv.h"
 26#include "qxl_object.h"
 27
 28static 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/* returns a pointer to the already allocated qxl_rect array inside
 39 * the qxl_clip_rects. This is *not* the same as the memory allocated
 40 * on the device, it is offset to qxl_clip_rects.chunk.data */
 41static 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
 59static int
 60alloc_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
 66static void
 67free_drawable(struct qxl_device *qdev, struct qxl_release *release)
 68{
 69	qxl_release_free(qdev, release);
 70}
 71
 72/* release needs to be reserved at this point */
 73static int
 74make_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;		/* Only primary for now */
 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	/* FIXME: add clipping */
 95	drawable->clip.type = SPICE_CLIP_TYPE_NONE;
 96
 97	/*
 98	 * surfaces_dest[i] should apparently be filled out with the
 99	 * surfaces that we depend on, and surface_rects should be
100	 * filled with the rectangles of those surfaces that we
101	 * are going to use.
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/* push a draw command using the given clipping rectangles as
115 * the sources from the shadow framebuffer.
116 *
117 * Right now implementing with a single draw and a clip list. Clip
118 * lists are known to be a problem performance wise, this can be solved
119 * by treating them differently in the server.
120 */
121void 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	 * TODO: if flags & DRM_MODE_FB_DIRTY_ANNOTATE_FILL then we should
131	 * send a fill command instead, much cheaper.
132	 *
133	 * See include/drm/drm_mode.h
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	/* depth is not actually interesting, we don't mask with it */
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	/* skip the first clip rect */
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	/* do a reservation run over all the objects we just allocated */
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		goto out_release_backoff;
214
215	drawable = (struct qxl_drawable *)qxl_release_map(qdev, release);
216
217	drawable->clip.type = SPICE_CLIP_TYPE_RECTS;
218	drawable->clip.data = qxl_bo_physical_address(qdev,
219						      clips_bo, 0);
220
221	drawable->u.copy.src_area.top = 0;
222	drawable->u.copy.src_area.bottom = height;
223	drawable->u.copy.src_area.left = 0;
224	drawable->u.copy.src_area.right = width;
225
226	drawable->u.copy.rop_descriptor = SPICE_ROPD_OP_PUT;
227	drawable->u.copy.scale_mode = 0;
228	drawable->u.copy.mask.flags = 0;
229	drawable->u.copy.mask.pos.x = 0;
230	drawable->u.copy.mask.pos.y = 0;
231	drawable->u.copy.mask.bitmap = 0;
232
233	drawable->u.copy.src_bitmap = qxl_bo_physical_address(qdev, dimage->bo, 0);
234	qxl_release_unmap(qdev, release, &drawable->release_info);
235
236	clips_ptr = clips;
237	for (i = 0; i < num_clips; i++, clips_ptr += inc) {
238		rects[i].left   = clips_ptr->x1;
239		rects[i].right  = clips_ptr->x2;
240		rects[i].top    = clips_ptr->y1;
241		rects[i].bottom = clips_ptr->y2;
242	}
243	qxl_bo_kunmap(clips_bo);
244
 
245	qxl_push_command_ring_release(qdev, release, QXL_CMD_DRAW, false);
246	qxl_release_fence_buffer_objects(release);
247
248out_release_backoff:
249	if (ret)
250		qxl_release_backoff_reserve_list(release);
251out_free_image:
252	qxl_image_free_objects(qdev, dimage);
253out_free_clips:
254	qxl_bo_unref(&clips_bo);
255out_free_drawable:
256	/* only free drawable on error */
257	if (ret)
258		free_drawable(qdev, release);
259
260}