source: svn/trunk/newcon3bcm2_21bu/magnum/portinginterface/vdc/7552/bvdc_window.c

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

first commit

  • Property svn:executable set to *
File size: 175.4 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: bvdc_window.c $
11* $brcm_Revision: Hydra_Software_Devel/321 $
12* $brcm_Date: 3/8/12 11:52a $
13 *
14 * Module Description:
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /magnum/portinginterface/vdc/7038/bvdc_window.c $
19 *
20 * Hydra_Software_Devel/321   3/8/12 11:52a yuxiaz
21 * SW7425-2546: Fixed warning msg.
22 *
23 * Hydra_Software_Devel/320   3/2/12 2:24p yuxiaz
24 * SW7425-2526: Added runtime query capabilities for compositor, window
25 * and display.
26 *
27 * Hydra_Software_Devel/319   12/2/11 9:34a yuxiaz
28 * SW7425-968, SW7344-95: Fixed compile warning and coverity errors.
29 *
30 * Hydra_Software_Devel/318   12/1/11 4:34p yuxiaz
31 * SW7425-968, SW7344-95: Merged into mainline.: added independent source
32 * clipping of right window in 3D mode.
33 *
34 * Hydra_Software_Devel/317   11/30/11 5:36p yuxiaz
35 * SW7425-1182: Set default 8bit 422 format based on LE or BE.
36 *
37 * Hydra_Software_Devel/316   11/23/11 4:24p tdo
38 * SW7435-9: Add support for CMP4-5, GFD4-5, MFD3, VFD5
39 *
40 * Hydra_Software_Devel/315   10/27/11 4:29p syang
41 * SW7425-1429: move per vsync call back from window to display
42 *
43 * Hydra_Software_Devel/314   10/24/11 4:29p syang
44 * SW7425-1429: check in after debug
45 *
46 * Hydra_Software_Devel/313   10/19/11 3:30p yuxiaz
47 * SW7425-1182: Merge into mainline: Add support for more pixel formats
48 * for surfaces accessed by CAP/MFD
49 *
50 * Hydra_Software_Devel/SW7425-1182/1   10/18/11 3:18p yuxiaz
51 * SW7425-1182: Clean up packing_type settings.
52 *
53 * Hydra_Software_Devel/312   9/8/11 10:21a syang
54 * SW7425-1265: honor back to back new setting
55 *
56 * Hydra_Software_Devel/311   8/31/11 5:39p pntruong
57 * SW7425-973:  Implement bandwidth restriction for madr.
58 *
59 * Hydra_Software_Devel/310   8/26/11 5:39p syang
60 * SW7425-1170: merge from branch SW7572-1170
61 *
62 * Hydra_Software_Devel/SW7425-1170/2   8/26/11 4:22p syang
63 * SW7425-1170: refactor pixel aspect ratio related code
64 *
65 * Hydra_Software_Devel/SW7425-1170/1   8/24/11 6:56p vanessah
66 * SW7425-1170: ASP code clean
67 *
68 * Hydra_Software_Devel/309   8/25/11 11:03a pntruong
69 * SW7425-1190, SW7425-630: Improved documentation and renamed parameter
70 * to better fit functionality.
71 *
72 * Hydra_Software_Devel/308   8/23/11 12:06p pntruong
73 * SW7425-630: Corrected the get BVDC_Window_GetDstRightRect.
74 *
75 * Hydra_Software_Devel/307   8/5/11 8:25p albertl
76 * SW7425-745: Added blanking to compositor color for all outputs and all
77 * colorspaces.
78 *
79 * Hydra_Software_Devel/306   7/22/11 11:31a vanessah
80 * SW7425-923: remove ANR restriction
81 *
82 * Hydra_Software_Devel/305   6/2/11 11:24a vanessah
83 * SW7425-630: Further fix API and setDisplaySize CurInfo NewInfo
84 * confusion.
85 *
86 * Hydra_Software_Devel/304   1/4/11 4:08p yuxiaz
87 * SW7422-174: Refactor DCX macros.
88 *
89 * Hydra_Software_Devel/303   12/23/10 5:13p tdo
90 * SW7422-148: Refactor MCVP to address chips w/wo MCTF
91 *
92 * Hydra_Software_Devel/302   12/7/10 2:42p tdo
93 * SW7422-42:  Add BVDC_Display_GetOrientation function
94 *
95 * Hydra_Software_Devel/301   11/11/10 12:44p tdo
96 * SW7422-13: Only turn on ANR when mode is set to enable
97 *
98 * Hydra_Software_Devel/300   11/10/10 4:37p albertl
99 * SW7550-610: Extended BVDC_Window_SetCoefficientIndex to work for
100 * graphics windows.
101 *
102 * Hydra_Software_Devel/299   10/29/10 3:02p tdo
103 * SW7422-40: Update GetBuffer() capability in VDC with 3D case
104 *
105 * Hydra_Software_Devel/298   10/28/10 6:15p tdo
106 * SW7422-42:  Update compositor 3D programming.
107 *
108 * Hydra_Software_Devel/297   10/20/10 4:11p yuxiaz
109 * SW7420-1190: Put back generic VDC drian buffer for mosaic mode. Only
110 * allocate drain buffer in window if it does not use main VDC heap.
111 *
112 * Hydra_Software_Devel/296   10/19/10 4:07p yuxiaz
113 * SW7420-1190: Make mosaic scratch buffer to be per window base.
114 *
115 * Hydra_Software_Devel/295   10/18/10 11:00a yuxiaz
116 * SW7422-39: Added BAVC_SourceId_eMpeg2 support in VDC.
117 *
118 * Hydra_Software_Devel/294   10/15/10 2:44p pntruong
119 * SW7422-52: Fixed bug that not allow mad to be turned off.
120 *
121 * Hydra_Software_Devel/293   10/11/10 12:51p jessem
122 * SW7420-173: Added support for VFD as source feature.
123 *
124* Hydra_Software_Devel/292   9/28/10 10:56p tdo
125* SW7425-33: VDC: Add the 4th Compositor Support for 7422/7425
126*
127* Hydra_Software_Devel/291   9/3/10 4:04p vanessah
128* SW7420-52:  autotest_vbi, vdc_test error
129*
130* Hydra_Software_Devel/290   9/3/10 2:21p vanessah
131* SW7422-52:  MAD + MCVP on the same chip, coverity and check error
132*
133* Hydra_Software_Devel/287   8/26/10 8:08p albertl
134* SW7405-4556, SW7405-4515: Changed RGB attenuation to use inverse of
135* user matrix C.
136*
137* Hydra_Software_Devel/286   8/26/10 4:27p vanessah
138* SW7420-965:  Game mode enum consistency
139*
140* Hydra_Software_Devel/285   8/26/10 2:37p vanessah
141* SW7125-556: SW7420-965:  Support for MAD 4 fields 1 delay and MCVP game
142* mode
143*
144* Hydra_Software_Devel/SW7420-965/1   8/20/10 1:29p vanessah
145* SW7420-965:  MCVP game mode support
146*
147* Hydra_Software_Devel/284   8/2/10 5:02p tdo
148* SW3548-2817, SW3548-2707: Add more error messages
149*
150* Hydra_Software_Devel/283   7/27/10 5:21p tdo
151* SW3548-2817, SW3548-2707: More bug fixes
152*
153* Hydra_Software_Devel/282   7/16/10 11:12a tdo
154* SW3548-2817, SW3548-2707: More bug fixes
155*
156* Hydra_Software_Devel/281   7/13/10 1:43p tdo
157* SW3548-2817, SW3548-2707: take into account bInterpolateTables flag
158* when checking for user errors
159*
160* Hydra_Software_Devel/280   7/1/10 2:16p tdo
161* SW3548-2817, SW3548-2707: more fine tuning
162*
163* Hydra_Software_Devel/279   7/1/10 7:56a tdo
164* SW3548-2817, SW3548-2707: Fix coverity error
165*
166* Hydra_Software_Devel/278   6/30/10 9:57p tdo
167* SW3548-2817, SW3548-2707: Add validation code for invalid data from
168* user tables
169*
170* Hydra_Software_Devel/277   6/18/10 4:24p rpan
171* SW7400-2763: New BVN resource management.
172*
173* Hydra_Software_Devel/276   6/17/10 5:37p hongtaoz
174* SW3548-2912: added support for pseudo-1080i input for 3DTV; allow API
175* to disable SCL vertical phase shift;
176*
177 * Hydra_Software_Devel/275   5/7/10 7:21p albertl
178 * SW7125-364: Changed dirty bits to use union structure to avoid type-pun
179 * warnings
180 *
181 * Hydra_Software_Devel/274   4/19/10 10:24p tdo
182 * SW3548-2814: Improvements to VDC ulBlackMagic. Move
183 * BDBG_OBJECT_ID_DECLARE private header files instead of .c.
184 *
185 * Hydra_Software_Devel/273   4/7/10 11:38a tdo
186 * SW3548-2814: Improvements to VDC ulBlackMagic.  Rename TLA
187 *
188 * Hydra_Software_Devel/272   4/5/10 4:18p tdo
189 * SW3548-2814: Improvements to VDC ulBlackMagic
190 *
191 * Hydra_Software_Devel/271   3/25/10 4:09p pntruong
192 * SW3548-2858: Need looks at all changed fields.
193 *
194 * Hydra_Software_Devel/270   2/25/10 4:09p yuxiaz
195 * SW7405-1601: VDC should expose adjusted scale-out rects after aspect
196 * ratio cut-out
197 *
198 * Hydra_Software_Devel/269   2/11/10 11:00a pntruong
199 * SW7405-3829: Moved shrinkwidth to mad settings.
200 *
201 * Hydra_Software_Devel/268   2/1/10 6:43p hongtaoz
202 * SW3548-2678, SW3548-2680, SW3548-2681: added HDMI1.4 3D formats support
203 * for 3548; added multi-buffer low delay mode support for 1to2 and 2to5
204 * rate gap cases; reduced capture buffer allocation for interlaced
205 * pulldown case;
206 *
207 * Hydra_Software_Devel/BCM3D/1   12/17/09 6:09p hongtaoz
208 * SW3548-2678: added game mode delay support for 1to2 and 2to5 src/disp
209 * rate ratioes;
210 *
211 * Hydra_Software_Devel/267   1/28/10 11:11a syang
212 * SW7405-3829: add option for app to shrink src width to use deinterlace
213 *
214 * Hydra_Software_Devel/266   1/21/10 9:27a pntruong
215 * SW3548-2676: Allowed support of 10-bits in pip path if applicable.
216 *
217 * Hydra_Software_Devel/265   12/23/09 2:03p tdo
218 * SW7408-26: Add new TNT support
219 *
220 * Hydra_Software_Devel/264   12/22/09 5:15p tdo
221 * SW7401-3828: Add AFD support
222 *
223 * Hydra_Software_Devel/263   12/17/09 2:15p yuxiaz
224 * SW3548-2676: Include bvdc_feeder_priv.h
225 *
226 * Hydra_Software_Devel/262   12/17/09 2:02p yuxiaz
227 * SW3548-2676: Only returns warning for unsupported pixel formats on old
228 * chipset.
229 *
230 * Hydra_Software_Devel/261   12/2/09 3:05p yuxiaz
231 * SW7405-3120: Added support for overlapping mosaic videos with z-
232 * ordering
233 *
234 * Hydra_Software_Devel/260   11/16/09 5:04p yuxiaz
235 * SW7405-3406: Clean up bMosaicMode and  bMosaicClearOutside.
236 *
237 * Hydra_Software_Devel/259   11/10/09 4:32p tdo
238 * SW7400-2574: Adjust TNT based on input and output format
239 *
240 * Hydra_Software_Devel/258   10/26/09 4:44p pntruong
241 * SW3548-1649, SW7420-22: Used new scl-cap bias function, and corrected
242 * default for force capture to match rts doc.
243 *
244 * Hydra_Software_Devel/257   8/28/09 1:25p yuxiaz
245 * SW3556-672: BVDC_Window_GetDeinterlaceDefaultConfiguration should
246 * Return Dynamic Defaults.
247 *
248 * Hydra_Software_Devel/256   8/7/09 12:08p yuxiaz
249 * PR56325: Add new API to get window sync lock status.
250 *
251 * Hydra_Software_Devel/255   7/30/09 10:36a pntruong
252 * PR57216: Added support for scaler split screen demo modes.
253 *
254 * Hydra_Software_Devel/254   7/15/09 5:20p pntruong
255 * PR55237: Added options to avoid black flashes on dst and/or src change.
256 *
257 * Hydra_Software_Devel/253   6/19/09 5:57p darnstein
258 * PR55225: add support for 7342 chipset.
259 *
260 * Hydra_Software_Devel/252   6/15/09 5:17p pntruong
261 * PR56026: Don't restrict MAD to tie to CMP_0 only.
262 *
263 * Hydra_Software_Devel/251   6/11/09 4:01p darnstein
264 * PR55878: fill in some details for 7340 chipset.
265 *
266 * Hydra_Software_Devel/250   6/9/09 11:50a syang
267 * PR54181: change lbox enabling WRN to MSG
268 *
269 * Hydra_Software_Devel/249   5/14/09 3:27p tdo
270 * PR38710: Only apply blue stretch property to chipsets that support it
271 *
272 * Hydra_Software_Devel/248   4/28/09 1:42p rpan
273 * PR47621: Minor user capture buffer implementation clean-up.
274 *
275 * Hydra_Software_Devel/247   4/24/09 6:40p tdo
276 * PR54181: Take into account user clipping parameters in source scanout
277 * rect calculation.
278 *
279 * Hydra_Software_Devel/246   4/7/09 6:51p tdo
280 * PR53553: Only allow ANR setting to windows from compositor 0
281 *
282 * Hydra_Software_Devel/245   4/3/09 4:35p yuxiaz
283 * PR53460: Optimal 444/422 conversion settings
284 *
285 * Hydra_Software_Devel/244   3/30/09 2:22p hongtaoz
286 * PR53037, PR53038: Implement the VEC Locking/Alignments For Memory
287 * Reduction; Implement Double-Capture-Buffer Algorithm Under VEC Locking
288 * Scheme
289 *
290 * Hydra_Software_Devel/243   3/26/09 5:58p tdo
291 * PR53553: Only allow ANR settings on main window
292 *
293 * Hydra_Software_Devel/242   3/24/09 3:58p tdo
294 * PR53553: Set ANR dirty bit when SNR value adjusted
295 *
296 * Hydra_Software_Devel/241   3/19/09 11:36p pntruong
297 * PR53429: Corrected the anr/mad/hscl vnet connection.  Removed ununsed
298 * bAnrMadCombo flags.
299 *
300 * Hydra_Software_Devel/240   3/16/09 10:52p tdo
301 * PR45785, PR45789: Merge from MCVP branch
302 *
303 * Hydra_Software_Devel/7420_mcvp/5   3/4/09 5:24p tdo
304 * PR45785, PR45789: merge from main branch on 3/04/09
305 *
306 * Hydra_Software_Devel/239   3/4/09 4:10p tdo
307 * PR51106: Support table base dynamic contrast algorithm.  Change
308 * precision of level threshold for histogram data.
309 *
310 * Hydra_Software_Devel/7420_mcvp/4   2/26/09 11:18p tdo
311 * PR 45785, PR 45789: merge from main branch on 2/26/09
312 *
313 * Hydra_Software_Devel/238   2/26/09 6:12p yuxiaz
314 * PR52287: 422-444 and 444-422 converters should use decimate/duplicate.
315 *
316 * Hydra_Software_Devel/7420_mcvp/3   2/11/09 11:31a tdo
317 * PR 45785, PR 45789: merge from main branch on 2/11/09
318 *
319 * Hydra_Software_Devel/237   2/11/09 11:04a tdo
320 * PR50391: Add smoothscaling for 7420
321 *
322 * Hydra_Software_Devel/7420_mcvp/2   2/5/09 10:53a syang
323 * PR 45785, PR 45789: merge from main branch on 2/5/09
324 *
325 * Hydra_Software_Devel/236   2/3/09 7:15p tdo
326 * PR51627: add VDC 7336 PI support
327 *
328 * Hydra_Software_Devel/7420_mcvp/1   1/23/09 11:32p syang
329 * PR 45785, PR 45789: add PI support for new the new module  MCVP
330 * (MCTF+MCDI)
331 *
332 * Hydra_Software_Devel/235   1/21/09 8:31p pntruong
333 * PR51419: Corrected the pixel validation for anr.
334 *
335 * Hydra_Software_Devel/234   1/16/09 6:28p hongtaoz
336 * PR51079: added new deinterlacer custom chroma settings;
337 *
338 * Hydra_Software_Devel/233   1/6/09 11:24p pntruong
339 * PR49391, PR49398: Don't zero the madsettings's pinters.  It is used to
340 * indicate interested default settings.
341 *
342 * Hydra_Software_Devel/232   1/5/09 2:06p rpan
343 * PR50411: Removed the unnecessary
344 * BVDC_Window_SetBandwidthEquationParams() delta value check.
345 *
346 * Hydra_Software_Devel/231   12/10/08 2:00p albertl
347 * PR45808: Updated 7420 CSC support and reworked non-linear window and
348 * CMP CSC versioning.
349 *
350 * Hydra_Software_Devel/230   12/2/08 1:46p yuxiaz
351 * PR49377: Coverity Defect ID:13248 REVERSE_INULL
352 *
353 * Hydra_Software_Devel/229   12/1/08 7:51p pntruong
354 * PR49391, PR49398: Initialized get storage to avoid unitialized usage.
355 *
356 * Hydra_Software_Devel/228   11/19/08 6:14p tdo
357 * PR49461: Add validation checking for support window in functions to set
358 * sharpness
359 *
360 * Hydra_Software_Devel/227   11/12/08 3:14p tdo
361 * PR48642: Provide clipping rect for histo luma region
362 *
363 * Hydra_Software_Devel/226   11/10/08 8:22p pntruong
364 * PR41898: Need to trigger change for new pixel format.
365 *
366 * Hydra_Software_Devel/225   11/10/08 5:01p syang
367 * PR 41898: remove un-needed bools from win-context and dirty bits
368 *
369 * Hydra_Software_Devel/224   11/5/08 1:37p yuxiaz
370 * PR48618: BVDC_Window_GetBuffer can crash if no picture present
371 *
372 * Hydra_Software_Devel/223   11/4/08 7:10p pntruong
373 * PR48029: Added control for gain/horz/core weight factor for dejagging.
374 * Enforced dejagging on only if passed threshold.
375 *
376 * Hydra_Software_Devel/222   10/28/08 9:15p pntruong
377 * PR48028, PR48029: Allow controlling of scaler's dejagging and
378 * deringing.
379 *
380 * Hydra_Software_Devel/221   10/24/08 2:45a albertl
381 * PR48023:  Added BVDC_Display_SetDvoAttenuationRGB and
382 * BVDC_Display_GetDvoAttenuationRGB, enabling CSC adjustment on DVO
383 * path.  Further cleaned up CSC matrix multiplication code.
384 *
385 * Hydra_Software_Devel/220   10/23/08 5:52p albertl
386 * PR47318, PR47814: Fixed overflow when calculating RGB attenuation
387 * offsets.  Rewrote portions of RGB attenuation code and fixed various
388 * offset related issues.
389 *
390 * Hydra_Software_Devel/219   10/18/08 12:00p jessem
391 * PR 46489: Removed assert in BVDC_Windwo_SetSharpnessConfig.
392 *
393 * Hydra_Software_Devel/218   10/7/08 9:54a jessem
394 * PR 47304, PR 46489: Added TNT interpolation table support and private
395 * functions.
396 *
397 * Hydra_Software_Devel/217   10/3/08 11:01a yuxiaz
398 * PR46305, PR46307, PR46309: Use new TestFeature1 function from BSUR.
399 * Change BVDC_P_SUPPORT_VIDEO_TestFeature1 to
400 * BVDC_P_SUPPORT_VIDEO_TESTFEATURE1.
401 *
402 * Hydra_Software_Devel/216   10/3/08 9:25a yuxiaz
403 * PR46305, PR46307, PR46309: More Video TestFeature1 support.
404 *
405 * Hydra_Software_Devel/215   10/2/08 10:11a pntruong
406 * PR47303, PR46309: Fixed warnings.
407 *
408 * Hydra_Software_Devel/214   10/1/08 8:33p pntruong
409 * PR47303, PR46309: Reused the TestFeature1 type in surface.
410 *
411 * Hydra_Software_Devel/213   10/1/08 5:05p yuxiaz
412 * PR47303, PR46309: Add video TestFeature1 support for GFD on 3548 B0.
413 *
414 * Hydra_Software_Devel/212   9/30/08 12:35p jessem
415 * PR 46489: Re-added TN2T support using tighter compiler directive to
416 * compile only when BVDC_P_SUPPORT_TNT_VER >= 5.
417 *
418 * Hydra_Software_Devel/210   9/29/08 4:38p jessem
419 * PR 46489: Added TN2T support.
420 *
421 * Hydra_Software_Devel/209   9/26/08 3:25p yuxiaz
422 * PR46305, PR46307: More video TestFeature1 support for 3548 B0.
423 *
424 * Hydra_Software_Devel/208   9/24/08 6:19p pntruong
425 * PR47113, PR45308: Allow flexibility in selecting builtins and user
426 * defined filter coefficients.
427 *
428 * Hydra_Software_Devel/207   9/22/08 4:53p yuxiaz
429 * PR46305, PR46307, PR46309: Added video TestFeature1 support for 3548 B0.
430 *
431 * Hydra_Software_Devel/206   9/18/08 3:06p pntruong
432 * PR46477: B0: Remove workaround dealing with VDEC/BVB hookup.
433 *
434 * Hydra_Software_Devel/205   8/22/08 11:50a rpan
435 * PR45979: Assert if the two VBI passthru APIs being called.
436 *
437 * Hydra_Software_Devel/204   8/22/08 10:29a rpan
438 * PR45979: Remove VBI passthru support.
439 *
440 * Hydra_Software_Devel/203   8/21/08 10:07a rpan
441 * PR45620: Changing pixel format should not force reconfig vnet.
442 *
443 * Hydra_Software_Devel/202   7/30/08 11:36a tdo
444 * PR45181: Implement New Dynamic Contrast Algorithm
445 *
446 * Hydra_Software_Devel/201   7/11/08 4:47p rpan
447 * PR43614: Bandwidth equation API change.
448 *
449 * Hydra_Software_Devel/200   6/18/08 3:07p syang
450 * PR35549: 1). src-pending when new win is created; 2). don't do
451 * BufferHeap_AllocateBuffers as bReConfigSrc
452 *
453 * Hydra_Software_Devel/199   6/17/08 10:59a rpan
454 * PR43614: Moved bandwidth equation parameters to BVDC_P_Window_info
455 * structure. Changed factor to 1000.
456 *
457 * Hydra_Software_Devel/198   6/16/08 4:59p rpan
458 * PR43614: Added API for user to set/get bandwidth equation parameters.
459 *
460 * Hydra_Software_Devel/197   5/30/08 1:38p tdo
461 * PR38362, PR38678, PR38841, PR38842: More fine tuning of the BVN HW
462 * limitation implementation.
463 *
464 * Hydra_Software_Devel/196   5/21/08 1:55p albertl
465 * PR39163:  Updated CMP csc tables to use 10 bit offset values.
466 * Corrected to use proper csc tables in conversions involving ntsc, pal,
467 * and smpte 240M.  Moved colorclip from window to compositor and changed
468 * BVDC_Window_Set/GetColorClip to BVDC_Compositor_Set/GetColorClip.
469 *
470 * Hydra_Software_Devel/195   5/19/08 5:03p yuxiaz
471 * PR40122: Use new 10-bit 422 40-bit packed format for ANR on 3548.
472 *
473 * Hydra_Software_Devel/194   5/19/08 2:25p yuxiaz
474 * PR40122: Use new 10-bit 422 packed pixel format for MAD on 3548.
475 *
476 * Hydra_Software_Devel/193   5/15/08 3:40p yuxiaz
477 * PR42712: Coverity Defect ID:9043 OVERRUN_STATIC bvdc_window.c
478 *
479 * Hydra_Software_Devel/192   5/8/08 6:09p tdo
480 * PR39331: Add LAB table control and demo mode.  Also, force LAB table to
481 * be loaded in one vsync with the enable to avoid using uninitialized
482 * LAB table.
483 *
484 * Hydra_Software_Devel/191   5/2/08 9:14p albertl
485 * PR42395:  Fixed fixed point MTH overflow in
486 * BVDC_P_Csc_ColorTempToAttenuationRGB.
487 *
488 * Hydra_Software_Devel/190   5/2/08 10:53a jessem
489 * PR 39335: Added CM3D demo.
490 *
491 * Hydra_Software_Devel/189   4/22/08 7:40p albertl
492 * PR39163:  Fixed user matrix set functions to apply to stNewInfo.
493 *
494 * Hydra_Software_Devel/188   4/11/08 2:12p tdo
495 * PR39333: Properly handle Hist in vnet
496 *
497 * Hydra_Software_Devel/187   4/8/08 6:11p albertl
498 * PR39163:  Updated BVDC_Window_SetColorClip and BVDC_Window_GetColorClip
499 * interface to use settings structure.
500 *
501 * Hydra_Software_Devel/186   4/3/08 2:07p tdo
502 * PR39333: Add error checking for invalid bin number
503 *
504 * Hydra_Software_Devel/185   3/27/08 7:41p albertl
505 * PR39163:  Implemented non-linear get matrix functions.
506 *
507 * Hydra_Software_Devel/184   3/27/08 5:08p albertl
508 * PR39163:  Implemented non-linear xvYCC csc support for 3548.
509 *
510 * Hydra_Software_Devel/183   3/21/08 5:09p tdo
511 * PR39333: More Hist implementation for 3548
512 *
513 * Hydra_Software_Devel/182   3/21/08 12:21p hongtaoz
514 * PR39154, PR39202: updated MAD revision ID and validation for 3548;
515 *
516 * Hydra_Software_Devel/181   3/20/08 9:43a pntruong
517 * PR39154, PR39202, PR39203: Fixed merged errors.
518 *
519 * Hydra_Software_Devel/180   3/19/08 7:47p hongtaoz
520 * PR39154, PR39202, PR39203: combined ANR and MAD in memory saving mode
521 * on 3548; implemented MAD specific change; updated SCL precision for
522 * 3548;
523 *
524 * Hydra_Software_Devel/179   3/19/08 5:43p tdo
525 * PR39333: Implement HIST core
526 *
527 * Hydra_Software_Devel/178   3/13/08 10:26a yuxiaz
528 * PR40517: Fixed KLOCWORK errors.
529 *
530 * Hydra_Software_Devel/177   3/4/08 2:26p yuxiaz
531 * PR40187: Fixed the assertion in BVDC_P_Window_Writer_isr when
532 * BVDC_Window_SetDeinterlaceConfiguration is called with bDeinterlace is
533 * false and a null pointer for pMadSettings.
534 *
535 * Hydra_Software_Devel/176   2/28/08 10:12p pntruong
536 * PR39154: Resolved clearcase merged.
537 *
538 * Hydra_Software_Devel/175   2/26/08 4:52p jessem
539 * PR 34590, PR 39456: Removed ENDIAN treatment of pixel format of
540 * picture in BVDC_Window_GetBuffer.
541 *
542 * Hydra_Software_Devel/174   2/20/08 4:15p hongtaoz
543 * PR39154: added window API to toggle ANR; prepare for combo ANR/MAD
544 * feature on 3548;
545 *
546 * Hydra_Software_Devel/173   2/14/08 4:33p tdo
547 * PR39331, PR39332: Regroup PEP block to add support for 3548
548 *
549 * Hydra_Software_Devel/172   2/13/08 3:11p pntruong
550 * PR39421: Removed unused code to improve readability.
551 *
552 * Hydra_Software_Devel/171   1/24/08 5:49p tdo
553 * PR38710: Fix compiling error for chips that do not have PEP support
554 *
555 * Hydra_Software_Devel/170   1/24/08 5:27p tdo
556 * PR38710: Add blue stretch support
557 *
558 * Hydra_Software_Devel/169   1/23/08 11:13a tdo
559 * PR38710: Rename blue stretch and green stretch to blue boost and green
560 * boost to match their functionality
561 *
562 * Hydra_Software_Devel/168   1/18/08 11:20a hongtaoz
563 * PR38736: added force_spatial 3-field MAD game mode; re-grouped MAD game
564 * modes definition and added more comments;
565 *
566 * Hydra_Software_Devel/167   1/9/08 10:46a yuxiaz
567 * PR38613, PR38614: Enable force capture and smooth scaling on 7325 and
568 * 7335.
569 *
570 * Hydra_Software_Devel/166   11/28/07 2:02p tdo
571 * PR37413: Provide new Api to set offset and size of histogram window and
572 * read corresponding parameters from specific window
573 *
574 * Hydra_Software_Devel/165   11/14/07 10:56a rpan
575 * PR31084: Consider NULL pointers as valid values when getting
576 * VDEC/Deinterlace default settings.
577 *
578 * Hydra_Software_Devel/164   11/13/07 5:35p rpan
579 * PR31084: Added support for getting VDEC default settings.
580 *
581 * Hydra_Software_Devel/163   11/13/07 4:07p rpan
582 * PR31084: Added support for getting default de-interlace settings.
583 *
584 * Hydra_Software_Devel/162   10/23/07 11:18a yuxiaz
585 * PR29569, PR36290: Add FGT support on 7405.
586 *
587 * Hydra_Software_Devel/PR29569/4   10/22/07 5:16p yuxiaz
588 * PR29569: More FGT work.
589 *
590 * Hydra_Software_Devel/PR29569/3   10/22/07 3:21p yuxiaz
591 * PR29569: Merge from mainline.
592 *
593 * Hydra_Software_Devel/161   10/22/07 11:27a pntruong
594 * PR35941: Added option to allow smooth transition or bandwidth
595 * optimization.
596 *
597 * Hydra_Software_Devel/160   10/11/07 2:10p albertl
598 * PR35135:  Fixed user csc macros and added 10-bit/8-bit video data
599 * conversion.
600 *
601 * Hydra_Software_Devel/159   10/2/07 11:26a pntruong
602 * PR35136: Some cleanup of unused code.
603 *
604 * Hydra_Software_Devel/158   9/28/07 12:59p pntruong
605 * PR35135: Don't use the csc from window as it's not context safe.
606 *
607 * Hydra_Software_Devel/157   9/20/07 1:22a albertl
608 * PR35135:  Cleaned up color space matrices and changed them to use same
609 * macro system.  Added color space conversion functionality to graphics
610 * windows.
611 *
612 * Hydra_Software_Devel/156   9/4/07 5:40p jessem
613 * PR 34590: Added check for unsupported 8-bit 422 VFD/MFD pixel formats
614 * in BVDC_Window_SetPixelFormat(). If this is used, CAP will be
615 * programmed accordingly but the VFD will not work which will result in
616 * a pink/green video.
617 *
618 * Hydra_Software_Devel/155   8/30/07 10:28p pntruong
619 * PR34472: Use MASK block to improve the Contour/Quantization noise
620 * issue.
621 *
622 * Hydra_Software_Devel/154   8/30/07 3:14p pntruong
623 * PR34348: MAD optimizing Low Angle Settings for reduce gray noise.
624 *
625 * Hydra_Software_Devel/PR34348/1   8/29/07 4:07p xhuang
626 * PR34348:add low angle customer settings
627 *
628 * Hydra_Software_Devel/153   8/7/07 12:44p tdo
629 * PR33792: Addtional Parameter for MAD chroma settings
630 *
631 * Hydra_Software_Devel/152   7/30/07 6:50p albertl
632 * PR28869:  Removed VDC dependency on BAVC_MOSAIC_MAX.  Clear rect and
633 * mosaic maximums are now dependent on definitions in bvdc_common.h.
634 *
635 * Hydra_Software_Devel/151   7/23/07 6:44p hongtaoz
636 * PR33345: added 3-field 0-delay MAD game mode;
637 *
638 * Hydra_Software_Devel/150   7/10/07 6:11p tdo
639 * PR32853: Extending the range of CMS saturation and hue gains to match
640 * BBS3.0 tool
641 *
642 * Hydra_Software_Devel/149   6/28/07 7:26p hongtaoz
643 * PR32130, PR29189: added buffer game mode delay control; fixed picture
644 * timestamp update bug when isr reorder occurs; invalid timestamp/drift
645 * delay should disappear now; lipsync delay reflects the correct game
646 * mode effect;
647 *
648 * Hydra_Software_Devel/VDC_Game_Mode/3   6/28/07 5:39p hongtaoz
649 * PR32130: added game mode clock adjustment; added restriction of fast
650 * adjustment for 1080p in 1080p out to avoid flash caused by bandwidth
651 * overshoot when accelerating;
652 *
653 * Hydra_Software_Devel/VDC_Game_Mode/2   6/26/07 2:28p hongtaoz
654 * PR32130: added game mode buffer delay control;
655 *
656 * Hydra_Software_Devel/VDC_Game_Mode/1   6/26/07 2:22p hongtaoz
657 * PR32130: added window game mode buffer delay control;
658 *
659 * Hydra_Software_Devel/148   6/18/07 11:39a tdo
660 * PR30613: Fix typo in CMS range chacking for hue gain
661 *
662 * Hydra_Software_Devel/147   6/12/07 11:19a tdo
663 * PR30613: Move CSC calculations into bvdc_csc_priv.c
664 *
665 * Hydra_Software_Devel/146   6/11/07 1:07p tdo
666 * PR30613: Modify dynamic contrast stretch prototype to meet customer
667 * requirement
668 *
669 * Hydra_Software_Devel/145   6/7/07 2:36p tdo
670 * PR29965: Alternating CAB and LAB table programming using RUL in every
671 * other vsync
672 *
673 * Hydra_Software_Devel/144   6/6/07 11:38a tdo
674 * PR28978: Fix range for hue gain
675 *
676 * Hydra_Software_Devel/143   5/31/07 3:26p tdo
677 * PR28978: C0: Provide API to realize CMS function
678 *
679 * Hydra_Software_Devel/142   5/18/07 4:22p albertl
680 * PR28894:  Added new 3-field low bandwidth MAD game mode for 3563 C0.
681 *
682 * Hydra_Software_Devel/141   5/17/07 3:44p pntruong
683 * PR30364: Provide API to control MAD up/down sampling.
684 *
685 * Hydra_Software_Devel/140   5/1/07 4:44p syang
686 * PR 28541: 1) changed non-linear scl api; 2). carry sub-pxl accuracy
687 * through the pipe line by SrcHStep and SrcVStep
688 *
689 * Hydra_Software_Devel/139   4/15/07 1:51a albertl
690 * PR28869:  Maximum clear rect now defined for each window and chipset.
691 *
692 * Hydra_Software_Devel/138   4/12/07 5:37p tdo
693 * PR28837: Provide API to customize LAB LUT
694 *
695 * Hydra_Software_Devel/137   4/9/07 11:26a pntruong
696 * PR28266: Provide API to customize DVO CSC.
697 *
698 * Hydra_Software_Devel/136   4/5/07 11:26p pntruong
699 * PR28395, PR28538, PR28539, PR28540: Vdec customizations, and
700 * deinterlacer customizations.
701 *
702 * Hydra_Software_Devel/135   4/5/07 6:12p tdo
703 * PR25462: add support for luma average reporting in the PEP
704 *
705 * Hydra_Software_Devel/134   4/5/07 4:57p albertl
706 * PR29194:  Added BVDC_Window_SetCoefficientIndex and input and index
707 * matching support to scaler coefficient tables.
708 *
709 * Hydra_Software_Devel/133   4/5/07 2:04p pntruong
710 * PR28538, PR28539, PR28540, PR25462: Average pixel luma and customized
711 * deinterlacer support.
712 *
713 * Hydra_Software_Devel/132   3/29/07 4:19p tdo
714 * PR 28404: Implement user set contrast stretch configuration
715 *
716 * Hydra_Software_Devel/PR28538/3   4/3/07 9:33p xhuang
717 * PR25462: Support APL setting
718 *
719 * Hydra_Software_Devel/PR28538/2   3/29/07 3:07p xhuang
720 * PR28538:modify to get correct current setting of mad
721 *
722 * Hydra_Software_Devel/PR28538/1   3/28/07 6:42p xhuang
723 * PR28538:Add new api for 3:2 pulldown, 2:2 pulldown and mad setting.
724 * Also for PR28539,PR28540
725 *
726 * Hydra_Software_Devel/131   3/28/07 6:16p tdo
727 * PR28392, PR28282: Implement get color matrix function
728 *
729 * Hydra_Software_Devel/130   3/28/07 4:10p tdo
730 * PR28403: Move user sharpness config dirty bit set out of validation
731 * code for optimization
732 *
733 * Hydra_Software_Devel/129   3/28/07 3:28p tdo
734 * PR 28403: Provide API to customize TNT for sharpness
735 *
736 * Hydra_Software_Devel/128   3/26/07 3:28p tdo
737 * PR 28401: Provide API to customize CAB LUT and enable/disable CAB
738 *
739 * Hydra_Software_Devel/127   3/25/07 2:09p yuxiaz
740 * PR25181: VDC Buffer Allocation Fragments fix: set dirty bit directly.
741 *
742 * Hydra_Software_Devel/126   3/25/07 1:45p yuxiaz
743 * PR25181: VDC Buffer Allocation Fragments fix.
744 *
745 * Hydra_Software_Devel/125   3/23/07 4:39p tdo
746 * PR 28282: Provide API to customize CMP CSC
747 *
748 * Hydra_Software_Devel/124   3/20/07 4:48p hongtaoz
749 * PR22434: added mosaic channel frame rate tracking API;
750 *
751 * Hydra_Software_Devel/123   3/13/07 8:58a maivu
752 * PR 27216: Fixed compiler warnings for Vxworks
753 *
754 * Hydra_Software_Devel/122   3/1/07 11:17p albertl
755 * PR24587:  Added support for compositor blenders that are not arraigned
756 * in order.
757 *
758 * Hydra_Software_Devel/120   2/16/07 3:44p syang
759 * PR 22569: add anr filter level;  add back even line allign plus out-of-
760 * range check
761 *
762 * Hydra_Software_Devel/119   1/16/07 1:45p yuxiaz
763 * PR27067: Use window Id in BVDC_Window_Create.
764 *
765 * Hydra_Software_Devel/118   1/15/07 3:30p yuxiaz
766 * PR27067: Use window Id in BVDC_Window_Create.
767 *
768 * Hydra_Software_Devel/117   1/10/07 4:44p yuxiaz
769 * PR 26313: Rename BVDC_SplitScreenSettings to
770 * BVDC_Window_SplitScreenSettings.
771 *
772 * Hydra_Software_Devel/116   1/10/07 4:28p tdo
773 * PR 17994, PR 26113: Add demo mode support for CMP 1 and CMP 2 for 7400
774 * B0
775 *
776 * Hydra_Software_Devel/115   1/10/07 3:32p yuxiaz
777 * PR 26313: Change DNR API to source based API: Remove
778 * BVDC_Window_SetDnrFilterLevel and BVDC_Window_GetDnrFilterLevel. Add
779 * BVDC_Source_SetDnrFilterLevel, BVDC_Source_GetDnrFilterLevel,
780 * BVDC_Source_SetSplitScreenMode and BVDC_Source_GetSplitScreenMode.
781 *
782 * Hydra_Software_Devel/114   1/5/07 4:26p syang
783 * PR 22569: almost completed coding for new vnet build/shutdown algorithm
784 * (by each sub-modules)
785 *
786 * Hydra_Software_Devel/113   1/4/07 12:03p yuxiaz
787 * PR 26890: Added VDC_Source_GetDefaultSettings,
788 * BVDC_Window_GetDefaultSettings and BVDC_Compositor_GetDefaultSettings.
789 *
790 * Hydra_Software_Devel/112   12/18/06 11:24p pntruong
791 * PR22577: Merged back to mainline.
792 *
793 * Hydra_Software_Devel/Refsw_Devel_3563/17   12/11/06 5:25p albertl
794 * PR24587:  Added 3rd GFX Feeder source.
795 *
796 * Hydra_Software_Devel/Refsw_Devel_3563/16   11/29/06 4:27p syang
797 * PR 26151: release shred resource after it is not used by HW
798 *
799 * Hydra_Software_Devel/Refsw_Devel_3563/15   11/27/06 10:33a syang
800 * PR 26151:  only release shared scl as win destroy
801 *
802 * Hydra_Software_Devel/Refsw_Devel_3563/14   11/22/06 3:53p syang
803 * PR 26151: re-write shared resource manager. update letter box, mad, dnr
804 * shared-scl acquire/release code accordingly
805 *
806 * Hydra_Software_Devel/Refsw_Devel_3563/13   11/15/06 5:09p albertl
807 * PR24587:  Added downsample source for 7440.
808 *
809 * Hydra_Software_Devel/Refsw_Devel_3563/12   11/13/06 5:05p hongtaoz
810 * PR20716: added Get function for mosaic config;
811 *
812 * Hydra_Software_Devel/Refsw_Devel_3563/11   11/13/06 3:35p hongtaoz
813 * PR20716: separate displays/compsoitors for loops;
814 *
815 * Hydra_Software_Devel/Refsw_Devel_3563/10   11/1/06 10:49a jessem
816 * PR 23748: Added game mode support.
817 *
818 * Hydra_Software_Devel/Refsw_Devel_3563/9   10/20/06 1:41p pntruong
819 * PR23521:  Removed duplicate code, and move game mode into existing
820 * deinterlace settings structures.
821 *
822 * Hydra_Software_Devel/Refsw_Devel_3563/8   10/19/06 3:53p albertl
823 * PR23521:  Added MAD game mode functionality.
824 *
825 * Hydra_Software_Devel/Refsw_Devel_3563/7   10/18/06 9:30p albertl
826 * PR23210:  Added color temp and offset functionality.
827 *
828 * Hydra_Software_Devel/Refsw_Devel_3563/6   10/12/06 5:46p tdo
829 * PR 23377:  Add support for MAD 3:2 and 2:2 reverse pulldown
830 *
831 * Hydra_Software_Devel/Refsw_Devel_3563/5   9/20/06 6:21p tdo
832 * PR 23213, PR 23383: Fix error in user input validation for demo mode.
833 *
834 * Hydra_Software_Devel/Refsw_Devel_3563/4   9/20/06 3:54p tdo
835 * PR 23213, PR 23383: Using new API for demo mode
836 *
837 * Hydra_Software_Devel/Refsw_Devel_3563/3   9/20/06 12:57p pntruong
838 * PR23222, PR23225:  Defer window and source heap assignments until user
839 * create.
840 *
841 * Hydra_Software_Devel/Refsw_Devel_3563/2   9/19/06 4:36p pntruong
842 * PR23222, PR23225: VDEC - ATSC & PC input support.
843 *
844 * Hydra_Software_Devel/Refsw_Devel_3563/1   9/19/06 1:47p pntruong
845 * PR23222, PR23225: VDEC - ATSC & PC input support.
846 *
847 * Hydra_Software_Devel/111   9/13/06 4:27p syang
848 * PR 23331: add BVDC_Window_SetHorizScale; add more desc to the APIs
849 * related feeding gfx surf to mfd and cap video to gfx surf.
850 *
851 * Hydra_Software_Devel/110   9/7/06 5:12p tdo
852 * PR 17994, PR 23213, PR 23383:  Add input validation checks for demo
853 * mode controls
854 *
855 * Hydra_Software_Devel/109   9/1/06 3:40p yuxiaz
856 * PR20875 : Added more error checking in BVDC_Window_SetPixelFormat.
857 *
858 * Hydra_Software_Devel/108   8/31/06 12:29p syang
859 * PR 23977: report error when mad is called for 7118
860 *
861 * Hydra_Software_Devel/107   8/30/06 5:59p tdo
862 * PR 17994, PR 23213, PR 23383:  Implement demo mode support for the PEP.
863 *
864 * Hydra_Software_Devel/106   8/29/06 3:28p tdo
865 * PR 23212: Add new APIs for contrast stretch, color clip, auto flesh,
866 * green stretch and blue stretch.
867 *
868 * Hydra_Software_Devel/105   8/15/06 6:17p hongtaoz
869 * PR18233, PR20716: added support for mosaic mode - missing channels;
870 * assume picture list's channel id are in ascending order; single
871 * channel will not result in full-screen automatically;
872 *
873 * Hydra_Software_Devel/104   7/31/06 6:11p hongtaoz
874 * PR22499: added DCR filter setting as a part of DNR block;
875 *
876 * Hydra_Software_Devel/103   7/27/06 4:21p yuxiaz
877 * PR22412: Added BVDC_Window_SetForceCapture and
878 * BVDC_Window_GetForceCapture.
879 *
880 * Hydra_Software_Devel/102   7/18/06 1:34p syang
881 * PR 21963: ensure ulWindows copied from src new info to cur info, to
882 * avoid  win bUserAppliedChanges and src bPictureChanged being always
883 * set true with ApplyChanges (that causes extra busy with brutus replay
884 * with gfx updating frequently )
885 *
886 * Hydra_Software_Devel/101   7/17/06 5:57p pntruong
887 * PR18233: Moved MOSAIC_MAX to avc since other PIs need to access the
888 * definition.
889 *
890 * Hydra_Software_Devel/100   7/7/06 4:15p yuxiaz
891 * PR 22296, PR 22108, PR22109: Removed
892 * BVDC_Window_InstallLipSyncDelayCallback, added new generic window
893 * callback function BVDC_Window_InstallCallback for lip sync.
894 *
895 * Hydra_Software_Devel/99   7/7/06 3:47p jessem
896 * PR 21445: Removed
897 * pWindow->stNewInfo.stDirty.stBits.bUserReleaseBuffer = BVDC_P_DIRTY. This is
898 * now set in BVDC_P_Window_ReleasePicture_isr.
899 *
900 * Hydra_Software_Devel/99   7/7/06 2:43p jessem
901 * PR 21445: Removed
902 * pWindow->stNewInfo.stDirty.stBits.bUserReleaseBuffer = BVDC_P_DIRTY. This is
903 * now set in BVDC_P_Window_ReleasePicture_isr.
904 *
905 * Hydra_Software_Devel/98   6/14/06 6:52p hongtaoz
906 * PR20716, PR21804: implement modified version of mosaic mode;
907 *
908 * Hydra_Software_Devel/97   5/23/06 5:41p hongtaoz
909 * PR17514: support correct usage mode of DNR; now DNR is available for
910 * any video window and shared between mpeg sources; only one mpeg source
911 * can acquire the DNR at a time;
912 *
913 * Hydra_Software_Devel/96   5/19/06 2:29p hongtaoz
914 * PR17514: added bypass filter enum for DNR setting; disable extreme
915 * filter for 7401a0 due to PR16299; fixed range clamping for DNR
916 * settings; added DNR demo mode setting in test api;
917 *
918 * Hydra_Software_Devel/95   4/20/06 5:50p pntruong
919 * PR20750: Please update bavc.h to reflect presence of third VEC.
920 *
921 * Hydra_Software_Devel/94   4/12/06 4:24p jessem
922 * PR19972: Added big endian mapping of pixel format in
923 * BVDC_Window_GetBuffer.
924 *
925 * Hydra_Software_Devel/92   4/4/06 1:50p hongtaoz
926 * PR20403: add triple displays for 7400;
927 *
928 * Hydra_Software_Devel/91   3/29/06 5:34p jessem
929 * PR 20422: Reassigned pWindow->stCurInfo.pBufferToUser to a local
930 * variable in BVDC_Window_GetBuffer to avoid race condition.
931 *
932 * Hydra_Software_Devel/90   2/13/06 11:09a pntruong
933 * PR13275, PR19258: Back out uncessary feature.  Already available with
934 * window source clipping.
935 *
936 * Hydra_Software_Devel/89   2/8/06 10:39a yuxiaz
937 * PR13275: Added new functions VDC_Window_Set704Sample4Vdec
938 * and VDC_Window_Get704Sample4Vdec for support of 704 pixels output from
939 * the VDEC on a CCIR-656 port.
940 *
941 * Hydra_Software_Devel/88   1/27/06 1:08p jessem
942 * PR 18021: Added BVDC_Window_SetPixelFormat.
943 *
944 * Hydra_Software_Devel/87   1/27/06 10:37a pntruong
945 * PR19218: ATSC display corrupted.  Synclock source with multiple window
946 * must be capture when it's not in cmp_0 to avoid accessive bandwidth
947 * the other slip capture paths.
948 *
949 * Hydra_Software_Devel/86   1/12/06 1:34p hongtaoz
950 * PR18233: added mosaic mode support;
951 *
952 * Hydra_Software_Devel/MosaicMode_Feature_PR18233/3   1/12/06 11:35a hongtaoz
953 * PR18233: modified mosaic mode API to be more flexible;
954 *
955 * Hydra_Software_Devel/85   1/12/06 10:36a yuxiaz
956 * PR18476: Added new functions BVDC_Window_SetLumaKey and
957 * BVDC_Window_GetLumaKey for luma key support.
958 *
959 * Hydra_Software_Devel/84   11/10/05 6:04p jessem
960 * PR 17972, PR 18072: Modified BVDC_Window_GetBuffer to handle new
961 * changes in BVDC_P_Window_CapturePicture_isr().
962 *
963 * Hydra_Software_Devel/83   10/31/05 6:26p hongtaoz
964 * PR17514: add DNR support in VDC;
965 *
966 * Hydra_Software_Devel/82   10/28/05 11:45a tdo
967 * PR 17788:  Add 656 input support for 7038Cx
968 *
969 * Hydra_Software_Devel/81   9/12/05 4:33p jessem
970 * PR 12739: Fixed bug in BVDC_Window_Destroy that causes leaked resource
971 * error.
972 *
973 * Hydra_Software_Devel/80   9/12/05 4:26p jessem
974 * PR 12739: Cleaned up debug code.
975 *
976 * Hydra_Software_Devel/79   9/12/05 3:01p jessem
977 * PR 12739: Renamed
978 * BVDC_P_Window_CheckForNonReturnedUserCapturedBuffer_isr to
979 * BVDC_P_Window_CheckForUnReturnedUserCapturedBuffer_isr.
980 *
981 * Hydra_Software_Devel/78   9/12/05 2:51p jessem
982 * PR 12739: Added 3 functions to support user capture of fields and/or
983 * frames: BVDC_Window_SetUserCaptureBufferCount(),
984 * BVDC_Window_GetBuffer(), and BVDC_Window_ReturnBuffer(). Also modified
985 * Window destroy to check for unreturned user capture buffers.
986 *
987 * Hydra_Software_Devel/77   9/6/05 7:03p hongtaoz
988 * PR16812, PR15888: mute writer blocks and muxe earlier; window blocks
989 * shutdown and normal programming order are reverse; not to re-init
990 * window shared resource at create time;
991 *
992 * Hydra_Software_Devel/76   9/1/05 6:23p jasonh
993 * PR 16967: Removing XVD source
994 *
995 * Hydra_Software_Devel/75   8/22/05 5:25p hongtaoz
996 * PR12192, PR15888: make MAD sharable between the two video windows of
997 * main display; reduced unnecessary window shutdown initiation if it's
998 * already in the middle of shutdown; build both slots RULs for analog
999 * progressive source format during shutdown to workaround unexpected
1000 * trigger pattern;
1001 *
1002 * Hydra_Software_Devel/74   8/19/05 2:57p hongtaoz
1003 * PR15888: adding support for dynamic switch on/off shared scaler on
1004 * bypass window;
1005 *
1006 * Hydra_Software_Devel/73   8/18/05 1:20p pntruong
1007 * PR15757, PR16391, PR16411, PR12519, PR14791, PR15535, PR15206, PR15778:
1008 * Improved bandwidth for cropping/scaler/capture/playback.   Unified
1009 * window shutdown sequence for destroy, reconfigure mad/scaler, and/or
1010 * reconfigure result of source changes.  And miscellances fixes from
1011 * above PRs.
1012 *
1013 * Hydra_Software_Devel/XVDPhase1/XVDPhase1_merge/3   8/16/05 2:02p pntruong
1014 * PR12519: Take in additional fixes from mainline.
1015 *
1016 * Hydra_Software_Devel/XVDPhase1/XVDPhase1_merge/2   8/15/05 5:37p pntruong
1017 * PR14791: Remove unneeded function from VDC.
1018 *
1019 * Hydra_Software_Devel/XVDPhase1/XVDPhase1_merge/1   8/2/05 1:07p pntruong
1020 * PR16484: (1241) Progressive outputs give flickery picture.
1021 *
1022 * Hydra_Software_Devel/XVDPhase1/2   5/20/05 11:07a pntruong
1023 * PR 15183: Add sharpness control to the PEP and remove the old TAB
1024 * setting.
1025 *
1026 * Hydra_Software_Devel/XVDPhase1/1   5/2/05 4:55p pntruong
1027 * PR12519, PR13121, PR15048, PR15084, PR15100: Dynamically re-allocate
1028 * capture in bvn path to reduce memory consumption and bandwith.
1029 *
1030 * Hydra_Software_Devel/3   5/2/05 2:43p pntruong
1031 * Temporary turn off deinterlacer.
1032 *
1033 * Hydra_Software_Devel/2   5/2/05 12:57p pntruong
1034 * Initial support for decoding of 480i for hddvi.
1035 *
1036 * Hydra_Software_Devel/1   5/1/05 4:52p pntruong
1037 * XVDPhase1 branch off.  Temp storage so we can keep track of changes.
1038 *
1039 * Hydra_Software_Devel/69   3/18/05 6:32p pntruong
1040 * PR14494: Basic vdc up and running.  Background and passed output format
1041 * switch test.
1042 *
1043 * Hydra_Software_Devel/68   3/17/05 6:42p pntruong
1044 * PR14494: Add preliminary software support to 3560 A0.
1045 *
1046 * Hydra_Software_Devel/67   2/4/05 4:56p hongtaoz
1047 * PR13793: added compile option to use scaler_3 for bypass window;
1048 *
1049 * Hydra_Software_Devel/66   1/31/05 11:33a yuxiaz
1050 * PR13955: Enable HD_DVI on 7038C.
1051 *
1052 * Hydra_Software_Devel/65   1/28/05 9:18a pntruong
1053 * PR13321: Stress test failed (MAIN/PIP swap and format change).
1054 *
1055 * Hydra_Software_Devel/64   1/26/05 2:30p tdo
1056 * PR13526: Add VDEC support for C0
1057 *
1058 ***************************************************************************/
1059#include "bstd.h"                 /* standard types */
1060#include "bkni.h"                 /* memcpy calls */
1061#include "bvdc.h"                 /* Video display */
1062#include "bvdc_priv.h"
1063#include "bvdc_mad_priv.h"
1064#include "bvdc_window_priv.h"
1065#include "bvdc_source_priv.h"
1066#include "bvdc_compositor_priv.h"
1067#include "bvdc_gfxfeeder_priv.h"  /* for blend factor validation */
1068#include "bvdc_hist_priv.h"
1069#include "bvdc_csc_priv.h"
1070#include "bvdc_tnt_priv.h"
1071#include "bvdc_feeder_priv.h"
1072
1073BDBG_MODULE(BVDC_WIN);
1074
1075/* Window Id lookup table with compostior id, and source id.  This
1076 * only lookup window id for the first gfx or video window. */
1077typedef struct BVDC_P_Window_SelectedId
1078{
1079        bool bValid;
1080        BVDC_P_WindowId eWindowId;
1081} BVDC_P_Window_SelectedId;
1082
1083/* INDEX: by BAVC_SourceId & BVDC_P_CompositorId. */
1084static const BVDC_P_Window_SelectedId s_aaWindowIdSelectTable
1085        [BVDC_P_MAX_COMPOSITOR_COUNT /* compositor id (0,1,bypass) */]
1086        [BVDC_P_MAX_SOURCE_COUNT     /* source (mpeg, gfx, etc)    */] =
1087{
1088        /* compositor 0: could take any video source or gfx0 */
1089        {{true,  BVDC_P_WindowId_eComp0_V0},  /* Mpeg0 */
1090         {true,  BVDC_P_WindowId_eComp0_V0},  /* Mpeg1 */
1091         {true,  BVDC_P_WindowId_eComp0_V0},  /* Mpeg2 */
1092         {true,  BVDC_P_WindowId_eComp0_V0},  /* Mpeg3 */
1093         {true,  BVDC_P_WindowId_eComp0_V0},  /* Vdec0 */
1094         {true,  BVDC_P_WindowId_eComp0_V0},  /* Vdec1 */
1095         {true,  BVDC_P_WindowId_eComp0_V0},  /* 656In0 */
1096         {true,  BVDC_P_WindowId_eComp0_V0},  /* 656In1 */
1097         {true,  BVDC_P_WindowId_eComp0_G0},  /* Gfx0 */
1098         {false, BVDC_P_WindowId_eComp0_G0},  /* Gfx1 */
1099         {false, BVDC_P_WindowId_eComp0_G0},  /* Gfx2 */
1100         {false, BVDC_P_WindowId_eComp0_G0},  /* Gfx3 */
1101         {false, BVDC_P_WindowId_eComp0_G0},  /* Gfx4 */
1102         {false, BVDC_P_WindowId_eComp0_G0},  /* Gfx5 */
1103         {true,  BVDC_P_WindowId_eComp0_V0},  /* HdDvi0 */
1104         {true,  BVDC_P_WindowId_eComp0_V0},  /* HdDvi1 */
1105         {true,  BVDC_P_WindowId_eComp0_V0},  /* Ds0 */
1106         {true,  BVDC_P_WindowId_eComp0_V0},  /* Vfd0 */
1107         {true,  BVDC_P_WindowId_eComp0_V0},  /* Vfd1 */
1108         {false, BVDC_P_WindowId_eComp0_V0},  /* Vfd2 */
1109         {false, BVDC_P_WindowId_eComp0_V0},  /* Vfd3 */
1110         {false, BVDC_P_WindowId_eComp0_V0},  /* Vfd4 */
1111         {false, BVDC_P_WindowId_eComp0_V0}}, /* Vfd5 */
1112
1113        /* compositor 1: could take any video source or gfx1 */
1114        {{true,  BVDC_P_WindowId_eComp1_V0},  /* Mpeg0 */
1115         {true,  BVDC_P_WindowId_eComp1_V0},  /* Mpeg1 */
1116         {true,  BVDC_P_WindowId_eComp1_V0},  /* Mpeg2 */
1117         {true,  BVDC_P_WindowId_eComp1_V0},  /* Mpeg3 */
1118         {true,  BVDC_P_WindowId_eComp1_V0},  /* Vdec0 */
1119         {true,  BVDC_P_WindowId_eComp1_V0},  /* Vdec1 */
1120         {true,  BVDC_P_WindowId_eComp1_V0},  /* 656In0 */
1121         {true,  BVDC_P_WindowId_eComp1_V0},  /* 656In1 */
1122         {false, BVDC_P_WindowId_eComp1_G0},  /* Gfx0 */
1123         {true,  BVDC_P_WindowId_eComp1_G0},  /* Gfx1 */
1124         {false, BVDC_P_WindowId_eComp1_G0},  /* Gfx2 */
1125         {false, BVDC_P_WindowId_eComp1_G0},  /* Gfx3 */
1126         {false, BVDC_P_WindowId_eComp1_G0},  /* Gfx4 */
1127         {false, BVDC_P_WindowId_eComp1_G0},  /* Gfx5 */
1128         {true,  BVDC_P_WindowId_eComp1_V0},  /* HdDvi0 */
1129         {true,  BVDC_P_WindowId_eComp1_V0},  /* HdDvi1 */
1130         {true,  BVDC_P_WindowId_eComp1_V0},  /* Ds0 */
1131         {false, BVDC_P_WindowId_eComp1_V0},  /* Vfd0 */
1132         {false, BVDC_P_WindowId_eComp1_V0},  /* Vfd1 */
1133         {true,  BVDC_P_WindowId_eComp1_V0},  /* Vfd2 */
1134         {true,  BVDC_P_WindowId_eComp1_V0},  /* Vfd3 */
1135         {false, BVDC_P_WindowId_eComp1_V0},  /* Vfd4 */
1136         {false, BVDC_P_WindowId_eComp1_V0}}, /* Vfd5 */
1137
1138        /* bypass 0: intended for analog PVR; enforce analog video source */
1139        {{true,  BVDC_P_WindowId_eComp2_V0},  /* Mpeg0 */
1140         {true,  BVDC_P_WindowId_eComp2_V0},  /* Mpeg1 */
1141         {true,  BVDC_P_WindowId_eComp2_V0},  /* Mpeg2 */
1142         {true,  BVDC_P_WindowId_eComp2_V0},  /* Mpeg3 */
1143         {true,  BVDC_P_WindowId_eComp2_V0},  /* Vdec0 */
1144         {true,  BVDC_P_WindowId_eComp2_V0},  /* Vdec1 */
1145         {true,  BVDC_P_WindowId_eComp2_V0},  /* 656In0 */
1146         {true,  BVDC_P_WindowId_eComp2_V0},  /* 656In1 */
1147         {false, BVDC_P_WindowId_eComp2_G0},  /* Gfx0 */
1148         {false, BVDC_P_WindowId_eComp2_G0},  /* Gfx1 */
1149         {true,  BVDC_P_WindowId_eComp2_G0},  /* Gfx2 */
1150         {false, BVDC_P_WindowId_eComp2_G0},  /* Gfx3 */
1151         {false, BVDC_P_WindowId_eComp2_G0},  /* Gfx4 */
1152         {false, BVDC_P_WindowId_eComp2_G0},  /* Gfx5 */
1153         {true,  BVDC_P_WindowId_eComp2_V0},  /* HdDvi0 */
1154         {true,  BVDC_P_WindowId_eComp2_V0},  /* HdDvi1 */
1155         {false, BVDC_P_WindowId_eComp2_V0},  /* Ds0 */
1156         {false, BVDC_P_WindowId_eComp2_V0},  /* Vfd0 */
1157         {false, BVDC_P_WindowId_eComp2_V0},  /* Vfd1 */
1158         {false, BVDC_P_WindowId_eComp2_V0},  /* Vfd2 */
1159         {true,  BVDC_P_WindowId_eComp2_V0},  /* Vfd3 */
1160         {true,  BVDC_P_WindowId_eComp2_V0},  /* Vfd4 */
1161         {true,  BVDC_P_WindowId_eComp2_V0}}, /* Vfd5 */
1162
1163        /* VICE */
1164        {{true,  BVDC_P_WindowId_eComp3_V0},  /* Mpeg0 */
1165         {true,  BVDC_P_WindowId_eComp3_V0},  /* Mpeg1 */
1166         {true,  BVDC_P_WindowId_eComp3_V0},  /* Mpeg2 */
1167         {true,  BVDC_P_WindowId_eComp3_V0},  /* Mpeg3 */
1168         {true,  BVDC_P_WindowId_eComp3_V0},  /* Vdec0 */
1169         {true,  BVDC_P_WindowId_eComp3_V0},  /* Vdec1 */
1170         {true,  BVDC_P_WindowId_eComp3_V0},  /* 656In0 */
1171         {true,  BVDC_P_WindowId_eComp3_V0},  /* 656In1 */
1172         {false, BVDC_P_WindowId_eComp3_G0},  /* Gfx0 */
1173         {false, BVDC_P_WindowId_eComp3_G0},  /* Gfx1 */
1174         {false, BVDC_P_WindowId_eComp3_G0},  /* Gfx2 */
1175         {true,  BVDC_P_WindowId_eComp3_G0},  /* Gfx3 */
1176         {true,  BVDC_P_WindowId_eComp3_G0},  /* Gfx4 */
1177         {true,  BVDC_P_WindowId_eComp3_G0},  /* Gfx5 */
1178         {true,  BVDC_P_WindowId_eComp3_V0},  /* HdDvi0 */
1179         {true,  BVDC_P_WindowId_eComp3_V0},  /* HdDvi1 */
1180         {false, BVDC_P_WindowId_eComp3_V0},  /* Ds0 */
1181         {false, BVDC_P_WindowId_eComp3_V0},  /* Vfd0 */
1182         {false, BVDC_P_WindowId_eComp3_V0},  /* Vfd1 */
1183         {false, BVDC_P_WindowId_eComp3_V0},  /* Vfd2 */
1184         {false, BVDC_P_WindowId_eComp3_V0},  /* Vfd3 */
1185         {true,  BVDC_P_WindowId_eComp3_V0},  /* Vfd4 */
1186         {true,  BVDC_P_WindowId_eComp3_V0}}, /* Vfd5 */
1187
1188        /* VICE */
1189        {{true,  BVDC_P_WindowId_eComp4_V0},  /* Mpeg0 */
1190         {true,  BVDC_P_WindowId_eComp4_V0},  /* Mpeg1 */
1191         {true,  BVDC_P_WindowId_eComp4_V0},  /* Mpeg2 */
1192         {true,  BVDC_P_WindowId_eComp4_V0},  /* Mpeg3 */
1193         {true,  BVDC_P_WindowId_eComp4_V0},  /* Vdec0 */
1194         {true,  BVDC_P_WindowId_eComp4_V0},  /* Vdec1 */
1195         {true,  BVDC_P_WindowId_eComp4_V0},  /* 656In0 */
1196         {true,  BVDC_P_WindowId_eComp4_V0},  /* 656In1 */
1197         {false, BVDC_P_WindowId_eComp4_G0},  /* Gfx0 */
1198         {false, BVDC_P_WindowId_eComp4_G0},  /* Gfx1 */
1199         {false, BVDC_P_WindowId_eComp4_G0},  /* Gfx2 */
1200         {true,  BVDC_P_WindowId_eComp4_G0},  /* Gfx3 */
1201         {true,  BVDC_P_WindowId_eComp4_G0},  /* Gfx4 */
1202         {true,  BVDC_P_WindowId_eComp4_G0},  /* Gfx5 */
1203         {true,  BVDC_P_WindowId_eComp4_V0},  /* HdDvi0 */
1204         {true,  BVDC_P_WindowId_eComp4_V0},  /* HdDvi1 */
1205         {false, BVDC_P_WindowId_eComp4_V0},  /* Ds0 */
1206         {false, BVDC_P_WindowId_eComp4_V0},  /* Vfd0 */
1207         {false, BVDC_P_WindowId_eComp4_V0},  /* Vfd1 */
1208         {false, BVDC_P_WindowId_eComp4_V0},  /* Vfd2 */
1209         {false, BVDC_P_WindowId_eComp4_V0},  /* Vfd3 */
1210         {true,  BVDC_P_WindowId_eComp4_V0},  /* Vfd4 */
1211         {true,  BVDC_P_WindowId_eComp4_V0}}, /* Vfd5 */
1212
1213        /* VICE */
1214        {{true,  BVDC_P_WindowId_eComp5_V0},  /* Mpeg0 */
1215         {true,  BVDC_P_WindowId_eComp5_V0},  /* Mpeg1 */
1216         {true,  BVDC_P_WindowId_eComp5_V0},  /* Mpeg2 */
1217         {true,  BVDC_P_WindowId_eComp5_V0},  /* Mpeg3 */
1218         {true,  BVDC_P_WindowId_eComp5_V0},  /* Vdec0 */
1219         {true,  BVDC_P_WindowId_eComp5_V0},  /* Vdec1 */
1220         {true,  BVDC_P_WindowId_eComp5_V0},  /* 656In0 */
1221         {true,  BVDC_P_WindowId_eComp5_V0},  /* 656In1 */
1222         {false, BVDC_P_WindowId_eComp5_G0},  /* Gfx0 */
1223         {false, BVDC_P_WindowId_eComp5_G0},  /* Gfx1 */
1224         {false, BVDC_P_WindowId_eComp5_G0},  /* Gfx2 */
1225         {true,  BVDC_P_WindowId_eComp5_G0},  /* Gfx3 */
1226         {true,  BVDC_P_WindowId_eComp5_G0},  /* Gfx4 */
1227         {true,  BVDC_P_WindowId_eComp5_G0},  /* Gfx5 */
1228         {true,  BVDC_P_WindowId_eComp5_V0},  /* HdDvi0 */
1229         {true,  BVDC_P_WindowId_eComp5_V0},  /* HdDvi1 */
1230         {false, BVDC_P_WindowId_eComp5_V0},  /* Ds0 */
1231         {false, BVDC_P_WindowId_eComp5_V0},  /* Vfd0 */
1232         {false, BVDC_P_WindowId_eComp5_V0},  /* Vfd1 */
1233         {false, BVDC_P_WindowId_eComp5_V0},  /* Vfd2 */
1234         {false, BVDC_P_WindowId_eComp5_V0},  /* Vfd3 */
1235         {true,  BVDC_P_WindowId_eComp5_V0},  /* Vfd4 */
1236         {true,  BVDC_P_WindowId_eComp5_V0}}, /* Vfd5 */
1237};
1238
1239/* max clear rect: index by eWinId */
1240static const uint32_t s_aulWinMaxClearRect[] =
1241{
1242        BVDC_P_CMP_0_CLEAR_RECT_V0,  /* BVDC_P_WindowId_eComp0_V0 = 0 */
1243        BVDC_P_CMP_0_CLEAR_RECT_V1,  /* BVDC_P_WindowId_eComp0_V1 */
1244        BVDC_P_CMP_1_CLEAR_RECT_V0,  /* BVDC_P_WindowId_eComp1_V0 */
1245        BVDC_P_CMP_1_CLEAR_RECT_V1,  /* BVDC_P_WindowId_eComp1_V1 */
1246        BVDC_P_CMP_2_CLEAR_RECT_V0,  /* BVDC_P_WindowId_eComp2_V0 */
1247        BVDC_P_CMP_3_CLEAR_RECT_V0,  /* BVDC_P_WindowId_eComp3_V0 */
1248        BVDC_P_CMP_4_CLEAR_RECT_V0,  /* BVDC_P_WindowId_eComp4_V0 */
1249        BVDC_P_CMP_5_CLEAR_RECT_V0,  /* BVDC_P_WindowId_eComp5_V0 */
1250        0,                           /* BVDC_P_WindowId_eComp0_G0 */
1251        0,                           /* BVDC_P_WindowId_eComp0_G1 */
1252        0,                           /* BVDC_P_WindowId_eComp0_G2 */
1253        0,                           /* BVDC_P_WindowId_eComp1_G0 */
1254        0,                           /* BVDC_P_WindowId_eComp2_G0 */
1255        0,                           /* BVDC_P_WindowId_eComp3_G0 */
1256        0,                           /* BVDC_P_WindowId_eComp4_G0 */
1257        0                            /* BVDC_P_WindowId_eComp5_G0 */
1258};
1259
1260
1261/***************************************************************************
1262 *
1263 */
1264BERR_Code BVDC_Window_GetDefaultSettings
1265        ( BVDC_WindowId                    eWindowId,
1266          BVDC_Window_Settings            *pDefSettings )
1267{
1268        BSTD_UNUSED(eWindowId);
1269
1270        /* Clear out first */
1271        BKNI_Memset(pDefSettings, 0, sizeof(BVDC_Window_Settings));
1272
1273        /* Initialized */
1274        pDefSettings->hHeap = NULL;
1275        pDefSettings->ulMaxMosaicRect = s_aulWinMaxClearRect[eWindowId];
1276
1277        /* if this is true, then sync-slipped window may have double-capture-buffer
1278           instead of multi-buffer operation; this works with VEC locking; */
1279        pDefSettings->bForceSyncLock = false;
1280
1281        /* KLUDGE: PR53654, no flash for source format smaller than 720p.  This
1282         * currently temporary assumption, and will be going thru a public api
1283         * that allow application to specify the minimun buffer allow that will
1284         * not flash.
1285         * Maintain flag for backward compatibility, user specify no flag but
1286         * did not specify format we default to 720p. */
1287        #ifndef BVDC_NO_FLASH
1288        #define BVDC_NO_FLASH (0)
1289        #endif
1290        #if (BVDC_NO_FLASH)
1291        if(!pDefSettings->pMinSrcFmt)
1292        {
1293                pDefSettings->pMinSrcFmt = BFMT_GetVideoFormatInfoPtr(BFMT_VideoFmt_e720p);
1294        }
1295        #endif
1296
1297        return BERR_SUCCESS;
1298}
1299
1300
1301/***************************************************************************
1302 *
1303 */
1304BERR_Code BVDC_Window_Create
1305        ( BVDC_Compositor_Handle           hCompositor,
1306          BVDC_Window_Handle              *phWindow,
1307          BVDC_WindowId                    eId,
1308          BVDC_Source_Handle               hSource,
1309          const BVDC_Window_Settings      *pDefSettings )
1310{
1311        BVDC_Window_Handle hWindow;
1312        BVDC_P_WindowId eWindowId;
1313        uint32_t i;
1314
1315        BDBG_ENTER(BVDC_Window_Create);
1316
1317        BDBG_ASSERT(hCompositor);
1318        BDBG_ASSERT(phWindow);
1319        BDBG_ASSERT(hSource);
1320
1321        /* Check internally if we created. */
1322        BDBG_OBJECT_ASSERT(hSource, BVDC_SRC);
1323        BDBG_OBJECT_ASSERT(hCompositor, BVDC_CMP);
1324
1325        /* Make sure the source/compositor is active or created. */
1326        if(BVDC_P_STATE_IS_INACTIVE(hSource) ||
1327           BVDC_P_STATE_IS_DESTROY(hSource) ||
1328           BVDC_P_STATE_IS_INACTIVE(hCompositor) ||
1329           BVDC_P_STATE_IS_DESTROY(hCompositor))
1330        {
1331                BDBG_ERR(("Compositor and/or Source are not active."));
1332                return BERR_TRACE(BVDC_ERR_WINDOW_NOT_AVAILABLE);
1333        }
1334
1335        /* Check if this window allow on this compositor?  Some compositor does not
1336         * support graphics window that crosses to other compositor. */
1337        if(!s_aaWindowIdSelectTable[hCompositor->eId][hSource->eId].bValid)
1338        {
1339                BDBG_ERR(("Window is not available."));
1340                return BERR_TRACE(BVDC_ERR_WINDOW_NOT_AVAILABLE);
1341        }
1342
1343        /* Determine what window id to use. */
1344        eWindowId = s_aaWindowIdSelectTable[hCompositor->eId][hSource->eId].eWindowId;
1345
1346
1347        /* Check if any VFD source is active but has no connected windows */
1348        if (!BVDC_P_SRC_IS_VFD(hSource->eId))
1349        {
1350                for (i=0; i<BVDC_P_MAX_SOURCE_COUNT; i++)
1351                {
1352                        BVDC_Source_Handle hTmpSrc = hSource->hVdc->ahSource[i];
1353                        if (hTmpSrc)
1354                        {
1355                                if (BVDC_P_SRC_IS_VFD(hTmpSrc->eId) && BVDC_P_STATE_IS_ACTIVE(hTmpSrc))
1356                                {
1357                                        if (eWindowId == s_aaWindowIdSelectTable[hCompositor->eId][hTmpSrc->eId].eWindowId)
1358                                        {
1359                                                BDBG_ERR(("Window is already assigned to source %d.", hTmpSrc->eId));
1360                                                return BERR_TRACE(BVDC_ERR_WINDOW_NOT_AVAILABLE);
1361                                        }
1362                                }
1363                        }
1364                }
1365        }
1366
1367        if(BVDC_P_SRC_IS_VIDEO(hSource->eId) && (eId != BVDC_WindowId_eAuto))
1368        {
1369                eWindowId += eId;
1370        }
1371
1372        /* Need to select V0 or V1 for comp0/comp1. */
1373        if((BVDC_P_SRC_IS_VIDEO(hSource->eId)) && (eId == BVDC_WindowId_eAuto) &&
1374           (hCompositor->pFeatures->ulMaxVideoWindow > 1))
1375        {
1376                uint32_t              ulIndex;
1377                BVDC_Window_Handle hV0, hV1;
1378
1379                ulIndex = (hCompositor->eId == BVDC_CompositorId_eCompositor0)
1380                        ? BVDC_P_WindowId_eComp0_V0 : BVDC_P_WindowId_eComp1_V0;
1381                hV0 = hCompositor->ahWindow[ulIndex];
1382                hV1 = hCompositor->ahWindow[ulIndex+1];
1383                BDBG_OBJECT_ASSERT(hV0, BVDC_WIN);
1384                BDBG_OBJECT_ASSERT(hV1, BVDC_WIN);
1385
1386                /* Check if V0 or V1 is available */
1387                hWindow = (BVDC_P_STATE_IS_INACTIVE(hV0)) ? hV0 : hV1;
1388        }
1389        else
1390        {
1391                hWindow = hCompositor->ahWindow[eWindowId];
1392                BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
1393        }
1394
1395        /* Check if the window is already created or not. */
1396        if(!BVDC_P_STATE_IS_INACTIVE(hWindow))
1397        {
1398                BDBG_ERR(("Window[%d] state = %d", hWindow->eId, hWindow->eState));
1399                return BERR_TRACE(BVDC_ERR_WINDOW_ALREADY_CREATED);
1400        }
1401
1402        BDBG_MSG(("Creating window%d", hWindow->eId));
1403        BDBG_ASSERT(BVDC_P_STATE_IS_INACTIVE(hWindow));
1404
1405        /* Reinitialize context.  But not make it active until apply. */
1406        *phWindow = hWindow;
1407
1408        /* Which heap to use? */
1409        hWindow->hHeap = ((pDefSettings) && (pDefSettings->hHeap))
1410                ? pDefSettings->hHeap : hCompositor->hVdc->hBufferHeap;
1411
1412        /* Default settings */
1413        if(pDefSettings)
1414        {
1415                hWindow->stSettings = *pDefSettings;
1416                /* Do not allow override of number of rect this is read-only
1417                 * information. */
1418                if(hWindow->eId < BVDC_P_WindowId_eUnknown)
1419                {
1420                        hWindow->stSettings.ulMaxMosaicRect = s_aulWinMaxClearRect[hWindow->eId];
1421                }
1422                else
1423                {
1424                        BDBG_ASSERT(hWindow->eId < BVDC_P_WindowId_eUnknown);
1425                }
1426        }
1427        else
1428        {
1429                BVDC_Window_GetDefaultSettings(hWindow->eId, &hWindow->stSettings);
1430        }
1431
1432#if BVDC_P_SUPPORT_MOSAIC_MODE
1433        if((pDefSettings) && (pDefSettings->hHeap))
1434        {
1435                /* Allocate drain buffer from window heap */
1436                if(hWindow->stSettings.ulMaxMosaicRect)
1437                {
1438                        /* allocate drain buffer (2 pixels deep) for mosaic mode support */
1439                        hWindow->pvNullBufAddr = BMEM_Heap_AllocAligned(
1440                                pDefSettings->hHeap->hMem,
1441                                16, /* 2 pixels wide, in case 10-bit 4:2:2 capture rounding; */
1442                                4,  /* 16 bytes aligned for capture engine */
1443                                0   /* no boundary */);
1444                        BERR_TRACE(BMEM_Heap_ConvertAddressToOffset(
1445                                pDefSettings->hHeap->hMem,
1446                                hWindow->pvNullBufAddr, &hWindow->ulNullBufOffset));
1447                }
1448                else
1449                {
1450                        hWindow->pvNullBufAddr = NULL;
1451                        hWindow->ulNullBufOffset = 0;
1452                }
1453        }
1454        else
1455        {
1456                /* Use the drain buffer from VDC main heap. Set pvNullBufAddr to NULL
1457                 * so it will not be free in BVDC_Window_Destroy */
1458                hWindow->pvNullBufAddr = NULL;
1459                hWindow->ulNullBufOffset = hCompositor->hVdc->ulVdcNullBufOffset;
1460        }
1461
1462#endif
1463
1464        /* Inititial window fields */
1465        BVDC_P_Window_Init(*phWindow, hSource);
1466
1467        /* Keep count of new number of windows that connected to source! */
1468        hSource->stNewInfo.ulWindows++;
1469        hSource->stNewInfo.stDirty.stBits.bWindowNum = BVDC_P_DIRTY;
1470        hSource->stNewInfo.stDirty.stBits.bAddWin = BVDC_P_DIRTY;
1471
1472        BKNI_EnterCriticalSection();
1473        if(BVDC_P_SRC_IS_GFX(hSource->eId))
1474        {
1475                BVDC_P_Source_ConnectWindow_isr(hSource, hWindow);
1476        }
1477
1478        /* Mark as create, awating for apply. */
1479        hWindow->eState = BVDC_P_State_eCreate;
1480        BKNI_LeaveCriticalSection();
1481
1482        BDBG_MSG(("Window[%d] is BVDC_P_State_eCreate", hWindow->eId));
1483
1484        BDBG_LEAVE(BVDC_Window_Create);
1485        return BERR_SUCCESS;
1486}
1487
1488
1489/***************************************************************************
1490 *
1491 */
1492BERR_Code BVDC_Window_Destroy
1493        ( BVDC_Window_Handle               hWindow )
1494{
1495        BERR_Code eRet = BERR_SUCCESS;
1496
1497        BDBG_ENTER(BVDC_Window_Destroy);
1498
1499        /* Return if trying to free a NULL handle. */
1500        if(!hWindow)
1501        {
1502                goto done;
1503        }
1504
1505        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
1506        if(BVDC_P_STATE_IS_DESTROY(hWindow) ||
1507           BVDC_P_STATE_IS_INACTIVE(hWindow))
1508        {
1509                goto done;
1510        }
1511
1512        BVDC_P_Window_DisableBoxDetect(hWindow);
1513
1514        BKNI_EnterCriticalSection();
1515        if (BVDC_P_STATE_IS_CREATE(hWindow))
1516        {
1517                hWindow->eState = BVDC_P_State_eInactive;
1518                BDBG_MSG(("Window[%d] is BVDC_P_State_eInactive", hWindow->eId));
1519
1520                /* Keep count of new number of windows that connected to source! */
1521                hWindow->stNewInfo.hSource->stNewInfo.ulWindows--;
1522                hWindow->stNewInfo.hSource->stNewInfo.stDirty.stBits.bWindowNum = BVDC_P_DIRTY;
1523        }
1524        else if (BVDC_P_STATE_IS_ACTIVE(hWindow))
1525        {
1526                /* check if user-captured buffers, if any, were returned */
1527                if (BVDC_P_Window_CheckForUnReturnedUserCapturedBuffer_isr(hWindow))
1528                {
1529                        eRet = BVDC_ERR_USER_STILL_HAS_CAPTURE_BUFFER;
1530                }
1531
1532                /* Keep count of new number of windows that connected to source! */
1533                hWindow->stCurInfo.hSource->stNewInfo.ulWindows--;
1534                hWindow->stNewInfo.hSource->stNewInfo.stDirty.stBits.bWindowNum = BVDC_P_DIRTY;
1535                hWindow->eState = BVDC_P_State_eDestroy;
1536                BDBG_MSG(("Window[%d] is BVDC_P_State_eDestroy", hWindow->eId));
1537        }
1538        BKNI_LeaveCriticalSection();
1539
1540#if BVDC_P_SUPPORT_MOSAIC_MODE
1541        if(hWindow->pvNullBufAddr)
1542        {
1543                /* free drain buffer */
1544                BMEM_Heap_Free(hWindow->hHeap->hMem, hWindow->pvNullBufAddr);
1545        }
1546#endif
1547
1548
1549done:
1550        BDBG_LEAVE(BVDC_Window_Destroy);
1551        return eRet;
1552}
1553
1554
1555/***************************************************************************
1556 *
1557 */
1558BERR_Code BVDC_Window_SetSrcClip
1559        ( BVDC_Window_Handle               hWindow,
1560          uint32_t                         ulLeft,
1561          uint32_t                         ulRight,
1562          uint32_t                         ulTop,
1563          uint32_t                         ulBottom )
1564{
1565        BDBG_ENTER(BVDC_Window_SetSrcClip);
1566        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
1567
1568        /* set new value */
1569        hWindow->stNewInfo.stSrcClip.ulLeft   = ulLeft;
1570        hWindow->stNewInfo.stSrcClip.ulRight  = ulRight;
1571        hWindow->stNewInfo.stSrcClip.ulTop    = ulTop;
1572        hWindow->stNewInfo.stSrcClip.ulBottom = ulBottom;
1573
1574        BDBG_LEAVE(BVDC_Window_SetSrcClip);
1575        return BERR_SUCCESS;
1576}
1577
1578
1579
1580/***************************************************************************
1581 *
1582 */
1583BERR_Code BVDC_Window_SetSrcRightClip
1584        ( BVDC_Window_Handle               hWindow,
1585          int32_t                          lLeftDelta )
1586{
1587        BERR_Code eRet = BERR_SUCCESS;
1588
1589#if (!BVDC_P_SUPPORT_3D_INDEP_SRC_CLIP)
1590        BSTD_UNUSED(lLeftDelta);
1591#endif
1592
1593        BDBG_ENTER(BVDC_Window_SetSrcRightClip);
1594        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
1595
1596#if (!BVDC_P_SUPPORT_3D_INDEP_SRC_CLIP)
1597        BDBG_ERR(("Independent source clipping not support on this chip!"));
1598        eRet = BVDC_ERR_3D_INDEP_SRC_CLIP_NOT_SUPPORTED;
1599#else
1600        /* set new value */
1601        hWindow->stNewInfo.stSrcClip.lLeftDelta_R = lLeftDelta;
1602#endif
1603
1604        BDBG_LEAVE(BVDC_Window_SetSrcRightClip);
1605        return BERR_TRACE(eRet);
1606}
1607
1608/***************************************************************************
1609 *
1610 */
1611BERR_Code BVDC_Window_GetSrcRightClip
1612        ( const BVDC_Window_Handle         hWindow,
1613          int32_t                         *plLeftDelta )
1614{
1615        BDBG_ENTER(BVDC_Window_GetSrcRightClip);
1616        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
1617
1618        if(plLeftDelta)
1619        {
1620                *plLeftDelta = hWindow->stCurInfo.stSrcClip.lLeftDelta_R;
1621        }
1622
1623        BDBG_LEAVE(BVDC_Window_GetSrcRightClip);
1624        return BERR_SUCCESS;
1625}
1626
1627
1628/***************************************************************************
1629 *
1630 */
1631BERR_Code BVDC_Window_SetSrcClip_isr
1632        ( BVDC_Window_Handle               hWindow,
1633          uint32_t                         ulLeft,
1634          uint32_t                         ulRight,
1635          uint32_t                         ulTop,
1636          uint32_t                         ulBottom )
1637{
1638        BDBG_ENTER(BVDC_Window_SetSrcClip_isr);
1639        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
1640
1641        /* set isr value and validate it later */
1642        hWindow->stIsrInfo.stSrcClip.ulLeft   = ulLeft;
1643        hWindow->stIsrInfo.stSrcClip.ulRight  = ulRight;
1644        hWindow->stIsrInfo.stSrcClip.ulTop    = ulTop;
1645        hWindow->stIsrInfo.stSrcClip.ulBottom = ulBottom;
1646
1647        BDBG_LEAVE(BVDC_Window_SetSrcClip_isr);
1648        return BERR_SUCCESS;
1649}
1650
1651
1652/***************************************************************************
1653 *
1654 */
1655BERR_Code BVDC_Window_GetSrcClip
1656        ( const BVDC_Window_Handle         hWindow,
1657          uint32_t                        *pulLeft,
1658          uint32_t                        *pulRight,
1659          uint32_t                        *pulTop,
1660          uint32_t                        *pulBottom )
1661{
1662        BDBG_ENTER(BVDC_Window_GetSrcClip);
1663        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
1664
1665        /* get value */
1666        if(pulLeft)
1667        {
1668                *pulLeft = hWindow->stCurInfo.stSrcClip.ulLeft;
1669        }
1670
1671        if(pulRight)
1672        {
1673                *pulRight = hWindow->stCurInfo.stSrcClip.ulRight;
1674        }
1675
1676        if(pulTop)
1677        {
1678                *pulTop = hWindow->stCurInfo.stSrcClip.ulTop;
1679        }
1680
1681        if(pulBottom)
1682        {
1683                *pulBottom = hWindow->stCurInfo.stSrcClip.ulBottom;
1684        }
1685
1686        BDBG_LEAVE(BVDC_Window_GetSrcClip);
1687        return BERR_SUCCESS;
1688}
1689
1690
1691/***************************************************************************
1692 *
1693 */
1694BERR_Code BVDC_Window_SetDstRect
1695        ( BVDC_Window_Handle               hWindow,
1696          int32_t                          lLeft,
1697          int32_t                          lTop,
1698          uint32_t                         ulWidth,
1699          uint32_t                         ulHeight )
1700{
1701        BDBG_ENTER(BVDC_Window_SetDstRect);
1702        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
1703
1704        /* Dst Rect cannot be smaller than 2x1. */
1705        if(ulWidth < BVDC_P_WIN_DST_OUTPUT_H_MIN ||
1706           ulHeight < BVDC_P_WIN_DST_OUTPUT_V_MIN)
1707        {
1708                BDBG_ERR(("Min Dst Rect is %dx%d",
1709                        BVDC_P_WIN_DST_OUTPUT_H_MIN,
1710                        BVDC_P_WIN_DST_OUTPUT_V_MIN));
1711                return BERR_TRACE(BERR_INVALID_PARAMETER);
1712        }
1713
1714        /* set new value */
1715        hWindow->stNewInfo.stDstRect.lLeft    = lLeft;
1716        hWindow->stNewInfo.stDstRect.lTop     = lTop;
1717        hWindow->stNewInfo.stDstRect.ulWidth  = ulWidth;
1718        hWindow->stNewInfo.stDstRect.ulHeight = ulHeight;
1719
1720        BDBG_LEAVE(BVDC_Window_SetDstRect);
1721        return BERR_SUCCESS;
1722}
1723
1724/***************************************************************************
1725 *
1726 */
1727BERR_Code BVDC_Window_SetDstRect_isr
1728        ( BVDC_Window_Handle               hWindow,
1729          int32_t                          lLeft,
1730          int32_t                          lTop,
1731          uint32_t                         ulWidth,
1732          uint32_t                         ulHeight )
1733{
1734        BDBG_ENTER(BVDC_Window_SetDstRect_isr);
1735        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
1736
1737        /* set isr value and validate it later */
1738        hWindow->stIsrInfo.stDstRect.lLeft    = lLeft;
1739        hWindow->stIsrInfo.stDstRect.lTop     = lTop;
1740        hWindow->stIsrInfo.stDstRect.ulWidth  = ulWidth;
1741        hWindow->stIsrInfo.stDstRect.ulHeight = ulHeight;
1742
1743        BDBG_LEAVE(BVDC_Window_SetDstRect_isr);
1744        return BERR_SUCCESS;
1745}
1746
1747
1748/***************************************************************************
1749 *
1750 */
1751BERR_Code BVDC_Window_GetDstRect
1752        ( const BVDC_Window_Handle         hWindow,
1753          int32_t                         *plLeftScreen,
1754          int32_t                         *plTopScreen,
1755          uint32_t                        *pulWidth,
1756          uint32_t                        *pulHeight )
1757{
1758        BDBG_ENTER(BVDC_Window_GetDstRect);
1759        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
1760
1761        /* get value */
1762        if(plLeftScreen)
1763        {
1764                *plLeftScreen = hWindow->stCurInfo.stDstRect.lLeft;
1765        }
1766
1767        if(plTopScreen)
1768        {
1769                *plTopScreen = hWindow->stCurInfo.stDstRect.lTop;
1770        }
1771
1772        if(pulWidth)
1773        {
1774                *pulWidth = hWindow->stCurInfo.stDstRect.ulWidth;
1775        }
1776
1777        if(pulHeight)
1778        {
1779                *pulHeight = hWindow->stCurInfo.stDstRect.ulHeight;
1780        }
1781
1782        BDBG_LEAVE(BVDC_Window_GetDstRect);
1783        return BERR_SUCCESS;
1784}
1785
1786
1787/***************************************************************************
1788 *
1789 */
1790BERR_Code BVDC_Window_SetScalerOutput
1791        ( BVDC_Window_Handle               hWindow,
1792          uint32_t                         ulLeft,
1793          uint32_t                         ulTop,
1794          uint32_t                         ulWidth,
1795          uint32_t                         ulHeight )
1796{
1797        BDBG_ENTER(BVDC_Window_SetScalerOutput);
1798        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
1799
1800        /* Preliminary checking that does not depend on until applychanges. */
1801        if((ulLeft > ulWidth) ||
1802           (ulTop  > ulHeight))
1803        {
1804                BDBG_ERR(("Top, Left must be inside rectangle dimension"));
1805                return BERR_TRACE(BERR_INVALID_PARAMETER);
1806        }
1807
1808        /* set new value */
1809        hWindow->stNewInfo.stScalerOutput.lLeft    = ulLeft;
1810        hWindow->stNewInfo.stScalerOutput.lTop     = ulTop;
1811        hWindow->stNewInfo.stScalerOutput.ulWidth  = ulWidth;
1812        hWindow->stNewInfo.stScalerOutput.ulHeight = ulHeight;
1813
1814        BDBG_LEAVE(BVDC_Window_SetScalerOutput);
1815        return BERR_SUCCESS;
1816}
1817
1818/***************************************************************************
1819 *
1820 */
1821BERR_Code BVDC_Window_SetScalerOutput_isr
1822        ( BVDC_Window_Handle               hWindow,
1823          uint32_t                         ulLeft,
1824          uint32_t                         ulTop,
1825          uint32_t                         ulWidth,
1826          uint32_t                         ulHeight )
1827{
1828        BDBG_ENTER(BVDC_Window_SetScalerOutput_isr);
1829        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
1830
1831        /* Preliminary checking. */
1832        if((ulLeft > ulWidth) ||
1833           (ulTop  > ulHeight))
1834        {
1835                BDBG_ERR(("Top, Left must be inside rectangle dimension"));
1836                return BERR_TRACE(BERR_INVALID_PARAMETER);
1837        }
1838
1839        /* set isr value and validate it later */
1840        hWindow->stIsrInfo.stScalerOutput.lLeft    = ulLeft;
1841        hWindow->stIsrInfo.stScalerOutput.lTop     = ulTop;
1842        hWindow->stIsrInfo.stScalerOutput.ulWidth  = ulWidth;
1843        hWindow->stIsrInfo.stScalerOutput.ulHeight = ulHeight;
1844
1845        BDBG_LEAVE(BVDC_Window_SetScalerOutput_isr);
1846        return BERR_SUCCESS;
1847}
1848
1849
1850/***************************************************************************
1851 *
1852 */
1853BERR_Code BVDC_Window_GetScalerOutput
1854        ( const BVDC_Window_Handle         hWindow,
1855          uint32_t                        *pulLeft,
1856          uint32_t                        *pulTop,
1857          uint32_t                        *pulWidth,
1858          uint32_t                        *pulHeight )
1859{
1860        BDBG_ENTER(BVDC_Window_GetScalerOutput);
1861        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
1862
1863        /* get value */
1864        if(pulLeft)
1865        {
1866                *pulLeft = hWindow->stCurInfo.stScalerOutput.lLeft;
1867        }
1868
1869        if(pulTop)
1870        {
1871                *pulTop = hWindow->stCurInfo.stScalerOutput.lTop;
1872        }
1873
1874        if(pulWidth)
1875        {
1876                *pulWidth = hWindow->stCurInfo.stScalerOutput.ulWidth;
1877        }
1878
1879        if(pulHeight)
1880        {
1881                *pulHeight = hWindow->stCurInfo.stScalerOutput.ulHeight;
1882        }
1883
1884
1885        BDBG_LEAVE(BVDC_Window_GetScalerOutput);
1886        return BERR_SUCCESS;
1887}
1888
1889
1890/***************************************************************************
1891 *
1892 */
1893BERR_Code BVDC_Window_SetAlpha
1894        ( BVDC_Window_Handle               hWindow,
1895          uint8_t                          ucAlpha )
1896{
1897        BDBG_ENTER(BVDC_Window_SetAlpha);
1898        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
1899
1900        /* set new value */
1901        hWindow->stNewInfo.ucAlpha = ucAlpha;
1902
1903        BDBG_LEAVE(BVDC_Window_SetAlpha);
1904        return BERR_SUCCESS;
1905}
1906
1907
1908/***************************************************************************
1909 *
1910 */
1911BERR_Code BVDC_Window_GetAlpha
1912        ( const BVDC_Window_Handle         hWindow,
1913          uint8_t                         *pucAlpha )
1914{
1915        BDBG_ENTER(BVDC_Window_GetAlpha);
1916        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
1917
1918        /* set new value */
1919        if(pucAlpha)
1920        {
1921                *pucAlpha = hWindow->stCurInfo.ucAlpha;
1922        }
1923
1924        BDBG_LEAVE(BVDC_Window_GetAlpha);
1925        return BERR_SUCCESS;
1926}
1927
1928
1929/***************************************************************************
1930 *
1931 */
1932BERR_Code BVDC_Window_SetBlendFactor
1933        ( BVDC_Window_Handle               hWindow,
1934          BVDC_BlendFactor                 eSrcBlendFactor,
1935          BVDC_BlendFactor                 eDstBlendFactor,
1936          uint8_t                          ucConstantAlpha )
1937{
1938        BERR_Code  eResult;
1939
1940        BDBG_ENTER(BVDC_Window_SetBlendFactor);
1941        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
1942
1943        /* For gfx window need to restrict blending factor. */
1944        if( BVDC_P_WIN_IS_GFX_WINDOW(hWindow->eId) )
1945        {
1946                eResult = BVDC_P_GfxFeeder_ValidateBlend( eSrcBlendFactor,
1947                                                                                                  eDstBlendFactor,
1948                                                                                                  ucConstantAlpha );
1949                if ( BERR_SUCCESS != eResult )
1950                {
1951                        return BERR_TRACE(eResult);
1952                }
1953        }
1954
1955        /* set new value */
1956        hWindow->stNewInfo.ucConstantAlpha   = ucConstantAlpha;
1957        hWindow->stNewInfo.eFrontBlendFactor = eSrcBlendFactor;
1958        hWindow->stNewInfo.eBackBlendFactor  = eDstBlendFactor;
1959
1960        BDBG_LEAVE(BVDC_Window_SetBlendFactor);
1961        return BERR_SUCCESS;
1962}
1963
1964
1965/***************************************************************************
1966 *
1967 */
1968BERR_Code BVDC_Window_GetBlendFactor
1969        ( const BVDC_Window_Handle         hWindow,
1970          uint8_t                         *pucConstantAlpha,
1971          BVDC_BlendFactor                *peSrcBlendFactor,
1972          BVDC_BlendFactor                *peDstBlendFactor )
1973{
1974        BDBG_ENTER(BVDC_Window_GetBlendFactor);
1975        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
1976
1977        /* set new value */
1978        if(pucConstantAlpha)
1979        {
1980                *pucConstantAlpha = hWindow->stCurInfo.ucConstantAlpha;
1981        }
1982
1983        if(peSrcBlendFactor)
1984        {
1985                *peSrcBlendFactor = hWindow->stCurInfo.eFrontBlendFactor;
1986        }
1987
1988        if(peDstBlendFactor)
1989        {
1990                *peDstBlendFactor = hWindow->stCurInfo.eBackBlendFactor;
1991        }
1992
1993        BDBG_LEAVE(BVDC_Window_GetBlendFactor);
1994        return BERR_SUCCESS;
1995}
1996
1997
1998/***************************************************************************
1999 *
2000 */
2001BERR_Code BVDC_Window_SetZOrder
2002        ( BVDC_Window_Handle               hWindow,
2003          uint8_t                          ucZOrder )
2004{
2005        BDBG_ENTER(BVDC_Window_SetZOrder);
2006        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2007
2008        /* Preliminary checking that does not depend on until applychanges. */
2009        if(ucZOrder > BVDC_Z_ORDER_MAX)
2010        {
2011                return BERR_TRACE(BERR_INVALID_PARAMETER);
2012        }
2013
2014        /* set new value */
2015        hWindow->stNewInfo.ucZOrder = ucZOrder;
2016
2017        BDBG_LEAVE(BVDC_Window_SetZOrder);
2018        return BERR_SUCCESS;
2019}
2020
2021
2022/***************************************************************************
2023 *
2024 */
2025BERR_Code BVDC_Window_GetZOrder
2026        ( const BVDC_Window_Handle         hWindow,
2027          uint8_t                         *pucZOrder )
2028{
2029        BDBG_ENTER(BVDC_Window_GetZOrder);
2030        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2031
2032        /* set new value */
2033        if(pucZOrder)
2034        {
2035                *pucZOrder = hWindow->stCurInfo.ucZOrder;
2036        }
2037
2038        BDBG_LEAVE(BVDC_Window_GetZOrder);
2039        return BERR_SUCCESS;
2040}
2041
2042
2043/***************************************************************************
2044 *
2045 */
2046BERR_Code BVDC_Window_SetVisibility
2047        ( BVDC_Window_Handle               hWindow,
2048          bool                             bVisible )
2049{
2050        BDBG_ENTER(BVDC_Window_SetVisibility);
2051        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2052
2053        /* set new value */
2054        hWindow->stNewInfo.bVisible = bVisible;
2055
2056        BDBG_LEAVE(BVDC_Window_SetVisibility);
2057        return BERR_SUCCESS;
2058}
2059
2060
2061/***************************************************************************
2062 *
2063 */
2064BERR_Code BVDC_Window_GetVisibility
2065        ( const BVDC_Window_Handle         hWindow,
2066          bool                            *pbVisible )
2067{
2068        BDBG_ENTER(BVDC_Window_GetVisibility);
2069        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2070
2071        /* set new value */
2072        if(pbVisible)
2073        {
2074                *pbVisible = hWindow->stCurInfo.bVisible;
2075        }
2076
2077        BDBG_LEAVE(BVDC_Window_GetVisibility);
2078        return BERR_SUCCESS;
2079}
2080
2081
2082/***************************************************************************
2083 *
2084 */
2085BERR_Code BVDC_Window_SetDeinterlaceConfiguration
2086        ( BVDC_Window_Handle               hWindow,
2087          bool                             bDeinterlace,
2088          const BVDC_Deinterlace_Settings *pMadSettings )
2089{
2090        BVDC_P_Deinterlace_Settings *pNewMad;
2091        const BVDC_P_Deinterlace_Settings *pCurMad;
2092        BERR_Code    eResult;
2093
2094        BDBG_ENTER(BVDC_Window_SetDeinterlaceConfiguration);
2095        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2096
2097        pNewMad = &hWindow->stNewInfo.stMadSettings;
2098        pCurMad = &hWindow->stCurInfo.stMadSettings;
2099
2100        /* set new value */
2101        hWindow->stNewInfo.bDeinterlace = bDeinterlace;
2102
2103        if(bDeinterlace && pMadSettings)
2104        {
2105                eResult = BVDC_P_Window_SetMcvp_DeinterlaceConfiguration(hWindow, bDeinterlace, pMadSettings);
2106                if(eResult != BERR_SUCCESS)
2107                {
2108                        return BERR_TRACE(BERR_NOT_SUPPORTED);
2109                }
2110
2111                /*Mad: validate game mode */
2112                eResult = BVDC_P_Window_SetMad_DeinterlaceConfiguration(hWindow, bDeinterlace, pMadSettings);
2113                if(eResult != BERR_SUCCESS)
2114                {
2115                        return BERR_TRACE(BERR_NOT_SUPPORTED);
2116                }
2117
2118                pNewMad->eGameMode = pMadSettings->eGameMode;
2119                pNewMad->bShrinkWidth = pMadSettings->bShrinkWidth;
2120                pNewMad->bReverse32Pulldown = pMadSettings->bReverse32Pulldown;
2121                pNewMad->bReverse22Pulldown = pMadSettings->bReverse22Pulldown;
2122
2123#if (BVDC_P_SUPPORT_VIDEO_TESTFEATURE1_MAD_ANR)
2124                pNewMad->stTestFeature1.bEnable = pMadSettings->stVideoTestFeature1.bEnable;
2125                pNewMad->stTestFeature1.ulBitsPerPixel = pMadSettings->stVideoTestFeature1.ulBitsPerPixel;
2126#else
2127                BDBG_MSG(("This chip will ignore MAD TestFeature1 user setting!"));
2128#endif
2129
2130                if(pMadSettings->pChromaSettings)
2131                {
2132                        pNewMad->stChromaSettings = *(pMadSettings->pChromaSettings);
2133                        hWindow->stNewInfo.bChromaCustom = true;
2134                }
2135                else
2136                {
2137                        hWindow->stNewInfo.bChromaCustom = false;
2138                }
2139
2140                if(pMadSettings->pMotionSettings)
2141                {
2142                        pNewMad->stMotionSettings= *(pMadSettings->pMotionSettings);
2143                        hWindow->stNewInfo.bMotionCustom = true;
2144                }
2145                else
2146                {
2147                        hWindow->stNewInfo.bMotionCustom = false;
2148                }
2149
2150                if(pMadSettings->pReverse32Settings)
2151                {
2152                        pNewMad->stReverse32Settings = *(pMadSettings->pReverse32Settings);
2153                        hWindow->stNewInfo.bRev32Custom = true;
2154                }
2155                else
2156                {
2157                        hWindow->stNewInfo.bRev32Custom= false;
2158                }
2159
2160                if(pMadSettings->pReverse22Settings)
2161                {
2162                        pNewMad->stReverse22Settings = *(pMadSettings->pReverse22Settings);
2163                        hWindow->stNewInfo.bRev22Custom = true;
2164                }
2165                else
2166                {
2167                        hWindow->stNewInfo.bRev22Custom = false;
2168                }
2169
2170                /* Use the customized Up/Down sampler filter settings */
2171                if(pMadSettings->pUpSampler)
2172                {
2173                        pNewMad->stUpSampler = *(pMadSettings->pUpSampler);
2174                }
2175                else
2176                {
2177                        BVDC_P_Mad_Init_Custom(&pNewMad->stUpSampler, NULL, NULL);
2178                }
2179                if(pMadSettings->pDnSampler)
2180                {
2181                        pNewMad->stDnSampler = *(pMadSettings->pDnSampler);
2182                }
2183                else
2184                {
2185                        BVDC_P_Mad_Init_Custom(NULL, &pNewMad->stDnSampler, NULL);
2186                }
2187
2188                /* low angles setting */
2189                if(pMadSettings->pLowAngles)
2190                {
2191                        pNewMad->stLowAngles = *(pMadSettings->pLowAngles);
2192                }
2193                else
2194                {
2195                        BVDC_P_Mad_Init_Custom(NULL, NULL, &pNewMad->stLowAngles);
2196                }
2197        }
2198
2199        /* On/Off toggle and game mode change will be handled separately */
2200        if( (bDeinterlace != hWindow->stCurInfo.bDeinterlace) ||
2201          (bDeinterlace && pMadSettings &&
2202          (pNewMad->eGameMode != pCurMad->eGameMode ||
2203           pNewMad->ePixelFmt != pCurMad->ePixelFmt ||
2204           pNewMad->stTestFeature1.bEnable != pCurMad->stTestFeature1.bEnable ||
2205           pNewMad->stTestFeature1.ulBitsPerPixel  != pCurMad->stTestFeature1.ulBitsPerPixel ||
2206           pNewMad->bShrinkWidth != pCurMad->bShrinkWidth ||
2207           pNewMad->bReverse22Pulldown != pCurMad->bReverse22Pulldown ||
2208           pNewMad->bReverse32Pulldown != pCurMad->bReverse32Pulldown ||
2209           pNewMad->stChromaSettings.bChromaField420EdgeDetMode != pCurMad->stChromaSettings.bChromaField420EdgeDetMode ||
2210           pNewMad->stChromaSettings.bChromaField420InitPhase != pCurMad->stChromaSettings.bChromaField420InitPhase ||
2211           pNewMad->stChromaSettings.eChroma422InverseTelecineMode!= pCurMad->stChromaSettings.eChroma422InverseTelecineMode ||
2212           pNewMad->stChromaSettings.eChroma422MotionAdaptiveMode != pCurMad->stChromaSettings.eChroma422MotionAdaptiveMode ||
2213           pNewMad->stChromaSettings.eChromaField420InvMethod != pCurMad->stChromaSettings.eChromaField420InvMethod ||
2214           pNewMad->stChromaSettings.eChroma420MotionMode != pCurMad->stChromaSettings.eChroma420MotionMode ||
2215           pNewMad->stChromaSettings.eChroma422MotionMode != pCurMad->stChromaSettings.eChroma422MotionMode ||
2216           pNewMad->stChromaSettings.eChroma420MotionAdaptiveMode != pCurMad->stChromaSettings.eChroma420MotionAdaptiveMode ||
2217           pNewMad->stChromaSettings.bMS_3548 != pCurMad->stChromaSettings.bMS_3548 ||
2218           pNewMad->stChromaSettings.bMT_3548 != pCurMad->stChromaSettings.bMT_3548 ||
2219           pNewMad->stChromaSettings.ulMaxXChroma != pCurMad->stChromaSettings.ulMaxXChroma ||
2220           pNewMad->stMotionSettings.bEnableQmK != pCurMad->stMotionSettings.bEnableQmK ||
2221           pNewMad->stMotionSettings.bEnableQmL != pCurMad->stMotionSettings.bEnableQmL ||
2222           pNewMad->stMotionSettings.bEnableQmM != pCurMad->stMotionSettings.bEnableQmM ||
2223           pNewMad->stMotionSettings.eSmMode != pCurMad->stMotionSettings.eSmMode ||
2224           pNewMad->stMotionSettings.eTmMode != pCurMad->stMotionSettings.eTmMode ||
2225           pNewMad->stReverse22Settings.ulBwvLuma22Threshold != pCurMad->stReverse22Settings.ulBwvLuma22Threshold ||
2226           pNewMad->stReverse22Settings.ulEnterLockLevel != pCurMad->stReverse22Settings.ulEnterLockLevel ||
2227           pNewMad->stReverse22Settings.ulLockSatLevel != pCurMad->stReverse22Settings.ulLockSatLevel ||
2228           pNewMad->stReverse22Settings.ulNonMatchMatchRatio != pCurMad->stReverse22Settings.ulNonMatchMatchRatio ||
2229           pNewMad->stReverse32Settings.ulBadEditLevel != pCurMad->stReverse32Settings.ulBadEditLevel ||
2230           pNewMad->stReverse32Settings.ulBwvLuma32Threshold != pCurMad->stReverse32Settings.ulBwvLuma32Threshold ||
2231           pNewMad->stReverse32Settings.ulEnterLockLevel != pCurMad->stReverse32Settings.ulEnterLockLevel ||
2232           pNewMad->stReverse32Settings.ulLockSatLevel != pCurMad->stReverse32Settings.ulLockSatLevel ||
2233           pNewMad->stReverse32Settings.ulPhaseMatchThreshold != pCurMad->stReverse32Settings.ulPhaseMatchThreshold ||
2234           pNewMad->stReverse32Settings.ulRepfPxlCorrectLevel!= pCurMad->stReverse32Settings.ulRepfPxlCorrectLevel ||
2235           pNewMad->stReverse32Settings.ulRepfVetoLevel != pCurMad->stReverse32Settings.ulRepfVetoLevel ||
2236           hWindow->stNewInfo.bChromaCustom != hWindow->stCurInfo.bChromaCustom ||
2237           hWindow->stNewInfo.bMotionCustom != hWindow->stCurInfo.bMotionCustom ||
2238           hWindow->stNewInfo.bRev32Custom != hWindow->stCurInfo.bRev32Custom ||
2239           hWindow->stNewInfo.bRev22Custom != hWindow->stCurInfo.bRev22Custom ||
2240           pNewMad->stUpSampler.eFilterType != pCurMad->stUpSampler.eFilterType ||
2241           pNewMad->stUpSampler.eRingRemoval != pCurMad->stUpSampler.eRingRemoval ||
2242           pNewMad->stUpSampler.bUnbiasedRound != pCurMad->stUpSampler.bUnbiasedRound ||
2243           pNewMad->stDnSampler.eFilterType != pCurMad->stDnSampler.eFilterType ||
2244           pNewMad->stDnSampler.eRingRemoval != pCurMad->stDnSampler.eRingRemoval ||
2245           pNewMad->stLowAngles.ulLaControlDirRatio != pCurMad->stLowAngles.ulLaControlDirRatio ||
2246           pNewMad->stLowAngles.ulLaControlRangeLimitScale != pCurMad->stLowAngles.ulLaControlRangeLimitScale ||
2247           pNewMad->stLowAngles.ulLaMinNorthStrength != pCurMad->stLowAngles.ulLaMinNorthStrength)) )
2248        {
2249                hWindow->stNewInfo.stDirty.stBits.bDeinterlace = BVDC_P_DIRTY;
2250        }
2251
2252#if (!(BVDC_P_SUPPORT_MAD || BVDC_P_SUPPORT_MCVP))
2253        BSTD_UNUSED(pMadSettings);
2254
2255        if(bDeinterlace)
2256        {
2257                BDBG_ERR(("This chipset doesn't support deinterlace!"));
2258                return BERR_TRACE(BVDC_ERR_MAD_NOT_SUPPORTED);
2259        }
2260
2261#endif
2262
2263        BDBG_LEAVE(BVDC_Window_SetDeinterlaceConfiguration);
2264        return BERR_SUCCESS;
2265}
2266
2267
2268/***************************************************************************
2269 *
2270 */
2271BERR_Code BVDC_Window_GetDeinterlaceConfiguration
2272        ( const BVDC_Window_Handle         hWindow,
2273          bool                            *pbDeinterlace,
2274          BVDC_Deinterlace_Settings       *pMadSettings )
2275{
2276        const BVDC_P_Deinterlace_Settings *pCurMadSettings;
2277
2278        BDBG_ENTER(BVDC_Window_GetDeinterlaceConfiguration);
2279        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2280
2281        /* Cur Info */
2282        pCurMadSettings = &hWindow->stCurInfo.stMadSettings;
2283
2284        /* set new value */
2285        if(pbDeinterlace)
2286        {
2287                *pbDeinterlace = hWindow->stCurInfo.bDeinterlace;
2288        }
2289
2290        if(pMadSettings)
2291        {
2292                pMadSettings->eGameMode = pCurMadSettings->eGameMode;
2293                pMadSettings->ePxlFormat = pCurMadSettings->ePixelFmt;
2294                pMadSettings->bShrinkWidth       = pCurMadSettings->bShrinkWidth;
2295                pMadSettings->bReverse22Pulldown = pCurMadSettings->bReverse22Pulldown;
2296                pMadSettings->bReverse32Pulldown = pCurMadSettings->bReverse32Pulldown;
2297
2298                pMadSettings->stVideoTestFeature1.bEnable = pCurMadSettings->stTestFeature1.bEnable;
2299                pMadSettings->stVideoTestFeature1.ulBitsPerPixel = pCurMadSettings->stTestFeature1.ulBitsPerPixel;
2300
2301                /* Customized structure are NULL */
2302                pMadSettings->pChromaSettings    = NULL;
2303                pMadSettings->pMotionSettings    = NULL;
2304                pMadSettings->pReverse32Settings = NULL;
2305                pMadSettings->pReverse22Settings = NULL;
2306                pMadSettings->pUpSampler         = NULL;
2307                pMadSettings->pDnSampler         = NULL;
2308                pMadSettings->pLowAngles         = NULL;
2309        }
2310
2311        BDBG_LEAVE(BVDC_Window_GetDeinterlaceConfiguration);
2312        return BERR_SUCCESS;
2313}
2314
2315
2316/***************************************************************************
2317 *
2318 */
2319BERR_Code BVDC_Window_GetDeinterlaceDefaultConfiguration
2320        ( const BVDC_Window_Handle         hWindow,
2321          BVDC_Deinterlace_Settings       *pMadSettings )
2322{
2323        BDBG_ENTER(BVDC_Window_GetDeinterlaceDefaultConfiguration);
2324        /* sanity check input parameter as much as we can */
2325        BDBG_ASSERT(pMadSettings);
2326        BSTD_UNUSED(hWindow);
2327
2328        /* Get static default */
2329        BVDC_P_Mad_Init_Default(
2330                &pMadSettings->eGameMode,
2331                &pMadSettings->ePxlFormat,
2332                &pMadSettings->stVideoTestFeature1,
2333                &pMadSettings->bShrinkWidth,
2334                &pMadSettings->bReverse32Pulldown,
2335                 pMadSettings->pReverse32Settings,
2336                &pMadSettings->bReverse22Pulldown,
2337                 pMadSettings->pReverse22Settings,
2338                 pMadSettings->pChromaSettings,
2339                 pMadSettings->pMotionSettings);
2340
2341        BVDC_P_Mad_Init_Custom(
2342                pMadSettings->pUpSampler,
2343                pMadSettings->pDnSampler,
2344                pMadSettings->pLowAngles);
2345
2346        /* Get dynamic default */
2347        BVDC_P_Mad_Init_DynamicDefault(hWindow,
2348                pMadSettings->pReverse32Settings,
2349                pMadSettings->pReverse22Settings,
2350                pMadSettings->pChromaSettings);
2351
2352
2353        BDBG_LEAVE(BVDC_Window_GetDeinterlaceDefaultConfiguration);
2354        return BERR_SUCCESS;
2355}
2356
2357/***************************************************************************
2358 *
2359 */
2360BERR_Code BVDC_Window_SetVbiPassThrough
2361        ( BVDC_Window_Handle               hWindow,
2362          bool                             bAllowVbiPassThrough,
2363          uint32_t                         ulAdditionalVbiLines )
2364{
2365        BDBG_ERR(("BVDC_Window_SetVbiPassThrough() is no longer supported. "));
2366        BDBG_ASSERT(0);
2367        BSTD_UNUSED(hWindow);
2368        BSTD_UNUSED(bAllowVbiPassThrough);
2369        BSTD_UNUSED(ulAdditionalVbiLines);
2370        return BERR_NOT_SUPPORTED;
2371}
2372
2373
2374/***************************************************************************
2375 *
2376 */
2377BERR_Code BVDC_Window_GetVbiPassThrough
2378        ( const BVDC_Window_Handle         hWindow,
2379          bool                            *pbAllowVbiPassThrough,
2380          uint32_t                        *pulAdditionalVbiLines )
2381{
2382        BDBG_ERR(("BVDC_Window_GetVbiPassThrough() is no longer supported. "));
2383        BDBG_ASSERT(0);
2384        BSTD_UNUSED(hWindow);
2385        BSTD_UNUSED(pbAllowVbiPassThrough);
2386        BSTD_UNUSED(pulAdditionalVbiLines);
2387        return BERR_NOT_SUPPORTED;
2388}
2389
2390/***************************************************************************
2391 *
2392 */
2393BERR_Code BVDC_Window_SetAfdSettings
2394        ( BVDC_Window_Handle               hWindow,
2395          const BVDC_AfdSettings          *pAfdSettings )
2396{
2397        BDBG_ENTER(BVDC_Window_SetAfdSettings);
2398        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2399
2400        /* set new value */
2401        hWindow->stNewInfo.stAfdSettings = *pAfdSettings;
2402
2403        BDBG_LEAVE(BVDC_Window_SetAfdSettings);
2404        return BERR_SUCCESS;
2405}
2406
2407/***************************************************************************
2408 *
2409 */
2410BERR_Code BVDC_Window_GetAfdSettings
2411        ( const BVDC_Window_Handle         hWindow,
2412          BVDC_AfdSettings                *pAfdSettings )
2413{
2414        BDBG_ENTER(BVDC_Window_GetAfdSettings);
2415        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2416
2417        /* set new value */
2418        if(pAfdSettings)
2419        {
2420                *pAfdSettings = hWindow->stCurInfo.stAfdSettings;
2421        }
2422
2423        BDBG_LEAVE(BVDC_Window_GetAfdSettings);
2424        return BERR_SUCCESS;
2425}
2426
2427/***************************************************************************
2428 *
2429 */
2430BERR_Code BVDC_Window_SetPanScanType
2431        ( BVDC_Window_Handle               hWindow,
2432          BVDC_PanScanType                 ePanScanType )
2433{
2434        BDBG_ENTER(BVDC_Window_SetPanScanType);
2435        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2436
2437        /* set new value */
2438        hWindow->stNewInfo.ePanScanType = ePanScanType;
2439
2440        BDBG_LEAVE(BVDC_Window_SetPanScanType);
2441        return BERR_SUCCESS;
2442}
2443
2444
2445/***************************************************************************
2446 *
2447 */
2448BERR_Code BVDC_Window_GetPanScanType
2449        ( const BVDC_Window_Handle         hWindow,
2450          BVDC_PanScanType                *pePanScanType )
2451{
2452        BDBG_ENTER(BVDC_Window_GetPanScanType);
2453        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2454
2455        /* set new value */
2456        if(pePanScanType)
2457        {
2458                *pePanScanType = hWindow->stCurInfo.ePanScanType;
2459        }
2460
2461        BDBG_LEAVE(BVDC_Window_GetPanScanType);
2462        return BERR_SUCCESS;
2463}
2464
2465
2466/***************************************************************************
2467 *
2468 */
2469BERR_Code BVDC_Window_SetUserPanScan
2470        ( BVDC_Window_Handle               hWindow,
2471          int32_t                          lHorzPanScan,
2472          int32_t                          lVertPanScan )
2473{
2474        BDBG_ENTER(BVDC_Window_SetUserPanScan);
2475        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2476
2477        /* set new value */
2478        hWindow->stNewInfo.lUserHorzPanScan = lHorzPanScan;
2479        hWindow->stNewInfo.lUserVertPanScan = lVertPanScan;
2480
2481        BDBG_LEAVE(BVDC_Window_SetUserPanScan);
2482        return BERR_SUCCESS;
2483}
2484
2485
2486/***************************************************************************
2487 *
2488 */
2489BERR_Code BVDC_Window_GetUserPanScan
2490        ( const BVDC_Window_Handle         hWindow,
2491          int32_t                         *plHorzPanScan,
2492          int32_t                         *plVertPanScan )
2493{
2494        BDBG_ENTER(BVDC_Window_GetPanScanType);
2495        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2496
2497        if(plHorzPanScan)
2498        {
2499                *plHorzPanScan = hWindow->stCurInfo.lUserHorzPanScan;
2500        }
2501
2502        if(plVertPanScan)
2503        {
2504                *plVertPanScan = hWindow->stCurInfo.lUserVertPanScan;
2505        }
2506
2507        BDBG_LEAVE(BVDC_Window_GetPanScanType);
2508        return BERR_SUCCESS;
2509}
2510
2511/***************************************************************************
2512 *
2513 */
2514BERR_Code BVDC_Window_EnableBoxDetect
2515        ( BVDC_Window_Handle                hWindow,
2516          BVDC_Window_BoxDetectCallback_isr BoxDetectCallBack,
2517          void  *                           pvParm1,
2518          int                               iParm2,
2519          bool                              bAutoCutBlack )
2520{
2521        BERR_Code  eResult;
2522
2523        BDBG_ENTER(BVDC_Window_EnableBoxDetect);
2524        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2525
2526        BDBG_MSG(("LBox Detect might not work with extreme source clipping due to bandwidth issue"));
2527        eResult = BVDC_P_Window_EnableBoxDetect( hWindow,
2528                                                                                         BoxDetectCallBack, pvParm1, iParm2,
2529                                                                                         bAutoCutBlack );
2530
2531        BDBG_LEAVE(BVDC_Window_EnableBoxDetect);
2532        return BERR_TRACE(eResult);
2533}
2534
2535/***************************************************************************
2536 *
2537 */
2538BERR_Code BVDC_Window_DisableBoxDetect
2539        ( BVDC_Window_Handle                hWindow )
2540{
2541        BERR_Code  eResult;
2542
2543        BDBG_ENTER(BVDC_Window_DisableBoxDetect);
2544        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2545
2546        eResult = BVDC_P_Window_DisableBoxDetect( hWindow );
2547
2548        BDBG_LEAVE(BVDC_Window_DisableBoxDetect);
2549        return BERR_TRACE(eResult);
2550}
2551
2552
2553/***************************************************************************
2554 *
2555 */
2556BERR_Code BVDC_Window_SetAspectRatioMode
2557        ( BVDC_Window_Handle               hWindow,
2558          BVDC_AspectRatioMode             eAspectRatioMode )
2559{
2560        BDBG_ENTER(BVDC_Window_SetAspectRatioMode);
2561        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2562
2563        /* set new value */
2564        hWindow->stNewInfo.eAspectRatioMode = eAspectRatioMode;
2565
2566        BDBG_LEAVE(BVDC_Window_SetAspectRatioMode);
2567        return BERR_SUCCESS;
2568}
2569
2570/***************************************************************************
2571 *
2572 */
2573BERR_Code BVDC_Window_GetAspectRatioMode
2574        ( const BVDC_Window_Handle         hWindow,
2575          BVDC_AspectRatioMode            *peAspectRatioMode )
2576{
2577        BDBG_ENTER(BVDC_Window_GetAspectRatioMode);
2578        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2579
2580        if(peAspectRatioMode)
2581        {
2582                *peAspectRatioMode = hWindow->stCurInfo.eAspectRatioMode;
2583        }
2584
2585        BDBG_LEAVE(BVDC_Window_GetAspectRatioMode);
2586        return BERR_SUCCESS;
2587}
2588
2589
2590/***************************************************************************
2591 *
2592 */
2593BERR_Code BVDC_Window_SetNonLinearScl(
2594          BVDC_Window_Handle               hWindow,
2595          uint32_t                         ulNonLinearSrcWidth,
2596          uint32_t                         ulNonLinearSclOutWidth)
2597{
2598        BDBG_ENTER(BVDC_Window_SetNonLinearScl);
2599        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2600
2601        /* set new value */
2602        hWindow->stNewInfo.ulNonlinearSrcWidth = ulNonLinearSrcWidth;
2603        hWindow->stNewInfo.ulNonlinearSclOutWidth = ulNonLinearSclOutWidth;
2604
2605        BDBG_LEAVE(BVDC_Window_SetNonLinearScl);
2606        return BERR_SUCCESS;
2607}
2608
2609/***************************************************************************
2610 *
2611 */
2612BERR_Code BVDC_Window_GetNonLinearScl
2613        ( const BVDC_Window_Handle         hWindow,
2614          uint32_t                        *pulNonLinearSrcWidth,
2615          uint32_t                        *pulNonLinearSclOutWidth)
2616{
2617        BDBG_ENTER(BVDC_Window_GetHorizScale);
2618        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2619
2620        if(pulNonLinearSrcWidth)
2621        {
2622                *pulNonLinearSrcWidth = hWindow->stCurInfo.ulNonlinearSrcWidth;
2623        }
2624        if(pulNonLinearSclOutWidth)
2625        {
2626                *pulNonLinearSclOutWidth = hWindow->stCurInfo.ulNonlinearSclOutWidth;
2627        }
2628
2629        BDBG_LEAVE(BVDC_Window_GetHorizScale);
2630        return BERR_SUCCESS;
2631}
2632
2633/***************************************************************************
2634 *
2635 */
2636BERR_Code BVDC_Window_SetScaleFactorRounding
2637        ( BVDC_Window_Handle               hWindow,
2638          uint32_t                         ulHrzTolerance,
2639          uint32_t                         ulVrtTolerance )
2640{
2641        BDBG_ENTER(BVDC_Window_SetScaleFactorRounding);
2642        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2643
2644        /* set new value */
2645        hWindow->stNewInfo.ulHrzSclFctRndToler = ulHrzTolerance;
2646        hWindow->stNewInfo.ulVrtSclFctRndToler = ulVrtTolerance;
2647
2648        BDBG_LEAVE(BVDC_Window_SetScaleFactorRounding);
2649        return BERR_SUCCESS;
2650}
2651
2652/***************************************************************************
2653 *
2654 */
2655BERR_Code BVDC_Window_GetScaleFactorRounding
2656        ( BVDC_Window_Handle               hWindow,
2657          uint32_t                        *pulHrzTolerance,
2658          uint32_t                        *pulVrtTolerance )
2659{
2660        BDBG_ENTER(BVDC_Window_GetScaleFactorRounding);
2661        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2662
2663        if(pulHrzTolerance)
2664        {
2665                *pulHrzTolerance = hWindow->stCurInfo.ulHrzSclFctRndToler;
2666        }
2667        if(pulVrtTolerance)
2668        {
2669                *pulVrtTolerance = hWindow->stCurInfo.ulVrtSclFctRndToler;
2670        }
2671
2672        BDBG_LEAVE(BVDC_Window_GetScaleFactorRounding);
2673        return BERR_SUCCESS;
2674}
2675
2676
2677/***************************************************************************
2678 *
2679 */
2680BERR_Code BVDC_Window_SetPhaseAdjustMode
2681        ( BVDC_Window_Handle               hWindow,
2682          BVDC_PhaseAdjustMode             ePhaseAdjustMode )
2683{
2684        BDBG_ENTER(BVDC_Window_SetPhaseAdjustMode);
2685        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2686
2687        if(ePhaseAdjustMode > BVDC_PhaseAdjustMode_eTrackAndClamp)
2688        {
2689                return BERR_TRACE(BERR_INVALID_PARAMETER);
2690        }
2691
2692        /* set new value */
2693        hWindow->stNewInfo.ePhaseAdjustMode = ePhaseAdjustMode;
2694
2695        BDBG_LEAVE(BVDC_Window_SetPhaseAdjustMode);
2696        return BERR_SUCCESS;
2697}
2698
2699/***************************************************************************
2700 *
2701 */
2702BERR_Code BVDC_Window_GetPhaseAdjustMode
2703        ( const BVDC_Window_Handle         hWindow,
2704          BVDC_PhaseAdjustMode            *pePhaseAdjustMode )
2705{
2706        BDBG_ENTER(BVDC_Window_GetPhaseAdjustMode);
2707        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2708
2709        if(pePhaseAdjustMode)
2710        {
2711                *pePhaseAdjustMode = hWindow->stCurInfo.ePhaseAdjustMode;
2712        }
2713
2714        BDBG_LEAVE(BVDC_Window_GetPhaseAdjustMode);
2715        return BERR_SUCCESS;
2716}
2717
2718
2719/***************************************************************************
2720 *
2721 */
2722BERR_Code BVDC_Window_SetMasterFrameRate
2723        ( BVDC_Window_Handle               hWindow,
2724          bool                             bUseSrcFrameRate )
2725{
2726        BDBG_ENTER(BVDC_Window_SetMasterFrameRate);
2727        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2728
2729        /* set new value */
2730        hWindow->stNewInfo.bUseSrcFrameRate = bUseSrcFrameRate;
2731
2732        BDBG_LEAVE(BVDC_Window_SetMasterFrameRate);
2733        return BERR_SUCCESS;
2734}
2735
2736/***************************************************************************
2737 *
2738 */
2739BERR_Code BVDC_Window_GetMasterFrameRate
2740        ( const BVDC_Window_Handle         hWindow,
2741          bool                            *pbUseSrcFrameRate )
2742{
2743        BDBG_ENTER(BVDC_Window_GetMasterFrameRate);
2744        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2745
2746        if(pbUseSrcFrameRate)
2747        {
2748                *pbUseSrcFrameRate = hWindow->stCurInfo.bUseSrcFrameRate;
2749        }
2750
2751        BDBG_LEAVE(BVDC_Window_GetMasterFrameRate);
2752        return BERR_SUCCESS;
2753}
2754
2755/***************************************************************************
2756 *
2757 */
2758BERR_Code BVDC_Window_SetRgbMatching
2759        ( BVDC_Window_Handle               hWindow,
2760          bool                             bRgbMatching )
2761{
2762        BDBG_ENTER(BVDC_Window_SetRgbMatching);
2763        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2764
2765        /* set new value */
2766        hWindow->stNewInfo.bCscRgbMatching = bRgbMatching;
2767
2768        BDBG_LEAVE(BVDC_Window_SetRgbMatching);
2769        return BERR_SUCCESS;
2770}
2771
2772/***************************************************************************
2773 *
2774 */
2775BERR_Code BVDC_Window_GetRgbMatching
2776        ( const BVDC_Window_Handle         hWindow,
2777          bool                            *pbRgbMatching )
2778{
2779        BDBG_ENTER(BVDC_Window_GetRgbMatching);
2780        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2781
2782        if(pbRgbMatching)
2783        {
2784                *pbRgbMatching = hWindow->stCurInfo.bCscRgbMatching;
2785        }
2786
2787        BDBG_LEAVE(BVDC_Window_GetRgbMatching);
2788        return BERR_SUCCESS;
2789}
2790
2791/***************************************************************************
2792 *
2793 */
2794BERR_Code BVDC_Window_SetContrast
2795        ( BVDC_Window_Handle               hWindow,
2796          int16_t                          sContrast )
2797{
2798        BDBG_ENTER(BVDC_Window_SetContrast);
2799        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2800
2801        hWindow->stNewInfo.sContrast = sContrast;
2802
2803        BDBG_LEAVE(BVDC_Window_SetContrast);
2804        return BERR_SUCCESS;
2805}
2806
2807/***************************************************************************
2808 *
2809 */
2810BERR_Code BVDC_Window_GetContrast
2811        ( BVDC_Window_Handle               hWindow,
2812          int16_t                         *psContrast )
2813{
2814        BDBG_ENTER(BVDC_Window_GetContrast);
2815        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2816
2817        if(psContrast)
2818        {
2819                *psContrast = hWindow->stCurInfo.sContrast;
2820        }
2821
2822        BDBG_LEAVE(BVDC_Window_GetContrast);
2823        return BERR_SUCCESS;
2824}
2825
2826/***************************************************************************
2827 *
2828 */
2829BERR_Code BVDC_Window_SetSaturation
2830        ( BVDC_Window_Handle               hWindow,
2831          int16_t                          sSaturation )
2832{
2833        BDBG_ENTER(BVDC_Window_SetSaturation);
2834        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2835
2836        hWindow->stNewInfo.sSaturation = sSaturation;
2837
2838        BDBG_LEAVE(BVDC_Window_SetSaturation);
2839        return BERR_SUCCESS;
2840}
2841
2842/***************************************************************************
2843 *
2844 */
2845BERR_Code BVDC_Window_GetSaturation
2846        ( BVDC_Window_Handle               hWindow,
2847          int16_t                         *psSaturation )
2848{
2849        BDBG_ENTER(BVDC_Window_GetSaturation);
2850        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2851
2852        if(psSaturation)
2853        {
2854                *psSaturation = hWindow->stCurInfo.sSaturation;
2855        }
2856
2857        BDBG_LEAVE(BVDC_Window_GetSaturation);
2858        return BERR_SUCCESS;
2859}
2860
2861/***************************************************************************
2862 *
2863 */
2864BERR_Code BVDC_Window_SetHue
2865        ( BVDC_Window_Handle               hWindow,
2866          int16_t                          sHue )
2867{
2868        BDBG_ENTER(BVDC_Window_SetHue);
2869        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2870
2871        hWindow->stNewInfo.sHue = sHue;
2872
2873        BDBG_LEAVE(BVDC_Window_SetHue);
2874        return BERR_SUCCESS;
2875}
2876
2877/***************************************************************************
2878 *
2879 */
2880BERR_Code BVDC_Window_GetHue
2881        ( BVDC_Window_Handle               hWindow,
2882          int16_t                         *psHue )
2883{
2884        BDBG_ENTER(BVDC_Window_GetHue);
2885        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2886
2887        if(psHue)
2888        {
2889                *psHue = hWindow->stCurInfo.sHue;
2890        }
2891
2892        BDBG_LEAVE(BVDC_Window_GetHue);
2893        return BERR_SUCCESS;
2894}
2895
2896/***************************************************************************
2897 *
2898 */
2899BERR_Code BVDC_Window_SetBrightness
2900        ( BVDC_Window_Handle               hWindow,
2901          int16_t                          sBrightness )
2902{
2903        BDBG_ENTER(BVDC_Window_SetBrightness);
2904        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2905
2906        hWindow->stNewInfo.sBrightness = sBrightness;
2907
2908        BDBG_LEAVE(BVDC_Window_SetBrightness);
2909        return BERR_SUCCESS;
2910}
2911
2912/***************************************************************************
2913 *
2914 */
2915BERR_Code BVDC_Window_GetBrightness
2916        ( BVDC_Window_Handle               hWindow,
2917          int16_t                         *psBrightness )
2918{
2919        BDBG_ENTER(BVDC_Window_GetBrightness);
2920        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2921
2922        if(psBrightness)
2923        {
2924                *psBrightness = hWindow->stCurInfo.sBrightness;
2925        }
2926
2927        BDBG_LEAVE(BVDC_Window_GetBrightness);
2928        return BERR_SUCCESS;
2929}
2930
2931#if (BVDC_P_SUPPORT_TNT_VER == 5)            /* TNT2 HW base */
2932BERR_Code BVDC_Window_SetSharpnessConfig
2933        ( BVDC_Window_Handle               hWindow,
2934          const BVDC_SharpnessSettings    *pSharpnessSettings )
2935
2936{
2937        BERR_Code err = BERR_SUCCESS;
2938
2939        BDBG_ENTER(BVDC_Window_SetSharpnessConfig);
2940        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2941
2942        /* Only support main display's main window */
2943        if(hWindow->eId != BVDC_P_WindowId_eComp0_V0)
2944        {
2945                return BERR_TRACE(BVDC_ERR_TNT_WINDOW_NOT_SUPPORTED);
2946        }
2947
2948        if(pSharpnessSettings != NULL)
2949        {
2950                err = BVDC_P_Tnt_ValidateSharpnessSettings(pSharpnessSettings);
2951                if (err != BERR_SUCCESS)
2952                {
2953                        return err;
2954                }
2955                else
2956                {
2957                        /* set new value */
2958                        hWindow->stNewInfo.bUserSharpnessConfig = true;
2959                        hWindow->stNewInfo.stSharpnessConfig = *pSharpnessSettings;
2960
2961                        BVDC_P_Tnt_StoreSharpnessSettings(hWindow, pSharpnessSettings);
2962                }
2963        }
2964        else
2965        {
2966                hWindow->stNewInfo.bUserSharpnessConfig = false;
2967        }
2968
2969        hWindow->stNewInfo.stDirty.stBits.bTntAdjust = BVDC_P_DIRTY;
2970        hWindow->stNewInfo.sSharpness = 0;
2971
2972        BDBG_LEAVE(BVDC_Window_SetSharpnessConfig);
2973        return err;
2974
2975}
2976
2977
2978BERR_Code BVDC_Window_GetSharpnessConfig
2979        ( BVDC_Window_Handle               hWindow,
2980          BVDC_SharpnessSettings          *pSharpnessSettings )
2981{
2982        BERR_Code err = BERR_SUCCESS;
2983
2984        BDBG_ENTER(BVDC_Window_GetSharpnessConfig);
2985        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
2986        BDBG_ASSERT(pSharpnessSettings);
2987
2988        /* Only support main display's main window */
2989        if(hWindow->eId != BVDC_P_WindowId_eComp0_V0)
2990        {
2991                return BERR_TRACE(BVDC_ERR_TNT_WINDOW_NOT_SUPPORTED);
2992        }
2993
2994        if(pSharpnessSettings)
2995        {
2996                *pSharpnessSettings = hWindow->stCurInfo.stSharpnessConfig;
2997        }
2998
2999        BDBG_LEAVE(BVDC_Window_GetSharpnessConfig);
3000        return err;
3001
3002}
3003
3004#else
3005
3006/***************************************************************************
3007 *
3008 */
3009BERR_Code BVDC_Window_SetSharpnessConfig
3010        ( BVDC_Window_Handle               hWindow,
3011          const BVDC_SharpnessSettings    *pSharpnessSettings )
3012{
3013        BDBG_ENTER(BVDC_Window_SetSharpnessConfig);
3014        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3015
3016        /* Only support main display's main window */
3017        if(hWindow->eId != BVDC_P_WindowId_eComp0_V0)
3018        {
3019                return BERR_TRACE(BVDC_ERR_TNT_WINDOW_NOT_SUPPORTED);
3020        }
3021
3022        if(pSharpnessSettings != NULL)
3023        {
3024                /* set new value */
3025                hWindow->stNewInfo.bUserSharpnessConfig = true;
3026                hWindow->stNewInfo.stSharpnessConfig = *pSharpnessSettings;
3027        }
3028        else
3029        {
3030                hWindow->stNewInfo.bUserSharpnessConfig = false;
3031        }
3032
3033        hWindow->stNewInfo.stDirty.stBits.bTntAdjust = BVDC_P_DIRTY;
3034        hWindow->stNewInfo.sSharpness = 0;
3035
3036        BDBG_LEAVE(BVDC_Window_SetSharpnessConfig);
3037        return BERR_SUCCESS;
3038}
3039
3040/***************************************************************************
3041 *
3042 */
3043 BERR_Code BVDC_Window_GetSharpnessConfig
3044        ( BVDC_Window_Handle               hWindow,
3045          BVDC_SharpnessSettings          *pSharpnessSettings )
3046{
3047        BDBG_ENTER(BVDC_Window_GetSharpnessConfig);
3048        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3049
3050        if(pSharpnessSettings)
3051        {
3052                *pSharpnessSettings = hWindow->stCurInfo.stSharpnessConfig;
3053                if(!hWindow->stCurInfo.bUserSharpnessConfig)
3054                {
3055                        BKNI_EnterCriticalSection();
3056                        pSharpnessSettings->ulLumaCtrlGain = hWindow->stCurResource.hPep->ulLumaChromaGain;
3057                        pSharpnessSettings->ulChromaCtrlGain = hWindow->stCurResource.hPep->ulLumaChromaGain;
3058                        BKNI_LeaveCriticalSection();
3059                }
3060        }
3061
3062        BDBG_LEAVE(BVDC_Window_GetSharpnessConfig);
3063        return BERR_SUCCESS;
3064}
3065#endif
3066
3067/***************************************************************************
3068 *
3069 */
3070BERR_Code BVDC_Window_SetSharpness
3071        ( BVDC_Window_Handle               hWindow,
3072          bool                             bSharpnessEnable,
3073          int16_t                          sSharpness )
3074{
3075        BDBG_ENTER(BVDC_Window_SetSharpness);
3076        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3077
3078        /* Only support main display's main window */
3079        if(hWindow->eId != BVDC_P_WindowId_eComp0_V0)
3080        {
3081                return BERR_TRACE(BVDC_ERR_TNT_WINDOW_NOT_SUPPORTED);
3082        }
3083
3084        hWindow->stNewInfo.bSharpnessEnable = bSharpnessEnable;
3085        hWindow->stNewInfo.sSharpness = sSharpness;
3086
3087        BDBG_LEAVE(BVDC_Window_SetSharpness);
3088        return BERR_SUCCESS;
3089}
3090
3091/***************************************************************************
3092 *
3093 */
3094BERR_Code BVDC_Window_GetSharpness
3095        ( BVDC_Window_Handle               hWindow,
3096          bool                            *pbSharpnessEnable,
3097          int16_t                         *psSharpness )
3098{
3099        BDBG_ENTER(BVDC_Window_GetSharpness);
3100        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3101
3102        if(psSharpness)
3103        {
3104                *psSharpness = hWindow->stCurInfo.sSharpness;
3105        }
3106
3107        if(pbSharpnessEnable)
3108        {
3109                *pbSharpnessEnable = hWindow->stCurInfo.bSharpnessEnable;
3110        }
3111
3112        BDBG_LEAVE(BVDC_Window_GetSharpness);
3113        return BERR_SUCCESS;
3114}
3115
3116/***************************************************************************
3117 *
3118 */
3119BERR_Code BVDC_Window_SetColorTemp
3120        (BVDC_Window_Handle hWindow,
3121         int16_t sColorTemp)
3122{
3123        int32_t lAttenuationR;
3124        int32_t lAttenuationG;
3125        int32_t lAttenuationB;
3126
3127        BDBG_ENTER(BVDC_Window_SetColorTemp);
3128        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3129
3130        hWindow->stNewInfo.sColorTemp = sColorTemp;
3131
3132        if(BVDC_P_WIN_IS_GFX_WINDOW(hWindow->eId))
3133        {
3134                BVDC_P_CscCoeffs stCscCoeffs = BVDC_P_MAKE_GFD_CSC
3135                        ( 1.00000, 0.00000, 0.00000, 0.00000, 0.00000,
3136                          0.00000, 1.00000, 0.00000, 0.00000, 0.00000,
3137                          0.00000, 0.00000, 1.00000, 0.00000, 0.00000 );
3138
3139                BVDC_P_Csc_ColorTempToAttenuationRGB(sColorTemp,
3140                        &lAttenuationR, &lAttenuationG, &lAttenuationB, &stCscCoeffs);
3141        }
3142        else
3143        {
3144                BVDC_P_CscCoeffs stCscCoeffs = BVDC_P_MAKE_CMP_CSC
3145                        ( 1.00000, 0.00000, 0.00000, 0.00000,
3146                          0.00000, 1.00000, 0.00000, 0.00000,
3147                          0.00000, 0.00000, 1.00000, 0.00000 );
3148
3149                BVDC_P_Csc_ColorTempToAttenuationRGB(sColorTemp,
3150                        &lAttenuationR, &lAttenuationG, &lAttenuationB, &stCscCoeffs);
3151        }
3152
3153        hWindow->stNewInfo.lAttenuationR = lAttenuationR;
3154        hWindow->stNewInfo.lAttenuationG = lAttenuationG;
3155        hWindow->stNewInfo.lAttenuationB = lAttenuationB;
3156        hWindow->stNewInfo.lOffsetR = 0;
3157        hWindow->stNewInfo.lOffsetG = 0;
3158        hWindow->stNewInfo.lOffsetB = 0;
3159
3160        BDBG_LEAVE(BVDC_Window_SetColorTemp);
3161        return BERR_SUCCESS;
3162}
3163
3164/***************************************************************************
3165 *
3166 */
3167BERR_Code BVDC_Window_GetColorTemp
3168        ( BVDC_Window_Handle               hWindow,
3169          int16_t                         *psColorTemp )
3170{
3171        BDBG_ENTER(BVDC_Window_GetColorTemp);
3172        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3173
3174        if(psColorTemp)
3175        {
3176                *psColorTemp= hWindow->stCurInfo.sColorTemp;
3177        }
3178
3179        BDBG_LEAVE(BVDC_Window_GetColorTemp);
3180        return BERR_SUCCESS;
3181}
3182
3183/***************************************************************************
3184 *
3185 */
3186BERR_Code BVDC_Window_SetAttenuationRGB
3187        (BVDC_Window_Handle hWindow,
3188          int32_t   nAttentuationR,
3189          int32_t   nAttentuationG,
3190          int32_t   nAttentuationB,
3191          int32_t   nOffsetR,
3192          int32_t   nOffsetG,
3193          int32_t   nOffsetB)
3194{
3195        int32_t ulShiftBits;
3196
3197        BDBG_ENTER(BVDC_Window_SetAttenuationRGB);
3198        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3199
3200        ulShiftBits = BVDC_P_WIN_IS_GFX_WINDOW(hWindow->eId)?
3201                          BVDC_P_CSC_GFD_CX_F_BITS - 11 :
3202                          BVDC_P_CSC_CMP_CX_F_BITS - 11;
3203
3204        hWindow->stNewInfo.lAttenuationR = nAttentuationR << ulShiftBits;
3205        hWindow->stNewInfo.lAttenuationG = nAttentuationG << ulShiftBits;
3206        hWindow->stNewInfo.lAttenuationB = nAttentuationB << ulShiftBits;
3207        hWindow->stNewInfo.lOffsetR      = nOffsetR       << ulShiftBits;
3208        hWindow->stNewInfo.lOffsetG      = nOffsetG       << ulShiftBits;
3209        hWindow->stNewInfo.lOffsetB      = nOffsetB       << ulShiftBits;
3210
3211        BDBG_LEAVE(BVDC_Window_SetAttenuationRGB);
3212
3213        return BERR_SUCCESS;
3214}
3215
3216/***************************************************************************
3217 *
3218 */
3219BERR_Code BVDC_Window_GetAttenuationRGB
3220        ( BVDC_Window_Handle               hWindow,
3221          int32_t                         *plAttenuationR,
3222          int32_t                         *plAttenuationG,
3223          int32_t                         *plAttenuationB,
3224          int32_t                         *plOffsetR,
3225          int32_t                         *plOffsetG,
3226          int32_t                         *plOffsetB )
3227{
3228        int32_t ulShiftBits;
3229
3230        BDBG_ENTER(BVDC_Window_GetAttenuationRGB);
3231        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3232
3233        ulShiftBits = BVDC_P_WIN_IS_GFX_WINDOW(hWindow->eId)?
3234                      BVDC_P_CSC_GFD_CX_F_BITS - 11 :
3235                      BVDC_P_CSC_CMP_CX_F_BITS - 11;
3236
3237        (*plAttenuationR) = hWindow->stCurInfo.lAttenuationR >> ulShiftBits;
3238        (*plAttenuationG) = hWindow->stCurInfo.lAttenuationG >> ulShiftBits;
3239        (*plAttenuationB) = hWindow->stCurInfo.lAttenuationB >> ulShiftBits;
3240        (*plOffsetR)      = hWindow->stCurInfo.lOffsetR      >> ulShiftBits;
3241        (*plOffsetG)      = hWindow->stCurInfo.lOffsetG      >> ulShiftBits;
3242        (*plOffsetB)      = hWindow->stCurInfo.lOffsetB      >> ulShiftBits;
3243
3244        BDBG_LEAVE(BVDC_Window_GetAttenuationRGB);
3245        return BERR_SUCCESS;
3246}
3247
3248/***************************************************************************
3249 *
3250 */
3251BERR_Code BVDC_Window_SetAutoFlesh
3252        ( BVDC_Window_Handle               hWindow,
3253          uint32_t                         ulFleshtone )
3254{
3255        BDBG_ENTER(BVDC_Window_SetAutoFlesh);
3256        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3257
3258        /* only support main display's main window */
3259        if(hWindow->eId != BVDC_P_WindowId_eComp0_V0)
3260        {
3261                return BERR_TRACE(BVDC_ERR_PEP_WINDOW_NOT_SUPPORT);
3262        }
3263        if(ulFleshtone > BVDC_P_PEP_MAX_CAB_SETTING_GRANUALITY)
3264        {
3265                return BERR_TRACE(BVDC_ERR_PEP_INVALID_PARAMETER);
3266        }
3267
3268        hWindow->stNewInfo.ulFleshtone = ulFleshtone;
3269
3270        BDBG_LEAVE(BVDC_Window_SetAutoFlesh);
3271        return BERR_SUCCESS;
3272}
3273
3274/***************************************************************************
3275 *
3276 */
3277BERR_Code BVDC_Window_GetAutoFlesh
3278        ( const BVDC_Window_Handle          hWindow,
3279          uint32_t                         *pulFleshtone )
3280{
3281        BDBG_ENTER(BVDC_Window_GetAutoFlesh);
3282        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3283
3284        if(pulFleshtone)
3285        {
3286                *pulFleshtone = hWindow->stCurInfo.ulFleshtone;
3287        }
3288
3289        BDBG_LEAVE(BVDC_Window_GetAutoFlesh);
3290        return BERR_SUCCESS;
3291}
3292
3293/***************************************************************************
3294 *
3295 */
3296BERR_Code BVDC_Window_SetGreenBoost
3297        ( BVDC_Window_Handle               hWindow,
3298          uint32_t                         ulGreenBoost )
3299{
3300        BDBG_ENTER(BVDC_Window_SetGreenBoost);
3301        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3302
3303        /* only support main display's main window */
3304        if(hWindow->eId != BVDC_P_WindowId_eComp0_V0)
3305        {
3306                return BERR_TRACE(BVDC_ERR_PEP_WINDOW_NOT_SUPPORT);
3307        }
3308        if(ulGreenBoost > BVDC_P_PEP_MAX_CAB_SETTING_GRANUALITY)
3309        {
3310                return BERR_TRACE(BVDC_ERR_PEP_INVALID_PARAMETER);
3311        }
3312
3313        hWindow->stNewInfo.ulGreenBoost = ulGreenBoost;
3314
3315        BDBG_LEAVE(BVDC_Window_SetGreenBoost);
3316        return BERR_SUCCESS;
3317}
3318
3319/***************************************************************************
3320 *
3321 */
3322BERR_Code BVDC_Window_GetGreenBoost
3323        ( const BVDC_Window_Handle          hWindow,
3324          uint32_t                         *pulGreenBoost )
3325{
3326        BDBG_ENTER(BVDC_Window_GetGreenBoost);
3327        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3328
3329        if(pulGreenBoost)
3330        {
3331                *pulGreenBoost= hWindow->stCurInfo.ulGreenBoost;
3332        }
3333
3334        BDBG_LEAVE(BVDC_Window_GetGreenBoost);
3335        return BERR_SUCCESS;
3336}
3337
3338/***************************************************************************
3339 *
3340 */
3341BERR_Code BVDC_Window_SetBlueBoost
3342        ( BVDC_Window_Handle               hWindow,
3343          uint32_t                         ulBlueBoost )
3344{
3345        BDBG_ENTER(BVDC_Window_SetBlueBoost);
3346        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3347
3348        /* only support main display's main window */
3349        if(hWindow->eId != BVDC_P_WindowId_eComp0_V0)
3350        {
3351                return BERR_TRACE(BVDC_ERR_PEP_WINDOW_NOT_SUPPORT);
3352        }
3353        if(ulBlueBoost > BVDC_P_PEP_MAX_CAB_SETTING_GRANUALITY)
3354        {
3355                return BERR_TRACE(BVDC_ERR_PEP_INVALID_PARAMETER);
3356        }
3357
3358        hWindow->stNewInfo.ulBlueBoost = ulBlueBoost;
3359
3360        BDBG_LEAVE(BVDC_Window_SetBlueBoost);
3361        return BERR_SUCCESS;
3362}
3363
3364/***************************************************************************
3365 *
3366 */
3367BERR_Code BVDC_Window_GetBlueBoost
3368        ( const BVDC_Window_Handle          hWindow,
3369          uint32_t                         *pulBlueBoost )
3370{
3371        BDBG_ENTER(BVDC_Window_GetBlueBoost);
3372        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3373
3374        if(pulBlueBoost)
3375        {
3376                *pulBlueBoost = hWindow->stCurInfo.ulBlueBoost;
3377        }
3378
3379        BDBG_LEAVE(BVDC_Window_GetBlueBoost);
3380        return BERR_SUCCESS;
3381}
3382
3383/***************************************************************************
3384 *
3385 */
3386BERR_Code BVDC_Window_SetCmsControl
3387        ( const BVDC_Window_Handle          hWindow,
3388          const BVDC_ColorBar              *pSaturationGain,
3389          const BVDC_ColorBar              *pHueGain )
3390{
3391        BDBG_ENTER(BVDC_Window_SetCmsControl);
3392        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3393
3394        /* only support main display's main window */
3395        if(hWindow->eId != BVDC_P_WindowId_eComp0_V0)
3396        {
3397                return BERR_TRACE(BVDC_ERR_PEP_WINDOW_NOT_SUPPORT);
3398        }
3399        if(pSaturationGain &&
3400           !BVDC_P_PEP_CMS_SAT_WITHIN_RANGE(pSaturationGain))
3401        {
3402                return BERR_TRACE(BVDC_ERR_PEP_INVALID_PARAMETER);
3403        }
3404        if(pHueGain &&
3405           !BVDC_P_PEP_CMS_HUE_WITHIN_RANGE(pHueGain))
3406        {
3407                return BERR_TRACE(BVDC_ERR_PEP_INVALID_PARAMETER);
3408        }
3409
3410        if(pSaturationGain)
3411        {
3412                hWindow->stNewInfo.stSatGain = *pSaturationGain;
3413        }
3414        if(pHueGain)
3415        {
3416                hWindow->stNewInfo.stHueGain = *pHueGain;
3417        }
3418
3419        BDBG_LEAVE(BVDC_Window_SetCmsControl);
3420        return BERR_SUCCESS;
3421}
3422
3423/***************************************************************************
3424 *
3425 */
3426BERR_Code BVDC_Window_GetCmsControl
3427        ( const BVDC_Window_Handle          hWindow,
3428          BVDC_ColorBar                    *pSaturationGain,
3429          BVDC_ColorBar                    *pHueGain )
3430{
3431        BDBG_ENTER(BVDC_Window_GetCmsControl);
3432        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3433
3434        if(pSaturationGain)
3435        {
3436                *pSaturationGain = hWindow->stCurInfo.stSatGain;
3437        }
3438
3439        if(pHueGain)
3440        {
3441                *pHueGain = hWindow->stCurInfo.stHueGain;
3442        }
3443
3444        BDBG_LEAVE(BVDC_Window_GetCmsControl);
3445        return BERR_SUCCESS;
3446}
3447
3448/***************************************************************************
3449 *
3450 */
3451BERR_Code BVDC_Window_EnableContrastStretch
3452        ( BVDC_Window_Handle               hWindow,
3453          bool                             bEnable )
3454{
3455        BDBG_ENTER(BVDC_Window_EnableContrastStretch);
3456        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3457
3458        /* only support main display's main window */
3459        if(hWindow->eId != BVDC_P_WindowId_eComp0_V0)
3460        {
3461                return BERR_TRACE(BVDC_ERR_PEP_WINDOW_NOT_SUPPORT);
3462        }
3463
3464        hWindow->stNewInfo.bContrastStretch   = bEnable;
3465
3466        BDBG_LEAVE(BVDC_Window_SetContrastStretch);
3467        return BERR_SUCCESS;
3468}
3469
3470/***************************************************************************
3471 *
3472 */
3473BERR_Code BVDC_Window_SetContrastStretch
3474        ( BVDC_Window_Handle               hWindow,
3475          const BVDC_ContrastStretch      *pContrastStretch )
3476{
3477        BDBG_ENTER(BVDC_Window_SetContrastStretch);
3478        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3479
3480        /* only support main display's main window */
3481        if(hWindow->eId != BVDC_P_WindowId_eComp0_V0)
3482        {
3483                return BERR_TRACE(BVDC_ERR_PEP_WINDOW_NOT_SUPPORT);
3484        }
3485
3486        /*
3487        * Validating user data:
3488        * - All values in the table should be 0-1023.
3489        * - The first column should start at 64 or less, and finish at 940 or more,
3490        *   and should always be increasing (avoids the zero problem we have found here).
3491        * - The values along each row (excluding the first column) should always be increasing.
3492        * - The values in the IRE table should always be increasing, with increments
3493        *   of at least 16 between each entry.
3494        */
3495        if(pContrastStretch && pContrastStretch->aulDcTable1[0] != 0)
3496        {
3497                uint32_t i, j = 0;
3498                for(i = 0; i < BVDC_DC_TABLE_ROWS * BVDC_DC_TABLE_COLS; i++)
3499                {
3500                        if(pContrastStretch->aulDcTable1[i] > BVDC_P_PEP_MAX_LUMA_VALUE ||
3501                                (pContrastStretch->bInterpolateTables &&
3502                                pContrastStretch->aulDcTable2[i] > BVDC_P_PEP_MAX_LUMA_VALUE))
3503                        {
3504                                BDBG_MSG(("No value in the table should be greater than %d", BVDC_P_PEP_MAX_LUMA_VALUE));
3505                                BDBG_MSG(("aulDcTable1[%d] = %d, bInterpolateTables = %d, aulDcTable2[%d] = %d",
3506                                        i, pContrastStretch->aulDcTable1[i], pContrastStretch->bInterpolateTables,
3507                                        i, pContrastStretch->aulDcTable2[i]));
3508                                return BERR_TRACE(BVDC_ERR_PEP_INVALID_PARAMETER);
3509                        }
3510
3511                        if(j == 1 &&
3512                                (pContrastStretch->aulDcTable1[i] > BVDC_P_PEP_BLACK_LUMA_VALUE ||
3513                                (pContrastStretch->bInterpolateTables &&
3514                                pContrastStretch->aulDcTable2[i] > BVDC_P_PEP_BLACK_LUMA_VALUE)))
3515                        {
3516                                BDBG_MSG(("The first point on each curve should be %d or less (black level)", BVDC_P_PEP_BLACK_LUMA_VALUE));
3517                                BDBG_MSG(("aulDcTable1[%d] = %d, bInterpolateTables = %d, aulDcTable2[%d] = %d",
3518                                        i, pContrastStretch->aulDcTable1[i], pContrastStretch->bInterpolateTables,
3519                                        i, pContrastStretch->aulDcTable2[i]));
3520                                return BERR_TRACE(BVDC_ERR_PEP_INVALID_PARAMETER);
3521                        }
3522
3523                        if(j > 0 && j < (BVDC_DC_TABLE_COLS - 1) &&
3524                                (i < (BVDC_DC_TABLE_ROWS * BVDC_DC_TABLE_COLS - 1)) &&
3525                                (pContrastStretch->aulDcTable1[i] > pContrastStretch->aulDcTable1[i + 1] ||
3526                                (pContrastStretch->bInterpolateTables &&
3527                                pContrastStretch->aulDcTable2[i] > pContrastStretch->aulDcTable2[i + 1])))
3528                        {
3529                                BDBG_MSG(("Each point on a curve should be greater than or equal to the previous point on the curve (monotonically increasing along the curve)"));
3530                                BDBG_MSG(("aulDcTable1[%d] = %d, aulDcTable1[%d] = %d, bInterpolateTables = %d, aulDcTable2[%d] = %d, aulDcTable2[%d] = %d",
3531                                        i, pContrastStretch->aulDcTable1[i], i+1, pContrastStretch->aulDcTable1[i+1],
3532                                        pContrastStretch->bInterpolateTables,
3533                                        i, pContrastStretch->aulDcTable2[i], i+1, pContrastStretch->aulDcTable2[i + 1]));
3534                                return BERR_TRACE(BVDC_ERR_PEP_INVALID_PARAMETER);
3535                        }
3536
3537                        j++;
3538                        if(j == BVDC_DC_TABLE_COLS)
3539                        {
3540                                if(pContrastStretch->aulDcTable1[i] < BVDC_P_PEP_WHITE_LUMA_VALUE ||
3541                                        (pContrastStretch->bInterpolateTables &&
3542                                        pContrastStretch->aulDcTable2[i] < BVDC_P_PEP_WHITE_LUMA_VALUE))
3543                                {
3544                                        BDBG_MSG(("The last point on each curve should be %d or more (white level)", BVDC_P_PEP_WHITE_LUMA_VALUE));
3545                                        BDBG_MSG(("aulDcTable1[%d] = %d, bInterpolateTables = %d, aulDcTable2[%d] = %d",
3546                                                i, pContrastStretch->aulDcTable1[i], pContrastStretch->bInterpolateTables,
3547                                                i, pContrastStretch->aulDcTable2[i]));
3548                                        return BERR_TRACE(BVDC_ERR_PEP_INVALID_PARAMETER);
3549                                }
3550                                j = 0;
3551                        }
3552                }
3553
3554                for(i = 1; i < BVDC_DC_TABLE_COLS - 1; i++)
3555                {
3556                        if((pContrastStretch->alIreTable[i] - pContrastStretch->alIreTable[i - 1]) < 16)
3557                        {
3558                                BDBG_MSG(("Steps between values in the IRE table must be at least 16"));
3559                                BDBG_MSG(("alIreTable[%d] = %d, alIreTable[%d] = %d",
3560                                        i, pContrastStretch->alIreTable[i], i - 1, pContrastStretch->alIreTable[i - 1]));
3561                                return BERR_TRACE(BVDC_ERR_PEP_INVALID_PARAMETER);
3562                        }
3563                }
3564        }
3565
3566        if(pContrastStretch)
3567        {
3568                hWindow->stNewInfo.stContrastStretch = *pContrastStretch;
3569        }
3570
3571        hWindow->stNewInfo.stDirty.stBits.bLabAdjust = BVDC_P_DIRTY;
3572
3573        BDBG_LEAVE(BVDC_Window_SetContrastStretch);
3574        return BERR_SUCCESS;
3575}
3576
3577/***************************************************************************
3578 *
3579 */
3580BERR_Code BVDC_Window_GetContrastStretch
3581        ( const BVDC_Window_Handle          hWindow,
3582          BVDC_ContrastStretch             *pContrastStretch )
3583{
3584        BDBG_ENTER(BVDC_Window_GetContrastStretch);
3585        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3586
3587        if(pContrastStretch)
3588        {
3589                *pContrastStretch = hWindow->stCurInfo.stContrastStretch;
3590        }
3591
3592        BDBG_LEAVE(BVDC_Window_GetContrastStretch);
3593        return BERR_SUCCESS;
3594}
3595
3596/***************************************************************************
3597 *
3598 */
3599BERR_Code BVDC_Window_SetBlueStretch
3600        ( BVDC_Window_Handle               hWindow,
3601          const BVDC_BlueStretch          *pBlueStretch )
3602{
3603        BDBG_ENTER(BVDC_Window_SetBlueStretch);
3604        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3605
3606        /* only support main display's main window */
3607        if(hWindow->eId != BVDC_P_WindowId_eComp0_V0)
3608        {
3609                return BERR_TRACE(BVDC_ERR_PEP_WINDOW_NOT_SUPPORT);
3610        }
3611
3612        if(pBlueStretch && BVDC_P_SUPPORT_PEP_VER == BVDC_P_SUPPORT_PEP_VER_3)
3613        {
3614                hWindow->stNewInfo.stBlueStretch = *pBlueStretch;
3615                hWindow->stNewInfo.bBlueStretch = true;
3616        }
3617        else
3618        {
3619                hWindow->stNewInfo.bBlueStretch = false;
3620        }
3621
3622        BDBG_LEAVE(BVDC_Window_SetBlueStretch);
3623        return BERR_SUCCESS;
3624}
3625
3626/***************************************************************************
3627 *
3628 */
3629BERR_Code BVDC_Window_GetBlueStretch
3630        ( const BVDC_Window_Handle          hWindow,
3631          BVDC_BlueStretch                 *pBlueStretch )
3632{
3633        BDBG_ENTER(BVDC_Window_GetBlueStretch);
3634        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3635
3636        if(pBlueStretch)
3637        {
3638                *pBlueStretch = hWindow->stCurInfo.stBlueStretch;
3639        }
3640
3641        BDBG_LEAVE(BVDC_Window_GetBlueStretch);
3642        return BERR_SUCCESS;
3643}
3644
3645/***************************************************************************
3646 *
3647 */
3648BERR_Code BVDC_Window_SetSplitScreenMode
3649        ( BVDC_Window_Handle                      hWindow,
3650          const BVDC_Window_SplitScreenSettings  *pSplitScreen )
3651{
3652        BVDC_Window_SplitScreenSettings *pSetting;
3653
3654        BDBG_ENTER(BVDC_Window_SetSplitScreenMode);
3655        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3656        pSetting = &hWindow->stNewInfo.stSplitScreenSetting;
3657
3658#if (BCHP_CHIP == 7400) && (BCHP_VER >= BCHP_VER_B0)
3659        if((pSplitScreen->eHue             != BVDC_SplitScreenMode_eDisable ||
3660            pSplitScreen->eContrast        != BVDC_SplitScreenMode_eDisable ||
3661            pSplitScreen->eBrightness      != BVDC_SplitScreenMode_eDisable ||
3662            pSplitScreen->eColorTemp       != BVDC_SplitScreenMode_eDisable) &&
3663           (hWindow->eId != BVDC_P_WindowId_eComp0_V0 &&
3664            hWindow->eId != BVDC_P_WindowId_eComp1_V0 &&
3665            hWindow->eId != BVDC_P_WindowId_eComp2_V0))
3666#else
3667        if((pSplitScreen->eHue             != BVDC_SplitScreenMode_eDisable ||
3668            pSplitScreen->eContrast        != BVDC_SplitScreenMode_eDisable ||
3669            pSplitScreen->eBrightness      != BVDC_SplitScreenMode_eDisable ||
3670            pSplitScreen->eColorTemp       != BVDC_SplitScreenMode_eDisable) &&
3671           (hWindow->eId != BVDC_P_WindowId_eComp0_V0))
3672#endif
3673        {
3674                return BERR_TRACE(BVDC_ERR_PEP_WINDOW_NOT_SUPPORT);
3675        }
3676
3677        if((pSplitScreen->eAutoFlesh       != BVDC_SplitScreenMode_eDisable ||
3678            pSplitScreen->eSharpness       != BVDC_SplitScreenMode_eDisable ||
3679            pSplitScreen->eBlueBoost       != BVDC_SplitScreenMode_eDisable ||
3680            pSplitScreen->eGreenBoost      != BVDC_SplitScreenMode_eDisable ||
3681            pSplitScreen->eCms             != BVDC_SplitScreenMode_eDisable ||
3682            pSplitScreen->eContrastStretch != BVDC_SplitScreenMode_eDisable ||
3683            pSplitScreen->eBlueStretch     != BVDC_SplitScreenMode_eDisable) &&
3684           (hWindow->eId != BVDC_P_WindowId_eComp0_V0))
3685        {
3686                return BERR_TRACE(BVDC_ERR_PEP_WINDOW_NOT_SUPPORT);
3687        }
3688
3689        /* Since Auto Flesh, Green Boost and Blue Boost are controlled */
3690        /* by CAB, their setting can't be different */
3691        if((pSplitScreen->eAutoFlesh != pSplitScreen->eBlueBoost)  ||
3692           (pSplitScreen->eAutoFlesh != pSplitScreen->eGreenBoost) ||
3693           (pSplitScreen->eBlueBoost != pSplitScreen->eGreenBoost))
3694        {
3695                return BERR_TRACE(BERR_INVALID_PARAMETER);
3696        }
3697
3698#if (BVDC_P_SUPPORT_PEP_VER == BVDC_P_SUPPORT_PEP_VER_3)
3699        /* Since contrast stretch and blue stretch are controlled by LAB, */
3700        /* their setting can't be different */
3701        if(pSplitScreen->eContrastStretch != pSplitScreen->eBlueStretch)
3702        {
3703                return BERR_TRACE(BERR_INVALID_PARAMETER);
3704        }
3705#endif
3706
3707        /* User can select which features of the display (hue, brightness, contrast,  */
3708        /* or colortemp) to apply to the split screen demo mode but they have */
3709        /* to be applied to the same side of the screen */
3710        if(pSplitScreen->eHue != BVDC_SplitScreenMode_eDisable &&
3711           ((pSplitScreen->eBrightness != BVDC_SplitScreenMode_eDisable &&
3712             pSplitScreen->eBrightness != pSplitScreen->eHue) ||
3713            (pSplitScreen->eContrast != BVDC_SplitScreenMode_eDisable &&
3714             pSplitScreen->eContrast != pSplitScreen->eHue) ||
3715            (pSplitScreen->eColorTemp != BVDC_SplitScreenMode_eDisable &&
3716             pSplitScreen->eColorTemp != pSplitScreen->eHue)))
3717        {
3718                BDBG_ERR(("Hue=%d, Brightness=%d, Contrast=%d, ColorTemp=%d",
3719                        pSplitScreen->eHue, pSplitScreen->eBrightness, pSplitScreen->eContrast, pSplitScreen->eColorTemp));
3720                return BERR_TRACE(BERR_INVALID_PARAMETER);
3721        }
3722        if(pSplitScreen->eBrightness != BVDC_SplitScreenMode_eDisable &&
3723           ((pSplitScreen->eHue != BVDC_SplitScreenMode_eDisable &&
3724             pSplitScreen->eHue != pSplitScreen->eBrightness) ||
3725            (pSplitScreen->eContrast != BVDC_SplitScreenMode_eDisable &&
3726             pSplitScreen->eContrast != pSplitScreen->eBrightness) ||
3727                (pSplitScreen->eColorTemp != BVDC_SplitScreenMode_eDisable &&
3728             pSplitScreen->eColorTemp != pSplitScreen->eBrightness)))
3729        {
3730                BDBG_ERR(("Brightness=%d, Hue=%d, Contrast=%d, ColorTemp=%d",
3731                        pSplitScreen->eBrightness, pSplitScreen->eHue, pSplitScreen->eContrast, pSplitScreen->eColorTemp));
3732                return BERR_TRACE(BERR_INVALID_PARAMETER);
3733        }
3734        if(pSplitScreen->eContrast != BVDC_SplitScreenMode_eDisable &&
3735           ((pSplitScreen->eHue != BVDC_SplitScreenMode_eDisable &&
3736             pSplitScreen->eHue != pSplitScreen->eContrast) ||
3737            (pSplitScreen->eBrightness != BVDC_SplitScreenMode_eDisable &&
3738             pSplitScreen->eBrightness != pSplitScreen->eContrast) ||
3739            (pSplitScreen->eColorTemp != BVDC_SplitScreenMode_eDisable &&
3740             pSplitScreen->eColorTemp != pSplitScreen->eContrast)))
3741        {
3742                BDBG_ERR(("Contrast=%d, Hue=%d, Brightness=%d, ColorTemp=%d",
3743                        pSplitScreen->eContrast, pSplitScreen->eHue, pSplitScreen->eBrightness, pSplitScreen->eColorTemp));
3744                return BERR_TRACE(BERR_INVALID_PARAMETER);
3745        }
3746        if(pSplitScreen->eColorTemp != BVDC_SplitScreenMode_eDisable &&
3747           ((pSplitScreen->eHue != BVDC_SplitScreenMode_eDisable &&
3748             pSplitScreen->eHue != pSplitScreen->eColorTemp) ||
3749            (pSplitScreen->eBrightness != BVDC_SplitScreenMode_eDisable &&
3750             pSplitScreen->eBrightness != pSplitScreen->eColorTemp) ||
3751            (pSplitScreen->eContrast != BVDC_SplitScreenMode_eDisable &&
3752             pSplitScreen->eContrast != pSplitScreen->eColorTemp)))
3753        {
3754                BDBG_ERR(("ColorTemp=%d, Hue=%d, Brightness=%d, Contrast=%d",
3755                        pSplitScreen->eColorTemp, pSplitScreen->eContrast, pSplitScreen->eHue, pSplitScreen->eBrightness));
3756                return BERR_TRACE(BERR_INVALID_PARAMETER);
3757        }
3758
3759        if(pSplitScreen->eCm3d != BVDC_SplitScreenMode_eDisable &&
3760           (pSplitScreen->eCms != BVDC_SplitScreenMode_eDisable ||
3761            pSplitScreen->eAutoFlesh != BVDC_SplitScreenMode_eDisable ||
3762            pSplitScreen->eBlueBoost != BVDC_SplitScreenMode_eDisable ||
3763            pSplitScreen->eGreenBoost != BVDC_SplitScreenMode_eDisable ||
3764            pSplitScreen->eBlueStretch != BVDC_SplitScreenMode_eDisable))
3765        {
3766                BDBG_ERR(("Cms, AutoFlesh, BlueBoost, GreenBoost, and BlueStretch cannot be enabled if CM3D is enabled."));
3767                return BERR_TRACE(BERR_INVALID_PARAMETER);
3768        }
3769
3770        if(pSplitScreen->eCm3d != BVDC_SplitScreenMode_eDisable &&
3771           pSplitScreen->eContrastStretch != BVDC_SplitScreenMode_eDisable &&
3772           pSplitScreen->eCm3d != pSplitScreen->eContrastStretch)
3773        {
3774                BDBG_ERR(("Demo setting for CM3D and dynamic contrast need to be same when enabled."));
3775                return BERR_TRACE(BERR_INVALID_PARAMETER);
3776        }
3777
3778        /* Indicate require copy of new bits */
3779        if((pSetting->eDeJagging != pSplitScreen->eDeJagging) ||
3780           (pSetting->eDeRinging != pSplitScreen->eDeRinging))
3781        {
3782                hWindow->stNewInfo.stDirty.stBits.bMiscCtrl = BVDC_P_DIRTY;
3783        }
3784
3785        *pSetting = *pSplitScreen;
3786
3787        BDBG_LEAVE(BVDC_Window_SetSplitScreenMode);
3788        return BERR_SUCCESS;
3789}
3790
3791/***************************************************************************
3792 *
3793 */
3794BERR_Code BVDC_Window_GetSplitScreenMode
3795        ( const BVDC_Window_Handle          hWindow,
3796          BVDC_Window_SplitScreenSettings  *pSplitScreen )
3797{
3798        BDBG_ENTER(BVDC_Window_GetSplitScreenMode);
3799        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3800
3801        if(pSplitScreen)
3802        {
3803                *pSplitScreen = hWindow->stCurInfo.stSplitScreenSetting;
3804        }
3805
3806        BDBG_LEAVE(BVDC_Window_GetSplitScreenMode);
3807        return BERR_SUCCESS;
3808}
3809
3810/***************************************************************************
3811 *
3812 */
3813BERR_Code BVDC_Window_SetForceCapture
3814        ( BVDC_Window_Handle               hWindow,
3815          bool                             bForceCapture )
3816{
3817        BDBG_ENTER(BVDC_Window_SetForceCapture);
3818        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3819
3820        hWindow->stNewInfo.bForceCapture = bForceCapture;
3821
3822        BDBG_LEAVE(BVDC_Window_SetForceCapture);
3823        return BERR_SUCCESS;
3824}
3825
3826/***************************************************************************
3827 *
3828 */
3829BERR_Code BVDC_Window_GetForceCapture
3830        ( const BVDC_Window_Handle          hWindow,
3831          bool                             *pbForceCapture )
3832{
3833        BDBG_ENTER(BVDC_Window_GetForceCapture);
3834        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3835
3836        if(pbForceCapture)
3837        {
3838                *pbForceCapture = hWindow->stCurInfo.bForceCapture;
3839        }
3840
3841        BDBG_LEAVE(BVDC_Window_GetForceCapture);
3842        return BERR_SUCCESS;
3843}
3844
3845/***************************************************************************
3846 *
3847 */
3848BERR_Code BVDC_Window_GetMaxDelay
3849        ( const BVDC_Window_Handle         hWindow,
3850          unsigned int                    *puiMaxVsyncDelay )
3851{
3852        BDBG_ENTER(BVDC_Window_GetMaxDelay);
3853        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3854
3855        /* Base on if this window has deinterlacer, and/or capture. */
3856        if(puiMaxVsyncDelay)
3857        {
3858                *puiMaxVsyncDelay  = BVDC_P_LIP_SYNC_VEC_DELAY;
3859                *puiMaxVsyncDelay += (hWindow->pResource->bRequirePlayback)
3860                        ? BVDC_P_LIP_SYNC_CAP_PLK_SLIP_DELAY : 0;
3861                *puiMaxVsyncDelay += (hWindow->pResourceFeature->ulMad != BVDC_P_Able_eInvalid)
3862                        ? BVDC_P_LIP_SYNC_DEINTERLACED_DELAY : 0;
3863        }
3864
3865        BDBG_LEAVE(BVDC_Window_GetMaxDelay);
3866        return BERR_SUCCESS;
3867}
3868
3869/***************************************************************************
3870 *
3871 */
3872BERR_Code BVDC_Window_SetDelayOffset
3873        ( BVDC_Window_Handle               hWindow,
3874          unsigned int                     uiVsyncDelayOffset )
3875{
3876        BDBG_ENTER(BVDC_Window_SetDelayOffset);
3877        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3878
3879        hWindow->stNewInfo.uiVsyncDelayOffset = uiVsyncDelayOffset;
3880
3881        BDBG_LEAVE(BVDC_Window_SetDelayOffset);
3882        return BERR_SUCCESS;
3883}
3884
3885/***************************************************************************
3886 *
3887 */
3888BERR_Code BVDC_Window_GetDelayOffset
3889        ( const BVDC_Window_Handle         hWindow,
3890          unsigned int                    *puiVsyncDelayOffset )
3891{
3892        BDBG_ENTER(BVDC_Window_GetDelayOffset);
3893        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3894
3895        if( puiVsyncDelayOffset )
3896        {
3897                *puiVsyncDelayOffset = hWindow->stCurInfo.uiVsyncDelayOffset;
3898        }
3899
3900        BDBG_LEAVE(BVDC_Window_GetDelayOffset);
3901        return BERR_SUCCESS;
3902}
3903
3904
3905/***************************************************************************
3906 *
3907 */
3908BERR_Code BVDC_Window_SetMosaicConfiguration
3909        ( BVDC_Window_Handle               hWindow,
3910          bool                             bEnable,
3911          BVDC_MosaicConfiguration        *pstSettings )
3912{
3913#if BVDC_P_SUPPORT_MOSAIC_MODE
3914        BDBG_ENTER(BVDC_Window_SetMosaicConfiguration);
3915        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3916
3917        /* preliminary error checking */
3918        if(bEnable && (!pstSettings || !hWindow->bClearRectSupport))
3919        {
3920                if(!pstSettings)
3921                {
3922                        BDBG_ERR(("Please provide Moasic configuration settings!"));
3923                }
3924                if(!hWindow->bClearRectSupport)
3925                {
3926                        BDBG_ERR(("This window[%d] does not support Mosaic Mode!", hWindow->eId));
3927                }
3928                return BERR_TRACE(BVDC_ERR_INVALID_MOSAIC_MODE);
3929        }
3930
3931        hWindow->stNewInfo.bClearRect = bEnable;
3932        if(bEnable)
3933        {
3934                uint32_t ulARGB;
3935
3936                /* 8-bit settings for now */
3937                if((pstSettings->ulClearRectAlpha > 255) ||
3938                   (pstSettings->bClearRectByMaskColor &&
3939                    (pstSettings->ulMaskColorBlue  |
3940                     pstSettings->ulMaskColorGreen |
3941                     pstSettings->ulMaskColorRed) > 255))
3942                {
3943                        return BERR_TRACE(BVDC_ERR_INVALID_MOSAIC_MODE);
3944                }
3945
3946                if(!BVDC_P_SRC_IS_MPEG(hWindow->stNewInfo.hSource->eId) &&
3947                   pstSettings->bVideoInMosaics)
3948                {
3949                        BDBG_ERR(("Video in Mosaic Mode must be MPEG window!"));
3950                        return(BVDC_ERR_INVALID_MOSAIC_MODE);
3951                }
3952
3953                hWindow->stNewInfo.bMosaicMode   = pstSettings->bVideoInMosaics;
3954                hWindow->stNewInfo.bClearRectByMaskColor = pstSettings->bClearRectByMaskColor;
3955                hWindow->stNewInfo.ulClearRectAlpha = pstSettings->ulClearRectAlpha;
3956                ulARGB = BPXL_MAKE_PIXEL(BPXL_eA8_R8_G8_B8,
3957                        0x00, pstSettings->ulMaskColorRed, pstSettings->ulMaskColorGreen,
3958                        pstSettings->ulMaskColorBlue);
3959                BPXL_ConvertPixel_RGBtoYCbCr(BPXL_eA8_Y8_Cb8_Cr8, BPXL_eA8_R8_G8_B8,
3960                        ulARGB, (unsigned int*)&hWindow->stNewInfo.ulMaskColorYCrCb);
3961        }
3962        else
3963        {
3964                hWindow->stNewInfo.bMosaicMode   = false;
3965        }
3966        BDBG_LEAVE(BVDC_Window_SetMosaicConfiguration);
3967#else
3968        BDBG_ERR(("This chipset doesn't support Mosaic Mode!"));
3969        BSTD_UNUSED(hWindow);
3970        BSTD_UNUSED(bEnable);
3971        BSTD_UNUSED(pstSettings);
3972#endif
3973        return BERR_SUCCESS;
3974}
3975
3976/***************************************************************************
3977 *
3978 */
3979BERR_Code BVDC_Window_GetMosaicConfiguration
3980        ( const BVDC_Window_Handle         hWindow,
3981          bool                            *pbEnable,
3982          BVDC_MosaicConfiguration        *pstSettings )
3983{
3984#if BVDC_P_SUPPORT_MOSAIC_MODE
3985        BDBG_ENTER(BVDC_Window_GetMosaicConfiguration);
3986        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
3987
3988        /* set new value */
3989        if(pbEnable)
3990        {
3991                *pbEnable = hWindow->stCurInfo.bClearRect;
3992        }
3993
3994        if(pstSettings)
3995        {
3996                unsigned int uiARGB;
3997
3998                /* To make sure thing get initialize */
3999                BKNI_Memset(pstSettings, 0, sizeof(*pstSettings));
4000
4001                pstSettings->bVideoInMosaics = hWindow->stCurInfo.bMosaicMode;
4002                pstSettings->bClearRectByMaskColor = hWindow->stCurInfo.bClearRectByMaskColor;
4003                pstSettings->ulClearRectAlpha = hWindow->stCurInfo.ulClearRectAlpha;
4004                BPXL_ConvertPixel_YCbCrtoRGB(BPXL_eA8_R8_G8_B8, BPXL_eA8_Y8_Cb8_Cr8,
4005                        hWindow->stNewInfo.ulMaskColorYCrCb, 0, 0, &uiARGB);
4006                pstSettings->ulMaskColorRed   = BPXL_GET_COMPONENT(BPXL_eA8_R8_G8_B8, uiARGB, 2);
4007                pstSettings->ulMaskColorGreen = BPXL_GET_COMPONENT(BPXL_eA8_R8_G8_B8, uiARGB, 1);
4008                pstSettings->ulMaskColorBlue  = BPXL_GET_COMPONENT(BPXL_eA8_R8_G8_B8, uiARGB, 0);
4009        }
4010
4011        BDBG_LEAVE(BVDC_Window_GetMosaicConfiguration);
4012#else
4013        BDBG_ERR(("This chipset doesn't support Mosaic Mode!"));
4014        BSTD_UNUSED(hWindow);
4015        BSTD_UNUSED(pbEnable);
4016        BSTD_UNUSED(pstSettings);
4017#endif
4018        return BERR_SUCCESS;
4019}
4020
4021/***************************************************************************
4022 *
4023 */
4024BERR_Code BVDC_Window_SetMosaicRectsVisibility
4025        ( BVDC_Window_Handle               hWindow,
4026          uint32_t                         ulRectsCount,
4027          bool                             abRectsVisible[] )
4028{
4029#if BVDC_P_SUPPORT_MOSAIC_MODE
4030        BDBG_ENTER(BVDC_Window_SetMosaicRectsVisibility);
4031        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
4032
4033        /* preliminary error checking */
4034        if((ulRectsCount > hWindow->stSettings.ulMaxMosaicRect) ||
4035           (ulRectsCount && !abRectsVisible))
4036        {
4037                return BERR_TRACE(BVDC_ERR_INVALID_MOSAIC_MODE);
4038        }
4039        if(!hWindow->bClearRectSupport)
4040        {
4041                BDBG_ERR(("This window[%d] does not support Mosaic Mode!", hWindow->eId));
4042                return BERR_TRACE(BVDC_ERR_INVALID_MOSAIC_MODE);
4043        }
4044        hWindow->stNewInfo.ulMosaicCount = ulRectsCount;
4045
4046        if(ulRectsCount)
4047        {
4048                BKNI_Memcpy((void*)hWindow->stNewInfo.abMosaicVisible, (void*)abRectsVisible,
4049                        sizeof(bool) * ulRectsCount);
4050        }
4051        BDBG_LEAVE(BVDC_Window_SetMosaicRectsVisibility);
4052#else
4053        BDBG_ERR(("This chipset doesn't support Mosaic Mode!"));
4054        BSTD_UNUSED(hWindow);
4055        BSTD_UNUSED(ulRectsCount);
4056        BSTD_UNUSED(abRectsVisible);
4057#endif
4058        return BERR_SUCCESS;
4059}
4060
4061/***************************************************************************
4062 *
4063 */
4064BERR_Code BVDC_Window_SetMosaicDstRects
4065        ( BVDC_Window_Handle               hWindow,
4066          uint32_t                         ulMosaicCount,
4067          BVDC_Rect                        astRect[] )
4068{
4069#if BVDC_P_SUPPORT_MOSAIC_MODE
4070        uint32_t   i;
4071
4072        BDBG_ENTER(BVDC_Window_SetMosaicDstRects);
4073        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
4074
4075        /* preliminary error checking */
4076        if((ulMosaicCount > hWindow->stSettings.ulMaxMosaicRect) ||
4077           (ulMosaicCount && !astRect))
4078        {
4079                return BERR_TRACE(BVDC_ERR_INVALID_MOSAIC_MODE);
4080        }
4081        if(!hWindow->bClearRectSupport)
4082        {
4083                BDBG_ERR(("This window[%d] does not support Mosaic Mode!", hWindow->eId));
4084                return BERR_TRACE(BVDC_ERR_INVALID_MOSAIC_MODE);
4085        }
4086
4087        for(i = 0; i < ulMosaicCount; i++)
4088        {
4089                hWindow->stNewInfo.astMosaicRect[i].lLeft    = astRect[i].lLeft;
4090                hWindow->stNewInfo.astMosaicRect[i].lLeft_R  = astRect[i].lLeft;
4091                hWindow->stNewInfo.astMosaicRect[i].lTop     = astRect[i].lTop;
4092                hWindow->stNewInfo.astMosaicRect[i].ulWidth  = astRect[i].ulWidth;
4093                hWindow->stNewInfo.astMosaicRect[i].ulHeight = astRect[i].ulHeight;
4094        }
4095
4096        BDBG_LEAVE(BVDC_Window_SetMosaicDstRects);
4097#else
4098        BDBG_ERR(("This chipset doesn't support Mosaic Mode!"));
4099        BSTD_UNUSED(hWindow);
4100        BSTD_UNUSED(ulMosaicCount);
4101        BSTD_UNUSED(astRect);
4102#endif
4103        return BERR_SUCCESS;
4104}
4105
4106
4107/***************************************************************************
4108 *
4109 */
4110BERR_Code BVDC_Window_SetMosaicRectsZOrder
4111        ( BVDC_Window_Handle               hWindow,
4112          uint32_t                         ulRectsCount,
4113          uint8_t                          aucZOrder[] )
4114{
4115#if BVDC_P_SUPPORT_MOSAIC_MODE
4116        BDBG_ENTER(BVDC_Window_SetMosaicRectsZOrder);
4117        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
4118
4119        /* preliminary error checking */
4120        if((ulRectsCount > hWindow->stSettings.ulMaxMosaicRect) ||
4121           (ulRectsCount && !aucZOrder))
4122        {
4123                return BERR_TRACE(BVDC_ERR_INVALID_MOSAIC_MODE);
4124        }
4125        if(!hWindow->bClearRectSupport)
4126        {
4127                BDBG_ERR(("This window[%d] does not support Mosaic Mode!", hWindow->eId));
4128                return BERR_TRACE(BVDC_ERR_INVALID_MOSAIC_MODE);
4129        }
4130        hWindow->stNewInfo.ulMosaicCount = ulRectsCount;
4131
4132        if(ulRectsCount)
4133        {
4134                BKNI_Memcpy((void*)hWindow->stNewInfo.aucMosaicZOrder, (void*)aucZOrder,
4135                        sizeof(uint8_t) * ulRectsCount);
4136        }
4137
4138        BDBG_LEAVE(BVDC_Window_SetMosaicRectsZOrder);
4139
4140#else
4141        BDBG_ERR(("This chipset doesn't support Mosaic Mode!"));
4142        BSTD_UNUSED(hWindow);
4143        BSTD_UNUSED(ulRectsCount);
4144        BSTD_UNUSED(aucZOrder);
4145#endif
4146        return BERR_SUCCESS;
4147}
4148
4149/***************************************************************************
4150 *
4151 */
4152BERR_Code BVDC_Window_SetMosaicTrack
4153        ( BVDC_Window_Handle               hWindow,
4154          uint32_t                         ulChannelId )
4155{
4156#if BVDC_P_SUPPORT_MOSAIC_MODE
4157        BDBG_ENTER(BVDC_Window_SetMosaicTrack);
4158        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
4159
4160        /* preliminary error checking */
4161        if(ulChannelId >= hWindow->stSettings.ulMaxMosaicRect)
4162        {
4163                return BERR_TRACE(BVDC_ERR_INVALID_MOSAIC_MODE);
4164        }
4165        if(!hWindow->bClearRectSupport)
4166        {
4167                BDBG_ERR(("This window[%d] does not support Mosaic Mode!", hWindow->eId));
4168                return BERR_TRACE(BVDC_ERR_INVALID_MOSAIC_MODE);
4169        }
4170
4171        hWindow->stNewInfo.ulMosaicTrackChannelId = ulChannelId;
4172
4173        BDBG_LEAVE(BVDC_Window_SetMosaicTrack);
4174#else
4175        BDBG_ERR(("This chipset doesn't support Mosaic Mode!"));
4176        BSTD_UNUSED(hWindow);
4177        BSTD_UNUSED(ulChannelId);
4178#endif
4179        return BERR_SUCCESS;
4180}
4181
4182/***************************************************************************
4183 *
4184 */
4185BERR_Code BVDC_Window_GetMosaicTrack
4186        ( BVDC_Window_Handle               hWindow,
4187          uint32_t                        *pulChannelId )
4188{
4189#if BVDC_P_SUPPORT_MOSAIC_MODE
4190        BDBG_ENTER(BVDC_Window_GetMosaicTrack);
4191        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
4192
4193        if(!hWindow->bClearRectSupport)
4194        {
4195                BDBG_ERR(("This window[%d] does not support Mosaic Mode!", hWindow->eId));
4196                return BERR_TRACE(BVDC_ERR_INVALID_MOSAIC_MODE);
4197        }
4198
4199        if(pulChannelId)
4200        {
4201                *pulChannelId = hWindow->stCurInfo.ulMosaicTrackChannelId;
4202        }
4203
4204        BDBG_LEAVE(BVDC_Window_GetMosaicTrack);
4205#else
4206        BDBG_ERR(("This chipset doesn't support Mosaic Mode!"));
4207        BSTD_UNUSED(hWindow);
4208        BSTD_UNUSED(pulChannelId);
4209#endif
4210        return BERR_SUCCESS;
4211}
4212
4213/***************************************************************************
4214 *
4215 */
4216BERR_Code BVDC_Window_SetCallbackSettings
4217                ( BVDC_Window_Handle                  hWindow,
4218                  BVDC_Window_CallbackSettings       *pSettings )
4219{
4220        BVDC_Window_CallbackSettings *pDefSettings;
4221
4222        BDBG_ENTER(BVDC_Window_SetCallbackSettings);
4223        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
4224
4225        if(!pSettings)
4226        {
4227                return BERR_TRACE(BERR_INVALID_PARAMETER);
4228        }
4229
4230        pDefSettings = &hWindow->stCallbackSettings;
4231        pDefSettings->stMask.bVsyncDelay = pSettings->stMask.bVsyncDelay;
4232        pDefSettings->stMask.bDriftDelay = pSettings->stMask.bDriftDelay;
4233        pDefSettings->stMask.bRectAdjust = pSettings->stMask.bRectAdjust;
4234        pDefSettings->stMask.bGameModeDelay = pSettings->stMask.bGameModeDelay;
4235        pDefSettings->ulLipSyncTolerance = pSettings->ulLipSyncTolerance;
4236        pDefSettings->ulGameModeReadWritePhaseDiff = pSettings->ulGameModeReadWritePhaseDiff;
4237        pDefSettings->ulGameModeTolerance = pSettings->ulGameModeTolerance;
4238
4239        BDBG_LEAVE(BVDC_Window_SetCallbackSettings);
4240        return BERR_SUCCESS;
4241}
4242
4243/***************************************************************************
4244 *
4245 */
4246BERR_Code BVDC_Window_GetCallbackSettings
4247                ( BVDC_Window_Handle                  hWindow,
4248                  BVDC_Window_CallbackSettings       *pSettings )
4249{
4250        BDBG_ENTER(BVDC_Window_GetCallbackSettings);
4251        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
4252
4253        if(pSettings)
4254        {
4255                *pSettings = hWindow->stCallbackSettings;
4256        }
4257
4258        BDBG_LEAVE(BVDC_Window_GetCallbackSettings);
4259        return BERR_SUCCESS;
4260}
4261
4262
4263/***************************************************************************
4264 *
4265 */
4266BERR_Code BVDC_Window_InstallCallback
4267        ( BVDC_Window_Handle               hWindow,
4268          const BVDC_CallbackFunc_isr      pfCallback,
4269          void                            *pvParm1,
4270          int                              iParm2 )
4271{
4272        BDBG_ENTER(BVDC_Window_InstallCallback);
4273        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
4274
4275        /* Store the new infos */
4276        hWindow->stNewInfo.pfGenCallback      = pfCallback;
4277        hWindow->stNewInfo.pvGenCallbackParm1 = pvParm1;
4278        hWindow->stNewInfo.iGenCallbackParm2  = iParm2;
4279
4280        BDBG_LEAVE(BVDC_Window_InstallCallback);
4281        return BERR_SUCCESS;
4282}
4283
4284
4285/***************************************************************************
4286 *
4287 */
4288BERR_Code BVDC_Window_SetPixelFormat
4289        ( BVDC_Window_Handle        hWindow,
4290          BPXL_Format                ePixelFormat)
4291{
4292        BDBG_ENTER(BVDC_Window_SetPixelFormat);
4293        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
4294
4295        if(!BPXL_IS_YCbCr422_FORMAT(ePixelFormat)
4296#if (BVDC_P_SUPPORT_BVN_10BIT_444)
4297         && !BPXL_IS_YCbCr422_10BIT_FORMAT(ePixelFormat)
4298         && !BPXL_IS_YCbCr444_10BIT_FORMAT(ePixelFormat)
4299#endif
4300        )
4301        {
4302                BDBG_ERR(("Pixel format %s is not supported by Video feeders",
4303                        BPXL_ConvertFmtToStr(ePixelFormat)));
4304                return BERR_TRACE(BERR_INVALID_PARAMETER);
4305        }
4306
4307#if (!BVDC_P_MFD_SUPPORT_BYTE_ORDER)
4308#if (BSTD_CPU_ENDIAN == BSTD_ENDIAN_LITTLE)
4309        if ((ePixelFormat == BPXL_eY08_Cr8_Y18_Cb8) ||
4310                (ePixelFormat == BPXL_eCr8_Y08_Cb8_Y18) ||
4311                (ePixelFormat == BPXL_eY08_Cb8_Y18_Cr8) ||
4312                (ePixelFormat == BPXL_eCb8_Y08_Cr8_Y18))
4313#else
4314        if ((ePixelFormat == BPXL_eCb8_Y18_Cr8_Y08) ||
4315                (ePixelFormat == BPXL_eY18_Cb8_Y08_Cr8) ||
4316                (ePixelFormat == BPXL_eCr8_Y18_Cb8_Y08) ||
4317                (ePixelFormat == BPXL_eY18_Cr8_Y08_Cb8))
4318#endif
4319        {
4320                BDBG_WRN(("Pixel format %s is not supported by Video feeders",
4321                        BPXL_ConvertFmtToStr(ePixelFormat)));
4322                BDBG_WRN(("Video display has wrong color, data in capture buffer is correct"));
4323        }
4324#endif
4325
4326        hWindow->stNewInfo.ePixelFormat = ePixelFormat;
4327
4328        if(ePixelFormat != hWindow->stCurInfo.ePixelFormat)
4329        {
4330                hWindow->stNewInfo.stDirty.stBits.bMiscCtrl = BVDC_P_DIRTY;
4331        }
4332
4333        BDBG_LEAVE(BVDC_Window_SetPixelFormat);
4334        return BERR_SUCCESS;
4335}
4336
4337/***************************************************************************
4338 *
4339 */
4340BERR_Code BVDC_Window_SetUserCaptureBufferCount
4341        ( BVDC_Window_Handle        hWindow,
4342          unsigned int              uiCaptureBufferCount )
4343{
4344        BDBG_ENTER(BVDC_Window_SetUserCaptureBufferCount);
4345        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
4346
4347        if (uiCaptureBufferCount > BVDC_P_MAX_USER_CAPTURE_BUFFER_COUNT)
4348        {
4349                return(BERR_TRACE(BVDC_ERR_CAPTURE_BUFFERS_MORE_THAN_MAX));
4350        }
4351
4352        hWindow->stNewInfo.uiCaptureBufCnt = uiCaptureBufferCount;
4353
4354        /* set dirty bit */
4355        hWindow->stNewInfo.stDirty.stBits.bUserCaptureBuffer = BVDC_P_DIRTY;
4356
4357        BDBG_LEAVE(BVDC_Window_SetUserCaptureBufferCount);
4358        return BERR_SUCCESS;
4359}
4360
4361/***************************************************************************
4362 *
4363 */
4364BERR_Code BVDC_Window_GetBuffer
4365        ( BVDC_Window_Handle         hWindow,
4366          BVDC_Window_CapturedImage *pCapturedImage )
4367{
4368        BERR_Code eRet = BERR_SUCCESS;
4369        BVDC_P_Window_CapturedPicture stCaptPic;
4370        BPXL_Format ePxlFmt;
4371        BSUR_Surface_Settings *pSurSettings = NULL;
4372#if (BVDC_P_SUPPORT_VIDEO_TESTFEATURE1_CAP)
4373        BSUR_Surface_Settings stSurSettings;
4374#endif
4375
4376        BDBG_ENTER(BVDC_Window_GetBuffer);
4377        BDBG_ASSERT(pCapturedImage);
4378        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
4379
4380        BKNI_EnterCriticalSection();
4381        eRet = BVDC_P_Window_CapturePicture_isr(hWindow, &stCaptPic);
4382        BKNI_LeaveCriticalSection();
4383
4384        ePxlFmt = stCaptPic.ePxlFmt;
4385        if (eRet == BERR_SUCCESS)
4386        {
4387#if (BVDC_P_SUPPORT_VIDEO_TESTFEATURE1_CAP)
4388        BKNI_Memset(&stSurSettings, 0, sizeof(BSUR_Surface_Settings));
4389        pSurSettings = &stSurSettings;
4390        pSurSettings->stTestFeature1Settings.bEnable = stCaptPic.pPicture->stCapTestFeature1.bEnable;
4391        pSurSettings->stTestFeature1Settings.ulBitsPerPixel = stCaptPic.pPicture->stCapTestFeature1.ulBitsPerPixel;
4392#endif
4393
4394                /* Create surface */
4395                eRet = BSUR_Surface_Create(hWindow->hHeap->hMem,
4396                        stCaptPic.ulWidth, stCaptPic.ulHeight, stCaptPic.ulPitch,
4397                        stCaptPic.pvBufAddr, ePxlFmt, NULL, 0, pSurSettings,
4398                        &pCapturedImage->hCaptureBuffer);
4399                if (eRet == BERR_SUCCESS)
4400                {
4401                        pCapturedImage->eCapturePolarity = stCaptPic.ePolarity;
4402                        pCapturedImage->ulCaptureNumVbiLines = stCaptPic.ulNumVbiLines;
4403                        /* Store surface in picture node */
4404                        stCaptPic.pPicture->hSurface = pCapturedImage->hCaptureBuffer;
4405#if (BVDC_P_SUPPORT_3D_VIDEO)
4406                        if(stCaptPic.pvBufAddr != NULL)
4407                        {
4408                                eRet = BSUR_Surface_Create(hWindow->hHeap->hMem,
4409                                        stCaptPic.ulWidth, stCaptPic.ulHeight, stCaptPic.ulPitch,
4410                                        stCaptPic.pvBufAddr_R, ePxlFmt, NULL, 0, pSurSettings,
4411                                        &pCapturedImage->hRCaptureBuffer);
4412                                if (eRet == BERR_SUCCESS)
4413                                {
4414                                        /* Store right surface in picture node */
4415                                        stCaptPic.pPicture->hSurface_R = pCapturedImage->hRCaptureBuffer;
4416                                        pCapturedImage->eOutOrientation = stCaptPic.eDispOrientation;
4417                                }
4418                        }
4419                        else
4420#endif
4421                        {
4422                                pCapturedImage->hRCaptureBuffer = NULL;
4423                        }
4424                }
4425                else
4426                {
4427                        pCapturedImage->hCaptureBuffer = NULL;
4428                        pCapturedImage->hRCaptureBuffer = NULL;
4429                        pCapturedImage->hCaptureBuffer = NULL;
4430                        pCapturedImage->eCapturePolarity = BAVC_Polarity_eTopField;
4431                        pCapturedImage->ulCaptureNumVbiLines = 0;
4432                        BDBG_ERR(("Failed to create surface from captured picture"));
4433                        return BERR_TRACE(eRet);
4434                }
4435        }
4436        else
4437        {
4438                pCapturedImage->hCaptureBuffer = NULL;
4439                pCapturedImage->hRCaptureBuffer = NULL;
4440        }
4441
4442        BDBG_LEAVE(BVDC_Window_GetBuffer);
4443        return BERR_TRACE(eRet);
4444}
4445
4446/***************************************************************************
4447 *
4448 */
4449BERR_Code BVDC_Window_ReturnBuffer
4450        ( BVDC_Window_Handle               hWindow,
4451          BVDC_Window_CapturedImage       *pCapturedImage )
4452{
4453        BERR_Code eRet = BERR_SUCCESS;
4454
4455        BDBG_ENTER(BVDC_Window_ReturnBuffer);
4456        BDBG_ASSERT(pCapturedImage);
4457        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
4458
4459        BKNI_EnterCriticalSection();
4460        eRet = BVDC_P_Window_ReleasePicture_isr(hWindow, pCapturedImage->hCaptureBuffer);
4461        BKNI_LeaveCriticalSection();
4462
4463        if (eRet != BERR_SUCCESS)
4464                return BERR_TRACE(eRet);
4465        else
4466        {
4467                BDBG_MSG(("destroying surface"));
4468                /* Destroy surface */
4469                BSUR_Surface_Destroy(pCapturedImage->hCaptureBuffer);
4470        }
4471
4472#if (BVDC_P_SUPPORT_3D_VIDEO)
4473        if(pCapturedImage->hRCaptureBuffer)
4474        {
4475                BKNI_EnterCriticalSection();
4476                eRet = BVDC_P_Window_ReleasePicture_isr(hWindow, pCapturedImage->hRCaptureBuffer);
4477                BKNI_LeaveCriticalSection();
4478
4479                if (eRet != BERR_SUCCESS)
4480                        return BERR_TRACE(eRet);
4481                else
4482                {
4483                        BDBG_MSG(("destroying right surface"));
4484                        /* Destroy surface */
4485                        BSUR_Surface_Destroy(pCapturedImage->hRCaptureBuffer);
4486                }
4487        }
4488#endif
4489
4490        BDBG_LEAVE(BVDC_Window_ReturnBuffer);
4491        return BERR_SUCCESS;
4492}
4493
4494/***************************************************************************
4495 *
4496 */
4497BERR_Code BVDC_Window_SetLumaKey
4498        ( BVDC_Window_Handle               hWindow,
4499          bool                             bLumaKey,
4500          uint8_t                          ucLumaKeyMask,
4501          uint8_t                          ucLumaKeyHigh,
4502          uint8_t                          ucLumaKeyLow )
4503{
4504        BERR_Code             err = BERR_SUCCESS;
4505
4506        BDBG_ENTER(BVDC_Window_SetLumaKey);
4507        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
4508
4509        if( (hWindow->eId == BVDC_P_WindowId_eComp0_V0) ||
4510            (hWindow->eId == BVDC_P_WindowId_eComp0_V1) ||
4511            (hWindow->eId == BVDC_P_WindowId_eComp1_V0) ||
4512            (hWindow->eId == BVDC_P_WindowId_eComp1_V1) )
4513        {
4514                hWindow->stNewInfo.bLumaKey      = bLumaKey;
4515                hWindow->stNewInfo.ucLumaKeyMask = ucLumaKeyMask;
4516                hWindow->stNewInfo.ucLumaKeyHigh = ucLumaKeyHigh;
4517                hWindow->stNewInfo.ucLumaKeyLow  = ucLumaKeyLow;
4518        }
4519        else
4520        {
4521                err = BERR_TRACE(BERR_NOT_SUPPORTED);
4522                BDBG_ERR(("Luma key not supported for window[%d]", hWindow->eId));
4523        }
4524
4525        BDBG_LEAVE(BVDC_Window_SetLumaKey);
4526        return err;
4527}
4528
4529/***************************************************************************
4530 *
4531 */
4532BERR_Code BVDC_Window_GetLumaKey
4533        ( BVDC_Window_Handle               hWindow,
4534          bool                            *pbLumaKey,
4535          uint8_t                         *pucLumaKeyMask,
4536          uint8_t                         *pucLumaKeyHigh,
4537          uint8_t                         *pucLumaKeyLow )
4538{
4539        BDBG_ENTER(BVDC_Window_GetLumaKey);
4540        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
4541
4542        if(pbLumaKey)
4543        {
4544                *pbLumaKey = hWindow->stCurInfo.bLumaKey;
4545        }
4546
4547        if(pucLumaKeyMask)
4548        {
4549                *pucLumaKeyMask = hWindow->stCurInfo.ucLumaKeyMask;
4550        }
4551
4552        if(pucLumaKeyHigh)
4553        {
4554                *pucLumaKeyHigh = hWindow->stCurInfo.ucLumaKeyHigh;
4555        }
4556
4557        if(pucLumaKeyLow)
4558        {
4559                *pucLumaKeyLow = hWindow->stCurInfo.ucLumaKeyLow;
4560        }
4561
4562
4563        BDBG_LEAVE(BVDC_Window_GetLumaKey);
4564        return BERR_SUCCESS;
4565
4566}
4567
4568/***************************************************************************
4569 *
4570 */
4571BERR_Code BVDC_Window_SetColorMatrix
4572        ( BVDC_Window_Handle               hWindow,
4573          bool                             bOverride,
4574          const int32_t                    pl32_Matrix[BVDC_CSC_COEFF_COUNT],
4575          uint32_t                         ulShift )
4576{
4577        BDBG_ENTER(BVDC_Window_SetColorMatrix);
4578        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
4579
4580        if (BVDC_P_WIN_IS_NONLINEAR_CSC_WIN(hWindow->eId))
4581        {
4582                return BERR_TRACE(BERR_NOT_SUPPORTED);
4583        }
4584
4585        if (bOverride)
4586        {
4587                BVDC_P_Window_SetColorMatrix(hWindow, pl32_Matrix, hWindow->stNewInfo.pl32_Matrix);
4588        }
4589
4590        hWindow->stNewInfo.bUserCsc = bOverride;
4591        hWindow->stNewInfo.ulUserShift = ulShift;
4592
4593        /* set dirty bit */
4594        hWindow->stNewInfo.stDirty.stBits.bCscAdjust = BVDC_P_DIRTY;
4595
4596        BDBG_LEAVE(BVDC_Window_SetColorMatrix);
4597        return BERR_SUCCESS;
4598}
4599
4600/***************************************************************************
4601 *
4602 */
4603BERR_Code BVDC_Window_SetColorMatrixNonLinearA
4604        ( BVDC_Window_Handle               hWindow,
4605          bool                             bOverride,
4606          const int32_t                    pl32_Matrix[BVDC_CSC_COEFF_COUNT],
4607          uint32_t                         ulShift )
4608{
4609        BDBG_ENTER(BVDC_Window_SetColorMatrix);
4610        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
4611
4612        if (!BVDC_P_WIN_IS_NONLINEAR_CSC_WIN(hWindow->eId))
4613        {
4614                return BERR_TRACE(BERR_NOT_SUPPORTED);
4615        }
4616
4617        BVDC_P_Window_SetColorMatrix(hWindow, pl32_Matrix, hWindow->stNewInfo.pl32_MatrixA);
4618
4619        hWindow->stNewInfo.bUserCscA = bOverride;
4620        hWindow->stNewInfo.ulUserShiftA = ulShift;
4621
4622        /* set dirty bit */
4623        hWindow->stNewInfo.stDirty.stBits.bCscAdjust = BVDC_P_DIRTY;
4624
4625        BDBG_LEAVE(BVDC_Window_SetColorMatrix);
4626        return BERR_SUCCESS;
4627}
4628
4629/***************************************************************************
4630 *
4631 */
4632BERR_Code BVDC_Window_SetColorMatrixNonLinearB
4633        ( BVDC_Window_Handle               hWindow,
4634          bool                             bOverride,
4635          const int32_t                    pl32_Matrix[BVDC_CSC_COEFF_COUNT],
4636          uint32_t                         ulShift )
4637{
4638        BDBG_ENTER(BVDC_Window_SetColorMatrix);
4639        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
4640
4641        if (!BVDC_P_WIN_IS_NONLINEAR_CSC_WIN(hWindow->eId))
4642        {
4643                return BERR_TRACE(BERR_NOT_SUPPORTED);
4644        }
4645
4646        BVDC_P_Window_SetColorMatrix(hWindow, pl32_Matrix, hWindow->stNewInfo.pl32_MatrixB);
4647
4648        hWindow->stNewInfo.bUserCscB = bOverride;
4649        hWindow->stNewInfo.ulUserShiftB = ulShift;
4650
4651        /* set dirty bit */
4652        hWindow->stNewInfo.stDirty.stBits.bCscAdjust = BVDC_P_DIRTY;
4653
4654        BDBG_LEAVE(BVDC_Window_SetColorMatrix);
4655        return BERR_SUCCESS;
4656}
4657
4658/***************************************************************************
4659 *
4660 */
4661BERR_Code BVDC_Window_SetColorMatrixNonLinearC
4662        ( BVDC_Window_Handle               hWindow,
4663          bool                             bOverride,
4664          const int32_t                    pl32_Matrix[BVDC_CSC_COEFF_COUNT],
4665          uint32_t                         ulShift )
4666{
4667        BDBG_ENTER(BVDC_Window_SetColorMatrix);
4668        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
4669
4670        BVDC_P_Window_SetColorMatrix(hWindow, pl32_Matrix, hWindow->stNewInfo.pl32_MatrixC);
4671
4672        if (bOverride)
4673        {
4674                /* calculate Inverse Matrix C here for use later in RGB attenuation calculations */
4675                if(BVDC_P_WIN_IS_GFX_WINDOW(hWindow->eId))
4676                {
4677                        BVDC_P_CscCoeffs stCscCoeffs = BVDC_P_MAKE_GFD_CSC
4678                                ( 1.00000, 0.00000, 0.00000, 0.00000, 0.00000,
4679                                  0.00000, 1.00000, 0.00000, 0.00000, 0.00000,
4680                                  0.00000, 0.00000, 1.00000, 0.00000, 0.00000 );
4681                        BVDC_P_Csc_FromMatrix_isr(&stCscCoeffs, pl32_Matrix, ulShift);
4682                        BVDC_P_Csc_MatrixInverse(&stCscCoeffs, &hWindow->stInvUserCscC);
4683                }
4684                else
4685                {
4686                        BVDC_P_CscCoeffs stCscCoeffs = BVDC_P_MAKE_CMP_CSC
4687                                ( 1.00000, 0.00000, 0.00000, 0.00000,
4688                                  0.00000, 1.00000, 0.00000, 0.00000,
4689                                  0.00000, 0.00000, 1.00000, 0.00000 );
4690                        BVDC_P_Csc_FromMatrix_isr(&stCscCoeffs, pl32_Matrix, ulShift);
4691                        BVDC_P_Csc_MatrixInverse(&stCscCoeffs, &hWindow->stInvUserCscC);
4692                }
4693        }
4694        hWindow->stNewInfo.bUserCscC = bOverride;
4695        hWindow->stNewInfo.ulUserShiftC = ulShift;
4696
4697        /* set dirty bit */
4698        hWindow->stNewInfo.stDirty.stBits.bCscAdjust = BVDC_P_DIRTY;
4699
4700        BDBG_LEAVE(BVDC_Window_SetColorMatrix);
4701        return BERR_SUCCESS;
4702}
4703
4704/***************************************************************************
4705 *
4706 */
4707BERR_Code BVDC_Window_GetColorMatrix
4708        ( BVDC_Window_Handle               hWindow,
4709          bool                            *pbOverride,
4710          int32_t                          pl32_Matrix[BVDC_CSC_COEFF_COUNT],
4711          uint32_t                        *pulShift )
4712{
4713        BDBG_ENTER(BVDC_Window_GetColorMatrix);
4714        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
4715
4716        if (BVDC_P_WIN_IS_NONLINEAR_CSC_WIN(hWindow->eId))
4717        {
4718                return BERR_TRACE(BERR_NOT_SUPPORTED);
4719        }
4720
4721        BVDC_P_Window_GetColorMatrix(hWindow, hWindow->stNewInfo.bUserCsc, &hWindow->stPriCsc,
4722                                         hWindow->stCurInfo.pl32_Matrix, pl32_Matrix);
4723
4724        *pbOverride = hWindow->stNewInfo.bUserCsc;
4725        *pulShift =  (*pbOverride)? hWindow->stNewInfo.ulUserShift : BVDC_P_FIX_POINT_SHIFT;
4726
4727        BDBG_LEAVE(BVDC_Window_GetColorMatrix);
4728        return BERR_SUCCESS;
4729}
4730
4731/***************************************************************************
4732 *
4733 */
4734BERR_Code BVDC_Window_GetColorMatrixNonLinearA
4735        ( BVDC_Window_Handle               hWindow,
4736          bool                            *pbOverride,
4737          int32_t                          pl32_Matrix[BVDC_CSC_COEFF_COUNT],
4738          uint32_t                        *pulShift )
4739{
4740        BDBG_ENTER(BVDC_Window_GetColorMatrix);
4741        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
4742
4743        if (!BVDC_P_WIN_IS_NONLINEAR_CSC_WIN(hWindow->eId))
4744        {
4745                return BERR_TRACE(BERR_NOT_SUPPORTED);
4746        }
4747
4748        BVDC_P_Window_GetColorMatrix(hWindow, hWindow->stNewInfo.bUserCsc, &hWindow->stPriCscA,
4749                                         hWindow->stCurInfo.pl32_MatrixA, pl32_Matrix);
4750
4751        *pbOverride = hWindow->stNewInfo.bUserCscA;
4752        *pulShift =  (*pbOverride)? hWindow->stNewInfo.ulUserShiftA : BVDC_P_FIX_POINT_SHIFT;
4753
4754        BDBG_LEAVE(BVDC_Window_GetColorMatrix);
4755        return BERR_SUCCESS;
4756}
4757
4758/***************************************************************************
4759 *
4760 */
4761BERR_Code BVDC_Window_GetColorMatrixNonLinearB
4762        ( BVDC_Window_Handle               hWindow,
4763          bool                            *pbOverride,
4764          int32_t                          pl32_Matrix[BVDC_CSC_COEFF_COUNT],
4765          uint32_t                        *pulShift )
4766{
4767        BDBG_ENTER(BVDC_Window_GetColorMatrix);
4768        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
4769
4770        if (!BVDC_P_WIN_IS_NONLINEAR_CSC_WIN(hWindow->eId))
4771        {
4772                return BERR_TRACE(BERR_NOT_SUPPORTED);
4773        }
4774
4775        BVDC_P_Window_GetColorMatrix(hWindow, hWindow->stNewInfo.bUserCscB, &hWindow->stPriCscB,
4776                                         hWindow->stCurInfo.pl32_MatrixB, pl32_Matrix);
4777
4778        *pbOverride = hWindow->stNewInfo.bUserCscB;
4779        *pulShift =  (*pbOverride)? hWindow->stNewInfo.ulUserShiftB : BVDC_P_FIX_POINT_SHIFT;
4780
4781        BDBG_LEAVE(BVDC_Window_GetColorMatrix);
4782        return BERR_SUCCESS;
4783}
4784
4785/***************************************************************************
4786 *
4787 */
4788BERR_Code BVDC_Window_GetColorMatrixNonLinearC
4789        ( BVDC_Window_Handle               hWindow,
4790          bool                            *pbOverride,
4791          int32_t                          pl32_Matrix[BVDC_CSC_COEFF_COUNT],
4792          uint32_t                        *pulShift )
4793{
4794        BDBG_ENTER(BVDC_Window_GetColorMatrix);
4795        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
4796
4797        if (!BVDC_P_WIN_IS_NONLINEAR_CSC_WIN(hWindow->eId))
4798        {
4799                return BERR_TRACE(BERR_NOT_SUPPORTED);
4800        }
4801
4802        BVDC_P_Window_GetColorMatrix(hWindow, hWindow->stNewInfo.bUserCscC, &hWindow->stPriCscC,
4803                                         hWindow->stCurInfo.pl32_MatrixC, pl32_Matrix);
4804
4805        *pbOverride = hWindow->stNewInfo.bUserCscC;
4806        *pulShift =  (*pbOverride)? hWindow->stNewInfo.ulUserShiftC : BVDC_P_FIX_POINT_SHIFT;
4807
4808        BDBG_LEAVE(BVDC_Window_GetColorMatrix);
4809        return BERR_SUCCESS;
4810}
4811
4812/***************************************************************************
4813 *
4814 */
4815BERR_Code BVDC_Window_LoadCabTable
4816        ( BVDC_Window_Handle               hWindow,
4817          const uint32_t                  *pulCabTable,
4818          uint32_t                         ulOffset,
4819          uint32_t                         ulSize )
4820{
4821        BDBG_ENTER(BVDC_Window_LoadCabTable);
4822        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
4823
4824        /* only support main display's main window */
4825        if(hWindow->eId != BVDC_P_WindowId_eComp0_V0)
4826        {
4827                return BERR_TRACE(BVDC_ERR_PEP_WINDOW_NOT_SUPPORT);
4828        }
4829
4830        /* Check for valid offset and size */
4831        if((pulCabTable != NULL) && ((ulOffset + ulSize) > BVDC_P_CAB_TABLE_SIZE))
4832        {
4833                return BERR_TRACE(BVDC_ERR_PEP_INVALID_PARAMETER);
4834        }
4835
4836        if(pulCabTable != NULL)
4837        {
4838                uint32_t id;
4839
4840                /* set new value */
4841                hWindow->stNewInfo.bUserCabEnable = true;
4842
4843                /* copy pulCabTable to internal table */
4844                for(id = 0; id < ulSize; id++)
4845                {
4846                        *(hWindow->stNewInfo.aulCabTable + (id + ulOffset)) =
4847                                *(pulCabTable + id);
4848                        BDBG_MSG(("User CabTable[%d]= 0x%x", id + ulOffset, hWindow->stNewInfo.aulCabTable[id+ulOffset]));
4849                }
4850        }
4851        else
4852        {
4853                hWindow->stNewInfo.bUserCabEnable = false;
4854        }
4855
4856        BDBG_LEAVE(BVDC_Window_LoadCabTable);
4857        return BERR_SUCCESS;
4858}
4859
4860/***************************************************************************
4861 *
4862 */
4863BERR_Code BVDC_Window_LoadLabTableCustomized
4864        ( BVDC_Window_Handle               hWindow,
4865          const uint32_t                  *pulLumaTable,
4866          const uint32_t                  *pulCbTable,
4867          const uint32_t                  *pulCrTable,
4868          uint32_t                         ulOffset,
4869          uint32_t                         ulSize )
4870{
4871        uint32_t id;
4872
4873        BDBG_ENTER(BVDC_Window_LoadLabTableCustomized);
4874        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
4875
4876        /* only support main display's main window */
4877        if(hWindow->eId != BVDC_P_WindowId_eComp0_V0)
4878        {
4879                return BERR_TRACE(BVDC_ERR_PEP_WINDOW_NOT_SUPPORT);
4880        }
4881
4882        /* Check for valid offset and size */
4883        if((pulLumaTable != NULL || pulCbTable != NULL || pulCrTable != NULL) &&
4884           ((ulOffset + ulSize) > BVDC_P_LAB_TABLE_SIZE))
4885        {
4886                return BERR_TRACE(BVDC_ERR_PEP_INVALID_PARAMETER);
4887        }
4888
4889        /* Check if user provides both Cb and Cr tables or not */
4890        if((pulCbTable != NULL && pulCrTable == NULL) ||
4891           (pulCbTable == NULL && pulCrTable != NULL))
4892        {
4893                BDBG_ERR(("Need to provide both Cb and Cr tables"));
4894                return BERR_TRACE(BVDC_ERR_PEP_INVALID_PARAMETER);
4895        }
4896
4897        hWindow->stNewInfo.bUserLabLuma = (pulLumaTable != NULL) ? true : false;
4898        hWindow->stNewInfo.bUserLabCbCr = (pulCbTable != NULL) ? true : false;
4899
4900        /* copy to internal tables */
4901        for(id = 0; id < ulSize; id++)
4902        {
4903                if(pulLumaTable != NULL)
4904                {
4905                        *(hWindow->stNewInfo.aulLabLumaTbl + (id + ulOffset)) =
4906                                *(pulLumaTable + id);
4907                        BDBG_MSG(("User LumTable[%d]= 0x%x", id + ulOffset, hWindow->stNewInfo.aulLabLumaTbl[id+ulOffset]));
4908                }
4909                if(pulCbTable != NULL && pulCrTable != NULL)
4910                {
4911                        *(hWindow->stNewInfo.aulLabCbTbl + (id + ulOffset)) =
4912                                *(pulCbTable + id);
4913                        *(hWindow->stNewInfo.aulLabCrTbl + (id + ulOffset)) =
4914                                *(pulCrTable + id);
4915                        BDBG_MSG(("User CbTable[%d]= 0x%x, CrTable[%d] = 0x%x",
4916                                id + ulOffset, hWindow->stNewInfo.aulLabCbTbl[id+ulOffset],
4917                                id + ulOffset, hWindow->stNewInfo.aulLabCrTbl[id+ulOffset]));
4918                }
4919        }
4920
4921        BDBG_LEAVE(BVDC_Window_LoadLabTableCustomized);
4922        return BERR_SUCCESS;
4923}
4924
4925/***************************************************************************
4926 *
4927 */
4928BERR_Code BVDC_Window_LoadLabTable
4929        ( BVDC_Window_Handle               hWindow,
4930          const uint32_t                  *pulLabTable,
4931          uint32_t                         ulOffset,
4932          uint32_t                         ulSize )
4933{
4934        BDBG_ENTER(BVDC_Window_LoadLabTable);
4935        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
4936
4937#if (BVDC_P_SUPPORT_PEP && BVDC_P_SUPPORT_PEP_VER <= BVDC_P_SUPPORT_PEP_VER_3)
4938        /* only support main display's main window */
4939        if(hWindow->eId != BVDC_P_WindowId_eComp0_V0)
4940        {
4941                return BERR_TRACE(BVDC_ERR_PEP_WINDOW_NOT_SUPPORT);
4942        }
4943
4944        /* Check for valid offset and size */
4945        if((pulLabTable != NULL) && ((ulOffset + ulSize) > BVDC_P_LAB_TABLE_SIZE))
4946        {
4947                return BERR_TRACE(BVDC_ERR_PEP_INVALID_PARAMETER);
4948        }
4949
4950        if(pulLabTable != NULL)
4951        {
4952                uint32_t id;
4953                uint32_t *pulLumaTable;
4954                uint32_t *pulCbTable;
4955                uint32_t *pulCrTable;
4956
4957                pulLumaTable = (uint32_t *)(BKNI_Malloc(BVDC_P_LAB_TABLE_SIZE * sizeof(uint32_t)));
4958                pulCbTable = (uint32_t *)(BKNI_Malloc(BVDC_P_LAB_TABLE_SIZE * sizeof(uint32_t)));
4959                pulCrTable = (uint32_t *)(BKNI_Malloc(BVDC_P_LAB_TABLE_SIZE * sizeof(uint32_t)));
4960
4961                /* break out the data into luma, Cb and Cr tables */
4962                for(id = 0; id < ulSize; id++)
4963                {
4964                        *(pulLumaTable + (id + ulOffset)) =
4965                                BCHP_GET_FIELD_DATA(*(pulLabTable + id), PEP_CMP_0_V0_LAB_LUT_DATA_i, LUMA_DATA);
4966                        *(pulCbTable + (id + ulOffset)) =
4967                                BCHP_GET_FIELD_DATA(*(pulLabTable + id), PEP_CMP_0_V0_LAB_LUT_DATA_i, CB_OFFSET);
4968                        *(pulCrTable + (id + ulOffset)) =
4969                                BCHP_GET_FIELD_DATA(*(pulLabTable + id), PEP_CMP_0_V0_LAB_LUT_DATA_i, CR_OFFSET);
4970                        BDBG_MSG(("User Luma[%d]= 0x%x, Cb = 0x%x, Cr = 0x%x",
4971                                id + ulOffset, pulLumaTable[id+ulOffset],
4972                                pulCbTable[id+ulOffset], pulCrTable[id+ulOffset]));
4973                }
4974                /* Calling the new function to load Lab table */
4975                BVDC_Window_LoadLabTableCustomized(hWindow, pulLumaTable, pulCbTable, pulCrTable, ulOffset, ulSize);
4976
4977                BKNI_Free((uint32_t *)pulLumaTable);
4978                BKNI_Free((uint32_t *)pulCbTable);
4979                BKNI_Free((uint32_t *)pulCrTable);
4980        }
4981        else
4982        {
4983                BVDC_Window_LoadLabTableCustomized(hWindow, NULL, NULL, NULL, ulOffset, ulSize);
4984        }
4985#else
4986        BSTD_UNUSED(pulLabTable);
4987        BSTD_UNUSED(ulOffset);
4988        BSTD_UNUSED(ulSize);
4989#endif
4990
4991        BDBG_LEAVE(BVDC_Window_LoadLabTable);
4992        return BERR_SUCCESS;
4993}
4994
4995/***************************************************************************
4996 *
4997 */
4998BERR_Code BVDC_Window_SetLumaStatsConfiguration
4999        ( BVDC_Window_Handle               hWindow,
5000          const BVDC_LumaSettings         *pLumaSettings )
5001{
5002        BERR_Code             err = BERR_SUCCESS;
5003
5004        BDBG_ENTER(BVDC_Window_SetLumaStatsConfiguration);
5005        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
5006
5007        if((hWindow->eId != BVDC_P_WindowId_eComp0_V0) && (!hWindow->bHistAvail))
5008        {
5009                return BERR_TRACE(BERR_NOT_SUPPORTED);
5010        }
5011
5012        if(pLumaSettings && pLumaSettings->eNumBins >= BVDC_HistBinSelect_eInvalid)
5013        {
5014                return BERR_TRACE(BERR_INVALID_PARAMETER);
5015        }
5016
5017        if(pLumaSettings &&
5018           (pLumaSettings->stRegion.ulLeft   > BVDC_P_CLIPRECT_PERCENT ||
5019            pLumaSettings->stRegion.ulRight  > BVDC_P_CLIPRECT_PERCENT ||
5020            pLumaSettings->stRegion.ulTop    > BVDC_P_CLIPRECT_PERCENT ||
5021            pLumaSettings->stRegion.ulBottom > BVDC_P_CLIPRECT_PERCENT ||
5022            pLumaSettings->stRegion.ulLeft + pLumaSettings->stRegion.ulRight  > BVDC_P_CLIPRECT_PERCENT ||
5023            pLumaSettings->stRegion.ulTop  + pLumaSettings->stRegion.ulBottom > BVDC_P_CLIPRECT_PERCENT))
5024        {
5025                return BERR_TRACE(BERR_INVALID_PARAMETER);
5026        }
5027
5028        if(pLumaSettings)
5029        {
5030                hWindow->stNewInfo.stLumaRect = *pLumaSettings;
5031                hWindow->stNewInfo.bLumaRectUserSet = true;
5032        }
5033        else
5034        {
5035                hWindow->stNewInfo.bLumaRectUserSet = false;
5036        }
5037
5038        BDBG_LEAVE(BVDC_Window_SetLumaStatsConfiguration);
5039        return err;
5040}
5041
5042/***************************************************************************
5043 *
5044 */
5045BERR_Code BVDC_Window_GetLumaStatsConfiguration
5046        ( BVDC_Window_Handle               hWindow,
5047          BVDC_LumaSettings               *pLumaSettings )
5048{
5049        BDBG_ENTER(BVDC_Window_GetLumaStatsConfiguration);
5050        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
5051
5052        if(pLumaSettings)
5053        {
5054                *pLumaSettings = hWindow->stCurInfo.stLumaRect;
5055        }
5056
5057        BDBG_LEAVE(BVDC_Window_GetLumaStatsConfiguration);
5058        return BERR_SUCCESS;
5059}
5060
5061/***************************************************************************
5062 *
5063 */
5064BERR_Code BVDC_Window_GetLumaStatus
5065        ( const BVDC_Window_Handle         hWindow,
5066          BVDC_LumaStatus                 *pLumaStatus )
5067{
5068        BDBG_ENTER(BVDC_Window_GetLumaStatus);
5069        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
5070
5071        if((hWindow->eId != BVDC_P_WindowId_eComp0_V0) && (!hWindow->bHistAvail))
5072        {
5073                return BERR_TRACE(BERR_NOT_SUPPORTED);
5074        }
5075
5076        /* set return value */
5077        if(pLumaStatus)
5078        {
5079#if (BVDC_P_SUPPORT_HIST)
5080                if(hWindow->bHistAvail)
5081                {
5082                        /* For chipsets that have new hist hardware, only return */
5083                        /* histogram data if hist is enabled by users or dynamic contrast */
5084                        if(hWindow->stCurInfo.bHistEnable)
5085                        {
5086                                BVDC_P_Hist_GetHistogramData(hWindow, pLumaStatus);
5087                        }
5088                        else
5089                        {
5090                                BDBG_ERR(("HIST is not enable, cannot retrieve histogram data"));
5091                                return BERR_TRACE(BERR_NOT_SUPPORTED);
5092                        }
5093                }
5094                else
5095                {
5096                        /* Get Min/Max/Histogram from PEP */
5097                        BVDC_P_Pep_GetLumaStatus(hWindow, pLumaStatus);
5098                }
5099#endif
5100        }
5101
5102        BDBG_LEAVE(BVDC_Window_GetLumaStatus);
5103        return BERR_SUCCESS;
5104}
5105
5106/***************************************************************************
5107 *
5108 */
5109BERR_Code BVDC_Window_SetCoefficientIndex
5110        ( BVDC_Window_Handle               hWindow,
5111          const BVDC_CoefficientIndex     *pCtIndex )
5112{
5113        BDBG_ENTER(BVDC_Window_SetCoefficientIndex);
5114        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
5115
5116        if(pCtIndex)
5117        {
5118                hWindow->stNewInfo.stCtIndex = *pCtIndex;
5119
5120                /* Flag change */
5121                if((pCtIndex->ulSclHorzLuma    != hWindow->stCurInfo.stCtIndex.ulSclHorzLuma   ) ||
5122                   (pCtIndex->ulSclVertLuma    != hWindow->stCurInfo.stCtIndex.ulSclVertLuma   ) ||
5123                   (!BVDC_P_WIN_IS_GFX_WINDOW(hWindow->eId) &&
5124                        ((pCtIndex->ulSclHorzChroma  != hWindow->stCurInfo.stCtIndex.ulSclHorzChroma ) ||
5125                         (pCtIndex->ulSclVertChroma  != hWindow->stCurInfo.stCtIndex.ulSclVertChroma ) ||
5126                         (pCtIndex->ulMadHorzLuma    != hWindow->stCurInfo.stCtIndex.ulMadHorzLuma   ) ||
5127                         (pCtIndex->ulMadHorzChroma  != hWindow->stCurInfo.stCtIndex.ulMadHorzChroma ) ||
5128                         (pCtIndex->ulHsclHorzLuma   != hWindow->stCurInfo.stCtIndex.ulHsclHorzLuma  ) ||
5129                         (pCtIndex->ulHsclHorzChroma != hWindow->stCurInfo.stCtIndex.ulHsclHorzChroma))))
5130                {
5131                        hWindow->stNewInfo.stDirty.stBits.bCtIndex = BVDC_P_DIRTY;
5132                }
5133        }
5134
5135        BDBG_LEAVE(BVDC_Window_SetCoefficientIndex);
5136        return BERR_SUCCESS;
5137}
5138
5139/***************************************************************************
5140 *
5141 */
5142BERR_Code BVDC_Window_SetGameModeDelay
5143        ( BVDC_Window_Handle               hWindow,
5144          BVDC_Window_GameModeSettings    *pstGameModeDelay )
5145{
5146        #define BVDC_P_GAME_MODE_MIN_BUF_DELAY     (1000) /* in usecs */
5147
5148        BDBG_ENTER(BVDC_Window_SetGameModeDelay);
5149        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
5150
5151        if(!pstGameModeDelay)
5152        {
5153                hWindow->stNewInfo.stGameDelaySetting.bEnable = false;
5154        }
5155        else
5156        {
5157                if(pstGameModeDelay->bEnable)
5158                {
5159                        if(pstGameModeDelay->ulBufferDelayTarget < pstGameModeDelay->ulBufferDelayTolerance)
5160                        {
5161                                BDBG_ERR(("Game mode delay target[%d] < tolerance[%d]!",
5162                                        pstGameModeDelay->ulBufferDelayTarget, pstGameModeDelay->ulBufferDelayTolerance));
5163                                return BERR_TRACE(BERR_INVALID_PARAMETER);
5164                        }
5165                        if(pstGameModeDelay->ulBufferDelayTarget < BVDC_P_GAME_MODE_MIN_BUF_DELAY)
5166                        {
5167                                BDBG_ERR(("Game mode delay target[%d] < %d usecs, too small!",
5168                                        pstGameModeDelay->ulBufferDelayTarget, BVDC_P_GAME_MODE_MIN_BUF_DELAY));
5169                                return BERR_TRACE(BERR_INVALID_PARAMETER);
5170                        }
5171                        if(pstGameModeDelay->ulBufferDelayTarget >=
5172                                (hWindow->hBuffer->ulActiveBufCnt) * 1000000 * BFMT_FREQ_FACTOR / hWindow->stCurInfo.hSource->ulVertFreq)
5173                        {
5174                                BDBG_ERR(("Game mode delay target[%d usec] > %d fields, too large!",
5175                                        pstGameModeDelay->ulBufferDelayTarget,
5176                                        hWindow->hBuffer->ulActiveBufCnt-1));
5177                                return BERR_TRACE(BERR_INVALID_PARAMETER);
5178                        }
5179                }
5180                hWindow->stNewInfo.stGameDelaySetting = *pstGameModeDelay;
5181        }
5182
5183        BDBG_LEAVE(BVDC_Window_SetGameModeDelay);
5184        return BERR_SUCCESS;
5185}
5186
5187/***************************************************************************
5188 *
5189 */
5190BERR_Code BVDC_Window_GetGameModeDelay
5191        ( BVDC_Window_Handle               hWindow,
5192          BVDC_Window_GameModeSettings    *pstGameModeDelay )
5193{
5194        BDBG_ENTER(BVDC_Window_GetGameModeDelay);
5195        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
5196
5197        if(!pstGameModeDelay)
5198        {
5199                return BERR_TRACE(BERR_INVALID_PARAMETER);
5200        }
5201        *pstGameModeDelay = hWindow->stCurInfo.stGameDelaySetting;
5202
5203        BDBG_LEAVE(BVDC_Window_GetGameModeDelay);
5204        return BERR_SUCCESS;
5205}
5206
5207/***************************************************************************
5208 *
5209 */
5210BERR_Code BVDC_Window_SetDitherConfiguration
5211        ( BVDC_Window_Handle               hWindow,
5212          const BVDC_DitherSettings       *pDither )
5213{
5214        BDBG_ENTER(BVDC_Window_SetDitherConfiguration);
5215        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
5216
5217        /* only support main display's main window */
5218        if(hWindow->eId != BVDC_P_WindowId_eComp0_V0)
5219        {
5220                return BERR_TRACE(BVDC_ERR_PEP_WINDOW_NOT_SUPPORT);
5221        }
5222
5223        /* set new values */
5224        hWindow->stNewInfo.stDither = *pDither;
5225
5226        /* set dirty bit */
5227        if((pDither->bReduceSmooth != hWindow->stCurInfo.stDither.bReduceSmooth) ||
5228           (pDither->bSmoothEnable != hWindow->stCurInfo.stDither.bSmoothEnable) ||
5229           (pDither->ulSmoothLimit != hWindow->stCurInfo.stDither.ulSmoothLimit))
5230        {
5231                hWindow->stNewInfo.stDirty.stBits.bDitAdjust = BVDC_P_DIRTY;
5232        }
5233
5234        BDBG_LEAVE(BVDC_Window_SetDitherConfiguration);
5235        return BERR_SUCCESS;
5236}
5237
5238/***************************************************************************
5239 *
5240 */
5241BERR_Code BVDC_Window_GetDitherConfiguration
5242        ( const BVDC_Window_Handle         hWindow,
5243          BVDC_DitherSettings             *pDither )
5244{
5245        BDBG_ENTER(BVDC_Window_GetDitherConfiguration);
5246        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
5247
5248        /* only support main display's main window */
5249        if(hWindow->eId != BVDC_P_WindowId_eComp0_V0)
5250        {
5251                return BERR_TRACE(BVDC_ERR_PEP_WINDOW_NOT_SUPPORT);
5252        }
5253
5254        /* set new values */
5255        if(pDither)
5256        {
5257                *pDither = hWindow->stNewInfo.stDither;
5258        }
5259
5260        BDBG_LEAVE(BVDC_Window_GetDitherConfiguration);
5261        return BERR_SUCCESS;
5262
5263}
5264
5265/***************************************************************************
5266 *
5267 */
5268BERR_Code BVDC_Window_SetFgtConfiguration
5269        ( BVDC_Window_Handle               hWindow,
5270          const BVDC_Fgt_Settings         *pFgtSettings )
5271{
5272        BERR_Code  eStatus = BERR_SUCCESS;
5273        BVDC_P_Window_Info   *pNewInfo, *pCurInfo;
5274
5275        BDBG_ENTER(BVDC_Window_SetFgtConfiguration);
5276        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
5277        BDBG_OBJECT_ASSERT(hWindow->hCompositor->hVdc, BVDC_VDC);
5278        BDBG_ASSERT(pFgtSettings);
5279
5280        pNewInfo = &hWindow->stNewInfo;
5281        pCurInfo = &hWindow->stCurInfo;
5282
5283#if (BVDC_P_SUPPORT_FGT)
5284        if(pFgtSettings->bEnable)
5285        {
5286                if(!hWindow->hCompositor->hVdc->stSettings.bEnableFgt)
5287                {
5288                        BDBG_ERR(("FGT is disabled in BVDC_Settings!"));
5289                        eStatus = BERR_TRACE(BVDC_ERR_FGT_NOT_SUPPORTED);
5290                }
5291
5292                if(!BVDC_P_SRC_IS_MPEG(hWindow->stNewInfo.hSource->eId))
5293                {
5294                        BDBG_ERR(("Video must be MPEG window!"));
5295                        eStatus = BERR_TRACE(BVDC_ERR_FGT_NOT_SUPPORTED);
5296                }
5297        }
5298
5299        /* configuration */
5300        pNewInfo->stFgtSettings = *pFgtSettings;
5301        pNewInfo->bFgt = pFgtSettings->bEnable;
5302
5303        if((pCurInfo->bFgt != pNewInfo->bFgt) ||
5304           (pCurInfo->stFgtSettings.bEnable != pNewInfo->stFgtSettings.bEnable))
5305        {
5306                pNewInfo->stDirty.stBits.bFgt = BVDC_P_DIRTY;
5307        }
5308
5309#else
5310        BSTD_UNUSED(pFgtSettings);
5311        BDBG_ERR(("This chipset doesn't support FGT!"));
5312        eStatus = BERR_TRACE(BVDC_ERR_FGT_NOT_SUPPORTED);
5313#endif
5314
5315        BDBG_LEAVE(BVDC_Window_SetFgtConfiguration);
5316        return eStatus;
5317}
5318
5319
5320/***************************************************************************
5321 *
5322 */
5323BERR_Code BVDC_Window_GetFgtConfiguration
5324        ( const BVDC_Window_Handle         hWindow,
5325          BVDC_Fgt_Settings               *pFgtSettings )
5326{
5327        BERR_Code  eStatus = BERR_SUCCESS;
5328
5329        BDBG_ENTER(BVDC_Window_GetFgtConfiguration);
5330        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
5331
5332#if (BVDC_P_SUPPORT_FGT)
5333        if(pFgtSettings)
5334        {
5335                *pFgtSettings = hWindow->stCurInfo.stFgtSettings;
5336        }
5337#else
5338        BSTD_UNUSED(pFgtSettings);
5339        BDBG_ERR(("This chipset doesn't support FGT!"));
5340        eStatus = BERR_TRACE(BVDC_ERR_FGT_NOT_SUPPORTED);
5341#endif
5342
5343        BDBG_LEAVE(BVDC_Window_GetFgtConfiguration);
5344        return eStatus;
5345}
5346
5347/***************************************************************************
5348 *
5349 */
5350BERR_Code BVDC_Window_SetAnrConfiguration
5351        ( BVDC_Window_Handle               hWindow,
5352          const BVDC_Anr_Settings         *pAnrSettings )
5353{
5354        BERR_Code  eStatus = BERR_SUCCESS;
5355
5356        BDBG_ENTER(BVDC_Window_SetAnrConfiguration);
5357        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
5358
5359#if (BVDC_P_SUPPORT_ANR) || (BVDC_P_SUPPORT_MANR)
5360        /* only support main display's main window */
5361        if(!pAnrSettings )
5362        {
5363                eStatus = BERR_TRACE(BERR_INVALID_PARAMETER);
5364        }
5365        else
5366        {
5367                BVDC_P_Window_Info *pNewInfo = &hWindow->stNewInfo;
5368                const BVDC_P_Window_Info *pCurInfo = &hWindow->stCurInfo;
5369                BVDC_Anr_Settings  *pNewAnr;
5370                const BVDC_Anr_Settings  *pCurAnr;
5371
5372                pNewAnr = &pNewInfo->stAnrSettings;
5373                pCurAnr = &pCurInfo->stAnrSettings;
5374
5375                if(pAnrSettings->eMode)
5376                {
5377#if(BVDC_P_SUPPORT_ANR_VER >= 2 || BVDC_P_SUPPORT_MANR)
5378                        if(!BPXL_IS_YCbCr422_FORMAT(pAnrSettings->ePxlFormat) &&
5379                           !BPXL_IS_YCbCr422_10BIT_FORMAT(pAnrSettings->ePxlFormat) &&
5380                           !BPXL_IS_YCbCr422_10BIT_PACKED_FORMAT(pAnrSettings->ePxlFormat))
5381                        {
5382                                BDBG_ERR(("This chip only supports 8-bit or 10-bit 4:2:2 ANR pixel format!"));
5383                                return BERR_TRACE(BVDC_ERR_MAD_NOT_SUPPORTED);
5384                        }
5385#elif(BVDC_P_SUPPORT_ANR_VER < 2)
5386                        if(!BPXL_IS_YCbCr422_FORMAT(pAnrSettings->ePxlFormat))
5387                        {
5388                                BDBG_WRN(("This chip only supports 8-bit 4:2:2 ANR pixel format!"));
5389                                return BERR_TRACE(BERR_INVALID_PARAMETER);
5390                        }
5391#endif /* BVDC_P_SUPPORT_ANR_VER < 2 */
5392                }
5393
5394                /* configuration */
5395                pNewInfo->bAnr = (BVDC_FilterMode_eEnable == pAnrSettings->eMode);
5396                pNewInfo->stAnrSettings = *pAnrSettings;
5397
5398#if (BVDC_P_SUPPORT_VIDEO_TESTFEATURE1_MAD_ANR)
5399                /* TestFeature1 */
5400                pNewAnr->stVideoTestFeature1.bEnable = pAnrSettings->stVideoTestFeature1.bEnable;
5401                pNewAnr->stVideoTestFeature1.ulBitsPerPixel = pAnrSettings->stVideoTestFeature1.ulBitsPerPixel;
5402#else
5403                BDBG_MSG(("This chip will ignore ANR TestFeature1 user setting!"));
5404#endif
5405
5406                /* Dirty bit set */
5407                if((pAnrSettings->eMode       != pCurInfo->stAnrSettings.eMode) ||
5408                   (pAnrSettings->iSnDbAdjust != pCurInfo->stAnrSettings.iSnDbAdjust) ||
5409                   (pAnrSettings->pvUserInfo  != pCurInfo->stAnrSettings.pvUserInfo) ||
5410                   (pAnrSettings->stVideoTestFeature1.bEnable != pCurAnr->stVideoTestFeature1.bEnable) ||
5411                   (pAnrSettings->stVideoTestFeature1.ulBitsPerPixel != pCurAnr->stVideoTestFeature1.ulBitsPerPixel) ||
5412                   (pAnrSettings->ePxlFormat  != pCurInfo->stAnrSettings.ePxlFormat))
5413                {
5414                        pNewInfo->stDirty.stBits.bAnrAdjust = BVDC_P_DIRTY;
5415                }
5416        }
5417#else
5418        BSTD_UNUSED(pAnrSettings);
5419        eStatus = BERR_TRACE(BVDC_ERR_ANR_HW_NOT_AVAILABLE);
5420#endif
5421
5422        BDBG_LEAVE(BVDC_Window_SetAnrConfiguration);
5423        return eStatus;
5424}
5425
5426/***************************************************************************
5427 *
5428 */
5429BERR_Code BVDC_Window_GetAnrConfiguration
5430        ( BVDC_Window_Handle               hWindow,
5431          BVDC_Anr_Settings               *pAnrSettings )
5432{
5433        BERR_Code  eStatus = BERR_SUCCESS;
5434
5435        BDBG_ENTER(BVDC_Window_GetAnrConfiguration);
5436        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
5437
5438#if (BVDC_P_SUPPORT_ANR) || (BVDC_P_SUPPORT_MANR)
5439        if(pAnrSettings)
5440        {
5441                *pAnrSettings = hWindow->stCurInfo.stAnrSettings;
5442        }
5443        else
5444        {
5445                eStatus = BERR_TRACE(BERR_INVALID_PARAMETER);
5446        }
5447#else
5448        BSTD_UNUSED(pAnrSettings);
5449        eStatus = BERR_TRACE(BVDC_ERR_ANR_HW_NOT_AVAILABLE);
5450#endif
5451        BDBG_LEAVE(BVDC_Window_GetAnrConfiguration);
5452        return eStatus;
5453}
5454
5455
5456/***************************************************************************
5457 *
5458 */
5459
5460BERR_Code BVDC_Window_SetBandwidthEquationParams
5461        ( BVDC_Window_Handle               hWindow,
5462          const uint32_t                   ulDelta,
5463          const BVDC_SclCapBias            eSclCapBias)
5464{
5465        BERR_Code  eStatus = BERR_SUCCESS;
5466
5467        BDBG_ENTER(BVDC_Window_SetBandwidthEquationParams);
5468        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
5469
5470        hWindow->stNewInfo.eSclCapBias = eSclCapBias;
5471        hWindow->stNewInfo.ulBandwidthDelta = ulDelta;
5472
5473        BDBG_LEAVE(BVDC_Window_SetBandwidthEquationParams);
5474        return eStatus;
5475}
5476
5477
5478/***************************************************************************
5479 *
5480 */
5481
5482BERR_Code BVDC_Window_GetBandwidthEquationParams
5483        ( BVDC_Window_Handle               hWindow,
5484          uint32_t                         *pulDelta,
5485          BVDC_SclCapBias                  *peSclCapBias)
5486{
5487        BERR_Code  eStatus = BERR_SUCCESS;
5488
5489        BDBG_ENTER(BVDC_Window_GetBandwidthEquationParams);
5490        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
5491
5492        *pulDelta = hWindow->stCurInfo.ulBandwidthDelta;
5493        *peSclCapBias = hWindow->stCurInfo.eSclCapBias;
5494
5495        BDBG_LEAVE(BVDC_Window_GetBandwidthEquationParams);
5496        return eStatus;
5497}
5498
5499/***************************************************************************
5500 *
5501 */
5502BERR_Code BVDC_Window_SetTestFeature1
5503        ( BVDC_Window_Handle                       hWindow,
5504          const BVDC_Video_TestFeature1_Settings  *pTestFeature1Settings )
5505{
5506        BVDC_Video_TestFeature1_Settings         *pNewTestFeature1;
5507        const BVDC_Video_TestFeature1_Settings   *pCurTestFeature1;
5508
5509        BDBG_ENTER(BVDC_Window_SetTestFeature1);
5510        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
5511        pNewTestFeature1 = &hWindow->stNewInfo.stCapTestFeature1;
5512        pCurTestFeature1 = &hWindow->stCurInfo.stCapTestFeature1;
5513
5514#if (!BVDC_P_SUPPORT_VIDEO_TESTFEATURE1_CAP)
5515        BSTD_UNUSED(pTestFeature1Settings);
5516        BDBG_WRN(("Video TestFeature1 is not supported on this chip!"));
5517#else
5518        BDBG_ASSERT(pTestFeature1Settings);
5519
5520        /* only support main display's window */
5521        if((pTestFeature1Settings->bEnable) &&
5522           (hWindow->eId != BVDC_P_WindowId_eComp0_V0))
5523        {
5524                return BERR_TRACE(BVDC_ERR_VIDEO_TestFeature1_NON_MAIN_WINDOW);
5525        }
5526
5527        /* set new value */
5528        pNewTestFeature1->bEnable = pTestFeature1Settings->bEnable;
5529        pNewTestFeature1->ulBitsPerPixel = pTestFeature1Settings->ulBitsPerPixel;
5530
5531        if((pNewTestFeature1->bEnable        != pCurTestFeature1->bEnable) ||
5532           (pNewTestFeature1->ulBitsPerPixel != pCurTestFeature1->ulBitsPerPixel))
5533        {
5534                hWindow->stNewInfo.stDirty.stBits.bTestFeature1 = BVDC_P_DIRTY;
5535        }
5536#endif
5537
5538        BDBG_LEAVE(BVDC_Window_SetTestFeature1);
5539        return BERR_SUCCESS;
5540
5541}
5542
5543/***************************************************************************
5544 *
5545 */
5546BERR_Code BVDC_Window_GetTestFeature1
5547        ( BVDC_Window_Handle                       hWindow,
5548          BVDC_Video_TestFeature1_Settings        *pTestFeature1Settings )
5549{
5550        const BVDC_Video_TestFeature1_Settings *pCurTestFeature1;
5551
5552        BDBG_ENTER(BVDC_Window_GetTestFeature1);
5553        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
5554
5555        /* Cur Info */
5556        pCurTestFeature1 = &hWindow->stCurInfo.stCapTestFeature1;
5557
5558        /* set new value */
5559        if(pTestFeature1Settings)
5560        {
5561                pTestFeature1Settings->bEnable        = pCurTestFeature1->bEnable;
5562                pTestFeature1Settings->ulBitsPerPixel = pCurTestFeature1->ulBitsPerPixel;
5563        }
5564
5565        BDBG_LEAVE(BVDC_Window_GetTestFeature1);
5566        return BERR_SUCCESS;
5567}
5568
5569/***************************************************************************
5570 *
5571 */
5572BERR_Code BVDC_Window_SetScalerConfiguration
5573        ( BVDC_Window_Handle               hWindow,
5574          const BVDC_Scaler_Settings      *pScalerSettings )
5575{
5576        BDBG_ENTER(BVDC_Window_SetScalerConfiguration);
5577        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
5578
5579        if(pScalerSettings)
5580        {
5581                const BVDC_Scaler_Settings *pCurSclSettings = &hWindow->stCurInfo.stSclSettings;
5582                hWindow->stNewInfo.stSclSettings = *pScalerSettings;
5583
5584                /* Flag change */
5585                if((pScalerSettings->bSclVertDejagging       != pCurSclSettings->bSclVertDejagging      ) ||
5586                   (pScalerSettings->bSclHorzLumaDeringing   != pCurSclSettings->bSclHorzLumaDeringing  ) ||
5587                   (pScalerSettings->bSclVertLumaDeringing   != pCurSclSettings->bSclVertLumaDeringing  ) ||
5588                   (pScalerSettings->bSclHorzChromaDeringing != pCurSclSettings->bSclHorzChromaDeringing) ||
5589                   (pScalerSettings->bSclVertChromaDeringing != pCurSclSettings->bSclVertChromaDeringing) ||
5590                   (pScalerSettings->bSclVertPhaseIgnore     != pCurSclSettings->bSclVertPhaseIgnore    ) ||
5591                   (pScalerSettings->ulSclDejaggingCore      != pCurSclSettings->ulSclDejaggingCore     ) ||
5592                   (pScalerSettings->ulSclDejaggingGain      != pCurSclSettings->ulSclDejaggingGain     ) ||
5593                   (pScalerSettings->ulSclDejaggingHorz      != pCurSclSettings->ulSclDejaggingHorz     ))
5594                {
5595                        hWindow->stNewInfo.stDirty.stBits.bMiscCtrl = BVDC_P_DIRTY;
5596                }
5597        }
5598
5599        BDBG_LEAVE(BVDC_Window_SetScalerConfiguration);
5600        return BERR_SUCCESS;
5601}
5602
5603/***************************************************************************
5604 *
5605 */
5606BERR_Code BVDC_Window_GetScalerConfiguration
5607        ( BVDC_Window_Handle               hWindow,
5608          BVDC_Scaler_Settings            *pScalerSettings )
5609{
5610        BDBG_ENTER(BVDC_Window_GetScalerConfiguration);
5611        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
5612
5613        /* set new value */
5614        if(pScalerSettings)
5615        {
5616                *pScalerSettings = hWindow->stCurInfo.stSclSettings;
5617        }
5618
5619        BDBG_LEAVE(BVDC_Window_GetScalerConfiguration);
5620        return BERR_SUCCESS;
5621}
5622
5623
5624/***************************************************************************
5625 *
5626 */
5627BERR_Code BVDC_Window_GetStatus
5628        ( const BVDC_Window_Handle         hWindow,
5629          BVDC_Window_Status              *pWindowStatus )
5630{
5631        BDBG_ENTER(BVDC_Window_GetStatus);
5632        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
5633
5634        /* set new value */
5635        if(pWindowStatus)
5636        {
5637                pWindowStatus->bSyncLock = hWindow->bSyncLockSrc;
5638        }
5639
5640        BDBG_LEAVE(BVDC_Window_GetStatus);
5641        return BERR_SUCCESS;
5642}
5643
5644/***************************************************************************
5645 *
5646 */
5647BERR_Code BVDC_Window_SetDstRightRect
5648        ( const BVDC_Window_Handle         hWindow,
5649          int32_t                          lRWinXOffsetDelta)
5650{
5651        BDBG_ENTER(BVDC_Window_SetDstRightRect);
5652        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
5653
5654        /* set new value */
5655        hWindow->stNewInfo.lRWinXOffsetDelta  = lRWinXOffsetDelta;
5656        hWindow->stNewInfo.stDirty.stBits.b3D = BVDC_P_DIRTY;
5657
5658        BDBG_LEAVE(BVDC_Window_SetDstRightRect);
5659        return BERR_SUCCESS;
5660}
5661
5662/***************************************************************************
5663 *
5664 */
5665BERR_Code BVDC_Window_GetDstRightRect
5666        ( const BVDC_Window_Handle         hWindow,
5667          int32_t                         *plRWinXOffsetDelta )
5668{
5669        BDBG_ENTER(BVDC_Window_GetDstRightRect);
5670        BDBG_OBJECT_ASSERT(hWindow, BVDC_WIN);
5671
5672        /* set new value */
5673        if(plRWinXOffsetDelta)
5674        {
5675                *plRWinXOffsetDelta = hWindow->stCurInfo.lRWinXOffsetDelta;
5676        }
5677
5678        BDBG_LEAVE(BVDC_Window_GetDstRightRect);
5679        return BERR_SUCCESS;
5680}
5681
5682/***************************************************************************
5683 *
5684 */
5685BERR_Code BVDC_Window_GetCapabilities
5686        ( BVDC_Window_Handle               hWindow,
5687          BVDC_Window_Capabilities        *pCapabilities )
5688{
5689        BSTD_UNUSED(hWindow);
5690        BSTD_UNUSED(pCapabilities);
5691
5692        return BERR_SUCCESS;
5693}
5694/* End of File */
Note: See TracBrowser for help on using the repository browser.