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: #include "directgdiadapter.h" sl@0: #include "directgdiimagesourceimpl.h" sl@0: #include "directgdidriverimpl.h" sl@0: #include "directgdidriverprocessstate.h" sl@0: #include sl@0: sl@0: /** sl@0: Constructs a CDirectGdiImageSourceImpl. sl@0: @param aDriver The driver implementation which created this target. sl@0: */ sl@0: CDirectGdiImageSourceImpl::CDirectGdiImageSourceImpl(CDirectGdiDriverImpl& aDriver) : sl@0: iDriver(aDriver), sl@0: iVgImage(VG_INVALID_HANDLE) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Destructor. sl@0: sl@0: @post The associated VgImage (if any) is destroyed by the process state. sl@0: This image is removed from the associated driver's list of source images. sl@0: */ sl@0: CDirectGdiImageSourceImpl::~CDirectGdiImageSourceImpl() sl@0: { sl@0: GRAPHICS_LOG_DEBUG("Destroying CDirectGdiImageSourceImpl"); sl@0: if (iVgImage != VG_INVALID_HANDLE) sl@0: { sl@0: iDriver.ProcessState().DestroyVgImage(iDriver.EglDisplay(), iVgImage); sl@0: } sl@0: iDriver.UnregisterSourceImage(*this); sl@0: } sl@0: sl@0: /** sl@0: Two-phase construction of a CDirectGdiImageSourceImpl object. sl@0: @param aImage On success, holds a pointer to the newly-created image. sl@0: @param aDriver The driver to register this image with. sl@0: @param aSgImage The RSgImage which this image will be based upon. sl@0: @return KErrNone if successful, KErrNoMemory if not enough memory could be allocated, otherwise a return sl@0: value from Construct(). sl@0: */ sl@0: TInt CDirectGdiImageSourceImpl::New(CDirectGdiImageSourceImpl*& aImage, CDirectGdiDriverImpl& aDriver, const RSgImage& aSgImage) sl@0: { sl@0: CDirectGdiImageSourceImpl* image = new CDirectGdiImageSourceImpl(aDriver); sl@0: if (!image) sl@0: return KErrNoMemory; sl@0: TInt err = image->Construct(aSgImage); sl@0: if (err == KErrNone) sl@0: aImage = image; sl@0: else sl@0: delete image; sl@0: return err; sl@0: } sl@0: sl@0: /** sl@0: Gets the supplied image structure and sets the internal data. sl@0: Registers itself with the driver. sl@0: sl@0: @param aSgImage The RSgImage to create the source image from. sl@0: @return KErrNone if successful, otherwise an error from CDirectGdiImageRef::Construct(). sl@0: */ sl@0: TInt CDirectGdiImageSourceImpl::Construct(const RSgImage& aSgImage) sl@0: { sl@0: TInt err = CDirectGdiImageRef::Construct(aSgImage); sl@0: sl@0: if (err == KErrNone) sl@0: { sl@0: // Let the process state create the VGImage as EGLImages and their associated VGImages sl@0: // are shared across all threads in this process. (Only one EGLImage can be created per RSgImage sl@0: // in a process). sl@0: err = iDriver.ProcessState().CreateVgImage(iDriver.EglDisplay(), iVgImage, iSgImage); sl@0: } sl@0: sl@0: if (err == KErrNone) sl@0: { sl@0: err = iDriver.RegisterSourceImage(*this); sl@0: } sl@0: sl@0: if (err == KErrNone) sl@0: { sl@0: Open(); sl@0: } sl@0: sl@0: return err; sl@0: } sl@0: