os/graphics/graphicsresourceservices/graphicsresourceadaptation/inc/sgimageimpl.h
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicsresourceservices/graphicsresourceadaptation/inc/sgimageimpl.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,374 @@
1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +/**
1.20 + @file
1.21 + @internalComponent
1.22 +*/
1.23 +
1.24 +#ifndef SGIMAGEIMPL_H
1.25 +#define SGIMAGEIMPL_H
1.26 +
1.27 +#include "sgimageadapter.h"
1.28 +#include "sgdriverimpl.h"
1.29 +#include "sgimage_sw.h"
1.30 +#include "sgimage_chunk.h"
1.31 +
1.32 +
1.33 +/**
1.34 +@internalComponent
1.35 +
1.36 +This class encapsulates the adapter-specific metadata associated with an image.
1.37 +User attributes are excluded.
1.38 +*/
1.39 +class TSgImageMetaData
1.40 + {
1.41 +public:
1.42 + TSgImageMetaData(const TSgImageInfo& aInfo, TArray<TSgPixelFormatTableEntry> aPixelFormatTable, TBool aIsCached = ETrue);
1.43 + void GetInfo(TSgImageInfo& aInfo, TBool aGetPotentialUsage = EFalse) const;
1.44 +public:
1.45 + /**
1.46 + The identifier of the process that created the image.
1.47 + */
1.48 + TProcessId iCreatorProcess;
1.49 + /**
1.50 + The size of the image in pixels.
1.51 + */
1.52 + TSize iSizeInPixels;
1.53 + /**
1.54 + The pixel format of the image.
1.55 + */
1.56 + TUidPixelFormat iPixelFormat;
1.57 + /**
1.58 + The intended usage of the image as requested during creation.
1.59 + */
1.60 + TUint32 iRequestedUsage;
1.61 + /**
1.62 + The potential usage of the image as allowed by the implementation of the Graphics
1.63 + subsystem. This is calculated from the image attributes, excluding the requested
1.64 + usage, and the pixel format support table.
1.65 + */
1.66 + TUint32 iPotentialUsage;
1.67 + /**
1.68 + Whether the image is shareable between processes.
1.69 + */
1.70 + TBool iShareable;
1.71 + /**
1.72 + Whether and how the image is mappable for CPU access.
1.73 + */
1.74 + TSgCpuAccess iCpuAccess;
1.75 + /**
1.76 + The identifier of the screen on which the image is usable or -1 if the image
1.77 + is usable on all screens.
1.78 + */
1.79 + TInt iScreenId;
1.80 + /**
1.81 + Whether the image is CPU-cached.
1.82 + */
1.83 + TBool iIsCached;
1.84 + };
1.85 +
1.86 +
1.87 +/**
1.88 +@internalComponent
1.89 +
1.90 +Base class for all classes representing image state. The state of an image consists
1.91 +of the following items:
1.92 + - The situation in memory of the pixel data. In platforms with Unified Memory
1.93 + Architecture this is simply the address and stride of the pixel data in system
1.94 + memory, since the image is always located in system memory. In other memory
1.95 + architectures the image might change location between specialised graphics
1.96 + memory and system memory, for example.
1.97 + - The situation in memory of the metadata and the user attributes. In the current
1.98 + image implementation based on the Surface Manager the metadata is stored in
1.99 + the same memory chunk as the pixel data and the user attributes are stored
1.100 + as surface hints.
1.101 + - Whether and how the pixel data is being accessed by the CPU.
1.102 +
1.103 +@see XSgImageImplBase
1.104 +*/
1.105 +class XSgImageStateBase: public XSgBase
1.106 + {
1.107 +public:
1.108 + virtual const TSgImageMetaData& MetaData() const = 0;
1.109 + virtual TInt GetUserAttributes(TSgUserAttribute* aUserAttributes, TInt aUserAttributeCount) const = 0;
1.110 + virtual TAny* DataAddress() const = 0;
1.111 + inline TInt DataStride() const;
1.112 + virtual TInt BeginDataAccess(TSgCpuAccess aCpuAccess, TBool aIsUserAccess);
1.113 + virtual TInt EndDataAccess(TBool aIsUserAccess);
1.114 +protected:
1.115 + inline XSgImageStateBase(XSgDriverImpl& aDriverImpl);
1.116 + inline XSgImageStateBase(XSgDriverImpl& aDriverImpl, TInt aDataStride);
1.117 +protected:
1.118 + /**
1.119 + The number of bytes between rows of the pixel data.
1.120 + */
1.121 + TInt iDataStride;
1.122 + /**
1.123 + Whether the pixel data is being accessed by the CPU for reading only, for
1.124 + writing only, for reading and writing or not at all.
1.125 + */
1.126 + TSgCpuAccess iCpuAccess;
1.127 + /**
1.128 + The level of CPU access, if any:
1.129 + - If ETrue the pixel data is being accessed by the CPU from the application
1.130 + level through a call to RSgImage::MapReadOnly(), RSgImage::MapWriteOnly()
1.131 + or RSgImage::MapReadWrite().
1.132 + - If EFalse the pixel data is being accessed by the CPU from the Graphics
1.133 + subsystem level through the MSgImage_Sw extension interface.
1.134 + */
1.135 + TBool iIsUserAccess;
1.136 + };
1.137 +
1.138 +
1.139 +/**
1.140 +@internalComponent
1.141 +
1.142 +Base class for all image adapter objects. This class currently implements the
1.143 +MSgImage_Sw extension interface, since it assumes a platform with Unified Memory
1.144 +Architecture and therefore availability of the extension interface on all images.
1.145 +
1.146 +@see XSgImageStateBase
1.147 +*/
1.148 +class XSgImageImplBase: public XSgBase, public MSgImageAdapter, public MSgImage_Sw
1.149 + {
1.150 +public:
1.151 + ~XSgImageImplBase();
1.152 + inline const TSgImageMetaData& MetaData() const;
1.153 + static TInt Compare(const TSgDrawableId* aId, const XSgImageImplBase& aImage);
1.154 + static TInt Compare(const XSgImageImplBase& aImage1, const XSgImageImplBase& aImage2);
1.155 + static TInt CompareIgnoringFlags(const TSgDrawableId* aId, const XSgImageImplBase& aImage);
1.156 + // From MSgResourceAdapter
1.157 + void Close();
1.158 + // From MSgDrawableAdapter
1.159 + const TSgDrawableId& Id() const;
1.160 + TUid DrawableType() const;
1.161 + TInt GetInterface(TUid aInterfaceUid, TAny*& aInterfacePtr);
1.162 + // From MSgImageAdapter
1.163 + TInt GetInfo(TSgImageInfo& aInfo) const;
1.164 + TInt MapReadOnly(const TAny*& aDataAddress, TInt& aDataStride);
1.165 + TInt MapWriteOnly(TAny*& aDataAddress, TInt& aDataStride);
1.166 + TInt MapReadWrite(TAny*& aDataAddress, TInt& aDataStride);
1.167 + TInt Unmap();
1.168 + // From MSgImage_Sw
1.169 + TAny* DataAddress() const;
1.170 + TInt DataStride() const;
1.171 + TInt BeginDataAccess(TSgCpuAccess aCpuAccess);
1.172 + TInt EndDataAccess();
1.173 +protected:
1.174 + inline XSgImageImplBase(XSgDriverImpl& aDriverImpl);
1.175 + inline XSgImageImplBase(XSgDriverImpl& aDriverImpl, const TSgDrawableId& aId);
1.176 + XSgImageImplBase(const XSgImageImplBase& aImage, TUint32 aFlags);
1.177 + TInt SetData(const TAny* aDataAddress, TInt aDataStride);
1.178 +protected:
1.179 + /** The unique identifier of the image. */
1.180 + TSgDrawableId iId;
1.181 + /** The state of the image. */
1.182 + XSgImageStateBase* iState;
1.183 + };
1.184 +
1.185 +
1.186 +/**
1.187 +@internalComponent
1.188 +
1.189 +The position, as index into an array of 32-bit words, of the 32 bits reserved
1.190 +for flags in the unique identifier of an image.
1.191 +*/
1.192 +const TInt KSgImageIdFlagsIndex = 5;
1.193 +
1.194 +
1.195 +#ifndef SYMBIAN_GRAPHICS_USE_GPU
1.196 +
1.197 +/**
1.198 +@internalComponent
1.199 +
1.200 +The structure of the unique identifier of an image allocated in memory that is
1.201 +accessible only from the user-side of the creator process.
1.202 +
1.203 +@see XSgImageImpl_SwLocal
1.204 +*/
1.205 +class TSgImageId_SwLocal
1.206 + {
1.207 +public:
1.208 + inline static TBool IsMatch(const TSgDrawableId& aId);
1.209 +public:
1.210 + /** 64 bits reserved for the identifier of the creator process. */
1.211 + TUint64 iProcessId;
1.212 + /** 64 random bits. */
1.213 + TUint32 iRandom[2];
1.214 + /** 32 bits set to "1". */
1.215 + TInt32 iMinusOne;
1.216 + /** 32 bits reserved for flags. */
1.217 + TUint32 iFlags;
1.218 + };
1.219 +
1.220 +
1.221 +/**
1.222 +@internalComponent
1.223 +
1.224 +This class represents the state of an image allocated in memory that is accessible
1.225 +only from the user-side of the creator process.
1.226 +
1.227 +@see XSgImageImpl_SwLocal
1.228 +*/
1.229 +class XSgImageState_SwLocal: public XSgImageStateBase
1.230 + {
1.231 +public:
1.232 + static TInt New(XSgImageState_SwLocal*& aPtr, XSgDriverImpl& aDriverImpl, const TSgImageInfo& aInfo);
1.233 + const TSgImageMetaData& MetaData() const;
1.234 + TInt GetUserAttributes(TSgUserAttribute* aUserAttributes, TInt aUserAttributeCount) const;
1.235 + TAny* DataAddress() const;
1.236 +private:
1.237 + XSgImageState_SwLocal(XSgDriverImpl& aDriverImpl, const TSgImageInfo& aInfo, TInt aDataStride);
1.238 +private:
1.239 + /**
1.240 + The metadata of the image.
1.241 + */
1.242 + TSgImageMetaData iMetaData;
1.243 + /**
1.244 + The number of user attributes.
1.245 + */
1.246 + TInt iUserAttributeCount;
1.247 + /**
1.248 + The user attributes of the image. The pixel data of the image is stored after
1.249 + them in the same heap cell.
1.250 + */
1.251 + TSgUserAttribute iUserAttributes[1];
1.252 + };
1.253 +
1.254 +
1.255 +/**
1.256 +@internalComponent
1.257 +
1.258 +An adapter object representing an image allocated in memory that is accessible only
1.259 +from the user-side of the creator process. Non-shareable images are allocated in
1.260 +this way on platforms without hardware acceleration. The pixel data, the metadata
1.261 +and the user attributes of such an image are stored in the same heap cell.
1.262 +
1.263 +@see XSgImageState_SwLocal
1.264 +*/
1.265 +class XSgImageImpl_SwLocal: public XSgImageImplBase
1.266 + {
1.267 +public:
1.268 + static TInt New(XSgImageImpl_SwLocal*& aPtr, XSgDriverImpl& aDriverImpl, const TSgDrawableId& aId,
1.269 + const TSgImageInfo& aInfo, const TAny* aDataAddress, TInt aDataStride);
1.270 + static TInt New(XSgImageImpl_SwLocal*& aPtr, const XSgImageImpl_SwLocal& aImage, TUint32 aFlags);
1.271 +private:
1.272 + inline XSgImageImpl_SwLocal(XSgDriverImpl& aDriverImpl, const TSgDrawableId& aId);
1.273 + inline XSgImageImpl_SwLocal(const XSgImageImpl_SwLocal& aImage, TUint32 aFlags);
1.274 + TInt Construct(const TSgImageInfo& aInfo, const TAny* aDataAddress, TInt aDataStride);
1.275 + };
1.276 +
1.277 +#endif
1.278 +
1.279 +
1.280 +/**
1.281 +@internalComponent
1.282 +
1.283 +The structure of the unique identifier of an image stored in a surface buffer.
1.284 +
1.285 +@see XSgImageImpl_SurfaceManager
1.286 +*/
1.287 +class TSgImageId_SurfaceManager
1.288 + {
1.289 +public:
1.290 + inline static TBool IsMatch(const TSgDrawableId& aId);
1.291 +public:
1.292 + /** 128 bits reserved for the surface identifier. */
1.293 + TSurfaceId iSurfaceId;
1.294 + /** 16 bits reserved for the index to the surface buffer. */
1.295 + TInt16 iBufferIndex;
1.296 + /** 16 bits reserved for the index to the metadata. */
1.297 + TInt16 iMetaDataIndex;
1.298 + /** 32 bits reserved for flags. */
1.299 + TUint32 iFlags;
1.300 + };
1.301 +
1.302 +
1.303 +/**
1.304 +@internalComponent
1.305 +
1.306 +This class represents the state of an image stored in a surface buffer.
1.307 +
1.308 +@see XSgImageImpl_SurfaceManager
1.309 +*/
1.310 +class XSgImageState_SurfaceManager: public XSgImageStateBase
1.311 + {
1.312 +public:
1.313 + static TInt New(XSgImageState_SurfaceManager*& aPtr, XSgDriverImpl& aDriverImpl, const TSgImageInfo& aInfo, TBool aIsCached);
1.314 + static TInt New(XSgImageState_SurfaceManager*& aPtr, XSgDriverImpl& aDriverImpl, const TSgDrawableId& aId);
1.315 + ~XSgImageState_SurfaceManager();
1.316 + const TSgImageMetaData& MetaData() const;
1.317 + TInt GetUserAttributes(TSgUserAttribute* aUserAttributes, TInt aUserAttributeCount) const;
1.318 + TAny* DataAddress() const;
1.319 +#ifdef SYMBIAN_GRAPHICS_AUTOFLUSH_CACHE
1.320 + TInt BeginDataAccess(TSgCpuAccess aCpuAccess, TBool aIsUserAccess);
1.321 + TInt EndDataAccess(TBool aIsUserAccess);
1.322 +#endif
1.323 + inline const TSurfaceId& SurfaceId() const;
1.324 + inline const RChunk& DataChunk() const;
1.325 + inline TInt DataOffset() const;
1.326 +private:
1.327 + inline XSgImageState_SurfaceManager(XSgDriverImpl& aDriverImpl);
1.328 + TInt Construct(const TSgImageInfo& aInfo, TBool aIsCached);
1.329 + TInt Construct(const TSgDrawableId& aId);
1.330 +private:
1.331 + /** The identifier of the surface in which the image is stored. */
1.332 + TSurfaceId iSurfaceId;
1.333 + /** Index to the surface buffer in which the image is stored. */
1.334 + TInt iBufferIndex;
1.335 + /** Offset to the metadata from the base of the underlying memory chunk. */
1.336 + TInt iMetaDataOffset;
1.337 + /** Handle to the underlying memory chunk. */
1.338 + RChunk iDataChunk;
1.339 + /** Offset to the pixel data from the base of the underlying memory chunk. */
1.340 + TInt iDataOffset;
1.341 + };
1.342 +
1.343 +
1.344 +/**
1.345 +@internalComponent
1.346 +
1.347 +An adapter object representing an image stored in a surface buffer. The metadata
1.348 +of such an image is stored at the beginning of the underlying memory chunk.
1.349 +
1.350 +@see XSgImageState_SurfaceManager
1.351 +*/
1.352 +class XSgImageImpl_SurfaceManager: public XSgImageImplBase, public MSgImage_Chunk
1.353 + {
1.354 +public:
1.355 + static TInt New(XSgImageImpl_SurfaceManager*& aPtr, XSgDriverImpl& aDriverImpl,
1.356 + const TSgImageInfo& aInfo, TBool aIsCached, const TAny* aDataAddress, TInt aDataStride);
1.357 + static TInt New(XSgImageImpl_SurfaceManager*& aPtr, XSgDriverImpl& aDriverImpl, const TSgDrawableId& aId);
1.358 + static TInt New(XSgImageImpl_SurfaceManager*& aPtr, const XSgImageImpl_SurfaceManager& aImage, TUint32 aFlags);
1.359 + // From MSgDrawableAdapter
1.360 + TInt GetInterface(TUid aInterfaceUid, TAny*& aInterfacePtr);
1.361 + // From MSgImage_Chunk
1.362 + const RChunk& DataChunk() const;
1.363 + TInt DataOffset() const;
1.364 + TInt DataStride() const;
1.365 +private:
1.366 + inline XSgImageImpl_SurfaceManager(XSgDriverImpl& aDriverImpl);
1.367 + inline XSgImageImpl_SurfaceManager(XSgDriverImpl& aDriverImpl, const TSgDrawableId& aId);
1.368 + inline XSgImageImpl_SurfaceManager(const XSgImageImpl_SurfaceManager& aImage, TUint32 aFlags);
1.369 + TInt Construct(const TSgImageInfo& aInfo, TBool aIsCached, const TAny* aDataAddress, TInt aDataStride);
1.370 + TInt Construct(const TSgDrawableId& aId);
1.371 + };
1.372 +
1.373 +
1.374 +#include "sgimageimpl.inl"
1.375 +
1.376 +
1.377 +#endif // SGIMAGEIMPL_H