Bug 835381 - Update libnestegg to 38c83d9d4c0c5c84373aa285bd30094a12d6b6f6. r=kinetik
[gecko.git] / gfx / thebes / gfxImageSurface.h
blob11f6033202c532248d1d39b6723ea3c1b7f2db89
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef GFX_IMAGESURFACE_H
7 #define GFX_IMAGESURFACE_H
9 #include "gfxASurface.h"
10 #include "gfxPoint.h"
12 // ARGB -- raw buffer.. wont be changed.. good for storing data.
14 class gfxSubimageSurface;
16 namespace mozilla {
17 namespace gfx {
18 class SourceSurface;
22 /**
23 * A raw image buffer. The format can be set in the constructor. Its main
24 * purpose is for storing read-only images and using it as a source surface,
25 * but it can also be drawn to.
27 class THEBES_API gfxImageSurface : public gfxASurface {
28 public:
29 /**
30 * Construct an image surface around an existing buffer of image data.
31 * @param aData A buffer containing the image data
32 * @param aSize The size of the buffer
33 * @param aStride The stride of the buffer
34 * @param format Format of the data
36 * @see gfxImageFormat
38 gfxImageSurface(unsigned char *aData, const gfxIntSize& aSize,
39 long aStride, gfxImageFormat aFormat);
41 /**
42 * Construct an image surface.
43 * @param aSize The size of the buffer
44 * @param format Format of the data
46 * @see gfxImageFormat
48 gfxImageSurface(const gfxIntSize& size, gfxImageFormat format, bool aClear = true);
49 gfxImageSurface(cairo_surface_t *csurf);
51 virtual ~gfxImageSurface();
53 // ImageSurface methods
54 gfxImageFormat Format() const { return mFormat; }
56 virtual const gfxIntSize GetSize() const { return mSize; }
57 int32_t Width() const { return mSize.width; }
58 int32_t Height() const { return mSize.height; }
60 /**
61 * Distance in bytes between the start of a line and the start of the
62 * next line.
64 int32_t Stride() const { return mStride; }
65 /**
66 * Returns a pointer for the image data. Users of this function can
67 * write to it, but must not attempt to free the buffer.
69 unsigned char* Data() const { return mData; } // delete this data under us and die.
70 /**
71 * Returns the total size of the image data.
73 int32_t GetDataSize() const { return mStride*mSize.height; }
75 /* Fast copy from another image surface; returns TRUE if successful, FALSE otherwise */
76 bool CopyFrom (gfxImageSurface *other);
78 /**
79 * Fast copy from a source surface; returns TRUE if successful, FALSE otherwise
80 * Assumes that the format of this surface is compatable with aSurface
82 bool CopyFrom (mozilla::gfx::SourceSurface *aSurface);
84 /* return new Subimage with pointing to original image starting from aRect.pos
85 * and size of aRect.size. New subimage keeping current image reference
87 already_AddRefed<gfxSubimageSurface> GetSubimage(const gfxRect& aRect);
89 virtual already_AddRefed<gfxImageSurface> GetAsImageSurface();
91 /** See gfxASurface.h. */
92 virtual void MovePixels(const nsIntRect& aSourceRect,
93 const nsIntPoint& aDestTopLeft) MOZ_OVERRIDE;
95 static long ComputeStride(const gfxIntSize&, gfxImageFormat);
97 virtual size_t SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
98 MOZ_OVERRIDE;
99 virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
100 MOZ_OVERRIDE;
101 virtual bool SizeOfIsMeasured() const MOZ_OVERRIDE;
103 protected:
104 gfxImageSurface();
105 void InitWithData(unsigned char *aData, const gfxIntSize& aSize,
106 long aStride, gfxImageFormat aFormat);
107 void InitFromSurface(cairo_surface_t *csurf);
108 long ComputeStride() const { return ComputeStride(mSize, mFormat); }
111 void MakeInvalid();
113 gfxIntSize mSize;
114 bool mOwnsData;
115 unsigned char *mData;
116 gfxImageFormat mFormat;
117 long mStride;
120 class THEBES_API gfxSubimageSurface : public gfxImageSurface {
121 protected:
122 friend class gfxImageSurface;
123 gfxSubimageSurface(gfxImageSurface* aParent,
124 unsigned char* aData,
125 const gfxIntSize& aSize);
126 private:
127 nsRefPtr<gfxImageSurface> mParent;
130 #endif /* GFX_IMAGESURFACE_H */