browser/engine/src/Screenshot.cpp
changeset 0 c316ab048e9d
equal deleted inserted replaced
-1:000000000000 0:c316ab048e9d
       
     1 /*
       
     2  * Name        : Screenshot.cpp
       
     3  * Description : Performs screenshot and bitmap conversion
       
     4  * Project     : This file is part of OpenMAR, an Open Mobile Augmented Reality browser
       
     5  * Website     : http://OpenMAR.org
       
     6  *
       
     7  * Copyright (c) 2010 David Caabeiro
       
     8  *
       
     9  * All rights reserved. This program and the accompanying materials are made available 
       
    10  * under the terms of the Eclipse Public License v1.0 which accompanies this 
       
    11  * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
       
    12  *
       
    13  */
       
    14 
       
    15 #include "Screenshot.h"
       
    16 
       
    17 #include <eikenv.h>
       
    18 #include <fbs.h>
       
    19 #include <ImageConversion.h> 
       
    20 #include <PathInfo.h>
       
    21 #include <w32std.h>
       
    22 
       
    23 #include "Logger.h"
       
    24 
       
    25 CScreenshot* CScreenshot::NewL(MObserver& aObserver, const TSize& aSize, const TDisplayMode& aDisplayMode)
       
    26 {
       
    27     CScreenshot* self = new(ELeave) CScreenshot(aObserver);
       
    28     CleanupStack::PushL(self);
       
    29     self->ConstructL(aSize, aDisplayMode);
       
    30     CleanupStack::Pop();
       
    31 
       
    32     return self;
       
    33 }
       
    34 
       
    35 CScreenshot::~CScreenshot()
       
    36 {
       
    37     Cancel();
       
    38 
       
    39     delete iEncoder;
       
    40     
       
    41     delete iBitmapContext;
       
    42     delete iBitmapDevice;
       
    43     delete iBitmap;
       
    44 }
       
    45 
       
    46 CScreenshot::CScreenshot(MObserver& aObserver)
       
    47     :CActive(EPriorityStandard), iObserver(aObserver)
       
    48 {
       
    49     CActiveScheduler::Add(this);
       
    50 }
       
    51 
       
    52 void CScreenshot::ConstructL(const TSize& aSize, const TDisplayMode& aDisplayMode)
       
    53 {
       
    54     // Create bitmap where screen bitmap will be blitted
       
    55     iBitmap = new(ELeave) CFbsBitmap;
       
    56     iBitmap->Create(aSize, aDisplayMode);
       
    57 
       
    58     iBitmapDevice = CFbsBitmapDevice::NewL(iBitmap);
       
    59     User::LeaveIfError(iBitmapDevice->CreateContext(iBitmapContext));
       
    60 
       
    61     LOGARG("Bitmap capture size is %d x %d", aSize.iWidth, aSize.iHeight);
       
    62 }
       
    63 
       
    64 void CScreenshot::RequestL(const CFbsBitmap& aSourceBitmap, const TSize& aSize)
       
    65 {
       
    66     // Blit screen bitmap into internal bitmap
       
    67     iBitmapContext->BitBlt(TPoint(0, 0), &aSourceBitmap, TRect(TPoint(0, 0), aSize));
       
    68 
       
    69     // Generate file name
       
    70     TTime time;
       
    71     time.HomeTime();
       
    72 
       
    73     TDateTime dateTime = time.DateTime();
       
    74 
       
    75 #if defined(__WINS__)
       
    76     iFilename.Copy(PathInfo::PhoneMemoryRootPath());
       
    77 #else
       
    78     iFilename.Copy(PathInfo::MemoryCardRootPath());
       
    79 #endif
       
    80     iFilename.Append(PathInfo::ImagesPath());
       
    81 
       
    82     _LIT(KFormat, "%04d%02d%02d%02d%02d%02d.png");
       
    83     iFilename.AppendFormat(KFormat, dateTime.Year(), dateTime.Month() + 1, dateTime.Day() + 1, dateTime.Hour(), dateTime.Minute(), dateTime.Second());
       
    84 
       
    85     // Convert to PNG
       
    86     delete iEncoder;
       
    87     iEncoder = 0;
       
    88 
       
    89     iEncoder = CImageEncoder::FileNewL(CCoeEnv::Static()->FsSession(), iFilename, CImageEncoder::EOptionAlwaysThread, KImageTypePNGUid);
       
    90     iEncoder->Convert(&iStatus, *iBitmap);
       
    91     SetActive();
       
    92 }
       
    93 
       
    94 void CScreenshot::RunL()
       
    95 {   
       
    96     iObserver.ScreenshotReadyL(iStatus.Int(), iFilename);
       
    97 }
       
    98 
       
    99 void CScreenshot::DoCancel()    
       
   100 {
       
   101     if (iEncoder)
       
   102         iEncoder->Cancel();
       
   103 }