sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @internalComponent sl@0: */ sl@0: sl@0: #ifndef SGIMAGEIMPL_H sl@0: #define SGIMAGEIMPL_H sl@0: sl@0: #include "sgimageadapter.h" sl@0: #include "sgdriverimpl.h" sl@0: #include "sgimage_sw.h" sl@0: #include "sgimage_chunk.h" sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: sl@0: This class encapsulates the adapter-specific metadata associated with an image. sl@0: User attributes are excluded. sl@0: */ sl@0: class TSgImageMetaData sl@0: { sl@0: public: sl@0: TSgImageMetaData(const TSgImageInfo& aInfo, TArray aPixelFormatTable, TBool aIsCached = ETrue); sl@0: void GetInfo(TSgImageInfo& aInfo, TBool aGetPotentialUsage = EFalse) const; sl@0: public: sl@0: /** sl@0: The identifier of the process that created the image. sl@0: */ sl@0: TProcessId iCreatorProcess; sl@0: /** sl@0: The size of the image in pixels. sl@0: */ sl@0: TSize iSizeInPixels; sl@0: /** sl@0: The pixel format of the image. sl@0: */ sl@0: TUidPixelFormat iPixelFormat; sl@0: /** sl@0: The intended usage of the image as requested during creation. sl@0: */ sl@0: TUint32 iRequestedUsage; sl@0: /** sl@0: The potential usage of the image as allowed by the implementation of the Graphics sl@0: subsystem. This is calculated from the image attributes, excluding the requested sl@0: usage, and the pixel format support table. sl@0: */ sl@0: TUint32 iPotentialUsage; sl@0: /** sl@0: Whether the image is shareable between processes. sl@0: */ sl@0: TBool iShareable; sl@0: /** sl@0: Whether and how the image is mappable for CPU access. sl@0: */ sl@0: TSgCpuAccess iCpuAccess; sl@0: /** sl@0: The identifier of the screen on which the image is usable or -1 if the image sl@0: is usable on all screens. sl@0: */ sl@0: TInt iScreenId; sl@0: /** sl@0: Whether the image is CPU-cached. sl@0: */ sl@0: TBool iIsCached; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: sl@0: Base class for all classes representing image state. The state of an image consists sl@0: of the following items: sl@0: - The situation in memory of the pixel data. In platforms with Unified Memory sl@0: Architecture this is simply the address and stride of the pixel data in system sl@0: memory, since the image is always located in system memory. In other memory sl@0: architectures the image might change location between specialised graphics sl@0: memory and system memory, for example. sl@0: - The situation in memory of the metadata and the user attributes. In the current sl@0: image implementation based on the Surface Manager the metadata is stored in sl@0: the same memory chunk as the pixel data and the user attributes are stored sl@0: as surface hints. sl@0: - Whether and how the pixel data is being accessed by the CPU. sl@0: sl@0: @see XSgImageImplBase sl@0: */ sl@0: class XSgImageStateBase: public XSgBase sl@0: { sl@0: public: sl@0: virtual const TSgImageMetaData& MetaData() const = 0; sl@0: virtual TInt GetUserAttributes(TSgUserAttribute* aUserAttributes, TInt aUserAttributeCount) const = 0; sl@0: virtual TAny* DataAddress() const = 0; sl@0: inline TInt DataStride() const; sl@0: virtual TInt BeginDataAccess(TSgCpuAccess aCpuAccess, TBool aIsUserAccess); sl@0: virtual TInt EndDataAccess(TBool aIsUserAccess); sl@0: protected: sl@0: inline XSgImageStateBase(XSgDriverImpl& aDriverImpl); sl@0: inline XSgImageStateBase(XSgDriverImpl& aDriverImpl, TInt aDataStride); sl@0: protected: sl@0: /** sl@0: The number of bytes between rows of the pixel data. sl@0: */ sl@0: TInt iDataStride; sl@0: /** sl@0: Whether the pixel data is being accessed by the CPU for reading only, for sl@0: writing only, for reading and writing or not at all. sl@0: */ sl@0: TSgCpuAccess iCpuAccess; sl@0: /** sl@0: The level of CPU access, if any: sl@0: - If ETrue the pixel data is being accessed by the CPU from the application sl@0: level through a call to RSgImage::MapReadOnly(), RSgImage::MapWriteOnly() sl@0: or RSgImage::MapReadWrite(). sl@0: - If EFalse the pixel data is being accessed by the CPU from the Graphics sl@0: subsystem level through the MSgImage_Sw extension interface. sl@0: */ sl@0: TBool iIsUserAccess; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: sl@0: Base class for all image adapter objects. This class currently implements the sl@0: MSgImage_Sw extension interface, since it assumes a platform with Unified Memory sl@0: Architecture and therefore availability of the extension interface on all images. sl@0: sl@0: @see XSgImageStateBase sl@0: */ sl@0: class XSgImageImplBase: public XSgBase, public MSgImageAdapter, public MSgImage_Sw sl@0: { sl@0: public: sl@0: ~XSgImageImplBase(); sl@0: inline const TSgImageMetaData& MetaData() const; sl@0: static TInt Compare(const TSgDrawableId* aId, const XSgImageImplBase& aImage); sl@0: static TInt Compare(const XSgImageImplBase& aImage1, const XSgImageImplBase& aImage2); sl@0: static TInt CompareIgnoringFlags(const TSgDrawableId* aId, const XSgImageImplBase& aImage); sl@0: // From MSgResourceAdapter sl@0: void Close(); sl@0: // From MSgDrawableAdapter sl@0: const TSgDrawableId& Id() const; sl@0: TUid DrawableType() const; sl@0: TInt GetInterface(TUid aInterfaceUid, TAny*& aInterfacePtr); sl@0: // From MSgImageAdapter sl@0: TInt GetInfo(TSgImageInfo& aInfo) const; sl@0: TInt MapReadOnly(const TAny*& aDataAddress, TInt& aDataStride); sl@0: TInt MapWriteOnly(TAny*& aDataAddress, TInt& aDataStride); sl@0: TInt MapReadWrite(TAny*& aDataAddress, TInt& aDataStride); sl@0: TInt Unmap(); sl@0: // From MSgImage_Sw sl@0: TAny* DataAddress() const; sl@0: TInt DataStride() const; sl@0: TInt BeginDataAccess(TSgCpuAccess aCpuAccess); sl@0: TInt EndDataAccess(); sl@0: protected: sl@0: inline XSgImageImplBase(XSgDriverImpl& aDriverImpl); sl@0: inline XSgImageImplBase(XSgDriverImpl& aDriverImpl, const TSgDrawableId& aId); sl@0: XSgImageImplBase(const XSgImageImplBase& aImage, TUint32 aFlags); sl@0: TInt SetData(const TAny* aDataAddress, TInt aDataStride); sl@0: protected: sl@0: /** The unique identifier of the image. */ sl@0: TSgDrawableId iId; sl@0: /** The state of the image. */ sl@0: XSgImageStateBase* iState; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: sl@0: The position, as index into an array of 32-bit words, of the 32 bits reserved sl@0: for flags in the unique identifier of an image. sl@0: */ sl@0: const TInt KSgImageIdFlagsIndex = 5; sl@0: sl@0: sl@0: #ifndef SYMBIAN_GRAPHICS_USE_GPU sl@0: sl@0: /** sl@0: @internalComponent sl@0: sl@0: The structure of the unique identifier of an image allocated in memory that is sl@0: accessible only from the user-side of the creator process. sl@0: sl@0: @see XSgImageImpl_SwLocal sl@0: */ sl@0: class TSgImageId_SwLocal sl@0: { sl@0: public: sl@0: inline static TBool IsMatch(const TSgDrawableId& aId); sl@0: public: sl@0: /** 64 bits reserved for the identifier of the creator process. */ sl@0: TUint64 iProcessId; sl@0: /** 64 random bits. */ sl@0: TUint32 iRandom[2]; sl@0: /** 32 bits set to "1". */ sl@0: TInt32 iMinusOne; sl@0: /** 32 bits reserved for flags. */ sl@0: TUint32 iFlags; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: sl@0: This class represents the state of an image allocated in memory that is accessible sl@0: only from the user-side of the creator process. sl@0: sl@0: @see XSgImageImpl_SwLocal sl@0: */ sl@0: class XSgImageState_SwLocal: public XSgImageStateBase sl@0: { sl@0: public: sl@0: static TInt New(XSgImageState_SwLocal*& aPtr, XSgDriverImpl& aDriverImpl, const TSgImageInfo& aInfo); sl@0: const TSgImageMetaData& MetaData() const; sl@0: TInt GetUserAttributes(TSgUserAttribute* aUserAttributes, TInt aUserAttributeCount) const; sl@0: TAny* DataAddress() const; sl@0: private: sl@0: XSgImageState_SwLocal(XSgDriverImpl& aDriverImpl, const TSgImageInfo& aInfo, TInt aDataStride); sl@0: private: sl@0: /** sl@0: The metadata of the image. sl@0: */ sl@0: TSgImageMetaData iMetaData; sl@0: /** sl@0: The number of user attributes. sl@0: */ sl@0: TInt iUserAttributeCount; sl@0: /** sl@0: The user attributes of the image. The pixel data of the image is stored after sl@0: them in the same heap cell. sl@0: */ sl@0: TSgUserAttribute iUserAttributes[1]; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: sl@0: An adapter object representing an image allocated in memory that is accessible only sl@0: from the user-side of the creator process. Non-shareable images are allocated in sl@0: this way on platforms without hardware acceleration. The pixel data, the metadata sl@0: and the user attributes of such an image are stored in the same heap cell. sl@0: sl@0: @see XSgImageState_SwLocal sl@0: */ sl@0: class XSgImageImpl_SwLocal: public XSgImageImplBase sl@0: { sl@0: public: sl@0: static TInt New(XSgImageImpl_SwLocal*& aPtr, XSgDriverImpl& aDriverImpl, const TSgDrawableId& aId, sl@0: const TSgImageInfo& aInfo, const TAny* aDataAddress, TInt aDataStride); sl@0: static TInt New(XSgImageImpl_SwLocal*& aPtr, const XSgImageImpl_SwLocal& aImage, TUint32 aFlags); sl@0: private: sl@0: inline XSgImageImpl_SwLocal(XSgDriverImpl& aDriverImpl, const TSgDrawableId& aId); sl@0: inline XSgImageImpl_SwLocal(const XSgImageImpl_SwLocal& aImage, TUint32 aFlags); sl@0: TInt Construct(const TSgImageInfo& aInfo, const TAny* aDataAddress, TInt aDataStride); sl@0: }; sl@0: sl@0: #endif sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: sl@0: The structure of the unique identifier of an image stored in a surface buffer. sl@0: sl@0: @see XSgImageImpl_SurfaceManager sl@0: */ sl@0: class TSgImageId_SurfaceManager sl@0: { sl@0: public: sl@0: inline static TBool IsMatch(const TSgDrawableId& aId); sl@0: public: sl@0: /** 128 bits reserved for the surface identifier. */ sl@0: TSurfaceId iSurfaceId; sl@0: /** 16 bits reserved for the index to the surface buffer. */ sl@0: TInt16 iBufferIndex; sl@0: /** 16 bits reserved for the index to the metadata. */ sl@0: TInt16 iMetaDataIndex; sl@0: /** 32 bits reserved for flags. */ sl@0: TUint32 iFlags; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: sl@0: This class represents the state of an image stored in a surface buffer. sl@0: sl@0: @see XSgImageImpl_SurfaceManager sl@0: */ sl@0: class XSgImageState_SurfaceManager: public XSgImageStateBase sl@0: { sl@0: public: sl@0: static TInt New(XSgImageState_SurfaceManager*& aPtr, XSgDriverImpl& aDriverImpl, const TSgImageInfo& aInfo, TBool aIsCached); sl@0: static TInt New(XSgImageState_SurfaceManager*& aPtr, XSgDriverImpl& aDriverImpl, const TSgDrawableId& aId); sl@0: ~XSgImageState_SurfaceManager(); sl@0: const TSgImageMetaData& MetaData() const; sl@0: TInt GetUserAttributes(TSgUserAttribute* aUserAttributes, TInt aUserAttributeCount) const; sl@0: TAny* DataAddress() const; sl@0: #ifdef SYMBIAN_GRAPHICS_AUTOFLUSH_CACHE sl@0: TInt BeginDataAccess(TSgCpuAccess aCpuAccess, TBool aIsUserAccess); sl@0: TInt EndDataAccess(TBool aIsUserAccess); sl@0: #endif sl@0: inline const TSurfaceId& SurfaceId() const; sl@0: inline const RChunk& DataChunk() const; sl@0: inline TInt DataOffset() const; sl@0: private: sl@0: inline XSgImageState_SurfaceManager(XSgDriverImpl& aDriverImpl); sl@0: TInt Construct(const TSgImageInfo& aInfo, TBool aIsCached); sl@0: TInt Construct(const TSgDrawableId& aId); sl@0: private: sl@0: /** The identifier of the surface in which the image is stored. */ sl@0: TSurfaceId iSurfaceId; sl@0: /** Index to the surface buffer in which the image is stored. */ sl@0: TInt iBufferIndex; sl@0: /** Offset to the metadata from the base of the underlying memory chunk. */ sl@0: TInt iMetaDataOffset; sl@0: /** Handle to the underlying memory chunk. */ sl@0: RChunk iDataChunk; sl@0: /** Offset to the pixel data from the base of the underlying memory chunk. */ sl@0: TInt iDataOffset; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: sl@0: An adapter object representing an image stored in a surface buffer. The metadata sl@0: of such an image is stored at the beginning of the underlying memory chunk. sl@0: sl@0: @see XSgImageState_SurfaceManager sl@0: */ sl@0: class XSgImageImpl_SurfaceManager: public XSgImageImplBase, public MSgImage_Chunk sl@0: { sl@0: public: sl@0: static TInt New(XSgImageImpl_SurfaceManager*& aPtr, XSgDriverImpl& aDriverImpl, sl@0: const TSgImageInfo& aInfo, TBool aIsCached, const TAny* aDataAddress, TInt aDataStride); sl@0: static TInt New(XSgImageImpl_SurfaceManager*& aPtr, XSgDriverImpl& aDriverImpl, const TSgDrawableId& aId); sl@0: static TInt New(XSgImageImpl_SurfaceManager*& aPtr, const XSgImageImpl_SurfaceManager& aImage, TUint32 aFlags); sl@0: // From MSgDrawableAdapter sl@0: TInt GetInterface(TUid aInterfaceUid, TAny*& aInterfacePtr); sl@0: // From MSgImage_Chunk sl@0: const RChunk& DataChunk() const; sl@0: TInt DataOffset() const; sl@0: TInt DataStride() const; sl@0: private: sl@0: inline XSgImageImpl_SurfaceManager(XSgDriverImpl& aDriverImpl); sl@0: inline XSgImageImpl_SurfaceManager(XSgDriverImpl& aDriverImpl, const TSgDrawableId& aId); sl@0: inline XSgImageImpl_SurfaceManager(const XSgImageImpl_SurfaceManager& aImage, TUint32 aFlags); sl@0: TInt Construct(const TSgImageInfo& aInfo, TBool aIsCached, const TAny* aDataAddress, TInt aDataStride); sl@0: TInt Construct(const TSgDrawableId& aId); sl@0: }; sl@0: sl@0: sl@0: #include "sgimageimpl.inl" sl@0: sl@0: sl@0: #endif // SGIMAGEIMPL_H