os/graphics/graphicscomposition/openwfcompositionengine/adaptation/src/Platform/Graphics/symbian/owfscreen.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicscomposition/openwfcompositionengine/adaptation/src/Platform/Graphics/symbian/owfscreen.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,193 @@
     1.4 +// Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +//
     1.6 +// Permission is hereby granted, free of charge, to any person obtaining a
     1.7 +// copy of this software and/or associated documentation files (the
     1.8 +// "Materials"), to deal in the Materials without restriction, including
     1.9 +// without limitation the rights to use, copy, modify, merge, publish,
    1.10 +// distribute, sublicense, and/or sell copies of the Materials, and to
    1.11 +// permit persons to whom the Materials are furnished to do so, subject to
    1.12 +// the following conditions:
    1.13 +//
    1.14 +// The above copyright notice and this permission notice shall be included
    1.15 +// in all copies or substantial portions of the Materials.
    1.16 +//
    1.17 +// THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    1.18 +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    1.19 +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    1.20 +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    1.21 +// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    1.22 +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    1.23 +// MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
    1.24 +//
    1.25 +// Description:
    1.26 +// Display Channel adaptation for owfscreen
    1.27 +// 
    1.28 +//
    1.29 +
    1.30 +#include <WF/openwfc_ri_display.h>
    1.31 +#include <hal.h>
    1.32 +#include "owfscreen.h"
    1.33 +#include "owfdebug.h"
    1.34 +#include "owfdisplaycontext.h"
    1.35 +
    1.36 +#include <assert.h>
    1.37 +
    1.38 +static OWFboolean OWF_Number_Of_Screens(OWFint *pNumberOfScreens)
    1.39 +    {
    1.40 +    TInt screens = 0;
    1.41 +    TInt err = HAL::Get(HAL::EDisplayNumberOfScreens, screens);   
    1.42 +    if (err != KErrNone)
    1.43 +        {
    1.44 +        DPRINT(("Cannot get number of screens from HAL, error: %d", err));
    1.45 +        return OWF_FALSE;
    1.46 +        }
    1.47 +    *pNumberOfScreens = (OWFint)screens;
    1.48 +    return OWF_TRUE;
    1.49 +    }
    1.50 +
    1.51 +OWF_ROTATION ConvertRotation(TUint32 rotation)
    1.52 +    {
    1.53 +    switch(rotation)
    1.54 +        {
    1.55 +            case COpenWFC_RI_Display::EScreenRotate0:
    1.56 +                return OWF_ROTATION_0;
    1.57 +            case COpenWFC_RI_Display::EScreenRotate90:
    1.58 +                return OWF_ROTATION_90;
    1.59 +            case COpenWFC_RI_Display::EScreenRotate180:
    1.60 +                return OWF_ROTATION_180;
    1.61 +            default:
    1.62 +                OWF_ASSERT(rotation == COpenWFC_RI_Display::EScreenRotate270);
    1.63 +                return OWF_ROTATION_270;
    1.64 +        }
    1.65 +    }
    1.66 +
    1.67 +OWF_API_CALL OWFint OWF_Screen_GetDefaultNumber()
    1.68 +    {
    1.69 +    return COpenWFC_RI_Display::DefaultScreenNumber();
    1.70 +    }
    1.71 +
    1.72 +OWF_API_CALL OWFboolean OWF_Screen_Valid(OWFint screen)
    1.73 +    {
    1.74 +    OWFint numberOfScreens = 0;
    1.75 +    if (!OWF_Number_Of_Screens(&numberOfScreens))
    1.76 +        {
    1.77 +        return OWF_FALSE;
    1.78 +        }
    1.79 +    if (screen < 0 || screen >= numberOfScreens)
    1.80 +        {
    1.81 +        return OWF_FALSE;
    1.82 +        }
    1.83 +    return OWF_TRUE;
    1.84 +    }
    1.85 +
    1.86 +
    1.87 +OWF_API_CALL OWFboolean OWF_Screen_GetHeader(OWF_DISPCTX dc, OWF_SCREEN* header)
    1.88 +    {
    1.89 +    OWF_ASSERT(dc && header);
    1.90 +    
    1.91 +    OWFDisplayContext *pDispCtx = _OWF_DISPLAYCONTEXT(dc);
    1.92 +    
    1.93 +    OWF_ASSERT(pDispCtx->iScreenContext);
    1.94 +    
    1.95 +    COpenWFC_RI_Display::TScreenGeometryAttribute info;
    1.96 +    if (KErrNone != pDispCtx->iScreenContext->GetAttribute(COpenWFC_RI_Display::EScreenAttributeScreenGeometry,
    1.97 +                                           &info,
    1.98 +                                           sizeof(info)))
    1.99 +        {
   1.100 +        return OWF_FALSE;
   1.101 +        }
   1.102 +    
   1.103 +    header->currentRotation = ConvertRotation(info.iCurrentRotation);
   1.104 +    header->initialRotation = ConvertRotation(info.iDefaultRotation);
   1.105 +    if (info.iPixelFormat != EUidPixelFormatXRGB_8888)
   1.106 +        {
   1.107 +        return OWF_FALSE;
   1.108 +        }
   1.109 +    header->pixelFormat = OWF_IMAGE_XRGB8888;
   1.110 +    header->normal.height = info.iNormalHeight;
   1.111 +    header->normal.width = info.iNormalWidth;
   1.112 +    header->normal.stride = info.iNormalStride;
   1.113 +    header->flipped.height = info.iFlippedHeight;
   1.114 +    header->flipped.width = info.iFlippedWidth;
   1.115 +    header->flipped.stride = info.iFlippedStride;
   1.116 +    return OWF_TRUE;
   1.117 +    }
   1.118 +
   1.119 +OWF_API_CALL OWFboolean OWF_Screen_Rotation_Supported(OWF_DISPCTX dc)
   1.120 +    {
   1.121 +    OWFDisplayContext *pDispCtx = _OWF_DISPLAYCONTEXT(dc);
   1.122 +    if (!dc || !pDispCtx->iScreenContext)
   1.123 +        {
   1.124 +        return OWF_FALSE;
   1.125 +        }
   1.126 +    
   1.127 +    TUint32 supportedRotations;
   1.128 +    pDispCtx->iScreenContext->GetAttribute(COpenWFC_RI_Display::EScreenAttributeSupportedRotation,
   1.129 +                                           &supportedRotations,
   1.130 +                                           sizeof(supportedRotations));
   1.131 +    
   1.132 +    return ((supportedRotations & 0xF) == 0xF) ? OWF_TRUE : OWF_FALSE;
   1.133 +    }
   1.134 +
   1.135 +OWF_API_CALL OWFboolean OWF_Screen_Post_Topmost_Layer(OWF_DISPCTX dc, 
   1.136 +                                                      OWFNativeStreamType stream, 
   1.137 +                                                      OWF_ROTATION rotation)
   1.138 +    {
   1.139 +    OWFDisplayContext *pDispCtx = _OWF_DISPLAYCONTEXT(dc);
   1.140 +    OWF_ASSERT(dc && stream && pDispCtx->iScreenContext);
   1.141 +    COpenWFC_RI_Display* screenContext= pDispCtx->iScreenContext;
   1.142 +
   1.143 +    // If the display driver cannot handle rotation itself, the buffer will
   1.144 +    // already have been rotated. 
   1.145 +    TInt setTopErr=screenContext->SetTopLayerSurface((SymbianStreamType)stream);
   1.146 +    if (setTopErr)
   1.147 +        {
   1.148 +        return OWF_FALSE;
   1.149 +        }
   1.150 +
   1.151 +    if (OWF_Screen_Rotation_Supported(dc))
   1.152 +        {
   1.153 +        TUint32 screenRotation;
   1.154 +        switch(rotation)
   1.155 +            {
   1.156 +                case OWF_ROTATION_0:
   1.157 +                    screenRotation = COpenWFC_RI_Display::EScreenRotate0;
   1.158 +                    break;
   1.159 +                case OWF_ROTATION_90:
   1.160 +                    screenRotation = COpenWFC_RI_Display::EScreenRotate90;
   1.161 +                    break;
   1.162 +                case OWF_ROTATION_180:
   1.163 +                    screenRotation = COpenWFC_RI_Display::EScreenRotate180;
   1.164 +                    break;
   1.165 +                default:
   1.166 +                    OWF_ASSERT(rotation == OWF_ROTATION_270);
   1.167 +                    screenRotation = COpenWFC_RI_Display::EScreenRotate270;
   1.168 +            }
   1.169 +        
   1.170 +        
   1.171 +        screenContext->SetAttribute(COpenWFC_RI_Display::EScreenAttributeCurrentRotation, 
   1.172 +                                    &screenRotation,
   1.173 +                                    sizeof(screenRotation));
   1.174 +        screenContext->CommitAttribute();
   1.175 +        }
   1.176 +    screenContext->UpdateDisplay();
   1.177 +    return OWF_TRUE;
   1.178 +    }
   1.179 +
   1.180 +OWF_API_CALL OWFboolean OWF_Screen_Create(OWFint screen, OWF_DISPCTX dc)
   1.181 +    {
   1.182 +    OWFDisplayContext *pDispCtx = _OWF_DISPLAYCONTEXT(dc);
   1.183 +    OWF_ASSERT(dc);
   1.184 +    
   1.185 +    TRAPD(err, pDispCtx->iScreenContext = COpenWFC_RI_Display::NewL(screen))
   1.186 +    
   1.187 +    return (err == KErrNone) ? OWF_TRUE : OWF_FALSE;
   1.188 +    }
   1.189 +
   1.190 +OWF_API_CALL void OWF_Screen_Destroy(OWF_DISPCTX dc)
   1.191 +    {
   1.192 +    OWFDisplayContext *pDispCtx = _OWF_DISPLAYCONTEXT(dc);
   1.193 +    OWF_ASSERT(dc && pDispCtx->iScreenContext);
   1.194 +    delete pDispCtx->iScreenContext;
   1.195 +    pDispCtx->iScreenContext = NULL;
   1.196 +    }