os/graphics/graphicsresourceservices/graphicsresourceinterface/inc/sgimage.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
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
// Graphics Resource - images
sl@0
    15
//
sl@0
    16
sl@0
    17
#ifndef SGIMAGE_H
sl@0
    18
#define SGIMAGE_H
sl@0
    19
sl@0
    20
#include <sgresource/sgresource.h>
sl@0
    21
sl@0
    22
/**
sl@0
    23
A class that encapsulates the basic attributes of an image.
sl@0
    24
It is used both to create images and to obtain information about them.
sl@0
    25
The basic attributes of an image cannot be changed after creation.
sl@0
    26
For an instance of TSgImageInfo to be valid the following conditions must be satisfied:
sl@0
    27
	- The width and height in iSizeInPixels must both be greater than zero.
sl@0
    28
	- iPixelFormat must not be EUidPixelFormatUnknown.
sl@0
    29
	- iUsage must have at least one usage bit set.
sl@0
    30
*/
sl@0
    31
NONSHARABLE_CLASS(TSgImageInfo)
sl@0
    32
	{
sl@0
    33
public:
sl@0
    34
	/**
sl@0
    35
	Default constructor.
sl@0
    36
	Data members remain uninitialised.
sl@0
    37
	*/
sl@0
    38
	inline TSgImageInfo();
sl@0
    39
sl@0
    40
	/**
sl@0
    41
	Constructor which initialises data members to the given values.
sl@0
    42
	*/
sl@0
    43
	inline TSgImageInfo(const TSize& aSizeInPixels, TInt aPixelFormat, TUint32 aUsage);
sl@0
    44
public:
sl@0
    45
	/** The size of the image in pixels.*/
sl@0
    46
	TSize iSizeInPixels;
sl@0
    47
	/**
sl@0
    48
	UID representing the pixel format of the image. 
sl@0
    49
	The values enumerated in TSgPixelFormat are guaranteed to be supported by 
sl@0
    50
	every implementation of the Graphics Resource API but additional pixel 
sl@0
    51
	formats from TUidPixelFormat may be supported by some implementations.
sl@0
    52
	@see RSgImage::GetPixelFormats().
sl@0
    53
	*/
sl@0
    54
	TInt iPixelFormat;
sl@0
    55
	/** The possible usage of the image as a combination of bits from TSgUsageBits.*/
sl@0
    56
	TUint32 iUsage;
sl@0
    57
	};
sl@0
    58
sl@0
    59
/**
sl@0
    60
The drawable resource type associated with images.
sl@0
    61
*/
sl@0
    62
const TUid KSgImageTypeUid = {0x10285A73};
sl@0
    63
sl@0
    64
/**
sl@0
    65
An image handle. 
sl@0
    66
It inherits all the general handle functionality from RSgDrawable. 
sl@0
    67
An image is a drawable resource containing a two-dimensional pixel array. 
sl@0
    68
Its basic attributes are the size in pixels, the pixel format and the usage.
sl@0
    69
The usage for which an image is created must be declared so that it can be properly allocated.
sl@0
    70
The attributes of an image cannot be changed after creation.
sl@0
    71
Instances of RSgImage can be constructed before RSgDriver::Open() is called and 
sl@0
    72
the implementation of the Graphics Resource API is initialised in the context 
sl@0
    73
of the process, but most attempts to call a function of RSgImage will panic 
sl@0
    74
with category “SGRES” and code 1 both in debug and release builds if the 
sl@0
    75
implementation of the Graphics Resource API is not initialised in the context 
sl@0
    76
of the process. Any attempt to call a function of RSgImage on an invalid handle 
sl@0
    77
will panic with category “SGRES” and code 3 both in debug and release builds.
sl@0
    78
*/
sl@0
    79
NONSHARABLE_CLASS(RSgImage): public RSgDrawable
sl@0
    80
	{
sl@0
    81
public:
sl@0
    82
	/**
sl@0
    83
	Default constructor which sets iHandleType to KSgImageTypeUid and 
sl@0
    84
	creates null image handles.
sl@0
    85
	*/
sl@0
    86
	inline RSgImage();
sl@0
    87
sl@0
    88
	/**
sl@0
    89
	Creates an image with the basic attributes given by the parameter aInfo 
sl@0
    90
	and the initial contents given by the parameters aDataAddress and 
sl@0
    91
	aDataStride, and returns KErrNone if successful.
sl@0
    92
sl@0
    93
	@pre An RSgDriver handle has been opened in the context of the process.
sl@0
    94
	@pre The instance of RSgImage is a null handle.
sl@0
    95
	@pre The parameter aInfo is valid.
sl@0
    96
	@pre If the parameter aDataAddress is not NULL then the parameter aDataStride 
sl@0
    97
		is not zero and its absolute value is equal to or greater than the 
sl@0
    98
		minimum number of bytes needed for a row of pixel data.
sl@0
    99
	@post The created image has an initial reference count of one.
sl@0
   100
	@param aInfo An instance of TSgImageInfo with the basic attributes of the 
sl@0
   101
		image to be created.
sl@0
   102
	@param aDataAddress The base address of the pixel data used to populate the 
sl@0
   103
		image to be created. The pixel format of the data must be the exact 
sl@0
   104
		pixel format given in aInfo but the implementation of Graphics 
sl@0
   105
		Resource may convert the data to the internal pixel format of the image, 
sl@0
   106
		which could be any pixel format without loss of data. 
sl@0
   107
		If aDataAddress is NULL the initial contents of the image are undefined.
sl@0
   108
	@param aDataStride The number of bytes between the rows of the pixel data 
sl@0
   109
		pointed to by aDataAddress. It can be a positive value to indicate 
sl@0
   110
		top-down ordering of the rows of pixel data or a negative value to 
sl@0
   111
		indicate bottom-up ordering of the rows of pixel data. Inside each row 
sl@0
   112
		of pixel data, ordering of pixels is always left-to-right.
sl@0
   113
	@param aAttributes A pointer to an array of extension attributes, if allowed 
sl@0
   114
		by any extension of the Graphics Resource API, or NULL otherwise.
sl@0
   115
	@return KErrNone if successful;
sl@0
   116
		KErrInUse if the instance of RSgImage is an open handle;
sl@0
   117
		KErrArgument if either 
sl@0
   118
			1. the parameter aInfo is not valid or 
sl@0
   119
			2. the parameter aDataAddress is not NULL and the parameter aDataStride 
sl@0
   120
				is zero or its absolute value is less than the minimum number of bytes 
sl@0
   121
				needed for a row of pixel data;
sl@0
   122
		KErrTooBig if the size given by the parameter aInfo is greater than 
sl@0
   123
			the maximum image size supported by the implementation of Graphics 
sl@0
   124
			Resource API. The maximum image size supported by an implementation of 
sl@0
   125
			the Graphics Resource API is at least 2048 by 2048 pixels;
sl@0
   126
		KErrNotSupported if either 
sl@0
   127
			1. the combination of pixel format and usages given by the parameter 
sl@0
   128
				aInfo is not supported by the implementation of the Graphics Resource 
sl@0
   129
				API or 
sl@0
   130
			2. the parameter aAttributes is not NULL and one or more of the extension 
sl@0
   131
				attributes in the array is not defined by any extension of the Graphics 
sl@0
   132
				Resource API;
sl@0
   133
		KErrNoMemory if there is not enough system memory to create the image;
sl@0
   134
		KErrNoGraphicsMemory if there is not enough specialised graphics memory 
sl@0
   135
			to create the image.
sl@0
   136
	@panic SGRES 1 No RSgDriver handle has been opened in the context of the process.
sl@0
   137
	*/
sl@0
   138
	IMPORT_C TInt Create(const TSgImageInfo& aInfo,
sl@0
   139
	                     const TAny* aDataAddress = NULL,
sl@0
   140
	                     TInt aDataStride = 0,
sl@0
   141
	                     const TSgAttributeArrayBase* aAttributes = NULL);
sl@0
   142
sl@0
   143
	/**
sl@0
   144
	Creates an image with the basic attributes given by the parameter aInfo 
sl@0
   145
	and the initial contents copied from an existing image given by the 
sl@0
   146
	parameter aImage, and returns KErrNone if successful.
sl@0
   147
sl@0
   148
	@pre An RSgDriver handle has been opened in the context of the process.
sl@0
   149
	@pre The instance of RSgImage is a null handle.
sl@0
   150
	@pre The parameter aInfo is valid.
sl@0
   151
	@pre The parameter aImage is an open handle
sl@0
   152
	@pre The size and the pixel format given by aInfo must be the same as 
sl@0
   153
		the size and the pixel format of the existing image.
sl@0
   154
	@post The created image has an initial reference count of one.
sl@0
   155
	@param aInfo An instance of TSgImageInfo with the basic attributes of the 
sl@0
   156
		image to be created.
sl@0
   157
	@param aImage A handle to the existing image.
sl@0
   158
	@param aAttributes A pointer to an array of extension attributes, if allowed 
sl@0
   159
		by any extension of the Graphics Resource API, or NULL otherwise.
sl@0
   160
	@return KErrNone if successful;
sl@0
   161
		KErrInUse if the instance of RSgImage is an open handle;
sl@0
   162
		KErrArgument if either 
sl@0
   163
			1. the parameter aInfo is not valid or 
sl@0
   164
			2. the parameter aImage is a null handle;
sl@0
   165
		KErrNotSupported if either 
sl@0
   166
			1. the combination of pixel format and usages given by the parameter 
sl@0
   167
				aInfo is not supported by the implementation of the Graphics Resource 
sl@0
   168
				API or 
sl@0
   169
			2. the size and the pixel format given by the parameter aInfo are 
sl@0
   170
				not the same as the size and the pixel format of the existing image or 
sl@0
   171
			3. the parameter aAttributes is not NULL and one or more of the extension 
sl@0
   172
				attributes in the array is not defined by any extension of the Graphics 
sl@0
   173
				Resource API;
sl@0
   174
		KErrNoMemory if there is not enough system memory to create the image;
sl@0
   175
		KErrNoGraphicsMemory if there is not enough specialised graphics memory 
sl@0
   176
			to create the image.
sl@0
   177
	@panic SGRES 1 No RSgDriver handle has been opened in the context of the process.
sl@0
   178
	@panic SGRES 3 aImage is an invalid handle.
sl@0
   179
	*/
sl@0
   180
	IMPORT_C TInt Create(const TSgImageInfo& aInfo,
sl@0
   181
	                     const RSgImage& aImage,
sl@0
   182
	                     const TSgAttributeArrayBase* aAttributes = NULL);
sl@0
   183
sl@0
   184
	/**
sl@0
   185
	Retrieves the values of the basic attributes of an image and returns 
sl@0
   186
	KErrNone if successful.
sl@0
   187
sl@0
   188
	@pre An RSgDriver handle has been opened in the context of the process.
sl@0
   189
	@pre The instance of RSgImage is an open handle.
sl@0
   190
	@param[out] aInfo An instance of TSgImageInfo that on return contains the 
sl@0
   191
		values of the basic attributes of the image.
sl@0
   192
	@return KErrNone if successful;
sl@0
   193
		KErrBadHandle if the instance of RSgImage is a null handle.
sl@0
   194
	@panic SGRES 1 No RSgDriver handle has been opened in the context of the process.
sl@0
   195
	@panic SGRES 3 The instance of RSgImage is an invalid handle.
sl@0
   196
	*/
sl@0
   197
	IMPORT_C TInt GetInfo(TSgImageInfo& aInfo) const;
sl@0
   198
sl@0
   199
	/**
sl@0
   200
	Retrieves the value of an extension attribute of an image and returns 
sl@0
   201
	KErrNone if successful.
sl@0
   202
sl@0
   203
	@pre An RSgDriver handle has been opened in the context of the process.
sl@0
   204
	@pre The instance of RSgImage is an open handle.
sl@0
   205
	@param[in] aUid The UID of the extension attribute.
sl@0
   206
	@param[out] aInfo A reference to a variable that on return holds the value 
sl@0
   207
		of the extension attribute.
sl@0
   208
	@return KErrNone if successful;
sl@0
   209
		KErrBadHandle if the instance of RSgImage is a null handle;
sl@0
   210
		KErrNotSupported if no extension of the Graphics Resource API defines 
sl@0
   211
		an extension attribute that applies to the image with the given UID.
sl@0
   212
	@panic SGRES 1 No RSgDriver handle has been opened in the context of the process.
sl@0
   213
	@panic SGRES 3 The instance of RSgImage is an invalid handle.
sl@0
   214
	*/
sl@0
   215
	IMPORT_C TInt GetAttribute(TUid aUid, TInt& aValue) const;
sl@0
   216
sl@0
   217
	/**
sl@0
   218
	Retrieves the list of pixel formats supported by the implementation 
sl@0
   219
	of the Graphics Resource API for images with the usage given by the 
sl@0
   220
	parameter aUsage and returns KErrNone if successful. 
sl@0
   221
	This is a utility function typically called before creating images.
sl@0
   222
sl@0
   223
	@pre The parameter aUsage has at least one usage bit set.
sl@0
   224
	@pre The number of elements in the array referenced by the parameter 
sl@0
   225
		aPixelFormats is zero.
sl@0
   226
	@param[in] aUsage A combination of usages from TSgUsageBits.
sl@0
   227
	@param[out] aPixelFormats A reference to an array that on input must be empty 
sl@0
   228
		and on return contains the list of supported pixel formats.
sl@0
   229
	@param[in] aAttributes A pointer to an array with extension image attributes, 
sl@0
   230
		if any extension of the Graphics Resource API defines extension image 
sl@0
   231
		attributes that have an impact on the list of supported pixel formats, 
sl@0
   232
		or NULL otherwise.
sl@0
   233
	@return KErrNone if successful;
sl@0
   234
		KErrArgument if either 
sl@0
   235
			1. the parameter aUsage does not have at least one usage bit set or 
sl@0
   236
			2. the number of elements in the array referenced by the parameter 
sl@0
   237
				aPixelFormats was not zero before calling this function;
sl@0
   238
		KErrNotSupported if the parameter aAttributes is not NULL and one or 
sl@0
   239
			more of the extension attributes in the array is not defined by any 
sl@0
   240
			extension of the Graphics Resource API;
sl@0
   241
		KErrNoMemory if there is not enough system memory to add a pixel format 
sl@0
   242
			to the array referenced by the parameter aPixelFormats.
sl@0
   243
	*/
sl@0
   244
	IMPORT_C static TInt GetPixelFormats(TUint32 aUsage,
sl@0
   245
	                                     RArray<TInt>& aPixelFormats,
sl@0
   246
	                                     const TSgAttributeArrayBase* aAttributes = NULL);
sl@0
   247
	};
sl@0
   248
sl@0
   249
#include <sgresource/sgimage.inl>
sl@0
   250
sl@0
   251
#endif // SGIMAGE_H