source: svn/trunk/newcon3bcm2_21bu/magnum/commonutils/sur/7552/bsur.c @ 2

Last change on this file since 2 was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 22.8 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2003-2012, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: bsur.c $
11 * $brcm_Revision: Hydra_Software_Devel/36 $
12 * $brcm_Date: 3/28/12 10:03a $
13 *
14 * Module Description:
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /magnum/commonutils/sur/7038/bsur.c $
19 *
20 * Hydra_Software_Devel/36   3/28/12 10:03a erickson
21 * SW7358-245: M2MC HW accesses palette as 1024 bytes, regardless of
22 * palette format. so we must alloc a constant 1024 to avoid ARC
23 * violations
24 *
25 * Hydra_Software_Devel/35   9/29/11 5:08p nissen
26 * SW7425-1078: Fixed problem with getting NULL palette handle.
27 *
28 * Hydra_Software_Devel/34   9/29/11 1:39p nissen
29 * SW7425-1078: Made it unnecessary to provide a palette when creating a
30 * P0 surface.
31 *
32 * Hydra_Software_Devel/33   9/28/11 4:19p nissen
33 * SW7425-1078: Added support for A0 and P0 pixel formats.
34 *
35 * Hydra_Software_Devel/32   3/18/11 1:42p nissen
36 * SW7420-1200: Added function to get all the packet blit info.
37 *
38 * Hydra_Software_Devel/31   2/5/10 3:30p erickson
39 * SW3548-2765: added BDBG_OBJECT_ASSERT protection for surface and
40 * palette handles
41 *
42 * Hydra_Software_Devel/30   2/26/09 4:24p nissen
43 * PR 47303: Added prediction mode field to settings structure.
44 *
45 * Hydra_Software_Devel/29   10/3/08 10:45a yuxiaz
46 * PR47303: More TestFeature1 support in BSUR.
47 *
48 * Hydra_Software_Devel/28   10/1/08 5:41p nissen
49 * PR 47303: Added functions to get default surface settings and
50 * TestFeature1 settings. Added settings structure parameter to surface
51 * create function.
52 *
53 * Hydra_Software_Devel/27   4/4/08 11:18a nissen
54 * PR 40122: Added support for 10-bit 422 40-bit packed formats.
55 *
56 * Hydra_Software_Devel/26   11/15/06 10:55a nissen
57 * PR 25683: Added function to set surface ID and removed surface ID
58 * global variable.
59 *
60 * Hydra_Software_Devel/25   11/10/06 12:52p nissen
61 * PR 25023: Fixed compiler warning.
62 *
63 * Hydra_Software_Devel/24   11/8/06 10:58a nissen
64 * PR 25683: Added support for a surface ID.
65 *
66 * Hydra_Software_Devel/23   8/25/06 11:08a nissen
67 * PR 18990: Added support for 10-bit YCbCr 422 alignment.
68 *
69 * Hydra_Software_Devel/22   3/21/06 12:53p nissen
70 * PR 20331: Added functions to return offsets for surfaces and palettes.
71 *
72 * Hydra_Software_Devel/21   3/15/06 11:51a nissen
73 * PR 15840: Added support for creating YCbCr 420 surfaces.
74 *
75 * Hydra_Software_Devel/20   11/10/05 5:02p syang
76 * PR 12244: move alpha-only pixel constant color setting from BSUR to
77 * BVDC
78 *
79 * Hydra_Software_Devel/19   2/24/05 1:43p nissen
80 * PR 14207: Added bstd.h include.
81 *
82 * Hydra_Software_Devel/18   2/2/05 10:12a nissen
83 * PR 13979: Added user allocated palette memory alignment check.
84 *
85 * Hydra_Software_Devel/17   8/11/04 6:27p syang
86 * PR 12244: added alpha only pixel format support for gfx feeder (new B0
87 * feature)
88 *
89 * Hydra_Software_Devel/16   6/11/04 4:50p syang
90 * PR 11299: changed func name BSUR_Palette_GetEntryFormat to
91 * BSUR_Palette_GetFormat
92 *
93 * Hydra_Software_Devel/15   6/7/04 1:22p nissen
94 * PR 11307: Added code to verify that palette surfaces are created with
95 * palettes.
96 *
97 * Hydra_Software_Devel/14   5/3/04 10:49p nissen
98 * PR 9635: Increased address alignment when allocating memory for
99 * palettes.
100 *
101 * Hydra_Software_Devel/13   11/20/03 6:51p nissen
102 * Removed converting handle parameters to pointers.
103 *
104 * Hydra_Software_Devel/12   10/28/03 1:53p syang
105 * added BSUR_Palette_GetEntryFormat
106 *
107 * Hydra_Software_Devel/11   10/20/03 1:41p nissen
108 * Eliminated warnings.
109 *
110 * Hydra_Software_Devel/10   9/4/03 5:48p jasonh
111 * Changed calls to BMEM_Alloc to BMEM_AllocAligned.
112 *
113 * Hydra_Software_Devel/9   8/25/03 5:50p pntruong
114 * Added the double parathesis for BDBG calls (this fixed compile error
115 * for msvc60).
116 *
117 * Hydra_Software_Devel/8   8/21/03 1:25p nissen
118 * Added constraints for width and height being a power of 2.
119 *
120 * Hydra_Software_Devel/7   8/20/03 4:30p nissen
121 * Removed open and close functions. Replaced usage mask functions and
122 * parameters with constraint mask functions and parameters. Replaced
123 * surface module handle parameters with memory module handle.
124 *
125 * Hydra_Software_Devel/6   8/19/03 10:07a nissen
126 * Removed usage mask functions and parameters and added alignment
127 * parameter to surface and palette creation functions.
128 *
129 * Hydra_Software_Devel/5   8/6/03 2:27p nissen
130 * Changed all references to "unsigned int" to "uint32_t".
131 *
132 * Hydra_Software_Devel/4   6/5/03 5:33p jasonh
133 * Added setting for debug module.
134 *
135 * Hydra_Software_Devel/3   6/5/03 11:36a nissen
136 * Added entry point function to get surface format.
137 *
138 * Hydra_Software_Devel/2   4/25/03 3:38p nissen
139 * Added alignment checking when creating surfaces and palettes.
140 *
141 * Hydra_Software_Devel/1   4/25/03 12:18p nissen
142 * Surface module
143 *
144 ***************************************************************************/
145
146#include "bstd.h"
147#include "bstd_defs.h"
148#include "berr.h"
149#include "bkni.h"
150#include "bmem.h"
151#include "bsur.h"
152#include "bsur_private.h"
153
154BDBG_MODULE(BSUR);
155
156BDBG_OBJECT_ID(BSUR_Palette);
157BDBG_OBJECT_ID(BSUR_Surface);
158
159/***************************************************************************/
160BERR_Code BSUR_Palette_Create(
161        BMEM_Handle hMem,
162        uint32_t ulNumEntries,
163        void *pvPaletteAddress,
164        BPXL_Format eFormat,
165        uint32_t ulConstraintMask,
166        BSUR_Palette_Handle *phPalette )
167{
168        BSUR_Palette_Handle hPalette;
169
170        BDBG_ENTER(BSUR_Palette_Create);
171        BDBG_ASSERT( ulNumEntries );
172        BDBG_ASSERT( phPalette );
173
174        if( hMem == (BMEM_Handle) 0 )
175                return BERR_TRACE(BERR_INVALID_PARAMETER);
176
177        /* check palette format */
178        if( (eFormat != BPXL_eA8_Y8_Cb8_Cr8) && (eFormat != BPXL_eA8_R8_G8_B8) )
179                return BERR_TRACE(BERR_INVALID_PARAMETER);
180
181        /* check palette address alignment */
182        if( pvPaletteAddress && BSUR_P_PALETTE_UNALIGNED( pvPaletteAddress ) )
183                return BERR_TRACE(BERR_INVALID_PARAMETER);
184
185        /* allocate memory for private palette data */
186        hPalette = (BSUR_Palette_Handle) BKNI_Malloc( sizeof (BSUR_P_Palette_Handle) );
187        if( hPalette == NULL )
188                return BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);
189
190        BKNI_Memset( hPalette, 0, sizeof (BSUR_P_Palette_Handle) );
191        BDBG_OBJECT_SET(hPalette, BSUR_Palette);
192
193        /* allocate memory for palette entries if required */
194        if( pvPaletteAddress == NULL )
195        {
196        /* M2MC HW accesses palette as 1024 bytes, regardless of palette format. so we must alloc a constant 1024 to avoid ARC violations. */
197                pvPaletteAddress = BMEM_AllocAligned( hMem, 1024 * BPXL_BITS_PER_PIXEL(eFormat) / 8, BSUR_P_PALETTE_ALIGNMENT, 0 );
198                if( pvPaletteAddress == NULL )
199                {
200                BDBG_OBJECT_DESTROY(hPalette, BSUR_Palette);
201                        BKNI_Free( (void *) hPalette );
202                        return BERR_TRACE(BERR_OUT_OF_DEVICE_MEMORY);
203                }
204                hPalette->bDriverOwned = true;
205        }
206
207        /* set private palette data */
208        hPalette->hMem = hMem;
209        hPalette->pvAddress = pvPaletteAddress;
210        hPalette->ulNumEntries = ulNumEntries;
211        hPalette->ulConstraintMask = ulConstraintMask;
212        hPalette->eFormat = eFormat;
213
214        /* set return handle */
215        *phPalette = hPalette;
216
217        BDBG_LEAVE(BSUR_Palette_Create);
218        return BERR_SUCCESS;
219}
220
221/***************************************************************************/
222BERR_Code BSUR_Palette_Destroy(
223        BSUR_Palette_Handle hPalette )
224{
225        BDBG_ENTER(BSUR_Palette_Destroy);
226        BDBG_OBJECT_ASSERT(hPalette, BSUR_Palette);
227
228        /* free palette memory if required */
229        if( hPalette->bDriverOwned && hPalette->pvAddress )
230                BMEM_Free( hPalette->hMem, hPalette->pvAddress );
231
232        /* free private palette data */
233        BDBG_OBJECT_DESTROY(hPalette, BSUR_Palette);
234        BKNI_Free( (void *) hPalette );
235
236        BDBG_LEAVE(BSUR_Palette_Destroy);
237        return BERR_SUCCESS;
238}
239
240/***************************************************************************/
241BERR_Code BSUR_Palette_GetConstraintMask(
242        BSUR_Palette_Handle hPalette,
243        uint32_t *pulConstraintMask )
244{
245        BDBG_ENTER(BSUR_Palette_GetConstraintMask);
246        BDBG_OBJECT_ASSERT(hPalette, BSUR_Palette);
247        BDBG_ASSERT( pulConstraintMask );
248
249        /* set return value */
250        *pulConstraintMask = hPalette->ulConstraintMask;
251
252        BDBG_LEAVE(BSUR_Palette_GetConstraintMask);
253        return BERR_SUCCESS;
254}
255
256/***************************************************************************/
257BERR_Code BSUR_Palette_GetNumEntries(
258        BSUR_Palette_Handle hPalette,
259        uint32_t *pulNumEntries )
260{
261        BDBG_ENTER(BSUR_Palette_GetNumEntries);
262        BDBG_OBJECT_ASSERT(hPalette, BSUR_Palette);
263        BDBG_ASSERT( pulNumEntries );
264
265        /* set return value */
266        *pulNumEntries = hPalette->ulNumEntries;
267
268        BDBG_LEAVE(BSUR_Palette_GetNumEntries);
269        return BERR_SUCCESS;
270}
271
272/***************************************************************************/
273BERR_Code BSUR_Palette_GetAddress(
274        BSUR_Palette_Handle hPalette,
275        void **ppvAddress )
276{
277        BDBG_ENTER(BSUR_Palette_GetAddress);
278        BDBG_OBJECT_ASSERT(hPalette, BSUR_Palette);
279        BDBG_ASSERT( ppvAddress );
280
281        /* set return value */
282        *ppvAddress = hPalette->pvAddress;
283
284        BDBG_LEAVE(BSUR_Palette_GetAddress);
285        return BERR_SUCCESS;
286}
287
288/***************************************************************************/
289BERR_Code BSUR_Palette_GetOffset(
290        BSUR_Palette_Handle hPalette,
291        uint32_t *pulOffset )
292{
293        BERR_Code err;
294
295        BDBG_ENTER(BSUR_Palette_GetOffset);
296        BDBG_OBJECT_ASSERT(hPalette, BSUR_Palette);
297        BDBG_ASSERT( pulOffset );
298
299        /* get offset */
300        err = BMEM_ConvertAddressToOffset( hPalette->hMem, hPalette->pvAddress, pulOffset );
301        if( err != BERR_SUCCESS )
302                return BERR_TRACE(err);
303
304        BDBG_LEAVE(BSUR_Palette_GetOffset);
305        return BERR_SUCCESS;
306}
307
308/***************************************************************************/
309BERR_Code BSUR_Palette_GetFormat(
310        BSUR_Palette_Handle hPalette,
311        BPXL_Format *peFormat )
312{
313        BDBG_ENTER(BSUR_Palette_GetFormat);
314        BDBG_OBJECT_ASSERT(hPalette, BSUR_Palette);
315        BDBG_ASSERT( peFormat );
316
317        /* set return value */
318        *peFormat = hPalette->eFormat;
319
320        BDBG_LEAVE(BSUR_Palette_GetFormat);
321        return BERR_SUCCESS;
322}
323
324/***************************************************************************/
325static BSUR_Surface_Settings s_SUR_DefaultSettings =
326{
327        { false, BSUR_P_DCX_TESTFEATURE1_BITSPERPIXEL_DEFAULT, 0 }  /* stTestFeature1Settings */
328};
329
330/***************************************************************************/
331BERR_Code BSUR_Surface_GetDefaultSettings(
332        BSUR_Surface_Settings *pDefSettings )
333{
334        BDBG_ENTER(BSUR_Surface_GetDefaultSettings);
335        BDBG_ASSERT( pDefSettings );
336
337        /* set return value */
338        *pDefSettings = s_SUR_DefaultSettings;
339
340        BDBG_LEAVE(BSUR_Surface_GetDefaultSettings);
341        return BERR_SUCCESS;
342}
343
344/***************************************************************************/
345BERR_Code BSUR_Surface_Create(
346        BMEM_Handle hMem,
347        uint32_t ulWidth,
348        uint32_t ulHeight,
349        uint32_t ulPitch,
350        void *pvPixelAddress,
351        BPXL_Format eFormat,
352        BSUR_Palette_Handle hPalette,
353        uint32_t ulConstraintMask,
354        BSUR_Surface_Settings *pSettings,
355        BSUR_Surface_Handle *phSurface )
356{
357        BSUR_Surface_Handle hSurface;
358        unsigned int ucAlignBits = 2;
359
360        BDBG_ENTER(BSUR_Surface_Create);
361        BDBG_ASSERT( ulWidth );
362        BDBG_ASSERT( ulHeight );
363        BDBG_ASSERT( phSurface );
364
365        /* check parameters */
366        if( hMem == (BMEM_Handle) 0 )
367                return BERR_TRACE(BERR_INVALID_PARAMETER);
368
369        if( pvPixelAddress && (ulPitch == 0) )
370                return BERR_TRACE(BERR_INVALID_PARAMETER);
371
372        /* check for alignment constraints */
373        if( BSUR_CONSTRAINT_MATCH(ulConstraintMask, BSUR_CONSTRAINT_ADDRESS_PIXEL_ALIGNED) )
374        {
375                /* check pixel address alignment */
376                if( pvPixelAddress && BSUR_P_PIXEL_UNALIGNED( eFormat, pvPixelAddress ) )
377                        return BERR_TRACE(BERR_INVALID_PARAMETER);
378
379                /* check pitch alignment */
380                if( ulPitch && BSUR_P_PIXEL_UNALIGNED( eFormat, ulPitch ) )
381                        return BERR_TRACE(BERR_INVALID_PARAMETER);
382        }
383
384        /* check for power of 2 constraints */
385        if( BSUR_CONSTRAINT_MATCH(ulConstraintMask, BSUR_CONSTRAINT_WIDTH_POWER_2) && (ulWidth & (ulWidth - 1)) )
386                return BERR_TRACE(BERR_INVALID_PARAMETER);
387
388        if( BSUR_CONSTRAINT_MATCH(ulConstraintMask, BSUR_CONSTRAINT_HEIGHT_POWER_2) && (ulHeight & (ulHeight - 1)) )
389                return BERR_TRACE(BERR_INVALID_PARAMETER);
390
391        /* check for YCbCr420 alignment constraints */
392        if( BSUR_CONSTRAINT_MATCH(ulConstraintMask, BSUR_CONSTRAINT_YCbCr420_FORMAT) )
393        {
394                /* check pixel address alignment */
395                if( pvPixelAddress && BSUR_P_YCbCr420_UNALIGNED( pvPixelAddress ) )
396                        return BERR_TRACE(BERR_INVALID_PARAMETER);
397
398                /* check pitch alignment */
399                if( ulPitch && BSUR_P_YCbCr420_UNALIGNED( ulPitch ) )
400                        return BERR_TRACE(BERR_INVALID_PARAMETER);
401
402                ucAlignBits = BSUR_P_YCbCr420_ALIGNMENT;
403        }
404
405        /* check for YCbCr422 10-bit alignment constraints */
406        if( BSUR_CONSTRAINT_MATCH(ulConstraintMask, BSUR_CONSTRAINT_YCbCr422_10BIT_FORMAT) )
407        {
408                /* check pixel address alignment */
409                if( pvPixelAddress && BSUR_P_YCbCr422_10BIT_UNALIGNED( pvPixelAddress ) )
410                        return BERR_TRACE(BERR_INVALID_PARAMETER);
411
412                /* check pitch alignment */
413                if( ulPitch && BSUR_P_YCbCr422_10BIT_UNALIGNED( ulPitch ) )
414                        return BERR_TRACE(BERR_INVALID_PARAMETER);
415
416                ucAlignBits = BSUR_P_YCbCr422_10BIT_ALIGNMENT;
417        }
418
419        /* check for YCbCr422 10-bit packed alignment constraints */
420        if( BSUR_CONSTRAINT_MATCH(ulConstraintMask, BSUR_CONSTRAINT_YCbCr422_10BIT_PACKED_FORMAT) )
421        {
422                /* check pixel address alignment */
423                if( pvPixelAddress && BSUR_P_YCbCr422_10BIT_PACKED_UNALIGNED( pvPixelAddress ) )
424                        return BERR_TRACE(BERR_INVALID_PARAMETER);
425
426                /* check pitch alignment */
427                if( ulPitch && BSUR_P_YCbCr422_10BIT_PACKED_UNALIGNED( ulPitch ) )
428                        return BERR_TRACE(BERR_INVALID_PARAMETER);
429
430                ucAlignBits = BSUR_P_YCbCr422_10BIT_PACKED_ALIGNMENT;
431        }
432
433        /* check for DCX TestFeature1 alignment constraints */
434        if( BSUR_CONSTRAINT_MATCH(ulConstraintMask, BSUR_CONSTRAINT_DCX_TESTFEATURE1_FORMAT) )
435        {
436                /* check pixel address alignment */
437                if( pvPixelAddress && BSUR_P_DCX_TESTFEATURE1_UNALIGNED( pvPixelAddress ) )
438                        return BERR_TRACE(BERR_INVALID_PARAMETER);
439
440                /* check if pitch or palette handle is zero */
441                if( ulPitch && hPalette )
442                        return BERR_TRACE(BERR_INVALID_PARAMETER);
443
444                /* check if format is RGB, YCbCr422 or YCbCr444 */
445                if( (BPXL_IS_RGB_FORMAT(eFormat) == 0) && (BPXL_IS_YCbCr444_FORMAT(eFormat) == 0) )
446                        return BERR_TRACE(BERR_INVALID_PARAMETER);
447
448                ucAlignBits = BSUR_P_DCX_TESTFEATURE1_ALIGNMENT;
449        }
450
451        /* verify DCX TestFeature1 settings */
452        if( pSettings )
453        {
454                if( pSettings->stTestFeature1Settings.bEnable && (
455                        (pSettings->stTestFeature1Settings.ulBitsPerPixel < BSUR_P_DCX_TESTFEATURE1_BITSPERPIXEL_MINIMUM) ||
456                        (pSettings->stTestFeature1Settings.ulBitsPerPixel > BSUR_P_DCX_TESTFEATURE1_BITSPERPIXEL_MAXIMUM)) )
457                        return BERR_TRACE(BERR_INVALID_PARAMETER);
458        }
459
460        /* check for palette with palette formats */
461        if( BPXL_IS_PALETTE_FORMAT(eFormat) && (hPalette == 0) && (eFormat != BPXL_eP0) )
462                return BERR_TRACE(BERR_INVALID_PARAMETER);
463
464        /* allocate memory for private surface data */
465        hSurface = (BSUR_Surface_Handle) BKNI_Malloc( sizeof (BSUR_P_Surface_Handle) );
466        if( hSurface == NULL )
467                return BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);
468
469        BKNI_Memset( hSurface, 0, sizeof (BSUR_P_Surface_Handle) );
470        BDBG_OBJECT_SET(hSurface, BSUR_Surface);
471
472        /* allocate memory for surface pixels if required */
473        if( (pvPixelAddress == NULL) && (eFormat != BPXL_eA0) && (eFormat != BPXL_eP0) )
474        {
475                uint32_t ulMemorySize;
476                if( pSettings && pSettings->stTestFeature1Settings.bEnable )
477                {
478                        /* DCX TestFeature1 memory size */
479                        uint32_t ulAlignMask = (1 << BSUR_P_DCX_TESTFEATURE1_ALIGNMENT) - 1;
480                        uint32_t ulMemoryBits = (pSettings->stTestFeature1Settings.ulBitsPerPixel * ulWidth * ulHeight + 1) / 2 + 16*1024 + 64;
481                        ulMemorySize = ((ulMemoryBits + ulAlignMask) & (~ulAlignMask)) / 8;
482                }
483                else
484                {
485                        /* standard memory size */
486                        unsigned int uiPitch = 0;
487                        if( ulPitch == 0 )
488                        {
489                                BPXL_GetBytesPerNPixels( eFormat, ulWidth, &uiPitch );
490                                ulPitch = (uint32_t) uiPitch;
491                        }
492                        ulMemorySize = ulPitch * ulHeight;
493                }
494
495                pvPixelAddress = BMEM_AllocAligned( hMem, ulMemorySize, ucAlignBits, 0 );
496                if( pvPixelAddress == NULL )
497                {
498                        BDBG_OBJECT_DESTROY(hSurface, BSUR_Surface);
499                        BKNI_Free( (void *) hSurface );
500                        return BERR_TRACE(BERR_OUT_OF_DEVICE_MEMORY);
501                }
502                hSurface->bDriverOwned = true;
503        }
504
505        /* set private surface data */
506        hSurface->stSettings = pSettings ? *pSettings : s_SUR_DefaultSettings;
507        hSurface->hMem = hMem;
508        hSurface->pvAddress = pvPixelAddress;
509        hSurface->ulWidth = ulWidth;
510        hSurface->ulHeight = ulHeight;
511        hSurface->ulPitch = ulPitch;
512        hSurface->ulConstraintMask = ulConstraintMask;
513        hSurface->eFormat = eFormat;
514        hSurface->ulID = 0;
515
516        /* attach palette */
517        if( hPalette )
518        {
519                BERR_Code err = BSUR_Surface_SetPalette( hSurface, hPalette );
520                if( err != BERR_SUCCESS )
521                {
522                        BSUR_Surface_Destroy( hSurface );
523                        return err;
524                }
525        }
526
527        /* set return handle */
528        *phSurface = hSurface;
529
530        BDBG_LEAVE(BSUR_Surface_Create);
531        return BERR_SUCCESS;
532}
533
534/***************************************************************************/
535BERR_Code BSUR_Surface_Destroy(
536        BSUR_Surface_Handle hSurface )
537{
538        BDBG_ENTER(BSUR_Surface_Destroy);
539        BDBG_OBJECT_ASSERT(hSurface, BSUR_Surface);
540
541        /* free surface memory if required */
542        if( hSurface->bDriverOwned && hSurface->pvAddress )
543                BMEM_Free( hSurface->hMem, hSurface->pvAddress );
544
545        /* free private surface data */
546        BDBG_OBJECT_DESTROY(hSurface, BSUR_Surface);
547        BKNI_Free( (void *) hSurface );
548
549        BDBG_LEAVE(BSUR_Surface_Destroy);
550        return BERR_SUCCESS;
551}
552
553/***************************************************************************/
554BERR_Code BSUR_Surface_SetPalette(
555        BSUR_Surface_Handle hSurface,
556        BSUR_Palette_Handle hPalette )
557{
558        BDBG_ENTER(BSUR_Surface_SetPalette);
559        BDBG_OBJECT_ASSERT(hSurface, BSUR_Surface);
560        if (hPalette) {
561                BDBG_OBJECT_ASSERT(hPalette, BSUR_Palette);
562        }
563
564        /* check compatibility between surface and palette */
565        if( (!BPXL_IS_PALETTE_FORMAT(hSurface->eFormat)) || (hPalette &&
566                ((uint32_t) BPXL_NUM_PALETTE_ENTRIES(hSurface->eFormat) != hPalette->ulNumEntries)) )
567                return BERR_TRACE(BERR_INVALID_PARAMETER);
568
569        /* attach palette to surface */
570        hSurface->hPalette = hPalette;
571
572        BDBG_LEAVE(BSUR_Surface_SetPalette);
573        return BERR_SUCCESS;
574}
575
576/***************************************************************************/
577BERR_Code BSUR_Surface_GetDimensions(
578        BSUR_Surface_Handle hSurface,
579        uint32_t *pulWidth,
580        uint32_t *pulHeight )
581{
582        BDBG_ENTER(BSUR_Surface_GetDimensions);
583        BDBG_OBJECT_ASSERT(hSurface, BSUR_Surface);
584        BDBG_ASSERT( pulWidth );
585        BDBG_ASSERT( pulHeight );
586
587        /* set return values */
588        *pulWidth = hSurface->ulWidth;
589        *pulHeight = hSurface->ulHeight;
590
591        BDBG_LEAVE(BSUR_Surface_GetDimensions);
592        return BERR_SUCCESS;
593}
594
595/***************************************************************************/
596BERR_Code BSUR_Surface_GetPalette(
597        BSUR_Surface_Handle hSurface,
598        BSUR_Palette_Handle *phPalette )
599{
600        BDBG_ENTER(BSUR_Surface_GetPalette);
601        BDBG_OBJECT_ASSERT(hSurface, BSUR_Surface);
602        BDBG_ASSERT( phPalette );
603
604        /* set return value */
605        *phPalette = hSurface->hPalette;
606
607        if( hSurface->hPalette )
608        {
609                BDBG_OBJECT_ASSERT(*phPalette, BSUR_Palette);
610        }
611
612        BDBG_LEAVE(BSUR_Surface_GetPalette);
613        return BERR_SUCCESS;
614}
615
616/***************************************************************************/
617BERR_Code BSUR_Surface_GetConstraintMask(
618        BSUR_Surface_Handle hSurface,
619        uint32_t *pulConstraintMask )
620{
621        BDBG_ENTER(BSUR_Surface_GetConstraintMask);
622        BDBG_OBJECT_ASSERT(hSurface, BSUR_Surface);
623        BDBG_ASSERT( pulConstraintMask );
624
625        /* set return value */
626        *pulConstraintMask = hSurface->ulConstraintMask;
627
628        BDBG_LEAVE(BSUR_Surface_GetConstraintMask);
629        return BERR_SUCCESS;
630}
631
632/***************************************************************************/
633BERR_Code BSUR_Surface_GetAddress(
634        BSUR_Surface_Handle hSurface,
635        void **ppvPixelAddress,
636        uint32_t *pulPitch )
637{
638        BDBG_ENTER(BSUR_Surface_GetAddress);
639        BDBG_OBJECT_ASSERT(hSurface, BSUR_Surface);
640        BDBG_ASSERT( ppvPixelAddress );
641        BDBG_ASSERT( pulPitch );
642
643        /* set return values */
644        *ppvPixelAddress = hSurface->pvAddress;
645        *pulPitch = hSurface->ulPitch;
646
647        BDBG_LEAVE(BSUR_Surface_GetAddress);
648        return BERR_SUCCESS;
649}
650
651/***************************************************************************/
652BERR_Code BSUR_Surface_GetOffset(
653        BSUR_Surface_Handle hSurface,
654        uint32_t *pulOffset )
655{
656        BERR_Code err;
657
658        BDBG_ENTER(BSUR_Surface_GetOffset);
659        BDBG_OBJECT_ASSERT(hSurface, BSUR_Surface);
660        BDBG_ASSERT( pulOffset );
661
662        /* get offset */
663        if( hSurface->pvAddress )
664        {
665                err = BMEM_ConvertAddressToOffset( hSurface->hMem, hSurface->pvAddress, pulOffset );
666                if( err != BERR_SUCCESS )
667                        return BERR_TRACE(err);
668        }
669        else
670        {
671                *pulOffset = 0;
672        }
673
674        BDBG_LEAVE(BSUR_Surface_GetOffset);
675        return BERR_SUCCESS;
676}
677
678/***************************************************************************/
679BERR_Code BSUR_Surface_GetFormat(
680        BSUR_Surface_Handle hSurface,
681        BPXL_Format *peFormat )
682{
683        BDBG_ENTER(BSUR_Surface_GetFormat);
684        BDBG_OBJECT_ASSERT(hSurface, BSUR_Surface);
685        BDBG_ASSERT( peFormat );
686
687        /* set return value */
688        *peFormat = hSurface->eFormat;
689
690        BDBG_LEAVE(BSUR_Surface_GetFormat);
691        return BERR_SUCCESS;
692}
693
694/***************************************************************************/
695BERR_Code BSUR_Surface_GetPacketBlitInfo(
696        BSUR_Surface_Handle hSurface,
697        BPXL_Format *peFormat,
698        uint32_t *pulOffset,
699        uint32_t *pulPitch,
700        uint32_t *pulWidth,
701        uint32_t *pulHeight )
702{
703        BERR_Code err;
704        BDBG_ENTER(BSUR_Surface_GetPacketBlitInfo);
705        BDBG_OBJECT_ASSERT(hSurface, BSUR_Surface);
706
707        /* set return values */
708        if( pulOffset )
709        {
710                err = BMEM_ConvertAddressToOffset( hSurface->hMem, hSurface->pvAddress, pulOffset );
711                if( err != BERR_SUCCESS )
712                        return BERR_TRACE(err);
713        }
714
715        if( peFormat )
716                *peFormat = hSurface->eFormat;
717
718        if( pulPitch )
719                *pulPitch = hSurface->ulPitch;
720
721        if( pulWidth )
722                *pulWidth = hSurface->ulWidth;
723
724        if( pulHeight )
725                *pulHeight = hSurface->ulHeight;
726
727        BDBG_LEAVE(BSUR_Surface_GetPacketBlitInfo);
728        return BERR_SUCCESS;
729}
730
731/***************************************************************************/
732BERR_Code BSUR_Surface_GetID(
733        BSUR_Surface_Handle hSurface,
734        uint32_t *pulID )
735{
736        BDBG_ENTER(BSUR_Surface_GetID);
737        BDBG_OBJECT_ASSERT(hSurface, BSUR_Surface);
738        BDBG_ASSERT( pulID );
739
740        /* set return value */
741        *pulID = hSurface->ulID;
742
743        BDBG_LEAVE(BSUR_Surface_GetID);
744        return BERR_SUCCESS;
745}
746
747/***************************************************************************/
748BERR_Code BSUR_Surface_SetID(
749        BSUR_Surface_Handle hSurface,
750        uint32_t ulID )
751{
752        BDBG_ENTER(BSUR_Surface_SetID);
753        BDBG_OBJECT_ASSERT(hSurface, BSUR_Surface);
754
755        /* return error if ID already set */
756        if( hSurface->ulID )
757                return BERR_TRACE(BERR_INVALID_PARAMETER);
758
759        hSurface->ulID = ulID;
760
761        BDBG_LEAVE(BSUR_Surface_SetID);
762        return BERR_SUCCESS;
763}
764
765/***************************************************************************/
766BERR_Code BSUR_Surface_GetTestFeature1(
767        BSUR_Surface_Handle hSurface,
768        BSUR_TestFeature1_Settings *pTestFeature1Settings )
769{
770        BDBG_ENTER(BSUR_Surface_GetTestFeature1);
771        BDBG_OBJECT_ASSERT(hSurface, BSUR_Surface);
772        BDBG_ASSERT( pTestFeature1Settings );
773
774        /* set return value */
775        *pTestFeature1Settings = hSurface->stSettings.stTestFeature1Settings;
776
777        BDBG_LEAVE(BSUR_Surface_GetTestFeature1);
778        return BERR_SUCCESS;
779}
780
781/* End of File */
Note: See TracBrowser for help on using the repository browser.