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
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
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 <limits.h>
|
|
|
|
|
|
|
|
#include "prenv.h"
|
|
|
|
|
|
|
|
#include "gfxPlatform.h"
|
2010-08-13 06:30:02 -07:00
|
|
|
#include "gfxUtils.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"
|
2012-01-17 12:33:04 -08:00
|
|
|
#include "sampler.h"
|
2012-10-26 06:32:10 -07:00
|
|
|
#include "mozilla/Likely.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
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint32_t gTotalDDBs = 0;
|
|
|
|
static uint32_t gTotalDDBSize = 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
|
|
|
// only use up a maximum of 64MB in DDBs
|
|
|
|
#define kMaxDDBSize (64*1024*1024)
|
|
|
|
// and don't let anything in that's bigger than 4MB
|
|
|
|
#define kMaxSingleDDBSize (4*1024*1024)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2012-03-15 13:30:41 -07:00
|
|
|
using namespace mozilla::image;
|
|
|
|
|
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
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t tmp = aWidth * aHeight;
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_UNLIKELY(tmp / aHeight != aWidth)) {
|
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
|
|
|
}
|
|
|
|
tmp = tmp * 4;
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_UNLIKELY(tmp / 4 != aWidth * 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
|
|
|
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),
|
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),
|
|
|
|
mNeverUseDeviceSurface(false),
|
|
|
|
mFormatChanged(false),
|
2012-03-23 15:10:50 -07:00
|
|
|
mCompositingFailed(false),
|
|
|
|
mNonPremult(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
|
|
|
#ifdef USE_WIN_SURFACE
|
2012-03-23 15:10:50 -07:00
|
|
|
mIsDDBSurface(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
|
2012-03-23 15:10:50 -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
|
|
|
{
|
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;
|
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 (mIsDDBSurface) {
|
|
|
|
gTotalDDBs--;
|
|
|
|
gTotalDDBSize -= mSize.width * mSize.height * 4;
|
|
|
|
}
|
|
|
|
#endif
|
2012-03-15 13:30:41 -07:00
|
|
|
|
|
|
|
if (mInformedDiscardTracker) {
|
|
|
|
DiscardTracker::InformAllocation(-4 * mSize.height * mSize.width);
|
|
|
|
}
|
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
|
|
|
nsresult imgFrame::Init(int32_t aX, int32_t aY, int32_t aWidth, int32_t aHeight,
|
|
|
|
gfxASurface::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
|
|
|
|
if (!AllowedImageSize(aWidth, aHeight))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
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) {
|
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());
|
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
|
|
|
|
if (!mNeverUseDeviceSurface && !ShouldUseImageSurfaces()) {
|
|
|
|
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
|
|
|
|
|
|
|
|
// For other platforms we create the image surface first and then
|
|
|
|
// possibly wrap it in a device surface. This branch is also used
|
|
|
|
// on Windows if we're not using device surfaces or if we couldn't
|
|
|
|
// create one.
|
|
|
|
if (!mImageSurface)
|
|
|
|
mImageSurface = new gfxImageSurface(gfxIntSize(mSize.width, mSize.height), mFormat);
|
|
|
|
|
|
|
|
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
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
if (!mNeverUseDeviceSurface && !ShouldUseImageSurfaces()) {
|
|
|
|
mQuartzSurface = new gfxQuartzImageSurface(mImageSurface);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-03-15 13:30:41 -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()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
if (mFormat == gfxASurface::ImageFormatARGB32 ||
|
|
|
|
mFormat == gfxASurface::ImageFormatRGB24)
|
|
|
|
{
|
2012-03-23 15:10:50 -07:00
|
|
|
// Should already be premult if desired.
|
|
|
|
gfxRGBA::PackedColorType inputType = gfxRGBA::PACKED_XRGB;
|
|
|
|
if (mFormat == gfxASurface::ImageFormatARGB32)
|
|
|
|
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
|
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
|
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) {
|
|
|
|
DiscardTracker::InformAllocation(-4 * mSize.width * mSize.height);
|
|
|
|
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.
|
|
|
|
if (mNeverUseDeviceSurface || ShouldUseImageSurfaces())
|
|
|
|
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
|
|
|
|
// we need to special-case windows here, because windows has
|
|
|
|
// a distinction between DIB and DDB and we want to use DDBs as much
|
|
|
|
// as we can.
|
|
|
|
if (mWinSurface) {
|
|
|
|
// Don't do DDBs for large images; see bug 359147
|
|
|
|
// Note that we bother with DDBs at all because they are much faster
|
|
|
|
// on some systems; on others there isn't much of a speed difference
|
|
|
|
// between DIBs and DDBs.
|
|
|
|
//
|
|
|
|
// Originally this just limited to 1024x1024; but that still
|
|
|
|
// had us hitting overall total memory usage limits (which was
|
|
|
|
// around 220MB on my intel shared memory system with 2GB RAM
|
|
|
|
// and 16-128mb in use by the video card, so I can't make
|
|
|
|
// heads or tails out of this limit).
|
|
|
|
//
|
|
|
|
// So instead, we clamp the max size to 64MB (this limit shuld
|
|
|
|
// be made dynamic based on.. something.. as soon a we figure
|
|
|
|
// out that something) and also limit each individual image to
|
|
|
|
// be less than 4MB to keep very large images out of DDBs.
|
|
|
|
|
|
|
|
// assume (almost -- we don't quadword-align) worst-case size
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t ddbSize = mSize.width * mSize.height * 4;
|
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 (ddbSize <= kMaxSingleDDBSize &&
|
|
|
|
ddbSize + gTotalDDBSize <= kMaxDDBSize)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
nsRefPtr<gfxWindowsSurface> wsurf = mWinSurface->OptimizeToDDB(nullptr, gfxIntSize(mSize.width, mSize.height), 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 (wsurf) {
|
|
|
|
gTotalDDBs++;
|
|
|
|
gTotalDDBSize += ddbSize;
|
2011-10-17 07:59:28 -07:00
|
|
|
mIsDDBSurface = 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
|
|
|
mOptSurface = wsurf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!mOptSurface && !mFormatChanged) {
|
|
|
|
// just use the DIB if the format has not changed
|
|
|
|
mOptSurface = mWinSurface;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
if (mQuartzSurface) {
|
|
|
|
mQuartzSurface->Flush();
|
|
|
|
mOptSurface = mQuartzSurface;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (mOptSurface) {
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
gfxRect& aImageRect)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
gfxIntSize 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");
|
2010-08-13 06:30:27 -07:00
|
|
|
return SurfaceWithFormat(new gfxSurfaceDrawable(ThebesSurface(), 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
|
|
|
|
gfxImageSurface::gfxImageFormat format = gfxASurface::ImageFormatARGB32;
|
|
|
|
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 {
|
|
|
|
tmpCtx.SetSource(ThebesSurface(), gfxPoint(aPadding.left, aPadding.top));
|
|
|
|
}
|
|
|
|
tmpCtx.Rectangle(available);
|
|
|
|
tmpCtx.Fill();
|
2012-03-23 15:10:50 -07:00
|
|
|
|
2010-08-13 06:30:27 -07:00
|
|
|
return SurfaceWithFormat(new gfxSurfaceDrawable(surface, 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);
|
|
|
|
return SurfaceWithFormat(new gfxSurfaceDrawable(ThebesSurface(),
|
|
|
|
availableSize),
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void imgFrame::Draw(gfxContext *aContext, gfxPattern::GraphicsFilter aFilter,
|
|
|
|
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
|
|
|
{
|
2012-01-17 12:33:04 -08:00
|
|
|
SAMPLE_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);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxMatrix userSpaceToImageSpace = aUserSpaceToImageSpace;
|
|
|
|
gfxRect sourceRect = userSpaceToImageSpace.Transform(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!");
|
|
|
|
|
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,
|
|
|
|
imageRect);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult imgFrame::Extract(const nsIntRect& aRegion, imgFrame** aResult)
|
|
|
|
{
|
|
|
|
nsAutoPtr<imgFrame> subImage(new imgFrame());
|
|
|
|
|
|
|
|
// The scaling problems described in bug 468496 are especially
|
|
|
|
// likely to be visible for the sub-image, as at present the only
|
|
|
|
// user is the border-image code and border-images tend to get
|
|
|
|
// stretched a lot. At the same time, the performance concerns
|
|
|
|
// that prevent us from just using Cairo's fallback scaler when
|
|
|
|
// accelerated graphics won't cut it are less relevant to such
|
|
|
|
// images, since they also tend to be small. Thus, we forcibly
|
|
|
|
// disable the use of anything other than a client-side image
|
|
|
|
// surface for the sub-image; this ensures that the correct
|
|
|
|
// (albeit slower) Cairo fallback scaler will be used.
|
2011-10-17 07:59:28 -07:00
|
|
|
subImage->mNeverUseDeviceSurface = 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
|
|
|
|
|
|
|
nsresult rv = subImage->Init(0, 0, aRegion.width, aRegion.height,
|
|
|
|
mFormat, mPaletteDepth);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-03-23 15:10:50 -07:00
|
|
|
subImage->SetAsNonPremult(mNonPremult);
|
|
|
|
|
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
|
|
|
// scope to destroy ctx
|
|
|
|
{
|
|
|
|
gfxContext ctx(subImage->ThebesSurface());
|
|
|
|
ctx.SetOperator(gfxContext::OPERATOR_SOURCE);
|
|
|
|
if (mSinglePixel) {
|
|
|
|
ctx.SetDeviceColor(mSinglePixelColor);
|
|
|
|
} else {
|
|
|
|
// SetSource() places point (0,0) of its first argument at
|
|
|
|
// the coordinages given by its second argument. We want
|
|
|
|
// (x,y) of the image to be (0,0) of source space, so we
|
|
|
|
// put (0,0) of the image at (-x,-y).
|
|
|
|
ctx.SetSource(this->ThebesSurface(), gfxPoint(-aRegion.x, -aRegion.y));
|
|
|
|
}
|
|
|
|
ctx.Rectangle(gfxRect(0, 0, aRegion.width, aRegion.height));
|
|
|
|
ctx.Fill();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntRect filled(0, 0, aRegion.width, aRegion.height);
|
|
|
|
|
|
|
|
rv = subImage->ImageUpdated(filled);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
subImage->Optimize();
|
|
|
|
|
|
|
|
*aResult = subImage.forget();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult imgFrame::ImageUpdated(const nsIntRect &aUpdateRect)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
if (mQuartzSurface)
|
|
|
|
mQuartzSurface->Flush();
|
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntRect imgFrame::GetRect() const
|
|
|
|
{
|
|
|
|
return nsIntRect(mOffset, mSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxASurface::gfxImageFormat imgFrame::GetFormat() const
|
|
|
|
{
|
|
|
|
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.
|
|
|
|
return (mFormat == gfxASurface::ImageFormatARGB32 || !ImageComplete());
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
NS_ERROR("GetImageBytesPerRow called with mImageSurface == null and mPaletteDepth == 0");
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2009-07-21 21:19:59 -07:00
|
|
|
return mFormat == gfxASurface::ImageFormatARGB32;
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult imgFrame::LockImageData()
|
|
|
|
{
|
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
|
|
|
|
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 || mSinglePixel) && !mImageSurface) {
|
|
|
|
// Recover the pixels
|
|
|
|
mImageSurface = new gfxImageSurface(gfxIntSize(mSize.width, mSize.height),
|
|
|
|
gfxImageSurface::ImageFormatARGB32);
|
|
|
|
if (!mImageSurface || mImageSurface->CairoStatus())
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
gfxContext context(mImageSurface);
|
|
|
|
context.SetOperator(gfxContext::OPERATOR_SOURCE);
|
|
|
|
if (mSinglePixel)
|
|
|
|
context.SetDeviceColor(mSinglePixelColor);
|
|
|
|
else
|
|
|
|
context.SetSource(mOptSurface);
|
|
|
|
context.Paint();
|
|
|
|
|
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
|
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
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
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()
|
|
|
|
{
|
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
|
|
|
|
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
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t imgFrame::GetTimeout() 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
|
|
|
{
|
|
|
|
// Ensure a minimal time between updates so we don't throttle the UI thread.
|
|
|
|
// consider 0 == unspecified and make it fast but not too fast. See bug
|
|
|
|
// 125137, bug 139677, and bug 207059. The behavior of recent IE and Opera
|
|
|
|
// versions seems to be:
|
|
|
|
// IE 6/Win:
|
|
|
|
// 10 - 50ms go 100ms
|
|
|
|
// >50ms go correct speed
|
|
|
|
// Opera 7 final/Win:
|
|
|
|
// 10ms goes 100ms
|
|
|
|
// >10ms go correct speed
|
|
|
|
// It seems that there are broken tools out there that set a 0ms or 10ms
|
|
|
|
// timeout when they really want a "default" one. So munge values in that
|
|
|
|
// range.
|
|
|
|
if (mTimeout >= 0 && mTimeout <= 10)
|
|
|
|
return 100;
|
|
|
|
else
|
|
|
|
return mTimeout;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void imgFrame::SetTimeout(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
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
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()
|
|
|
|
{
|
|
|
|
if (mFormat == gfxASurface::ImageFormatARGB32) {
|
|
|
|
mFormat = gfxASurface::ImageFormatRGB24;
|
2011-10-17 07:59:28 -07:00
|
|
|
mFormatChanged = 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
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
imgFrame::SizeOfExcludingThisWithComputedFallbackIfHeap(gfxASurface::MemoryLocation aLocation, nsMallocSizeOfFun aMallocSizeOf) const
|
2010-05-21 21:10:14 -07:00
|
|
|
{
|
2012-02-19 19:51:48 -08:00
|
|
|
// aMallocSizeOf is only used if aLocation==MEMORY_IN_PROCESS_HEAP. It
|
|
|
|
// should be NULL otherwise.
|
|
|
|
NS_ABORT_IF_FALSE(
|
|
|
|
(aLocation == gfxASurface::MEMORY_IN_PROCESS_HEAP && aMallocSizeOf) ||
|
|
|
|
(aLocation != gfxASurface::MEMORY_IN_PROCESS_HEAP && !aMallocSizeOf),
|
|
|
|
"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
|
|
|
|
2011-07-18 06:20:27 -07:00
|
|
|
if (mPalettedImageData && aLocation == gfxASurface::MEMORY_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
|
|
|
}
|
|
|
|
|
2012-02-19 19:51:48 -08:00
|
|
|
// XXX: should pass aMallocSizeOf here. See bug 723827.
|
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
|
2011-07-18 06:20:27 -07:00
|
|
|
if (mQuartzSurface && aLocation == gfxASurface::MEMORY_IN_PROCESS_HEAP) {
|
2012-02-19 19:51:48 -08:00
|
|
|
n += mSize.width * mSize.height * 4;
|
2010-05-21 21:10:14 -07:00
|
|
|
} else
|
|
|
|
#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;
|
|
|
|
if (aLocation == gfxASurface::MEMORY_IN_PROCESS_HEAP) { // HEAP: measure
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-07-18 06:20:27 -07:00
|
|
|
if (mOptSurface && aLocation == mOptSurface->GetMemoryLocation()) {
|
2012-02-19 19:51:48 -08:00
|
|
|
n += mOptSurface->KnownMemoryUsed();
|
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
|
|
|
}
|