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

📄 textst_presctrl.cpp

📁 这是DVD中伺服部分的核心代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
            else
            {
                // left
                ulXcoord -= hTextSTPresCtrl->hTextST->pDSS->region_style[ubRegionID].user_control_style[hTextSTPresCtrl->hTextST->ubUserStyleID].region_horizontal_position_delta;
            }

            /* adjust vertical coordinates based on user style selected */
            if (hTextSTPresCtrl->hTextST->pDSS->region_style[ubRegionID].user_control_style[hTextSTPresCtrl->hTextST->ubUserStyleID].region_vertical_position_direction == 0)
            {
                // down
                ulYcoord += hTextSTPresCtrl->hTextST->pDSS->region_style[ubRegionID].user_control_style[hTextSTPresCtrl->hTextST->ubUserStyleID].region_vertical_position_delta;
            }
            else
            {
                // up
                ulYcoord -= hTextSTPresCtrl->hTextST->pDSS->region_style[ubRegionID].user_control_style[hTextSTPresCtrl->hTextST->ubUserStyleID].region_vertical_position_delta;
            }
        }

        DBGPRINT(DBG_ON(DBG_TRACE), ("textstpresctrlDisplayDPS: DPS #%ld, Region %d - x = %d, y = %d\n",
            pBmpObj->dps_number, i, ulXcoord, ulYcoord));

        /*
         * Blit from the DPS's bitmap object surface to the primary display surface.
         */
        if (hTextSTPresCtrl->hTextST->DFBInfo.PrimarySurface->Blit(hTextSTPresCtrl->hTextST->DFBInfo.PrimarySurface, pBmpObj->surface[i], NULL, ulXcoord, ulYcoord) != DFB_OK)
        {
            DBGPRINT(DBG_ON(DBG_ERROR), ("textstpresctrlDisplayDPS: Failed to blit bitmap object!\n"));
            return (TEXTST_FAILURE);
        }
    }

    /* Flip primary surface */
    TextSTPresCtrlFlip();

    return (TEXTST_SUCCESS);
}

/**
 * textstpresctrlReleaseBitmapObj -- Release bitmap object.
 *
 * @param
 *      pBmpObj -- pointer to bitmap object
 *
 * @retval
 *      TEXTST_STATUS
 */
TEXTST_STATUS  textstpresctrlReleaseBitmapObj(TEXTST_BITMAP_OBJECT *pBmpObj)
{
    TEXTST_STATUS status = TEXTST_SUCCESS;

    if (pBmpObj == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("textstpresctrlReleaseBitmapObj: NULL pointer!\n"));
        return (TEXTST_FAILURE);
    }

    if (pBmpObj->fValid == TRUE)
    {
        /* Entering BOB critical section */
        OS_SemTake(hTextSTPresCtrl->hTextST->semBOB, OS_WAIT_FOREVER);

        for (int i = 0; i < pBmpObj->ubNumberOfRegions; i++)
        {
            if (pBmpObj->surface[i] != NULL)
            {
                /* Delete directfb surface */
                pBmpObj->surface[i]->Release(pBmpObj->surface[i]);
            }

            if (pBmpObj->pvBitmapBuffer[i] != NULL)
            {
                /* Free memory from Bitmap Object Buffer */
                if (OS_MemPoolFree(hTextSTPresCtrl->hTextST->mempoolBOB, pBmpObj->pvBitmapBuffer[i]) != OS_OK)
                {
                    DBGPRINT(DBG_ON(DBG_ERROR), ("textstpresctrlReleaseBitmapObj: Failed to release buffer!\n"));
                    status = TEXTST_FAILURE;
                }
            }
        }

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

    return (status);
}

/**
 * textstpresctrlReleaseCompInfo -- Release bitmap object.
 *
 * @param
 *      pCompInfo -- pointer to composition object
 *
 * @retval
 *      TEXTST_STATUS
 */
TEXTST_STATUS  textstpresctrlReleaseCompInfo(TEXTST_COMPOSITION_INFO *pCompInfo)
{
    TEXTST_STATUS status = TEXTST_SUCCESS;

    if (pCompInfo != NULL)
    {
        /* Entering DCB critical section */
        OS_SemTake(hTextSTPresCtrl->hTextST->semDCB, OS_WAIT_FOREVER);

        /* Free memory from Composition Buffer */
        if (OS_MemPoolFree(hTextSTPresCtrl->hTextST->mempoolDCB, pCompInfo) != OS_OK)
        {
            DBGPRINT(DBG_ON(DBG_ERROR), ("textstpresctrlReleaseCompInfo: Failed to release from DCB!\n"));
            status = TEXTST_FAILURE;
        }

        /* Leaving DCB Critical Section */
        OS_SemGive(hTextSTPresCtrl->hTextST->semDCB);
    }

    return (status);
}

/**
 * textstpresctrlMakeARGBfromYCrCb601 - color space conversion from YCrCbT to RGB
 *
 * @param y - y component
 * @param cr - cr component
 * @param cb - cb component
 *
 * @return
 * int - 32 bit pixel code with byte position in RGB0 format
 */
ULONG textstpresctrlMakeARGBfromYCrCb601(BYTE y, BYTE cr, BYTE cb, BYTE t)
{
    ULONG pixel32;
    BYTE *pixel = (BYTE *)&pixel32;
    int r, g, b;

    r = y + (int)(1.370705 * (cr-128));
    g = y - (int)((0.698001 * (cr-128)) - (0.337633 * (cb-128)));
    b = y + (int)(1.732446 * (cb-128));

    if (r > 255) r = 255;
    if (g > 255) g = 255;
    if (b > 255) b = 255;

    /* pre-multiply alpha */
    r = (t * r + 127) / 255;
    b = (t * b + 127) / 255;
    g = (t * g + 127) / 255;

    if (r < 0) r = 0;
    if (g < 0) g = 0;
    if (b < 0) b = 0;

    pixel[0] = t;
    pixel[1] = r;
    pixel[2] = g;
    pixel[3] = b;  // fully opaque

    return pixel32;
}

/**
 * textstpresctrlMakeARGBfromYCrCb709 - color space conversion from YCrCbT to RGB
 *
 * @param y - y component
 * @param cr - cr component
 * @param cb - cb component
 *
 * @return
 * int - 32 bit pixel code with byte position in RGB0 format
 */
ULONG textstpresctrlMakeARGBfromYCrCb709(BYTE y, BYTE cr, BYTE cb, BYTE t)
{
    ULONG pixel32;
    BYTE *pixel = (BYTE *)&pixel32;
    int r, g, b;

    r = y + (int)(1.540 * (cr-128));
    g = y - (int)((0.459 * (cr-128)) - (0.183 * (cb-128)));
    b = y + (int)(1.816 * (cb-128));

    if (r > 255) r = 255;
    if (g > 255) g = 255;
    if (b > 255) b = 255;

    /* pre-multiply alpha */
    r = (t * r + 127) / 255;
    b = (t * b + 127) / 255;
    g = (t * g + 127) / 255;

    if (r < 0) r = 0;
    if (g < 0) g = 0;
    if (b < 0) b = 0;

    pixel[0] = t;
    pixel[1] = r;
    pixel[2] = g;
    pixel[3] = b;  // fully opaque

    return pixel32;
}


/**
 * TextSTPresCtrlTask -- Thread in which all TextST Presentation Control processing occurs.
 */
static ULONG TextSTPresCtrlTask(PVOID pvParam)
{
    TEXTST_INFO             *hTextST    = (TEXTST_INFO *)pvParam;
    TEXTST_COMPOSITION_INFO *pCompInfo  = NULL;
    TEXTST_BITMAP_OBJECT    BmpObj;

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

    while (hTextSTPresCtrl->fExitPending == FALSE)
    {
        if (hTextSTPresCtrl->fSuspendPending == TRUE)
        {
            /* Signal that presentation controller is now suspended */
            OS_SemGive(hTextSTPresCtrl->semSynch);

            /* Wait until presentation controller is resumed */
            OS_SemTake(hTextSTPresCtrl->semSuspend, OS_WAIT_FOREVER);
        }

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

        /* Wait for a composition message */
        if (OS_MsgQReceive(hTextSTPresCtrl->CompMsgQID, (char *)&pCompInfo, sizeof(TEXTST_COMPOSITION_INFO *), OS_WAIT_FOREVER) != OS_OK)
        {
            DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTPresCtrlTask: Failure receiving message!\n"));
            hTextSTPresCtrl->fExitPending = TRUE;
        }
        else
        {
            if (pCompInfo != NULL)
            {
                DBGPRINT(DBG_ON(DBG_VERBOSE), ("TextSTPresCtrlTask: Got Composition Info\n"));

                /*
                 * If there is a palette update for this dps, then just do the palette update.
                 */
                if (pCompInfo->palette_update_flag == 1)
                {
                    /*
                     * If this is not the first DPS being presented, then just wait until
                     * presentation time to update the palette.  Otherwise, we need to display
                     * the rendered bitmap object on the primary surface.
                     */
                    if (pCompInfo->fFirstDPS != TRUE)
                    {
                        /* Set start pts of the current dps */
                        hTextST->ulWaitStartPTS = (ULONG)(pCompInfo->presentation_start_time);

                        DBGPRINT(DBG_ON(DBG_TRACE), ("TextSTPresCtrlTask: Waiting for start PTS for palette update: 0x%08x\n", hTextST->ulWaitStartPTS));

                        /*
                         * Wait for start PTS...
                         */
                        OS_SemTake(hTextSTPresCtrl->semPresentation, OS_WAIT_FOREVER);

                        /* Set the end pts for this dps */
                        if (pCompInfo->continuous_present_flag == 1)
                        {
                            /*
                             * Continuous presentation between this DPS and the next, so do not want
                             * to erase this dps at the end pts, so just set the end pts to invalid.
                             */
                            hTextST->ulWaitEndPTS = 0xffffffff;
                        }
                        else
                        {
                            hTextST->ulWaitEndPTS = (ULONG)(pCompInfo->presentation_end_time);
                        }
                    }

                    /* Load the new palette definition */
                    if (TextSTPresCtrlLoadPalette(&pCompInfo->palette, hTextST->DFBInfo.dfb_palette) != TEXTST_SUCCESS)
                    {
                        DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTPresCtrlTask: Failure loading palette!\n"));
                    }

                    /* Only set the new palette to the surface if display is on */
                    if (hTextST->tDisplay == TEXTST_DISPLAY_ON)
                    {
                        /* Set the new palette to surface */
                        if (TextSTPresCtrlSetPalette(hTextST->DFBInfo.dfb_palette) != TEXTST_SUCCESS)
                        {
                            DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTPresCtrlTask: Failure setting palette!\n"));
                        }
                    }

                    /*
                     * Flip primary surface to show palette change (only if this is not
                     * the first dps)
                     */
                    if (pCompInfo->fFirstDPS != TRUE)
                    {
                        TextSTPresCtrlFlip();
                    }
                }

                /*
                 * If this is not a palette update -OR- if this is the first DPS being
                 * presented, then we need to get the bitmap object for this DPS and
                 * display it on the primary surface.
                 */
                if ( (pCompInfo->palette_update_flag == 0) || (pCompInfo->fFirstDPS == TRUE) )
                {
                    do
                    {
                        /* Wait for a bitmap object message */
                        if (OS_MsgQReceive(hTextSTPresCtrl->BmpMsgQID, (char *)&BmpObj, sizeof(TEXTST_BITMAP_OBJECT), OS_WAIT_FOREVER) != OS_OK)
                        {
                            DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTPresCtrlTask: Failure receiving message!\n"));
                            hTextSTPresCtrl->fExitPending = TRUE;
                            break;
                        }

                        /* Check that message is valid */
                        if (BmpObj.fValid == FALSE)
                        {
                            break;
                        }

                        if (BmpObj.dps_number < pCompInfo->dps_number)
                        {
                            DBGPRINT(DBG_ON(DBG_TRACE), ("TextSTPresCtrlTask: Throwing away bitmap object!\n"));

                            /* Relese bitmap object */
                            textstpresctrlReleaseBitmapObj(&BmpObj);
                        }
                    } while (BmpObj.dps_number < pCompInfo->dps_number);

                    if ( (hTextSTPresCtrl->fExitPending != TRUE) && (hTextSTPresCtrl->fSuspendPending != TRUE) &&
                         (BmpObj.fValid == TRUE) && (BmpObj.dps_number == pCompInfo->dps_number) )
                    {
                        /* Set start pts of the current dps */
                        hTextST->ulWaitStartPTS = (ULONG)(pCompInfo->presentation_start_time);

                        DBGPRINT(DBG_ON(DBG_TRACE), ("TextSTPresCtrlTask: Waiting for start PTS: 0x%08x\n", hTextST->ulWaitStartPTS));

                        /*
                         * Wait for start PTS...
                         */
                        OS_SemTake(hTextSTPresCtrl->semPresentation, OS_WAIT_FOREVER);

                        /* Set the end pts for this dps */
                        if (pCompInfo->continuous_present_flag == 1)
                        {
                            /*
                             * Continuous presentation between this DPS and the next, so do not want
                             * to erase this dps at the end pts, so just set the end pts to invalid.
                             */
                            hTextST->ulWaitEndPTS = 0xffffffff;
                        }
                        else
                        {
                            hTextST->ulWaitEndPTS = (ULONG)(pCompInfo->presentation_end_time);
                        }

                        /* If suspending, then do not display dps */
                        if (hTextSTPresCtrl->fSuspendPending == FALSE)
                        {
                            /*
                             * If display is off, but the forced on flag is set, then
                             * turn the display on.
                             */
                            if ( (hTextST->tDisplay == TEXTST_DISPLAY_OFF) &&
                                 ( (pCompInfo->forced_on_flag[0] == 1) || (pCompInfo->forced_on_flag[1] == 1) ) )
                            {
                                /* Set display state to on */
                                hTextST->tDisplay = TEXTST_DISPLAY_ON;

                                DBGPRINT(DBG_ON(DBG_TRACE), ("TextSTPresCtrlTask: forcing textst on\n"));

                                /* Set the display palette to the primary surface */
                                TextSTPresCtrlSetPalette(hTextST->DFBInfo.dfb_palette);
                            }

                            /* display dps */
                            if (textstpresctrlDisplayDPS(&BmpObj, pCompInfo) != TEXTST_SUCCESS)
                            {
                                DBGPRINT(DBG_ON(DBG_ERROR), ("TextSTPresCtrlTask: Failed to display DPS!\n"));
                            }
                        }
                    }

                    /* Relese bitmap object */
                    textstpresctrlReleaseBitmapObj(&BmpObj);
                }

                /* Release composition object */
                textstpresctrlReleaseCompInfo(pCompInfo);
            }
        }
    }

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

    /* exit task */
    OS_TaskExit();

    return (0);
}

⌨️ 快捷键说明

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