LCOV - code coverage report
Current view: directory - gfx/2d - SourceSurfaceSkia.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 52 0 0.0 %
Date: 2012-06-02 Functions: 11 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2                 :  * ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is Mozilla Corporation code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is Mozilla Foundation.
      18                 :  * Portions created by the Initial Developer are Copyright (C) 2011
      19                 :  * the Initial Developer. All Rights Reserved.
      20                 :  *
      21                 :  * Contributor(s):
      22                 :  *   Matt Woodrow <mwoodrow@mozilla.com>
      23                 :  *
      24                 :  * Alternatively, the contents of this file may be used under the terms of
      25                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      26                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      28                 :  * of those above. If you wish to allow use of your version of this file only
      29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      30                 :  * use your version of this file under the terms of the MPL, indicate your
      31                 :  * decision by deleting the provisions above and replace them with the notice
      32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      33                 :  * the provisions above, a recipient may use your version of this file under
      34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      35                 :  *
      36                 :  * ***** END LICENSE BLOCK ***** */
      37                 : 
      38                 : 
      39                 : #include "Logging.h"
      40                 : #include "SourceSurfaceSkia.h"
      41                 : #include "skia/SkBitmap.h"
      42                 : #include "skia/SkDevice.h"
      43                 : #include "HelpersSkia.h"
      44                 : #include "DrawTargetSkia.h"
      45                 : 
      46                 : namespace mozilla {
      47                 : namespace gfx {
      48                 : 
      49               0 : SourceSurfaceSkia::SourceSurfaceSkia()
      50               0 :   : mDrawTarget(NULL)
      51                 : {
      52               0 : }
      53                 : 
      54               0 : SourceSurfaceSkia::~SourceSurfaceSkia()
      55                 : {
      56               0 :   MarkIndependent();
      57               0 : }
      58                 : 
      59                 : IntSize
      60               0 : SourceSurfaceSkia::GetSize() const
      61                 : {
      62               0 :   return mSize;
      63                 : }
      64                 : 
      65                 : SurfaceFormat
      66               0 : SourceSurfaceSkia::GetFormat() const
      67                 : {
      68               0 :   return mFormat;
      69                 : }
      70                 : 
      71                 : bool 
      72               0 : SourceSurfaceSkia::InitFromData(unsigned char* aData,
      73                 :                                 const IntSize &aSize,
      74                 :                                 int32_t aStride,
      75                 :                                 SurfaceFormat aFormat)
      76                 : {
      77               0 :   SkBitmap temp;
      78               0 :   temp.setConfig(GfxFormatToSkiaConfig(aFormat), aSize.width, aSize.height, aStride);
      79               0 :   temp.setPixels(aData);
      80                 : 
      81               0 :   if (!temp.copyTo(&mBitmap, GfxFormatToSkiaConfig(aFormat))) {
      82               0 :     return false;
      83                 :   }
      84                 :   
      85               0 :   mSize = aSize;
      86               0 :   mFormat = aFormat;
      87               0 :   mStride = aStride;
      88               0 :   return true;
      89                 : }
      90                 : 
      91                 : bool
      92               0 : SourceSurfaceSkia::InitWithBitmap(const SkBitmap& aBitmap,
      93                 :                                   SurfaceFormat aFormat,
      94                 :                                   DrawTargetSkia* aOwner)
      95                 : {
      96               0 :   mFormat = aFormat;
      97               0 :   mSize = IntSize(aBitmap.width(), aBitmap.height());
      98                 : 
      99               0 :   if (aOwner) {
     100               0 :     mBitmap = aBitmap;
     101               0 :     mStride = aBitmap.rowBytes();
     102               0 :     mDrawTarget = aOwner;
     103               0 :     return true;
     104               0 :   } else if (aBitmap.copyTo(&mBitmap, aBitmap.getConfig())) {
     105               0 :     mStride = mBitmap.rowBytes();
     106               0 :     return true;
     107                 :   }
     108               0 :   return false;
     109                 : }
     110                 : 
     111                 : unsigned char*
     112               0 : SourceSurfaceSkia::GetData()
     113                 : {
     114               0 :   mBitmap.lockPixels();
     115               0 :   unsigned char *pixels = (unsigned char *)mBitmap.getPixels();
     116               0 :   mBitmap.unlockPixels();
     117               0 :   return pixels;
     118                 : 
     119                 : }
     120                 : 
     121                 : void
     122               0 : SourceSurfaceSkia::DrawTargetWillChange()
     123                 : {
     124               0 :   if (mDrawTarget) {
     125               0 :     mDrawTarget = NULL;
     126               0 :     SkBitmap temp = mBitmap;
     127               0 :     mBitmap.reset();
     128               0 :     temp.copyTo(&mBitmap, temp.getConfig());
     129                 :   }
     130               0 : }
     131                 : 
     132                 : void
     133               0 : SourceSurfaceSkia::DrawTargetDestroyed()
     134                 : {
     135               0 :   mDrawTarget = NULL;
     136               0 : }
     137                 : 
     138                 : void
     139               0 : SourceSurfaceSkia::MarkIndependent()
     140                 : {
     141               0 :   if (mDrawTarget) {
     142               0 :     mDrawTarget->RemoveSnapshot(this);
     143               0 :     mDrawTarget = NULL;
     144                 :   }
     145               0 : }
     146                 : 
     147                 : }
     148                 : }

Generated by: LCOV version 1.7