source: svn/newcon3bcm2_21bu/nexus/modules/display/7552/src/nexus_display_graphics.c

Last change on this file was 76, checked in by megakiss, 10 years ago

1W 대기전력을 만족시키기 위하여 POWEROFF시 튜너를 Standby 상태로 함

  • Property svn:executable set to *
File size: 32.6 KB
Line 
1/***************************************************************************
2 *     (c)2007-2011 Broadcom Corporation
3 *
4 *  This program is the proprietary software of Broadcom Corporation and/or its licensors,
5 *  and may only be used, duplicated, modified or distributed pursuant to the terms and
6 *  conditions of a separate, written license agreement executed between you and Broadcom
7 *  (an "Authorized License").  Except as set forth in an Authorized License, Broadcom grants
8 *  no license (express or implied), right to use, or waiver of any kind with respect to the
9 *  Software, and Broadcom expressly reserves all rights in and to the Software and all
10 *  intellectual property rights therein.  IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU
11 *  HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY
12 *  NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE.
13 *
14 *  Except as expressly set forth in the Authorized License,
15 *
16 *  1.     This program, including its structure, sequence and organization, constitutes the valuable trade
17 *  secrets of Broadcom, and you shall use all reasonable efforts to protect the confidentiality thereof,
18 *  and to use this information only in connection with your use of Broadcom integrated circuit products.
19 *
20 *  2.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
21 *  AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR
22 *  WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
23 *  THE SOFTWARE.  BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES
24 *  OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE,
25 *  LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION
26 *  OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF
27 *  USE OR PERFORMANCE OF THE SOFTWARE.
28 *
29 *  3.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS
30 *  LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR
31 *  EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR
32 *  USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF
33 *  THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT
34 *  ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE
35 *  LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF
36 *  ANY LIMITED REMEDY.
37 *
38 * $brcm_Workfile: nexus_display_graphics.c $
39 * $brcm_Revision: 40 $
40 * $brcm_Date: 9/8/11 2:18p $
41 *
42 * Module Description:
43 *
44 * Revision History:
45 *
46 * $brcm_Log: /nexus/modules/display/7400/src/nexus_display_graphics.c $
47 *
48 * 40   9/8/11 2:18p erickson
49 * SW7425-1267: add NEXUS_GraphicsSettings.horizontalCoeffIndex and
50 *  .verticalCoeffIndex
51 *
52 * 39   4/22/11 3:13p vsilyaev
53 * SW7425-416: Updated 3D display API
54 *
55 * 38   4/14/11 3:14p jtna
56 * SWDTV-6321: remove duplicate perl keywords
57 *
58 * 34   11/9/10 2:49p erickson
59 * SW35230-1899: add NEXUS_GraphicsSettings.visible
60 *
61 * 33   11/2/10 2:19p vsilyaev
62 * SW7422-64: Added API to set 3D framebuffer
63 *
64 * 32   11/1/10 10:28a erickson
65 * SW7422-43: use new BAVC_Gfx_Picture struct
66 *
67 * 31   8/6/10 1:08p erickson
68 * SW7420-703: NEXUS_Surface_GetCreateSettings will always return a non-
69 *  NULL heap
70 *
71 * 30   8/4/10 4:36p spothana
72 * SW7420-886: Add support for 32b UMA mode using MEMC0 only for 97410.
73 *
74 * 29   7/15/10 4:23p erickson
75 * SW7420-890: update 7420 fb check
76 *
77 * 28   6/25/10 12:12p erickson
78 * SW7405-4515: add NEXUS_Display_SetGraphicsColorSettings. allow
79 *  NEXUS_Display_SetGraphicsColorMatrix with NULL to unset matrix.
80 *
81 * 27   4/22/10 4:32p erickson
82 * SW7420-703: don't assume nexusHeap[0]. just give a general warning.
83 *
84 * 26   4/6/10 3:20p erickson
85 * SW7420-678: added check into NEXUS_Display_SetGraphicsFramebuffer for
86 *  framebuffer MEMC on 7420
87 *
88 * 25   11/12/09 10:50a erickson
89 * SW3548-2616: refactor NEXUS_Display_P_InitGraphics and related code
90 *
91 * 24   8/10/09 4:11p erickson
92 * PR55364: factor in !handleDynamicRts to graphics test
93 *
94 * 23   8/10/09 8:17a gmohile
95 * PR 56400 : Merge legacy vdc support to main line
96 *
97 * 22   8/6/09 2:38p erickson
98 * PR56417: removed NEXUS_GraphicsSettings.gammaCorrection. feature should
99 *  not be used.
100 *
101 * 21   7/16/09 11:50a erickson
102 * PR56417: added NEXUS_GraphicsSettings.gammaCorrection
103 *
104 * 20   5/20/09 4:00p erickson
105 * PR54512: added requirement that framebuffers with non-zero bitsPerPixel
106 *  cannot be clipped
107 *
108 * 19   5/1/09 11:07a jgarrett
109 * PR 54512: Adding gfx bits per pixel restrictions
110 *
111 * 18   4/2/09 11:57a erickson
112 * PR53810: fix logic for setting frameBufferChanged
113 *
114 * 17   3/6/09 4:32p erickson
115 * PR52839: added NEXUS_GraphicsFilterCoeffs to NEXUS_GraphicsSettings for
116 *  controlling GFD scaling coefficients
117 *
118 * 16   1/9/09 12:19a erickson
119 * PR48984: fix warning a different way
120 *
121 * 15   1/8/09 2:33a erickson
122 * PR48984: fix warnings
123 *
124 * 14   1/6/09 11:33a jgarrett
125 * PR 48984: Merge dynamic RTS code to main branch
126 *
127 * PR48984/2   12/10/08 11:29a jgarrett
128 * PR 48984: Adding additional info on VDB violations
129 *
130 * PR48984/1   11/20/08 6:47p jgarrett
131 * PR 48984: Adding vdb hooks
132 *
133 * 13   10/29/08 1:20p erickson
134 * PR48409: remove default 1/2 width framebuffer for HD. customers must
135 *  know their graphics cliprect width and program it. apps should not
136 *  rely on a 1/2 width default.
137 *
138 * 12   9/18/08 4:19p erickson
139 * PR47111: fix warnings
140 *
141 * 11   9/18/08 11:02a erickson
142 * PR47014: update blend equation enums
143 *
144 * 10   9/17/08 12:29p erickson
145 * PR47014: expose compositor blend equation in NEXUS_VideoWindowSettings
146 *  and NEXUS_GraphicsSettings
147 *
148 * 9   7/3/08 5:07p erickson
149 * PR43699: Remove unnecessary VDC Get functions from Nexus to avoid race
150 *  conditions
151 *
152 * 8   6/10/08 3:29p vsilyaev
153 * PR 43184: Added support for Start/Stop callbacks in linux kernel/user
154 *  proxy mode
155 *
156 * 7   4/4/08 4:06p erickson
157 * PR39257: add NEXUS_DisplayType_eBypass for DTV
158 *
159 * 6   3/24/08 5:35p vsilyaev
160 * PR 40755: Added implementation for colorkeying
161 *
162 * 5   3/20/08 2:17p erickson
163 * PR40156: convert to BVDC_Window_GetColorMatrix for graphics color
164 *  matrix
165 *
166 * 4   3/3/08 9:21a erickson
167 * PR40156: fix legacy VDC
168 *
169 * 3   2/29/08 5:39p erickson
170 * PR40156: implement ColorMatrix function
171 *
172 * 2   2/28/08 10:42p vsilyaev
173 * PR 40103: Added interfaceHandle and settings for the
174 *  NEXUS_IsrCallbackCreate
175 *
176 * 1   1/18/08 2:20p jgarrett
177 * PR 38808: Merging to main branch
178 *
179 * Nexus_Devel/10   11/28/07 1:43p vsilyaev
180 * PR 36159: Added global UpdateMode, removed per-function ApplyChanges
181 *
182 * Nexus_Devel/9   10/17/07 11:05a erickson
183 * PR36068: set zorder and alpha
184 *
185 * Nexus_Devel/8   10/16/07 12:32p erickson
186 * PR36068: hardcode graphics zorder to 2 for now
187 *
188 * Nexus_Devel/7   10/3/07 1:24p vsilyaev
189 * PR 34662: Added window clipping
190 *
191 * Nexus_Devel/6   10/2/07 6:18p vsilyaev
192 * PR 34662: Added support for format changes
193 *
194 * Nexus_Devel/5   10/2/07 10:40a vsilyaev
195 * PR 34662: Clear picture info in the callback
196 *
197 * Nexus_Devel/4   10/1/07 5:49p vsilyaev
198 * PR 34662: Implemented graphics framebuffer callback
199 *
200 * Nexus_Devel/3   9/28/07 4:25p jgarrett
201 * PR 35002: Successful 7400 build
202 *
203 * Nexus_Devel/2   9/26/07 5:35p vsilyaev
204 * PR 34662: Fixed graphics destroy
205 *
206 * Nexus_Devel/1   9/26/07 1:42p vsilyaev
207 * PR 34662: Implementation of display framebuffer
208 *
209 *
210 **************************************************************************/
211#include "nexus_base.h"
212#include "nexus_display_module.h"
213#include "priv/nexus_surface_priv.h"
214
215BDBG_MODULE(nexus_display_graphics);
216
217static bool NEXUS_Display_P_GraphicsValid(NEXUS_DisplayHandle display, const NEXUS_GraphicsSettings *pSettings, const NEXUS_GraphicsFramebuffer3D *framebuffer3d);
218static void NEXUS_Display_P_DestroyGraphics(NEXUS_DisplayHandle display);
219
220static void
221NEXUS_Display_P_GraphicsNext_isr(void  *disp, int unused, BAVC_Polarity  polarity, BAVC_SourceState  state, void **picture)
222{
223    NEXUS_DisplayHandle display = disp;
224    struct NEXUS_DisplayGraphics *graphics = &display->graphics;
225
226    BSTD_UNUSED(unused);
227    BSTD_UNUSED(state);
228    BSTD_UNUSED(polarity);
229    BDBG_OBJECT_ASSERT(display, NEXUS_Display);
230    BDBG_ASSERT(picture);
231    *picture = NULL; /* clear picture info */
232    if(graphics->queuedSurface) {
233        BAVC_Gfx_Picture pic;
234        BERR_Code rc;
235        rc = BVDC_Source_GetSurface_isr(graphics->source, &pic);
236        if (!rc) {
237            if (pic.hSurface == graphics->queuedSurface) {
238                graphics->queuedSurface = NULL;
239                NEXUS_IsrCallback_Fire_isr(graphics->frameBufferCallback);
240            }
241        }
242    }
243    return;
244}
245
246static NEXUS_Error
247NEXUS_Display_P_SetGraphicsChromaKey(const struct NEXUS_DisplayGraphics *graphics, const NEXUS_GraphicsSettings *cfg)
248{
249    BERR_Code rc;
250
251    if(cfg->chromakeyEnabled) {
252        uint32_t min,max,mask;
253        switch(graphics->frameBufferPixelFormat) {
254        default:
255            min = cfg->lowerChromakey;
256            max = cfg->upperChromakey;
257            mask = BPXL_MAKE_PIXEL(BPXL_eA8_R8_G8_B8, 0xFF, 0xFF, 0xFF, 0xFF);
258            break;
259        case NEXUS_PixelFormat_eY08_Cb8_Y18_Cr8:
260        case NEXUS_PixelFormat_eCr8_Y18_Cb8_Y08:
261            {
262            unsigned t_min, t_max;
263
264            BPXL_ConvertPixel_RGBtoYCbCr(BPXL_eA8_Y8_Cb8_Cr8, BPXL_eA8_R8_G8_B8, cfg->lowerChromakey, &t_min);
265            BPXL_ConvertPixel_RGBtoYCbCr(BPXL_eA8_Y8_Cb8_Cr8, BPXL_eA8_R8_G8_B8, cfg->upperChromakey, &t_max);
266            min = t_min;
267            max = t_max;
268            mask = BPXL_MAKE_PIXEL(BPXL_eY08_Cr8_Y18_Cb8, 0xFF, 0xFF, 0xFF, 0xFF);
269            break;
270            }
271        }
272        rc = BVDC_Source_EnableColorKey(graphics->source, min, max, mask, 0 /* alpha 0 - remove it */);
273        if(rc!=BERR_SUCCESS) {return BERR_TRACE(rc);}
274    } else {
275        rc = BVDC_Source_DisableColorKey(graphics->source);
276        if(rc!=BERR_SUCCESS) {return BERR_TRACE(rc);}
277    }
278    return NEXUS_SUCCESS;
279}
280
281
282static BERR_Code
283NEXUS_Display_P_SetGraphicsSettings(NEXUS_DisplayHandle display, const NEXUS_GraphicsSettings *cfg, bool force)
284{
285    BERR_Code rc;
286    struct NEXUS_DisplayGraphics *graphics = &display->graphics;
287    const NEXUS_DisplayModule_State *video= &g_NEXUS_DisplayModule_State;
288
289    /* Check VDB limits first */
290    if ( !NEXUS_Display_P_GraphicsValid(display, cfg, &display->graphics.frameBuffer3D) )
291    {
292        NEXUS_Display_P_DestroyGraphics(display);
293        return BERR_TRACE(BERR_NOT_SUPPORTED);
294    }
295
296    force = force || video->lastUpdateFailed;
297
298    if(force || graphics->cfg.horizontalFilter != cfg->horizontalFilter) {
299        BDBG_CASSERT(BVDC_FilterCoeffs_eSharp == (BVDC_FilterCoeffs)NEXUS_GraphicsFilterCoeffs_eSharp);
300        rc = BVDC_Source_SetHorizontalScaleCoeffs(graphics->source, cfg->horizontalFilter);
301        if (rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc);goto err_source_cfg;}
302    }
303   
304    if (force || 
305        graphics->cfg.horizontalCoeffIndex != cfg->horizontalCoeffIndex ||
306        graphics->cfg.verticalCoeffIndex != cfg->verticalCoeffIndex) 
307    {
308        BVDC_CoefficientIndex coeffSettings;
309        BKNI_Memset(&coeffSettings, 0, sizeof(coeffSettings)); /* no GetSettings */
310        coeffSettings.ulSclVertLuma = graphics->cfg.verticalCoeffIndex;
311        coeffSettings.ulSclHorzLuma = graphics->cfg.horizontalCoeffIndex;
312        rc = BVDC_Window_SetCoefficientIndex(graphics->windowVdc, &coeffSettings);
313        if (rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc);goto err_window_cfg;}
314    }
315
316    /* Set the graphics framebuffer to be full screen for its display. */
317    rc = BVDC_Window_SetScalerOutput( graphics->windowVdc, 0, 0, cfg->position.width, cfg->position.height);
318    if (rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc);goto err_window_cfg;}
319
320    rc = BVDC_Window_SetDstRect( graphics->windowVdc, cfg->position.x, cfg->position.y, cfg->position.width, cfg->position.height);
321    if (rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc);goto err_window_cfg;}
322
323    /* Clip the framebuffer to match the display size */
324    rc = BVDC_Window_SetSrcClip( graphics->windowVdc, cfg->clip.x, graphics->frameBufferWidth - (cfg->clip.width+cfg->clip.x), cfg->clip.y, graphics->frameBufferHeight - (cfg->clip.height+cfg->clip.y));
325    if (rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc);goto err_window_cfg;}
326
327    if(force || graphics->cfg.zorder != cfg->zorder) {
328        rc = BVDC_Window_SetZOrder( graphics->windowVdc, cfg->zorder);
329        if (rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc);goto err_window_cfg;}
330    }
331
332    if(force || graphics->cfg.alpha != cfg->alpha ||
333                graphics->cfg.sourceBlendFactor != cfg->sourceBlendFactor ||
334                graphics->cfg.destBlendFactor != cfg->destBlendFactor ||
335                graphics->cfg.constantAlpha != cfg->constantAlpha)
336    {
337        rc = BVDC_Window_SetAlpha(graphics->windowVdc, cfg->alpha);
338        if (rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc);goto err_window_cfg;}
339
340        rc = BVDC_Window_SetBlendFactor( graphics->windowVdc, cfg->sourceBlendFactor, cfg->destBlendFactor, cfg->constantAlpha);
341        if (rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc);goto err_window_cfg;}
342    }
343
344    if(force || (graphics->cfg.chromakeyEnabled!=cfg->chromakeyEnabled || graphics->cfg.lowerChromakey!=cfg->lowerChromakey || graphics->cfg.upperChromakey!=cfg->upperChromakey)) {
345        rc = NEXUS_Display_P_SetGraphicsChromaKey(graphics, cfg);
346        if(rc!=NEXUS_SUCCESS) {rc=BERR_TRACE(rc);goto err_source_cfg;}
347    }
348
349    if(force || (graphics->cfg.visible != cfg->visible)) {
350        rc = BVDC_Window_SetVisibility(graphics->windowVdc, cfg->visible);
351        if (rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc);goto err_window_cfg;}
352    }
353
354    if(force || (graphics->cfg.graphics3DSettings.rightViewOffset != cfg->graphics3DSettings.rightViewOffset)) {
355        rc = BVDC_Window_SetDstRightRect(graphics->windowVdc, cfg->graphics3DSettings.rightViewOffset);
356        if (rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc);goto err_window_cfg;}
357    }
358   
359
360    return rc;
361err_window_cfg:
362err_source_cfg:
363    return rc;
364}
365
366static NEXUS_Error
367NEXUS_Display_P_SetGraphicsSource(NEXUS_DisplayHandle display, const NEXUS_GraphicsFramebuffer3D *frameBuffer3D, BSUR_Surface_Handle main)
368{
369    BERR_Code rc;
370    BAVC_Gfx_Picture pic;
371    const NEXUS_DisplayModule_State *video= &g_NEXUS_DisplayModule_State;
372
373    BKNI_Memset(&pic, 0, sizeof(pic));
374    pic.hSurface = main;
375    pic.eInOrientation = NEXUS_P_VideoOrientation_ToMagnum(frameBuffer3D->orientation);
376    pic.ucW0Alpha = frameBuffer3D->alphaW0;
377    pic.ucW1Alpha = frameBuffer3D->alphaW1;
378    if(frameBuffer3D->alpha || frameBuffer3D->right || frameBuffer3D->rightAlpha) {
379        NEXUS_Module_Lock(video->modules.surface);
380        if(frameBuffer3D->right) {
381            pic.hRSurface = NEXUS_Surface_GetSurface_priv(frameBuffer3D->right);
382        }
383        if(frameBuffer3D->alpha) {
384            pic.hAlphaSurface = NEXUS_Surface_GetSurface_priv(frameBuffer3D->alpha);
385        }
386        if(frameBuffer3D->rightAlpha) {
387            pic.hAlphaRSurface = NEXUS_Surface_GetSurface_priv(frameBuffer3D->rightAlpha);
388        }
389        NEXUS_Module_Unlock(video->modules.surface);
390    }
391    rc = BVDC_Source_SetSurface( display->graphics.source, &pic);
392    if (rc!=BERR_SUCCESS) { return BERR_TRACE(rc);}
393
394    return NEXUS_SUCCESS;
395}
396
397static BERR_Code
398NEXUS_Display_P_CreateGraphics(NEXUS_DisplayHandle display, const NEXUS_GraphicsSettings *cfg)
399{
400    BERR_Code rc;
401    BERR_Code cleanup_rc; /* keep original error code */
402    const NEXUS_DisplayModule_State *video= &g_NEXUS_DisplayModule_State;
403    struct NEXUS_DisplayGraphics *graphics = &display->graphics;
404    static const BAVC_SourceId gfx_ids[]={BAVC_SourceId_eGfx0,BAVC_SourceId_eGfx1, BAVC_SourceId_eGfx2};
405    BSUR_Surface_Handle surface;
406    NEXUS_SurfaceCreateSettings surfaceCfg;
407
408    BDBG_MSG((">graphics: %ux%u video=%#x display=%#x graphics=%#x", cfg->position.width, cfg->position.height, (unsigned)video, (unsigned)display, (unsigned)graphics));
409    if (display->index >= sizeof(gfx_ids)/sizeof(*gfx_ids)) {
410        return BERR_TRACE(NEXUS_INVALID_PARAMETER);
411    }
412    BDBG_ASSERT(graphics->frameBuffer3D.main);
413    NEXUS_Module_Lock(video->modules.surface);
414    surface = NEXUS_Surface_GetSurface_priv(graphics->frameBuffer3D.main);
415    BDBG_ASSERT(surface);
416    NEXUS_Module_Unlock(video->modules.surface);
417    NEXUS_Surface_GetCreateSettings(graphics->frameBuffer3D.main, &surfaceCfg);
418    graphics->queuedSurface = surface;
419    graphics->frameBufferHeight = surfaceCfg.height;
420    graphics->frameBufferWidth = surfaceCfg.width;
421    graphics->frameBufferPixelFormat = surfaceCfg.pixelFormat;
422
423#ifdef B_HAS_LEGACY_VDC
424    rc = BVDC_Source_Create( video->vdc, &graphics->source, gfx_ids[display->index]);
425#else
426    rc = BVDC_Source_Create( video->vdc, &graphics->source, gfx_ids[display->index], NULL);
427#endif
428    if (rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc);goto err_source;}
429    rc = NEXUS_Display_P_SetGraphicsSource(display, &graphics->frameBuffer3D, surface);
430    if (rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc);goto err_source_cfg;}
431
432    rc = BVDC_Source_InstallPictureCallback(graphics->source, NEXUS_Display_P_GraphicsNext_isr, display, 0);
433    if (rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc);goto err_source_cfg;}
434
435#ifdef B_HAS_LEGACY_VDC
436    rc = BVDC_Window_Create( display->compositor, &graphics->windowVdc, graphics->source);
437#else
438    rc = BVDC_Window_Create( display->compositor, &graphics->windowVdc, BVDC_WindowId_eAuto, graphics->source, NULL);
439#endif
440    if (rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc);goto err_window;}
441
442    rc = NEXUS_Display_P_SetGraphicsSettings(display, cfg, true);
443    if (rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc);goto err_graphics_cfg;}
444
445    if(video->updateMode != NEXUS_DisplayUpdateMode_eAuto) { rc = BERR_TRACE(NEXUS_NOT_SUPPORTED);}
446    rc = BVDC_ApplyChanges(video->vdc);
447    if (rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc);goto err_apply_changes;}
448    BDBG_MSG(("<graphics:%#x", graphics->windowVdc));
449
450    return BERR_SUCCESS;
451
452err_apply_changes:
453err_graphics_cfg:
454    cleanup_rc = BVDC_AbortChanges(video->vdc);
455    if (cleanup_rc!=BERR_SUCCESS) { cleanup_rc = BERR_TRACE(cleanup_rc);}
456    cleanup_rc = BVDC_Window_Destroy(graphics->windowVdc);
457    if (cleanup_rc!=BERR_SUCCESS) { cleanup_rc = BERR_TRACE(cleanup_rc);}
458err_window:
459err_source_cfg:
460    cleanup_rc = BVDC_Source_Destroy(graphics->source);
461    if (cleanup_rc!=BERR_SUCCESS) { cleanup_rc = BERR_TRACE(cleanup_rc);}
462err_source:
463    return rc;
464
465}
466
467/* destroy graphics and reset NEXUS_GraphicsSettings based on the current display format */
468void
469NEXUS_Display_P_ResetGraphics(NEXUS_DisplayHandle display)
470{
471    /* if graphics has not been created, we should reset the display dimensions for when it is */
472    NEXUS_Display_P_DestroyGraphics(display);
473
474    display->graphics.cfg.position = display->displayRect;
475    display->graphics.cfg.clip = display->displayRect;
476    display->graphics.validCount = 0;
477    return;
478}
479
480void
481NEXUS_Display_P_DestroyGraphicsSource(NEXUS_DisplayHandle display)
482{
483    BERR_Code rc;
484    struct NEXUS_DisplayGraphics *graphics = &display->graphics;
485    const NEXUS_DisplayModule_State *video= &g_NEXUS_DisplayModule_State;
486   
487    if (!graphics->windowVdc) {
488        return;
489    }
490       
491    graphics->queuedSurface = NULL;
492    rc = BVDC_Window_Destroy(graphics->windowVdc);
493    if(rc!=BERR_SUCCESS) {rc=BERR_TRACE(rc);}
494    rc = BVDC_Source_Destroy(graphics->source);
495    if(rc!=BERR_SUCCESS) {rc=BERR_TRACE(rc);}
496    /* If apply changes fails now, we're in an unrecoverable state, so stop here. */
497    if(video->updateMode != NEXUS_DisplayUpdateMode_eAuto) { rc = BERR_TRACE(NEXUS_NOT_SUPPORTED);}
498    rc = BVDC_ApplyChanges(video->vdc);
499    if(rc!=BERR_SUCCESS) {rc=BERR_TRACE(rc);}
500    graphics->source = NULL;
501    graphics->windowVdc = NULL;
502   
503}
504
505static void
506NEXUS_Display_P_DestroyGraphics(NEXUS_DisplayHandle display)
507{   
508    struct NEXUS_DisplayGraphics *graphics = &display->graphics;   
509
510    if (!graphics->windowVdc) {
511        return;
512    }
513
514    BDBG_MSG((">graphics: destroy %#x", graphics));
515
516    NEXUS_Display_P_DestroyGraphicsSource(display);
517   
518    NEXUS_Graphics_GetDefaultFramebuffer3D(&graphics->frameBuffer3D);   
519
520    BDBG_MSG(("<graphics: destroy %#x", graphics));
521
522    return;
523}
524
525void
526NEXUS_Display_GetGraphicsSettings(NEXUS_DisplayHandle display, NEXUS_GraphicsSettings *settings)
527{
528    BDBG_OBJECT_ASSERT(display, NEXUS_Display);
529    BDBG_ASSERT(settings);
530    *settings = display->graphics.cfg;
531    return;
532}
533
534NEXUS_Error
535NEXUS_Display_SetGraphicsSettings(NEXUS_DisplayHandle display,const NEXUS_GraphicsSettings *settings)
536{
537    struct NEXUS_DisplayGraphics *graphics = &display->graphics;
538    const NEXUS_DisplayModule_State *video= &g_NEXUS_DisplayModule_State;
539    BERR_Code rc;
540
541    BDBG_OBJECT_ASSERT(display, NEXUS_Display);
542    BDBG_ASSERT(settings);
543    if(graphics->windowVdc && !settings->enabled) {
544        NEXUS_Display_P_DestroyGraphics(display);
545    }
546    if(!settings->enabled) {
547        NEXUS_Graphics_GetDefaultFramebuffer3D(&graphics->frameBuffer3D);
548    }
549    if(graphics->frameBuffer3D.main && settings->enabled) {
550        if(graphics->windowVdc) {  /* update existing */
551            rc = NEXUS_Display_P_SetGraphicsSettings(display, settings, false);
552            if (rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc);goto err_graphics_cfg;}
553            rc = NEXUS_Display_P_ApplyChanges();
554            if (rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc);goto err_apply_changes;}
555        } else { /* create new graphics */
556            rc = NEXUS_Display_P_CreateGraphics(display, settings);
557            if(rc!=BERR_SUCCESS) {rc = BERR_TRACE(rc);goto err_create;}
558        }
559    } /* if no frame bufeer or graphics not enabled delay activation of graphics */
560    graphics->cfg = *settings;
561    NEXUS_IsrCallback_Set(graphics->frameBufferCallback, &graphics->cfg.frameBufferCallback);
562    return BERR_SUCCESS;
563
564err_apply_changes:
565err_graphics_cfg:
566    {
567        BERR_Code rc = BVDC_AbortChanges(video->vdc);
568        if(rc!=BERR_SUCCESS) {rc=BERR_TRACE(rc); }
569    }
570err_create:
571    return rc;
572}
573
574NEXUS_Error
575NEXUS_Display_SetGraphicsFramebuffer(NEXUS_DisplayHandle display, NEXUS_SurfaceHandle frameBuffer)
576{
577    NEXUS_Error rc;
578    NEXUS_GraphicsFramebuffer3D framebuffer3D;
579
580    NEXUS_Graphics_GetDefaultFramebuffer3D(&framebuffer3D);
581    framebuffer3D.orientation = NEXUS_VideoOrientation_e2D;
582    framebuffer3D.main = frameBuffer;
583    rc = NEXUS_Display_SetGraphicsFramebuffer3D(display, &framebuffer3D);
584    if(rc!=NEXUS_SUCCESS) {return BERR_TRACE(rc);}
585
586    return rc;
587}
588
589
590NEXUS_Error
591NEXUS_Display_SetGraphicsFramebuffer3D(NEXUS_DisplayHandle display, const NEXUS_GraphicsFramebuffer3D *frameBuffer3D)
592{
593    struct NEXUS_DisplayGraphics *graphics = &display->graphics;
594    const NEXUS_DisplayModule_State *video= &g_NEXUS_DisplayModule_State;
595
596    BERR_Code rc;
597    BDBG_OBJECT_ASSERT(display, NEXUS_Display);
598    BDBG_ASSERT(frameBuffer3D);
599
600
601    if(frameBuffer3D->main==NULL) { return BERR_TRACE(NEXUS_INVALID_PARAMETER); }
602
603    /* Check VDB limits first */
604    if ( !NEXUS_Display_P_GraphicsValid(display, &display->graphics.cfg, frameBuffer3D) )
605    {
606        NEXUS_Display_P_DestroyGraphics(display);
607        return BERR_TRACE(BERR_NOT_SUPPORTED);
608    }
609
610    graphics->frameBuffer3D = *frameBuffer3D;
611    if(graphics->windowVdc) {
612        BSUR_Surface_Handle surface;
613        NEXUS_SurfaceCreateSettings surfaceCfg;
614        bool frameBufferChanged;
615
616        BDBG_ASSERT(graphics->source);
617        NEXUS_Module_Lock(video->modules.surface);
618        surface = NEXUS_Surface_GetSurface_priv(frameBuffer3D->main);
619        BDBG_ASSERT(surface);
620        NEXUS_Module_Unlock(video->modules.surface);
621        NEXUS_Surface_GetCreateSettings(graphics->frameBuffer3D.main, &surfaceCfg);
622        if(graphics->queuedSurface) {
623            BDBG_MSG(("NEXUS_Display_SetGraphicsFramebuffer: %#lx setting duplicated framebuffer %#lx %s", (unsigned long)display, (unsigned long)frameBuffer3D->main, graphics->queuedSurface==surface?"without sync":""));
624        }
625        graphics->queuedSurface = surface;
626        frameBufferChanged = (graphics->frameBufferHeight != surfaceCfg.height || graphics->frameBufferWidth != surfaceCfg.width || graphics->frameBufferPixelFormat != surfaceCfg.pixelFormat);
627        graphics->frameBufferHeight = surfaceCfg.height;
628        graphics->frameBufferWidth = surfaceCfg.width;
629        graphics->frameBufferPixelFormat = surfaceCfg.pixelFormat;
630        rc = NEXUS_Display_P_SetGraphicsSource(display, frameBuffer3D, surface);
631        if (rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc);goto err_set_source;}
632        if(frameBufferChanged) {
633            rc = NEXUS_Display_P_SetGraphicsSettings(display, &graphics->cfg, true);
634            if (rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc);goto err_graphics_cfg;}
635        }
636        rc = NEXUS_Display_P_ApplyChanges();
637        if (rc!=BERR_SUCCESS) { rc = BERR_TRACE(rc);goto err_apply_changes;}
638    } else {
639        if(graphics->cfg.enabled) {
640            rc = NEXUS_Display_P_CreateGraphics(display, &graphics->cfg);
641            if(rc!=BERR_SUCCESS) {rc = BERR_TRACE(rc); goto err_create;}
642        }
643    }
644    return BERR_SUCCESS;
645err_apply_changes:
646err_graphics_cfg:
647    {
648        BERR_Code rc = BVDC_AbortChanges(video->vdc);
649        if(rc!=BERR_SUCCESS) {rc=BERR_TRACE(rc); }
650    }
651err_set_source:
652err_create:
653    return rc;
654}
655
656/* NEXUS_Display_P_InitGraphics is only called from NEXUS_Display_Open */
657BERR_Code
658NEXUS_Display_P_InitGraphics(NEXUS_DisplayHandle display)
659{
660    BERR_Code rc;
661    struct NEXUS_DisplayGraphics *graphics = &display->graphics;
662
663    graphics->source = NULL;
664    graphics->windowVdc = NULL;
665    graphics->frameBufferWidth = 0;
666    graphics->frameBufferHeight = 0;
667    graphics->frameBufferPixelFormat = NEXUS_PixelFormat_eA8_R8_G8_B8;
668    graphics->queuedSurface = NULL;
669    graphics->validCount = 0;
670    NEXUS_Graphics_GetDefaultFramebuffer3D(&graphics->frameBuffer3D);
671    BKNI_Memset(&graphics->cfg, 0, sizeof(graphics->cfg));
672    BKNI_Memset(&graphics->colorMatrix, 0, sizeof(graphics->colorMatrix));
673    graphics->cfg.enabled = true;
674    graphics->cfg.visible = true;
675    /* cfg.position and cfg.clip are set from NEXUS_Display_P_ResetGraphics when the format changes */
676    graphics->cfg.alpha = 0xFF;
677    graphics->cfg.zorder = 2;
678    graphics->cfg.sourceBlendFactor = NEXUS_CompositorBlendFactor_eSourceAlpha;
679    graphics->cfg.destBlendFactor = NEXUS_CompositorBlendFactor_eInverseSourceAlpha;
680    graphics->cfg.constantAlpha = 0xFF;
681    graphics->cfg.horizontalFilter = NEXUS_GraphicsFilterCoeffs_eAnisotropic;
682    NEXUS_CallbackDesc_Init(&graphics->cfg.frameBufferCallback);
683    graphics->frameBufferCallback = NEXUS_IsrCallback_Create(display, NULL);
684    if(!graphics->frameBufferCallback) {
685        rc = BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);
686        goto err_callback;
687    }
688    NEXUS_IsrCallback_Set(graphics->frameBufferCallback, &graphics->cfg.frameBufferCallback);
689    return BERR_SUCCESS;
690err_callback:
691    return rc;
692}
693
694/* NEXUS_Display_P_UninitGraphics is only called from NEXUS_Display_Close */
695void
696NEXUS_Display_P_UninitGraphics(NEXUS_DisplayHandle display)
697{
698    struct NEXUS_DisplayGraphics *graphics = &display->graphics;
699
700    BDBG_OBJECT_ASSERT(display, NEXUS_Display);
701
702    NEXUS_Display_P_DestroyGraphics(display);
703
704    NEXUS_IsrCallback_Destroy(graphics->frameBufferCallback);
705    return;
706}
707
708void NEXUS_Display_GetGraphicsColorMatrix( NEXUS_DisplayHandle display, NEXUS_ColorMatrix *pColorMatrix )
709{
710    BDBG_OBJECT_ASSERT(display, NEXUS_Display);
711    *pColorMatrix = display->graphics.colorMatrix;
712}
713
714NEXUS_Error NEXUS_Display_SetGraphicsColorMatrix( NEXUS_DisplayHandle display, const NEXUS_ColorMatrix *pColorMatrix )
715{
716#ifndef B_HAS_LEGACY_VDC
717    BERR_Code rc;
718
719    BDBG_OBJECT_ASSERT(display, NEXUS_Display);
720
721    if (pColorMatrix) {
722        display->graphics.colorMatrix = *pColorMatrix;
723    }
724
725    if (pColorMatrix) {
726        rc = BVDC_Window_SetColorMatrix(display->graphics.windowVdc, true, pColorMatrix->coeffMatrix, pColorMatrix->shift);
727        if (rc) return BERR_TRACE(rc);
728    }
729    else {
730        rc = BVDC_Window_SetColorMatrix(display->graphics.windowVdc, false, NULL, 0);
731        if (rc) return BERR_TRACE(rc);
732    }
733
734    rc = NEXUS_Display_P_ApplyChanges();
735    if (rc) return BERR_TRACE(rc);
736#else
737    BSTD_UNUSED(display);
738    BSTD_UNUSED(pColorMatrix);
739#endif
740    return 0;
741}
742
743void NEXUS_Display_GetGraphicsColorSettings( NEXUS_DisplayHandle display, NEXUS_GraphicsColorSettings *pSettings )
744{
745    BERR_Code rc;
746
747    BDBG_OBJECT_ASSERT(display, NEXUS_Display);
748
749    BKNI_Memset(pSettings, 0, sizeof(*pSettings));
750
751    rc = BVDC_Window_GetContrast(display->graphics.windowVdc, &pSettings->contrast);
752    if (rc) rc = BERR_TRACE(rc);
753    rc = BVDC_Window_GetSaturation(display->graphics.windowVdc, &pSettings->saturation);
754    if (rc) rc = BERR_TRACE(rc);
755    rc = BVDC_Window_GetHue(display->graphics.windowVdc, &pSettings->hue);
756    if (rc) rc = BERR_TRACE(rc);
757    rc = BVDC_Window_GetBrightness(display->graphics.windowVdc, &pSettings->brightness);
758    if (rc) rc = BERR_TRACE(rc);
759}
760
761NEXUS_Error NEXUS_Display_SetGraphicsColorSettings( NEXUS_DisplayHandle display, const NEXUS_GraphicsColorSettings *pSettings )
762{
763    BERR_Code rc;
764
765    BDBG_OBJECT_ASSERT(display, NEXUS_Display);
766
767    rc = BVDC_Window_SetContrast(display->graphics.windowVdc, pSettings->contrast);
768    if (rc) return BERR_TRACE(rc);
769    rc = BVDC_Window_SetSaturation(display->graphics.windowVdc, pSettings->saturation);
770    if (rc) return BERR_TRACE(rc);
771    rc = BVDC_Window_SetHue(display->graphics.windowVdc, pSettings->hue);
772    if (rc) return BERR_TRACE(rc);
773    rc = BVDC_Window_SetBrightness(display->graphics.windowVdc, pSettings->brightness);
774    if (rc) return BERR_TRACE(rc);
775    rc = NEXUS_Display_P_ApplyChanges();
776    if (rc) return BERR_TRACE(rc);
777
778    return 0;
779}
780
781static bool NEXUS_Display_P_GraphicsValid(NEXUS_DisplayHandle display, const NEXUS_GraphicsSettings *pSettings, const NEXUS_GraphicsFramebuffer3D *framebuffer3d)
782{
783    bool valid=true;
784    NEXUS_SurfaceHandle framebuffer = framebuffer3d->main;
785
786    if ( pSettings->enabled )
787    {
788        if ( 0 == display->restrictions.gfxHeight )
789        {
790            BDBG_ERR(("Graphics is not supported on display %d due to bandwidth restrictions."));
791            valid = false;
792        }
793        else
794        {
795            NEXUS_SurfaceCreateSettings createSettings;
796            unsigned bpp;
797
798            NEXUS_Surface_GetCreateSettings(framebuffer, &createSettings);
799            bpp = NEXUS_Vdb_P_GetBpp(createSettings.pixelFormat);
800            if ( createSettings.bitsPerPixel == 0 && display->restrictions.specialFeature1 != 0 )
801            {
802                BDBG_ERR(("Graphics bitsPerPixel setting is invalid for a framebuffer in this usage mode."));
803                BDBG_ERR(("Please set NEXUS_SurfaceCreateSettings.bitsPerPixel to a non-zero value <= %d.", display->restrictions.specialFeature1));
804                valid = false;
805            }
806            else if ( createSettings.bitsPerPixel > display->restrictions.specialFeature1 && g_NEXUS_DisplayModule_State.moduleSettings.handleDynamicRts )
807            {
808                BDBG_ERR(("Graphics bitsPerPixel setting is invalid for a framebuffer in this usage mode."));
809                if ( display->restrictions.specialFeature1 )
810                {
811                    BDBG_ERR(("Please set NEXUS_SurfaceCreateSettings.bitsPerPixel to a non-zero value <= %d.", display->restrictions.specialFeature1));
812                }
813                else
814                {
815                    BDBG_ERR(("Please do not specify a bitsPerPixel value for the framebuffer in this usage mode."));
816                }
817                valid = false;
818            }
819            if ( pSettings->clip.height > display->restrictions.gfxHeight ||
820                 pSettings->clip.width > display->restrictions.gfxWidth ||
821                 bpp > display->restrictions.gfxBpp )
822            {
823                BDBG_ERR(("Graphics resolution (%dx%d %dbpp) is above current system limitations (%dx%d %dbpp).",
824                          pSettings->clip.width, pSettings->clip.height, NEXUS_Vdb_P_GetBpp(createSettings.pixelFormat),
825                          display->restrictions.gfxWidth, display->restrictions.gfxHeight, display->restrictions.gfxBpp));
826                valid = false;
827            }
828            if (createSettings.bitsPerPixel != 0 &&
829                (pSettings->clip.x || pSettings->clip.y || createSettings.width != pSettings->clip.width || createSettings.height != pSettings->clip.height))
830            {
831                BDBG_ERR(("Cannot clip a framebuffer with non-zero NEXUS_SurfaceCreateSettings.bitsPerPixel"));
832                valid = false;
833            }
834        }
835    }
836
837    if ( !valid )
838    {
839        BDBG_ERR(("Disabling Graphics."));
840    }
841
842    return valid;
843}
844
845void NEXUS_Graphics_GetDefaultFramebuffer3D(NEXUS_GraphicsFramebuffer3D *pFramebuffer3D)
846{
847    BDBG_ASSERT(pFramebuffer3D);
848    BKNI_Memset(pFramebuffer3D, 0, sizeof(*pFramebuffer3D));
849    pFramebuffer3D->orientation = NEXUS_VideoOrientation_e2D;
850    pFramebuffer3D->main = NULL;
851    return;
852}
853
Note: See TracBrowser for help on using the repository browser.