2005-04-06 05:54:26 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2005-04-06 05:54:26 +04:00
|
|
|
|
2005-04-11 08:36:18 +04:00
|
|
|
#ifndef GFX_ASURFACE_H
|
|
|
|
#define GFX_ASURFACE_H
|
2005-04-06 05:54:26 +04:00
|
|
|
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2014-01-06 19:49:03 +04:00
|
|
|
#include "mozilla/UniquePtr.h"
|
|
|
|
|
2017-06-28 18:42:23 +03:00
|
|
|
#include "gfxPoint.h"
|
2017-07-05 18:22:00 +03:00
|
|
|
#include "gfxRect.h"
|
2005-06-28 13:18:55 +04:00
|
|
|
#include "gfxTypes.h"
|
2013-09-25 00:45:13 +04:00
|
|
|
#include "nscore.h"
|
2014-05-28 04:59:10 +04:00
|
|
|
#include "nsSize.h"
|
2015-04-21 18:04:57 +03:00
|
|
|
#include "mozilla/gfx/Rect.h"
|
2013-09-25 00:45:13 +04:00
|
|
|
|
|
|
|
#include "nsStringFwd.h"
|
2012-02-01 06:18:30 +04:00
|
|
|
|
2009-06-26 00:30:56 +04:00
|
|
|
class gfxImageSurface;
|
2013-09-25 00:45:13 +04:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct already_AddRefed;
|
2009-06-26 00:30:56 +04:00
|
|
|
|
2005-08-20 09:36:47 +04:00
|
|
|
/**
|
|
|
|
* A surface is something you can draw on. Instantiate a subclass of this
|
|
|
|
* abstract class, and use gfxContext to draw on this surface.
|
|
|
|
*/
|
2013-05-30 01:59:24 +04:00
|
|
|
class gfxASurface {
|
2007-01-18 01:20:16 +03:00
|
|
|
public:
|
2012-01-06 18:44:25 +04:00
|
|
|
#ifdef MOZILLA_INTERNAL_API
|
2007-01-27 04:26:49 +03:00
|
|
|
nsrefcnt AddRef(void);
|
|
|
|
nsrefcnt Release(void);
|
2012-01-06 18:44:25 +04:00
|
|
|
#else
|
2012-07-27 18:03:25 +04:00
|
|
|
virtual nsrefcnt AddRef(void);
|
|
|
|
virtual nsrefcnt Release(void);
|
2012-01-06 18:44:25 +04:00
|
|
|
#endif
|
|
|
|
|
2005-04-06 05:54:26 +04:00
|
|
|
public:
|
2006-08-10 00:25:07 +04:00
|
|
|
|
2010-06-18 13:21:15 +04:00
|
|
|
/** Wrap the given cairo surface and return a gfxASurface for it.
|
|
|
|
* This adds a reference to csurf (owned by the returned gfxASurface).
|
|
|
|
*/
|
2015-06-01 11:26:19 +03:00
|
|
|
static already_AddRefed<gfxASurface> Wrap(cairo_surface_t *csurf, const mozilla::gfx::IntSize& aSize = mozilla::gfx::IntSize(-1, -1));
|
2006-04-05 01:54:22 +04:00
|
|
|
|
2005-06-28 13:18:55 +04:00
|
|
|
/*** this DOES NOT addref the surface */
|
2007-05-10 23:58:09 +04:00
|
|
|
cairo_surface_t *CairoSurface() {
|
|
|
|
return mSurface;
|
|
|
|
}
|
2006-04-05 01:54:22 +04:00
|
|
|
|
2007-01-27 04:26:49 +03:00
|
|
|
gfxSurfaceType GetType() const;
|
2005-04-06 05:54:26 +04:00
|
|
|
|
2007-01-27 04:26:49 +03:00
|
|
|
gfxContentType GetContentType() const;
|
2006-08-10 00:25:07 +04:00
|
|
|
|
2007-02-08 23:47:48 +03:00
|
|
|
void SetDeviceOffset(const gfxPoint& offset);
|
2007-01-27 04:26:49 +03:00
|
|
|
gfxPoint GetDeviceOffset() const;
|
2005-11-29 23:12:29 +03:00
|
|
|
|
2010-08-09 06:19:17 +04:00
|
|
|
void Flush() const;
|
2007-01-27 04:26:49 +03:00
|
|
|
void MarkDirty();
|
|
|
|
void MarkDirty(const gfxRect& r);
|
|
|
|
|
2016-06-16 19:25:54 +03:00
|
|
|
/* Printing backend functions */
|
|
|
|
virtual nsresult BeginPrinting(const nsAString& aTitle, const nsAString& aPrintToFileName);
|
|
|
|
virtual nsresult EndPrinting();
|
|
|
|
virtual nsresult AbortPrinting();
|
|
|
|
virtual nsresult BeginPage();
|
|
|
|
virtual nsresult EndPage();
|
|
|
|
|
2006-02-22 04:44:31 +03:00
|
|
|
void SetData(const cairo_user_data_key_t *key,
|
|
|
|
void *user_data,
|
2007-01-27 04:26:49 +03:00
|
|
|
thebes_destroy_func_t destroy);
|
|
|
|
void *GetData(const cairo_user_data_key_t *key);
|
2006-02-22 04:44:31 +03:00
|
|
|
|
2007-03-01 03:02:27 +03:00
|
|
|
virtual void Finish();
|
2007-01-27 04:46:14 +03:00
|
|
|
|
2010-06-01 03:37:44 +04:00
|
|
|
/**
|
|
|
|
* Create an offscreen surface that can be efficiently copied into
|
|
|
|
* this surface (at least if tiling is not involved).
|
|
|
|
* Returns null on error.
|
|
|
|
*/
|
|
|
|
virtual already_AddRefed<gfxASurface> CreateSimilarSurface(gfxContentType aType,
|
2015-05-28 16:00:17 +03:00
|
|
|
const mozilla::gfx::IntSize& aSize);
|
2010-11-11 23:31:22 +03:00
|
|
|
|
|
|
|
/**
|
2012-07-30 18:20:58 +04:00
|
|
|
* Returns an image surface for this surface, or nullptr if not supported.
|
2010-11-11 23:31:22 +03:00
|
|
|
* This will not copy image data, just wraps an image surface around
|
|
|
|
* pixel data already available in memory.
|
|
|
|
*/
|
2013-09-25 00:45:13 +04:00
|
|
|
virtual already_AddRefed<gfxImageSurface> GetAsImageSurface();
|
2010-11-11 23:31:22 +03:00
|
|
|
|
2013-03-06 03:39:48 +04:00
|
|
|
/**
|
|
|
|
* Creates a new ARGB32 image surface with the same contents as this surface.
|
|
|
|
* Returns null on error.
|
|
|
|
*/
|
|
|
|
already_AddRefed<gfxImageSurface> CopyToARGB32ImageSurface();
|
|
|
|
|
2007-05-11 00:50:16 +04:00
|
|
|
int CairoStatus();
|
2007-05-10 23:58:09 +04:00
|
|
|
|
2008-04-29 05:15:30 +04:00
|
|
|
static gfxContentType ContentFromFormat(gfxImageFormat format);
|
|
|
|
|
2010-05-22 08:10:14 +04:00
|
|
|
/**
|
|
|
|
* Record number of bytes for given surface type. Use positive bytes
|
|
|
|
* for allocations and negative bytes for deallocations.
|
|
|
|
*/
|
2013-09-25 00:45:13 +04:00
|
|
|
static void RecordMemoryUsedForSurfaceType(gfxSurfaceType aType,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aBytes);
|
2010-05-22 08:10:14 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Same as above, but use current surface type as returned by GetType().
|
|
|
|
* The bytes will be accumulated until RecordMemoryFreed is called,
|
|
|
|
* in which case the value that was recorded for this surface will
|
|
|
|
* be freed.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
void RecordMemoryUsed(int32_t aBytes);
|
2010-05-22 08:10:14 +04:00
|
|
|
void RecordMemoryFreed();
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
virtual int32_t KnownMemoryUsed() { return mBytesRecorded; }
|
2011-07-18 17:20:27 +04:00
|
|
|
|
2013-06-23 16:03:39 +04:00
|
|
|
virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
|
|
|
virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
2012-12-19 09:59:30 +04:00
|
|
|
// gfxASurface has many sub-classes. This method indicates if a sub-class
|
|
|
|
// is capable of measuring its own size accurately. If not, the caller
|
|
|
|
// must fall back to a computed size. (Note that gfxASurface can actually
|
|
|
|
// measure itself, but we must |return false| here because it serves as the
|
|
|
|
// (conservative) default for all the sub-classes. Therefore, this
|
|
|
|
// function should only be called on a |gfxASurface*| that actually points
|
|
|
|
// to a sub-class of gfxASurface.)
|
|
|
|
virtual bool SizeOfIsMeasured() const { return false; }
|
2012-11-27 04:29:56 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static int32_t BytePerPixelFromFormat(gfxImageFormat format);
|
2010-06-11 13:33:22 +04:00
|
|
|
|
2015-05-28 16:00:17 +03:00
|
|
|
virtual const mozilla::gfx::IntSize GetSize() const;
|
2010-09-08 04:36:57 +04:00
|
|
|
|
2015-07-07 05:11:38 +03:00
|
|
|
virtual mozilla::gfx::SurfaceFormat GetSurfaceFormat() const;
|
|
|
|
|
2013-09-25 00:45:13 +04:00
|
|
|
void SetOpaqueRect(const gfxRect& aRect);
|
|
|
|
|
2011-01-03 04:48:08 +03:00
|
|
|
const gfxRect& GetOpaqueRect() {
|
2013-09-25 00:45:13 +04:00
|
|
|
if (!!mOpaqueRect)
|
2011-01-03 04:48:08 +03:00
|
|
|
return *mOpaqueRect;
|
2013-09-25 00:45:13 +04:00
|
|
|
return GetEmptyOpaqueRect();
|
2011-01-03 04:48:08 +03:00
|
|
|
}
|
|
|
|
|
2012-12-13 02:47:28 +04:00
|
|
|
static uint8_t BytesPerPixel(gfxImageFormat aImageFormat);
|
|
|
|
|
2005-04-06 05:54:26 +04:00
|
|
|
protected:
|
2013-09-25 00:45:13 +04:00
|
|
|
gfxASurface();
|
2007-05-10 23:58:09 +04:00
|
|
|
|
2006-04-05 01:54:22 +04:00
|
|
|
static gfxASurface* GetSurfaceWrapper(cairo_surface_t *csurf);
|
|
|
|
static void SetSurfaceWrapper(cairo_surface_t *csurf, gfxASurface *asurf);
|
2005-04-06 05:54:26 +04:00
|
|
|
|
2011-01-04 19:40:54 +03:00
|
|
|
// NB: Init() *must* be called from within subclass's
|
|
|
|
// constructors. It's unsafe to call it after the ctor finishes;
|
|
|
|
// leaks and use-after-frees are possible.
|
2011-09-29 10:19:26 +04:00
|
|
|
void Init(cairo_surface_t *surface, bool existingSurface = false);
|
2005-06-30 08:58:27 +04:00
|
|
|
|
2013-09-25 00:45:13 +04:00
|
|
|
// out-of-line helper to allow GetOpaqueRect() to be inlined
|
|
|
|
// without including gfxRect.h here
|
|
|
|
static const gfxRect& GetEmptyOpaqueRect();
|
2010-06-18 13:21:15 +04:00
|
|
|
|
2013-09-25 00:45:13 +04:00
|
|
|
virtual ~gfxASurface();
|
2010-05-22 08:10:14 +04:00
|
|
|
|
2010-06-01 03:37:44 +04:00
|
|
|
cairo_surface_t *mSurface;
|
2014-01-06 19:49:03 +04:00
|
|
|
mozilla::UniquePtr<gfxRect> mOpaqueRect;
|
2010-06-01 03:37:44 +04:00
|
|
|
|
2005-07-02 05:36:23 +04:00
|
|
|
private:
|
2007-05-10 23:58:09 +04:00
|
|
|
static void SurfaceDestroyFunc(void *data);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mFloatingRefs;
|
|
|
|
int32_t mBytesRecorded;
|
2007-01-18 01:20:16 +03:00
|
|
|
|
2007-05-10 23:58:09 +04:00
|
|
|
protected:
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mSurfaceValid;
|
2005-04-06 05:54:26 +04:00
|
|
|
};
|
|
|
|
|
2016-09-27 21:52:17 +03:00
|
|
|
/**
|
|
|
|
* An Unknown surface; used to wrap unknown cairo_surface_t returns from cairo
|
|
|
|
*/
|
|
|
|
class gfxUnknownSurface : public gfxASurface {
|
|
|
|
public:
|
|
|
|
gfxUnknownSurface(cairo_surface_t *surf, const mozilla::gfx::IntSize& aSize)
|
|
|
|
: mSize(aSize)
|
|
|
|
{
|
|
|
|
Init(surf, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~gfxUnknownSurface() { }
|
|
|
|
virtual const mozilla::gfx::IntSize GetSize() const override { return mSize; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
mozilla::gfx::IntSize mSize;
|
|
|
|
};
|
|
|
|
|
2005-04-11 08:36:18 +04:00
|
|
|
#endif /* GFX_ASURFACE_H */
|