summaryrefslogtreecommitdiff
path: root/src/mesa/drivers/dri/nouveau_winsys/nv04_region.c
blob: cbe70983f5cb4f4d7ff0346f8572d8371fd40233 (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
#include "pipe/p_context.h"

#include "nouveau_context.h"

static INLINE int
nv04_surface_format(int cpp)
{
	switch (cpp) {
	case 1: return 0x1;
	case 2: return 0x4;
	case 4: return 0xb;
	default:
		return -1;
	}
}

static INLINE int
nv04_rect_format(int cpp)
{
	switch (cpp) {
	case 1: return 0x3;
	case 2: return 0x1;
	case 4: return 0x3;
	default:
		return -1;
	}
}

static int
nv04_region_display(void)
{
	NOUVEAU_ERR("unimplemented\n");
	return 0;
}

static int
nv04_region_copy(struct nouveau_context *nv, struct pipe_region *dst,
		 unsigned dst_offset, unsigned dx, unsigned dy,
		 struct pipe_region *src, unsigned src_offset,
		 unsigned sx, unsigned sy, unsigned w, unsigned h)
{
	int format;

	if (src->cpp != dst->cpp)
		return 1;

	if ((format = nv04_surface_format(dst->cpp)) < 0) {
		NOUVEAU_ERR("Bad cpp = %d\n", dst->cpp);
		return 1;
	}

	BEGIN_RING(NvCtxSurf2D, 0x0184, 2);
	OUT_RELOCo(src->buffer, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
	OUT_RELOCo(dst->buffer, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
	BEGIN_RING(NvCtxSurf2D, 0x0300, 4);
	OUT_RING  (format);
	OUT_RING  (((dst->pitch * dst->cpp) << 16) | (src->pitch * src->cpp));
	OUT_RELOCl(src->buffer, src_offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
	OUT_RELOCl(dst->buffer, dst_offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);

	BEGIN_RING(NvImageBlit, 0x0300, 3);
	OUT_RING  ((sy << 16) | sx);
	OUT_RING  ((dy << 16) | dx);
	OUT_RING  (( h << 16) |  w);

	return 0;
}

static int
nv04_region_fill(struct nouveau_context *nv,
		 struct pipe_region *dst, unsigned dst_offset,
		 unsigned dx, unsigned dy, unsigned w, unsigned h,
		 unsigned value)
{
	int cs2d_format, gdirect_format;

	if ((cs2d_format = nv04_surface_format(dst->cpp)) < 0) {
		NOUVEAU_ERR("Bad cpp = %d\n", dst->cpp);
		return 1;
	}

	if ((gdirect_format = nv04_rect_format(dst->cpp)) < 0) {
		NOUVEAU_ERR("Bad cpp = %d\n", dst->cpp);
		return 1;
	}

	BEGIN_RING(NvCtxSurf2D, 0x0184, 2);
	OUT_RELOCo(dst->buffer, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
	OUT_RELOCo(dst->buffer, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
	BEGIN_RING(NvCtxSurf2D, 0x0300, 4);
	OUT_RING  (cs2d_format);
	OUT_RING  (((dst->pitch * dst->cpp) << 16) | (dst->pitch * dst->cpp));
	OUT_RELOCl(dst->buffer, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
	OUT_RELOCl(dst->buffer, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);

	BEGIN_RING(NvGdiRect, 0x0300, 1);
	OUT_RING  (gdirect_format);
	BEGIN_RING(NvGdiRect, 0x03fc, 1);
	OUT_RING  (value);
	BEGIN_RING(NvGdiRect, 0x0400, 2);
	OUT_RING  ((dx << 16) | dy);
	OUT_RING  (( w << 16) |  h);

	return 0;
}

static int
nv04_region_data(struct nouveau_context *nv, struct pipe_region *dst,
		 unsigned dst_offset, unsigned dx, unsigned dy,
		 const void *src, unsigned src_pitch,
		 unsigned sx, unsigned sy, unsigned w, unsigned h)
{
	NOUVEAU_ERR("unimplemented!!\n");
	return 0;
}

int
nouveau_region_init_nv04(struct nouveau_context *nv)
{
	int ret;

	if ((ret = nouveau_grobj_alloc(nv->channel, nv->next_handle++, 0x62,
				       &nv->NvCtxSurf2D))) {
		NOUVEAU_ERR("Error creating 2D surface object: %d\n", ret);
		return 1;
	}
	BEGIN_RING(NvCtxSurf2D, 0x0184, 2);
	OUT_RING  (nv->channel->vram->handle);
	OUT_RING  (nv->channel->vram->handle);

	if ((ret = nouveau_grobj_alloc(nv->channel, nv->next_handle++, 0x9f,
				       &nv->NvImageBlit))) {
		NOUVEAU_ERR("Error creating blit object: %d\n", ret);
		return 1;
	}
	BEGIN_RING(NvImageBlit, 0x0180, 1);
	OUT_RING  (nv->sync_notifier->handle);
	BEGIN_RING(NvImageBlit, 0x019c, 1);
	OUT_RING  (nv->NvCtxSurf2D->handle);
	BEGIN_RING(NvImageBlit, 0x02fc, 1);
	OUT_RING  (3);

	if ((ret = nouveau_grobj_alloc(nv->channel, nv->next_handle++, 0x4a,
				       &nv->NvGdiRect))) {
		NOUVEAU_ERR("Error creating rect object: %d\n", ret);
		return 1;
	}
	BEGIN_RING(NvGdiRect, 0x0180, 1);
	OUT_RING  (nv->sync_notifier->handle);
	BEGIN_RING(NvGdiRect, 0x0198, 1);
	OUT_RING  (nv->NvCtxSurf2D->handle);
	BEGIN_RING(NvGdiRect, 0x02fc, 1);
	OUT_RING  (3);
	BEGIN_RING(NvGdiRect, 0x0304, 1);
	OUT_RING  (2);

	nv->region_display = nv04_region_display;
	nv->region_copy = nv04_region_copy;
	nv->region_fill = nv04_region_fill;
	nv->region_data = nv04_region_data;
	return 0;
}