os/graphics/graphicsresourceservices/graphicsresourceadaptation/src/sgpixelformats.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include <hal.h>
sl@0
    17
#include "sgdriverimpl.h"
sl@0
    18
sl@0
    19
sl@0
    20
TInt SgMinDataStride(TInt aWidth, TUidPixelFormat aPixelFormat)
sl@0
    21
	{
sl@0
    22
	switch (aPixelFormat)
sl@0
    23
		{
sl@0
    24
	case EUidPixelFormatXRGB_8888:
sl@0
    25
	case EUidPixelFormatBGRX_8888:
sl@0
    26
	case EUidPixelFormatXBGR_8888:
sl@0
    27
	case EUidPixelFormatBGRA_8888:
sl@0
    28
	case EUidPixelFormatARGB_8888:
sl@0
    29
	case EUidPixelFormatABGR_8888:
sl@0
    30
	case EUidPixelFormatARGB_8888_PRE:
sl@0
    31
	case EUidPixelFormatABGR_8888_PRE:
sl@0
    32
	case EUidPixelFormatBGRA_8888_PRE:
sl@0
    33
	case EUidPixelFormatARGB_2101010:
sl@0
    34
	case EUidPixelFormatABGR_2101010:
sl@0
    35
		return aWidth * 4;
sl@0
    36
	case EUidPixelFormatBGR_888:
sl@0
    37
	case EUidPixelFormatRGB_888:
sl@0
    38
		return aWidth * 3;
sl@0
    39
	case EUidPixelFormatRGB_565:
sl@0
    40
	case EUidPixelFormatBGR_565:
sl@0
    41
	case EUidPixelFormatARGB_1555:
sl@0
    42
	case EUidPixelFormatXRGB_1555:
sl@0
    43
	case EUidPixelFormatARGB_4444:
sl@0
    44
	case EUidPixelFormatARGB_8332:
sl@0
    45
	case EUidPixelFormatBGRX_5551:
sl@0
    46
	case EUidPixelFormatBGRA_5551:
sl@0
    47
	case EUidPixelFormatBGRA_4444:
sl@0
    48
	case EUidPixelFormatBGRX_4444:
sl@0
    49
	case EUidPixelFormatAP_88:
sl@0
    50
	case EUidPixelFormatXRGB_4444:
sl@0
    51
	case EUidPixelFormatXBGR_4444:
sl@0
    52
		return aWidth * 2;
sl@0
    53
	case EUidPixelFormatRGB_332:
sl@0
    54
	case EUidPixelFormatA_8:
sl@0
    55
	case EUidPixelFormatBGR_332:
sl@0
    56
	case EUidPixelFormatP_8:
sl@0
    57
		return aWidth;
sl@0
    58
	case EUidPixelFormatP_4:
sl@0
    59
		return (aWidth + 1) / 2;
sl@0
    60
	case EUidPixelFormatP_2:
sl@0
    61
		return (aWidth + 3) / 4;
sl@0
    62
	case EUidPixelFormatP_1:
sl@0
    63
		return (aWidth + 7) / 8;
sl@0
    64
	default:
sl@0
    65
		return KErrNotSupported;
sl@0
    66
		}
sl@0
    67
	}
sl@0
    68
sl@0
    69
sl@0
    70
const TUint32 KSgSupportedConstantSources = ESgUsageDirectGdiSource
sl@0
    71
	| ESgUsageOpenGlesTexture2D | ESgUsageOpenVgImage | ESgUsageOpenGles2Texture2D | ESgUsageWindowGcSource;
sl@0
    72
const TUint32 KSgSupportedCpuSources = ESgUsageDirectGdiSource | ESgUsageCompositionSource
sl@0
    73
	| ESgUsageOpenGlesTexture2D | ESgUsageOpenVgImage | ESgUsageOpenGles2Texture2D | ESgUsageWindowGcSource;
sl@0
    74
const TUint32 KSgSupportedOffScreenSources = ESgUsageDirectGdiSource | ESgUsageCompositionSource | ESgUsageScreenSource
sl@0
    75
	| ESgUsageOpenGlesTexture2D | ESgUsageOpenVgImage | ESgUsageOpenGles2Texture2D | ESgUsageWindowGcSource;
sl@0
    76
sl@0
    77
const TUidPixelFormat KSgSupportedOpaqueTargetFormat = EUidPixelFormatXRGB_8888;
sl@0
    78
const TUidPixelFormat KSgSupportedAlphaTargetFormat = EUidPixelFormatARGB_8888_PRE;
sl@0
    79
sl@0
    80
#ifdef SYMBIAN_GRAPHICS_USE_NUMA
sl@0
    81
const TSgCpuAccess KSgSupportedOffScreenCpuAccess = ESgCpuAccessNone;
sl@0
    82
#else
sl@0
    83
const TSgCpuAccess KSgSupportedOffScreenCpuAccess = ESgCpuAccessReadWrite;
sl@0
    84
#endif
sl@0
    85
sl@0
    86
const TSgPixelFormatTableEntry KSgAnyScreenPixelFormatTableEntries[] =
sl@0
    87
	{
sl@0
    88
	// Support for constant images
sl@0
    89
	{EUidPixelFormatRGB_565,       KSgSupportedConstantSources, ESgCpuAccessNone, KSgScreenIdAny},
sl@0
    90
	{EUidPixelFormatXRGB_8888,     KSgSupportedConstantSources, ESgCpuAccessNone, KSgScreenIdAny},
sl@0
    91
	{EUidPixelFormatARGB_8888,     KSgSupportedConstantSources, ESgCpuAccessNone, KSgScreenIdAny},
sl@0
    92
	{EUidPixelFormatARGB_8888_PRE, KSgSupportedConstantSources, ESgCpuAccessNone, KSgScreenIdAny},
sl@0
    93
	};
sl@0
    94
sl@0
    95
const TSgPixelFormatTableEntry KSgPerScreenPixelFormatTableEntries[] =
sl@0
    96
	{
sl@0
    97
	// Support for CPU rendering
sl@0
    98
	{EUidPixelFormatRGB_565,       KSgSupportedCpuSources, ESgCpuAccessReadWrite, KSgScreenIdMain},
sl@0
    99
	{EUidPixelFormatXRGB_8888,     KSgSupportedCpuSources, ESgCpuAccessReadWrite, KSgScreenIdMain},
sl@0
   100
	{EUidPixelFormatARGB_8888,     KSgSupportedCpuSources, ESgCpuAccessReadWrite, KSgScreenIdMain},
sl@0
   101
	{EUidPixelFormatARGB_8888_PRE, KSgSupportedCpuSources, ESgCpuAccessReadWrite, KSgScreenIdMain},
sl@0
   102
sl@0
   103
	// Support for off-screen rendering
sl@0
   104
	{KSgSupportedOpaqueTargetFormat, KSgSupportedOffScreenSources|ESgUsageDirectGdiTarget|ESgUsageOpenGlesTarget|ESgUsageOpenGles2Target|ESgUsageOpenVgTarget, KSgSupportedOffScreenCpuAccess, KSgScreenIdMain},
sl@0
   105
	{KSgSupportedAlphaTargetFormat,  KSgSupportedOffScreenSources|ESgUsageDirectGdiTarget|ESgUsageOpenGlesTarget|ESgUsageOpenGles2Target|ESgUsageOpenVgTarget, KSgSupportedOffScreenCpuAccess, KSgScreenIdMain},
sl@0
   106
	{EUidPixelFormatRGB_565,         KSgSupportedOffScreenSources|ESgUsageDirectGdiTarget|ESgUsageOpenGlesTarget|ESgUsageOpenGles2Target|ESgUsageOpenVgTarget, KSgSupportedOffScreenCpuAccess, KSgScreenIdMain},
sl@0
   107
sl@0
   108
	{KSgSupportedOpaqueTargetFormat, KSgSupportedOffScreenSources|ESgUsageCompositionTarget, KSgSupportedOffScreenCpuAccess, KSgScreenIdMain},
sl@0
   109
	{KSgSupportedAlphaTargetFormat,  KSgSupportedOffScreenSources|ESgUsageCompositionTarget, KSgSupportedOffScreenCpuAccess, KSgScreenIdMain},
sl@0
   110
	{EUidPixelFormatRGB_565,         KSgSupportedOffScreenSources|ESgUsageCompositionTarget, KSgSupportedOffScreenCpuAccess, KSgScreenIdMain},
sl@0
   111
sl@0
   112
	{KSgSupportedOpaqueTargetFormat, KSgSupportedOffScreenSources|ESgUsageEglCopyBuffersTarget, KSgSupportedOffScreenCpuAccess, KSgScreenIdMain},
sl@0
   113
	{KSgSupportedAlphaTargetFormat,  KSgSupportedOffScreenSources|ESgUsageEglCopyBuffersTarget, KSgSupportedOffScreenCpuAccess, KSgScreenIdMain},
sl@0
   114
	{EUidPixelFormatRGB_565,         KSgSupportedOffScreenSources|ESgUsageEglCopyBuffersTarget, KSgSupportedOffScreenCpuAccess, KSgScreenIdMain},
sl@0
   115
	};
sl@0
   116
sl@0
   117
sl@0
   118
TInt XSgDriverImpl::ConstructPixelFormatTable()
sl@0
   119
	{
sl@0
   120
	TInt numberOfScreens;
sl@0
   121
	TInt err = HAL::Get(HAL::EDisplayNumberOfScreens, numberOfScreens);
sl@0
   122
	if (err != KErrNone)
sl@0
   123
		{
sl@0
   124
		return err;
sl@0
   125
		}
sl@0
   126
	for (TInt i = 0; i < sizeof(KSgAnyScreenPixelFormatTableEntries) / sizeof(TSgPixelFormatTableEntry); ++i)
sl@0
   127
		{
sl@0
   128
		RHeap* prevHeap = User::SwitchHeap(iHeap);
sl@0
   129
		err = iPixelFormatTable.Append(KSgAnyScreenPixelFormatTableEntries[i]);
sl@0
   130
		User::SwitchHeap(prevHeap);
sl@0
   131
		if (err != KErrNone)
sl@0
   132
			{
sl@0
   133
			return err;
sl@0
   134
			}
sl@0
   135
		}
sl@0
   136
	for (TInt screenId = 0; screenId < numberOfScreens; ++screenId)
sl@0
   137
		{
sl@0
   138
		for (TInt i = 0; i < sizeof(KSgPerScreenPixelFormatTableEntries) / sizeof(TSgPixelFormatTableEntry); ++i)
sl@0
   139
			{
sl@0
   140
			TSgPixelFormatTableEntry entry = KSgPerScreenPixelFormatTableEntries[i];
sl@0
   141
			entry.iScreenId = screenId;
sl@0
   142
			RHeap* prevHeap = User::SwitchHeap(iHeap);
sl@0
   143
			err = iPixelFormatTable.Append(entry);
sl@0
   144
			User::SwitchHeap(prevHeap);
sl@0
   145
			if (err != KErrNone)
sl@0
   146
				{
sl@0
   147
				return err;
sl@0
   148
				}
sl@0
   149
			}
sl@0
   150
		}
sl@0
   151
	return KErrNone;
sl@0
   152
	}