gfx/thebes/gfxImageSurface.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/thebes/gfxImageSurface.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,173 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef GFX_IMAGESURFACE_H
    1.10 +#define GFX_IMAGESURFACE_H
    1.11 +
    1.12 +#include "mozilla/MemoryReporting.h"
    1.13 +#include "mozilla/RefPtr.h"
    1.14 +#include "gfxASurface.h"
    1.15 +#include "nsAutoPtr.h"
    1.16 +#include "nsSize.h"
    1.17 +
    1.18 +// ARGB -- raw buffer.. wont be changed.. good for storing data.
    1.19 +
    1.20 +class gfxSubimageSurface;
    1.21 +
    1.22 +namespace mozilla {
    1.23 +namespace gfx {
    1.24 +class DataSourceSurface;
    1.25 +class SourceSurface;
    1.26 +}
    1.27 +}
    1.28 +
    1.29 +/**
    1.30 + * A raw image buffer. The format can be set in the constructor. Its main
    1.31 + * purpose is for storing read-only images and using it as a source surface,
    1.32 + * but it can also be drawn to.
    1.33 + */
    1.34 +class gfxImageSurface : public gfxASurface {
    1.35 +public:
    1.36 +    /**
    1.37 +     * Construct an image surface around an existing buffer of image data.
    1.38 +     * @param aData A buffer containing the image data
    1.39 +     * @param aSize The size of the buffer
    1.40 +     * @param aStride The stride of the buffer
    1.41 +     * @param format Format of the data
    1.42 +     *
    1.43 +     * @see gfxImageFormat
    1.44 +     */
    1.45 +    gfxImageSurface(unsigned char *aData, const gfxIntSize& aSize,
    1.46 +                    long aStride, gfxImageFormat aFormat);
    1.47 +
    1.48 +    /**
    1.49 +     * Construct an image surface.
    1.50 +     * @param aSize The size of the buffer
    1.51 +     * @param format Format of the data
    1.52 +     *
    1.53 +     * @see gfxImageFormat
    1.54 +     */
    1.55 +    gfxImageSurface(const gfxIntSize& size, gfxImageFormat format, bool aClear = true);
    1.56 +
    1.57 +    /**
    1.58 +     * Construct an image surface, with a specified stride and allowing the
    1.59 +     * allocation of more memory than required for the storage of the surface
    1.60 +     * itself.  When aStride and aMinimalAllocation are <=0, this constructor
    1.61 +     * is the equivalent of the preceeding one.
    1.62 +     *
    1.63 +     * @param format Format of the data
    1.64 +     * @param aSize The size of the buffer
    1.65 +     * @param aStride The stride of the buffer - if <=0, use ComputeStride()
    1.66 +     * @param aMinimalAllocation Allocate at least this many bytes.  If smaller
    1.67 +     *        than width * stride, or width*stride <=0, this value is ignored.
    1.68 +     * @param aClear 
    1.69 +     *
    1.70 +     * @see gfxImageFormat
    1.71 +     */
    1.72 +    gfxImageSurface(const gfxIntSize& aSize, gfxImageFormat aFormat,
    1.73 +                    long aStride, int32_t aMinimalAllocation, bool aClear);
    1.74 +
    1.75 +    gfxImageSurface(cairo_surface_t *csurf);
    1.76 +
    1.77 +    virtual ~gfxImageSurface();
    1.78 +
    1.79 +    // ImageSurface methods
    1.80 +    gfxImageFormat Format() const { return mFormat; }
    1.81 +
    1.82 +    virtual const gfxIntSize GetSize() const { return mSize; }
    1.83 +    int32_t Width() const { return mSize.width; }
    1.84 +    int32_t Height() const { return mSize.height; }
    1.85 +
    1.86 +    /**
    1.87 +     * Distance in bytes between the start of a line and the start of the
    1.88 +     * next line.
    1.89 +     */
    1.90 +    int32_t Stride() const { return mStride; }
    1.91 +    /**
    1.92 +     * Returns a pointer for the image data. Users of this function can
    1.93 +     * write to it, but must not attempt to free the buffer.
    1.94 +     */
    1.95 +    unsigned char* Data() const { return mData; } // delete this data under us and die.
    1.96 +    /**
    1.97 +     * Returns the total size of the image data.
    1.98 +     */
    1.99 +    int32_t GetDataSize() const { return mStride*mSize.height; }
   1.100 +
   1.101 +    /* Fast copy from another image surface; returns TRUE if successful, FALSE otherwise */
   1.102 +    bool CopyFrom (gfxImageSurface *other);
   1.103 +
   1.104 +    /**
   1.105 +     * Fast copy from a source surface; returns TRUE if successful, FALSE otherwise
   1.106 +     * Assumes that the format of this surface is compatable with aSurface
   1.107 +     */
   1.108 +    bool CopyFrom (mozilla::gfx::SourceSurface *aSurface);
   1.109 +
   1.110 +    /**
   1.111 +     * Fast copy to a source surface; returns TRUE if successful, FALSE otherwise
   1.112 +     * Assumes that the format of this surface is compatible with aSurface
   1.113 +     */
   1.114 +    bool CopyTo (mozilla::gfx::SourceSurface *aSurface);
   1.115 +
   1.116 +    /**
   1.117 +     * Copy to a Moz2D DataSourceSurface.
   1.118 +     * Marked as virtual so that browsercomps can access this method.
   1.119 +     */
   1.120 +    virtual mozilla::TemporaryRef<mozilla::gfx::DataSourceSurface> CopyToB8G8R8A8DataSourceSurface();
   1.121 +
   1.122 +    /* return new Subimage with pointing to original image starting from aRect.pos
   1.123 +     * and size of aRect.size. New subimage keeping current image reference
   1.124 +     */
   1.125 +    already_AddRefed<gfxSubimageSurface> GetSubimage(const gfxRect& aRect);
   1.126 +
   1.127 +    virtual already_AddRefed<gfxImageSurface> GetAsImageSurface();
   1.128 +
   1.129 +    /** See gfxASurface.h. */
   1.130 +    virtual void MovePixels(const nsIntRect& aSourceRect,
   1.131 +                            const nsIntPoint& aDestTopLeft) MOZ_OVERRIDE;
   1.132 +
   1.133 +    static long ComputeStride(const gfxIntSize&, gfxImageFormat);
   1.134 +
   1.135 +    virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
   1.136 +        MOZ_OVERRIDE;
   1.137 +    virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
   1.138 +        MOZ_OVERRIDE;
   1.139 +    virtual bool SizeOfIsMeasured() const MOZ_OVERRIDE;
   1.140 +
   1.141 +protected:
   1.142 +    gfxImageSurface();
   1.143 +    void InitWithData(unsigned char *aData, const gfxIntSize& aSize,
   1.144 +                      long aStride, gfxImageFormat aFormat);
   1.145 +    /**
   1.146 +     * See the parameters to the matching constructor.  This should only
   1.147 +     * be called once, in the constructor, which has already set mSize
   1.148 +     * and mFormat.
   1.149 +     */
   1.150 +    void AllocateAndInit(long aStride, int32_t aMinimalAllocation, bool aClear);
   1.151 +    void InitFromSurface(cairo_surface_t *csurf);
   1.152 +
   1.153 +    long ComputeStride() const { return ComputeStride(mSize, mFormat); }
   1.154 +
   1.155 +
   1.156 +    void MakeInvalid();
   1.157 +
   1.158 +    gfxIntSize mSize;
   1.159 +    bool mOwnsData;
   1.160 +    unsigned char *mData;
   1.161 +    gfxImageFormat mFormat;
   1.162 +    long mStride;
   1.163 +};
   1.164 +
   1.165 +class gfxSubimageSurface : public gfxImageSurface {
   1.166 +protected:
   1.167 +    friend class gfxImageSurface;
   1.168 +    gfxSubimageSurface(gfxImageSurface* aParent,
   1.169 +                       unsigned char* aData,
   1.170 +                       const gfxIntSize& aSize,
   1.171 +                       gfxImageFormat aFormat);
   1.172 +private:
   1.173 +    nsRefPtr<gfxImageSurface> mParent;
   1.174 +};
   1.175 +
   1.176 +#endif /* GFX_IMAGESURFACE_H */

mercurial