summaryrefslogtreecommitdiff
path: root/src/host1x-gr2d.c
blob: 2b1cc294da790ed093f094969a5fc325a99dfbf8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
/*
 * Copyright (c) 2012, 2013 Erik Faye-Lund
 * Copyright (c) 2013 Thierry Reding
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

#include "vdpau_tegra.h"

#define FLOAT_TO_FIXED_6_12(fp) \
    (((int32_t) (fp * 4096.0f + 0.5f)) & ((1 << 18) - 1))

#define FLOAT_TO_FIXED_2_7(fp) \
    ((((int32_t) (fp * 128.0f)) & 0x300) | \
        (((int32_t) (fabs(fp) * 128.0f + 0.5f)) & ((1 << 8) - 1)))

#define FLOAT_TO_FIXED_1_7(fp) \
    ((((int32_t) (fp * 128.0f)) & 0x100) | \
        (((int32_t) (fabs(fp) * 128.0f + 0.5f)) & ((1 << 8) - 1)))

#define FLOAT_TO_FIXED_0_8(fp) \
    (((int32_t) (fp * 256.0f + 0.5f)) & ((1 << 8) - 1))

int host1x_gr2d_clear(struct tegra_stream *stream,
                      struct host1x_pixelbuffer *pixbuf,
                      uint32_t color)
{
    return host1x_gr2d_clear_rect(stream, pixbuf, color, 0, 0,
                                  pixbuf->width, pixbuf->height);
}

int host1x_gr2d_clear_rect(struct tegra_stream *stream,
                           struct host1x_pixelbuffer *pixbuf,
                           uint32_t color,
                           unsigned x, unsigned y,
                           unsigned width, unsigned height)
{
    unsigned tiled = 0;
    int err;

    if (x + width > pixbuf->width)
        return -EINVAL;

    if (y + height > pixbuf->height)
        return -EINVAL;

    switch (pixbuf->layout) {
    case PIX_BUF_LAYOUT_TILED_16x16:
        tiled = 1;
    case PIX_BUF_LAYOUT_LINEAR:
        break;
    default:
        host1x_error("Invalid layout %u\n", pixbuf->layout);
        return -EINVAL;
    }

    err = tegra_stream_begin(stream);
    if (err < 0)
        return err;

    tegra_stream_push_setclass(stream, HOST1X_CLASS_GR2D);
    tegra_stream_push(stream, HOST1X_OPCODE_MASK(0x09, 9));
    tegra_stream_push(stream, 0x0000003a);
    tegra_stream_push(stream, 0x00000000);
    tegra_stream_push(stream, HOST1X_OPCODE_MASK(0x1e, 7));
    tegra_stream_push(stream, 0x00000000); /* controlsecond */
    tegra_stream_push(stream, /* controlmain */
                      (PIX_BUF_FORMAT_BYTES(pixbuf->format) >> 1) << 16 |
                      1 << 6 | /* srcsld */
                      1 << 2 /* turbofill */);
    tegra_stream_push(stream, 0x000000cc);
    tegra_stream_push(stream, HOST1X_OPCODE_MASK(0x2b, 9));
    tegra_stream_push_reloc(stream, pixbuf->bo, 0);
    tegra_stream_push(stream, pixbuf->pitch);
    tegra_stream_push(stream, HOST1X_OPCODE_NONINCR(0x35, 1));
    tegra_stream_push(stream, color);
    tegra_stream_push(stream, HOST1X_OPCODE_NONINCR(0x46, 1));
    tegra_stream_push(stream, tiled << 20); /* tilemode */
    tegra_stream_push(stream, HOST1X_OPCODE_MASK(0x38, 5));
    tegra_stream_push(stream, height << 16 | width);
    tegra_stream_push(stream, y << 16 | x);

    err = tegra_stream_end(stream);
    if (err < 0)
        return err;

    err = tegra_stream_flush(stream);
    if (err < 0)
        return err;

    host1x_pixelbuffer_check_guard(pixbuf);

    return 0;
}

int host1x_gr2d_clear_rect_clipped(struct tegra_stream *stream,
                                   struct host1x_pixelbuffer *pixbuf,
                                   uint32_t color,
                                   unsigned x, unsigned y,
                                   unsigned width, unsigned height,
                                   unsigned clip_x0, unsigned clip_y0,
                                   unsigned clip_x1, unsigned clip_y1,
                                   bool draw_outside)
{
    unsigned tiled = 0;
    int err;

    if (x + width > pixbuf->width)
        return -EINVAL;

    if (y + height > pixbuf->height)
        return -EINVAL;

    switch (pixbuf->layout) {
    case PIX_BUF_LAYOUT_TILED_16x16:
        tiled = 1;
    case PIX_BUF_LAYOUT_LINEAR:
        break;
    default:
        host1x_error("Invalid layout %u\n", pixbuf->layout);
        return -EINVAL;
    }

    err = tegra_stream_begin(stream);
    if (err < 0)
        return err;

    tegra_stream_push_setclass(stream, HOST1X_CLASS_GR2D);
    tegra_stream_push(stream, HOST1X_OPCODE_MASK(0x09, 9));
    tegra_stream_push(stream, 0x0000003a);
    tegra_stream_push(stream, 0x00000000);
    tegra_stream_push(stream, HOST1X_OPCODE_MASK(0x1e, 7));
    tegra_stream_push(stream, /* controlsecond */
                      (draw_outside ? 3 : 2) << 21 /* clip inside/outside */);
    tegra_stream_push(stream, /* controlmain */
                      (PIX_BUF_FORMAT_BYTES(pixbuf->format) >> 1) << 16 |
                      1 << 6 /* srcsld */);
    tegra_stream_push(stream, 0x000000cc);
    tegra_stream_push(stream, HOST1X_OPCODE_INCR(0x22, 2));
    tegra_stream_push(stream, clip_y0 << 16 | clip_x0);
    tegra_stream_push(stream, clip_y1 << 16 | clip_x1);
    tegra_stream_push(stream, HOST1X_OPCODE_MASK(0x2b, 9));
    tegra_stream_push_reloc(stream, pixbuf->bo, 0);
    tegra_stream_push(stream, pixbuf->pitch);
    tegra_stream_push(stream, HOST1X_OPCODE_NONINCR(0x35, 1));
    tegra_stream_push(stream, color);
    tegra_stream_push(stream, HOST1X_OPCODE_NONINCR(0x46, 1));
    tegra_stream_push(stream, tiled << 20); /* tilemode */
    tegra_stream_push(stream, HOST1X_OPCODE_MASK(0x38, 5));
    tegra_stream_push(stream, height << 16 | width);
    tegra_stream_push(stream, y << 16 | x);

    err = tegra_stream_end(stream);
    if (err < 0)
        return err;

    err = tegra_stream_flush(stream);
    if (err < 0)
        return err;

    host1x_pixelbuffer_check_guard(pixbuf);

    return 0;
}

int host1x_gr2d_blit(struct tegra_stream *stream,
                     struct host1x_pixelbuffer *src,
                     struct host1x_pixelbuffer *dst,
                     unsigned int sx, unsigned int sy,
                     unsigned int dx, unsigned int dy,
                     unsigned int width, int height)
{
    unsigned src_tiled = 0;
    unsigned dst_tiled = 0;
    unsigned yflip = 0;
    unsigned xdir = 0;
    unsigned ydir = 0;
    int err;

    if (PIX_BUF_FORMAT_BYTES(src->format) !=
        PIX_BUF_FORMAT_BYTES(dst->format))
    {
        host1x_error("Unequal bytes size\n");
        return -EINVAL;
    }

    switch (src->layout) {
    case PIX_BUF_LAYOUT_TILED_16x16:
        src_tiled = 1;
    case PIX_BUF_LAYOUT_LINEAR:
        break;
    default:
        host1x_error("Invalid src layout %u\n", src->layout);
        return -EINVAL;
    }

    switch (dst->layout) {
    case PIX_BUF_LAYOUT_TILED_16x16:
        dst_tiled = 1;
    case PIX_BUF_LAYOUT_LINEAR:
        break;
    default:
        host1x_error("Invalid dst layout %u\n", dst->layout);
        return -EINVAL;
    }

    if (height < 0) {
        yflip = 1;
        height = -height;
    }

    if (sx + width > src->width ||
        dx + width > dst->width ||
        sy + height > src->height ||
        dy + height > dst->height) {
        host1x_error("Coords out of range\n");
        return -EINVAL;
    }

    if (src != dst)
        goto yflip_setup;

    if (sx >= dx + width || sx + width <= dx)
        goto yflip_setup;

    if (sy >= dy + height || sy + height <= dy)
        goto yflip_setup;

    if (dx > sx) {
        xdir = 1;
        sx += width - 1;
        dx += width - 1;
    }

    if (dy > sy) {
        ydir = 1;
        sy += height - 1;
        dy += height - 1;
    }

yflip_setup:
    if (yflip && !ydir)
        dy += height - 1;

    err = tegra_stream_begin(stream);
    if (err < 0)
        return err;

    tegra_stream_push_setclass(stream, HOST1X_CLASS_GR2D);

    tegra_stream_push(stream, HOST1X_OPCODE_MASK(0x009, 9));
    tegra_stream_push(stream, 0x0000003a); /* trigger */
    tegra_stream_push(stream, 0x00000000); /* cmdsel */

    tegra_stream_push(stream, HOST1X_OPCODE_MASK(0x01e, 0x7));
    tegra_stream_push(stream, 0x00000000); /* controlsecond */
    /*
     * [20:20] source color depth (0: mono, 1: same)
     * [17:16] destination color depth (0: 8 bpp, 1: 16 bpp, 2: 32 bpp)
     */
    tegra_stream_push(stream, /* controlmain */
                      1 << 20 |
                      (PIX_BUF_FORMAT_BYTES(dst->format) >> 1) << 16 |
                      yflip << 14 | ydir << 10 | xdir << 9);
    tegra_stream_push(stream, 0x000000cc); /* ropfade */

    tegra_stream_push(stream, HOST1X_OPCODE_NONINCR(0x046, 1));
    /*
     * [20:20] destination write tile mode (0: linear, 1: tiled)
     * [ 0: 0] tile mode Y/RGB (0: linear, 1: tiled)
     */
    tegra_stream_push(stream, dst_tiled << 20 | src_tiled); /* tilemode */

    tegra_stream_push(stream, HOST1X_OPCODE_MASK(0x02b, 0xe149));
    tegra_stream_push_reloc(stream, dst->bo, 0); /* dstba */
    tegra_stream_push(stream, dst->pitch); /* dstst */
    tegra_stream_push_reloc(stream, src->bo, 0); /* srcba */
    tegra_stream_push(stream, src->pitch); /* srcst */
    tegra_stream_push(stream, height << 16 | width); /* dstsize */
    tegra_stream_push(stream, sy << 16 | sx); /* srcps */
    tegra_stream_push(stream, dy << 16 | dx); /* dstps */

    err = tegra_stream_end(stream);
    if (err < 0)
        return err;

    err = tegra_stream_flush(stream);
    if (err < 0)
        return err;

    host1x_pixelbuffer_check_guard(dst);

    return 0;
}

static uint32_t sb_offset(struct host1x_pixelbuffer *pixbuf,
                          uint32_t xpos, uint32_t ypos)
{
    uint32_t offset;
    uint32_t bytes_per_pixel = PIX_BUF_FORMAT_BYTES(pixbuf->format);
    uint32_t pixels_per_line = pixbuf->pitch / bytes_per_pixel;
    uint32_t xb;

    if (pixbuf->layout == PIX_BUF_LAYOUT_LINEAR) {
        offset = ypos * pixbuf->pitch;
        offset += xpos * bytes_per_pixel;
    } else {
        xb = xpos * bytes_per_pixel;
        offset = 16 * pixels_per_line * (ypos / 16);
        offset += 256 * (xb / 16);
        offset += 16 * (ypos % 16);
        offset += xb % 16;
    }

    return offset;
}

int host1x_gr2d_surface_blit(struct tegra_stream *stream,
                             struct host1x_pixelbuffer *src,
                             struct host1x_pixelbuffer *dst,
                             VdpCSCMatrix cscmat,
                             unsigned int sx, unsigned int sy,
                             unsigned int src_width, unsigned int src_height,
                             unsigned int dx, unsigned int dy,
                             unsigned int dst_width, int dst_height)
{
    float inv_scale_x;
    float inv_scale_y;
    unsigned src_tiled = 0;
    unsigned dst_tiled = 0;
    unsigned yflip = 0;
    unsigned src_fmt;
    unsigned dst_fmt;
    unsigned hftype;
    unsigned vftype;
    unsigned vfen;
    int err;

    switch (src->layout) {
    case PIX_BUF_LAYOUT_TILED_16x16:
        src_tiled = 1;
    case PIX_BUF_LAYOUT_LINEAR:
        break;
    default:
        host1x_error("Invalid src layout %u\n", src->layout);
        return -EINVAL;
    }

    switch (dst->layout) {
    case PIX_BUF_LAYOUT_TILED_16x16:
        dst_tiled = 1;
    case PIX_BUF_LAYOUT_LINEAR:
        break;
    default:
        host1x_error("Invalid dst layout %u\n", dst->layout);
        return -EINVAL;
    }

    /*
     * GR2DSB doesn't support this format. Not sure that this is fine
     * to do, but scaled result looks correct.
     */
    if (src->format == dst->format &&
        src->format == PIX_BUF_FMT_RGBA8888) {
        src_fmt = 14;
        dst_fmt = 14;
        goto coords_check;
    }

    switch (src->format) {
    case PIX_BUF_FMT_ABGR8888:
        src_fmt = 14;
        break;
    case PIX_BUF_FMT_ARGB8888:
        src_fmt = 15;
        break;
    case PIX_BUF_FMT_YV12:
        src_fmt = 0;
        break;
    default:
        host1x_error("Invalid src format %u\n", src->format);
        return -EINVAL;
    }

    switch (dst->format) {
    case PIX_BUF_FMT_ABGR8888:
        dst_fmt = 14;
        break;
    case PIX_BUF_FMT_ARGB8888:
        dst_fmt = 15;
        break;
    default:
        host1x_error("Invalid dst format %u\n", dst->format);
        return -EINVAL;
    }

coords_check:
    if (dst_height < 0) {
        yflip = 1;
        dst_height = -dst_height;
    }

    if (sx + src_width > src->width ||
        dx + dst_width > dst->width ||
        sy + src_height > src->height ||
        dy + dst_height > dst->height) {
        host1x_error("Coords out of range\n");
        return -EINVAL;
    }

    inv_scale_x = (src_width) / (float)(dst_width);
    inv_scale_y = (src_height) / (float)(dst_height);

    if (inv_scale_y > 64.0f || inv_scale_y < 1.0f / 4096.0f) {
        host1x_error("Unsupported Y scale\n");
        return -EINVAL;
    }

    if (inv_scale_x > 64.0f || inv_scale_x < 1.0f / 4096.0f) {
        host1x_error("Unsupported X scale\n");
        return -EINVAL;
    }

    if (inv_scale_x == 1.0f)
        hftype = 7;
    else if (inv_scale_x < 1.0f)
        hftype = 0;
    else if (inv_scale_x < 1.3f)
        hftype = 1;
    else if (inv_scale_x < 2.0f)
        hftype = 3;
    else
        hftype = 6;

    if (inv_scale_y == 1.0f) {
        vftype = 0;
        vfen = 0;
    } else {
        vfen = 1;

        if (inv_scale_y < 1.0f)
            vftype = 0;
        else if (inv_scale_y < 1.3f)
            vftype = 1;
        else if (inv_scale_y < 2.0f)
            vftype = 2;
        else
            vftype = 3;
    }

    err = tegra_stream_begin(stream);
    if (err < 0)
        return err;

    tegra_stream_push_setclass(stream, HOST1X_CLASS_GR2D_SB);

    tegra_stream_push(stream, HOST1X_OPCODE_MASK(0x009, 0xF09));
    tegra_stream_push(stream, 0x00000038); /* trigger */
    tegra_stream_push(stream, 0x00000001); /* cmdsel */
    tegra_stream_push(stream, FLOAT_TO_FIXED_6_12(inv_scale_y)); /* vdda */
    tegra_stream_push(stream, FLOAT_TO_FIXED_0_8(sy)); /* vddaini */
    tegra_stream_push(stream, FLOAT_TO_FIXED_6_12(inv_scale_x)); /* hdda */
    tegra_stream_push(stream, FLOAT_TO_FIXED_0_8(sx)); /* hddainils */

    /* CSC RGB -> RGB coefficients */
    if (src->format != PIX_BUF_FMT_YV12) {
        tegra_stream_push(stream, HOST1X_OPCODE_MASK(0x15, 0x787));

        tegra_stream_push(stream,
                /* cvr */ FLOAT_TO_FIXED_2_7(1.0f) << 12 |
                /* cub */ FLOAT_TO_FIXED_2_7(1.0f)); /* cscfirst */
        tegra_stream_push(stream,
                /* cyx */ FLOAT_TO_FIXED_1_7(1.0f) << 24 |
                /* cur */ FLOAT_TO_FIXED_2_7(0.0f) << 12 |
                /* cug */ FLOAT_TO_FIXED_1_7(0.0f)); /* cscsecond */
        tegra_stream_push(stream,
                /* cvb */ FLOAT_TO_FIXED_2_7(0.0f) << 16 |
                /* cvg */ FLOAT_TO_FIXED_1_7(0.0f)); /* cscthird */
    } else {
        tegra_stream_push(stream, HOST1X_OPCODE_MASK(0x15, 0x7E7));

        tegra_stream_push(stream,
                /* yos */ (-16) << 24 |
                /* cvr */ FLOAT_TO_FIXED_2_7(cscmat[0][2]) << 12 |
                /* cub */ FLOAT_TO_FIXED_2_7(cscmat[2][1])); /* cscfirst */
        tegra_stream_push(stream,
                /* cyx */ FLOAT_TO_FIXED_1_7(cscmat[0][0]) << 24 |
                /* cur */ FLOAT_TO_FIXED_2_7(cscmat[0][1]) << 12 |
                /* cug */ FLOAT_TO_FIXED_1_7(cscmat[1][1])); /* cscsecond */
        tegra_stream_push(stream,
                /* cvb */ FLOAT_TO_FIXED_2_7(cscmat[2][2]) << 16 |
                /* cvg */ FLOAT_TO_FIXED_1_7(cscmat[1][2])); /* cscthird */

        tegra_stream_push_reloc(stream, src->bos[1], src->bo_offset[1]); /* uba */
        tegra_stream_push_reloc(stream, src->bos[2], src->bo_offset[2]); /* vba */
    }

    tegra_stream_push(stream, dst_fmt << 8 | src_fmt); /* sbformat */
    tegra_stream_push(stream, /* controlsb */
                      hftype << 20 | vfen << 18 | vftype << 16 |
                      (3 << 8) /* uvst */ |
                      ((src->format == PIX_BUF_FMT_YV12) << 5) /* imode */);
    tegra_stream_push(stream, 0x00000000); /* controlsecond */
    /*
     * [20:20] source color depth (0: mono, 1: same)
     * [17:16] destination color depth (0: 8 bpp, 1: 16 bpp, 2: 32 bpp)
     */
    tegra_stream_push(stream, /* controlmain */
                      1 << 28 | 1 << 27 |
                      (PIX_BUF_FORMAT_BYTES(dst->format) >> 1) << 16 |
                      yflip << 14);

    tegra_stream_push(stream, HOST1X_OPCODE_MASK(0x044, 0x35));
    tegra_stream_push(stream, src->pitch_uv); /* uvstride */
    /*
     * [20:20] destination write tile mode (0: linear, 1: tiled)
     * [ 0: 0] tile mode Y/RGB (0: linear, 1: tiled)
     */
    tegra_stream_push(stream, dst_tiled << 20 | src_tiled); /* tilemode */
    tegra_stream_push_reloc(stream, src->bo, /* srcba_sb_surfbase */
                            sb_offset(src, sx, sy));
    tegra_stream_push_reloc(stream, dst->bo, /* dstba_sb_surfbase */
                            sb_offset(dst, dx, dy) +
                                yflip * dst->pitch * (dst_height - 1));

    tegra_stream_push(stream, HOST1X_OPCODE_MASK(0x02b, 0x3149));
    tegra_stream_push_reloc(stream, dst->bo, /* dstba */
                            sb_offset(dst, dx, dy) +
                                yflip * dst->pitch * (dst_height - 1));
    tegra_stream_push(stream, dst->pitch); /* dstst */
    tegra_stream_push_reloc(stream, src->bo, /* srcba */
                            sb_offset(src, sx, sy));
    tegra_stream_push(stream, src->pitch); /* srcst */
    tegra_stream_push(stream, (src_height - 1) << 16 | src_width); /* srcsize */
    tegra_stream_push(stream, (dst_height - 1) << 16 | dst_width); /* dstsize */

    err = tegra_stream_end(stream);
    if (err < 0)
        return err;

    err = tegra_stream_flush(stream);
    if (err < 0)
        return err;

    host1x_pixelbuffer_check_guard(dst);

    return 0;
}