aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/emgd/emgd/video/overlay/plb/ovl_plb_cache.c
blob: 1cb81a97826a3c4ed74597c87ad0ac9978370c23 (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
/* -*- pse-c -*-
 *-----------------------------------------------------------------------------
 * Filename: ovl_plb_cache.c
 * $Revision: 1.2 $
 *-----------------------------------------------------------------------------
 * Copyright © 2002-2010, Intel Corporation.
 * 
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 * 
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 
 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
 *-----------------------------------------------------------------------------
 * Description:
 *  Support functions for overlay caching.
 *-----------------------------------------------------------------------------
 */
#define MODULE_NAME hal.overlay

#include "ovl_plb_cache.h"

/* 
 * Caching helper functions.  Implemented in ovl_plb.c, but used by
 * the ovl2 and micro_ovl modules as well. 
 */

/* Tells if a rectangle has changed */
int is_changed_rect(
		    igd_rect_t *old_rect,
		    igd_rect_t *new_rect) 
{
	return ((old_rect->x1 != new_rect->x1) || 
		(old_rect->x2 != new_rect->x2) || 
		(old_rect->y1 != new_rect->y1) || 
		(old_rect->y2 != new_rect->y2) );
}

/* Tells if a surface has changed */
int is_changed_surf( 
			 igd_surface_t *old_surf, 
			 igd_surface_t *new_surf) 
{
	return( (old_surf->pitch        !=  new_surf-> pitch)        ||
		(old_surf->width        !=  new_surf-> width)        ||
		(old_surf->height       !=  new_surf-> height)       ||
		(old_surf->pixel_format !=  new_surf-> pixel_format) ||
		(old_surf->u_pitch      !=  new_surf-> u_pitch)      ||
		(old_surf->v_pitch      !=  new_surf-> v_pitch)      ||
		(old_surf->palette_info !=  new_surf-> palette_info) ||
		(old_surf->flags        !=  new_surf-> flags)        ||
		(old_surf->logic_ops    !=  new_surf-> logic_ops)    ||
		(old_surf->render_ops   !=  new_surf-> render_ops)   ||
		(old_surf->alpha        !=  new_surf-> alpha)        ||
		(old_surf->diffuse      !=  new_surf-> diffuse)      ||
		(old_surf->chroma_high  !=  new_surf-> chroma_high)  ||
		(old_surf->chroma_low   !=  new_surf-> chroma_low)   );

}

/* Tells if the color key has changed */
 int is_changed_color_key(
			 igd_ovl_info_t *old_info,
			 igd_ovl_info_t *new_info) 
{
	return ( (old_info->color_key.src_lo != new_info->color_key.src_lo)  ||
		 (old_info->color_key.src_hi != new_info->color_key.src_hi)  ||
		 (old_info->color_key.dest   != new_info->color_key.dest)    ||
		 (old_info->color_key.flags  != new_info->color_key.flags)   );

}

/* Tells if the video quality has changed */
int is_changed_vq(
			 igd_ovl_info_t *old_info,
			 igd_ovl_info_t *new_info) 
{
	return ( (old_info->video_quality.contrast   != 
		  new_info->video_quality.contrast)        || 
		 (old_info->video_quality.brightness != 
		  new_info->video_quality.brightness)      ||  
		 (old_info->video_quality.saturation != 
		  new_info->video_quality.saturation)       );

}

/* Tells if the gamma has changed */
int is_changed_gamma(
			 igd_ovl_info_t *old_info,
			 igd_ovl_info_t *new_info) 
{
	return ((old_info->gamma.red   != new_info->gamma.red)   ||
		(old_info->gamma.green != new_info->gamma.green) ||
		(old_info->gamma.blue  != new_info->gamma.blue)  ||
		(old_info->gamma.flags != new_info->gamma.flags) );

}

/* Copies a source rectangle to the cache */
void copy_src_rect_plb(igd_rect_t *src_rect, povl_plb_cache_t ovl_cache)
{
	if (src_rect) {
		OS_MEMCPY(&ovl_cache->src_rect, 
			  src_rect, 
			  sizeof(igd_rect_t));
	} else {
		OS_MEMSET(&ovl_cache->src_rect, 
			  0, 
			  sizeof(igd_rect_t));
	}
}


/* Copies a dest rectangle to the cache */
void copy_dest_rect_plb( igd_rect_t *dest_rect, povl_plb_cache_t ovl_cache)
{
	if (dest_rect) {
		OS_MEMCPY(&ovl_cache->dest_rect, 
			  dest_rect, 
			  sizeof(igd_rect_t));
	} else {
		OS_MEMSET(&ovl_cache->dest_rect, 
			  0, 
			  sizeof(igd_rect_t));
	}
}


/* Copies a surface to the cache */
void copy_surf_plb(igd_surface_t *src_surf, povl_plb_cache_t ovl_cache)
{
	if (src_surf) {
		OS_MEMCPY(&ovl_cache->src_surf, 
			  src_surf, 
			  sizeof(igd_surface_t));
	} else {
		OS_MEMSET(&ovl_cache->src_surf, 
			  0, 
			  sizeof(igd_surface_t));
	}
}


/* Copies the color key to the cache */
void copy_color_key_plb( igd_ovl_info_t *ovl_info, povl_plb_cache_t ovl_cache) 
{
	if (ovl_info) {
		OS_MEMCPY(&ovl_cache->ovl_info.color_key, 
			  &(ovl_info->color_key), 
			  sizeof(igd_ovl_color_key_info_t));
	} else {
		OS_MEMSET(&ovl_cache->ovl_info.color_key, 
			  0, 
			  sizeof(igd_ovl_color_key_info_t));
	}
}


/* Copies the video quality info to the cache */
void copy_vq_plb(igd_ovl_info_t *ovl_info, povl_plb_cache_t ovl_cache) 
{
	if (ovl_info) {
		OS_MEMCPY(&ovl_cache->ovl_info.video_quality, 
			  &(ovl_info->video_quality), 
			  sizeof(igd_ovl_video_quality_info_t));
	} else {
		OS_MEMSET(&ovl_cache->ovl_info.video_quality, 
			  0, 
			  sizeof(igd_ovl_video_quality_info_t));
	}
}


/* Copies the gamma to the cache */
void copy_gamma_plb(igd_ovl_info_t *ovl_info, povl_plb_cache_t ovl_cache) 
{
	if (ovl_info) {
		OS_MEMCPY(&ovl_cache->ovl_info.gamma, 
			  &(ovl_info->gamma), 
			  sizeof(igd_ovl_gamma_info_t));
	} else {
		OS_MEMSET(&ovl_cache->ovl_info.gamma, 
			  0, 
			  sizeof(igd_ovl_gamma_info_t));
	}
}



/* Checks to see what, if anything has changed. 
 * Clears bits in the command and config register that are invalid.
 * Returns a set of flags telling what changed */
unsigned int get_cache_changes_plb(
			       igd_surface_t  *src_surf,
			       igd_rect_t     *src_rect,
			       igd_rect_t     *dest_rect,
			       igd_ovl_info_t *ovl_info,
			       unsigned int    flags, 
			       povl_plb_cache_t ovl_cache)
{
	unsigned int cache_changed = 0;

	ovl_cache->ovl2_regs.control = 0;

	/* Have the flags changed? */
	if (ovl_cache->flags != flags) {

		/* NOTE that we did not check which flags changed. 
		   Currently if any flag changes, we invalidate all 
		   the flags. We could further optimize caching if 
		   we tested for individual flag changes, but I don't
		   think it will really help much.  Once a movie starts
		   playing, it pretty much uses the same flags
		   for its entire duration, unless the user is mucking
		   about with it as it plays, in which case it's going
		   to be slow anyway. */		

		ovl_cache->flags = flags;
		cache_changed |= IGD_OVL_PLB_UPDATE_FLAGS;

		/* Invalidating the flags cache will cause the following 
		 * bits to be re-calculated.  Clear them in preparation for
		 * re-calculation. */
		ovl_cache->ovl_regs.command &= ~ (OVL_CMD_FRAME_MODE      |
						 OVL_CMD_FIELD_MODE      |
						 OVL_CMD_FIELD_SYNC_FLIP |
						 OVL_CMD_ACT_FLD1        |
						 OVL_CMD_ACT_FLD0        );
	}

	/* Do a comparison to source surface */
	if (is_changed_surf(&ovl_cache->src_surf, src_surf)) {
		cache_changed |= IGD_OVL_PLB_UPDATE_SURF;
		copy_surf_plb(src_surf, ovl_cache);

		/* invalidating the source surface will cause the driver 
		 * to recalculate the following bits in command */
		ovl_cache->ovl_regs.command &= ~( OVL_CMD_YUV_422  |
						 OVL_CMD_YUV_420P |
						 OVL_CMD_YUV_410P |
						 OVL_CMD_YUV_NV12 |
						 OVL_CMD_Y_SWAP   |
						 OVL_CMD_UV_SWAP  |
						 OVL_CMD_RGB_8888 |
						 OVL_CMD_RGB_565  |
						 OVL_CMD_RGB_555  );

		/* Invalidating the source surface will cause the driver
		 * to recalculate the following bits in config */
		ovl_cache->ovl_regs.config &= ~ ( (1<<4)                    |
					    OVL_CONFIG_LINE_BUFF_MASK );

	}

	/* Do a comparison to source rectangle */
	if (is_changed_rect(&ovl_cache->src_rect, src_rect)) {
		cache_changed |= IGD_OVL_PLB_UPDATE_SRC;
		copy_src_rect_plb(src_rect, ovl_cache);

		/* invalidating the source rectangle will cause the driver 
		 * to recalculate the following bits in command */
		ovl_cache->ovl_regs.command &= ~( OVL_CMD_YUV_422  |
						 OVL_CMD_YUV_420P |
						 OVL_CMD_YUV_410P |
						 OVL_CMD_YUV_NV12 |
						 OVL_CMD_Y_SWAP   |
						 OVL_CMD_UV_SWAP  |
						 OVL_CMD_RGB_8888 |
						 OVL_CMD_RGB_565  |
						 OVL_CMD_RGB_555  );

		/* Invalidating the source rectangle will cause the driver
		 * to recalculate the following bits in config */
		ovl_cache->ovl_regs.config &= ~ ( (1<<4)                    |
					    OVL_CONFIG_LINE_BUFF_MASK );


	}

	/* Has our destination rectangle changed? */
	if (is_changed_rect(&ovl_cache->dest_rect, dest_rect)) {
		cache_changed |= IGD_OVL_PLB_UPDATE_DEST;
		copy_dest_rect_plb(dest_rect, ovl_cache);
	}

	/* Do a comparison to overlay info color key */
	if (is_changed_color_key(&ovl_cache->ovl_info, ovl_info)) {
		cache_changed |= (IGD_OVL_PLB_UPDATE_INFO | 
				  IGD_OVL_PLB_UPDATE_COLORKEY);
		copy_color_key_plb(ovl_info, ovl_cache);
	}

	/* Do a comparison to overlay info video quality */
	if (is_changed_vq(&ovl_cache->ovl_info, ovl_info)) {
		cache_changed |= ( IGD_OVL_PLB_UPDATE_INFO | 
				   IGD_OVL_PLB_UPDATE_VQ);
		copy_vq_plb(ovl_info, ovl_cache);
	}

	/* Do a comparison to overlay info gamma */
	if (is_changed_gamma(&ovl_cache->ovl_info, ovl_info)) {
		cache_changed |= ( IGD_OVL_PLB_UPDATE_INFO | 
				   IGD_OVL_PLB_UPDATE_GAMMA);
		copy_gamma_plb(ovl_info, ovl_cache);
	}

	return cache_changed;
}