os/graphics/graphicsdeviceinterface/directgdiadaptation/swsrc/swdirectgdidriverimpl.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicsdeviceinterface/directgdiadaptation/swsrc/swdirectgdidriverimpl.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,332 @@
     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 +#include "directgdiadapter.h"
    1.20 +#include "swdirectgdidriverimpl.h"
    1.21 +#include "swdirectgdiimagesourceimpl.h"
    1.22 +#include "swdirectgdiimagetargetimpl.h"
    1.23 +#include "pixelutil.h"
    1.24 +#include <e32cmn.h>
    1.25 +#include <pixelformats.h>
    1.26 +#include <graphics/sgimage_sw.h>
    1.27 +
    1.28 +/**
    1.29 +@panic DGDIAdapter 6, if the reference count to DirectGDI driver is invalid.
    1.30 +@panic DGDIAdapter 45, if objects are still in the source or target image array.
    1.31 +*/
    1.32 +CSwDirectGdiDriverImpl::~CSwDirectGdiDriverImpl()
    1.33 +	{
    1.34 +	GRAPHICS_ASSERT_DEBUG(iEngines.Count() == 0, EDirectGdiPanicDriverInvalidRefCount);
    1.35 +	GRAPHICS_ASSERT_DEBUG(iTargets.Count() == 0, EDirectGdiPanicItemsLeftInImageArray);
    1.36 +	GRAPHICS_ASSERT_DEBUG(iImageSources.Count() == 0, EDirectGdiPanicItemsLeftInImageArray);
    1.37 +	
    1.38 +	// Delete all the engines owned by this driver
    1.39 +	iEngines.ResetAndDestroy();
    1.40 +	iTargets.ResetAndDestroy();
    1.41 +	iImageSources.ResetAndDestroy();
    1.42 +	}
    1.43 +
    1.44 +/**
    1.45 +Constructor, which initialises base class.
    1.46 +*/
    1.47 +CSwDirectGdiDriverImpl::CSwDirectGdiDriverImpl(RLibrary aLibrary)
    1.48 +	: CDirectGdiDriverInternal(aLibrary)
    1.49 +	{
    1.50 +	}
    1.51 +
    1.52 +/**
    1.53 +Empty function as this adaptation is synchronous.
    1.54 +@see CDirectGdiDriverInternal::Flush()
    1.55 +*/
    1.56 +void CSwDirectGdiDriverImpl::Flush()
    1.57 +	{
    1.58 +	}
    1.59 +
    1.60 +/**
    1.61 +Empty function as this adaptation is synchronous.
    1.62 +@see CDirectGdiDriverInternal::Finish()
    1.63 +*/
    1.64 +void CSwDirectGdiDriverImpl::Finish()
    1.65 +	{
    1.66 +	}
    1.67 +
    1.68 +/**
    1.69 +@see CDirectGdiDriver::GetError()
    1.70 +*/
    1.71 +TInt CSwDirectGdiDriverImpl::GetError()
    1.72 +	{
    1.73 +	TInt err = iErrorCode;
    1.74 +	iErrorCode = KErrNone;
    1.75 +	return err;
    1.76 +	}
    1.77 +
    1.78 +/**
    1.79 +@see CDirectGdiDriverInternal::CloseDrawableSource()
    1.80 +@panic DGDIAdapter 57, if aHandleRet is not KNullHandle (debug only).
    1.81 +*/
    1.82 +TInt CSwDirectGdiDriverImpl::CreateDrawableSource(TInt& aHandleRet, const RSgDrawable& aSgDrawable)
    1.83 +	{
    1.84 +	TInt err = KErrNotSupported;
    1.85 +	const TUid typeUid = aSgDrawable.DrawableType(); 
    1.86 +	if(KSgImageTypeUid == typeUid)
    1.87 +		{
    1.88 +		CSwDirectGdiImageSourceImpl* imageSource = NULL;
    1.89 +		RSgImage* image =  (RSgImage*) (&aSgDrawable);
    1.90 +		err = CSwDirectGdiImageSourceImpl::New(imageSource, *this, *image);
    1.91 +	
    1.92 +		if (err == KErrNone)
    1.93 +			{
    1.94 +			aHandleRet = reinterpret_cast<TInt>(imageSource);
    1.95 +			}
    1.96 +		}
    1.97 +	return err;
    1.98 +	}
    1.99 +	
   1.100 +/**
   1.101 +@see CDirectGdiDriverInternal::CreateDrawableSource()
   1.102 +@panic DGDIAdapter 47, if the drawable source belonging to aHandle could not be found in the internal 
   1.103 +	   list of sources (debug only).
   1.104 +*/
   1.105 +void CSwDirectGdiDriverImpl::CloseDrawableSource(TInt& aHandle)
   1.106 +	{
   1.107 +	// Graphics Resource and DirectGDI reference implementation only support pixel based resource
   1.108 +	CSwDirectGdiImageSourceImpl* source = reinterpret_cast<CSwDirectGdiImageSourceImpl*>(aHandle);
   1.109 +	if (source)
   1.110 +		source->Close();
   1.111 +	aHandle = KNullHandle;
   1.112 +	}
   1.113 +	
   1.114 +/**
   1.115 +@see CDirectGdiDriverInternal::CreateImageTarget()
   1.116 +@panic DGDIAdapter 58, if aHandleRet is not KNullHandle (debug only).
   1.117 +@panic DGDIAdapter 1023, if the attempt to get an RSgImage interface MSgImage_Sw failed.
   1.118 +*/
   1.119 +TInt CSwDirectGdiDriverImpl::CreateImageTarget(TInt& aHandleRet, const RSgImage& aImage)
   1.120 +	{
   1.121 +	TSgImageInfo info;
   1.122 +	TInt ret = aImage.GetInfo(info);
   1.123 +	if (ret != KErrNone)
   1.124 +		{
   1.125 +		return ret;
   1.126 +		}
   1.127 +	TDisplayMode displayMode = PixelFormatUtil::ConvertToDisplayMode(info.iPixelFormat);
   1.128 +	TSize size = info.iSizeInPixels;
   1.129 +	CFbsDrawDevice* device = NULL;
   1.130 +	const MSgImage_Sw* pImage;
   1.131 +	TInt err = aImage.GetInterface(pImage);
   1.132 +	GRAPHICS_ASSERT_DEBUG((err == KErrNone) && (pImage != NULL), EDirectGdiPanicInvalidInterfaceHandle);
   1.133 +	TRAP(err, device = CFbsDrawDevice::NewBitmapDeviceL(size, displayMode, pImage->DataStride()));
   1.134 +	if (err != KErrNone)
   1.135 +		{		
   1.136 +		return err;
   1.137 +		}	
   1.138 +		
   1.139 +	// Setup the new device with the memory from the image
   1.140 +	device->SetBits(pImage->DataAddress());
   1.141 +		
   1.142 +	// Create a new image
   1.143 +	if (err == KErrNone)
   1.144 +		{
   1.145 +		CSwDirectGdiImageTargetImpl* target = NULL;
   1.146 +		err = CSwDirectGdiImageTargetImpl::New(target, *this, device, aImage);
   1.147 +		if (err == KErrNone)
   1.148 +			{
   1.149 +			// Make sure we aren't overwriting an exisiting valid handle.
   1.150 +			GRAPHICS_ASSERT_DEBUG(aHandleRet == KNullHandle, EDirectGdiPanicTargetHandleNotNull);
   1.151 +			aHandleRet = reinterpret_cast<TInt>(target);
   1.152 +			}		
   1.153 +		}
   1.154 +	
   1.155 +	if (err != KErrNone)
   1.156 +		{
   1.157 +		delete device;
   1.158 +		}
   1.159 +		
   1.160 +	return err;
   1.161 +	}
   1.162 +	
   1.163 +/**
   1.164 +@see CDirectGdiDriverInternal::CloseImageTarget()
   1.165 +@panic DGDIAdapter 40, if the image target associated with aHandle could not be found in the 
   1.166 +       internal list of targets (debug only).	
   1.167 +*/
   1.168 +void CSwDirectGdiDriverImpl::CloseImageTarget(TInt& aHandle)
   1.169 +	{
   1.170 +	CSwDirectGdiImageTargetImpl* target = reinterpret_cast<CSwDirectGdiImageTargetImpl*>(aHandle);
   1.171 +	if (target)
   1.172 +		target->Close();
   1.173 +	aHandle = KNullHandle;
   1.174 +	}
   1.175 +	
   1.176 +		
   1.177 +/**
   1.178 +@see CDirectGdiDriverInteral::CreateEngine()
   1.179 +*/
   1.180 +TInt CSwDirectGdiDriverImpl::CreateEngine(MDirectGdiEngine*& aEngine)
   1.181 +	{
   1.182 +	TInt err = KErrNoMemory; 
   1.183 +	CSwDirectGdiEngine* engine = new CSwDirectGdiEngine(this);
   1.184 +	aEngine = engine;	
   1.185 +	if(engine != NULL)	
   1.186 +		{		
   1.187 +		// Put this in an array so we can destroy it on close
   1.188 +		err = iEngines.InsertInAddressOrder(engine);
   1.189 +		if (KErrNone != err)
   1.190 +			{
   1.191 +			delete engine;
   1.192 +			aEngine = NULL;
   1.193 +			}
   1.194 +		}
   1.195 +	return err;
   1.196 +	}
   1.197 +		
   1.198 +/**
   1.199 +@see CDirectGdiDriverInternal::DestroyEngine()
   1.200 +@panic DGDIAdapter 60, if aEngine could not be found in the internal list of engines (debug only).
   1.201 +*/
   1.202 +void CSwDirectGdiDriverImpl::DestroyEngine(MDirectGdiEngine* aEngine)
   1.203 +	{
   1.204 +	TInt index = iEngines.FindInAddressOrder(aEngine);
   1.205 +	GRAPHICS_ASSERT_DEBUG(index != KErrNotFound, EDirectGdiPanicEngineNotFound);
   1.206 +	iEngines.Remove(index);
   1.207 +	delete (static_cast<CSwDirectGdiEngine*>(aEngine));
   1.208 +	}
   1.209 +
   1.210 +/**
   1.211 +@see CDirectGdiDriverInternal::SetError()
   1.212 +*/
   1.213 +void CSwDirectGdiDriverImpl::SetError(TInt aErr)
   1.214 +	{
   1.215 +	if (aErr != KErrNone && iErrorCode == KErrNone)
   1.216 +		{
   1.217 +		iErrorCode = aErr;
   1.218 +		}
   1.219 +	}
   1.220 +
   1.221 +/**
   1.222 +No extensions interfaces are supported.
   1.223 +
   1.224 +@see CDirectGdiDriver::GetInterface()
   1.225 + */
   1.226 +TInt CSwDirectGdiDriverImpl::GetInterface(TUid /*aInterfaceId*/, TAny*& aInterface)
   1.227 +	{
   1.228 +	aInterface = NULL;	
   1.229 +	return KErrExtensionNotSupported;			
   1.230 +	}
   1.231 +
   1.232 +/**
   1.233 +Deactivate the target if it was the current target, decrement the reference count of the target as it can be shared 
   1.234 +across many DirectGDI contexts.
   1.235 +
   1.236 +@param 	aRenderingTarget The target object which you want to deactivate.
   1.237 +
   1.238 +@panic DGDIAdapter 55, if aRengeringTarget is NULL.
   1.239 +*/
   1.240 +void CSwDirectGdiDriverImpl::Deactivate(CSwDirectGdiImageTargetImpl* aRenderingTarget)
   1.241 +	{
   1.242 +	GRAPHICS_ASSERT_ALWAYS(aRenderingTarget, EDirectGdiPanicNullTargetDeactivate);
   1.243 +	aRenderingTarget->Close();
   1.244 +	}
   1.245 +
   1.246 +/**
   1.247 +Checks whether the image source handle is valid. 
   1.248 +
   1.249 +@param aHandle The handle to an Image Source that should be found.
   1.250 +@return ETrue if aHandle is a valid handle to an image registered with the driver, otherwise EFalse.
   1.251 +*/
   1.252 +TBool CSwDirectGdiDriverImpl::ValidImageSource(TInt aHandle) const
   1.253 +	{
   1.254 +	CSwDirectGdiImageSourceImpl* impl = reinterpret_cast<CSwDirectGdiImageSourceImpl*>(aHandle);
   1.255 +	return iImageSources.FindInAddressOrder(impl) != KErrNotFound;
   1.256 +	}
   1.257 +
   1.258 +/**
   1.259 +Checks whether the target image handle is valid. 
   1.260 +
   1.261 +@param aHandle The handle to an Image Target that should be found.
   1.262 +@return ETrue if aHandle is a valid handle to an image registered with the driver, otherwise EFalse.
   1.263 +*/
   1.264 +TBool CSwDirectGdiDriverImpl::ValidImageTarget(TInt aHandle) const
   1.265 +	{	
   1.266 +	CSwDirectGdiImageTargetImpl* impl = reinterpret_cast<CSwDirectGdiImageTargetImpl*>(aHandle);
   1.267 +	return iTargets.FindInAddressOrder(impl) != KErrNotFound;
   1.268 +	}
   1.269 +
   1.270 +/**
   1.271 +Removes the specified image target from the internal list of targets.
   1.272 +
   1.273 +@param aImageTarget The image to remove.
   1.274 +@return KErrNotFound if it could not be found in the internal list, otherwise KErrNone.
   1.275 +*/
   1.276 +TInt CSwDirectGdiDriverImpl::UnregisterTargetImage(const CSwDirectGdiImageTargetImpl& aImageTarget)
   1.277 +	{
   1.278 +	TInt err = KErrNone;
   1.279 +	TInt index = iTargets.FindInAddressOrder(&aImageTarget);
   1.280 +	if (index == KErrNotFound)
   1.281 +		{
   1.282 +		err = KErrNotFound;
   1.283 +		}
   1.284 +	else
   1.285 +		{
   1.286 +		iTargets.Remove(index);
   1.287 +		iTargets.GranularCompress();
   1.288 +		}
   1.289 +	return err;
   1.290 +	}
   1.291 +
   1.292 +/**
   1.293 +Removes the specified image source from the internal list of sources.
   1.294 +
   1.295 +@param aImageSource The image to remove.
   1.296 +@return KErrNotFound if it could not be found in the internal list, otherwise KErrNone.
   1.297 +*/
   1.298 +TInt CSwDirectGdiDriverImpl::UnregisterSourceImage(const CSwDirectGdiImageSourceImpl& aImageSource)
   1.299 +	{
   1.300 +	TInt err = KErrNone;
   1.301 +	TInt index = iImageSources.FindInAddressOrder(&aImageSource);
   1.302 +	if (index == KErrNotFound)
   1.303 +		{		
   1.304 +		err = KErrNotFound;
   1.305 +		}
   1.306 +	else
   1.307 +		{	
   1.308 +		iImageSources.Remove(index);
   1.309 +		iImageSources.GranularCompress();
   1.310 +		}
   1.311 +	return err;
   1.312 +	}
   1.313 +
   1.314 +/**
   1.315 +Helper function. When an image source is constructed, it registers itself on the driver's internal 
   1.316 +list of image sources.
   1.317 +@param aImageSource The image to add to the array.
   1.318 +@return KErrNone if successful, otherwise one of the system-wide error codes.
   1.319 +*/
   1.320 +TInt CSwDirectGdiDriverImpl::RegisterSourceImage(const CSwDirectGdiImageSourceImpl& aImageSource)
   1.321 +	{
   1.322 +	return iImageSources.InsertInAddressOrder(&aImageSource);
   1.323 +	}
   1.324 +
   1.325 +/**
   1.326 +Helper function. When an image target is constructed, it registers itself on the driver's internal 
   1.327 +list of image targets.
   1.328 +@param aImageTarget The image to add to the array.
   1.329 +@return KErrNone if successful, otherwise one of the system-wide error codes.
   1.330 +*/
   1.331 +TInt CSwDirectGdiDriverImpl::RegisterTargetImage(const CSwDirectGdiImageTargetImpl& aImageTarget)
   1.332 +	{
   1.333 +	return iTargets.InsertInAddressOrder(&aImageTarget);
   1.334 +	}
   1.335 +