⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 textst_render.cpp

📁 这是DVD中伺服部分的核心代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
                case 0x02:
                    DBGPRINT(DBG_ON(DBG_TRACE), ("textstrenderDPSRender: Inline font set change!\n"));

                    /* set flag to indicate inline font change */
                    fInlineFontChange = TRUE;

                    /* release current font */
                    font->Release(font);
                    font = NULL;

                    /* set font id */
                    ubFontID = pRenderInfo->region_subtitle[i].inline_style_values[ubInlineStyleIndex];
                    if (ubFontID >= hTextST->ubNumberOfFonts)
                    {
                        DBGPRINT(DBG_ON(DBG_ERROR), ("textstrenderDPSRender: Invalid font id (%u), dps # = %lu!\n", ubFontID, pBmpObj->dps_number));
                        goto errout;
                    }

                    /* Create the font for the text subtitle */
                    if (hTextST->DFBInfo.pDFBHandle->CreateMemoryFont(hTextST->DFBInfo.pDFBHandle, hTextST->font_info[ubFontID].pvFontBuffer, 
                                                                      hTextST->font_info[ubFontID].uiBufferSize, &font_dsc, &font) != DFB_OK)
                    {
                        DBGPRINT(DBG_ON(DBG_ERROR), ("textstrenderDPSRender: Failed to create font!\n"));
                        goto errout;
                    }

                    /* Set the font for the surface */
                    if (pBmpObj->surface[i]->SetFont(pBmpObj->surface[i], font) != DFB_OK)
                    {
                        DBGPRINT(DBG_ON(DBG_ERROR), ("textstrenderDPSRender: Failed to set font for surface!\n"));
                        goto errout;
                    }

                    /* increment inline style index */
                    ubInlineStyleIndex++;
                    break;
                case 0x03:
                    /* increment inline style index */
                    ubInlineStyleIndex++;
                    break;
                case 0x04:
                    DBGPRINT(DBG_ON(DBG_TRACE), ("textstrenderDPSRender: Inline font size change!\n"));

                    /* set flag to indicate inline font change */
                    fInlineFontChange = TRUE;

                    /* release current font */
                    font->Release(font);
                    font = NULL;

                    /* set new font description */
                    font_dsc.flags  = DFDESC_HEIGHT;
                    font_dsc.height = pRenderInfo->region_subtitle[i].inline_style_values[ubInlineStyleIndex];

                    /* Create the font for the text subtitle */
                    if (hTextST->DFBInfo.pDFBHandle->CreateMemoryFont(hTextST->DFBInfo.pDFBHandle, hTextST->font_info[ubFontID].pvFontBuffer, 
                                                                      hTextST->font_info[ubFontID].uiBufferSize, &font_dsc, &font) != DFB_OK)
                    {
                        DBGPRINT(DBG_ON(DBG_ERROR), ("textstrenderDPSRender: Failed to create font!\n"));
                        goto errout;
                    }

                    /* Set the font for the surface */
                    if (pBmpObj->surface[i]->SetFont(pBmpObj->surface[i], font) != DFB_OK)
                    {
                        DBGPRINT(DBG_ON(DBG_ERROR), ("textstrenderDPSRender: Failed to set font for surface!\n"));
                        goto errout;
                    }

                    /* increment inline style index */
                    ubInlineStyleIndex++;
                    break;
                case 0x05:
                    DBGPRINT(DBG_ON(DBG_TRACE), ("textstrenderDPSRender: Inline text color change!\n"));

                    /* set flag to indicate inline color change */
                    fInlineColorChange = TRUE;

                    /* change text color */
                    if (pBmpObj->surface[i]->SetColorIndex(pBmpObj->surface[i], pRenderInfo->region_subtitle[i].inline_style_values[ubInlineStyleIndex]) != DFB_OK)
                    {
                        DBGPRINT(DBG_ON(DBG_ERROR), ("textstrenderDPSRender: Failed to set default text color index!\n"));
                        goto errout;
                    }

                    /* increment inline style index */
                    ubInlineStyleIndex++;
                    break;
                case 0x0A:
                    DBGPRINT(DBG_ON(DBG_TRACE), ("textstrenderDPSRender: Inline Line Break!\n"));

                    /* line break */
                    usXoffset   = 0;
                    usYcoord   += hTextST->pDSS->region_style[ubRegionID].line_space;
                    break;
                case 0x0B:
                    DBGPRINT(DBG_ON(DBG_TRACE), ("textstrenderDPSRender: End of Inline Style!\n"));

                    if (fInlineColorChange)
                    {
                        /* change back to default text color */
                        if (pBmpObj->surface[i]->SetColorIndex(pBmpObj->surface[i], hTextST->pDSS->region_style[ubRegionID].font_palette_entry_id_ref) != DFB_OK)
                        {
                            DBGPRINT(DBG_ON(DBG_ERROR), ("textstrenderDPSRender: Failed to set default text color index!\n"));
                            goto errout;
                        }
                    }

                    if (fInlineFontChange)
                    {
                        /* release current font */
                        font->Release(font);
                        font = NULL;
    
                        /* set font id back to the default */
                        ubFontID = hTextST->pDSS->region_style[ubRegionID].font_id_ref;

                        /* set default font description */
                        font_dsc.flags  = DFDESC_HEIGHT;
                        font_dsc.height = ubFontSize;

                        /* Create the font for the text subtitle */
                        if (hTextST->DFBInfo.pDFBHandle->CreateMemoryFont(hTextST->DFBInfo.pDFBHandle, hTextST->font_info[ubFontID].pvFontBuffer, 
                                                                          hTextST->font_info[ubFontID].uiBufferSize, &font_dsc, &font) != DFB_OK)
                        {
                            DBGPRINT(DBG_ON(DBG_ERROR), ("textstrenderDPSRender: Failed to create font!\n"));
                            goto errout;
                        }

                        /* Set the font for the surface */
                        if (pBmpObj->surface[i]->SetFont(pBmpObj->surface[i], font) != DFB_OK)
                        {
                            DBGPRINT(DBG_ON(DBG_ERROR), ("textstrenderDPSRender: Failed to set font for surface!\n"));
                            goto errout;
                        }
                    }

                    /* reset flags */
                    fInlineColorChange  = FALSE;
                    fInlineFontChange   = FALSE;
                    break;
                default:
                    break;
                }

                /* increment inline style index */
                ubInlinePosIndex++;
            }
        }

        /* Delete font */
        font->Release(font);
        font = NULL;
    }

    return (TEXTST_SUCCESS);

errout:

    if (font != NULL)
    {
        font->Release(font);
    }      
                        
    for (i = 0; i < pBmpObj->ubNumberOfRegions; i++)
    {
        if (pBmpObj->surface[i] != NULL)
        {
            pBmpObj->surface[i]->Release(pBmpObj->surface[i]);
        }
    }

    return (TEXTST_FAILURE);
}

/**
 * TextSTRenderTask -- Thread in which all TextST Rendering occurs.
 */
static ULONG TextSTRenderTask(PVOID pvParam)
{
    TEXTST_INFO             *hTextST                             = (TEXTST_INFO *)pvParam;
    TEXTST_RENDER_INFO      *pRenderInfo                         = NULL;
    PVOID                   pvBmpBuf[TEXTST_MAX_REGIONS_PER_DPS] = {NULL, NULL};
    TEXTST_BITMAP_OBJECT    BmpObj;
    TEXTST_STATUS           tStatus;
    ULONG                   ulBmpSize;
    int                     i;

    DBGPRINT(DBG_ON(DBG_TRACE), ("TextSTRenderTask: Started\n"));

    while (hTextSTRender->fExitPending == FALSE)
    {
        tStatus = TEXTST_SUCCESS;

        if (hTextSTRender->fSuspendPending == TRUE)
        {
            /* Signal that renderer is now suspended */
            OS_SemGive(hTextSTRender->semSynch);

            /* Wait until TextST renderer is resumed */
            OS_SemTake(hTextSTRender->semSuspend, OS_WAIT_FOREVER);
        }

        DBGPRINT(DBG_ON(DBG_VERBOSE), ("TextSTRenderTask: Wait for message\n"));

        /* Wait for a message */
        if (OS_MsgQReceive(hTextSTRender->MsgQID, (char *)&pRenderInfo, sizeof(TEXTST_RENDER_INFO *), OS_WAIT_FOREVER) != OS_OK)
        {
            DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTRenderTask: Failure receiving message!\n"));
            hTextSTRender->fExitPending = TRUE;
        }
        else
        {
            if (pRenderInfo == NULL)
            {
                continue;
            }
            else
            {
                pvBmpBuf[0] = pvBmpBuf[1] = NULL;

                DBGPRINT(DBG_ON(DBG_VERBOSE), ("TextSTRenderTask: Got Render Info\n"));

                if (pRenderInfo->number_of_regions <= 2)
                {
                    for (i = 0; i < pRenderInfo->number_of_regions; i++)
                    {
                        while ( (pvBmpBuf[i] == NULL) && (hTextSTRender->fSuspendPending == FALSE) )
                        {
                            /* Determine the bitmap size */
                            ulBmpSize =
                                hTextST->pDSS->region_style[pRenderInfo->region_style_id_ref[i]].region_info.region_width *
                                hTextST->pDSS->region_style[pRenderInfo->region_style_id_ref[i]].region_info.region_height;

                            /* Check if size is valid */
                            if ( (ulBmpSize > TEXTST_BOB_SIZE) || (ulBmpSize == 0) )
                            {
                                DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTRenderTask: Bitmap Size Invalid! DPS=%lu, Size=%u\n",
                                    pRenderInfo->dps_number, ulBmpSize));
                                tStatus = TEXTST_FAILURE;
                                break;
                            }

                            /* Entering BOB critical section */
                            OS_SemTake(hTextST->semBOB, OS_WAIT_FOREVER);

                            /* Allocate a buffer from the Bitmap Object Buffer for the rendered bitmap */
                            pvBmpBuf[i] = OS_MemPoolAlloc(hTextST->mempoolBOB, ulBmpSize);

                            /* Leaving BOB Critical Section */
                            OS_SemGive(hTextST->semBOB);

                            if (pvBmpBuf[i] == NULL)
                            {
                                DBGPRINT(DBG_ON(DBG_VERBOSE), ("TextSTRenderTask: Bitmap Object Buffer full!\n"));
                                OS_TaskYield();
                            }
                        }

                        if (tStatus != TEXTST_SUCCESS)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTRenderTask: Invalid number of regions!\n"));
                    tStatus = TEXTST_FAILURE;
                }

                if ( (tStatus != TEXTST_SUCCESS) || (hTextSTRender->fSuspendPending == TRUE) )
                {
                    /* Entering BOB critical section */
                    OS_SemTake(hTextST->semBOB, OS_WAIT_FOREVER);

                    for (i = 0; i < pRenderInfo->number_of_regions; i++)
                    {
                        if (pvBmpBuf[i] != NULL)
                        {
                            /* Free memory from Bitmap Object Buffer */
                            if (OS_MemPoolFree(hTextST->mempoolBOB, pvBmpBuf[i]) != OS_OK)
                            {
                                DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTRenderTask: Failed to release buffer!\n"));
                            }
                        }
                    }

                    /* Leaving BOB Critical Section */
                    OS_SemGive(hTextST->semBOB);

                    /* Entering DB critical section */
                    OS_SemTake(hTextST->semDB, OS_WAIT_FOREVER);

                    /* Free memory from Dialog Buffer */
                    if (OS_MemPoolFree(hTextST->mempoolDB, pRenderInfo) != OS_OK)
                    {
                        DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTRenderTask: Failed to release from DB!\n"));
                    }

                    /* Leaving DB Critical Section */
                    OS_SemGive(hTextST->semDB);

                    continue;
                }

                /* Set Bitmap Object information */
                BmpObj.dps_number           = pRenderInfo->dps_number;
                BmpObj.ubNumberOfRegions    = pRenderInfo->number_of_regions;
                BmpObj.pvBitmapBuffer[0]    = pvBmpBuf[0];
                BmpObj.pvBitmapBuffer[1]    = pvBmpBuf[1];
                BmpObj.surface[0]           = NULL;
                BmpObj.surface[1]           = NULL;

                /* Render the DPS */
                if (textstrenderDPSRender(hTextST, pRenderInfo, &BmpObj) != TEXTST_SUCCESS)
                {
                    DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTRenderTask: textstrenderDPSRender() Failed!\n"));
                    tStatus = TEXTST_FAILURE;
                }
                else
                {
                    /* Add bitmap object to the Presentation Controller bitmap queue */
                    if (TextSTPresCtrlAddBmpObj(&BmpObj) != TEXTST_SUCCESS)
                    {
                        DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTRenderTask: TextSTPresCtrlAddBmpObj() Failed!\n"));
                        tStatus = TEXTST_FAILURE;
                    }
                }

                /* Entering DB critical section */
                OS_SemTake(hTextST->semDB, OS_WAIT_FOREVER);

                /* Free memory from Dialog Buffer */
                if (OS_MemPoolFree(hTextST->mempoolDB, pRenderInfo) != OS_OK)
                {
                    DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTRenderTask: Failed to release from DB!\n"));
                }

                /* Leaving DB Critical Section */
                OS_SemGive(hTextST->semDB);

                if (tStatus != TEXTST_SUCCESS)
                {
                    /* Entering BOB critical section */
                    OS_SemTake(hTextST->semBOB, OS_WAIT_FOREVER);

                    for (i = 0; i < BmpObj.ubNumberOfRegions; i++)
                    {
                        if (pvBmpBuf[i] != NULL)
                        {
                            /* Free memory from Bitmap Object Buffer */
                            if (OS_MemPoolFree(hTextST->mempoolBOB, pvBmpBuf[i]) != OS_OK)
                            {
                                DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTRenderTask: Failed to release buffer!\n"));
                            }
                        }
                    }

                    /* Leaving BOB Critical Section */
                    OS_SemGive(hTextST->semBOB);
                }
            }
        }
    }

    DBGPRINT(DBG_ON(DBG_TRACE), ("TextSTRenderTask: Exitting\n"));

    /* exit task */
    OS_TaskExit();

    return (0);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -