1 /**********************************************************************
3 * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful but, except
10 * as otherwise stated in writing, without any warranty; without even the
11 * implied warranty of merchantability or fitness for a particular purpose.
12 * See the GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
21 * Contact Information:
22 * Imagination Technologies Ltd. <gpl-support@imgtec.com>
23 * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
25 ******************************************************************************/
27 #include "bufferclass_example.h"
28 #include "bufferclass_example_private.h"
30 #define MIN(a, b) ((a) < (b) ? (a) : (b))
32 static void FillYUV420Image(void __iomem *pvDest, int width, int height,
37 unsigned char u, v, y;
38 unsigned char *pui8y = (unsigned char __force *)pvDest;
39 unsigned short *pui16uv;
40 unsigned int count = 0;
42 for (j = 0; j < height; j++)
43 for (i = 0; i < width; i++) {
44 y = (((i + iPhase) >> 6) % (2) == 0) ? 0x7f : 0x00;
49 pui16uv = (unsigned short *)
50 ((unsigned char __force *)pvDest + (width * height));
53 for (j = 0; j < height; j += 2)
54 for (i = 0; i < width; i += 2) {
55 u = (j < (height / 2)) ?
56 ((i < (width / 2)) ? 0xFF : 0x33) :
57 ((i < (width / 2)) ? 0x33 : 0xAA);
58 v = (j < (height / 2)) ?
59 ((i < (width / 2)) ? 0xAC : 0x0) :
60 ((i < (width / 2)) ? 0x03 : 0xEE);
62 pui16uv[count++] = (v << 8) | u;
69 static void FillYUV422Image(void __iomem *pvDest, int width, int height,
74 unsigned char u, v, y0, y1;
75 unsigned int *pui32yuv = (unsigned int __force *)pvDest;
76 unsigned int count = 0;
78 for (y = 0; y < height; y++)
79 for (x = 0; x < width; x += 2) {
80 u = (y < (height / 2)) ?
81 ((x < (width / 2)) ? 0xFF : 0x33) :
82 ((x < (width / 2)) ? 0x33 : 0xAA);
83 v = (y < (height / 2)) ?
84 ((x < (width / 2)) ? 0xAA : 0x0) :
85 ((x < (width / 2)) ? 0x03 : 0xEE);
88 (((x + iPhase) >> 6) % (2) == 0) ? 0x7f : 0x00;
91 (y1 << 24) | (v << 16) | (y0 << 8) | u;
98 static void FillRGB565Image(void __iomem *pvDest, int width, int height,
102 unsigned long *pui32Addr = (unsigned long __force *)pvDest;
103 unsigned short *pui16Addr = (unsigned short __force *)pvDest;
104 unsigned long Colour32;
105 unsigned short Colour16;
106 static unsigned char Colour8;
108 Colour16 = (Colour8 >> 3) | ((Colour8 >> 2) << 5) |
109 ((Colour8 >> 3) << 11);
110 Colour32 = Colour16 | Colour16 << 16;
112 Count = (height * bytestride) >> 2;
114 for (i = 0; i < Count; i++)
115 pui32Addr[i] = Colour32;
119 pui16Addr = (unsigned short *)
120 ((unsigned char __force *)pvDest + (2 * Colour8));
122 for (i = 0; i < Count; i++) {
126 (unsigned short *)((unsigned char *)pui16Addr + bytestride);
128 Count = bytestride >> 2;
130 pui32Addr = (unsigned long *)((unsigned char __force *)pvDest +
131 (bytestride * (MIN(height - 1, 0xFF) - Colour8)));
133 for (i = 0; i < Count; i++)
134 pui32Addr[i] = 0x001F001F;
136 Colour8 = (Colour8 + 1) % MIN(height - 1, 0xFF);
139 int FillBuffer(unsigned int ui32BufferIndex)
141 struct BC_EXAMPLE_DEVINFO *psDevInfo = GetAnchorPtr();
142 struct BC_EXAMPLE_BUFFER *psBuffer;
143 struct BUFFER_INFO *psBufferInfo;
144 struct PVRSRV_SYNC_DATA *psSyncData;
146 if (psDevInfo == NULL)
149 psBuffer = &psDevInfo->psSystemBuffer[ui32BufferIndex];
150 psBufferInfo = &psDevInfo->sBufferInfo;
152 psSyncData = psBuffer->psSyncData;
155 if (psSyncData->ui32ReadOpsPending !=
156 psSyncData->ui32ReadOpsComplete)
159 psSyncData->ui32WriteOpsPending++;
162 switch (psBufferInfo->pixelformat) {
163 case PVRSRV_PIXEL_FORMAT_RGB565:
165 FillRGB565Image(psBuffer->sCPUVAddr, BC_EXAMPLE_WIDTH,
166 BC_EXAMPLE_HEIGHT, BC_EXAMPLE_STRIDE);
168 case PVRSRV_PIXEL_FORMAT_FOURCC_ORG_UYVY:
169 FillYUV422Image(psBuffer->sCPUVAddr, BC_EXAMPLE_WIDTH,
170 BC_EXAMPLE_HEIGHT, BC_EXAMPLE_STRIDE);
172 case PVRSRV_PIXEL_FORMAT_NV12:
173 FillYUV420Image(psBuffer->sCPUVAddr, BC_EXAMPLE_WIDTH,
174 BC_EXAMPLE_HEIGHT, BC_EXAMPLE_STRIDE);
179 psSyncData->ui32WriteOpsComplete++;
184 int GetBufferCount(unsigned int *pui32BufferCount)
186 struct BC_EXAMPLE_DEVINFO *psDevInfo = GetAnchorPtr();
188 if (psDevInfo == NULL)
191 *pui32BufferCount = psDevInfo->sBufferInfo.ui32BufferCount;