os/graphics/graphicsresourceservices/graphicsresourceadaptation/inc/sgimageimpl.h
Update contrib.
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.
24 #include "sgimageadapter.h"
25 #include "sgdriverimpl.h"
26 #include "sgimage_sw.h"
27 #include "sgimage_chunk.h"
33 This class encapsulates the adapter-specific metadata associated with an image.
34 User attributes are excluded.
36 class TSgImageMetaData
39 TSgImageMetaData(const TSgImageInfo& aInfo, TArray<TSgPixelFormatTableEntry> aPixelFormatTable, TBool aIsCached = ETrue);
40 void GetInfo(TSgImageInfo& aInfo, TBool aGetPotentialUsage = EFalse) const;
43 The identifier of the process that created the image.
45 TProcessId iCreatorProcess;
47 The size of the image in pixels.
51 The pixel format of the image.
53 TUidPixelFormat iPixelFormat;
55 The intended usage of the image as requested during creation.
57 TUint32 iRequestedUsage;
59 The potential usage of the image as allowed by the implementation of the Graphics
60 subsystem. This is calculated from the image attributes, excluding the requested
61 usage, and the pixel format support table.
63 TUint32 iPotentialUsage;
65 Whether the image is shareable between processes.
69 Whether and how the image is mappable for CPU access.
71 TSgCpuAccess iCpuAccess;
73 The identifier of the screen on which the image is usable or -1 if the image
74 is usable on all screens.
78 Whether the image is CPU-cached.
87 Base class for all classes representing image state. The state of an image consists
88 of the following items:
89 - The situation in memory of the pixel data. In platforms with Unified Memory
90 Architecture this is simply the address and stride of the pixel data in system
91 memory, since the image is always located in system memory. In other memory
92 architectures the image might change location between specialised graphics
93 memory and system memory, for example.
94 - The situation in memory of the metadata and the user attributes. In the current
95 image implementation based on the Surface Manager the metadata is stored in
96 the same memory chunk as the pixel data and the user attributes are stored
98 - Whether and how the pixel data is being accessed by the CPU.
100 @see XSgImageImplBase
102 class XSgImageStateBase: public XSgBase
105 virtual const TSgImageMetaData& MetaData() const = 0;
106 virtual TInt GetUserAttributes(TSgUserAttribute* aUserAttributes, TInt aUserAttributeCount) const = 0;
107 virtual TAny* DataAddress() const = 0;
108 inline TInt DataStride() const;
109 virtual TInt BeginDataAccess(TSgCpuAccess aCpuAccess, TBool aIsUserAccess);
110 virtual TInt EndDataAccess(TBool aIsUserAccess);
112 inline XSgImageStateBase(XSgDriverImpl& aDriverImpl);
113 inline XSgImageStateBase(XSgDriverImpl& aDriverImpl, TInt aDataStride);
116 The number of bytes between rows of the pixel data.
120 Whether the pixel data is being accessed by the CPU for reading only, for
121 writing only, for reading and writing or not at all.
123 TSgCpuAccess iCpuAccess;
125 The level of CPU access, if any:
126 - If ETrue the pixel data is being accessed by the CPU from the application
127 level through a call to RSgImage::MapReadOnly(), RSgImage::MapWriteOnly()
128 or RSgImage::MapReadWrite().
129 - If EFalse the pixel data is being accessed by the CPU from the Graphics
130 subsystem level through the MSgImage_Sw extension interface.
139 Base class for all image adapter objects. This class currently implements the
140 MSgImage_Sw extension interface, since it assumes a platform with Unified Memory
141 Architecture and therefore availability of the extension interface on all images.
143 @see XSgImageStateBase
145 class XSgImageImplBase: public XSgBase, public MSgImageAdapter, public MSgImage_Sw
149 inline const TSgImageMetaData& MetaData() const;
150 static TInt Compare(const TSgDrawableId* aId, const XSgImageImplBase& aImage);
151 static TInt Compare(const XSgImageImplBase& aImage1, const XSgImageImplBase& aImage2);
152 static TInt CompareIgnoringFlags(const TSgDrawableId* aId, const XSgImageImplBase& aImage);
153 // From MSgResourceAdapter
155 // From MSgDrawableAdapter
156 const TSgDrawableId& Id() const;
157 TUid DrawableType() const;
158 TInt GetInterface(TUid aInterfaceUid, TAny*& aInterfacePtr);
159 // From MSgImageAdapter
160 TInt GetInfo(TSgImageInfo& aInfo) const;
161 TInt MapReadOnly(const TAny*& aDataAddress, TInt& aDataStride);
162 TInt MapWriteOnly(TAny*& aDataAddress, TInt& aDataStride);
163 TInt MapReadWrite(TAny*& aDataAddress, TInt& aDataStride);
166 TAny* DataAddress() const;
167 TInt DataStride() const;
168 TInt BeginDataAccess(TSgCpuAccess aCpuAccess);
169 TInt EndDataAccess();
171 inline XSgImageImplBase(XSgDriverImpl& aDriverImpl);
172 inline XSgImageImplBase(XSgDriverImpl& aDriverImpl, const TSgDrawableId& aId);
173 XSgImageImplBase(const XSgImageImplBase& aImage, TUint32 aFlags);
174 TInt SetData(const TAny* aDataAddress, TInt aDataStride);
176 /** The unique identifier of the image. */
178 /** The state of the image. */
179 XSgImageStateBase* iState;
186 The position, as index into an array of 32-bit words, of the 32 bits reserved
187 for flags in the unique identifier of an image.
189 const TInt KSgImageIdFlagsIndex = 5;
192 #ifndef SYMBIAN_GRAPHICS_USE_GPU
197 The structure of the unique identifier of an image allocated in memory that is
198 accessible only from the user-side of the creator process.
200 @see XSgImageImpl_SwLocal
202 class TSgImageId_SwLocal
205 inline static TBool IsMatch(const TSgDrawableId& aId);
207 /** 64 bits reserved for the identifier of the creator process. */
209 /** 64 random bits. */
211 /** 32 bits set to "1". */
213 /** 32 bits reserved for flags. */
221 This class represents the state of an image allocated in memory that is accessible
222 only from the user-side of the creator process.
224 @see XSgImageImpl_SwLocal
226 class XSgImageState_SwLocal: public XSgImageStateBase
229 static TInt New(XSgImageState_SwLocal*& aPtr, XSgDriverImpl& aDriverImpl, const TSgImageInfo& aInfo);
230 const TSgImageMetaData& MetaData() const;
231 TInt GetUserAttributes(TSgUserAttribute* aUserAttributes, TInt aUserAttributeCount) const;
232 TAny* DataAddress() const;
234 XSgImageState_SwLocal(XSgDriverImpl& aDriverImpl, const TSgImageInfo& aInfo, TInt aDataStride);
237 The metadata of the image.
239 TSgImageMetaData iMetaData;
241 The number of user attributes.
243 TInt iUserAttributeCount;
245 The user attributes of the image. The pixel data of the image is stored after
246 them in the same heap cell.
248 TSgUserAttribute iUserAttributes[1];
255 An adapter object representing an image allocated in memory that is accessible only
256 from the user-side of the creator process. Non-shareable images are allocated in
257 this way on platforms without hardware acceleration. The pixel data, the metadata
258 and the user attributes of such an image are stored in the same heap cell.
260 @see XSgImageState_SwLocal
262 class XSgImageImpl_SwLocal: public XSgImageImplBase
265 static TInt New(XSgImageImpl_SwLocal*& aPtr, XSgDriverImpl& aDriverImpl, const TSgDrawableId& aId,
266 const TSgImageInfo& aInfo, const TAny* aDataAddress, TInt aDataStride);
267 static TInt New(XSgImageImpl_SwLocal*& aPtr, const XSgImageImpl_SwLocal& aImage, TUint32 aFlags);
269 inline XSgImageImpl_SwLocal(XSgDriverImpl& aDriverImpl, const TSgDrawableId& aId);
270 inline XSgImageImpl_SwLocal(const XSgImageImpl_SwLocal& aImage, TUint32 aFlags);
271 TInt Construct(const TSgImageInfo& aInfo, const TAny* aDataAddress, TInt aDataStride);
280 The structure of the unique identifier of an image stored in a surface buffer.
282 @see XSgImageImpl_SurfaceManager
284 class TSgImageId_SurfaceManager
287 inline static TBool IsMatch(const TSgDrawableId& aId);
289 /** 128 bits reserved for the surface identifier. */
290 TSurfaceId iSurfaceId;
291 /** 16 bits reserved for the index to the surface buffer. */
293 /** 16 bits reserved for the index to the metadata. */
294 TInt16 iMetaDataIndex;
295 /** 32 bits reserved for flags. */
303 This class represents the state of an image stored in a surface buffer.
305 @see XSgImageImpl_SurfaceManager
307 class XSgImageState_SurfaceManager: public XSgImageStateBase
310 static TInt New(XSgImageState_SurfaceManager*& aPtr, XSgDriverImpl& aDriverImpl, const TSgImageInfo& aInfo, TBool aIsCached);
311 static TInt New(XSgImageState_SurfaceManager*& aPtr, XSgDriverImpl& aDriverImpl, const TSgDrawableId& aId);
312 ~XSgImageState_SurfaceManager();
313 const TSgImageMetaData& MetaData() const;
314 TInt GetUserAttributes(TSgUserAttribute* aUserAttributes, TInt aUserAttributeCount) const;
315 TAny* DataAddress() const;
316 #ifdef SYMBIAN_GRAPHICS_AUTOFLUSH_CACHE
317 TInt BeginDataAccess(TSgCpuAccess aCpuAccess, TBool aIsUserAccess);
318 TInt EndDataAccess(TBool aIsUserAccess);
320 inline const TSurfaceId& SurfaceId() const;
321 inline const RChunk& DataChunk() const;
322 inline TInt DataOffset() const;
324 inline XSgImageState_SurfaceManager(XSgDriverImpl& aDriverImpl);
325 TInt Construct(const TSgImageInfo& aInfo, TBool aIsCached);
326 TInt Construct(const TSgDrawableId& aId);
328 /** The identifier of the surface in which the image is stored. */
329 TSurfaceId iSurfaceId;
330 /** Index to the surface buffer in which the image is stored. */
332 /** Offset to the metadata from the base of the underlying memory chunk. */
333 TInt iMetaDataOffset;
334 /** Handle to the underlying memory chunk. */
336 /** Offset to the pixel data from the base of the underlying memory chunk. */
344 An adapter object representing an image stored in a surface buffer. The metadata
345 of such an image is stored at the beginning of the underlying memory chunk.
347 @see XSgImageState_SurfaceManager
349 class XSgImageImpl_SurfaceManager: public XSgImageImplBase, public MSgImage_Chunk
352 static TInt New(XSgImageImpl_SurfaceManager*& aPtr, XSgDriverImpl& aDriverImpl,
353 const TSgImageInfo& aInfo, TBool aIsCached, const TAny* aDataAddress, TInt aDataStride);
354 static TInt New(XSgImageImpl_SurfaceManager*& aPtr, XSgDriverImpl& aDriverImpl, const TSgDrawableId& aId);
355 static TInt New(XSgImageImpl_SurfaceManager*& aPtr, const XSgImageImpl_SurfaceManager& aImage, TUint32 aFlags);
356 // From MSgDrawableAdapter
357 TInt GetInterface(TUid aInterfaceUid, TAny*& aInterfacePtr);
358 // From MSgImage_Chunk
359 const RChunk& DataChunk() const;
360 TInt DataOffset() const;
361 TInt DataStride() const;
363 inline XSgImageImpl_SurfaceManager(XSgDriverImpl& aDriverImpl);
364 inline XSgImageImpl_SurfaceManager(XSgDriverImpl& aDriverImpl, const TSgDrawableId& aId);
365 inline XSgImageImpl_SurfaceManager(const XSgImageImpl_SurfaceManager& aImage, TUint32 aFlags);
366 TInt Construct(const TSgImageInfo& aInfo, TBool aIsCached, const TAny* aDataAddress, TInt aDataStride);
367 TInt Construct(const TSgDrawableId& aId);
371 #include "sgimageimpl.inl"
374 #endif // SGIMAGEIMPL_H