os/graphics/graphicscomposition/openwfc_ri_displayupdater/src/openwfc_ri_displayupdater.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicscomposition/openwfc_ri_displayupdater/src/openwfc_ri_displayupdater.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,527 @@
     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 Adaptation Interface Implementation for Display Updater
    1.27 +// 
    1.28 +//
    1.29 +
    1.30 +#include "openwfc_ri_displayupdater.h"
    1.31 +#include <e32debug.h>
    1.32 +#include <hal.h>
    1.33 +
    1.34 +#if defined(ENABLE_LOGGING)
    1.35 +#define LOG(X)  RDebug::Printf X
    1.36 +#else
    1.37 +#define LOG(X)
    1.38 +#endif
    1.39 +
    1.40 +// #define LOG_DISPLAY_PROPERTIES
    1.41 +
    1.42 +const TUint32 KDefaultScreenNumber = 0;
    1.43 +
    1.44 +#ifdef _DEBUG
    1.45 +void Panic(TInt aPanic)
    1.46 +    {
    1.47 +    _LIT(KPanic, "DA-DU");
    1.48 +    User::Panic(KPanic, aPanic);
    1.49 +    }
    1.50 +#endif
    1.51 +
    1.52 +EXPORT_C COpenWFC_RI_Display* COpenWFC_RI_Display::NewL(TUint aScreen)
    1.53 +    {
    1.54 +    return COpenWFC_RI_DisplayUpdater::NewL(aScreen);
    1.55 +    }
    1.56 +
    1.57 +EXPORT_C TUint32 COpenWFC_RI_Display::DefaultScreenNumber()
    1.58 +    {
    1.59 +    return KDefaultScreenNumber;
    1.60 +    }
    1.61 +    
    1.62 +COpenWFC_RI_DisplayUpdater::COpenWFC_RI_DisplayUpdater(TUint aScreen):
    1.63 +iScreenNumber(aScreen),
    1.64 +iDisplayUpdater(NULL),
    1.65 +iCurrentSceneStream(SYMBIAN_INVALID_HANDLE),
    1.66 +iCurrentReadBuffer(SYMBIAN_INVALID_HANDLE),
    1.67 +iNextSceneStream(SYMBIAN_INVALID_HANDLE),
    1.68 +iNextReadBuffer(SYMBIAN_INVALID_HANDLE)
    1.69 +    {
    1.70 +    }
    1.71 +
    1.72 +COpenWFC_RI_DisplayUpdater* COpenWFC_RI_DisplayUpdater::NewL(TUint aScreen)
    1.73 +    {
    1.74 +    LOG((" +++ COpenWFC_RI_DisplayUpdater::NewL(%d)", aScreen));
    1.75 +    COpenWFC_RI_DisplayUpdater* screenContext = new(ELeave) COpenWFC_RI_DisplayUpdater(aScreen);
    1.76 +    CleanupStack::PushL(screenContext);
    1.77 +    screenContext->ConstructL();
    1.78 +    CleanupStack::Pop(screenContext);
    1.79 +    LOG((" --- COpenWFC_RI_DisplayUpdater::NewL(%d) : 0x%X", aScreen, screenContext));
    1.80 +    return screenContext;
    1.81 +    }
    1.82 +
    1.83 +COpenWFC_RI_DisplayUpdater::~COpenWFC_RI_DisplayUpdater()
    1.84 +    {
    1.85 +    LOG((" +++ COpenWFC_RI_DisplayUpdater::~COpenWFC_RI_DisplayUpdater(%d)", iScreenNumber));
    1.86 +    if (iDisplayUpdater)
    1.87 +        {
    1.88 +        TDisplayViewSettings viewSettings;  // DEFAULT
    1.89 +        TBufferInfo bufferInfo; // DEFAULT
    1.90 +        TInt err = KErrNone;
    1.91 +
    1.92 +        // Set to default view to release layer
    1.93 +        err = iDisplayUpdater->SetView(KTopMostLayer, viewSettings, bufferInfo);
    1.94 +        if (err != KErrNone)
    1.95 +            {
    1.96 +            LOG((" !!! COpenWFC_RI_DisplayUpdater::~COpenWFC_RI_DisplayUpdater()ERROR: Display update set view failed %d", err));
    1.97 +            }
    1.98 +
    1.99 +        TRequestStatus completedWhenReady = KRequestPending;
   1.100 +        LOG(("\n  +++ COpenWFC_RI_DisplayUpdater::~COpenWFC_RI_DisplayUpdater() FLUSHING *******\n"));
   1.101 +        iDisplayUpdater->Flush(completedWhenReady);
   1.102 +        LOG(("\n  +++ COpenWFC_RI_DisplayUpdater::~COpenWFC_RI_DisplayUpdater() AFTER FLUSHING ******* 2\n"));
   1.103 +        User::WaitForRequest(completedWhenReady);
   1.104 +        LOG(("\n  +++ COpenWFC_RI_DisplayUpdater::~COpenWFC_RI_DisplayUpdater() FLUSHING:REQUEST COMPLETED %d*******\n", completedWhenReady.Int()));
   1.105 +
   1.106 +        if (iCurrentSceneStream != SYMBIAN_INVALID_HANDLE && iCurrentReadBuffer != SYMBIAN_INVALID_HANDLE)
   1.107 +            {
   1.108 +            SymbianStreamReleaseReadBuffer(iCurrentSceneStream, iCurrentReadBuffer);
   1.109 +            }
   1.110 +        if (iNextSceneStream != SYMBIAN_INVALID_HANDLE && iNextReadBuffer != SYMBIAN_INVALID_HANDLE)
   1.111 +            {
   1.112 +            SymbianStreamReleaseReadBuffer(iNextSceneStream, iNextReadBuffer);
   1.113 +            }
   1.114 +        }
   1.115 +    delete iDisplayUpdater;
   1.116 +    iSurfaceManager.Close();
   1.117 +    LOG((" --- COpenWFC_RI_DisplayUpdater::~COpenWFC_RI_DisplayUpdater() completed"));    
   1.118 +    }
   1.119 +
   1.120 +void COpenWFC_RI_DisplayUpdater::ConstructL()
   1.121 +    {
   1.122 +    LOG((" +++ COpenWFC_RI_DisplayUpdater::ConstructL"));
   1.123 +    User::LeaveIfError(iSurfaceManager.Open());
   1.124 +    iDisplayUpdater = CDisplayUpdater::NewL(iScreenNumber);
   1.125 +    iScreenInfo.iDefaultRotation = EScreenRotate0;
   1.126 +    iDefaultRotation = ERotate0Deg;
   1.127 +    iCurrentRotation = ERotate0Deg;
   1.128 +    iRotationOffset = 0;
   1.129 +    iScreenInfo.iCurrentRotation = EScreenRotate0;
   1.130 +    iNewRotation = iScreenInfo.iCurrentRotation;
   1.131 +    
   1.132 +    TDisplayDrvInfo displayInfo;
   1.133 +    iDisplayUpdater->GetDisplayProperties(displayInfo);
   1.134 +
   1.135 +#if defined(LOG_DISPLAY_PROPERTIES)
   1.136 +    LOG((" ??? Display resolution (%d,%d)", displayInfo.iPanelResolution.iWidth, displayInfo.iPanelResolution.iHeight));
   1.137 +    LOG((" ??? Display twips (%d,%d)", displayInfo.iPanelTwips.iWidth, displayInfo.iPanelTwips.iHeight));
   1.138 +    LOG((" ??? Display refresh rate %dHz", displayInfo.iPanelRefreshRateHz));
   1.139 +    LOG((" ??? Display %d internal composition buffers", (TInt)displayInfo.iNumberOfBuffers));
   1.140 +    LOG((" ??? Display pixel formats: 0x%08.8X", (TInt)displayInfo.iSupportedFormats));
   1.141 +    LOG((" ??? Display pixel aspect ratio %d/%d", (TInt)displayInfo.iPixelAspectRNumerator, (TInt)displayInfo.iPixelAspectRDenominator));
   1.142 +    LOG((" ??? Display supported per-layer rotations: 0x%08.8X", (TInt)displayInfo.iSupportedPerLayerRotations));
   1.143 +    LOG((" ??? Display rotation works with: 0x%08.8X", (TInt)displayInfo.iRotationWorksWithTheseFeatures));
   1.144 +    LOG((" ??? Display scaling works with: 0x%08.8X", (TInt)displayInfo.iScalingWorksWithTheseFeatures));
   1.145 +    LOG((" ??? Display minimum scaling: 100/%d", (TInt)displayInfo.iScalingMinDenominator));
   1.146 +    LOG((" ??? Display maximum scaling: %d/100", (TInt)displayInfo.iScalingMaxNumerator));
   1.147 +    LOG((" ??? Display maximum overlays: %d", (TInt)displayInfo.iNumberOfOverlays));
   1.148 +    LOG((" ??? Display colour space: 0x%08.8X", (TInt)displayInfo.iDestinationColorSpace));
   1.149 +    LOG((" ??? Display colour coords: (%d,%d)R (%d,%d)G (%d,%d)B (%d,%d)W",
   1.150 +            displayInfo.iDestinationColorCoordinates.iRed.iX, displayInfo.iDestinationColorCoordinates.iRed.iY,
   1.151 +            displayInfo.iDestinationColorCoordinates.iGreen.iX, displayInfo.iDestinationColorCoordinates.iGreen.iY,
   1.152 +            displayInfo.iDestinationColorCoordinates.iBlue.iX, displayInfo.iDestinationColorCoordinates.iBlue.iY,
   1.153 +            displayInfo.iDestinationColorCoordinates.iWhite.iX, displayInfo.iDestinationColorCoordinates.iWhite.iY));
   1.154 +    LOG((" ??? Display direct buffer display: %d", (TInt)displayInfo.iGivenBufferWorksAsFrameBuffer));
   1.155 +    LOG((" ??? Display variable resolution: %d", (TInt)displayInfo.iVariableResolution));
   1.156 +    LOG((" ??? Display draw overscan: %d", (TInt)displayInfo.iOverscanToBeDrawn));
   1.157 +    LOG((" ??? Display is on: %d", (TInt)displayInfo.iDisplayOn));
   1.158 +#endif
   1.159 +
   1.160 +    TInt supportedFormats = displayInfo.iSupportedFormats;
   1.161 +    /* Note that in theory other formats could be supported for composition 
   1.162 +     * (eg  EPixelFormatARgb8888Le | EPixelFormatARgb8888LeP )
   1.163 +     * So long as the background colour is opaque then the final compiosed image should end up opaque,
   1.164 +     * so compatible with alpha modes.
   1.165 +     * However, it would give problems for fastpathing, where alpha byte should be ignored,
   1.166 +     * probably fastpath would need to be disabled.
   1.167 +     * At present we only care about PlatSim, 
   1.168 +     * and it is unlikely that any platform will NOT support xrgb32,
   1.169 +     * so it is better to assert the capabilities match than think about this hypothetical case too hard.  
   1.170 +     */
   1.171 +    if (supportedFormats & (EPixelFormatXRgb8888Le ))
   1.172 +        {
   1.173 +        iScreenInfo.iPixelFormat = EUidPixelFormatXRGB_8888;
   1.174 +        iScreenInfo.iBytesPerPixel = 4;
   1.175 +        }
   1.176 +    else
   1.177 +        {
   1.178 +        LOG((" !!! COpenWFC_RI_DisplayUpdater::ConstructL() unsupported pixel formats 0x%08.8x", supportedFormats));
   1.179 +        User::Leave(KErrNotSupported);
   1.180 +        }
   1.181 +
   1.182 +    iScreenInfo.iPixelFormat = EUidPixelFormatXRGB_8888;
   1.183 +    if (displayInfo.iRotationWorksWithTheseFeatures & EFeatureExternalBuf)
   1.184 +        {
   1.185 +        iScreenInfo.iSupportedRotations = displayInfo.iSupportedPerLayerRotations & 0x0f;
   1.186 +        }
   1.187 +    else
   1.188 +        {
   1.189 +        LOG((" +++ COpenWFC_RI_DisplayUpdater::ConstructL() fixed output rotation"));
   1.190 +        iScreenInfo.iSupportedRotations = (TInt32)ERotate0Deg;
   1.191 +        }
   1.192 +    
   1.193 +    iScreenInfo.iNormalWidth = displayInfo.iPanelResolution.iWidth;
   1.194 +    iScreenInfo.iNormalHeight = displayInfo.iPanelResolution.iHeight;
   1.195 +    iScreenInfo.iFlippedWidth = iScreenInfo.iNormalHeight;
   1.196 +    iScreenInfo.iFlippedHeight = iScreenInfo.iNormalWidth;
   1.197 +        
   1.198 +    iScreenInfo.iNormalStride = iScreenInfo.iBytesPerPixel * iScreenInfo.iNormalWidth;
   1.199 +    iScreenInfo.iFlippedStride = iScreenInfo.iBytesPerPixel * iScreenInfo.iFlippedWidth;
   1.200 +    LOG((" --- COpenWFC_RI_DisplayUpdater::ConstructL"));
   1.201 +    }
   1.202 +
   1.203 +TInt COpenWFC_RI_Display::GetAttributeSize(TUint aAttributeId)
   1.204 +    {
   1.205 +    LOG((" +++ COpenWFC_RI_DisplayUpdater::GetAttributeSize(%d)", aAttributeId));
   1.206 +    switch (aAttributeId)
   1.207 +        {
   1.208 +        case EScreenAttributeImplementationVersion:
   1.209 +        case EScreenAttributePixelFormat:
   1.210 +        case EScreenAttributeBytesPerPixel:
   1.211 +        case EScreenAttributeSupportedRotation:
   1.212 +        case EScreenAttributeNormalWidth:
   1.213 +        case EScreenAttributeNormalHeight:
   1.214 +        case EScreenAttributeNormalStride:
   1.215 +        case EScreenAttributeFlippedWidth:
   1.216 +        case EScreenAttributeFlippedHeight:
   1.217 +        case EScreenAttributeFlippedStride:
   1.218 +        case EScreenAttributeDefaultRotation:
   1.219 +        case EScreenAttributeCurrentRotation:
   1.220 +            LOG((" --- COpenWFC_RI_DisplayUpdater::GetAttributeSize(%d) = 4", aAttributeId));
   1.221 +            return sizeof(TUint32);
   1.222 +         
   1.223 +        case EScreenAttributeScreenGeometry:
   1.224 +            LOG((" --- COpenWFC_RI_DisplayUpdater::GetAttributeSize(%d) = %d", aAttributeId, sizeof(TScreenGeometryAttribute)));
   1.225 +            return sizeof(TScreenGeometryAttribute);
   1.226 +            
   1.227 +        default:
   1.228 +            LOG((" !!! COpenWFC_RI_DisplayUpdater::GetAttributeSize(%d) UNKNOWN", aAttributeId));
   1.229 +            return 0;
   1.230 +        }
   1.231 +    }
   1.232 +
   1.233 +TInt COpenWFC_RI_DisplayUpdater::GetAttribute(TInt aAttributeId, TAny* aAttribute, TInt aAttributeSize)
   1.234 +    {
   1.235 +    LOG((" +++ COpenWFC_RI_DisplayUpdater::GetAttribute(%d, 0x%X, %d)", aAttributeId, aAttribute, aAttributeSize));
   1.236 +    TInt parameterSize = GetAttributeSize(aAttributeId);
   1.237 +
   1.238 +    if (aAttribute == NULL)
   1.239 +        {
   1.240 +        LOG((" !!! COpenWFC_RI_DisplayUpdater::GetAttribute() aAttribute NULL ptr"));
   1.241 +        return KErrArgument;
   1.242 +        }
   1.243 +    
   1.244 +    if (parameterSize == 0)
   1.245 +        {
   1.246 +        LOG((" !!! COpenWFC_RI_DisplayUpdater::GetAttribute() Not Supported parameter aAttributeId"));
   1.247 +        return KErrNotSupported;
   1.248 +        }
   1.249 +    
   1.250 +    if (aAttributeSize != parameterSize)
   1.251 +        {
   1.252 +        LOG((" !!! COpenWFC_RI_DisplayUpdater::GetAttribute() aAttributeSize wrong size"));
   1.253 +        return KErrArgument;
   1.254 +        }
   1.255 +    
   1.256 +    switch (aAttributeId)
   1.257 +        {
   1.258 +        case EScreenAttributeImplementationVersion:
   1.259 +            *((TUint32*)aAttribute) = KImplementationVersion;
   1.260 +            break;
   1.261 +        case EScreenAttributePixelFormat:
   1.262 +            *((TUint32*)aAttribute) = iScreenInfo.iPixelFormat;
   1.263 +            break;
   1.264 +        case EScreenAttributeBytesPerPixel:
   1.265 +            *((TUint32*)aAttribute) = iScreenInfo.iBytesPerPixel;
   1.266 +            break;
   1.267 +        case EScreenAttributeSupportedRotation:
   1.268 +            *((TUint32*)aAttribute) = iScreenInfo.iSupportedRotations;
   1.269 +            break;
   1.270 +        case EScreenAttributeNormalWidth:
   1.271 +            *((TUint32*)aAttribute) = iScreenInfo.iNormalWidth;
   1.272 +            break;
   1.273 +        case EScreenAttributeNormalHeight:
   1.274 +            *((TUint32*)aAttribute) = iScreenInfo.iNormalHeight;
   1.275 +            break;
   1.276 +        case EScreenAttributeNormalStride:
   1.277 +            *((TUint32*)aAttribute) = iScreenInfo.iNormalStride;
   1.278 +            break;
   1.279 +        case EScreenAttributeFlippedWidth:
   1.280 +            *((TUint32*)aAttribute) = iScreenInfo.iFlippedWidth;
   1.281 +            break;
   1.282 +        case EScreenAttributeFlippedHeight:
   1.283 +            *((TUint32*)aAttribute) = iScreenInfo.iFlippedHeight;
   1.284 +            break;
   1.285 +        case EScreenAttributeFlippedStride:
   1.286 +            *((TUint32*)aAttribute) = iScreenInfo.iFlippedStride;
   1.287 +            break;
   1.288 +        case EScreenAttributeDefaultRotation:
   1.289 +            *((TUint32*)aAttribute) = iScreenInfo.iDefaultRotation;
   1.290 +            break;
   1.291 +        case EScreenAttributeCurrentRotation:
   1.292 +            *((TUint32*)aAttribute) = iScreenInfo.iCurrentRotation;
   1.293 +            break;
   1.294 +        case EScreenAttributeScreenGeometry:
   1.295 +            *((TScreenGeometryAttribute*)aAttribute) = iScreenInfo;
   1.296 +            break;
   1.297 +        default:
   1.298 +            LOG((" !!! COpenWFC_RI_DisplayUpdater::GetAttribute() attribute unrecognised"));
   1.299 +            return KErrNotSupported;
   1.300 +        }
   1.301 +    
   1.302 +    LOG((" --- COpenWFC_RI_DisplayUpdater::GetAttribute() = %d", *((TUint32*)aAttribute)));
   1.303 +    return KErrNone;
   1.304 +    }
   1.305 +
   1.306 +
   1.307 +TInt COpenWFC_RI_DisplayUpdater::SetAttribute(TInt aAttributeId, TAny* aAttribute, TInt aAttributeSize)
   1.308 +    {
   1.309 +    LOG((" +++ COpenWFC_RI_DisplayUpdater::SetAttribute(%d, 0x%X, %d)", aAttributeId, aAttribute, aAttributeSize));
   1.310 +    // the only parameter we can modify is the current rotation
   1.311 +    TInt parameterSize = GetAttributeSize(aAttributeId);
   1.312 +
   1.313 +    if (aAttributeSize != parameterSize || aAttribute == NULL)
   1.314 +        {
   1.315 +        LOG((" !!! COpenWFC_RI_DisplayUpdater::SetAttribute() Invalid parameter"));
   1.316 +        return KErrArgument;
   1.317 +        }
   1.318 +    
   1.319 +    switch (aAttributeId)
   1.320 +        {
   1.321 +        case EScreenAttributeCurrentRotation:
   1.322 +            iNewRotation = static_cast<TScreenRotation>(*((TUint32*)aAttribute));
   1.323 +            LOG((" +++ COpenWFC_RI_DisplayUpdater::SetAttribute(CurrentRotation, %d)", (TInt)iNewRotation));
   1.324 +            break;
   1.325 +        default:
   1.326 +            LOG((" !!! COpenWFC_RI_DisplayUpdater::SetAttribute() Invalid attribute"));
   1.327 +            return KErrNotSupported;
   1.328 +        }
   1.329 +    LOG((" --- COpenWFC_RI_DisplayUpdater::SetAttribute()"));
   1.330 +    return KErrNone;
   1.331 +    }
   1.332 +
   1.333 +
   1.334 +TInt COpenWFC_RI_DisplayUpdater::CommitAttribute()
   1.335 +    {
   1.336 +    LOG((" +++ COpenWFC_RI_DisplayUpdater::CommitAttribute"));
   1.337 +    // Hardware rotation is not demonstrated on PlatSim
   1.338 +    __ASSERT_DEBUG(iScreenInfo.iCurrentRotation == iNewRotation, Panic(__LINE__));
   1.339 +    return KErrNone;
   1.340 +    }
   1.341 +
   1.342 +TInt COpenWFC_RI_DisplayUpdater::SetLayerSurface(TInt aLayer, SymbianStreamType aStream, TInt* aNonTrivialAttribs)
   1.343 +    {
   1.344 +    // display channel interface can be seen as mono-layered
   1.345 +    if (aLayer != 0)
   1.346 +        {
   1.347 +        LOG((" !!! COpenWFC_RI_DisplayUpdater::SetLayerSurface : non-zero layer not supported"));
   1.348 +        return KErrArgument;
   1.349 +        }
   1.350 +    
   1.351 +    if (aNonTrivialAttribs && *aNonTrivialAttribs)
   1.352 +        { 
   1.353 +        LOG((" !!! COpenWFC_RI_DisplayUpdater::SetLayerSurface : Non-trivial attributes not accepted."));
   1.354 +        return KErrNotSupported;
   1.355 +        }
   1.356 +    
   1.357 +    if (aStream!=iNextSceneStream)
   1.358 +        {   //If, in future non-trivial attributes are supported then this condition is inadequate
   1.359 +         SymbianStreamBuffer nextReadBuffer=NULL;
   1.360 +        //Scene stream has changed - re-validate and set up for new info
   1.361 +        TInt err=SymbianStreamAcquireReadBuffer(aStream,&nextReadBuffer);
   1.362 +        if (err<KErrNone)
   1.363 +            {
   1.364 +            LOG((" !!! COpenWFC_RI_DisplayUpdater::SetLayerSurface : Falied to access stream properties"));
   1.365 +            return err;
   1.366 +            }
   1.367 +        const TSurfaceId* surfaceId;
   1.368 +        khronos_int32_t index;
   1.369 +        err= SymbianStreamGetBufferId(aStream,nextReadBuffer,&index,&surfaceId);
   1.370 +        if (err<KErrNone)
   1.371 +            {
   1.372 +            LOG((" !!! COpenWFC_RI_DisplayUpdater::SetLayerSurface : Falied to access stream properties"));
   1.373 +            SymbianStreamReleaseReadBuffer(aStream, nextReadBuffer);
   1.374 +            return err;
   1.375 +            }
   1.376 +        RSurfaceManager::TInfoBuf surfaceInfo;
   1.377 +        iSurfaceManager.SurfaceInfo(*surfaceId,surfaceInfo);
   1.378 +        TBool acceptable=ETrue;
   1.379 +        if (!surfaceInfo().iContiguous)
   1.380 +            {
   1.381 +            acceptable=EFalse;
   1.382 +            LOG((" !!! COpenWFC_RI_DisplayUpdater::SetLayerSurface : Stream 0x%08x iContiguous not accepted ",aStream));
   1.383 +            }
   1.384 +        khronos_int32_t format=surfaceInfo().iPixelFormat;
   1.385 +        if (format!=EUidPixelFormatARGB_8888 && format!=EUidPixelFormatARGB_8888_PRE && format!=EUidPixelFormatXRGB_8888)
   1.386 +            {
   1.387 +            acceptable=EFalse;
   1.388 +            LOG((" !!! COpenWFC_RI_DisplayUpdater::SetLayerSurface : Stream 0x%08x iPixelFormat 0x%08x not accepted ",aStream,surfaceInfo().iPixelFormat));
   1.389 +            }
   1.390 +                
   1.391 +        if (!acceptable)
   1.392 +            {
   1.393 +            LOG((" !!! COpenWFC_RI_DisplayUpdater::SetLayerSurface : Stream 0x%08x properties not accepted ",aStream));
   1.394 +            SymbianStreamReleaseReadBuffer(aStream, nextReadBuffer);
   1.395 +            return KErrNotSupported;
   1.396 +            }
   1.397 +        
   1.398 +        //Note that if we early-return before this point the previous top stream should still be locked for use.
   1.399 +        
   1.400 +        LOG((" !!! COpenWFC_RI_DisplayUpdater::SetLayerSurface : Stream changed 0x%08x --> 0x%08x ",iNextSceneStream,aStream));
   1.401 +        if (iNextSceneStream != SYMBIAN_INVALID_HANDLE && iNextReadBuffer != SYMBIAN_INVALID_HANDLE)
   1.402 +             {
   1.403 +             LOG((" !!! COpenWFC_RI_DisplayUpdater::SetLayerSurface : double-call to SetLayerSurface. First discarded."));
   1.404 +             SymbianStreamReleaseReadBuffer(iNextSceneStream, iNextReadBuffer);
   1.405 +             }
   1.406 +        iNextReadBuffer=nextReadBuffer;
   1.407 +        iNextSceneStream=aStream;
   1.408 +        }
   1.409 +    else
   1.410 +        {
   1.411 +        LOG((" !!! COpenWFC_RI_DisplayUpdater::SetLayerSurface : Stream still 0x%08x",aStream));
   1.412 +        }
   1.413 +    return KErrNone;
   1.414 +    }
   1.415 +
   1.416 +TInt COpenWFC_RI_DisplayUpdater::SetTopLayerSurface(SymbianStreamType aStream, TInt* aNonTrivialAttribs)
   1.417 +    {
   1.418 +    return SetLayerSurface(KTopMostLayer, aStream, aNonTrivialAttribs);
   1.419 +    }
   1.420 +
   1.421 +TInt COpenWFC_RI_DisplayUpdater::UpdateDisplay()
   1.422 +    {
   1.423 +    TInt err = KErrNone;
   1.424 +
   1.425 +    SymbianStreamBuffer readBuffer = iNextReadBuffer;
   1.426 +    iNextReadBuffer = SYMBIAN_INVALID_HANDLE;
   1.427 +    if (!iNextSceneStream)
   1.428 +        {
   1.429 +        LOG((" !!! COpenWFC_RI_DisplayUpdater::UpdateDisplay() ASSERT: No top layer has been set!"));
   1.430 +        return KErrNotReady;
   1.431 +        }
   1.432 +    if (readBuffer == SYMBIAN_INVALID_HANDLE)
   1.433 +        {
   1.434 +        if ((err = SymbianStreamAcquireReadBuffer(iNextSceneStream, &readBuffer)) != KErrNone)
   1.435 +            {   //AcquireReadBuffer "Can't fail" in theory, but just incase....
   1.436 +            LOG((" !!! COpenWFC_RI_DisplayUpdater::UpdateDisplay() Acquire failed: %d", err));
   1.437 +            return err;
   1.438 +            }
   1.439 +        }
   1.440 +    TBufferInfo bufferInfo;
   1.441 +    khronos_int32_t width, height, stride;
   1.442 +    SymbianStreamGetHeader(iNextSceneStream, &width, &height, &stride, NULL, NULL);
   1.443 +    bufferInfo.iBufferWidth = (TInt16)width;
   1.444 +    bufferInfo.iBufferHeight = (TInt16)height;
   1.445 +    bufferInfo.iStride = (TInt16)stride;
   1.446 +    bufferInfo.iBufferFormat = EPixelFormatXRgb8888Le;
   1.447 +    bufferInfo.iLinearAddress = 0;
   1.448 +    err = SymbianStreamGetBufferPointer(iNextSceneStream, readBuffer,&bufferInfo.iLinearAddress);
   1.449 +    if (err == KErrNone)
   1.450 +        {
   1.451 +        err = SymbianStreamGetChunkHandle(iNextSceneStream, &bufferInfo.iBufferRChunkHandle);
   1.452 +        }
   1.453 +
   1.454 +    if (err != KErrNone)
   1.455 +        {
   1.456 +        LOG((" !!! COpenWFC_RI_DisplayUpdater::UpdateDisplay() error %d getting stream data", err));
   1.457 +        SymbianStreamReleaseReadBuffer(iNextSceneStream, readBuffer);
   1.458 +        return err;
   1.459 +        }
   1.460 +
   1.461 +    TRect displayRect;
   1.462 +    displayRect.SetRect(TPoint(0, 0), TSize(bufferInfo.iBufferWidth, bufferInfo.iBufferHeight ));
   1.463 +    
   1.464 +    TDisplayViewSettings viewSettings; // Default
   1.465 +    viewSettings.iSourceScissor         = displayRect;
   1.466 +    viewSettings.iDestinationScaledRect = displayRect;
   1.467 +    viewSettings.iLayerRotation         = ERotate0Deg;
   1.468 +    viewSettings.iUsageHint             = EPurposeUi;
   1.469 +    viewSettings.iTearingFree           = ETrue;
   1.470 +      
   1.471 +    LOG((" $$$*** bufferInfo.iBufferWidth %d", bufferInfo.iBufferWidth));
   1.472 +    LOG((" $$$*** bufferInfo.iBufferHeight %d", bufferInfo.iBufferHeight));
   1.473 +    LOG((" $$$*** bufferInfo.iStride %d", bufferInfo.iStride));
   1.474 +    LOG((" $$$*** bufferInfo.iBufferFormat %d", bufferInfo.iBufferFormat));
   1.475 +    LOG((" $$$*** bufferInfo.iLinearAddress %08x", bufferInfo.iLinearAddress));
   1.476 +    LOG((" $$$*** bufferInfo.iBufferRChunkHandle %d", bufferInfo.iBufferRChunkHandle));
   1.477 +
   1.478 +    LOG((" $$$*** viewSettings iSourceScissor width %d", viewSettings.iSourceScissor.Width()));
   1.479 +    LOG((" $$$*** viewSettings iSourceScissor height %d", viewSettings.iSourceScissor.Height()));
   1.480 +    LOG((" $$$*** viewSettings iDestinationScaledRect width %d", viewSettings.iDestinationScaledRect.Width()));
   1.481 +    LOG((" $$$*** viewSettings iDestinationScaledRect height %d", viewSettings.iDestinationScaledRect.Height()));
   1.482 +    LOG((" $$$*** viewSettings iLayerRotation %d", viewSettings.iLayerRotation));
   1.483 +    LOG((" $$$*** viewSettings iUsageHint %d", viewSettings.iUsageHint));
   1.484 +    LOG((" $$$*** viewSettings iTearingFree %d", viewSettings.iTearingFree));
   1.485 +
   1.486 +    TRequestStatus completedWhenReady = KRequestPending;
   1.487 +    viewSettings.iLayerRotation = iCurrentRotation;
   1.488 +
   1.489 +    err = iDisplayUpdater->SetView(KTopMostLayer, viewSettings, bufferInfo);
   1.490 +    
   1.491 +    if (err != KErrNone)
   1.492 +        {
   1.493 +        LOG((" !!! COpenWFC_RI_DisplayUpdater::UpdateDisplay()ERROR: Display update set view failed %d", err));
   1.494 +        }
   1.495 +    else
   1.496 +        {
   1.497 +        err = iDisplayUpdater->SetBuffer(KTopMostLayer, displayRect, bufferInfo );
   1.498 +        if (err != KErrNone)
   1.499 +            {
   1.500 +            LOG((" !!! COpenWFC_RI_DisplayUpdater::UpdateDisplay()ERROR: Display Update set buffer failed %d", err));
   1.501 +            }
   1.502 +        }
   1.503 +
   1.504 +    ////////////////////////////////////////////////////////////////////////////////////////////
   1.505 +    iDisplayUpdater->Flush(completedWhenReady);
   1.506 +    
   1.507 +    /* The TRequestStatus& aCompletedWhenReady parameter is signalled 
   1.508 +     * either when the buffer has been copied, 
   1.509 +     * or it is streaming the first pixel to the display
   1.510 +     * In either case this indicates that the previous buffer is no longer required.
   1.511 +     * By waiting here we guarantee that the previous iCurrentReadBuffer is no longer required,
   1.512 +     * but here are more intelligent ways to wait, I am sure!
   1.513 +     */
   1.514 +    User::WaitForRequest(completedWhenReady);
   1.515 +    if (iCurrentReadBuffer != SYMBIAN_INVALID_HANDLE)
   1.516 +        {
   1.517 +        // Release the previous update's read buffer.
   1.518 +        /* This ensures that a lock is held on the displayed buffer until the next commit/compose
   1.519 +         * This is correct behaviour for streaming direct to the display, but is actually not
   1.520 +         * necessary if the display makes its own copy.
   1.521 +         * However, PlatSim currently supports only the latter, and we think the former is important,
   1.522 +         * so this implementation allows us to validate that the behaviour is correct in direct streaming.
   1.523 +         */
   1.524 +        SymbianStreamReleaseReadBuffer(iCurrentSceneStream, iCurrentReadBuffer);
   1.525 +        }
   1.526 +    iCurrentReadBuffer = readBuffer;
   1.527 +    iCurrentSceneStream = iNextSceneStream;
   1.528 +    return err;
   1.529 +    }
   1.530 +