photosgallery/viewframework/uiutilities/src/glxrequestfreegoom.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Mon, 21 Jun 2010 15:40:32 +0300
branchRCL_3
changeset 47 f9e827349359
child 57 ea65f74e6de4
permissions -rw-r--r--
Revision: 201023 Kit: 2010125

/*
 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). 
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
 * which accompanies this distribution, and is available
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
 *
 * Initial Contributors:
 * Nokia Corporation - initial contribution.
 *
 * Contributors:
 *
 * Description:    Request Goom to free memory in asynch way
 *
 */

#include <glxtracer.h>
#include <glxlog.h>

#include "glxrequestfreegoom.h"

const TInt KMinMemoryRequest = 3145728; // 3 MB

// ----------------------------------------------------------------------------
// CGlxRelaseGPUMemory::NewL
// ----------------------------------------------------------------------------
//
EXPORT_C CGlxRelaseGPUMemory* CGlxRelaseGPUMemory::NewL(
        MGoomNotifierObserver& aNotify)
    {
    TRACER("CGlxRelaseGPUMemory::NewL()");
    CGlxRelaseGPUMemory* self = CGlxRelaseGPUMemory::NewLC(aNotify);
    CleanupStack::Pop(self);
    return self;
    }

// ----------------------------------------------------------------------------
// CGlxRelaseGPUMemory::NewLC
// ----------------------------------------------------------------------------
//
CGlxRelaseGPUMemory* CGlxRelaseGPUMemory::NewLC(
        MGoomNotifierObserver& aNotify)
    {
    TRACER("CGlxRelaseGPUMemory::NewLC()");
    CGlxRelaseGPUMemory* self = new (ELeave) CGlxRelaseGPUMemory(aNotify);
    CleanupStack::PushL(self);
    self->ConstructL();
    return self;
    }

// ----------------------------------------------------------------------------
// CGlxRelaseGPUMemory::CGlxRelaseGPUMemory
// ----------------------------------------------------------------------------
//
CGlxRelaseGPUMemory::CGlxRelaseGPUMemory(MGoomNotifierObserver& aNotify) :
    CActive(CActive::EPriorityStandard), iNotify(aNotify), iIsFirstRequest(
            ETrue)
    {
    TRACER("CGlxRelaseGPUMemory::CGlxRelaseGPUMemory()");
    CActiveScheduler::Add(this);
    }

// ----------------------------------------------------------------------------
// CGlxRelaseGPUMemory::~CGlxRelaseGPUMemory()
// ----------------------------------------------------------------------------
//
CGlxRelaseGPUMemory::~CGlxRelaseGPUMemory()
    {
    TRACER("CGlxRelaseGPUMemory::~CGlxRelaseGPUMemory()");
    Cancel();
    }

// ----------------------------------------------------------------------------
// CGlxRelaseGPUMemory::IssueRequest()
// ----------------------------------------------------------------------------
//
void CGlxRelaseGPUMemory::IssueRequest()
    {
    TRACER("CGlxRelaseGPUMemory::IssueRequest()");
    if (!IsActive())
        {
#ifdef _DEBUG
        iStartTime.HomeTime();
#endif                          
        iGoom.RequestFreeMemory(KMinMemoryRequest, iStatus);
        SetActive();
        }
    }

// ----------------------------------------------------------------------------
// CGlxRelaseGPUMemory::ConstructL()
// ----------------------------------------------------------------------------
//
void CGlxRelaseGPUMemory::ConstructL()
    {
    TRACER("CGlxRelaseGPUMemory::ConstructL()");
    TInt err = iGoom.Connect();
    GLX_LOG_INFO1("CGlxRelaseGPUMemory::ConstructL %d", err);
    User::LeaveIfError(err);
    }

// ----------------------------------------------------------------------------
// CGlxRelaseGPUMemory::RequestMemory()
// ----------------------------------------------------------------------------
//
EXPORT_C void CGlxRelaseGPUMemory::RequestMemory()
    {
    TRACER("CGlxRelaseGPUMemory::RequestMemory()");
    IssueRequest();
    }

// ----------------------------------------------------------------------------
// CGlxRelaseGPUMemory::DoCancel()
// ----------------------------------------------------------------------------
//
void CGlxRelaseGPUMemory::DoCancel()
    {
    TRACER("CGlxRelaseGPUMemory::DoCancel()");
    iGoom.CancelRequestFreeMemory();
    iGoom.Close();
    }

// ----------------------------------------------------------------------------
// CGlxRelaseGPUMemory::RunL
// ----------------------------------------------------------------------------
//
void CGlxRelaseGPUMemory::RunL()
    {
    TRACER("CGlxRelaseGPUMemory::RunL()");
    GLX_LOG_INFO1("CGlxRelaseGPUMemory::RunL %d", iStatus.Int());
#ifdef _DEBUG
    iStopTime.HomeTime();
    GLX_DEBUG2("CGlxRelaseGPUMemory: Mem free GOOM took <%d> us",
            (TInt)iStopTime.MicroSecondsFrom(iStartTime).Int64());
#endif                          

    if (iIsFirstRequest && (iStatus.Int() != KErrNone))
        {
        iIsFirstRequest = EFalse;
        IssueRequest();
        return;
        }

    // Notify observer on the RequestFreeMemory() status
    iNotify.HandleGoomMemoryReleased(iStatus.Int());
    }