mini6410 2D driver (FIMG-2D)

Bobris
Hello FriendlyARM guys!

I am extremely disappointed by the fact that you do not supply source code
for 2D drivers for mini6410 despite your claim that you do.

In fact the drivers provided for 2D ( 3D, JPEG, CMM ... ) are completely
useless for anyone mostly because you chose not to include source code and
header files that are provided lack definitions of data structures used for
ioctl calls. IMHO it would be better if you would not provide any drivers
at all. 

You can argue that there are source code for drivers on the DVD, but these
apparently DO NOT match drivers actually used (and are buggy, and in
general do not work at all).

So to anyone trying to use 2D driver for mini6410 - make yourself a favor,
write your own driver and you will save a lot of time trying to get the
provided drivers to work (you will not succeed and you cannot, simply
because there are no source codes provided)

And for anyone needing hw accelerated 2D graphics - find a different
product or you will be left on your own and will end up writing your own
driver.

Cheers.
Bobris.

Juergen Beisert
For Android a complete useable solution for 2D and 3D acceleration for the
S3C6410 CPU is available and completely as open source.

Bobris
Really? where? Not in android kernel. Same thing as with linux, no sources,
only prebuild.fo file.

In any case, I assume android sources would use pmem, which is not
available in linux kernel ( unless you add it there by yourself )

Juergen Beisert
Take a look here: https://github.com/tom3q/openfimg

Bobris
Juergen, thank you for your attempt to help, however when you have a look
at the openfimg - there is no 2D driver at all there.

What I am really interested in is bitblt operations to go as fast as
possible. The s3c6410 processor has hardware support for this. Its
documentation isn't really great, but at least something. I was hoping that
there would be a driver (and there is at least some attempt for driver).
What really strikes me is why there are NO SOURCES for it, and why guys
from friendly arm are making it impossible to use existing driver by not
providing data structures used in ioctl calls.

Dezso
found some info here
http://sjmt6410pm090728.googlecode.com/svn/trunk/

//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft
end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to
use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on
your
// install media.
//
// Copyright (c) Samsung Electronics. Co. LTD. All rights reserved.

/*++

THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

Module Name:    hwblt.cpp

Abstract:   accelerated bitblt/rectangle for S3C6410 FIMGSE-2D

Functions:  HWBitBlt


Notes:


--*/

#include "precomp.h"

/**
*   @fn     void S3C6410Disp::HWBitBlt(GpeBltParms *pBltParms)
*   @brief  Check Further Optional processing. This is intemediate layer
between display driver and 2D driver
*   @param  pBltParms Blit Parameter Information Structure
*   @sa     GPEBltParms
*   @note   currently support only rotation
*   @note   DMDO_0 = 0, DMDO_90 = 1, DMDO_180 = 2, DMDO_270 = 4
*/
BOOL S3C6410Disp::HWBitBlt(GPEBltParms *pBltParms, PSURFACE_DESCRIPTOR
pdescSrcSurface, PSURFACE_DESCRIPTOR pdescDstSurface)
{
    PRECTL  prclSrc;     //< Src is already rotated.
    PRECTL  prclDst;     //< Dst is already rotated.
    RECT    rectlPhySrc;       //< If screen is rotated, this value has
RotateRectl(prclSrc), physically addressed coordinate.
    RECT    rectlPhyDst;        //< If screen is rotated, this value has
RotateRectl(prclDst), physically addressed coordinate.
    UINT    uiSrcWidth_0;       //< Source Rectangle's width as non-rotated
logically.
    UINT    uiDstWidth_0;       //< Destination Rectangle's width as
non-rotated logically.
    UINT    uiSrcHeight_0;      //< Source Rectangle's height as
non-rotated logically.
    UINT    uiDstHeight_0;      //< Destination Rectangle's height as
non-rotated logically.

    prclSrc = pBltParms->prclSrc;
    prclDst = pBltParms->prclDst;

    CopyRect(&rectlPhySrc, (LPRECT)prclSrc);
    CopyRect(&rectlPhyDst, (LPRECT)prclDst);

    int     iRotate = DMDO_0;

    RotateRectlBack(prclSrc);
    RotateRectlBack(prclDst);

    /// Get Logical Aspect.
    uiSrcWidth_0 = ABS(prclSrc->right - prclSrc->left);
    uiSrcHeight_0 = ABS(prclSrc->bottom - prclSrc->top);
    uiDstWidth_0 = ABS(prclDst->right - prclDst->left);
    uiDstHeight_0 = ABS(prclDst->bottom - prclDst->top);

    RotateRectl(prclSrc);
    RotateRectl(prclDst);
    

    /// Set Relative Rotation Degree
    iRotate = GetRelativeDegree(pBltParms->pSrc->Rotate(),
pBltParms->pDst->Rotate());

#define SWAP(x,y, _type)  { _type i; i = x; x = y; y = i; }
    RETAILMSG(DISP_ZONE_TEMP,(TEXT("HWBitBlt Src(%d,%d)~(%d,%d):%d,
Dst(%d,%d)~(%d,%d):%d, RelativeDegree:%d\n"),
        prclSrc->left, prclSrc->top, prclSrc->right, prclSrc->bottom,
pBltParms->pSrc->Rotate(),
        prclDst->left, prclDst->top, prclDst->right, prclDst->bottom,
pBltParms->pDst->Rotate(), iRotate));
        
    /// if Stretch option is set, run StretchBlt
    /// if StretchBlt is on, but source region and destination region are
same. use BitBlt
    if( ((pBltParms->bltFlags & BLT_STRETCH) == BLT_STRETCH) 
        //< If it does not need to stretch or shrink. just using BitBlt is
faster.
        && !(( uiSrcWidth_0 == uiDstWidth_0) && (uiSrcHeight_0 ==
uiDstHeight_0))
        )
    {
        if( (prclSrc->left < 0) || (prclSrc->right < 0) || (prclSrc->top <
0) || (prclSrc->bottom < 0)
            || (prclDst->left < 0) || (prclDst->right < 0) || (prclDst->top
< 0) || (prclDst->bottom <0))
        {
            /// If rotated coodinate has negative value. we can't care
about when stretching is need.
            /// So return false, then process it by SW
            return FALSE;
        }

        RECTL   t_rect;
        DWORD   dwSrcWidth;
        DWORD   dwSrcHeight;
        SURFACE_DESCRIPTOR descScratch;

        /// This is physical value == physically 0 degree;
        dwSrcWidth = ABS(prclSrc->right - prclSrc->left);
        dwSrcHeight  = ABS(prclSrc->bottom - prclSrc->top);

        /// Set Scratch Destination Region
        t_rect.left = 0;
        t_rect.top = 0;
        t_rect.right = dwSrcWidth;
        t_rect.bottom = dwSrcHeight;

        RETAILMSG(DISP_ZONE_TEMP,(TEXT("t_rect,realstretch:
(%d,%d)~(%d,%d), R:%d\r\n"), 
            t_rect.left,t_rect.top,t_rect.right,t_rect.bottom, iRotate));
        DumpBltParms(pBltParms);           

        /// Set Source Surface Descriptor 
        m_oG2D->SetSrcSurface(pdescSrcSurface);

        /// Check whether XY flip or not, 
        ///if XY flip is requested, just Rotation 180 degree
        RotateRectlBack(prclDst);
        if( (prclDst->right < prclDst->left)  && (prclDst->bottom <
prclDst->top) )
        {
            RotateRectl(prclDst);
            switch(iRotate)
            {
            case DMDO_0:
                iRotate = DMDO_180;
                break;
            case DMDO_90:
                iRotate = DMDO_270;
                break;
            case DMDO_180:
                iRotate = DMDO_0;
                break;
            case DMDO_270:
                iRotate = DMDO_90;
                break;
            }

            /// SWAP rect
            SWAP(prclDst->top, prclDst->bottom, LONG);
            SWAP(prclDst->left, prclDst->right, LONG);

#if (G2D_STRETCH_ALGORITHM==G2D_QUARTERED_ADJUSTING)
            /// Adjust Coordinate from (x1,y1)~(x2,y2) to
(0,0)~(x2-x1,y2-y1)
            /// and Recalculate BaseAddress
            m_oG2D->TranslateCoordinateToZero(pdescDstSurface, prclDst,
pBltParms->prclClip);
#endif
            /// Set Destination Surface to real Framebuffer Surface
            m_oG2D->SetDstSurface(pdescDstSurface);

            /// Set Destination Clipping window Rect
            if(pBltParms->prclClip)
            {
                m_oG2D->SetClipWindow(pBltParms->prclClip);
            }
            else
            {
                m_oG2D->SetClipWindow(prclDst);
            }

            EnterCriticalSection(&m_cs2D);
#if (G2D_STRETCH_ALGORITHM==G2D_QUARTERED_ADJUSTING)
            m_oG2D->StretchBlt_Bilinear( prclSrc, prclDst,
m_oG2D->GetRotType(iRotate));
#else
            m_oG2D->StretchBlt( prclSrc, prclDst,
m_oG2D->GetRotType(iRotate));
#endif
            LeaveCriticalSection(&m_cs2D);
            /// Recover rect
            SWAP(prclDst->top, prclDst->bottom, LONG);
            SWAP(prclDst->left, prclDst->right, LONG);

            //RotateRectl(prclDst);

            return TRUE;

        }
        RotateRectl(prclDst);


        /// Reconfigure HW to set destination framebuffer address as
Scratch Framebuffer

        /// Check mirror case, and reset region rectangle
        /// Doing FlipBlt from Source to Sratch
        /// In mirror case, source region does not change.
        /// only destination's regions has reverse coordinate, this cannot
be negative.
        if(iRotate == DMDO_90 || iRotate == DMDO_270)
        {
            /// back to logical value
            RotateRectlBack(prclDst);
            /// if left-right mirror case
            if(prclDst->right < prclDst->left)
            {
                RotateRectl(prclDst);
                /// Allocation Scratch Framebuffer for Flip Operation.
                DDGPESurf *ScratchSurf;

                AllocSurface(&ScratchSurf, dwSrcWidth, dwSrcHeight,
pBltParms->pDst->Format(),
EGPEFormatToEDDGPEPixelFormat[pBltParms->pDst->Format()],
GPE_REQUIRE_VIDEO_MEMORY);
                if(ScratchSurf == NULL)
                {
                    RETAILMSG(DISP_ZONE_WARNING,(TEXT("Scratch Surface
Allocation is failed. %d\n"), __LINE__));
#if 0//USE_PACSURF, To increase video memory is better than to use system
memory as Video Surface
                    RETAILMSG(TRUE,(TEXT("try to allocate surface usign PA
Surface\r\n")));
                    PACSurf *ScratchSurf;
#endif
                    RETAILMSG(DISP_ZONE_WARNING,(TEXT("Maybe There's no
sufficient video memory. please increase video memory\r\n")));
                    RETAILMSG(DISP_ZONE_WARNING,(TEXT("try to redirect to
SW Emulated Bitblt\r\n")));
                    return FALSE;
                }
                /// Set Scratch Surface Information
                descScratch.dwBaseaddr = (m_VideoMemoryPhysicalBase +
ScratchSurf->OffsetInVideoMemory());
                RETAILMSG(DISP_ZONE_TEMP,(TEXT("ScratchBaseAddr : 0x%x\n"),
descScratch.dwBaseaddr));
                descScratch.dwColorMode =
GetHWColorFormat(pBltParms->pDst);
                descScratch.dwHoriRes = dwSrcWidth;
                descScratch.dwVertRes = dwSrcHeight;

                /// Set Destination Surface to Scratch Surface
                m_oG2D->SetDstSurface(&descScratch);
                /// Set Destination Clipping window Rect
                m_oG2D->SetClipWindow(&t_rect);
                /// Set Y-axis flip flag
                EnterCriticalSection(&m_cs2D);
                m_oG2D->FlipBlt( prclSrc, &t_rect,  FLIP_Y );
                LeaveCriticalSection(&m_cs2D);
    ...stripped-down