2012-12-18 21:59:30 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 04:12:37 -07:00
|
|
|
* 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/. */
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
|
|
|
|
#include "imgFrame.h"
|
2012-03-15 13:30:41 -07:00
|
|
|
#include "DiscardTracker.h"
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
|
|
|
|
#include "prenv.h"
|
|
|
|
|
2014-02-09 00:04:38 -08:00
|
|
|
#include "gfx2DGlue.h"
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
#include "gfxPlatform.h"
|
2010-08-13 06:30:02 -07:00
|
|
|
#include "gfxUtils.h"
|
2014-02-24 19:37:51 -08:00
|
|
|
#include "gfxAlphaRecovery.h"
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool gDisableOptimize = false;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
|
|
|
|
#include "cairo.h"
|
2013-03-18 07:25:50 -07:00
|
|
|
#include "GeckoProfiler.h"
|
2012-10-26 06:32:10 -07:00
|
|
|
#include "mozilla/Likely.h"
|
2013-06-23 05:03:39 -07:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-09-06 19:15:49 -07:00
|
|
|
#include "nsMargin.h"
|
2013-10-02 07:44:53 -07:00
|
|
|
#include "mozilla/CheckedInt.h"
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
|
2011-05-05 14:14:27 -07:00
|
|
|
#if defined(XP_WIN)
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
|
2011-05-05 14:14:27 -07:00
|
|
|
#include "gfxWindowsPlatform.h"
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
|
|
|
|
/* Whether to use the windows surface; only for desktop win32 */
|
|
|
|
#define USE_WIN_SURFACE 1
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2013-07-04 11:45:57 -07:00
|
|
|
using namespace mozilla;
|
2014-02-09 00:04:38 -08:00
|
|
|
using namespace mozilla::gfx;
|
2012-03-15 13:30:41 -07:00
|
|
|
using namespace mozilla::image;
|
|
|
|
|
2014-02-24 19:37:51 -08:00
|
|
|
static cairo_user_data_key_t kVolatileBuffer;
|
|
|
|
|
|
|
|
static void
|
|
|
|
VolatileBufferRelease(void *vbuf)
|
|
|
|
{
|
|
|
|
delete static_cast<VolatileBufferPtr<unsigned char>*>(vbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxImageSurface *
|
|
|
|
LockedImageSurface::CreateSurface(VolatileBuffer *vbuf,
|
|
|
|
const gfxIntSize& size,
|
|
|
|
gfxImageFormat format)
|
|
|
|
{
|
|
|
|
VolatileBufferPtr<unsigned char> *vbufptr =
|
|
|
|
new VolatileBufferPtr<unsigned char>(vbuf);
|
|
|
|
MOZ_ASSERT(!vbufptr->WasBufferPurged(), "Expected image data!");
|
|
|
|
|
|
|
|
long stride = gfxImageSurface::ComputeStride(size, format);
|
|
|
|
gfxImageSurface *img = new gfxImageSurface(*vbufptr, size, stride, format);
|
|
|
|
if (!img || img->CairoStatus()) {
|
|
|
|
delete img;
|
|
|
|
delete vbufptr;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
img->SetData(&kVolatileBuffer, vbufptr, VolatileBufferRelease);
|
|
|
|
return img;
|
|
|
|
}
|
|
|
|
|
|
|
|
TemporaryRef<VolatileBuffer>
|
|
|
|
LockedImageSurface::AllocateBuffer(const gfxIntSize& size,
|
|
|
|
gfxImageFormat format)
|
|
|
|
{
|
|
|
|
long stride = gfxImageSurface::ComputeStride(size, format);
|
|
|
|
RefPtr<VolatileBuffer> buf = new VolatileBuffer();
|
|
|
|
if (buf->Init(stride * size.height,
|
|
|
|
1 << gfxAlphaRecovery::GoodAlignmentLog2()))
|
|
|
|
return buf;
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
// Returns true if an image of aWidth x aHeight is allowed and legal.
|
2012-08-22 08:56:38 -07:00
|
|
|
static bool AllowedImageSize(int32_t aWidth, int32_t aHeight)
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
{
|
|
|
|
// reject over-wide or over-tall images
|
2012-08-22 08:56:38 -07:00
|
|
|
const int32_t k64KLimit = 0x0000FFFF;
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_UNLIKELY(aWidth > k64KLimit || aHeight > k64KLimit )) {
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
NS_WARNING("image too big");
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
}
|
|
|
|
|
2011-07-01 10:03:47 -07:00
|
|
|
// protect against invalid sizes
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_UNLIKELY(aHeight <= 0 || aWidth <= 0)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// check to make sure we don't overflow a 32-bit
|
2013-10-02 07:44:53 -07:00
|
|
|
CheckedInt32 requiredBytes = CheckedInt32(aWidth) * CheckedInt32(aHeight) * 4;
|
|
|
|
if (MOZ_UNLIKELY(!requiredBytes.isValid())) {
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
NS_WARNING("width or height too large");
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
}
|
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
// CoreGraphics is limited to images < 32K in *height*, so clamp all surfaces on the Mac to that height
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_UNLIKELY(aHeight > SHRT_MAX)) {
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
NS_WARNING("image too big");
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
}
|
|
|
|
#endif
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns whether we should, at this time, use image surfaces instead of
|
|
|
|
// optimized platform-specific surfaces.
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool ShouldUseImageSurfaces()
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
{
|
2011-05-05 14:14:27 -07:00
|
|
|
#if defined(USE_WIN_SURFACE)
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
static const DWORD kGDIObjectsHighWaterMark = 7000;
|
|
|
|
|
2010-02-25 22:36:07 -08:00
|
|
|
if (gfxWindowsPlatform::GetPlatform()->GetRenderMode() ==
|
|
|
|
gfxWindowsPlatform::RENDER_DIRECT2D) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-02-25 22:36:07 -08:00
|
|
|
}
|
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
// at 7000 GDI objects, stop allocating normal images to make sure
|
|
|
|
// we never hit the 10k hard limit.
|
|
|
|
// GetCurrentProcess() just returns (HANDLE)-1, it's inlined afaik
|
|
|
|
DWORD count = GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS);
|
|
|
|
if (count == 0 ||
|
|
|
|
count > kGDIObjectsHighWaterMark)
|
|
|
|
{
|
|
|
|
// either something's broken (count == 0),
|
|
|
|
// or we hit our high water mark; disable
|
|
|
|
// image allocations for a bit.
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
imgFrame::imgFrame() :
|
|
|
|
mDecoded(0, 0, 0, 0),
|
2013-07-04 11:45:57 -07:00
|
|
|
mDirtyMutex("imgFrame::mDirty"),
|
2012-07-30 07:20:58 -07:00
|
|
|
mPalettedImageData(nullptr),
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
mSinglePixelColor(0),
|
|
|
|
mTimeout(100),
|
|
|
|
mDisposalMethod(0), /* imgIContainer::kDisposeNotSpecified */
|
2012-09-26 08:33:06 -07:00
|
|
|
mLockCount(0),
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
mBlendMethod(1), /* imgIContainer::kBlendOver */
|
2011-10-17 07:59:28 -07:00
|
|
|
mSinglePixel(false),
|
|
|
|
mFormatChanged(false),
|
2012-03-23 15:10:50 -07:00
|
|
|
mCompositingFailed(false),
|
|
|
|
mNonPremult(false),
|
2014-02-24 19:37:51 -08:00
|
|
|
mDiscardable(false),
|
2013-07-04 11:45:57 -07:00
|
|
|
mInformedDiscardTracker(false),
|
|
|
|
mDirty(false)
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool hasCheckedOptimize = false;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
if (!hasCheckedOptimize) {
|
|
|
|
if (PR_GetEnv("MOZ_DISABLE_IMAGE_OPTIMIZE")) {
|
2011-10-17 07:59:28 -07:00
|
|
|
gDisableOptimize = true;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
hasCheckedOptimize = true;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
imgFrame::~imgFrame()
|
|
|
|
{
|
2012-10-03 11:10:31 -07:00
|
|
|
moz_free(mPalettedImageData);
|
|
|
|
mPalettedImageData = nullptr;
|
2012-03-15 13:30:41 -07:00
|
|
|
|
|
|
|
if (mInformedDiscardTracker) {
|
2014-04-10 09:15:51 -07:00
|
|
|
DiscardTracker::InformAllocation(-4 * mSize.height * mSize.width);
|
2012-03-15 13:30:41 -07:00
|
|
|
}
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
}
|
|
|
|
|
2013-03-29 13:14:19 -07:00
|
|
|
nsresult imgFrame::Init(int32_t aX, int32_t aY, int32_t aWidth, int32_t aHeight,
|
2013-09-24 13:45:13 -07:00
|
|
|
gfxImageFormat aFormat, uint8_t aPaletteDepth /* = 0 */)
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
{
|
|
|
|
// assert for properties that should be verified by decoders, warn for properties related to bad content
|
2013-05-22 02:10:38 -07:00
|
|
|
if (!AllowedImageSize(aWidth, aHeight)) {
|
|
|
|
NS_WARNING("Should have legal image size");
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2013-05-22 02:10:38 -07:00
|
|
|
}
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
|
|
|
|
mOffset.MoveTo(aX, aY);
|
|
|
|
mSize.SizeTo(aWidth, aHeight);
|
|
|
|
|
|
|
|
mFormat = aFormat;
|
|
|
|
mPaletteDepth = aPaletteDepth;
|
|
|
|
|
|
|
|
if (aPaletteDepth != 0) {
|
|
|
|
// We're creating for a paletted image.
|
|
|
|
if (aPaletteDepth > 8) {
|
2013-05-22 02:10:38 -07:00
|
|
|
NS_WARNING("Should have legal palette depth");
|
2010-06-17 13:28:38 -07:00
|
|
|
NS_ERROR("This Depth is not supported");
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2010-08-23 15:42:51 -07:00
|
|
|
// Use the fallible allocator here
|
2012-08-22 08:56:38 -07:00
|
|
|
mPalettedImageData = (uint8_t*)moz_malloc(PaletteDataLength() + GetImageDataLength());
|
2013-05-22 02:10:38 -07:00
|
|
|
if (!mPalettedImageData)
|
|
|
|
NS_WARNING("moz_malloc for paletted image data should succeed");
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
NS_ENSURE_TRUE(mPalettedImageData, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
} else {
|
|
|
|
// For Windows, we must create the device surface first (if we're
|
|
|
|
// going to) so that the image surface can wrap it. Can't be done
|
|
|
|
// the other way around.
|
|
|
|
#ifdef USE_WIN_SURFACE
|
2014-01-17 05:57:51 -08:00
|
|
|
if (!ShouldUseImageSurfaces()) {
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
mWinSurface = new gfxWindowsSurface(gfxIntSize(mSize.width, mSize.height), mFormat);
|
|
|
|
if (mWinSurface && mWinSurface->CairoStatus() == 0) {
|
|
|
|
// no error
|
2010-11-11 12:31:22 -08:00
|
|
|
mImageSurface = mWinSurface->GetAsImageSurface();
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
} else {
|
2012-07-30 07:20:58 -07:00
|
|
|
mWinSurface = nullptr;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-02-24 19:37:51 -08:00
|
|
|
// For other platforms, space for the image surface is first allocated in
|
|
|
|
// a volatile buffer and then wrapped by a LockedImageSurface.
|
|
|
|
// This branch is also used on Windows if we're not using device surfaces
|
|
|
|
// or if we couldn't create one.
|
|
|
|
if (!mImageSurface) {
|
|
|
|
mVBuf = LockedImageSurface::AllocateBuffer(mSize, mFormat);
|
|
|
|
if (!mVBuf) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
mImageSurface = LockedImageSurface::CreateSurface(mVBuf, mSize, mFormat);
|
|
|
|
}
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
|
|
|
|
if (!mImageSurface || mImageSurface->CairoStatus()) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mImageSurface = nullptr;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
// guess
|
2013-05-22 02:10:38 -07:00
|
|
|
if (!mImageSurface) {
|
|
|
|
NS_WARNING("Allocation of gfxImageSurface should succeed");
|
|
|
|
} else if (!mImageSurface->CairoStatus()) {
|
|
|
|
NS_WARNING("gfxImageSurface should have good CairoStatus");
|
|
|
|
}
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
2014-01-17 05:57:51 -08:00
|
|
|
if (!ShouldUseImageSurfaces()) {
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
mQuartzSurface = new gfxQuartzImageSurface(mImageSurface);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-04-10 09:15:51 -07:00
|
|
|
// Inform the discard tracker that we've allocated some memory, but only if
|
|
|
|
// we're not a paletted image (paletted images are not usually large and are
|
|
|
|
// used only for animated frames, which we don't discard).
|
|
|
|
if (!mPalettedImageData) {
|
|
|
|
DiscardTracker::InformAllocation(4 * mSize.width * mSize.height);
|
|
|
|
mInformedDiscardTracker = true;
|
|
|
|
}
|
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult imgFrame::Optimize()
|
|
|
|
{
|
2013-05-24 06:52:34 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
if (gDisableOptimize)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (mPalettedImageData || mOptSurface || mSinglePixel)
|
|
|
|
return NS_OK;
|
|
|
|
|
2012-03-23 15:10:50 -07:00
|
|
|
// Don't do single-color opts on non-premult data.
|
|
|
|
// Cairo doesn't support non-premult single-colors.
|
|
|
|
if (mNonPremult)
|
|
|
|
return NS_OK;
|
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
/* Figure out if the entire image is a constant color */
|
|
|
|
|
|
|
|
// this should always be true
|
|
|
|
if (mImageSurface->Stride() == mSize.width * 4) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t *imgData = (uint32_t*) mImageSurface->Data();
|
|
|
|
uint32_t firstPixel = * (uint32_t*) imgData;
|
|
|
|
uint32_t pixelCount = mSize.width * mSize.height + 1;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
|
|
|
|
while (--pixelCount && *imgData++ == firstPixel)
|
|
|
|
;
|
|
|
|
|
|
|
|
if (pixelCount == 0) {
|
|
|
|
// all pixels were the same
|
2014-01-23 10:26:40 -08:00
|
|
|
if (mFormat == gfxImageFormat::ARGB32 ||
|
|
|
|
mFormat == gfxImageFormat::RGB24)
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
{
|
2012-03-23 15:10:50 -07:00
|
|
|
// Should already be premult if desired.
|
|
|
|
gfxRGBA::PackedColorType inputType = gfxRGBA::PACKED_XRGB;
|
2014-01-23 10:26:40 -08:00
|
|
|
if (mFormat == gfxImageFormat::ARGB32)
|
2012-03-23 15:10:50 -07:00
|
|
|
inputType = gfxRGBA::PACKED_ARGB_PREMULTIPLIED;
|
|
|
|
|
|
|
|
mSinglePixelColor = gfxRGBA(firstPixel, inputType);
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mSinglePixel = true;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
|
|
|
|
// blow away the older surfaces (if they exist), to release their memory
|
2014-02-24 19:37:51 -08:00
|
|
|
mVBuf = nullptr;
|
2012-07-30 07:20:58 -07:00
|
|
|
mImageSurface = nullptr;
|
|
|
|
mOptSurface = nullptr;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
#ifdef USE_WIN_SURFACE
|
2012-07-30 07:20:58 -07:00
|
|
|
mWinSurface = nullptr;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
#endif
|
|
|
|
#ifdef XP_MACOSX
|
2012-07-30 07:20:58 -07:00
|
|
|
mQuartzSurface = nullptr;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
#endif
|
2014-04-02 18:32:54 -07:00
|
|
|
mDrawSurface = nullptr;
|
2012-03-15 13:30:41 -07:00
|
|
|
|
|
|
|
// We just dumped most of our allocated memory, so tell the discard
|
|
|
|
// tracker that we're not using any at all.
|
|
|
|
if (mInformedDiscardTracker) {
|
2014-04-10 09:15:51 -07:00
|
|
|
DiscardTracker::InformAllocation(-4 * mSize.width * mSize.height);
|
2012-03-15 13:30:41 -07:00
|
|
|
mInformedDiscardTracker = false;
|
|
|
|
}
|
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if it's not RGB24/ARGB32, don't optimize, but we never hit this at the moment
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we're being forced to use image surfaces due to
|
|
|
|
// resource constraints, don't try to optimize beyond same-pixel.
|
2014-01-17 05:57:51 -08:00
|
|
|
if (ShouldUseImageSurfaces())
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
mOptSurface = nullptr;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
|
|
|
|
#ifdef USE_WIN_SURFACE
|
|
|
|
if (mWinSurface) {
|
2014-01-20 09:02:34 -08:00
|
|
|
if (!mFormatChanged) {
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
// just use the DIB if the format has not changed
|
|
|
|
mOptSurface = mWinSurface;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
if (mQuartzSurface) {
|
|
|
|
mQuartzSurface->Flush();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-02-25 02:57:41 -08:00
|
|
|
#ifdef ANDROID
|
|
|
|
gfxImageFormat optFormat =
|
|
|
|
gfxPlatform::GetPlatform()->
|
|
|
|
OptimalFormatForContent(gfxASurface::ContentFromFormat(mFormat));
|
|
|
|
|
|
|
|
if (optFormat == gfxImageFormat::RGB16_565) {
|
|
|
|
RefPtr<VolatileBuffer> buf =
|
|
|
|
LockedImageSurface::AllocateBuffer(mSize, optFormat);
|
|
|
|
if (!buf)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsRefPtr<gfxImageSurface> surf =
|
|
|
|
LockedImageSurface::CreateSurface(buf, mSize, optFormat);
|
|
|
|
|
|
|
|
gfxContext ctx(surf);
|
|
|
|
ctx.SetOperator(gfxContext::OPERATOR_SOURCE);
|
|
|
|
ctx.SetSource(mImageSurface);
|
|
|
|
ctx.Paint();
|
|
|
|
|
|
|
|
mImageSurface = surf;
|
|
|
|
mVBuf = buf;
|
|
|
|
mFormat = optFormat;
|
2014-04-02 18:32:54 -07:00
|
|
|
mDrawSurface = nullptr;
|
2014-02-25 02:57:41 -08:00
|
|
|
}
|
|
|
|
#else
|
2012-07-30 07:20:58 -07:00
|
|
|
if (mOptSurface == nullptr)
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
mOptSurface = gfxPlatform::GetPlatform()->OptimizeImage(mImageSurface, mFormat);
|
2014-02-25 02:57:41 -08:00
|
|
|
#endif
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
|
|
|
|
if (mOptSurface) {
|
2014-02-24 19:37:51 -08:00
|
|
|
mVBuf = nullptr;
|
2012-07-30 07:20:58 -07:00
|
|
|
mImageSurface = nullptr;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
#ifdef USE_WIN_SURFACE
|
2012-07-30 07:20:58 -07:00
|
|
|
mWinSurface = nullptr;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
#endif
|
|
|
|
#ifdef XP_MACOSX
|
2012-07-30 07:20:58 -07:00
|
|
|
mQuartzSurface = nullptr;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
#endif
|
2014-04-02 18:32:54 -07:00
|
|
|
mDrawSurface = nullptr;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-13 06:30:02 -07:00
|
|
|
static void
|
|
|
|
DoSingleColorFastPath(gfxContext* aContext,
|
|
|
|
const gfxRGBA& aSinglePixelColor,
|
|
|
|
const gfxRect& aFill)
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
{
|
2010-08-13 06:30:02 -07:00
|
|
|
// if a == 0, it's a noop
|
|
|
|
if (aSinglePixelColor.a == 0.0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gfxContext::GraphicsOperator op = aContext->CurrentOperator();
|
|
|
|
if (op == gfxContext::OPERATOR_OVER && aSinglePixelColor.a == 1.0) {
|
|
|
|
aContext->SetOperator(gfxContext::OPERATOR_SOURCE);
|
|
|
|
}
|
|
|
|
|
|
|
|
aContext->SetDeviceColor(aSinglePixelColor);
|
|
|
|
aContext->NewPath();
|
|
|
|
aContext->Rectangle(aFill);
|
|
|
|
aContext->Fill();
|
|
|
|
aContext->SetOperator(op);
|
|
|
|
aContext->SetDeviceColor(gfxRGBA(0,0,0,0));
|
|
|
|
}
|
|
|
|
|
|
|
|
imgFrame::SurfaceWithFormat
|
2011-09-28 23:19:26 -07:00
|
|
|
imgFrame::SurfaceForDrawing(bool aDoPadding,
|
|
|
|
bool aDoPartialDecode,
|
|
|
|
bool aDoTile,
|
2010-08-13 06:30:02 -07:00
|
|
|
const nsIntMargin& aPadding,
|
|
|
|
gfxMatrix& aUserSpaceToImageSpace,
|
|
|
|
gfxRect& aFill,
|
|
|
|
gfxRect& aSubimage,
|
|
|
|
gfxRect& aSourceRect,
|
2014-03-02 08:17:26 -08:00
|
|
|
gfxRect& aImageRect,
|
|
|
|
gfxASurface* aSurface)
|
2010-08-13 06:30:02 -07:00
|
|
|
{
|
2014-02-09 00:04:38 -08:00
|
|
|
IntSize size(int32_t(aImageRect.Width()), int32_t(aImageRect.Height()));
|
2010-08-13 06:30:02 -07:00
|
|
|
if (!aDoPadding && !aDoPartialDecode) {
|
|
|
|
NS_ASSERTION(!mSinglePixel, "This should already have been handled");
|
2014-03-02 08:17:26 -08:00
|
|
|
return SurfaceWithFormat(new gfxSurfaceDrawable(aSurface, ThebesIntSize(size)), mFormat);
|
2010-08-13 06:30:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxRect available = gfxRect(mDecoded.x, mDecoded.y, mDecoded.width, mDecoded.height);
|
|
|
|
|
|
|
|
if (aDoTile || mSinglePixel) {
|
|
|
|
// Create a temporary surface.
|
|
|
|
// Give this surface an alpha channel because there are
|
|
|
|
// transparent pixels in the padding or undecoded area
|
2014-01-23 10:26:40 -08:00
|
|
|
gfxImageFormat format = gfxImageFormat::ARGB32;
|
2010-08-13 06:30:02 -07:00
|
|
|
nsRefPtr<gfxASurface> surface =
|
2010-09-16 14:34:53 -07:00
|
|
|
gfxPlatform::GetPlatform()->CreateOffscreenSurface(size, gfxImageSurface::ContentFromFormat(format));
|
2010-08-13 06:30:02 -07:00
|
|
|
if (!surface || surface->CairoStatus())
|
|
|
|
return SurfaceWithFormat();
|
|
|
|
|
|
|
|
// Fill 'available' with whatever we've got
|
|
|
|
gfxContext tmpCtx(surface);
|
|
|
|
tmpCtx.SetOperator(gfxContext::OPERATOR_SOURCE);
|
|
|
|
if (mSinglePixel) {
|
|
|
|
tmpCtx.SetDeviceColor(mSinglePixelColor);
|
|
|
|
} else {
|
2014-03-02 08:17:26 -08:00
|
|
|
tmpCtx.SetSource(aSurface, gfxPoint(aPadding.left, aPadding.top));
|
2010-08-13 06:30:02 -07:00
|
|
|
}
|
|
|
|
tmpCtx.Rectangle(available);
|
|
|
|
tmpCtx.Fill();
|
2012-03-23 15:10:50 -07:00
|
|
|
|
2014-02-09 00:04:38 -08:00
|
|
|
return SurfaceWithFormat(new gfxSurfaceDrawable(surface, ThebesIntSize(size)), format);
|
2010-08-13 06:30:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Not tiling, and we have a surface, so we can account for
|
|
|
|
// padding and/or a partial decode just by twiddling parameters.
|
|
|
|
// First, update our user-space fill rect.
|
|
|
|
aSourceRect = aSourceRect.Intersect(available);
|
|
|
|
gfxMatrix imageSpaceToUserSpace = aUserSpaceToImageSpace;
|
|
|
|
imageSpaceToUserSpace.Invert();
|
|
|
|
aFill = imageSpaceToUserSpace.Transform(aSourceRect);
|
|
|
|
|
|
|
|
aSubimage = aSubimage.Intersect(available) - gfxPoint(aPadding.left, aPadding.top);
|
|
|
|
aUserSpaceToImageSpace.Multiply(gfxMatrix().Translate(-gfxPoint(aPadding.left, aPadding.top)));
|
|
|
|
aSourceRect = aSourceRect - gfxPoint(aPadding.left, aPadding.top);
|
|
|
|
aImageRect = gfxRect(0, 0, mSize.width, mSize.height);
|
|
|
|
|
2010-08-13 06:30:27 -07:00
|
|
|
gfxIntSize availableSize(mDecoded.width, mDecoded.height);
|
2014-03-02 08:17:26 -08:00
|
|
|
return SurfaceWithFormat(new gfxSurfaceDrawable(aSurface, availableSize),
|
2010-08-13 06:30:27 -07:00
|
|
|
mFormat);
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
}
|
|
|
|
|
2014-03-02 08:17:26 -08:00
|
|
|
bool imgFrame::Draw(gfxContext *aContext, GraphicsFilter aFilter,
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
const gfxMatrix &aUserSpaceToImageSpace, const gfxRect& aFill,
|
2012-04-17 15:04:15 -07:00
|
|
|
const nsIntMargin &aPadding, const nsIntRect &aSubimage,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aImageFlags)
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
{
|
2013-03-15 21:47:02 -07:00
|
|
|
PROFILER_LABEL("image", "imgFrame::Draw");
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
NS_ASSERTION(!aFill.IsEmpty(), "zero dest size --- fix caller");
|
|
|
|
NS_ASSERTION(!aSubimage.IsEmpty(), "zero source size --- fix caller");
|
|
|
|
NS_ASSERTION(!mPalettedImageData, "Directly drawing a paletted image!");
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool doPadding = aPadding != nsIntMargin(0,0,0,0);
|
|
|
|
bool doPartialDecode = !ImageComplete();
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
|
2010-08-13 06:30:02 -07:00
|
|
|
if (mSinglePixel && !doPadding && !doPartialDecode) {
|
|
|
|
DoSingleColorFastPath(aContext, mSinglePixelColor, aFill);
|
2014-03-02 08:17:26 -08:00
|
|
|
return true;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxMatrix userSpaceToImageSpace = aUserSpaceToImageSpace;
|
2013-08-25 00:19:43 -07:00
|
|
|
gfxRect sourceRect = userSpaceToImageSpace.TransformBounds(aFill);
|
2010-08-13 06:30:02 -07:00
|
|
|
gfxRect imageRect(0, 0, mSize.width + aPadding.LeftRight(),
|
|
|
|
mSize.height + aPadding.TopBottom());
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
gfxRect subimage(aSubimage.x, aSubimage.y, aSubimage.width, aSubimage.height);
|
|
|
|
gfxRect fill = aFill;
|
|
|
|
|
|
|
|
NS_ASSERTION(!sourceRect.Intersect(subimage).IsEmpty(),
|
|
|
|
"We must be allowed to sample *some* source pixels!");
|
|
|
|
|
2014-04-02 18:32:54 -07:00
|
|
|
nsRefPtr<gfxASurface> surf = CachedThebesSurface();
|
|
|
|
VolatileBufferPtr<unsigned char> ref(mVBuf);
|
|
|
|
if (!mSinglePixel && !surf) {
|
|
|
|
if (ref.WasBufferPurged()) {
|
2014-03-02 08:17:26 -08:00
|
|
|
return false;
|
2014-04-02 18:32:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
surf = mDrawSurface;
|
|
|
|
if (!surf) {
|
|
|
|
long stride = gfxImageSurface::ComputeStride(mSize, mFormat);
|
|
|
|
nsRefPtr<gfxImageSurface> imgSurf =
|
|
|
|
new gfxImageSurface(ref, mSize, stride, mFormat);
|
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
surf = mDrawSurface = new gfxQuartzImageSurface(imgSurf);
|
|
|
|
#else
|
|
|
|
surf = mDrawSurface = imgSurf;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if (!surf || surf->CairoStatus()) {
|
|
|
|
mDrawSurface = nullptr;
|
|
|
|
return true;
|
|
|
|
}
|
2014-03-02 08:17:26 -08:00
|
|
|
}
|
|
|
|
|
2012-04-17 15:04:15 -07:00
|
|
|
bool doTile = !imageRect.Contains(sourceRect) &&
|
|
|
|
!(aImageFlags & imgIContainer::FLAG_CLAMP);
|
2010-08-13 06:30:02 -07:00
|
|
|
SurfaceWithFormat surfaceResult =
|
|
|
|
SurfaceForDrawing(doPadding, doPartialDecode, doTile, aPadding,
|
|
|
|
userSpaceToImageSpace, fill, subimage, sourceRect,
|
2014-03-02 08:17:26 -08:00
|
|
|
imageRect, surf);
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
|
2010-08-13 06:30:02 -07:00
|
|
|
if (surfaceResult.IsValid()) {
|
2010-08-13 06:30:27 -07:00
|
|
|
gfxUtils::DrawPixelSnapped(aContext, surfaceResult.mDrawable,
|
2010-08-13 06:30:02 -07:00
|
|
|
userSpaceToImageSpace,
|
|
|
|
subimage, sourceRect, imageRect, fill,
|
2012-04-17 15:04:15 -07:00
|
|
|
surfaceResult.mFormat, aFilter, aImageFlags);
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
}
|
2014-03-02 08:17:26 -08:00
|
|
|
return true;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
}
|
|
|
|
|
2013-05-24 06:52:34 -07:00
|
|
|
// This can be called from any thread, but not simultaneously.
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
nsresult imgFrame::ImageUpdated(const nsIntRect &aUpdateRect)
|
|
|
|
{
|
2013-07-04 11:45:57 -07:00
|
|
|
MutexAutoLock lock(mDirtyMutex);
|
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
mDecoded.UnionRect(mDecoded, aUpdateRect);
|
|
|
|
|
|
|
|
// clamp to bounds, in case someone sends a bogus updateRect (I'm looking at
|
|
|
|
// you, gif decoder)
|
2010-03-10 14:09:06 -08:00
|
|
|
nsIntRect boundsRect(mOffset, mSize);
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
mDecoded.IntersectRect(mDecoded, boundsRect);
|
|
|
|
|
2013-07-04 11:45:57 -07:00
|
|
|
mDirty = true;
|
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-15 11:38:59 -07:00
|
|
|
bool imgFrame::GetIsDirty() const
|
2013-07-04 11:45:57 -07:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mDirtyMutex);
|
|
|
|
return mDirty;
|
|
|
|
}
|
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
nsIntRect imgFrame::GetRect() const
|
|
|
|
{
|
|
|
|
return nsIntRect(mOffset, mSize);
|
|
|
|
}
|
|
|
|
|
2013-09-24 13:45:13 -07:00
|
|
|
gfxImageFormat imgFrame::GetFormat() const
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
{
|
|
|
|
return mFormat;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool imgFrame::GetNeedsBackground() const
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
{
|
|
|
|
// We need a background painted if we have alpha or we're incomplete.
|
2014-01-23 10:26:40 -08:00
|
|
|
return (mFormat == gfxImageFormat::ARGB32 || !ImageComplete());
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t imgFrame::GetImageBytesPerRow() const
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
{
|
|
|
|
if (mImageSurface)
|
|
|
|
return mImageSurface->Stride();
|
2010-05-21 21:10:14 -07:00
|
|
|
|
2014-02-24 19:37:51 -08:00
|
|
|
if (mVBuf)
|
|
|
|
return gfxImageSurface::ComputeStride(mSize, mFormat);
|
|
|
|
|
2010-05-21 21:10:14 -07:00
|
|
|
if (mPaletteDepth)
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
return mSize.width;
|
2010-05-21 21:10:14 -07:00
|
|
|
|
2014-02-24 19:37:51 -08:00
|
|
|
NS_ERROR("GetImageBytesPerRow called with mImageSurface == null, mVBuf == null and mPaletteDepth == 0");
|
2010-05-21 21:10:14 -07:00
|
|
|
|
|
|
|
return 0;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t imgFrame::GetImageDataLength() const
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
{
|
2010-05-21 21:10:14 -07:00
|
|
|
return GetImageBytesPerRow() * mSize.height;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void imgFrame::GetImageData(uint8_t **aData, uint32_t *length) const
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
{
|
2012-09-26 08:33:06 -07:00
|
|
|
NS_ABORT_IF_FALSE(mLockCount != 0, "Can't GetImageData unless frame is locked");
|
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
if (mImageSurface)
|
|
|
|
*aData = mImageSurface->Data();
|
|
|
|
else if (mPalettedImageData)
|
|
|
|
*aData = mPalettedImageData + PaletteDataLength();
|
|
|
|
else
|
2012-07-30 07:20:58 -07:00
|
|
|
*aData = nullptr;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
|
|
|
|
*length = GetImageDataLength();
|
|
|
|
}
|
|
|
|
|
2013-06-14 06:42:01 -07:00
|
|
|
uint8_t* imgFrame::GetImageData() const
|
|
|
|
{
|
|
|
|
uint8_t *data;
|
|
|
|
uint32_t length;
|
|
|
|
GetImageData(&data, &length);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool imgFrame::GetIsPaletted() const
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
return mPalettedImageData != nullptr;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool imgFrame::GetHasAlpha() const
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
{
|
2014-01-23 10:26:40 -08:00
|
|
|
return mFormat == gfxImageFormat::ARGB32;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void imgFrame::GetPaletteData(uint32_t **aPalette, uint32_t *length) const
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
{
|
2012-09-26 08:33:06 -07:00
|
|
|
NS_ABORT_IF_FALSE(mLockCount != 0, "Can't GetPaletteData unless frame is locked");
|
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
if (!mPalettedImageData) {
|
2012-07-30 07:20:58 -07:00
|
|
|
*aPalette = nullptr;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
*length = 0;
|
|
|
|
} else {
|
2012-08-22 08:56:38 -07:00
|
|
|
*aPalette = (uint32_t *) mPalettedImageData;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
*length = PaletteDataLength();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-14 06:42:01 -07:00
|
|
|
uint32_t* imgFrame::GetPaletteData() const
|
|
|
|
{
|
|
|
|
uint32_t* data;
|
|
|
|
uint32_t length;
|
|
|
|
GetPaletteData(&data, &length);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
nsresult imgFrame::LockImageData()
|
|
|
|
{
|
2013-05-24 06:52:34 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2012-09-26 08:33:06 -07:00
|
|
|
NS_ABORT_IF_FALSE(mLockCount >= 0, "Unbalanced locks and unlocks");
|
|
|
|
if (mLockCount < 0) {
|
2012-09-28 15:00:28 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-09-26 08:33:06 -07:00
|
|
|
}
|
2012-09-26 08:33:06 -07:00
|
|
|
|
|
|
|
mLockCount++;
|
|
|
|
|
|
|
|
// If we are not the first lock, there's nothing to do.
|
|
|
|
if (mLockCount != 1) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Paletted images don't have surfaces, so there's nothing to do.
|
|
|
|
if (mPalettedImageData)
|
|
|
|
return NS_OK;
|
2010-02-25 10:14:30 -08:00
|
|
|
|
2014-02-24 19:37:51 -08:00
|
|
|
if (!mImageSurface) {
|
|
|
|
if (mVBuf) {
|
|
|
|
VolatileBufferPtr<uint8_t> ref(mVBuf);
|
|
|
|
if (ref.WasBufferPurged())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
mImageSurface = LockedImageSurface::CreateSurface(mVBuf, mSize, mFormat);
|
|
|
|
if (!mImageSurface || mImageSurface->CairoStatus())
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2014-02-25 02:57:41 -08:00
|
|
|
}
|
|
|
|
if (mOptSurface || mSinglePixel || mFormat == gfxImageFormat::RGB16_565) {
|
|
|
|
gfxImageFormat format = mFormat;
|
|
|
|
if (mFormat == gfxImageFormat::RGB16_565)
|
|
|
|
format = gfxImageFormat::ARGB32;
|
|
|
|
|
2014-02-24 19:37:51 -08:00
|
|
|
// Recover the pixels
|
2014-02-25 02:57:41 -08:00
|
|
|
RefPtr<VolatileBuffer> buf =
|
|
|
|
LockedImageSurface::AllocateBuffer(mSize, format);
|
|
|
|
if (!buf) {
|
2014-02-24 19:37:51 -08:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2014-02-25 02:57:41 -08:00
|
|
|
RefPtr<gfxImageSurface> surf =
|
|
|
|
LockedImageSurface::CreateSurface(buf, mSize, mFormat);
|
|
|
|
if (!surf || surf->CairoStatus())
|
2014-02-24 19:37:51 -08:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
|
2014-02-25 02:57:41 -08:00
|
|
|
gfxContext context(surf);
|
2014-02-24 19:37:51 -08:00
|
|
|
context.SetOperator(gfxContext::OPERATOR_SOURCE);
|
|
|
|
if (mSinglePixel)
|
|
|
|
context.SetDeviceColor(mSinglePixelColor);
|
2014-02-25 02:57:41 -08:00
|
|
|
else if (mFormat == gfxImageFormat::RGB16_565)
|
|
|
|
context.SetSource(mImageSurface);
|
2014-02-24 19:37:51 -08:00
|
|
|
else
|
|
|
|
context.SetSource(mOptSurface);
|
|
|
|
context.Paint();
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
|
2014-02-25 02:57:41 -08:00
|
|
|
mFormat = format;
|
|
|
|
mVBuf = buf;
|
|
|
|
mImageSurface = surf;
|
2014-02-24 19:37:51 -08:00
|
|
|
mOptSurface = nullptr;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
#ifdef USE_WIN_SURFACE
|
2014-02-24 19:37:51 -08:00
|
|
|
mWinSurface = nullptr;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
#endif
|
|
|
|
#ifdef XP_MACOSX
|
2014-02-24 19:37:51 -08:00
|
|
|
mQuartzSurface = nullptr;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
#endif
|
2014-02-24 19:37:51 -08:00
|
|
|
}
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
}
|
|
|
|
|
2010-03-01 17:04:30 -08:00
|
|
|
// We might write to the bits in this image surface, so we need to make the
|
|
|
|
// surface ready for that.
|
|
|
|
if (mImageSurface)
|
|
|
|
mImageSurface->Flush();
|
|
|
|
|
2010-04-26 07:29:59 -07:00
|
|
|
#ifdef USE_WIN_SURFACE
|
|
|
|
if (mWinSurface)
|
|
|
|
mWinSurface->Flush();
|
|
|
|
#endif
|
|
|
|
|
2014-02-24 19:37:51 -08:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
if (!mQuartzSurface && !ShouldUseImageSurfaces()) {
|
|
|
|
mQuartzSurface = new gfxQuartzImageSurface(mImageSurface);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult imgFrame::UnlockImageData()
|
|
|
|
{
|
2013-05-24 06:52:34 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2012-09-26 08:33:06 -07:00
|
|
|
NS_ABORT_IF_FALSE(mLockCount != 0, "Unlocking an unlocked image!");
|
|
|
|
if (mLockCount == 0) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mLockCount--;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
|
2012-09-26 08:33:06 -07:00
|
|
|
NS_ABORT_IF_FALSE(mLockCount >= 0, "Unbalanced locks and unlocks");
|
|
|
|
if (mLockCount < 0) {
|
2010-02-25 10:14:30 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-09-26 08:33:06 -07:00
|
|
|
// If we are not the last lock, there's nothing to do.
|
|
|
|
if (mLockCount != 0) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Paletted images don't have surfaces, so there's nothing to do.
|
|
|
|
if (mPalettedImageData)
|
|
|
|
return NS_OK;
|
2010-02-25 10:14:30 -08:00
|
|
|
|
2013-07-04 11:46:02 -07:00
|
|
|
// FIXME: Bug 795737
|
|
|
|
// If this image has been drawn since we were locked, it has had snapshots
|
|
|
|
// added, and we need to remove them before calling MarkDirty.
|
|
|
|
if (mImageSurface)
|
|
|
|
mImageSurface->Flush();
|
|
|
|
|
|
|
|
#ifdef USE_WIN_SURFACE
|
|
|
|
if (mWinSurface)
|
|
|
|
mWinSurface->Flush();
|
|
|
|
#endif
|
|
|
|
|
2010-03-01 17:04:30 -08:00
|
|
|
// Assume we've been written to.
|
|
|
|
if (mImageSurface)
|
|
|
|
mImageSurface->MarkDirty();
|
|
|
|
|
2010-04-26 07:29:59 -07:00
|
|
|
#ifdef USE_WIN_SURFACE
|
|
|
|
if (mWinSurface)
|
|
|
|
mWinSurface->MarkDirty();
|
|
|
|
#endif
|
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
#ifdef XP_MACOSX
|
2010-03-01 17:04:30 -08:00
|
|
|
// The quartz image surface (ab)uses the flush method to get the
|
|
|
|
// cairo_image_surface data into a CGImage, so we have to call Flush() here.
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
if (mQuartzSurface)
|
|
|
|
mQuartzSurface->Flush();
|
|
|
|
#endif
|
2013-03-22 19:05:44 -07:00
|
|
|
|
2014-02-24 19:37:51 -08:00
|
|
|
if (mVBuf && mDiscardable) {
|
|
|
|
mImageSurface = nullptr;
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
mQuartzSurface = nullptr;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-04 11:45:57 -07:00
|
|
|
void imgFrame::ApplyDirtToSurfaces()
|
2013-03-22 19:05:44 -07:00
|
|
|
{
|
2013-05-24 06:52:34 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2013-07-04 11:45:57 -07:00
|
|
|
MutexAutoLock lock(mDirtyMutex);
|
|
|
|
if (mDirty) {
|
2013-07-04 11:46:02 -07:00
|
|
|
// FIXME: Bug 795737
|
|
|
|
// If this image has been drawn since we were locked, it has had snapshots
|
|
|
|
// added, and we need to remove them before calling MarkDirty.
|
2013-07-04 11:45:57 -07:00
|
|
|
if (mImageSurface)
|
|
|
|
mImageSurface->Flush();
|
2013-03-22 19:05:44 -07:00
|
|
|
|
|
|
|
#ifdef USE_WIN_SURFACE
|
2013-07-04 11:45:57 -07:00
|
|
|
if (mWinSurface)
|
|
|
|
mWinSurface->Flush();
|
2013-03-22 19:05:44 -07:00
|
|
|
#endif
|
|
|
|
|
2013-07-04 11:45:57 -07:00
|
|
|
if (mImageSurface)
|
|
|
|
mImageSurface->MarkDirty();
|
2013-03-22 19:05:44 -07:00
|
|
|
|
|
|
|
#ifdef USE_WIN_SURFACE
|
2013-07-04 11:45:57 -07:00
|
|
|
if (mWinSurface)
|
|
|
|
mWinSurface->MarkDirty();
|
2013-03-22 19:05:44 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
2013-07-04 11:45:57 -07:00
|
|
|
// The quartz image surface (ab)uses the flush method to get the
|
|
|
|
// cairo_image_surface data into a CGImage, so we have to call Flush() here.
|
|
|
|
if (mQuartzSurface)
|
|
|
|
mQuartzSurface->Flush();
|
2013-03-22 19:05:44 -07:00
|
|
|
#endif
|
2013-07-04 11:45:57 -07:00
|
|
|
|
|
|
|
mDirty = false;
|
|
|
|
}
|
2013-03-22 19:05:44 -07:00
|
|
|
}
|
|
|
|
|
2014-02-24 19:37:51 -08:00
|
|
|
void imgFrame::SetDiscardable()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mLockCount, "Expected to be locked when SetDiscardable is called");
|
|
|
|
mDiscardable = true;
|
|
|
|
}
|
|
|
|
|
2013-12-06 01:45:24 -08:00
|
|
|
int32_t imgFrame::GetRawTimeout() const
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
{
|
2013-12-06 01:45:24 -08:00
|
|
|
return mTimeout;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
}
|
|
|
|
|
2013-12-06 01:45:24 -08:00
|
|
|
void imgFrame::SetRawTimeout(int32_t aTimeout)
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
{
|
|
|
|
mTimeout = aTimeout;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t imgFrame::GetFrameDisposalMethod() const
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
{
|
|
|
|
return mDisposalMethod;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void imgFrame::SetFrameDisposalMethod(int32_t aFrameDisposalMethod)
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
{
|
|
|
|
mDisposalMethod = aFrameDisposalMethod;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t imgFrame::GetBlendMethod() const
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
{
|
|
|
|
return mBlendMethod;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void imgFrame::SetBlendMethod(int32_t aBlendMethod)
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
mBlendMethod = (int8_t)aBlendMethod;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
}
|
|
|
|
|
2013-07-15 11:38:59 -07:00
|
|
|
// This can be called from any thread.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool imgFrame::ImageComplete() const
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
{
|
2013-07-15 11:38:59 -07:00
|
|
|
MutexAutoLock lock(mDirtyMutex);
|
|
|
|
|
2011-04-18 20:07:23 -07:00
|
|
|
return mDecoded.IsEqualInterior(nsIntRect(mOffset, mSize));
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// A hint from the image decoders that this image has no alpha, even
|
|
|
|
// though we created is ARGB32. This changes our format to RGB24,
|
|
|
|
// which in turn will cause us to Optimize() to RGB24. Has no effect
|
|
|
|
// after Optimize() is called, though in all cases it will be just a
|
|
|
|
// performance win -- the pixels are still correct and have the A byte
|
|
|
|
// set to 0xff.
|
|
|
|
void imgFrame::SetHasNoAlpha()
|
|
|
|
{
|
2014-01-23 10:26:40 -08:00
|
|
|
if (mFormat == gfxImageFormat::ARGB32) {
|
|
|
|
mFormat = gfxImageFormat::RGB24;
|
2011-10-17 07:59:28 -07:00
|
|
|
mFormatChanged = true;
|
2013-09-20 02:50:05 -07:00
|
|
|
ThebesSurface()->SetOpaqueRect(gfxRect(0, 0, mSize.width, mSize.height));
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-20 18:50:15 -07:00
|
|
|
}
|
|
|
|
}
|
2009-11-12 15:18:40 -08:00
|
|
|
|
2012-03-23 15:10:50 -07:00
|
|
|
void imgFrame::SetAsNonPremult(bool aIsNonPremult)
|
|
|
|
{
|
|
|
|
mNonPremult = aIsNonPremult;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool imgFrame::GetCompositingFailed() const
|
2009-11-12 15:18:40 -08:00
|
|
|
{
|
|
|
|
return mCompositingFailed;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
void imgFrame::SetCompositingFailed(bool val)
|
2009-11-12 15:18:40 -08:00
|
|
|
{
|
|
|
|
mCompositingFailed = val;
|
|
|
|
}
|
2010-03-12 02:08:25 -08:00
|
|
|
|
2012-11-26 16:29:56 -08:00
|
|
|
// If |aLocation| indicates this is heap memory, we try to measure things with
|
|
|
|
// |aMallocSizeOf|. If that fails (because the platform doesn't support it) or
|
|
|
|
// it's non-heap memory, we fall back to computing the size analytically.
|
2012-02-19 19:51:48 -08:00
|
|
|
size_t
|
2013-09-24 13:45:13 -07:00
|
|
|
imgFrame::SizeOfExcludingThisWithComputedFallbackIfHeap(gfxMemoryLocation aLocation, mozilla::MallocSizeOf aMallocSizeOf) const
|
2010-05-21 21:10:14 -07:00
|
|
|
{
|
2014-01-23 10:26:40 -08:00
|
|
|
// aMallocSizeOf is only used if aLocation==gfxMemoryLocation::IN_PROCESS_HEAP. It
|
2013-08-23 12:51:00 -07:00
|
|
|
// should be nullptr otherwise.
|
2012-02-19 19:51:48 -08:00
|
|
|
NS_ABORT_IF_FALSE(
|
2014-01-23 10:26:40 -08:00
|
|
|
(aLocation == gfxMemoryLocation::IN_PROCESS_HEAP && aMallocSizeOf) ||
|
|
|
|
(aLocation != gfxMemoryLocation::IN_PROCESS_HEAP && !aMallocSizeOf),
|
2012-02-19 19:51:48 -08:00
|
|
|
"mismatch between aLocation and aMallocSizeOf");
|
2010-05-21 21:10:14 -07:00
|
|
|
|
2012-02-19 19:51:48 -08:00
|
|
|
size_t n = 0;
|
2010-05-21 21:10:14 -07:00
|
|
|
|
2014-01-23 10:26:40 -08:00
|
|
|
if (mPalettedImageData && aLocation == gfxMemoryLocation::IN_PROCESS_HEAP) {
|
2012-11-26 16:29:56 -08:00
|
|
|
size_t n2 = aMallocSizeOf(mPalettedImageData);
|
|
|
|
if (n2 == 0) {
|
|
|
|
n2 = GetImageDataLength() + PaletteDataLength();
|
2012-02-19 19:51:48 -08:00
|
|
|
}
|
2012-11-26 16:29:56 -08:00
|
|
|
n += n2;
|
2010-05-21 21:10:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef USE_WIN_SURFACE
|
2011-07-18 06:20:27 -07:00
|
|
|
if (mWinSurface && aLocation == mWinSurface->GetMemoryLocation()) {
|
2012-02-19 19:51:48 -08:00
|
|
|
n += mWinSurface->KnownMemoryUsed();
|
2010-05-21 21:10:14 -07:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
#ifdef XP_MACOSX
|
2014-01-23 10:26:40 -08:00
|
|
|
if (mQuartzSurface && aLocation == gfxMemoryLocation::IN_PROCESS_HEAP) {
|
2014-02-24 19:37:51 -08:00
|
|
|
n += aMallocSizeOf(mQuartzSurface);
|
|
|
|
}
|
2010-05-21 21:10:14 -07:00
|
|
|
#endif
|
2011-07-18 06:20:27 -07:00
|
|
|
if (mImageSurface && aLocation == mImageSurface->GetMemoryLocation()) {
|
2012-11-26 16:29:56 -08:00
|
|
|
size_t n2 = 0;
|
2014-01-23 10:26:40 -08:00
|
|
|
if (aLocation == gfxMemoryLocation::IN_PROCESS_HEAP) { // HEAP: measure
|
2012-11-26 16:29:56 -08:00
|
|
|
n2 = mImageSurface->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
if (n2 == 0) { // non-HEAP or computed fallback for HEAP
|
|
|
|
n2 = mImageSurface->KnownMemoryUsed();
|
|
|
|
}
|
|
|
|
n += n2;
|
2010-05-21 21:10:14 -07:00
|
|
|
}
|
|
|
|
|
2014-02-24 19:37:51 -08:00
|
|
|
if (mVBuf && aLocation == gfxMemoryLocation::IN_PROCESS_HEAP) {
|
|
|
|
n += aMallocSizeOf(mVBuf);
|
|
|
|
n += mVBuf->HeapSizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
2011-07-18 06:20:27 -07:00
|
|
|
if (mOptSurface && aLocation == mOptSurface->GetMemoryLocation()) {
|
2012-12-18 21:59:30 -08:00
|
|
|
size_t n2 = 0;
|
2014-01-23 10:26:40 -08:00
|
|
|
if (aLocation == gfxMemoryLocation::IN_PROCESS_HEAP &&
|
2012-12-18 21:59:30 -08:00
|
|
|
mOptSurface->SizeOfIsMeasured()) {
|
|
|
|
// HEAP: measure (but only if the sub-class is capable of measuring)
|
|
|
|
n2 = mOptSurface->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
if (n2 == 0) { // non-HEAP or computed fallback for HEAP
|
|
|
|
n2 = mOptSurface->KnownMemoryUsed();
|
|
|
|
}
|
|
|
|
n += n2;
|
2010-05-21 21:10:14 -07:00
|
|
|
}
|
|
|
|
|
2012-02-19 19:51:48 -08:00
|
|
|
return n;
|
2010-05-21 21:10:14 -07:00
|
|
|
}
|