|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @internalComponent |
|
19 */ |
|
20 |
|
21 #ifndef SGIMAGEIMPL_H |
|
22 #define SGIMAGEIMPL_H |
|
23 |
|
24 #include "sgimageadapter.h" |
|
25 #include "sgdriverimpl.h" |
|
26 #include "sgimage_sw.h" |
|
27 #include "sgimage_chunk.h" |
|
28 |
|
29 |
|
30 /** |
|
31 @internalComponent |
|
32 |
|
33 This class encapsulates the adapter-specific metadata associated with an image. |
|
34 User attributes are excluded. |
|
35 */ |
|
36 class TSgImageMetaData |
|
37 { |
|
38 public: |
|
39 TSgImageMetaData(const TSgImageInfo& aInfo, TArray<TSgPixelFormatTableEntry> aPixelFormatTable, TBool aIsCached = ETrue); |
|
40 void GetInfo(TSgImageInfo& aInfo, TBool aGetPotentialUsage = EFalse) const; |
|
41 public: |
|
42 /** |
|
43 The identifier of the process that created the image. |
|
44 */ |
|
45 TProcessId iCreatorProcess; |
|
46 /** |
|
47 The size of the image in pixels. |
|
48 */ |
|
49 TSize iSizeInPixels; |
|
50 /** |
|
51 The pixel format of the image. |
|
52 */ |
|
53 TUidPixelFormat iPixelFormat; |
|
54 /** |
|
55 The intended usage of the image as requested during creation. |
|
56 */ |
|
57 TUint32 iRequestedUsage; |
|
58 /** |
|
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. |
|
62 */ |
|
63 TUint32 iPotentialUsage; |
|
64 /** |
|
65 Whether the image is shareable between processes. |
|
66 */ |
|
67 TBool iShareable; |
|
68 /** |
|
69 Whether and how the image is mappable for CPU access. |
|
70 */ |
|
71 TSgCpuAccess iCpuAccess; |
|
72 /** |
|
73 The identifier of the screen on which the image is usable or -1 if the image |
|
74 is usable on all screens. |
|
75 */ |
|
76 TInt iScreenId; |
|
77 /** |
|
78 Whether the image is CPU-cached. |
|
79 */ |
|
80 TBool iIsCached; |
|
81 }; |
|
82 |
|
83 |
|
84 /** |
|
85 @internalComponent |
|
86 |
|
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 |
|
97 as surface hints. |
|
98 - Whether and how the pixel data is being accessed by the CPU. |
|
99 |
|
100 @see XSgImageImplBase |
|
101 */ |
|
102 class XSgImageStateBase: public XSgBase |
|
103 { |
|
104 public: |
|
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); |
|
111 protected: |
|
112 inline XSgImageStateBase(XSgDriverImpl& aDriverImpl); |
|
113 inline XSgImageStateBase(XSgDriverImpl& aDriverImpl, TInt aDataStride); |
|
114 protected: |
|
115 /** |
|
116 The number of bytes between rows of the pixel data. |
|
117 */ |
|
118 TInt iDataStride; |
|
119 /** |
|
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. |
|
122 */ |
|
123 TSgCpuAccess iCpuAccess; |
|
124 /** |
|
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. |
|
131 */ |
|
132 TBool iIsUserAccess; |
|
133 }; |
|
134 |
|
135 |
|
136 /** |
|
137 @internalComponent |
|
138 |
|
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. |
|
142 |
|
143 @see XSgImageStateBase |
|
144 */ |
|
145 class XSgImageImplBase: public XSgBase, public MSgImageAdapter, public MSgImage_Sw |
|
146 { |
|
147 public: |
|
148 ~XSgImageImplBase(); |
|
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 |
|
154 void Close(); |
|
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); |
|
164 TInt Unmap(); |
|
165 // From MSgImage_Sw |
|
166 TAny* DataAddress() const; |
|
167 TInt DataStride() const; |
|
168 TInt BeginDataAccess(TSgCpuAccess aCpuAccess); |
|
169 TInt EndDataAccess(); |
|
170 protected: |
|
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); |
|
175 protected: |
|
176 /** The unique identifier of the image. */ |
|
177 TSgDrawableId iId; |
|
178 /** The state of the image. */ |
|
179 XSgImageStateBase* iState; |
|
180 }; |
|
181 |
|
182 |
|
183 /** |
|
184 @internalComponent |
|
185 |
|
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. |
|
188 */ |
|
189 const TInt KSgImageIdFlagsIndex = 5; |
|
190 |
|
191 |
|
192 #ifndef SYMBIAN_GRAPHICS_USE_GPU |
|
193 |
|
194 /** |
|
195 @internalComponent |
|
196 |
|
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. |
|
199 |
|
200 @see XSgImageImpl_SwLocal |
|
201 */ |
|
202 class TSgImageId_SwLocal |
|
203 { |
|
204 public: |
|
205 inline static TBool IsMatch(const TSgDrawableId& aId); |
|
206 public: |
|
207 /** 64 bits reserved for the identifier of the creator process. */ |
|
208 TUint64 iProcessId; |
|
209 /** 64 random bits. */ |
|
210 TUint32 iRandom[2]; |
|
211 /** 32 bits set to "1". */ |
|
212 TInt32 iMinusOne; |
|
213 /** 32 bits reserved for flags. */ |
|
214 TUint32 iFlags; |
|
215 }; |
|
216 |
|
217 |
|
218 /** |
|
219 @internalComponent |
|
220 |
|
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. |
|
223 |
|
224 @see XSgImageImpl_SwLocal |
|
225 */ |
|
226 class XSgImageState_SwLocal: public XSgImageStateBase |
|
227 { |
|
228 public: |
|
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; |
|
233 private: |
|
234 XSgImageState_SwLocal(XSgDriverImpl& aDriverImpl, const TSgImageInfo& aInfo, TInt aDataStride); |
|
235 private: |
|
236 /** |
|
237 The metadata of the image. |
|
238 */ |
|
239 TSgImageMetaData iMetaData; |
|
240 /** |
|
241 The number of user attributes. |
|
242 */ |
|
243 TInt iUserAttributeCount; |
|
244 /** |
|
245 The user attributes of the image. The pixel data of the image is stored after |
|
246 them in the same heap cell. |
|
247 */ |
|
248 TSgUserAttribute iUserAttributes[1]; |
|
249 }; |
|
250 |
|
251 |
|
252 /** |
|
253 @internalComponent |
|
254 |
|
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. |
|
259 |
|
260 @see XSgImageState_SwLocal |
|
261 */ |
|
262 class XSgImageImpl_SwLocal: public XSgImageImplBase |
|
263 { |
|
264 public: |
|
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); |
|
268 private: |
|
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); |
|
272 }; |
|
273 |
|
274 #endif |
|
275 |
|
276 |
|
277 /** |
|
278 @internalComponent |
|
279 |
|
280 The structure of the unique identifier of an image stored in a surface buffer. |
|
281 |
|
282 @see XSgImageImpl_SurfaceManager |
|
283 */ |
|
284 class TSgImageId_SurfaceManager |
|
285 { |
|
286 public: |
|
287 inline static TBool IsMatch(const TSgDrawableId& aId); |
|
288 public: |
|
289 /** 128 bits reserved for the surface identifier. */ |
|
290 TSurfaceId iSurfaceId; |
|
291 /** 16 bits reserved for the index to the surface buffer. */ |
|
292 TInt16 iBufferIndex; |
|
293 /** 16 bits reserved for the index to the metadata. */ |
|
294 TInt16 iMetaDataIndex; |
|
295 /** 32 bits reserved for flags. */ |
|
296 TUint32 iFlags; |
|
297 }; |
|
298 |
|
299 |
|
300 /** |
|
301 @internalComponent |
|
302 |
|
303 This class represents the state of an image stored in a surface buffer. |
|
304 |
|
305 @see XSgImageImpl_SurfaceManager |
|
306 */ |
|
307 class XSgImageState_SurfaceManager: public XSgImageStateBase |
|
308 { |
|
309 public: |
|
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); |
|
319 #endif |
|
320 inline const TSurfaceId& SurfaceId() const; |
|
321 inline const RChunk& DataChunk() const; |
|
322 inline TInt DataOffset() const; |
|
323 private: |
|
324 inline XSgImageState_SurfaceManager(XSgDriverImpl& aDriverImpl); |
|
325 TInt Construct(const TSgImageInfo& aInfo, TBool aIsCached); |
|
326 TInt Construct(const TSgDrawableId& aId); |
|
327 private: |
|
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. */ |
|
331 TInt iBufferIndex; |
|
332 /** Offset to the metadata from the base of the underlying memory chunk. */ |
|
333 TInt iMetaDataOffset; |
|
334 /** Handle to the underlying memory chunk. */ |
|
335 RChunk iDataChunk; |
|
336 /** Offset to the pixel data from the base of the underlying memory chunk. */ |
|
337 TInt iDataOffset; |
|
338 }; |
|
339 |
|
340 |
|
341 /** |
|
342 @internalComponent |
|
343 |
|
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. |
|
346 |
|
347 @see XSgImageState_SurfaceManager |
|
348 */ |
|
349 class XSgImageImpl_SurfaceManager: public XSgImageImplBase, public MSgImage_Chunk |
|
350 { |
|
351 public: |
|
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; |
|
362 private: |
|
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); |
|
368 }; |
|
369 |
|
370 |
|
371 #include "sgimageimpl.inl" |
|
372 |
|
373 |
|
374 #endif // SGIMAGEIMPL_H |