graphicsdeviceinterface/directgdi/src/directgdidrawablesource.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     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 #include "directgdidriver.h"
       
    17 #include "directgdipaniccodes.h"
       
    18 #include <graphics/directgdidrawablesource.h>
       
    19 #include <graphics/sgimage.h>
       
    20 
       
    21 /**
       
    22 Default constructor. 
       
    23 Only for embedding instances of RDirectGdiDrawableSource into other classes as data members. 
       
    24 Before a RDirectGdiDrawableSource can be used the other constructor must be called. 
       
    25 */
       
    26 EXPORT_C RDirectGdiDrawableSource::RDirectGdiDrawableSource()
       
    27 	: iDriver(NULL), iHandle(KNullHandle)
       
    28 	{
       
    29 	}
       
    30 
       
    31 /**
       
    32 Constructor.
       
    33 
       
    34 @param 	aDriver The CDirectGdiDriver for this thread.
       
    35 
       
    36 @pre 	The CDirectGdiDriver object has been initialised from the calling thread.
       
    37 @post 	This handle has a pointer to the CDirectGdiDriver for this thread. 
       
    38 		This handle is not associated with any DirectGDI adaptation-specific resource.
       
    39 */
       
    40 EXPORT_C RDirectGdiDrawableSource::RDirectGdiDrawableSource(CDirectGdiDriver& aDriver)
       
    41 	: iDriver(&aDriver), iHandle(KNullHandle)
       
    42 	{
       
    43 	}
       
    44 
       
    45 /**
       
    46 Creates a DirectGDI adaptation-specific resource that is bound to the specified
       
    47 drawable resource so it can be drawn using the DirectGDI rendering API.
       
    48 
       
    49 @param 	aDrawable The drawable resource.
       
    50 
       
    51 @pre 	CDirectGdiDriver object for this handle has been set. The drawable
       
    52 		resource has been fully constructed.
       
    53 @post 	The DirectGDI adaptation-specific resource that is bound to the given
       
    54 		non-pixel resource is created and this handle is now associated with it.
       
    55 		The reference counter on the drawable resource is incremented.
       
    56 
       
    57 @return KErrNone if successful, KErrArgument if the drawable resource is not
       
    58 		valid, KErrAlreadyExists if this handle is already associated with a
       
    59 		DirectGDI adaptation-specific resource, otherwise one of the system-wide
       
    60 		error codes.
       
    61 @panic  DGDI 18, if this drawable source has no pointer to its assosicated CDirectGdiDriver.
       
    62         This may occur if constructed using the default constructor, and has not yet been 
       
    63         assigned to another drawable source created with the constructor overload.
       
    64 */
       
    65 EXPORT_C TInt RDirectGdiDrawableSource::Create(const RSgDrawable& aDrawable)
       
    66 	{
       
    67 	GRAPHICS_ASSERT_ALWAYS(iDriver, EDirectGdiPanicDrawableSourceWithoutDriver);
       
    68 	return iDriver->CreateDrawableSource(*this, aDrawable);
       
    69 	}
       
    70 
       
    71 /**
       
    72 Destroys the DirectGDI adaptation-specific resource associated with this handle.
       
    73 Calling this method on a handle that is not associated with any DirectGDI 
       
    74 adaptation-specific resource will do nothing. Once Close() is called, this handle can be reused.
       
    75 
       
    76 @pre 	The CDirectGdiDriver object for this handle has been set.
       
    77 @post 	The DirectGDI specific resource associated with this handle will be destroyed,
       
    78 		at any time. This handle is no longer associated with a DirectGDI specific
       
    79 		resource. The reference counter of the underlying drawable resource is
       
    80 		decremented.
       
    81 @panic  DGDI 18, if this drawable source has no pointer to its assosicated CDirectGdiDriver.
       
    82         This may occur if constructed using the default constructor, and has not yet been 
       
    83         assigned to another drawable source created with the constructor overload.
       
    84 */
       
    85 EXPORT_C void RDirectGdiDrawableSource::Close()
       
    86 	{
       
    87 	if (iHandle != KNullHandle)
       
    88 		{
       
    89 		GRAPHICS_ASSERT_ALWAYS(iDriver, EDirectGdiPanicDrawableSourceWithoutDriver);
       
    90 		iDriver->CloseDrawableSource(*this);
       
    91 		}
       
    92 	}