Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3254 Serge 1
#ifndef SNA_RENDER_H
2
#define SNA_RENDER_H
3
 
4
#include "compiler.h"
5
 
6
#include 
7
#include 
8
 
9
#define GRADIENT_CACHE_SIZE 16
10
 
11
#define GXinvalid 0xff
12
 
13
struct sna;
14
struct sna_glyph;
15
struct sna_video;
16
struct sna_video_frame;
17
struct brw_compile;
18
 
19
struct sna_composite_rectangles {
20
	struct sna_coordinate {
21
		int16_t x, y;
22
	} src, mask, dst;
23
	int16_t width, height;
24
};
25
 
26
struct sna_composite_op {
27
    fastcall void (*blt)(struct sna *sna, const struct sna_composite_op *op,
28
                 const struct sna_composite_rectangles *r);
29
    fastcall void (*box)(struct sna *sna,
30
                 const struct sna_composite_op *op,
31
                 const BoxRec *box);
32
    void (*boxes)(struct sna *sna, const struct sna_composite_op *op,
33
              const BoxRec *box, int nbox);
34
    void (*done)(struct sna *sna, const struct sna_composite_op *op);
35
 
36
    struct sna_damage **damage;
37
 
38
    uint32_t op;
39
 
40
    struct {
41
		PixmapPtr pixmap;
42
        CARD32    format;
43
        struct kgem_bo *bo;
44
        int16_t   x, y;
45
        uint16_t  width, height;
46
    } dst;
47
 
48
    struct sna_composite_channel {
49
        struct kgem_bo *bo;
50
//        PictTransform *transform;
51
        uint16_t width;
52
        uint16_t height;
53
        uint32_t pict_format;
54
        uint32_t card_format;
55
        uint32_t filter;
56
        uint32_t repeat;
57
        uint32_t is_affine : 1;
58
        uint32_t is_solid : 1;
59
        uint32_t is_linear : 1;
60
        uint32_t is_opaque : 1;
61
        uint32_t alpha_fixup : 1;
62
        uint32_t rb_reversed : 1;
63
        int16_t offset[2];
64
        float scale[2];
65
 
66
//        pixman_transform_t embedded_transform;
67
 
68
        union {
69
            struct {
70
				float dx, dy, offset;
71
			} linear;
72
			struct {
73
                uint32_t pixel;
74
            } gen2;
75
            struct gen3_shader_channel {
76
                int type;
77
                uint32_t mode;
78
                uint32_t constants;
79
            } gen3;
80
        } u;
81
    } src, mask;
82
    uint32_t is_affine : 1;
83
    uint32_t has_component_alpha : 1;
84
    uint32_t need_magic_ca_pass : 1;
85
    uint32_t rb_reversed : 1;
86
 
87
    int16_t floats_per_vertex;
88
    int16_t floats_per_rect;
89
    fastcall void (*prim_emit)(struct sna *sna,
90
                   const struct sna_composite_op *op,
91
                   const struct sna_composite_rectangles *r);
92
 
93
    struct sna_composite_redirect {
94
        struct kgem_bo *real_bo;
95
        struct sna_damage **real_damage, *damage;
96
        BoxRec box;
97
    } redirect;
98
 
99
    union {
100
        struct sna_blt_state {
101
			PixmapPtr src_pixmap;
102
            int16_t sx, sy;
103
 
104
            uint32_t inplace :1;
105
            uint32_t overwrites:1;
106
            uint32_t bpp : 6;
107
 
108
            uint32_t cmd;
109
            uint32_t br13;
110
            uint32_t pitch[2];
111
            uint32_t pixel;
112
            struct kgem_bo *bo[2];
113
        } blt;
114
 
115
        struct {
116
            float constants[8];
117
            uint32_t num_constants;
118
        } gen3;
119
 
120
        struct {
121
            int wm_kernel;
122
            int ve_id;
123
        } gen4;
124
 
125
        struct {
126
			int16_t wm_kernel;
127
			int16_t ve_id;
128
        } gen5;
129
 
130
        struct {
131
			uint32_t flags;
132
        } gen6;
133
 
134
        struct {
135
			uint32_t flags;
136
        } gen7;
137
	} u;
138
 
139
        void *priv;
140
};
141
 
142
struct sna_copy_op {
143
	struct sna_composite_op base;
144
 
145
	void (*blt)(struct sna *sna, const struct sna_copy_op *op,
146
		    int16_t sx, int16_t sy,
147
		    int16_t w, int16_t h,
148
		    int16_t dx, int16_t dy);
149
	void (*done)(struct sna *sna, const struct sna_copy_op *op);
150
};
151
 
152
struct sna_render {
153
	int active;
154
 
155
	int max_3d_size;
156
	int max_3d_pitch;
157
 
158
	unsigned prefer_gpu;
159
#define PREFER_GPU_BLT 0x1
160
#define PREFER_GPU_RENDER 0x2
161
#define PREFER_GPU_SPANS 0x4
162
 
163
#if 0
164
 
165
	bool (*composite)(struct sna *sna, uint8_t op,
166
			  PicturePtr dst, PicturePtr src, PicturePtr mask,
167
			  int16_t src_x, int16_t src_y,
168
			  int16_t msk_x, int16_t msk_y,
169
			  int16_t dst_x, int16_t dst_y,
170
			  int16_t w, int16_t h,
171
			  struct sna_composite_op *tmp);
172
 
173
	bool (*check_composite_spans)(struct sna *sna, uint8_t op,
174
				      PicturePtr dst, PicturePtr src,
175
				      int16_t w, int16_t h, unsigned flags);
176
	bool (*composite_spans)(struct sna *sna, uint8_t op,
177
				PicturePtr dst, PicturePtr src,
178
				int16_t src_x, int16_t src_y,
179
				int16_t dst_x, int16_t dst_y,
180
				int16_t w, int16_t h,
181
				unsigned flags,
182
				struct sna_composite_spans_op *tmp);
183
#define COMPOSITE_SPANS_RECTILINEAR 0x1
184
#define COMPOSITE_SPANS_INPLACE_HINT 0x2
185
 
186
	bool (*video)(struct sna *sna,
187
		      struct sna_video *video,
188
		      struct sna_video_frame *frame,
189
		      RegionPtr dstRegion,
190
		      short src_w, short src_h,
191
		      short drw_w, short drw_h,
192
		      short dx, short dy,
193
		      PixmapPtr pixmap);
194
 
195
	bool (*fill_boxes)(struct sna *sna,
196
			   CARD8 op,
197
			   PictFormat format,
198
			   const xRenderColor *color,
199
			   PixmapPtr dst, struct kgem_bo *dst_bo,
200
			   const BoxRec *box, int n);
201
	bool (*fill)(struct sna *sna, uint8_t alu,
202
		     PixmapPtr dst, struct kgem_bo *dst_bo,
203
		     uint32_t color,
204
		     struct sna_fill_op *tmp);
205
	bool (*fill_one)(struct sna *sna, PixmapPtr dst, struct kgem_bo *dst_bo,
206
			 uint32_t color,
207
			 int16_t x1, int16_t y1, int16_t x2, int16_t y2,
208
			 uint8_t alu);
209
	bool (*clear)(struct sna *sna, PixmapPtr dst, struct kgem_bo *dst_bo);
210
 
211
	bool (*copy_boxes)(struct sna *sna, uint8_t alu,
212
			   PixmapPtr src, struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
213
			   PixmapPtr dst, struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
214
			   const BoxRec *box, int n, unsigned flags);
215
#define COPY_LAST 0x1
216
#define COPY_SYNC 0x2
217
 
218
#endif
219
 
220
	bool (*copy)(struct sna *sna, uint8_t alu,
221
		     PixmapPtr src, struct kgem_bo *src_bo,
222
		     PixmapPtr dst, struct kgem_bo *dst_bo,
223
		     struct sna_copy_op *op);
224
 
225
	void (*flush)(struct sna *sna);
226
	void (*reset)(struct sna *sna);
227
	void (*fini)(struct sna *sna);
228
 
229
#if 0
230
 
231
	struct sna_alpha_cache {
232
		struct kgem_bo *cache_bo;
233
		struct kgem_bo *bo[256+7];
234
	} alpha_cache;
235
 
236
    struct sna_solid_cache {
237
         struct kgem_bo *cache_bo;
238
         struct kgem_bo *bo[1024];
239
		uint32_t color[1025];
240
         int last;
241
         int size;
242
         int dirty;
243
    } solid_cache;
244
 
245
	struct {
246
		struct sna_gradient_cache {
247
			struct kgem_bo *bo;
248
			int nstops;
249
			PictGradientStop *stops;
250
		} cache[GRADIENT_CACHE_SIZE];
251
		int size;
252
	} gradient_cache;
253
 
254
	struct sna_glyph_cache{
255
		PicturePtr picture;
256
		struct sna_glyph **glyphs;
257
		uint16_t count;
258
		uint16_t evict;
259
	} glyph[2];
260
	pixman_image_t *white_image;
261
	PicturePtr white_picture;
262
#if HAS_PIXMAN_GLYPHS
263
	pixman_glyph_cache_t *glyph_cache;
264
#endif
265
 
266
#endif
267
 
268
	uint16_t vb_id;
269
	uint16_t vertex_offset;
270
	uint16_t vertex_start;
271
	uint16_t vertex_index;
272
	uint16_t vertex_used;
273
	uint16_t vertex_size;
274
	uint16_t vertex_reloc[16];
275
	int nvertex_reloc;
276
 
277
    struct kgem_bo *vbo;
278
	float *vertices;
279
 
280
	float vertex_data[1024];
281
};
282
 
283
struct gen2_render_state {
284
	uint32_t target;
285
	bool need_invariant;
286
	uint32_t logic_op_enabled;
287
	uint32_t ls1, ls2, vft;
288
	uint32_t diffuse;
289
	uint32_t specular;
290
};
291
 
292
struct gen3_render_state {
293
	uint32_t current_dst;
294
	bool need_invariant;
295
	uint32_t tex_count;
296
	uint32_t last_drawrect_limit;
297
	uint32_t last_target;
298
	uint32_t last_blend;
299
	uint32_t last_constants;
300
	uint32_t last_sampler;
301
	uint32_t last_shader;
302
	uint32_t last_diffuse;
303
	uint32_t last_specular;
304
 
305
	uint16_t last_vertex_offset;
306
	uint16_t floats_per_vertex;
307
	uint16_t last_floats_per_vertex;
308
 
309
	uint32_t tex_map[4];
310
	uint32_t tex_handle[2];
311
	uint32_t tex_delta[2];
312
};
313
 
314
struct gen4_render_state {
315
	struct kgem_bo *general_bo;
316
 
317
	uint32_t vs;
318
	uint32_t sf;
319
	uint32_t wm;
320
	uint32_t cc;
321
 
322
	int ve_id;
323
	uint32_t drawrect_offset;
324
	uint32_t drawrect_limit;
325
	uint32_t last_pipelined_pointers;
326
	uint16_t last_primitive;
327
	int16_t floats_per_vertex;
328
	uint16_t surface_table;
329
 
330
	bool needs_invariant;
331
	bool needs_urb;
332
};
333
 
334
struct gen5_render_state {
335
	struct kgem_bo *general_bo;
336
 
337
	uint32_t vs;
338
	uint32_t sf[2];
339
	uint32_t wm;
340
	uint32_t cc;
341
 
342
	int ve_id;
343
	uint32_t drawrect_offset;
344
	uint32_t drawrect_limit;
345
	uint16_t last_primitive;
346
	int16_t floats_per_vertex;
347
	uint16_t surface_table;
348
	uint16_t last_pipelined_pointers;
349
 
350
	bool needs_invariant;
351
};
352
 
353
enum {
354
	GEN6_WM_KERNEL_NOMASK = 0,
355
	GEN6_WM_KERNEL_NOMASK_P,
356
 
357
    GEN6_WM_KERNEL_MASK,
358
	GEN6_WM_KERNEL_MASK_P,
359
 
360
	GEN6_WM_KERNEL_MASKCA,
361
	GEN6_WM_KERNEL_MASKCA_P,
362
 
363
	GEN6_WM_KERNEL_MASKSA,
364
	GEN6_WM_KERNEL_MASKSA_P,
365
 
366
	GEN6_WM_KERNEL_OPACITY,
367
	GEN6_WM_KERNEL_OPACITY_P,
368
 
369
	GEN6_WM_KERNEL_VIDEO_PLANAR,
370
	GEN6_WM_KERNEL_VIDEO_PACKED,
371
    GEN6_KERNEL_COUNT
372
};
373
 
374
struct gen6_render_state {
375
	const struct gt_info *info;
376
    struct kgem_bo *general_bo;
377
 
378
	uint32_t vs_state;
379
	uint32_t sf_state;
380
	uint32_t sf_mask_state;
381
	uint32_t wm_state;
382
	uint32_t wm_kernel[GEN6_KERNEL_COUNT][3];
383
 
384
	uint32_t cc_blend;
385
 
386
	uint32_t drawrect_offset;
387
	uint32_t drawrect_limit;
388
	uint32_t blend;
389
	uint32_t samplers;
390
	uint32_t kernel;
391
 
392
	uint16_t num_sf_outputs;
393
	uint16_t ve_id;
394
	uint16_t last_primitive;
395
	int16_t floats_per_vertex;
396
	uint16_t surface_table;
397
 
398
	bool needs_invariant;
399
	bool first_state_packet;
400
};
401
 
402
enum {
403
	GEN7_WM_KERNEL_NOMASK = 0,
404
	GEN7_WM_KERNEL_NOMASK_P,
405
 
406
	GEN7_WM_KERNEL_MASK,
407
	GEN7_WM_KERNEL_MASK_P,
408
 
409
	GEN7_WM_KERNEL_MASKCA,
410
	GEN7_WM_KERNEL_MASKCA_P,
411
 
412
	GEN7_WM_KERNEL_MASKSA,
413
	GEN7_WM_KERNEL_MASKSA_P,
414
 
415
	GEN7_WM_KERNEL_OPACITY,
416
	GEN7_WM_KERNEL_OPACITY_P,
417
 
418
	GEN7_WM_KERNEL_VIDEO_PLANAR,
419
	GEN7_WM_KERNEL_VIDEO_PACKED,
420
	GEN7_WM_KERNEL_COUNT
421
};
422
 
423
struct gen7_render_state {
424
	const struct gt_info *info;
425
	struct kgem_bo *general_bo;
426
 
427
	uint32_t vs_state;
428
	uint32_t sf_state;
429
	uint32_t sf_mask_state;
430
	uint32_t wm_state;
431
	uint32_t wm_kernel[GEN7_WM_KERNEL_COUNT][3];
432
 
433
	uint32_t cc_blend;
434
 
435
	uint32_t drawrect_offset;
436
	uint32_t drawrect_limit;
437
	uint32_t blend;
438
	uint32_t samplers;
439
	uint32_t kernel;
440
 
441
	uint16_t num_sf_outputs;
442
	uint16_t ve_id;
443
	uint16_t last_primitive;
444
	int16_t floats_per_vertex;
445
	uint16_t surface_table;
446
 
447
	bool needs_invariant;
448
	bool emit_flush;
449
};
450
 
451
struct sna_static_stream {
452
	uint32_t size, used;
453
	uint8_t *data;
454
};
455
 
456
int sna_static_stream_init(struct sna_static_stream *stream);
457
uint32_t sna_static_stream_add(struct sna_static_stream *stream,
458
			       const void *data, uint32_t len, uint32_t align);
459
void *sna_static_stream_map(struct sna_static_stream *stream,
460
			    uint32_t len, uint32_t align);
461
uint32_t sna_static_stream_offsetof(struct sna_static_stream *stream,
462
				    void *ptr);
463
unsigned sna_static_stream_compile_sf(struct sna *sna,
464
				      struct sna_static_stream *stream,
465
				      bool (*compile)(struct brw_compile *));
466
 
467
unsigned sna_static_stream_compile_wm(struct sna *sna,
468
				      struct sna_static_stream *stream,
469
				      bool (*compile)(struct brw_compile *, int),
470
				      int width);
471
struct kgem_bo *sna_static_stream_fini(struct sna *sna,
472
				       struct sna_static_stream *stream);
473
 
474
/*
475
struct kgem_bo *
476
sna_render_get_solid(struct sna *sna,
477
		     uint32_t color);
478
 
479
void
480
sna_render_flush_solid(struct sna *sna);
481
 
482
struct kgem_bo *
483
sna_render_get_gradient(struct sna *sna,
484
			PictGradient *pattern);
485
 
486
uint32_t sna_rgba_for_color(uint32_t color, int depth);
487
uint32_t sna_rgba_to_color(uint32_t rgba, uint32_t format);
488
bool sna_get_rgba_from_pixel(uint32_t pixel,
489
			     uint16_t *red,
490
			     uint16_t *green,
491
			     uint16_t *blue,
492
			     uint16_t *alpha,
493
			     uint32_t format);
494
bool sna_picture_is_solid(PicturePtr picture, uint32_t *color);
495
 
496
*/
497
 
498
void no_render_init(struct sna *sna);
499
 
500
bool gen2_render_init(struct sna *sna);
501
bool gen3_render_init(struct sna *sna);
502
bool gen4_render_init(struct sna *sna);
503
bool gen5_render_init(struct sna *sna);
504
bool gen6_render_init(struct sna *sna);
505
bool gen7_render_init(struct sna *sna);
506
 
507
#if 0
508
 
509
bool sna_tiling_composite(uint32_t op,
510
			  PicturePtr src,
511
			  PicturePtr mask,
512
			  PicturePtr dst,
513
			  int16_t src_x, int16_t src_y,
514
			  int16_t mask_x, int16_t mask_y,
515
			  int16_t dst_x, int16_t dst_y,
516
			  int16_t width, int16_t height,
517
			  struct sna_composite_op *tmp);
518
bool sna_tiling_fill_boxes(struct sna *sna,
519
			   CARD8 op,
520
			   PictFormat format,
521
			   const xRenderColor *color,
522
			   PixmapPtr dst, struct kgem_bo *dst_bo,
523
			   const BoxRec *box, int n);
524
 
525
bool sna_tiling_copy_boxes(struct sna *sna, uint8_t alu,
526
			   PixmapPtr src, struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
527
			   PixmapPtr dst, struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
528
			   const BoxRec *box, int n);
529
 
530
bool sna_tiling_blt_copy_boxes(struct sna *sna, uint8_t alu,
531
			       struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
532
			       struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
533
			       int bpp, const BoxRec *box, int nbox);
534
 
535
bool sna_blt_composite(struct sna *sna,
536
		       uint32_t op,
537
		       PicturePtr src,
538
		       PicturePtr dst,
539
		       int16_t src_x, int16_t src_y,
540
		       int16_t dst_x, int16_t dst_y,
541
		       int16_t width, int16_t height,
542
		       struct sna_composite_op *tmp,
543
		       bool fallback);
544
bool sna_blt_composite__convert(struct sna *sna,
545
				int x, int y,
546
				int width, int height,
547
		       struct sna_composite_op *tmp);
548
 
549
bool sna_blt_fill(struct sna *sna, uint8_t alu,
550
		  struct kgem_bo *bo,
551
		  int bpp,
552
		  uint32_t pixel,
553
		  struct sna_fill_op *fill);
554
 
555
bool sna_blt_copy(struct sna *sna, uint8_t alu,
556
		  struct kgem_bo *src,
557
		  struct kgem_bo *dst,
558
		  int bpp,
559
		  struct sna_copy_op *copy);
560
 
561
bool sna_blt_fill_boxes(struct sna *sna, uint8_t alu,
562
			struct kgem_bo *bo,
563
			int bpp,
564
			uint32_t pixel,
565
			const BoxRec *box, int n);
566
 
567
bool sna_blt_copy_boxes(struct sna *sna, uint8_t alu,
568
			struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
569
			struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
570
			int bpp,
571
			const BoxRec *box, int n);
572
bool sna_blt_copy_boxes_fallback(struct sna *sna, uint8_t alu,
573
				 PixmapPtr src, struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy,
574
				 PixmapPtr dst, struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy,
575
				 const BoxRec *box, int nbox);
576
 
577
bool _sna_get_pixel_from_rgba(uint32_t *pixel,
578
			     uint16_t red,
579
			     uint16_t green,
580
			     uint16_t blue,
581
			     uint16_t alpha,
582
			     uint32_t format);
583
 
584
static inline bool
585
sna_get_pixel_from_rgba(uint32_t * pixel,
586
			uint16_t red,
587
			uint16_t green,
588
			uint16_t blue,
589
			uint16_t alpha,
590
			uint32_t format)
591
{
592
	switch (format) {
593
	case PICT_x8r8g8b8:
594
		alpha = 0xffff;
595
		/* fall through to re-use a8r8g8b8 expansion */
596
	case PICT_a8r8g8b8:
597
		*pixel = ((alpha >> 8 << 24) |
598
			  (red >> 8 << 16) |
599
			  (green & 0xff00) |
600
			  (blue >> 8));
601
		return TRUE;
602
	case PICT_a8:
603
		*pixel = alpha >> 8;
604
		return TRUE;
605
	}
606
 
607
	return _sna_get_pixel_from_rgba(pixel, red, green, blue, alpha, format);
608
}
609
 
610
struct kgem_bo *
611
__sna_render_pixmap_bo(struct sna *sna,
612
		       PixmapPtr pixmap,
613
		       const BoxRec *box,
614
		       bool blt);
615
 
616
int
617
sna_render_pixmap_bo(struct sna *sna,
618
		     struct sna_composite_channel *channel,
619
		     PixmapPtr pixmap,
620
		     int16_t x, int16_t y,
621
		     int16_t w, int16_t h,
622
		     int16_t dst_x, int16_t dst_y);
623
 
624
bool
625
sna_render_pixmap_partial(struct sna *sna,
626
			  PixmapPtr pixmap,
627
			  struct kgem_bo *bo,
628
			  struct sna_composite_channel *channel,
629
			  int16_t x, int16_t y,
630
			  int16_t w, int16_t h);
631
 
632
int
633
sna_render_picture_extract(struct sna *sna,
634
			   PicturePtr picture,
635
			   struct sna_composite_channel *channel,
636
			   int16_t x, int16_t y,
637
			   int16_t w, int16_t h,
638
			   int16_t dst_x, int16_t dst_y);
639
 
640
int
641
sna_render_picture_approximate_gradient(struct sna *sna,
642
					PicturePtr picture,
643
					struct sna_composite_channel *channel,
644
					int16_t x, int16_t y,
645
					int16_t w, int16_t h,
646
					int16_t dst_x, int16_t dst_y);
647
 
648
int
649
sna_render_picture_fixup(struct sna *sna,
650
			 PicturePtr picture,
651
			 struct sna_composite_channel *channel,
652
			 int16_t x, int16_t y,
653
			 int16_t w, int16_t h,
654
			 int16_t dst_x, int16_t dst_y);
655
 
656
int
657
sna_render_picture_convert(struct sna *sna,
658
			   PicturePtr picture,
659
			   struct sna_composite_channel *channel,
660
			   PixmapPtr pixmap,
661
			   int16_t x, int16_t y,
662
			   int16_t w, int16_t h,
663
			   int16_t dst_x, int16_t dst_y,
664
			   bool fixup_alpha);
665
 
666
inline static void sna_render_composite_redirect_init(struct sna_composite_op *op)
667
{
668
	struct sna_composite_redirect *t = &op->redirect;
669
	t->real_bo = NULL;
670
	t->damage = NULL;
671
}
672
 
673
bool
674
sna_render_composite_redirect(struct sna *sna,
675
			      struct sna_composite_op *op,
676
			      int x, int y, int width, int height);
677
 
678
void
679
sna_render_composite_redirect_done(struct sna *sna,
680
				   const struct sna_composite_op *op);
681
 
682
bool
683
sna_composite_mask_is_opaque(PicturePtr mask);
684
 
685
#endif
686
 
687
void sna_vertex_init(struct sna *sna);
688
 
689
 
690
#endif /* SNA_RENDER_H */