зеркало из https://github.com/mozilla/gecko-dev.git
Bug 919219 - Trim gfxASurface more - r=jrmuizel
This commit is contained in:
Родитель
475818f81c
Коммит
0bda204d81
|
@ -9,13 +9,13 @@
|
|||
#include "mozilla/CheckedInt.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "nsTraceRefcnt.h"
|
||||
|
||||
#include "gfxASurface.h"
|
||||
#include "gfxContext.h"
|
||||
#include "gfxImageSurface.h"
|
||||
#include "gfxPlatform.h"
|
||||
|
||||
#include "nsRect.h"
|
||||
#include "gfxRect.h"
|
||||
|
||||
#include "cairo.h"
|
||||
#include <algorithm>
|
||||
|
@ -56,6 +56,20 @@ using namespace mozilla;
|
|||
|
||||
static cairo_user_data_key_t gfxasurface_pointer_key;
|
||||
|
||||
gfxASurface::gfxASurface()
|
||||
: mSurface(nullptr), mFloatingRefs(0), mBytesRecorded(0),
|
||||
mSurfaceValid(false), mAllowUseAsSource(true)
|
||||
{
|
||||
MOZ_COUNT_CTOR(gfxASurface);
|
||||
}
|
||||
|
||||
gfxASurface::~gfxASurface()
|
||||
{
|
||||
RecordMemoryFreed();
|
||||
|
||||
MOZ_COUNT_DTOR(gfxASurface);
|
||||
}
|
||||
|
||||
// Surfaces use refcounting that's tied to the cairo surface refcnt, to avoid
|
||||
// refcount mismatch issues.
|
||||
nsrefcnt
|
||||
|
@ -102,6 +116,18 @@ gfxASurface::Release(void)
|
|||
}
|
||||
}
|
||||
|
||||
nsrefcnt
|
||||
gfxASurface::AddRefExternal(void)
|
||||
{
|
||||
return AddRef();
|
||||
}
|
||||
|
||||
nsrefcnt
|
||||
gfxASurface::ReleaseExternal(void)
|
||||
{
|
||||
return Release();
|
||||
}
|
||||
|
||||
void
|
||||
gfxASurface::SurfaceDestroyFunc(void *data) {
|
||||
gfxASurface *surf = (gfxASurface*) data;
|
||||
|
@ -294,7 +320,7 @@ gfxASurface::Finish()
|
|||
|
||||
already_AddRefed<gfxASurface>
|
||||
gfxASurface::CreateSimilarSurface(gfxContentType aContent,
|
||||
const gfxIntSize& aSize)
|
||||
const nsIntSize& aSize)
|
||||
{
|
||||
if (!mSurface || !mSurfaceValid) {
|
||||
return nullptr;
|
||||
|
@ -330,7 +356,7 @@ gfxASurface::CopyToARGB32ImageSurface()
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
const gfxIntSize size = GetSize();
|
||||
const nsIntSize size = GetSize();
|
||||
nsRefPtr<gfxImageSurface> imgSurface =
|
||||
new gfxImageSurface(size, gfxASurface::ImageFormatARGB32);
|
||||
|
||||
|
@ -353,7 +379,7 @@ gfxASurface::CairoStatus()
|
|||
|
||||
/* static */
|
||||
bool
|
||||
gfxASurface::CheckSurfaceSize(const gfxIntSize& sz, int32_t limit)
|
||||
gfxASurface::CheckSurfaceSize(const nsIntSize& sz, int32_t limit)
|
||||
{
|
||||
if (sz.width < 0 || sz.height < 0) {
|
||||
NS_WARNING("Surface width or height < 0!");
|
||||
|
@ -519,7 +545,7 @@ gfxASurface::MovePixels(const nsIntRect& aSourceRect,
|
|||
// a temporary surface instead.
|
||||
nsRefPtr<gfxASurface> tmp =
|
||||
CreateSimilarSurface(GetContentType(),
|
||||
gfxIntSize(aSourceRect.width, aSourceRect.height));
|
||||
nsIntSize(aSourceRect.width, aSourceRect.height));
|
||||
// CreateSimilarSurface can return nullptr if the current surface is
|
||||
// in an error state. This isn't good, but its better to carry
|
||||
// on with the error surface instead of crashing.
|
||||
|
@ -749,7 +775,7 @@ void
|
|||
gfxASurface::WriteAsPNG_internal(FILE* aFile, bool aBinary)
|
||||
{
|
||||
nsRefPtr<gfxImageSurface> imgsurf = GetAsImageSurface();
|
||||
gfxIntSize size;
|
||||
nsIntSize size;
|
||||
|
||||
// FIXME/bug 831898: hack r5g6b5 for now.
|
||||
if (!imgsurf || imgsurf->Format() == ImageFormatRGB16_565) {
|
||||
|
@ -760,7 +786,7 @@ gfxASurface::WriteAsPNG_internal(FILE* aFile, bool aBinary)
|
|||
}
|
||||
|
||||
imgsurf =
|
||||
new gfxImageSurface(gfxIntSize(size.width, size.height),
|
||||
new gfxImageSurface(nsIntSize(size.width, size.height),
|
||||
gfxASurface::ImageFormatARGB32);
|
||||
|
||||
if (!imgsurf || imgsurf->CairoStatus()) {
|
||||
|
@ -888,3 +914,34 @@ gfxASurface::WriteAsPNG_internal(FILE* aFile, bool aBinary)
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
gfxASurface::SetOpaqueRect(const gfxRect& aRect)
|
||||
{
|
||||
if (aRect.IsEmpty()) {
|
||||
mOpaqueRect = nullptr;
|
||||
} else if (!!mOpaqueRect) {
|
||||
*mOpaqueRect = aRect;
|
||||
} else {
|
||||
mOpaqueRect = new gfxRect(aRect);
|
||||
}
|
||||
}
|
||||
|
||||
/* static */const gfxRect&
|
||||
gfxASurface::GetEmptyOpaqueRect()
|
||||
{
|
||||
static const gfxRect empty(0, 0, 0, 0);
|
||||
return empty;
|
||||
}
|
||||
|
||||
const nsIntSize
|
||||
gfxASurface::GetSize() const
|
||||
{
|
||||
return nsIntSize(-1, -1);
|
||||
}
|
||||
|
||||
already_AddRefed<gfxImageSurface>
|
||||
gfxASurface::GetAsImageSurface()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -12,8 +12,14 @@
|
|||
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "gfxTypes.h"
|
||||
#include "gfxRect.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "mozilla/Scoped.h"
|
||||
#include "nscore.h"
|
||||
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
#include "nsStringFwd.h"
|
||||
#else
|
||||
#include "nsStringAPI.h"
|
||||
#endif
|
||||
|
||||
typedef struct _cairo_surface cairo_surface_t;
|
||||
typedef struct _cairo_user_data_key cairo_user_data_key_t;
|
||||
|
@ -23,6 +29,12 @@ typedef void (*thebes_destroy_func_t) (void *data);
|
|||
class gfxImageSurface;
|
||||
struct nsIntPoint;
|
||||
struct nsIntRect;
|
||||
struct gfxRect;
|
||||
struct gfxPoint;
|
||||
struct nsIntSize;
|
||||
|
||||
template <typename T>
|
||||
struct already_AddRefed;
|
||||
|
||||
/**
|
||||
* A surface is something you can draw on. Instantiate a subclass of this
|
||||
|
@ -35,14 +47,8 @@ public:
|
|||
nsrefcnt Release(void);
|
||||
|
||||
// These functions exist so that browsercomps can refcount a gfxASurface
|
||||
virtual nsrefcnt AddRefExternal(void)
|
||||
{
|
||||
return AddRef();
|
||||
}
|
||||
virtual nsrefcnt ReleaseExternal(void)
|
||||
{
|
||||
return Release();
|
||||
}
|
||||
virtual nsrefcnt AddRefExternal(void);
|
||||
virtual nsrefcnt ReleaseExternal(void);
|
||||
#else
|
||||
virtual nsrefcnt AddRef(void);
|
||||
virtual nsrefcnt Release(void);
|
||||
|
@ -105,7 +111,6 @@ public:
|
|||
|
||||
/*** this DOES NOT addref the surface */
|
||||
cairo_surface_t *CairoSurface() {
|
||||
NS_ASSERTION(mSurface != nullptr, "gfxASurface::CairoSurface called with mSurface == nullptr!");
|
||||
return mSurface;
|
||||
}
|
||||
|
||||
|
@ -142,17 +147,14 @@ public:
|
|||
* Returns null on error.
|
||||
*/
|
||||
virtual already_AddRefed<gfxASurface> CreateSimilarSurface(gfxContentType aType,
|
||||
const gfxIntSize& aSize);
|
||||
const nsIntSize& aSize);
|
||||
|
||||
/**
|
||||
* Returns an image surface for this surface, or nullptr if not supported.
|
||||
* This will not copy image data, just wraps an image surface around
|
||||
* pixel data already available in memory.
|
||||
*/
|
||||
virtual already_AddRefed<gfxImageSurface> GetAsImageSurface()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
virtual already_AddRefed<gfxImageSurface> GetAsImageSurface();
|
||||
|
||||
/**
|
||||
* Returns a read-only ARGB32 image surface for this surface. If this is an
|
||||
|
@ -173,7 +175,7 @@ public:
|
|||
* using 4 bytes per pixel; optionally, make sure that either dimension
|
||||
* doesn't exceed the given limit.
|
||||
*/
|
||||
static bool CheckSurfaceSize(const gfxIntSize& sz, int32_t limit = 0);
|
||||
static bool CheckSurfaceSize(const nsIntSize& sz, int32_t limit = 0);
|
||||
|
||||
/* Provide a stride value that will respect all alignment requirements of
|
||||
* the accelerated image-rendering code.
|
||||
|
@ -239,7 +241,7 @@ public:
|
|||
|
||||
static int32_t BytePerPixelFromFormat(gfxImageFormat format);
|
||||
|
||||
virtual const gfxIntSize GetSize() const { return gfxIntSize(-1, -1); }
|
||||
virtual const nsIntSize GetSize() const;
|
||||
|
||||
/**
|
||||
* Debug functions to encode the current image as a PNG and export it.
|
||||
|
@ -264,23 +266,15 @@ public:
|
|||
* Copy a PNG encoded Data URL to the clipboard.
|
||||
*/
|
||||
void CopyAsDataURL();
|
||||
|
||||
|
||||
void WriteAsPNG_internal(FILE* aFile, bool aBinary);
|
||||
|
||||
void SetOpaqueRect(const gfxRect& aRect) {
|
||||
if (aRect.IsEmpty()) {
|
||||
mOpaqueRect = nullptr;
|
||||
} else if (mOpaqueRect) {
|
||||
*mOpaqueRect = aRect;
|
||||
} else {
|
||||
mOpaqueRect = new gfxRect(aRect);
|
||||
}
|
||||
}
|
||||
void SetOpaqueRect(const gfxRect& aRect);
|
||||
|
||||
const gfxRect& GetOpaqueRect() {
|
||||
if (mOpaqueRect)
|
||||
if (!!mOpaqueRect)
|
||||
return *mOpaqueRect;
|
||||
static const gfxRect empty(0, 0, 0, 0);
|
||||
return empty;
|
||||
return GetEmptyOpaqueRect();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -305,11 +299,7 @@ public:
|
|||
static uint8_t BytesPerPixel(gfxImageFormat aImageFormat);
|
||||
|
||||
protected:
|
||||
gfxASurface() : mSurface(nullptr), mFloatingRefs(0), mBytesRecorded(0),
|
||||
mSurfaceValid(false), mAllowUseAsSource(true)
|
||||
{
|
||||
MOZ_COUNT_CTOR(gfxASurface);
|
||||
}
|
||||
gfxASurface();
|
||||
|
||||
static gfxASurface* GetSurfaceWrapper(cairo_surface_t *csurf);
|
||||
static void SetSurfaceWrapper(cairo_surface_t *csurf, gfxASurface *asurf);
|
||||
|
@ -327,15 +317,14 @@ protected:
|
|||
// leaks and use-after-frees are possible.
|
||||
void Init(cairo_surface_t *surface, bool existingSurface = false);
|
||||
|
||||
virtual ~gfxASurface()
|
||||
{
|
||||
RecordMemoryFreed();
|
||||
// out-of-line helper to allow GetOpaqueRect() to be inlined
|
||||
// without including gfxRect.h here
|
||||
static const gfxRect& GetEmptyOpaqueRect();
|
||||
|
||||
MOZ_COUNT_DTOR(gfxASurface);
|
||||
}
|
||||
virtual ~gfxASurface();
|
||||
|
||||
cairo_surface_t *mSurface;
|
||||
nsAutoPtr<gfxRect> mOpaqueRect;
|
||||
mozilla::ScopedDeletePtr<gfxRect> mOpaqueRect;
|
||||
|
||||
private:
|
||||
static void SurfaceDestroyFunc(void *data);
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "gfxASurface.h"
|
||||
#include "nsExpirationTracker.h"
|
||||
#include "nsSize.h"
|
||||
|
||||
class gfxContext;
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "gfxASurface.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "gfxPoint.h"
|
||||
|
||||
// ARGB -- raw buffer.. wont be changed.. good for storing data.
|
||||
|
|
|
@ -10,10 +10,13 @@
|
|||
#include "nsTArray.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsAutoPtr.h"
|
||||
|
||||
#include "gfxTypes.h"
|
||||
#include "gfxASurface.h"
|
||||
#include "gfxColor.h"
|
||||
#include "nsRect.h"
|
||||
|
||||
#include "qcms.h"
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "gfxTeeSurface.h"
|
||||
#include "nsAutoPtr.h"
|
||||
|
||||
#include "cairo-tee.h"
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "gfxASurface.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsSize.h"
|
||||
|
||||
/**
|
||||
* Wraps a cairo_tee_surface. The first surface in the surface list is the
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#undef max // Xlibint.h defines this and it breaks std::max
|
||||
#undef min // Xlibint.h defines this and it breaks std::min
|
||||
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsAlgorithm.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#include "GLXLibrary.h"
|
||||
#endif
|
||||
|
||||
#include "nsSize.h"
|
||||
|
||||
class gfxXlibSurface : public gfxASurface {
|
||||
public:
|
||||
// construct a wrapper around the specified drawable with dpy/visual.
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "nsSurfaceTexture.h"
|
||||
#include "gfxImageSurface.h"
|
||||
#include "AndroidBridge.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include "AndroidDirectTexture.h"
|
||||
#include "nsRect.h"
|
||||
|
||||
typedef gfxASurface::gfxImageFormat gfxImageFormat;
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <android/log.h>
|
||||
#include "nsIObserverService.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
#ifdef MOZ_CRASHREPORTER
|
||||
#include "nsICrashReporter.h"
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include "nsIWidget.h"
|
||||
#include "gfxASurface.h"
|
||||
#include "nsAutoPtr.h"
|
||||
|
||||
#include "mozilla/X11Util.h"
|
||||
#include <X11/Xlib.h>
|
||||
|
|
Загрузка…
Ссылка в новой задаче