os/graphics/graphicsresourceservices/graphicsresourceadaptation/src/sgpixelformats.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicsresourceservices/graphicsresourceadaptation/src/sgpixelformats.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,152 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include <hal.h>
    1.20 +#include "sgdriverimpl.h"
    1.21 +
    1.22 +
    1.23 +TInt SgMinDataStride(TInt aWidth, TUidPixelFormat aPixelFormat)
    1.24 +	{
    1.25 +	switch (aPixelFormat)
    1.26 +		{
    1.27 +	case EUidPixelFormatXRGB_8888:
    1.28 +	case EUidPixelFormatBGRX_8888:
    1.29 +	case EUidPixelFormatXBGR_8888:
    1.30 +	case EUidPixelFormatBGRA_8888:
    1.31 +	case EUidPixelFormatARGB_8888:
    1.32 +	case EUidPixelFormatABGR_8888:
    1.33 +	case EUidPixelFormatARGB_8888_PRE:
    1.34 +	case EUidPixelFormatABGR_8888_PRE:
    1.35 +	case EUidPixelFormatBGRA_8888_PRE:
    1.36 +	case EUidPixelFormatARGB_2101010:
    1.37 +	case EUidPixelFormatABGR_2101010:
    1.38 +		return aWidth * 4;
    1.39 +	case EUidPixelFormatBGR_888:
    1.40 +	case EUidPixelFormatRGB_888:
    1.41 +		return aWidth * 3;
    1.42 +	case EUidPixelFormatRGB_565:
    1.43 +	case EUidPixelFormatBGR_565:
    1.44 +	case EUidPixelFormatARGB_1555:
    1.45 +	case EUidPixelFormatXRGB_1555:
    1.46 +	case EUidPixelFormatARGB_4444:
    1.47 +	case EUidPixelFormatARGB_8332:
    1.48 +	case EUidPixelFormatBGRX_5551:
    1.49 +	case EUidPixelFormatBGRA_5551:
    1.50 +	case EUidPixelFormatBGRA_4444:
    1.51 +	case EUidPixelFormatBGRX_4444:
    1.52 +	case EUidPixelFormatAP_88:
    1.53 +	case EUidPixelFormatXRGB_4444:
    1.54 +	case EUidPixelFormatXBGR_4444:
    1.55 +		return aWidth * 2;
    1.56 +	case EUidPixelFormatRGB_332:
    1.57 +	case EUidPixelFormatA_8:
    1.58 +	case EUidPixelFormatBGR_332:
    1.59 +	case EUidPixelFormatP_8:
    1.60 +		return aWidth;
    1.61 +	case EUidPixelFormatP_4:
    1.62 +		return (aWidth + 1) / 2;
    1.63 +	case EUidPixelFormatP_2:
    1.64 +		return (aWidth + 3) / 4;
    1.65 +	case EUidPixelFormatP_1:
    1.66 +		return (aWidth + 7) / 8;
    1.67 +	default:
    1.68 +		return KErrNotSupported;
    1.69 +		}
    1.70 +	}
    1.71 +
    1.72 +
    1.73 +const TUint32 KSgSupportedConstantSources = ESgUsageDirectGdiSource
    1.74 +	| ESgUsageOpenGlesTexture2D | ESgUsageOpenVgImage | ESgUsageOpenGles2Texture2D | ESgUsageWindowGcSource;
    1.75 +const TUint32 KSgSupportedCpuSources = ESgUsageDirectGdiSource | ESgUsageCompositionSource
    1.76 +	| ESgUsageOpenGlesTexture2D | ESgUsageOpenVgImage | ESgUsageOpenGles2Texture2D | ESgUsageWindowGcSource;
    1.77 +const TUint32 KSgSupportedOffScreenSources = ESgUsageDirectGdiSource | ESgUsageCompositionSource | ESgUsageScreenSource
    1.78 +	| ESgUsageOpenGlesTexture2D | ESgUsageOpenVgImage | ESgUsageOpenGles2Texture2D | ESgUsageWindowGcSource;
    1.79 +
    1.80 +const TUidPixelFormat KSgSupportedOpaqueTargetFormat = EUidPixelFormatXRGB_8888;
    1.81 +const TUidPixelFormat KSgSupportedAlphaTargetFormat = EUidPixelFormatARGB_8888_PRE;
    1.82 +
    1.83 +#ifdef SYMBIAN_GRAPHICS_USE_NUMA
    1.84 +const TSgCpuAccess KSgSupportedOffScreenCpuAccess = ESgCpuAccessNone;
    1.85 +#else
    1.86 +const TSgCpuAccess KSgSupportedOffScreenCpuAccess = ESgCpuAccessReadWrite;
    1.87 +#endif
    1.88 +
    1.89 +const TSgPixelFormatTableEntry KSgAnyScreenPixelFormatTableEntries[] =
    1.90 +	{
    1.91 +	// Support for constant images
    1.92 +	{EUidPixelFormatRGB_565,       KSgSupportedConstantSources, ESgCpuAccessNone, KSgScreenIdAny},
    1.93 +	{EUidPixelFormatXRGB_8888,     KSgSupportedConstantSources, ESgCpuAccessNone, KSgScreenIdAny},
    1.94 +	{EUidPixelFormatARGB_8888,     KSgSupportedConstantSources, ESgCpuAccessNone, KSgScreenIdAny},
    1.95 +	{EUidPixelFormatARGB_8888_PRE, KSgSupportedConstantSources, ESgCpuAccessNone, KSgScreenIdAny},
    1.96 +	};
    1.97 +
    1.98 +const TSgPixelFormatTableEntry KSgPerScreenPixelFormatTableEntries[] =
    1.99 +	{
   1.100 +	// Support for CPU rendering
   1.101 +	{EUidPixelFormatRGB_565,       KSgSupportedCpuSources, ESgCpuAccessReadWrite, KSgScreenIdMain},
   1.102 +	{EUidPixelFormatXRGB_8888,     KSgSupportedCpuSources, ESgCpuAccessReadWrite, KSgScreenIdMain},
   1.103 +	{EUidPixelFormatARGB_8888,     KSgSupportedCpuSources, ESgCpuAccessReadWrite, KSgScreenIdMain},
   1.104 +	{EUidPixelFormatARGB_8888_PRE, KSgSupportedCpuSources, ESgCpuAccessReadWrite, KSgScreenIdMain},
   1.105 +
   1.106 +	// Support for off-screen rendering
   1.107 +	{KSgSupportedOpaqueTargetFormat, KSgSupportedOffScreenSources|ESgUsageDirectGdiTarget|ESgUsageOpenGlesTarget|ESgUsageOpenGles2Target|ESgUsageOpenVgTarget, KSgSupportedOffScreenCpuAccess, KSgScreenIdMain},
   1.108 +	{KSgSupportedAlphaTargetFormat,  KSgSupportedOffScreenSources|ESgUsageDirectGdiTarget|ESgUsageOpenGlesTarget|ESgUsageOpenGles2Target|ESgUsageOpenVgTarget, KSgSupportedOffScreenCpuAccess, KSgScreenIdMain},
   1.109 +	{EUidPixelFormatRGB_565,         KSgSupportedOffScreenSources|ESgUsageDirectGdiTarget|ESgUsageOpenGlesTarget|ESgUsageOpenGles2Target|ESgUsageOpenVgTarget, KSgSupportedOffScreenCpuAccess, KSgScreenIdMain},
   1.110 +
   1.111 +	{KSgSupportedOpaqueTargetFormat, KSgSupportedOffScreenSources|ESgUsageCompositionTarget, KSgSupportedOffScreenCpuAccess, KSgScreenIdMain},
   1.112 +	{KSgSupportedAlphaTargetFormat,  KSgSupportedOffScreenSources|ESgUsageCompositionTarget, KSgSupportedOffScreenCpuAccess, KSgScreenIdMain},
   1.113 +	{EUidPixelFormatRGB_565,         KSgSupportedOffScreenSources|ESgUsageCompositionTarget, KSgSupportedOffScreenCpuAccess, KSgScreenIdMain},
   1.114 +
   1.115 +	{KSgSupportedOpaqueTargetFormat, KSgSupportedOffScreenSources|ESgUsageEglCopyBuffersTarget, KSgSupportedOffScreenCpuAccess, KSgScreenIdMain},
   1.116 +	{KSgSupportedAlphaTargetFormat,  KSgSupportedOffScreenSources|ESgUsageEglCopyBuffersTarget, KSgSupportedOffScreenCpuAccess, KSgScreenIdMain},
   1.117 +	{EUidPixelFormatRGB_565,         KSgSupportedOffScreenSources|ESgUsageEglCopyBuffersTarget, KSgSupportedOffScreenCpuAccess, KSgScreenIdMain},
   1.118 +	};
   1.119 +
   1.120 +
   1.121 +TInt XSgDriverImpl::ConstructPixelFormatTable()
   1.122 +	{
   1.123 +	TInt numberOfScreens;
   1.124 +	TInt err = HAL::Get(HAL::EDisplayNumberOfScreens, numberOfScreens);
   1.125 +	if (err != KErrNone)
   1.126 +		{
   1.127 +		return err;
   1.128 +		}
   1.129 +	for (TInt i = 0; i < sizeof(KSgAnyScreenPixelFormatTableEntries) / sizeof(TSgPixelFormatTableEntry); ++i)
   1.130 +		{
   1.131 +		RHeap* prevHeap = User::SwitchHeap(iHeap);
   1.132 +		err = iPixelFormatTable.Append(KSgAnyScreenPixelFormatTableEntries[i]);
   1.133 +		User::SwitchHeap(prevHeap);
   1.134 +		if (err != KErrNone)
   1.135 +			{
   1.136 +			return err;
   1.137 +			}
   1.138 +		}
   1.139 +	for (TInt screenId = 0; screenId < numberOfScreens; ++screenId)
   1.140 +		{
   1.141 +		for (TInt i = 0; i < sizeof(KSgPerScreenPixelFormatTableEntries) / sizeof(TSgPixelFormatTableEntry); ++i)
   1.142 +			{
   1.143 +			TSgPixelFormatTableEntry entry = KSgPerScreenPixelFormatTableEntries[i];
   1.144 +			entry.iScreenId = screenId;
   1.145 +			RHeap* prevHeap = User::SwitchHeap(iHeap);
   1.146 +			err = iPixelFormatTable.Append(entry);
   1.147 +			User::SwitchHeap(prevHeap);
   1.148 +			if (err != KErrNone)
   1.149 +				{
   1.150 +				return err;
   1.151 +				}
   1.152 +			}
   1.153 +		}
   1.154 +	return KErrNone;
   1.155 +	}