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"
|
2014-08-22 13:12:38 -07:00
|
|
|
#include "ImageRegion.h"
|
2014-09-23 15:32:19 -07:00
|
|
|
#include "ShutdownTracker.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
|
|
|
|
2013-03-18 07:25:50 -07:00
|
|
|
#include "GeckoProfiler.h"
|
2012-10-26 06:32:10 -07:00
|
|
|
#include "mozilla/Likely.h"
|
2014-11-27 19:55:57 -08:00
|
|
|
#include "MainThreadUtils.h"
|
2013-06-23 05:03:39 -07:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-09-06 19:15:49 -07:00
|
|
|
#include "nsMargin.h"
|
2015-01-08 00:04:31 -08:00
|
|
|
#include "nsThreadUtils.h"
|
2013-10-02 07:44:53 -07:00
|
|
|
#include "mozilla/CheckedInt.h"
|
2014-04-19 18:28:38 -07:00
|
|
|
#include "mozilla/gfx/Tools.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
|
|
|
|
2014-07-10 08:00:31 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
using namespace gfx;
|
|
|
|
|
|
|
|
namespace image {
|
2012-03-15 13:30:41 -07:00
|
|
|
|
2014-04-19 18:28:38 -07:00
|
|
|
static UserDataKey kVolatileBuffer;
|
2014-02-24 19:37:51 -08:00
|
|
|
|
|
|
|
static void
|
|
|
|
VolatileBufferRelease(void *vbuf)
|
|
|
|
{
|
|
|
|
delete static_cast<VolatileBufferPtr<unsigned char>*>(vbuf);
|
|
|
|
}
|
|
|
|
|
2014-06-10 12:44:04 -07:00
|
|
|
static int32_t
|
|
|
|
VolatileSurfaceStride(const IntSize& size, SurfaceFormat format)
|
|
|
|
{
|
|
|
|
// Stride must be a multiple of four or cairo will complain.
|
|
|
|
return (size.width * BytesPerPixel(format) + 0x3) & ~0x3;
|
|
|
|
}
|
|
|
|
|
2014-04-19 18:28:38 -07:00
|
|
|
static TemporaryRef<DataSourceSurface>
|
|
|
|
CreateLockedSurface(VolatileBuffer *vbuf,
|
|
|
|
const IntSize& size,
|
|
|
|
SurfaceFormat format)
|
2014-02-24 19:37:51 -08:00
|
|
|
{
|
|
|
|
VolatileBufferPtr<unsigned char> *vbufptr =
|
|
|
|
new VolatileBufferPtr<unsigned char>(vbuf);
|
|
|
|
MOZ_ASSERT(!vbufptr->WasBufferPurged(), "Expected image data!");
|
|
|
|
|
2014-06-10 12:44:04 -07:00
|
|
|
int32_t stride = VolatileSurfaceStride(size, format);
|
2014-04-19 18:28:38 -07:00
|
|
|
RefPtr<DataSourceSurface> surf =
|
|
|
|
Factory::CreateWrappingDataSourceSurface(*vbufptr, stride, size, format);
|
|
|
|
if (!surf) {
|
2014-02-24 19:37:51 -08:00
|
|
|
delete vbufptr;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-04-19 18:28:38 -07:00
|
|
|
surf->AddUserData(&kVolatileBuffer, vbufptr, VolatileBufferRelease);
|
|
|
|
return surf;
|
2014-02-24 19:37:51 -08:00
|
|
|
}
|
|
|
|
|
2014-04-19 18:28:38 -07:00
|
|
|
static TemporaryRef<VolatileBuffer>
|
|
|
|
AllocateBufferForImage(const IntSize& size, SurfaceFormat format)
|
2014-02-24 19:37:51 -08:00
|
|
|
{
|
2014-06-10 12:44:04 -07:00
|
|
|
int32_t stride = VolatileSurfaceStride(size, format);
|
2014-02-24 19:37:51 -08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-11-26 13:22:10 -08:00
|
|
|
static bool AllowedImageAndFrameDimensions(const nsIntSize& aImageSize,
|
|
|
|
const nsIntRect& aFrameRect)
|
|
|
|
{
|
|
|
|
if (!AllowedImageSize(aImageSize.width, aImageSize.height)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!AllowedImageSize(aFrameRect.width, aFrameRect.height)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
nsIntRect imageRect(0, 0, aImageSize.width, aImageSize.height);
|
|
|
|
if (!imageRect.Contains(aFrameRect)) {
|
2015-02-07 03:51:40 -08:00
|
|
|
NS_WARNING("Animated image frame does not fit inside bounds of image");
|
2014-11-26 13:22:10 -08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-08 00:04:31 -08:00
|
|
|
imgFrame::imgFrame()
|
2015-01-11 19:28:02 -08:00
|
|
|
: mMonitor("imgFrame")
|
2015-01-08 00:04:31 -08:00
|
|
|
, mDecoded(0, 0, 0, 0)
|
|
|
|
, mLockCount(0)
|
|
|
|
, mTimeout(100)
|
|
|
|
, mDisposalMethod(DisposalMethod::NOT_SPECIFIED)
|
|
|
|
, mBlendMethod(BlendMethod::OVER)
|
|
|
|
, mHasNoAlpha(false)
|
2015-01-11 19:28:02 -08:00
|
|
|
, mAborted(false)
|
2015-01-08 00:04:31 -08:00
|
|
|
, mPalettedImageData(nullptr)
|
|
|
|
, mPaletteDepth(0)
|
|
|
|
, mNonPremult(false)
|
|
|
|
, mSinglePixel(false)
|
|
|
|
, mCompositingFailed(false)
|
|
|
|
, mOptimizable(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()
|
|
|
|
{
|
2015-01-11 19:28:02 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
MOZ_ASSERT(mAborted || IsImageCompleteInternal());
|
|
|
|
#endif
|
|
|
|
|
2015-02-18 20:51:06 -08:00
|
|
|
free(mPalettedImageData);
|
2012-10-03 11:10:31 -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
|
|
|
}
|
|
|
|
|
2015-01-15 15:11:36 -08:00
|
|
|
nsresult
|
|
|
|
imgFrame::ReinitForDecoder(const nsIntSize& aImageSize,
|
|
|
|
const nsIntRect& aRect,
|
|
|
|
SurfaceFormat aFormat,
|
|
|
|
uint8_t aPaletteDepth /* = 0 */,
|
|
|
|
bool aNonPremult /* = false */)
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
|
|
|
|
if (mDecoded.x != 0 || mDecoded.y != 0 ||
|
|
|
|
mDecoded.width != 0 || mDecoded.height != 0) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Shouldn't reinit after write");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
if (mAborted) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Shouldn't reinit if aborted");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
if (mLockCount < 1) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Shouldn't reinit unless locked");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restore everything (except mLockCount, which we need to keep) to how it was
|
|
|
|
// when we were first created.
|
|
|
|
// XXX(seth): This is probably a little excessive, but I want to be *really*
|
|
|
|
// sure that nothing got missed.
|
|
|
|
mDecoded = nsIntRect(0, 0, 0, 0);
|
|
|
|
mTimeout = 100;
|
|
|
|
mDisposalMethod = DisposalMethod::NOT_SPECIFIED;
|
|
|
|
mBlendMethod = BlendMethod::OVER;
|
|
|
|
mHasNoAlpha = false;
|
|
|
|
mAborted = false;
|
|
|
|
mPaletteDepth = 0;
|
|
|
|
mNonPremult = false;
|
|
|
|
mSinglePixel = false;
|
|
|
|
mCompositingFailed = false;
|
|
|
|
mOptimizable = false;
|
|
|
|
mImageSize = IntSize();
|
|
|
|
mSize = IntSize();
|
|
|
|
mOffset = nsIntPoint();
|
|
|
|
mSinglePixelColor = Color();
|
|
|
|
|
|
|
|
// Release all surfaces.
|
|
|
|
mImageSurface = nullptr;
|
|
|
|
mOptSurface = nullptr;
|
|
|
|
mVBuf = nullptr;
|
|
|
|
mVBufPtr = nullptr;
|
2015-02-18 20:51:06 -08:00
|
|
|
free(mPalettedImageData);
|
2015-01-15 15:11:36 -08:00
|
|
|
mPalettedImageData = nullptr;
|
|
|
|
|
|
|
|
// Reinitialize.
|
|
|
|
nsresult rv = InitForDecoder(aImageSize, aRect, aFormat,
|
|
|
|
aPaletteDepth, aNonPremult);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We were locked before; perform the same actions we would've performed when
|
|
|
|
// we originally got locked.
|
|
|
|
if (mImageSurface) {
|
|
|
|
mVBufPtr = mVBuf;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mPalettedImageData) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("We got optimized somehow during reinit");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Paletted images don't have surfaces, so there's nothing to do.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-09-14 15:22:45 -07:00
|
|
|
nsresult
|
2014-11-26 13:22:10 -08:00
|
|
|
imgFrame::InitForDecoder(const nsIntSize& aImageSize,
|
|
|
|
const nsIntRect& aRect,
|
2014-09-14 15:22:45 -07:00
|
|
|
SurfaceFormat aFormat,
|
2015-01-08 00:04:31 -08:00
|
|
|
uint8_t aPaletteDepth /* = 0 */,
|
|
|
|
bool aNonPremult /* = 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
|
|
|
{
|
2014-09-14 15:22:45 -07:00
|
|
|
// Assert for properties that should be verified by decoders,
|
|
|
|
// warn for properties related to bad content.
|
2014-11-26 13:22:10 -08:00
|
|
|
if (!AllowedImageAndFrameDimensions(aImageSize, aRect)) {
|
2013-05-22 02:10:38 -07:00
|
|
|
NS_WARNING("Should have legal image size");
|
2015-01-11 19:28:02 -08:00
|
|
|
mAborted = 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_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
|
|
|
|
2015-03-29 07:59:08 -07:00
|
|
|
mImageSize = aImageSize;
|
2014-09-14 15:22:45 -07:00
|
|
|
mOffset.MoveTo(aRect.x, aRect.y);
|
|
|
|
mSize.SizeTo(aRect.width, aRect.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
|
|
|
|
|
|
|
mFormat = aFormat;
|
|
|
|
mPaletteDepth = aPaletteDepth;
|
2015-01-08 00:04:31 -08:00
|
|
|
mNonPremult = aNonPremult;
|
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 (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");
|
2015-01-11 19:28:02 -08:00
|
|
|
mAborted = 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_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-01-08 00:04:31 -08:00
|
|
|
// Use the fallible allocator here. Paletted images always use 1 byte per
|
|
|
|
// pixel, so calculating the amount of memory we need is straightforward.
|
|
|
|
mPalettedImageData =
|
2015-02-18 20:51:06 -08:00
|
|
|
static_cast<uint8_t*>(malloc(PaletteDataLength() +
|
|
|
|
(mSize.width * mSize.height)));
|
2013-05-22 02:10:38 -07:00
|
|
|
if (!mPalettedImageData)
|
2015-02-18 20:51:06 -08:00
|
|
|
NS_WARNING("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 {
|
2014-09-14 15:22:45 -07:00
|
|
|
MOZ_ASSERT(!mImageSurface, "Called imgFrame::InitForDecoder() twice?");
|
|
|
|
|
|
|
|
mVBuf = AllocateBufferForImage(mSize, mFormat);
|
|
|
|
if (!mVBuf) {
|
2015-01-11 19:28:02 -08:00
|
|
|
mAborted = true;
|
2014-09-14 15:22:45 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2014-02-24 19:37:51 -08:00
|
|
|
}
|
2014-09-14 15:22:45 -07:00
|
|
|
if (mVBuf->OnHeap()) {
|
|
|
|
int32_t stride = VolatileSurfaceStride(mSize, mFormat);
|
|
|
|
VolatileBufferPtr<uint8_t> ptr(mVBuf);
|
|
|
|
memset(ptr, 0, stride * mSize.height);
|
|
|
|
}
|
|
|
|
mImageSurface = CreateLockedSurface(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
|
|
|
|
2014-04-19 18:28:38 -07:00
|
|
|
if (!mImageSurface) {
|
|
|
|
NS_WARNING("Failed to create VolatileDataSourceSurface");
|
2015-01-11 19:28:02 -08:00
|
|
|
mAborted = 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_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2014-09-14 15:22:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
imgFrame::InitWithDrawable(gfxDrawable* aDrawable,
|
|
|
|
const nsIntSize& aSize,
|
|
|
|
const SurfaceFormat aFormat,
|
|
|
|
GraphicsFilter aFilter,
|
|
|
|
uint32_t aImageFlags)
|
|
|
|
{
|
|
|
|
// Assert for properties that should be verified by decoders,
|
|
|
|
// warn for properties related to bad content.
|
|
|
|
if (!AllowedImageSize(aSize.width, aSize.height)) {
|
|
|
|
NS_WARNING("Should have legal image size");
|
2015-01-11 19:28:02 -08:00
|
|
|
mAborted = true;
|
2014-09-14 15:22:45 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-03-29 07:59:08 -07:00
|
|
|
mImageSize = aSize;
|
2014-09-14 15:22:45 -07:00
|
|
|
mOffset.MoveTo(0, 0);
|
|
|
|
mSize.SizeTo(aSize.width, aSize.height);
|
|
|
|
|
|
|
|
mFormat = aFormat;
|
|
|
|
mPaletteDepth = 0;
|
|
|
|
|
|
|
|
RefPtr<DrawTarget> target;
|
|
|
|
|
|
|
|
bool canUseDataSurface =
|
|
|
|
gfxPlatform::GetPlatform()->CanRenderContentToDataSurface();
|
|
|
|
|
|
|
|
if (canUseDataSurface) {
|
|
|
|
// It's safe to use data surfaces for content on this platform, so we can
|
|
|
|
// get away with using volatile buffers.
|
|
|
|
MOZ_ASSERT(!mImageSurface, "Called imgFrame::InitWithDrawable() twice?");
|
|
|
|
|
|
|
|
mVBuf = AllocateBufferForImage(mSize, mFormat);
|
|
|
|
if (!mVBuf) {
|
2015-01-11 19:28:02 -08:00
|
|
|
mAborted = true;
|
2014-09-14 15:22:45 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t stride = VolatileSurfaceStride(mSize, mFormat);
|
|
|
|
VolatileBufferPtr<uint8_t> ptr(mVBuf);
|
|
|
|
if (!ptr) {
|
2015-01-11 19:28:02 -08:00
|
|
|
mAborted = true;
|
2014-09-14 15:22:45 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
if (mVBuf->OnHeap()) {
|
|
|
|
memset(ptr, 0, stride * mSize.height);
|
|
|
|
}
|
|
|
|
mImageSurface = CreateLockedSurface(mVBuf, mSize, mFormat);
|
|
|
|
|
|
|
|
target = gfxPlatform::GetPlatform()->
|
|
|
|
CreateDrawTargetForData(ptr, mSize, stride, mFormat);
|
|
|
|
} else {
|
|
|
|
// We can't use data surfaces for content, so we'll create an offscreen
|
|
|
|
// surface instead. This means if someone later calls RawAccessRef(), we
|
|
|
|
// may have to do an expensive readback, but we warned callers about that in
|
|
|
|
// the documentation for this method.
|
|
|
|
MOZ_ASSERT(!mOptSurface, "Called imgFrame::InitWithDrawable() twice?");
|
|
|
|
|
|
|
|
target = gfxPlatform::GetPlatform()->
|
|
|
|
CreateOffscreenContentDrawTarget(mSize, mFormat);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!target) {
|
2015-01-11 19:28:02 -08:00
|
|
|
mAborted = true;
|
2014-09-14 15:22:45 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw using the drawable the caller provided.
|
|
|
|
nsIntRect imageRect(0, 0, mSize.width, mSize.height);
|
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(target);
|
2015-03-29 07:59:15 -07:00
|
|
|
gfxUtils::DrawPixelSnapped(ctx, aDrawable, mSize,
|
2014-09-14 15:22:45 -07:00
|
|
|
ImageRegion::Create(imageRect),
|
|
|
|
mFormat, aFilter, aImageFlags);
|
|
|
|
|
|
|
|
if (canUseDataSurface && !mImageSurface) {
|
|
|
|
NS_WARNING("Failed to create VolatileDataSourceSurface");
|
2015-01-11 19:28:02 -08:00
|
|
|
mAborted = true;
|
2014-09-14 15:22:45 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!canUseDataSurface) {
|
|
|
|
// We used an offscreen surface, which is an "optimized" surface from
|
|
|
|
// imgFrame's perspective.
|
|
|
|
mOptSurface = target->Snapshot();
|
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
|
|
|
}
|
|
|
|
|
2015-01-11 19:28:02 -08:00
|
|
|
// If we reach this point, we should regard ourselves as complete.
|
|
|
|
mDecoded = GetRect();
|
|
|
|
MOZ_ASSERT(IsImageComplete());
|
|
|
|
|
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());
|
2015-01-11 19:28:02 -08:00
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
2014-09-18 19:26:01 -07:00
|
|
|
MOZ_ASSERT(mLockCount == 1,
|
|
|
|
"Should only optimize when holding the lock exclusively");
|
2013-05-24 06:52:34 -07:00
|
|
|
|
2014-09-23 15:32:19 -07:00
|
|
|
// Don't optimize during shutdown because gfxPlatform may not be available.
|
|
|
|
if (ShutdownTracker::ShutdownHasStarted())
|
|
|
|
return NS_OK;
|
|
|
|
|
2014-09-18 19:26:01 -07:00
|
|
|
if (!mOptimizable || gDisableOptimize)
|
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 (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 */
|
|
|
|
|
2015-01-27 17:43:21 -08:00
|
|
|
if (gfxPrefs::ImageSingleColorOptimizationEnabled() &&
|
|
|
|
mImageSurface->Stride() == mSize.width * 4) {
|
2014-04-19 18:28:38 -07:00
|
|
|
uint32_t *imgData = (uint32_t*) ((uint8_t *)mVBufPtr);
|
2012-08-22 08:56:38 -07:00
|
|
|
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-04-19 18:28:38 -07:00
|
|
|
if (mFormat == SurfaceFormat::B8G8R8A8 ||
|
|
|
|
mFormat == SurfaceFormat::B8G8R8X8) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mSinglePixel = true;
|
2014-04-19 18:28:38 -07:00
|
|
|
mSinglePixelColor.a = ((firstPixel >> 24) & 0xFF) * (1.0f / 255.0f);
|
|
|
|
mSinglePixelColor.r = ((firstPixel >> 16) & 0xFF) * (1.0f / 255.0f);
|
|
|
|
mSinglePixelColor.g = ((firstPixel >> 8) & 0xFF) * (1.0f / 255.0f);
|
|
|
|
mSinglePixelColor.b = ((firstPixel >> 0) & 0xFF) * (1.0f / 255.0f);
|
|
|
|
mSinglePixelColor.r /= mSinglePixelColor.a;
|
|
|
|
mSinglePixelColor.g /= mSinglePixelColor.a;
|
|
|
|
mSinglePixelColor.b /= mSinglePixelColor.a;
|
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;
|
2014-04-19 18:28:38 -07:00
|
|
|
mVBufPtr = nullptr;
|
2012-07-30 07:20:58 -07:00
|
|
|
mImageSurface = nullptr;
|
|
|
|
mOptSurface = nullptr;
|
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
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if it's not RGB24/ARGB32, don't optimize, but we never hit this at the moment
|
|
|
|
}
|
|
|
|
|
2014-02-25 02:57:41 -08:00
|
|
|
#ifdef ANDROID
|
2014-04-19 18:28:38 -07:00
|
|
|
SurfaceFormat optFormat =
|
|
|
|
gfxPlatform::GetPlatform()->Optimal2DFormatForContent(gfxContentType::COLOR);
|
2014-02-25 02:57:41 -08:00
|
|
|
|
2015-01-08 00:04:31 -08:00
|
|
|
if (mFormat != SurfaceFormat::B8G8R8A8 &&
|
|
|
|
optFormat == SurfaceFormat::R5G6B5) {
|
2014-02-25 02:57:41 -08:00
|
|
|
RefPtr<VolatileBuffer> buf =
|
2014-04-19 18:28:38 -07:00
|
|
|
AllocateBufferForImage(mSize, optFormat);
|
2014-02-25 02:57:41 -08:00
|
|
|
if (!buf)
|
|
|
|
return NS_OK;
|
|
|
|
|
2014-04-19 18:28:38 -07:00
|
|
|
RefPtr<DataSourceSurface> surf =
|
|
|
|
CreateLockedSurface(buf, mSize, optFormat);
|
|
|
|
if (!surf)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2014-02-25 02:57:41 -08:00
|
|
|
|
2014-04-19 18:28:38 -07:00
|
|
|
DataSourceSurface::MappedSurface mapping;
|
|
|
|
DebugOnly<bool> success =
|
|
|
|
surf->Map(DataSourceSurface::MapType::WRITE, &mapping);
|
|
|
|
NS_ASSERTION(success, "Failed to map surface");
|
|
|
|
RefPtr<DrawTarget> target =
|
|
|
|
Factory::CreateDrawTargetForData(BackendType::CAIRO,
|
|
|
|
mapping.mData,
|
|
|
|
mSize,
|
|
|
|
mapping.mStride,
|
|
|
|
optFormat);
|
|
|
|
|
2015-03-09 12:48:20 -07:00
|
|
|
if (!target) {
|
|
|
|
gfxWarning() << "imgFrame::Optimize failed in CreateDrawTargetForData";
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2014-04-19 18:28:38 -07:00
|
|
|
Rect rect(0, 0, mSize.width, mSize.height);
|
|
|
|
target->DrawSurface(mImageSurface, rect, rect);
|
|
|
|
target->Flush();
|
|
|
|
surf->Unmap();
|
2014-02-25 02:57:41 -08:00
|
|
|
|
|
|
|
mImageSurface = surf;
|
|
|
|
mVBuf = buf;
|
|
|
|
mFormat = optFormat;
|
|
|
|
}
|
|
|
|
#else
|
2014-04-19 18:28:38 -07:00
|
|
|
mOptSurface = gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget()->OptimizeSourceSurface(mImageSurface);
|
|
|
|
if (mOptSurface == mImageSurface)
|
|
|
|
mOptSurface = nullptr;
|
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;
|
2014-04-19 18:28:38 -07:00
|
|
|
mVBufPtr = 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
|
|
|
}
|
|
|
|
|
2014-09-18 19:26:01 -07:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2014-09-23 16:17:35 -07:00
|
|
|
// On Android, free mImageSurface unconditionally if we're discardable. This
|
|
|
|
// allows the operating system to free our volatile buffer.
|
2014-09-18 19:26:01 -07:00
|
|
|
// XXX(seth): We'd eventually like to do this on all platforms, but right now
|
2014-09-23 16:17:35 -07:00
|
|
|
// converting raw memory to a SourceSurface is expensive on some backends.
|
2014-11-26 13:22:10 -08:00
|
|
|
mImageSurface = nullptr;
|
2014-09-18 19:26:01 -07: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
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-09-10 17:06:45 -07:00
|
|
|
DrawableFrameRef
|
|
|
|
imgFrame::DrawableRef()
|
|
|
|
{
|
|
|
|
return DrawableFrameRef(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
RawAccessFrameRef
|
|
|
|
imgFrame::RawAccessRef()
|
|
|
|
{
|
|
|
|
return RawAccessFrameRef(this);
|
|
|
|
}
|
|
|
|
|
2015-01-07 01:40:23 -08:00
|
|
|
void
|
|
|
|
imgFrame::SetRawAccessOnly()
|
|
|
|
{
|
2015-01-08 00:04:31 -08:00
|
|
|
AssertImageDataLocked();
|
|
|
|
|
2015-01-07 01:40:23 -08:00
|
|
|
// Lock our data and throw away the key.
|
|
|
|
LockImageData();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-13 06:30:02 -07:00
|
|
|
imgFrame::SurfaceWithFormat
|
2011-09-28 23:19:26 -07:00
|
|
|
imgFrame::SurfaceForDrawing(bool aDoPadding,
|
|
|
|
bool aDoPartialDecode,
|
|
|
|
bool aDoTile,
|
2014-08-22 13:12:38 -07:00
|
|
|
gfxContext* aContext,
|
2010-08-13 06:30:02 -07:00
|
|
|
const nsIntMargin& aPadding,
|
2014-03-02 08:17:26 -08:00
|
|
|
gfxRect& aImageRect,
|
2014-08-22 13:12:38 -07:00
|
|
|
ImageRegion& aRegion,
|
2014-04-19 18:28:38 -07:00
|
|
|
SourceSurface* aSurface)
|
2010-08-13 06:30:02 -07:00
|
|
|
{
|
2015-01-08 00:04:31 -08:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-11 19:28:02 -08:00
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
2015-01-08 00:04:31 -08: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");
|
2015-03-29 07:59:15 -07:00
|
|
|
return SurfaceWithFormat(new gfxSurfaceDrawable(aSurface, 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-04-19 18:28:38 -07:00
|
|
|
RefPtr<DrawTarget> target =
|
|
|
|
gfxPlatform::GetPlatform()->
|
|
|
|
CreateOffscreenContentDrawTarget(size, SurfaceFormat::B8G8R8A8);
|
|
|
|
if (!target)
|
2010-08-13 06:30:02 -07:00
|
|
|
return SurfaceWithFormat();
|
|
|
|
|
|
|
|
// Fill 'available' with whatever we've got
|
|
|
|
if (mSinglePixel) {
|
2014-09-10 13:04:28 -07:00
|
|
|
target->FillRect(ToRect(aRegion.Intersect(available).Rect()),
|
|
|
|
ColorPattern(mSinglePixelColor),
|
2014-04-19 18:28:38 -07:00
|
|
|
DrawOptions(1.0f, CompositionOp::OP_SOURCE));
|
2010-08-13 06:30:02 -07:00
|
|
|
} else {
|
2014-04-19 18:28:38 -07:00
|
|
|
SurfacePattern pattern(aSurface,
|
|
|
|
ExtendMode::REPEAT,
|
2014-09-18 12:53:02 -07:00
|
|
|
Matrix::Translation(mDecoded.x, mDecoded.y));
|
2014-09-10 13:04:28 -07:00
|
|
|
target->FillRect(ToRect(aRegion.Intersect(available).Rect()), pattern);
|
2010-08-13 06:30:02 -07:00
|
|
|
}
|
2012-03-23 15:10:50 -07:00
|
|
|
|
2014-04-19 18:28:38 -07:00
|
|
|
RefPtr<SourceSurface> newsurf = target->Snapshot();
|
2015-03-29 07:59:15 -07:00
|
|
|
return SurfaceWithFormat(new gfxSurfaceDrawable(newsurf, size), target->GetFormat());
|
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.
|
2014-08-22 13:12:38 -07:00
|
|
|
gfxPoint paddingTopLeft(aPadding.left, aPadding.top);
|
|
|
|
aRegion = aRegion.Intersect(available) - paddingTopLeft;
|
|
|
|
aContext->Multiply(gfxMatrix::Translation(paddingTopLeft));
|
2010-08-13 06:30:02 -07:00
|
|
|
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-08-22 13:12:38 -07:00
|
|
|
bool imgFrame::Draw(gfxContext* aContext, const ImageRegion& aRegion,
|
2014-11-26 13:22:10 -08:00
|
|
|
GraphicsFilter aFilter, 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
|
|
|
{
|
2014-05-23 14:12:29 -07:00
|
|
|
PROFILER_LABEL("imgFrame", "Draw",
|
|
|
|
js::ProfileEntry::Category::GRAPHICS);
|
|
|
|
|
2015-01-08 00:04:31 -08:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-08-22 13:12:38 -07:00
|
|
|
NS_ASSERTION(!aRegion.Rect().IsEmpty(), "Drawing empty region!");
|
|
|
|
NS_ASSERTION(!aRegion.IsRestricted() ||
|
|
|
|
!aRegion.Rect().Intersect(aRegion.Restriction()).IsEmpty(),
|
|
|
|
"We must be allowed to sample *some* source pixels!");
|
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(!mPalettedImageData, "Directly drawing a paletted image!");
|
|
|
|
|
2015-01-11 19:28:02 -08:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2015-01-08 00:04:31 -08:00
|
|
|
|
2014-11-26 13:22:10 -08:00
|
|
|
nsIntMargin padding(mOffset.y,
|
|
|
|
mImageSize.width - (mOffset.x + mSize.width),
|
|
|
|
mImageSize.height - (mOffset.y + mSize.height),
|
|
|
|
mOffset.x);
|
|
|
|
|
|
|
|
bool doPadding = padding != nsIntMargin(0,0,0,0);
|
2015-01-11 19:28:02 -08:00
|
|
|
bool doPartialDecode = !IsImageCompleteInternal();
|
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) {
|
2014-04-19 18:28:38 -07:00
|
|
|
if (mSinglePixelColor.a == 0.0) {
|
|
|
|
return true;
|
|
|
|
}
|
2014-06-09 23:02:22 -07:00
|
|
|
RefPtr<DrawTarget> dt = aContext->GetDrawTarget();
|
2014-08-22 13:12:38 -07:00
|
|
|
dt->FillRect(ToRect(aRegion.Rect()),
|
2014-06-09 23:02:22 -07:00
|
|
|
ColorPattern(mSinglePixelColor),
|
|
|
|
DrawOptions(1.0f,
|
|
|
|
CompositionOpForOp(aContext->CurrentOperator())));
|
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
|
|
|
}
|
|
|
|
|
2015-01-08 00:04:31 -08:00
|
|
|
RefPtr<SourceSurface> surf = GetSurfaceInternal();
|
2014-09-10 13:04:28 -07:00
|
|
|
if (!surf && !mSinglePixel) {
|
2014-04-19 18:28:38 -07:00
|
|
|
return false;
|
2014-03-02 08:17:26 -08:00
|
|
|
}
|
|
|
|
|
2014-11-26 13:22:10 -08:00
|
|
|
gfxRect imageRect(0, 0, mImageSize.width, mImageSize.height);
|
2014-08-22 13:12:38 -07:00
|
|
|
bool doTile = !imageRect.Contains(aRegion.Rect()) &&
|
2012-04-17 15:04:15 -07:00
|
|
|
!(aImageFlags & imgIContainer::FLAG_CLAMP);
|
2014-08-22 13:12:38 -07:00
|
|
|
ImageRegion region(aRegion);
|
2014-09-29 10:26:31 -07:00
|
|
|
// SurfaceForDrawing changes the current transform, and we need it to still
|
|
|
|
// be changed when we call gfxUtils::DrawPixelSnapped. We still need to
|
|
|
|
// restore it before returning though.
|
|
|
|
// XXXjwatt In general having functions require someone further up the stack
|
|
|
|
// to undo transform changes that they make is bad practice. We should
|
|
|
|
// change how this code works.
|
|
|
|
gfxContextMatrixAutoSaveRestore autoSR(aContext);
|
2010-08-13 06:30:02 -07:00
|
|
|
SurfaceWithFormat surfaceResult =
|
2014-08-22 13:12:38 -07:00
|
|
|
SurfaceForDrawing(doPadding, doPartialDecode, doTile, aContext,
|
2014-11-26 13:22:10 -08:00
|
|
|
padding, imageRect, region, 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,
|
2014-08-22 13:12:38 -07:00
|
|
|
imageRect.Size(), region, 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
|
|
|
}
|
|
|
|
|
2015-01-08 00:04:31 -08:00
|
|
|
nsresult
|
|
|
|
imgFrame::ImageUpdated(const nsIntRect& aUpdateRect)
|
|
|
|
{
|
2015-01-11 19:28:02 -08:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2015-01-08 00:04:31 -08:00
|
|
|
return ImageUpdatedInternal(aUpdateRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
imgFrame::ImageUpdatedInternal(const nsIntRect& aUpdateRect)
|
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
|
|
|
{
|
2015-01-11 19:28:02 -08:00
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
2013-07-04 11:45:57 -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
|
|
|
mDecoded.UnionRect(mDecoded, aUpdateRect);
|
|
|
|
|
|
|
|
// clamp to bounds, in case someone sends a bogus updateRect (I'm looking at
|
|
|
|
// you, gif decoder)
|
2014-04-19 18:28:38 -07:00
|
|
|
nsIntRect boundsRect(mOffset, nsIntSize(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
|
|
|
mDecoded.IntersectRect(mDecoded, boundsRect);
|
|
|
|
|
2015-01-11 19:28:02 -08:00
|
|
|
// If the image is now complete, wake up anyone who's waiting.
|
|
|
|
if (IsImageCompleteInternal()) {
|
|
|
|
mMonitor.NotifyAll();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-01-08 00:04:31 -08:00
|
|
|
void
|
2015-01-11 19:28:02 -08:00
|
|
|
imgFrame::Finish(Opacity aFrameOpacity /* = Opacity::SOME_TRANSPARENCY */,
|
|
|
|
DisposalMethod aDisposalMethod /* = DisposalMethod::KEEP */,
|
|
|
|
int32_t aRawTimeout /* = 0 */,
|
|
|
|
BlendMethod aBlendMethod /* = BlendMethod::OVER */)
|
2015-01-08 00:04:31 -08:00
|
|
|
{
|
2015-01-11 19:28:02 -08:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2015-01-08 00:04:31 -08:00
|
|
|
MOZ_ASSERT(mLockCount > 0, "Image data should be locked");
|
|
|
|
|
|
|
|
if (aFrameOpacity == Opacity::OPAQUE) {
|
|
|
|
mHasNoAlpha = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDisposalMethod = aDisposalMethod;
|
|
|
|
mTimeout = aRawTimeout;
|
|
|
|
mBlendMethod = aBlendMethod;
|
|
|
|
ImageUpdatedInternal(GetRect());
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
2014-04-19 18:28:38 -07:00
|
|
|
return nsIntRect(mOffset, nsIntSize(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
|
|
|
}
|
|
|
|
|
2014-08-22 13:49:54 -07:00
|
|
|
int32_t
|
|
|
|
imgFrame::GetStride() const
|
|
|
|
{
|
2015-01-11 19:28:02 -08:00
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
2015-01-08 00:04:31 -08:00
|
|
|
|
2014-08-22 13:49:54 -07:00
|
|
|
if (mImageSurface) {
|
|
|
|
return mImageSurface->Stride();
|
|
|
|
}
|
|
|
|
|
|
|
|
return VolatileSurfaceStride(mSize, mFormat);
|
|
|
|
}
|
|
|
|
|
2014-04-19 18:28:38 -07:00
|
|
|
SurfaceFormat 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
|
|
|
{
|
2015-01-11 19:28:02 -08:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2015-01-11 19:28:02 -08:00
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
2015-01-08 00:04:31 -08:00
|
|
|
|
2014-02-24 19:37:51 -08:00
|
|
|
if (mVBuf)
|
2014-04-19 18:28:38 -07:00
|
|
|
return mSize.width * BytesPerPixel(mFormat);
|
2014-02-24 19:37:51 -08:00
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-01-08 00:04:31 -08:00
|
|
|
void
|
|
|
|
imgFrame::GetImageData(uint8_t** aData, uint32_t* aLength) 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
|
|
|
{
|
2015-01-11 19:28:02 -08:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2015-01-08 00:04:31 -08:00
|
|
|
GetImageDataInternal(aData, aLength);
|
|
|
|
}
|
2012-09-26 08:33:06 -07:00
|
|
|
|
2015-01-08 00:04:31 -08:00
|
|
|
void
|
|
|
|
imgFrame::GetImageDataInternal(uint8_t** aData, uint32_t* aLength) const
|
|
|
|
{
|
2015-01-11 19:28:02 -08:00
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
2015-01-08 00:04:31 -08:00
|
|
|
MOZ_ASSERT(mLockCount > 0, "Image data should be locked");
|
|
|
|
|
|
|
|
if (mImageSurface) {
|
2014-04-19 18:28:38 -07:00
|
|
|
*aData = mVBufPtr;
|
2015-01-08 00:04:31 -08:00
|
|
|
MOZ_ASSERT(*aData, "mImageSurface is non-null, but mVBufPtr is null in GetImageData");
|
|
|
|
} else if (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
|
|
|
*aData = mPalettedImageData + PaletteDataLength();
|
2015-01-08 00:04:31 -08:00
|
|
|
MOZ_ASSERT(*aData, "mPalettedImageData is non-null, but result is null in GetImageData");
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(false, "Have neither mImageSurface nor mPalettedImageData in GetImageData");
|
2012-07-30 07:20:58 -07:00
|
|
|
*aData = nullptr;
|
2015-01-08 00:04:31 -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
|
|
|
|
2015-01-08 00:04:31 -08:00
|
|
|
*aLength = 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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2015-01-08 00:04:31 -08:00
|
|
|
AssertImageDataLocked();
|
2012-09-26 08:33:06 -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
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-01-08 00:04:31 -08:00
|
|
|
nsresult
|
|
|
|
imgFrame::LockImageData()
|
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
|
|
|
{
|
2015-01-11 19:28:02 -08:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2013-05-24 06:52:34 -07:00
|
|
|
|
2015-01-08 00:04:31 -08:00
|
|
|
MOZ_ASSERT(mLockCount >= 0, "Unbalanced locks and unlocks");
|
2012-09-26 08:33:06 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-01-08 00:04:31 -08:00
|
|
|
// If we're the first lock, but have an image surface, we're OK.
|
|
|
|
if (mImageSurface) {
|
|
|
|
mVBufPtr = mVBuf;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-26 08:33:06 -07:00
|
|
|
// Paletted images don't have surfaces, so there's nothing to do.
|
2015-01-08 00:04:31 -08:00
|
|
|
if (mPalettedImageData) {
|
2012-09-26 08:33:06 -07:00
|
|
|
return NS_OK;
|
2015-01-08 00:04:31 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return Deoptimize();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
imgFrame::Deoptimize()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-11 19:28:02 -08:00
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
2015-01-08 00:04:31 -08:00
|
|
|
MOZ_ASSERT(!mImageSurface);
|
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;
|
|
|
|
|
2014-04-19 18:28:38 -07:00
|
|
|
mImageSurface = CreateLockedSurface(mVBuf, mSize, mFormat);
|
|
|
|
if (!mImageSurface)
|
2014-02-24 19:37:51 -08:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2014-02-25 02:57:41 -08:00
|
|
|
}
|
2014-04-19 18:28:38 -07:00
|
|
|
if (mOptSurface || mSinglePixel || mFormat == SurfaceFormat::R5G6B5) {
|
|
|
|
SurfaceFormat format = mFormat;
|
|
|
|
if (mFormat == SurfaceFormat::R5G6B5)
|
|
|
|
format = SurfaceFormat::B8G8R8A8;
|
2014-02-25 02:57:41 -08:00
|
|
|
|
2014-02-24 19:37:51 -08:00
|
|
|
// Recover the pixels
|
2014-02-25 02:57:41 -08:00
|
|
|
RefPtr<VolatileBuffer> buf =
|
2014-04-19 18:28:38 -07:00
|
|
|
AllocateBufferForImage(mSize, format);
|
2014-02-25 02:57:41 -08:00
|
|
|
if (!buf) {
|
2014-02-24 19:37:51 -08:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2014-04-19 18:28:38 -07:00
|
|
|
RefPtr<DataSourceSurface> surf =
|
|
|
|
CreateLockedSurface(buf, mSize, format);
|
|
|
|
if (!surf)
|
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-04-19 18:28:38 -07:00
|
|
|
DataSourceSurface::MappedSurface mapping;
|
|
|
|
DebugOnly<bool> success =
|
|
|
|
surf->Map(DataSourceSurface::MapType::WRITE, &mapping);
|
|
|
|
NS_ASSERTION(success, "Failed to map surface");
|
|
|
|
RefPtr<DrawTarget> target =
|
|
|
|
Factory::CreateDrawTargetForData(BackendType::CAIRO,
|
|
|
|
mapping.mData,
|
|
|
|
mSize,
|
|
|
|
mapping.mStride,
|
|
|
|
format);
|
2015-03-09 12:48:20 -07:00
|
|
|
if (!target) {
|
|
|
|
gfxWarning() << "imgFrame::Deoptimize failed in CreateDrawTargetForData";
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2014-04-19 18:28:38 -07:00
|
|
|
|
|
|
|
Rect rect(0, 0, mSize.width, mSize.height);
|
2014-02-24 19:37:51 -08:00
|
|
|
if (mSinglePixel)
|
2014-04-19 18:28:38 -07:00
|
|
|
target->FillRect(rect, ColorPattern(mSinglePixelColor),
|
|
|
|
DrawOptions(1.0f, CompositionOp::OP_SOURCE));
|
|
|
|
else if (mFormat == SurfaceFormat::R5G6B5)
|
|
|
|
target->DrawSurface(mImageSurface, rect, rect);
|
2014-02-24 19:37:51 -08:00
|
|
|
else
|
2014-04-19 18:28:38 -07:00
|
|
|
target->DrawSurface(mOptSurface, rect, rect,
|
|
|
|
DrawSurfaceOptions(),
|
|
|
|
DrawOptions(1.0f, CompositionOp::OP_SOURCE));
|
|
|
|
target->Flush();
|
|
|
|
surf->Unmap();
|
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
|
|
|
}
|
|
|
|
|
2014-04-19 18:28:38 -07:00
|
|
|
mVBufPtr = mVBuf;
|
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;
|
|
|
|
}
|
|
|
|
|
2015-01-08 00:04:31 -08:00
|
|
|
void
|
|
|
|
imgFrame::AssertImageDataLocked() 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
|
|
|
{
|
2015-01-08 00:04:31 -08:00
|
|
|
#ifdef DEBUG
|
2015-01-11 19:28:02 -08:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2015-01-08 00:04:31 -08:00
|
|
|
MOZ_ASSERT(mLockCount > 0, "Image data should be locked");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
class UnlockImageDataRunnable : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2015-01-08 01:28:21 -08:00
|
|
|
explicit UnlockImageDataRunnable(imgFrame* aTarget)
|
2015-01-08 00:04:31 -08:00
|
|
|
: mTarget(aTarget)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mTarget);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() { return mTarget->UnlockImageData(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsRefPtr<imgFrame> mTarget;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
imgFrame::UnlockImageData()
|
|
|
|
{
|
2015-01-11 19:28:02 -08:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2013-05-24 06:52:34 -07:00
|
|
|
|
2014-09-18 19:26:01 -07:00
|
|
|
MOZ_ASSERT(mLockCount > 0, "Unlocking an unlocked image!");
|
|
|
|
if (mLockCount <= 0) {
|
2012-09-26 08:33:06 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-01-11 19:28:02 -08:00
|
|
|
MOZ_ASSERT(mLockCount > 1 || IsImageCompleteInternal() || mAborted,
|
|
|
|
"Should have marked complete or aborted before unlocking");
|
|
|
|
|
2014-09-18 19:26:01 -07:00
|
|
|
// If we're about to become unlocked, we don't need to hold on to our data
|
|
|
|
// surface anymore. (But we don't need to do anything for paletted images,
|
|
|
|
// which don't have surfaces.)
|
|
|
|
if (mLockCount == 1 && !mPalettedImageData) {
|
2015-01-08 00:04:31 -08:00
|
|
|
// We can't safely optimize off-main-thread, so create a runnable to do it.
|
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
nsCOMPtr<nsIRunnable> runnable = new UnlockImageDataRunnable(this);
|
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-09-23 15:43:03 -07:00
|
|
|
// If we're using a surface format with alpha but the image has no alpha,
|
|
|
|
// change the format. This doesn't change the underlying data at all, but
|
|
|
|
// allows DrawTargets to avoid blending when drawing known opaque images.
|
|
|
|
if (mHasNoAlpha && mFormat == SurfaceFormat::B8G8R8A8 && mImageSurface) {
|
|
|
|
mFormat = SurfaceFormat::B8G8R8X8;
|
|
|
|
mImageSurface = CreateLockedSurface(mVBuf, mSize, mFormat);
|
|
|
|
}
|
|
|
|
|
2014-09-18 19:26:01 -07:00
|
|
|
// Convert the data surface to a GPU surface or a single color if possible.
|
|
|
|
// This will also release mImageSurface if possible.
|
|
|
|
Optimize();
|
|
|
|
|
|
|
|
// Allow the OS to release our data surface.
|
|
|
|
mVBufPtr = nullptr;
|
2012-09-26 08:33:06 -07:00
|
|
|
}
|
|
|
|
|
2014-09-18 19:26:01 -07:00
|
|
|
mLockCount--;
|
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
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-09-18 19:26:01 -07:00
|
|
|
void
|
|
|
|
imgFrame::SetOptimizable()
|
|
|
|
{
|
2015-01-08 00:04:31 -08:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
AssertImageDataLocked();
|
2014-09-18 19:26:01 -07:00
|
|
|
mOptimizable = true;
|
2014-02-24 19:37:51 -08:00
|
|
|
}
|
|
|
|
|
2015-01-08 00:04:31 -08:00
|
|
|
Color
|
|
|
|
imgFrame::SinglePixelColor() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
return mSinglePixelColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
imgFrame::IsSinglePixel() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
return mSinglePixel;
|
|
|
|
}
|
|
|
|
|
2014-04-19 18:28:38 -07:00
|
|
|
TemporaryRef<SourceSurface>
|
|
|
|
imgFrame::GetSurface()
|
|
|
|
{
|
2015-01-11 19:28:02 -08:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2015-01-08 00:04:31 -08:00
|
|
|
return GetSurfaceInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
TemporaryRef<SourceSurface>
|
|
|
|
imgFrame::GetSurfaceInternal()
|
|
|
|
{
|
2015-01-11 19:28:02 -08:00
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
2015-01-08 00:04:31 -08:00
|
|
|
|
2014-04-19 18:28:38 -07:00
|
|
|
if (mOptSurface) {
|
|
|
|
if (mOptSurface->IsValid())
|
|
|
|
return mOptSurface;
|
|
|
|
else
|
|
|
|
mOptSurface = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mImageSurface)
|
|
|
|
return mImageSurface;
|
|
|
|
|
|
|
|
if (!mVBuf)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
VolatileBufferPtr<char> buf(mVBuf);
|
|
|
|
if (buf.WasBufferPurged())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return CreateLockedSurface(mVBuf, mSize, mFormat);
|
|
|
|
}
|
|
|
|
|
2014-08-22 13:49:54 -07:00
|
|
|
TemporaryRef<DrawTarget>
|
|
|
|
imgFrame::GetDrawTarget()
|
|
|
|
{
|
2015-01-11 19:28:02 -08:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2014-08-22 13:49:54 -07:00
|
|
|
|
2015-01-08 00:04:31 -08:00
|
|
|
uint8_t* data;
|
|
|
|
uint32_t length;
|
|
|
|
GetImageDataInternal(&data, &length);
|
2014-08-22 13:49:54 -07:00
|
|
|
if (!data) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t stride = GetStride();
|
|
|
|
return gfxPlatform::GetPlatform()->
|
|
|
|
CreateDrawTargetForData(data, mSize, stride, mFormat);
|
|
|
|
}
|
|
|
|
|
2015-01-08 00:04:31 -08:00
|
|
|
AnimationData
|
|
|
|
imgFrame::GetAnimationData() 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
|
|
|
{
|
2015-01-11 19:28:02 -08:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2015-01-08 00:04:31 -08:00
|
|
|
MOZ_ASSERT(mLockCount > 0, "Image data should be 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
|
|
|
|
2015-01-08 00:04:31 -08:00
|
|
|
uint8_t* data;
|
|
|
|
if (mPalettedImageData) {
|
|
|
|
data = mPalettedImageData;
|
|
|
|
} else {
|
|
|
|
uint32_t length;
|
|
|
|
GetImageDataInternal(&data, &length);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasAlpha = mFormat == SurfaceFormat::B8G8R8A8;
|
|
|
|
|
|
|
|
return AnimationData(data, PaletteDataLength(), mTimeout, GetRect(),
|
|
|
|
mBlendMethod, mDisposalMethod, hasAlpha);
|
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
|
|
|
}
|
|
|
|
|
2015-01-08 00:04:31 -08:00
|
|
|
ScalingData
|
|
|
|
imgFrame::GetScalingData() 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
|
|
|
{
|
2015-01-11 19:28:02 -08:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2015-01-08 00:04:31 -08:00
|
|
|
MOZ_ASSERT(mLockCount > 0, "Image data should be locked");
|
|
|
|
MOZ_ASSERT(!GetIsPaletted(), "GetScalingData can't handle paletted images");
|
2013-07-15 11:38:59 -07:00
|
|
|
|
2015-01-08 00:04:31 -08:00
|
|
|
uint8_t* data;
|
|
|
|
uint32_t length;
|
|
|
|
GetImageDataInternal(&data, &length);
|
|
|
|
|
|
|
|
return ScalingData(data, mSize, GetImageBytesPerRow(), 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
|
|
|
}
|
|
|
|
|
2015-01-11 19:28:02 -08:00
|
|
|
void
|
|
|
|
imgFrame::Abort()
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
|
|
|
|
mAborted = true;
|
|
|
|
|
|
|
|
// Wake up anyone who's waiting.
|
2015-01-15 15:11:36 -08:00
|
|
|
mMonitor.NotifyAll();
|
2015-01-11 19:28:02 -08:00
|
|
|
}
|
|
|
|
|
2015-01-08 00:04:31 -08:00
|
|
|
bool
|
2015-01-11 19:28:02 -08:00
|
|
|
imgFrame::IsImageComplete() 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
|
|
|
{
|
2015-01-11 19:28:02 -08:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
return IsImageCompleteInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
imgFrame::WaitUntilComplete() const
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
// Return if we're aborted or complete.
|
|
|
|
if (mAborted || IsImageCompleteInternal()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not complete yet, so we'll have to wait.
|
|
|
|
mMonitor.Wait();
|
|
|
|
}
|
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
|
|
|
|
2015-01-08 00:04:31 -08:00
|
|
|
bool
|
2015-01-11 19:28:02 -08:00
|
|
|
imgFrame::IsImageCompleteInternal() const
|
2012-03-23 15:10:50 -07:00
|
|
|
{
|
2015-01-11 19:28:02 -08:00
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
2015-01-08 00:04:31 -08:00
|
|
|
return mDecoded.IsEqualInterior(nsIntRect(mOffset.x, mOffset.y,
|
|
|
|
mSize.width, mSize.height));
|
2012-03-23 15:10:50 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool imgFrame::GetCompositingFailed() const
|
2009-11-12 15:18:40 -08:00
|
|
|
{
|
2015-01-08 00:04:31 -08:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
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
|
|
|
{
|
2015-01-08 00:04:31 -08:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2009-11-12 15:18:40 -08:00
|
|
|
mCompositingFailed = val;
|
|
|
|
}
|
2010-03-12 02:08:25 -08:00
|
|
|
|
2012-02-19 19:51:48 -08:00
|
|
|
size_t
|
2014-11-26 18:00:15 -08:00
|
|
|
imgFrame::SizeOfExcludingThis(gfxMemoryLocation aLocation,
|
|
|
|
MallocSizeOf aMallocSizeOf) const
|
2010-05-21 21:10:14 -07:00
|
|
|
{
|
2015-01-11 19:28:02 -08:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2015-01-08 00:04:31 -08: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.
|
2015-02-09 14:34:50 -08:00
|
|
|
MOZ_ASSERT(
|
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) {
|
2014-11-26 18:00:15 -08:00
|
|
|
n += aMallocSizeOf(mPalettedImageData);
|
2010-05-21 21:10:14 -07:00
|
|
|
}
|
2014-04-19 18:28:38 -07:00
|
|
|
if (mImageSurface && aLocation == gfxMemoryLocation::IN_PROCESS_HEAP) {
|
|
|
|
n += aMallocSizeOf(mImageSurface);
|
2014-02-24 19:37:51 -08:00
|
|
|
}
|
2014-04-19 18:28:38 -07:00
|
|
|
if (mOptSurface && aLocation == gfxMemoryLocation::IN_PROCESS_HEAP) {
|
|
|
|
n += aMallocSizeOf(mOptSurface);
|
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);
|
|
|
|
}
|
|
|
|
|
2014-04-14 22:24:01 -07:00
|
|
|
if (mVBuf && aLocation == gfxMemoryLocation::IN_PROCESS_NONHEAP) {
|
|
|
|
n += mVBuf->NonHeapSizeOfExcludingThis();
|
|
|
|
}
|
|
|
|
|
2012-02-19 19:51:48 -08:00
|
|
|
return n;
|
2010-05-21 21:10:14 -07:00
|
|
|
}
|
2014-07-10 08:00:31 -07:00
|
|
|
|
|
|
|
} // namespace image
|
|
|
|
} // namespace mozilla
|