First public contribution.
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Graphics Resource - general functionality
21 #include <sgresource/sgconst.h>
24 Panic codes defined for use by the Graphics Resource API.
26 enum TSgResourcePanicReason
29 ESgPanicUnclosedResources = 2,
30 ESgPanicBadDrawableHandle = 3,
31 ESgPanicBadAttributeArrayIndex = 4
35 Panics the calling thread with category “SGRES” and the given panic code.
36 @param aReason The panic code.
38 inline void Panic(TSgResourcePanicReason aReason);
41 A handle to the implementation of the Graphics Resource API
42 initialised in the context of a process. It groups miscellaneous functions that
43 do not apply to individual drawable resources.
45 At least one thread in the process must call RSgDriver::Open() before the
46 Graphics Resource API can be used in the context of the process.
47 When the Graphics Resource API is no longer needed RSgDriver::Close() should be
48 called to release unused resources. Note that it is possible to call RSgDriver::Open()
49 and RSgDriver::Close() from different threads.
51 NONSHARABLE_CLASS(RSgDriver)
56 @post The instance of RSgDriver is a null handle.
61 Initialises the implementation of the Graphics Resource API in the context
62 of a process if it is not initialised already, updates the implementation
63 opening count in the process and returns KErrNone if successful.
64 Each successful call to RSgDriver::Open() in a process should be balanced
65 by a corresponding call to RSgDriver::Close() in the same process, but not
66 necessarily from the same thread.
68 Note that an RSgDriver handle should never be bitwise-copied into another
69 but this function should be used instead in all cases, since it is the only
70 way to ensure that the implementation opening count is kept up to date.
71 Failure to keep the implementation opening count up to date may result in
72 the implementation of the Graphics Resource API becoming unexpectedly
73 unavailable and, as a consequence, in an abnormal termination of the process.
75 @pre The instance of RSgDriver is a null handle.
76 @post The instance of RSgDriver references the implementation of the Graphics
77 Resource API initialised in the context of the process.
78 @return KErrNone if successful;
79 KErrInUse if the instance of RSgDriver is not a null handle;
80 KErrNoMemory if there is not enough system memory to initialise the
81 implementation of the Graphics Resource API;
82 KErrNoGraphicsMemory if there is not enough specialised graphics memory
83 to initialise the implementation of the Graphics Resource API.
88 Decrements the implementation opening count in the process.
89 When the count reaches zero, checks whether there are still open handles to
90 drawable resources in the process and carries out termination tasks to
91 release the internal resources used by the implementation of the Graphics
94 An attempt to carry out these termination tasks will panic with category
95 “SGRES” and code 2 in debug builds if there still are any open handles to
96 drawable resources in the process. In release builds all the open handles
97 to drawable resources in the process are silently closed at this point.
98 Calling this function on a null handle has no effect.
100 @post The instance of RSgDriver is a null handle.
101 @panic SGRES 2 Debug builds only. There are open handles to drawable resources
102 in the process during termination.
104 IMPORT_C void Close();
107 Makes the extension interface specified by the type of the parameter
108 aInterfacePtr available in the context of the process.
109 This function stores a pointer to the extension interface in the variable
110 referenced by the parameter aInterfacePtr and returns KErrNone if successful.
112 @pre An RSgDriver has been opened in the context of the process.
113 @param[out] aInterfacePtr Reference to a pointer to the interface class that on return points
114 to the extension interface or, in case of error, is set to NULL.
115 @return KErrNone if successful;
116 KErrBadHandle if the instance of RSgDriver is a null handle;
117 KErrExtensionNotSupported if the requested extension interface is not supported.
119 template<class M> inline TInt GetInterface(M*& aInterfacePtr) const;
122 Returns the version of the implementation of the Graphics Resource API.
123 The version comprises 3 numbers: major version number, minor version number
126 Major revisions mean incompatible changes in the API.
127 Minor revisions mean forward-compatible changes in the API.
128 Build numbers are unrelated to API changes.
130 @return The version of the implementation of the Graphics Resource API.
132 IMPORT_C static TVersion Version();
136 Implementation not provided. Declared private to prevent bit-wise copying
139 RSgDriver(const RSgDriver&);
143 Implementation not provided. Declared private to prevent bit-wise copying
146 const RSgDriver& operator =(const RSgDriver&);
149 Makes the extension interface with the given UID available in the context
151 This function stores a pointer to the extension interface in the variable
152 referenced by the parameter aInterfacePtr and returns KErrNone if successful.
154 @pre An RSgDriver has been opened in the context of the process.
155 @param[in] aInterfaceUid The UID of the extension interface.
156 @param[out] aInterfacePtr Reference to an untyped pointer that on return points
157 to the extension interface or, in case of error, is set to NULL.
158 @return KErrNone if successful;
159 KErrBadHandle if the instance of RSgDriver is a null handle;
160 KErrArgument if aInterfaceUid is the null UID;
161 KErrExtensionNotSupported if the requested extension interface is not supported.
163 IMPORT_C TInt GetInterface(TUid aInterfaceUid, TAny*& aInterfacePtr) const;
165 /** A pointer to an implementation-defined object initially set to NULL by the constructor.*/
170 An extension attribute.
172 NONSHARABLE_CLASS(TSgAttribute)
177 Data members remain uninitialised.
179 inline TSgAttribute();
182 Constructor which initialises data members to the given values.
184 inline TSgAttribute(TUid aUid, TInt aValue);
186 /** A UID that identifies the type of extension attribute.*/
188 /** The value of the extension attribute.*/
193 Base class of all attribute array classes.
194 It defines functions for bounds-checked access to extension attributes.
196 NONSHARABLE_CLASS(TSgAttributeArrayBase)
200 Returns the number of extension attributes in the array.
201 @return The number of extension attributes in the array.
203 inline TInt Count() const;
206 Returns a reference to the extension attribute located in the array at the
209 @pre aIndex is equal to or greater than zero and less than the number of
210 extension attributes in the array.
211 @param aIndex The position of the extension attribute in the array.
212 @return A reference to the extension attribute located in the array at the
214 @panic SGRES 4 Debug builds only. aIndex is out of bounds.
216 inline TSgAttribute& operator [](TInt aIndex);
219 Returns a const-qualified reference to the extension attribute located in
220 the array at the given position.
222 @pre aIndex is equal to or greater than zero and less than the number of
223 extension attributes in the array.
224 @param aIndex The position of the extension attribute in the array.
225 @return A reference to the extension attribute located in the array at the
227 @panic SGRES 4 Debug builds only. aIndex is out of bounds.
229 inline const TSgAttribute& operator [](TInt aIndex) const;
232 Constructor used by constructors of derived classes to initialise the
234 @param aCount The number of extension attributes.
236 inline TSgAttributeArrayBase(TInt aCount);
240 No operation is performed. Allows the compiler to generate assignment
241 operators for derived classes automatically.
243 inline void operator =(const TSgAttributeArrayBase&);
249 A fixed-size array of extension attributes.
250 It is a thin wrapper with bounds checking for arrays of TSgAttribute.
253 NONSHARABLE_CLASS(TSgAttributeArray): public TSgAttributeArrayBase
258 Data members remain uninitialised.
260 inline TSgAttributeArray();
262 TSgAttribute iAttributes[S];
266 A system-wide unique 64-bit identifier that can be used to share a drawable
267 resource between processes.
269 The actual value of a drawable resource identifier has no meaning to the user
270 of the Graphics Resource API, except that 64 zero bits represent the null
271 drawable resource identifier, which explicitly identifies no drawable resource.
272 As a convenience, the constant KSgNullDrawableId is defined as the null drawable
275 NONSHARABLE_CLASS(TSgDrawableId)
280 Tests whether the given drawable resource identifier is the same as this.
282 @param aId The drawable resource identifier to compare with this.
283 @return ETrue if the 64-bit identifiers are the same, EFalse if not.
285 inline TBool operator ==(TSgDrawableId aId) const;
289 Tests whether the given drawable resource identifier is different from this.
291 @param aId The drawable resource identifier to compare with this.
292 @return ETrue if the 64-bit identifiers are different, EFalse if they are the same.
294 inline TBool operator !=(TSgDrawableId aId) const;
296 /** The 64-bit identifier.*/
301 The null drawable resource identifier.
303 const TSgDrawableId KSgNullDrawableId = {0};
306 The UID identifying a RSgDrawable handle.
307 This must never be changed.
309 const TUid KSgDrawableTypeUid = {0x102858EB};
312 A drawable resource handle.
313 A null handle is a handle that explicitly does not reference any drawable resource.
314 An open handle is a handle that references an existing drawable resource.
315 An invalid handle is a handle that is not null but does not reference any
316 existing drawable resource.
317 Drawable resources are reference-counted so that a drawable resource is not
318 destroyed while there still are open handles to it in any process in the system.
320 RSgDrawable is not an abstract class, that is, it can be instantiated,
321 but it can also be derived from to define subclasses representing types of
322 handles that refer only to concrete types of drawable resources, for example,
323 image handles. RSgImage is the only subclass of RSgDrawable defined in version
324 1.1 of the Graphics Resource API.
325 Instances of RSgDrawable are useful when drawable resources created in a
326 component have to be passed to another component through a third component that
327 cannot depend on the concrete type of the drawable resources being passed.
330 NONSHARABLE_CLASS(RSgDrawable)
335 @post The instance of RSgDrawable is a null handle.
337 inline RSgDrawable();
340 Opens a new handle to the drawable resource with the given drawable resource
342 The drawable resource may have been created in the same process or in a
343 different one. This function does not allocate any specialised graphics memory.
345 Note that an RSgDrawable handle should never be bitwise-copied into another
346 but this function should be used instead in all cases, since it is the only
347 way to ensure that the reference count of the drawable resource is kept up
348 to date. Failure to keep the reference count of the resource up to date may
349 result in invalid handles.
351 @pre An RSgDriver handle has been opened in the context of the process.
352 @pre The instance of RSgDrawable is a null handle.
353 @post The specified drawable resource has its reference count incremented by one.
354 @param aId The identifier of the drawable resource.
355 @param aAttributes A pointer to an array of extension attributes,
356 if allowed by any extension of the Graphics Resource API, or NULL otherwise.
357 @return KErrNone if successful;
358 KErrInUse if the instance of RSgDrawable is an open handle;
359 KErrArgument if the parameter aId is the null drawable resource identifier;
360 KErrNotSupported if the parameter aAttributes is not NULL and one or more
361 of the extension attributes in the array is not defined by any extension
362 of the Graphics Resource API;
363 KErrNotFound if the parameter aId cannot be found to refer to an existing
365 KErrNoMemory if it fails due to lack of system memory.
366 @panic SGRES 1 No RSgDriver handle has been opened in the context of the process.
368 IMPORT_C TInt Open(TSgDrawableId aId, const TSgAttributeArrayBase* aAttributes = NULL);
371 Closes a handle to a drawable resource.
372 It decrements the reference count of the drawable resource and, if it reaches
373 zero, destroys the drawable resource.
374 Calling this function on a null handle has no effect.
376 @pre If the instance of RSgDrawable is not a null handle then an RSgDriver
377 handle has been opened in the context of the process.
378 @post The instance of RSgDrawable is a null handle.
379 @panic SGRES 1 The instance of RSgDrawable is not a null handle and no
380 RSgDriver handle has been opened in the context of the process.
381 @panic SGRES 3 The instance of RSgDrawable is an invalid handle.
383 IMPORT_C void Close();
386 Returns the identifier of the drawable resource.
387 This identifier can be used to open another handle to the drawable resource
388 in the same process or in a different process.
389 Calling this function on a null handle returns the null drawable resource
392 @pre If the instance of RSgDrawable is not a null handle then an RSgDriver
393 handle has been opened in the context of the process.
394 @return The identifier of the drawable resource.
395 @panic SGRES 1 The instance of RSgDrawable is not a null handle and no
396 RSgDriver handle has been opened in the context of the process.
397 @panic SGRES 3 The instance of RSgDrawable is an invalid handle.
399 IMPORT_C TSgDrawableId Id() const;
402 Tests whether a handle is null.
403 @return ETrue if the instance of RSgDrawable is a null handle; EFalse otherwise.
405 inline TBool IsNull() const;
408 Returns the UID corresponding to the concrete type of the drawable resource
409 referenced by a handle at run-time.
410 Calling this function on a null handle returns the null UID.
411 In version 1.1 of the Graphics Resource API every drawable resource is an image,
412 so this function always returns KSgImageTypeUid when called on an open handle.
414 @pre If the instance of RSgDrawable is not a null handle then an RSgDriver
415 handle has been opened in the context of the process.
416 @return The UID corresponding to the concrete type of the drawable resource.
417 @panic SGRES 1 The instance of RSgDrawable is not a null handle and no
418 RSgDriver handle has been opened in the context of the process.
419 @panic SGRES 3 The instance of RSgDrawable is an invalid handle.
421 IMPORT_C TUid DrawableType() const;
424 Makes the extension interface specified by the type of the parameter
425 aInterfacePtr available on a drawable resource.
426 This function stores a pointer to the extension interface in the variable
427 referenced by the parameter aInterfacePtr and returns KErrNone if successful.
428 The returned extension interface is tied to the drawable resource, that is,
429 calls to functions in the returned extension interface operate on the
432 @pre An RSgDriver handle has been opened in the context of the process.
433 @pre The instance of RSgDrawable is an open handle.
434 @param[out] aInterfacePtr Reference to a pointer to the interface class. that on return points
435 to the extension interface or, in case of error, is set to NULL.
436 @return KErrNone if successful;
437 KErrBadHandle if the instance of RSgDrawable is a null handle;
438 KErrExtensionNotSupported if the requested extension interface is not supported.
439 @panic SGRES 1 No RSgDriver handle has been opened in the context of the process.
440 @panic SGRES 3 The instance of RSgDrawable is an invalid handle.
442 template<class M> inline TInt GetInterface(M*& aInterfacePtr) const;
445 Handle base constructor.
446 Used by constructors of derived classes to initialise the handle type.
447 @post The instance of RSgDrawable is a null handle.
448 @param aHandleType The UID identifying the handle type.
450 inline RSgDrawable(TUid aHandleType);
454 Implementation not provided. Declared private to prevent bit-wise copying
457 RSgDrawable(const RSgDrawable&);
461 Implementation not provided. Declared private to prevent bit-wise copying
464 const RSgDrawable& operator =(const RSgDrawable&);
467 Makes the extension interface with the given UID available on a drawable
469 This function stores a pointer to the extension interface in the variable
470 referenced by the parameter aInterfacePtr and returns KErrNone if successful.
471 The returned extension interface is tied to the drawable resource, that is,
472 calls to functions in the returned extension interface operate on the
475 @pre An RSgDriver handle has been opened in the context of the process.
476 @pre The instance of RSgDrawable is an open handle.
477 @param[in] aInterfaceUid The UID of the extension interface.
478 @param[out] aInterfacePtr Reference to an untyped pointer that on return points
479 to the extension interface or, in case of error, is set to NULL.
480 @return KErrNone if successful;
481 KErrBadHandle if the instance of RSgDrawable is a null handle;
482 KErrArgument if aInterfaceUid is the null UID;
483 KErrExtensionNotSupported if the requested extension interface is not supported.
484 @panic SGRES 1 No RSgDriver handle has been opened in the context of the process.
485 @panic SGRES 3 The instance of RSgDrawable is an invalid handle.
487 IMPORT_C TInt GetInterface(TUid aInterfaceUid, TAny*& aInterfacePtr) const;
490 A UID permanently set by the constructor to the constant
491 KSgDrawableTypeUid, except for subclasses of RSgDrawable, in which case it
492 is permanently set by the constructor to the UID corresponding to the
493 concrete type of drawable resource referenced by instances of the subclass.
495 const TUid iHandleType;
497 /** A pointer to an implementation-defined object initially set to NULL by the constructor.*/
501 #include <sgresource/sgresource.inl>
503 #endif // SGRESOURCE_H