LCOV - code coverage report
Current view: directory - image/src - imgFrame.h (source / functions) Found Hit Coverage
Test: app.info Lines: 22 11 50.0 %
Date: 2012-06-02 Functions: 9 3 33.3 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2                 :  *
       3                 :  * ***** BEGIN LICENSE BLOCK *****
       4                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       5                 :  *
       6                 :  * The contents of this file are subject to the Mozilla Public License Version
       7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       8                 :  * the License. You may obtain a copy of the License at
       9                 :  * http://www.mozilla.org/MPL/
      10                 :  *
      11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      13                 :  * for the specific language governing rights and limitations under the
      14                 :  * License.
      15                 :  *
      16                 :  * The Original Code is mozilla.org code.
      17                 :  *
      18                 :  * The Initial Developer of the Original Code is Mozilla Foundation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2009
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Joe Drew <joe@drew.ca> (original author)
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      27                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : #ifndef imgFrame_h
      40                 : #define imgFrame_h
      41                 : 
      42                 : #include "nsRect.h"
      43                 : #include "nsPoint.h"
      44                 : #include "nsSize.h"
      45                 : #include "gfxTypes.h"
      46                 : #include "nsID.h"
      47                 : #include "gfxContext.h"
      48                 : #include "gfxPattern.h"
      49                 : #include "gfxDrawable.h"
      50                 : #include "gfxImageSurface.h"
      51                 : #if defined(XP_WIN)
      52                 : #include "gfxWindowsSurface.h"
      53                 : #elif defined(XP_MACOSX)
      54                 : #include "gfxQuartzImageSurface.h"
      55                 : #endif
      56                 : #include "nsAutoPtr.h"
      57                 : 
      58                 : class imgFrame
      59                 : {
      60                 : public:
      61                 :   imgFrame();
      62                 :   ~imgFrame();
      63                 : 
      64                 :   nsresult Init(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, gfxASurface::gfxImageFormat aFormat, PRUint8 aPaletteDepth = 0);
      65                 :   nsresult Optimize();
      66                 : 
      67                 :   void Draw(gfxContext *aContext, gfxPattern::GraphicsFilter aFilter,
      68                 :             const gfxMatrix &aUserSpaceToImageSpace, const gfxRect& aFill,
      69                 :             const nsIntMargin &aPadding, const nsIntRect &aSubimage);
      70                 : 
      71                 :   nsresult Extract(const nsIntRect& aRegion, imgFrame** aResult);
      72                 : 
      73                 :   nsresult ImageUpdated(const nsIntRect &aUpdateRect);
      74                 : 
      75                 :   nsIntRect GetRect() const;
      76                 :   gfxASurface::gfxImageFormat GetFormat() const;
      77                 :   bool GetNeedsBackground() const;
      78                 :   PRUint32 GetImageBytesPerRow() const;
      79                 :   PRUint32 GetImageDataLength() const;
      80                 :   bool GetIsPaletted() const;
      81                 :   bool GetHasAlpha() const;
      82                 :   void GetImageData(PRUint8 **aData, PRUint32 *length) const;
      83                 :   void GetPaletteData(PRUint32 **aPalette, PRUint32 *length) const;
      84                 : 
      85                 :   PRInt32 GetTimeout() const;
      86                 :   void SetTimeout(PRInt32 aTimeout);
      87                 : 
      88                 :   PRInt32 GetFrameDisposalMethod() const;
      89                 :   void SetFrameDisposalMethod(PRInt32 aFrameDisposalMethod);
      90                 :   PRInt32 GetBlendMethod() const;
      91                 :   void SetBlendMethod(PRInt32 aBlendMethod);
      92                 :   bool ImageComplete() const;
      93                 : 
      94                 :   void SetHasNoAlpha();
      95                 : 
      96                 :   bool GetCompositingFailed() const;
      97                 :   void SetCompositingFailed(bool val);
      98                 : 
      99                 :   nsresult LockImageData();
     100                 :   nsresult UnlockImageData();
     101                 : 
     102               0 :   nsresult GetSurface(gfxASurface **aSurface) const
     103                 :   {
     104               0 :     *aSurface = ThebesSurface();
     105               0 :     NS_IF_ADDREF(*aSurface);
     106               0 :     return NS_OK;
     107                 :   }
     108                 : 
     109              19 :   nsresult GetPattern(gfxPattern **aPattern) const
     110                 :   {
     111              19 :     if (mSinglePixel)
     112               0 :       *aPattern = new gfxPattern(mSinglePixelColor);
     113                 :     else
     114              38 :       *aPattern = new gfxPattern(ThebesSurface());
     115              19 :     NS_ADDREF(*aPattern);
     116              19 :     return NS_OK;
     117                 :   }
     118                 : 
     119              23 :   gfxASurface* ThebesSurface() const
     120                 :   {
     121              23 :     if (mOptSurface)
     122              20 :       return mOptSurface;
     123                 : #if defined(XP_WIN)
     124                 :     if (mWinSurface)
     125                 :       return mWinSurface;
     126                 : #elif defined(XP_MACOSX)
     127                 :     if (mQuartzSurface)
     128                 :       return mQuartzSurface;
     129                 : #endif
     130               3 :     return mImageSurface;
     131                 :   }
     132                 : 
     133                 :   size_t SizeOfExcludingThisWithComputedFallbackIfHeap(
     134                 :            gfxASurface::MemoryLocation aLocation,
     135                 :            nsMallocSizeOfFun aMallocSizeOf) const;
     136                 : 
     137               0 :   PRUint8 GetPaletteDepth() const { return mPaletteDepth; }
     138                 : 
     139                 : private: // methods
     140               6 :   PRUint32 PaletteDataLength() const {
     141               6 :     return ((1 << mPaletteDepth) * sizeof(PRUint32));
     142                 :   }
     143                 : 
     144               0 :   struct SurfaceWithFormat {
     145                 :     nsRefPtr<gfxDrawable> mDrawable;
     146                 :     gfxImageSurface::gfxImageFormat mFormat;
     147               0 :     SurfaceWithFormat() {}
     148               0 :     SurfaceWithFormat(gfxDrawable* aDrawable, gfxImageSurface::gfxImageFormat aFormat)
     149               0 :      : mDrawable(aDrawable), mFormat(aFormat) {}
     150               0 :     bool IsValid() { return !!mDrawable; }
     151                 :   };
     152                 : 
     153                 :   SurfaceWithFormat SurfaceForDrawing(bool               aDoPadding,
     154                 :                                       bool               aDoPartialDecode,
     155                 :                                       bool               aDoTile,
     156                 :                                       const nsIntMargin& aPadding,
     157                 :                                       gfxMatrix&         aUserSpaceToImageSpace,
     158                 :                                       gfxRect&           aFill,
     159                 :                                       gfxRect&           aSubimage,
     160                 :                                       gfxRect&           aSourceRect,
     161                 :                                       gfxRect&           aImageRect);
     162                 : 
     163                 : private: // data
     164                 :   nsRefPtr<gfxImageSurface> mImageSurface;
     165                 :   nsRefPtr<gfxASurface> mOptSurface;
     166                 : #if defined(XP_WIN)
     167                 :   nsRefPtr<gfxWindowsSurface> mWinSurface;
     168                 : #elif defined(XP_MACOSX)
     169                 :   nsRefPtr<gfxQuartzImageSurface> mQuartzSurface;
     170                 : #endif
     171                 : 
     172                 :   nsIntSize    mSize;
     173                 :   nsIntPoint   mOffset;
     174                 : 
     175                 :   nsIntRect    mDecoded;
     176                 : 
     177                 :   // The palette and image data for images that are paletted, since Cairo
     178                 :   // doesn't support these images.
     179                 :   // The paletted data comes first, then the image data itself.
     180                 :   // Total length is PaletteDataLength() + GetImageDataLength().
     181                 :   PRUint8*     mPalettedImageData;
     182                 : 
     183                 :   gfxRGBA      mSinglePixelColor;
     184                 : 
     185                 :   PRInt32      mTimeout; // -1 means display forever
     186                 :   PRInt32      mDisposalMethod;
     187                 : 
     188                 :   gfxASurface::gfxImageFormat mFormat;
     189                 :   PRUint8      mPaletteDepth;
     190                 :   PRInt8       mBlendMethod;
     191                 :   bool mSinglePixel;
     192                 :   bool mNeverUseDeviceSurface;
     193                 :   bool mFormatChanged;
     194                 :   bool mCompositingFailed;
     195                 :   /** Indicates if the image data is currently locked */
     196                 :   bool mLocked;
     197                 : 
     198                 : #ifdef XP_WIN
     199                 :   bool mIsDDBSurface;
     200                 : #endif
     201                 : };
     202                 : 
     203                 : #endif /* imgFrame_h */

Generated by: LCOV version 1.7