2012-12-19 09:59:30 +04: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 15:12:37 +04: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-21 05:50:15 +04:00
|
|
|
|
|
|
|
#include "imgFrame.h"
|
2014-08-23 00:12:38 +04:00
|
|
|
#include "ImageRegion.h"
|
2014-09-24 02:32:19 +04: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-21 05:50:15 +04:00
|
|
|
|
|
|
|
#include "prenv.h"
|
|
|
|
|
2014-02-09 12:04:38 +04: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-21 05:50:15 +04:00
|
|
|
#include "gfxPlatform.h"
|
2010-08-13 17:30:02 +04:00
|
|
|
#include "gfxUtils.h"
|
2014-02-25 07:37:51 +04: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-21 05:50:15 +04:00
|
|
|
|
2011-09-29 10:19:26 +04: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-21 05:50:15 +04:00
|
|
|
|
2013-03-18 18:25:50 +04:00
|
|
|
#include "GeckoProfiler.h"
|
2012-10-26 17:32:10 +04:00
|
|
|
#include "mozilla/Likely.h"
|
2014-11-28 06:55:57 +03:00
|
|
|
#include "MainThreadUtils.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-09-07 06:15:49 +04:00
|
|
|
#include "nsMargin.h"
|
2015-01-08 11:04:31 +03:00
|
|
|
#include "nsThreadUtils.h"
|
2013-10-02 18:44:53 +04:00
|
|
|
#include "mozilla/CheckedInt.h"
|
2014-04-20 05:28:38 +04: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-21 05:50:15 +04:00
|
|
|
|
2014-07-10 19:00:31 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
using namespace gfx;
|
|
|
|
|
|
|
|
namespace image {
|
2012-03-16 00:30:41 +04:00
|
|
|
|
2014-04-20 05:28:38 +04:00
|
|
|
static UserDataKey kVolatileBuffer;
|
2014-02-25 07:37:51 +04:00
|
|
|
|
|
|
|
static void
|
2015-03-31 20:48:00 +03:00
|
|
|
VolatileBufferRelease(void* vbuf)
|
2014-02-25 07:37:51 +04:00
|
|
|
{
|
|
|
|
delete static_cast<VolatileBufferPtr<unsigned char>*>(vbuf);
|
|
|
|
}
|
|
|
|
|
2014-06-10 23:44:04 +04: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;
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
static already_AddRefed<DataSourceSurface>
|
2015-03-31 20:48:00 +03:00
|
|
|
CreateLockedSurface(VolatileBuffer* vbuf,
|
2014-04-20 05:28:38 +04:00
|
|
|
const IntSize& size,
|
|
|
|
SurfaceFormat format)
|
2014-02-25 07:37:51 +04:00
|
|
|
{
|
2015-03-31 20:48:00 +03:00
|
|
|
VolatileBufferPtr<unsigned char>* vbufptr =
|
2014-02-25 07:37:51 +04:00
|
|
|
new VolatileBufferPtr<unsigned char>(vbuf);
|
|
|
|
MOZ_ASSERT(!vbufptr->WasBufferPurged(), "Expected image data!");
|
|
|
|
|
2014-06-10 23:44:04 +04:00
|
|
|
int32_t stride = VolatileSurfaceStride(size, format);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DataSourceSurface> surf =
|
2014-04-20 05:28:38 +04:00
|
|
|
Factory::CreateWrappingDataSourceSurface(*vbufptr, stride, size, format);
|
|
|
|
if (!surf) {
|
2014-02-25 07:37:51 +04:00
|
|
|
delete vbufptr;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-04-20 05:28:38 +04:00
|
|
|
surf->AddUserData(&kVolatileBuffer, vbufptr, VolatileBufferRelease);
|
2015-05-01 16:14:16 +03:00
|
|
|
return surf.forget();
|
2014-02-25 07:37:51 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
static already_AddRefed<VolatileBuffer>
|
2014-04-20 05:28:38 +04:00
|
|
|
AllocateBufferForImage(const IntSize& size, SurfaceFormat format)
|
2014-02-25 07:37:51 +04:00
|
|
|
{
|
2014-06-10 23:44:04 +04:00
|
|
|
int32_t stride = VolatileSurfaceStride(size, format);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<VolatileBuffer> buf = new VolatileBuffer();
|
2014-02-25 07:37:51 +04:00
|
|
|
if (buf->Init(stride * size.height,
|
2015-03-31 20:48:00 +03:00
|
|
|
1 << gfxAlphaRecovery::GoodAlignmentLog2())) {
|
2015-05-01 16:14:16 +03:00
|
|
|
return buf.forget();
|
2015-03-31 20:48:00 +03:00
|
|
|
}
|
2014-02-25 07:37:51 +04:00
|
|
|
|
|
|
|
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-21 05:50:15 +04:00
|
|
|
// Returns true if an image of aWidth x aHeight is allowed and legal.
|
2015-03-31 20:48:00 +03: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-21 05:50:15 +04:00
|
|
|
{
|
|
|
|
// reject over-wide or over-tall images
|
2012-08-22 19:56:38 +04:00
|
|
|
const int32_t k64KLimit = 0x0000FFFF;
|
2012-10-26 17:32:10 +04: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-21 05:50:15 +04:00
|
|
|
NS_WARNING("image too big");
|
2011-10-17 18:59:28 +04: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-21 05:50:15 +04:00
|
|
|
}
|
|
|
|
|
2011-07-01 21:03:47 +04:00
|
|
|
// protect against invalid sizes
|
2012-10-26 17:32:10 +04:00
|
|
|
if (MOZ_UNLIKELY(aHeight <= 0 || aWidth <= 0)) {
|
2011-10-17 18:59:28 +04: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-21 05:50:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// check to make sure we don't overflow a 32-bit
|
2013-10-02 18:44:53 +04: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-21 05:50:15 +04:00
|
|
|
NS_WARNING("width or height too large");
|
2011-10-17 18:59:28 +04: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-21 05:50:15 +04:00
|
|
|
}
|
|
|
|
#if defined(XP_MACOSX)
|
2015-03-31 20:48:00 +03:00
|
|
|
// CoreGraphics is limited to images < 32K in *height*, so clamp all surfaces
|
|
|
|
// on the Mac to that height
|
2012-10-26 17:32:10 +04: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-21 05:50:15 +04:00
|
|
|
NS_WARNING("image too big");
|
2011-10-17 18:59:28 +04: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-21 05:50:15 +04:00
|
|
|
}
|
|
|
|
#endif
|
2011-10-17 18:59:28 +04: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-21 05:50:15 +04:00
|
|
|
}
|
|
|
|
|
2014-11-27 00:22:10 +03: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 14:51:40 +03:00
|
|
|
NS_WARNING("Animated image frame does not fit inside bounds of image");
|
2014-11-27 00:22:10 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-08 11:04:31 +03:00
|
|
|
imgFrame::imgFrame()
|
2015-01-12 06:28:02 +03:00
|
|
|
: mMonitor("imgFrame")
|
2015-01-08 11:04:31 +03:00
|
|
|
, mDecoded(0, 0, 0, 0)
|
|
|
|
, mLockCount(0)
|
|
|
|
, mTimeout(100)
|
|
|
|
, mDisposalMethod(DisposalMethod::NOT_SPECIFIED)
|
|
|
|
, mBlendMethod(BlendMethod::OVER)
|
|
|
|
, mHasNoAlpha(false)
|
2015-01-12 06:28:02 +03:00
|
|
|
, mAborted(false)
|
2015-07-31 17:29:10 +03:00
|
|
|
, mOptimizable(false)
|
2015-01-08 11:04:31 +03:00
|
|
|
, mPalettedImageData(nullptr)
|
|
|
|
, mPaletteDepth(0)
|
|
|
|
, mNonPremult(false)
|
|
|
|
, mSinglePixel(false)
|
|
|
|
, mCompositingFailed(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-21 05:50:15 +04:00
|
|
|
{
|
2011-09-29 10:19:26 +04: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-21 05:50:15 +04:00
|
|
|
if (!hasCheckedOptimize) {
|
|
|
|
if (PR_GetEnv("MOZ_DISABLE_IMAGE_OPTIMIZE")) {
|
2011-10-17 18:59:28 +04: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-21 05:50:15 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04: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-21 05:50:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
imgFrame::~imgFrame()
|
|
|
|
{
|
2015-01-12 06:28:02 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
MOZ_ASSERT(mAborted || IsImageCompleteInternal());
|
|
|
|
#endif
|
|
|
|
|
2015-02-19 07:51:06 +03:00
|
|
|
free(mPalettedImageData);
|
2012-10-03 22:10:31 +04: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-21 05:50:15 +04:00
|
|
|
}
|
|
|
|
|
2014-09-15 02:22:45 +04:00
|
|
|
nsresult
|
2014-11-27 00:22:10 +03:00
|
|
|
imgFrame::InitForDecoder(const nsIntSize& aImageSize,
|
|
|
|
const nsIntRect& aRect,
|
2014-09-15 02:22:45 +04:00
|
|
|
SurfaceFormat aFormat,
|
2015-01-08 11:04:31 +03: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-21 05:50:15 +04:00
|
|
|
{
|
2014-09-15 02:22:45 +04:00
|
|
|
// Assert for properties that should be verified by decoders,
|
|
|
|
// warn for properties related to bad content.
|
2014-11-27 00:22:10 +03:00
|
|
|
if (!AllowedImageAndFrameDimensions(aImageSize, aRect)) {
|
2013-05-22 13:10:38 +04:00
|
|
|
NS_WARNING("Should have legal image size");
|
2015-01-12 06:28:02 +03: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-21 05:50:15 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2013-05-22 13:10:38 +04: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-21 05:50:15 +04:00
|
|
|
|
2015-03-29 17:59:08 +03:00
|
|
|
mImageSize = aImageSize;
|
2014-09-15 02:22:45 +04: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-21 05:50:15 +04:00
|
|
|
|
|
|
|
mFormat = aFormat;
|
|
|
|
mPaletteDepth = aPaletteDepth;
|
2015-01-08 11:04:31 +03: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-21 05:50:15 +04:00
|
|
|
|
|
|
|
if (aPaletteDepth != 0) {
|
|
|
|
// We're creating for a paletted image.
|
|
|
|
if (aPaletteDepth > 8) {
|
2013-05-22 13:10:38 +04:00
|
|
|
NS_WARNING("Should have legal palette depth");
|
2010-06-18 00:28:38 +04:00
|
|
|
NS_ERROR("This Depth is not supported");
|
2015-01-12 06:28:02 +03: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-21 05:50:15 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-01-08 11:04:31 +03: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-19 07:51:06 +03:00
|
|
|
static_cast<uint8_t*>(malloc(PaletteDataLength() +
|
|
|
|
(mSize.width * mSize.height)));
|
2015-03-31 20:48:00 +03:00
|
|
|
if (!mPalettedImageData) {
|
2015-02-19 07:51:06 +03:00
|
|
|
NS_WARNING("malloc for paletted image data should succeed");
|
2015-03-31 20:48:00 +03: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-21 05:50:15 +04:00
|
|
|
NS_ENSURE_TRUE(mPalettedImageData, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
} else {
|
2014-09-15 02:22:45 +04:00
|
|
|
MOZ_ASSERT(!mImageSurface, "Called imgFrame::InitForDecoder() twice?");
|
|
|
|
|
|
|
|
mVBuf = AllocateBufferForImage(mSize, mFormat);
|
|
|
|
if (!mVBuf) {
|
2015-01-12 06:28:02 +03:00
|
|
|
mAborted = true;
|
2014-09-15 02:22:45 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2014-02-25 07:37:51 +04:00
|
|
|
}
|
2014-09-15 02:22:45 +04: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-21 05:50:15 +04:00
|
|
|
|
2014-04-20 05:28:38 +04:00
|
|
|
if (!mImageSurface) {
|
|
|
|
NS_WARNING("Failed to create VolatileDataSourceSurface");
|
2015-01-12 06:28:02 +03: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-21 05:50:15 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2014-09-15 02:22:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
imgFrame::InitWithDrawable(gfxDrawable* aDrawable,
|
|
|
|
const nsIntSize& aSize,
|
|
|
|
const SurfaceFormat aFormat,
|
2015-10-06 03:18:10 +03:00
|
|
|
Filter aFilter,
|
2014-09-15 02:22:45 +04:00
|
|
|
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-12 06:28:02 +03:00
|
|
|
mAborted = true;
|
2014-09-15 02:22:45 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-03-29 17:59:08 +03:00
|
|
|
mImageSize = aSize;
|
2014-09-15 02:22:45 +04:00
|
|
|
mOffset.MoveTo(0, 0);
|
|
|
|
mSize.SizeTo(aSize.width, aSize.height);
|
|
|
|
|
|
|
|
mFormat = aFormat;
|
|
|
|
mPaletteDepth = 0;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DrawTarget> target;
|
2014-09-15 02:22:45 +04:00
|
|
|
|
|
|
|
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-12 06:28:02 +03:00
|
|
|
mAborted = true;
|
2014-09-15 02:22:45 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t stride = VolatileSurfaceStride(mSize, mFormat);
|
|
|
|
VolatileBufferPtr<uint8_t> ptr(mVBuf);
|
|
|
|
if (!ptr) {
|
2015-01-12 06:28:02 +03:00
|
|
|
mAborted = true;
|
2014-09-15 02:22:45 +04: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()->
|
2015-03-31 20:48:00 +03:00
|
|
|
CreateOffscreenContentDrawTarget(mSize, mFormat);
|
2014-09-15 02:22:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!target) {
|
2015-01-12 06:28:02 +03:00
|
|
|
mAborted = true;
|
2014-09-15 02:22:45 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw using the drawable the caller provided.
|
|
|
|
nsIntRect imageRect(0, 0, mSize.width, mSize.height);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxContext> ctx = new gfxContext(target);
|
2015-03-29 17:59:15 +03:00
|
|
|
gfxUtils::DrawPixelSnapped(ctx, aDrawable, mSize,
|
2015-11-12 01:23:14 +03:00
|
|
|
ImageRegion::Create(ThebesRect(imageRect)),
|
2014-09-15 02:22:45 +04:00
|
|
|
mFormat, aFilter, aImageFlags);
|
|
|
|
|
|
|
|
if (canUseDataSurface && !mImageSurface) {
|
|
|
|
NS_WARNING("Failed to create VolatileDataSourceSurface");
|
2015-01-12 06:28:02 +03:00
|
|
|
mAborted = true;
|
2014-09-15 02:22:45 +04: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-21 05:50:15 +04:00
|
|
|
}
|
|
|
|
|
2015-01-12 06:28:02 +03: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-21 05:50:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-31 20:48:00 +03:00
|
|
|
nsresult
|
|
|
|
imgFrame::Optimize()
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
{
|
2013-05-24 17:52:34 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-12 06:28:02 +03:00
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
2014-09-19 06:26:01 +04:00
|
|
|
MOZ_ASSERT(mLockCount == 1,
|
|
|
|
"Should only optimize when holding the lock exclusively");
|
2013-05-24 17:52:34 +04:00
|
|
|
|
2014-09-24 02:32:19 +04:00
|
|
|
// Don't optimize during shutdown because gfxPlatform may not be available.
|
2015-03-31 20:48:00 +03:00
|
|
|
if (ShutdownTracker::ShutdownHasStarted()) {
|
2014-09-24 02:32:19 +04:00
|
|
|
return NS_OK;
|
2015-03-31 20:48:00 +03:00
|
|
|
}
|
2014-09-24 02:32:19 +04:00
|
|
|
|
2015-03-31 20:48:00 +03: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-21 05:50:15 +04:00
|
|
|
return NS_OK;
|
2015-03-31 20:48:00 +03: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-21 05:50:15 +04:00
|
|
|
|
2015-03-31 20:48:00 +03:00
|
|
|
if (mPalettedImageData || mOptSurface || mSinglePixel) {
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
return NS_OK;
|
2015-03-31 20:48:00 +03: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-21 05:50:15 +04:00
|
|
|
|
2012-03-24 02:10:50 +04:00
|
|
|
// Don't do single-color opts on non-premult data.
|
|
|
|
// Cairo doesn't support non-premult single-colors.
|
2015-03-31 20:48:00 +03:00
|
|
|
if (mNonPremult) {
|
2012-03-24 02:10:50 +04:00
|
|
|
return NS_OK;
|
2015-03-31 20:48:00 +03:00
|
|
|
}
|
2012-03-24 02:10:50 +04: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-21 05:50:15 +04:00
|
|
|
/* Figure out if the entire image is a constant color */
|
|
|
|
|
2015-01-28 04:43:21 +03:00
|
|
|
if (gfxPrefs::ImageSingleColorOptimizationEnabled() &&
|
|
|
|
mImageSurface->Stride() == mSize.width * 4) {
|
2015-03-31 20:48:00 +03:00
|
|
|
uint32_t* imgData = (uint32_t*) ((uint8_t*) mVBufPtr);
|
2012-08-22 19:56:38 +04: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-21 05:50:15 +04:00
|
|
|
|
|
|
|
while (--pixelCount && *imgData++ == firstPixel)
|
|
|
|
;
|
|
|
|
|
|
|
|
if (pixelCount == 0) {
|
|
|
|
// all pixels were the same
|
2014-04-20 05:28:38 +04:00
|
|
|
if (mFormat == SurfaceFormat::B8G8R8A8 ||
|
|
|
|
mFormat == SurfaceFormat::B8G8R8X8) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mSinglePixel = true;
|
2014-04-20 05:28:38 +04: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-21 05:50:15 +04:00
|
|
|
|
|
|
|
// blow away the older surfaces (if they exist), to release their memory
|
2014-02-25 07:37:51 +04:00
|
|
|
mVBuf = nullptr;
|
2014-04-20 05:28:38 +04:00
|
|
|
mVBufPtr = nullptr;
|
2012-07-30 18:20:58 +04:00
|
|
|
mImageSurface = nullptr;
|
|
|
|
mOptSurface = nullptr;
|
2012-03-16 00:30:41 +04: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-21 05:50:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-31 20:48:00 +03:00
|
|
|
// if it's not RGB24/ARGB32, don't optimize, but we never hit this at the
|
|
|
|
// moment
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
}
|
|
|
|
|
2014-02-25 14:57:41 +04:00
|
|
|
#ifdef ANDROID
|
2015-03-31 20:48:00 +03:00
|
|
|
SurfaceFormat optFormat = gfxPlatform::GetPlatform()
|
|
|
|
->Optimal2DFormatForContent(gfxContentType::COLOR);
|
2014-02-25 14:57:41 +04:00
|
|
|
|
2015-01-08 11:04:31 +03:00
|
|
|
if (mFormat != SurfaceFormat::B8G8R8A8 &&
|
2015-10-23 09:01:31 +03:00
|
|
|
optFormat == SurfaceFormat::R5G6B5_UINT16) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<VolatileBuffer> buf =
|
2014-04-20 05:28:38 +04:00
|
|
|
AllocateBufferForImage(mSize, optFormat);
|
2015-03-31 20:48:00 +03:00
|
|
|
if (!buf) {
|
2014-02-25 14:57:41 +04:00
|
|
|
return NS_OK;
|
2015-03-31 20:48:00 +03:00
|
|
|
}
|
2014-02-25 14:57:41 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DataSourceSurface> surf =
|
2014-04-20 05:28:38 +04:00
|
|
|
CreateLockedSurface(buf, mSize, optFormat);
|
2015-03-31 20:48:00 +03:00
|
|
|
if (!surf) {
|
2014-04-20 05:28:38 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2015-03-31 20:48:00 +03:00
|
|
|
}
|
2014-02-25 14:57:41 +04:00
|
|
|
|
2014-04-20 05:28:38 +04:00
|
|
|
DataSourceSurface::MappedSurface mapping;
|
2015-06-11 20:06:23 +03:00
|
|
|
if (!surf->Map(DataSourceSurface::MapType::WRITE, &mapping)) {
|
|
|
|
gfxCriticalError() << "imgFrame::Optimize failed to map surface";
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DrawTarget> target =
|
2014-04-20 05:28:38 +04:00
|
|
|
Factory::CreateDrawTargetForData(BackendType::CAIRO,
|
|
|
|
mapping.mData,
|
|
|
|
mSize,
|
|
|
|
mapping.mStride,
|
|
|
|
optFormat);
|
|
|
|
|
2015-03-09 22:48:20 +03:00
|
|
|
if (!target) {
|
|
|
|
gfxWarning() << "imgFrame::Optimize failed in CreateDrawTargetForData";
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2014-04-20 05:28:38 +04:00
|
|
|
Rect rect(0, 0, mSize.width, mSize.height);
|
|
|
|
target->DrawSurface(mImageSurface, rect, rect);
|
|
|
|
target->Flush();
|
|
|
|
surf->Unmap();
|
2014-02-25 14:57:41 +04:00
|
|
|
|
|
|
|
mImageSurface = surf;
|
|
|
|
mVBuf = buf;
|
|
|
|
mFormat = optFormat;
|
|
|
|
}
|
|
|
|
#else
|
2015-03-31 20:48:00 +03:00
|
|
|
mOptSurface = gfxPlatform::GetPlatform()
|
|
|
|
->ScreenReferenceDrawTarget()->OptimizeSourceSurface(mImageSurface);
|
|
|
|
if (mOptSurface == mImageSurface) {
|
2014-04-20 05:28:38 +04:00
|
|
|
mOptSurface = nullptr;
|
2015-03-31 20:48:00 +03:00
|
|
|
}
|
2014-02-25 14:57:41 +04: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-21 05:50:15 +04:00
|
|
|
|
|
|
|
if (mOptSurface) {
|
2014-02-25 07:37:51 +04:00
|
|
|
mVBuf = nullptr;
|
2014-04-20 05:28:38 +04:00
|
|
|
mVBufPtr = nullptr;
|
2012-07-30 18:20:58 +04: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-21 05:50:15 +04:00
|
|
|
}
|
|
|
|
|
2014-09-19 06:26:01 +04:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2014-09-24 03:17:35 +04:00
|
|
|
// On Android, free mImageSurface unconditionally if we're discardable. This
|
|
|
|
// allows the operating system to free our volatile buffer.
|
2014-09-19 06:26:01 +04:00
|
|
|
// XXX(seth): We'd eventually like to do this on all platforms, but right now
|
2014-09-24 03:17:35 +04:00
|
|
|
// converting raw memory to a SourceSurface is expensive on some backends.
|
2014-11-27 00:22:10 +03:00
|
|
|
mImageSurface = nullptr;
|
2014-09-19 06:26:01 +04: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-21 05:50:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-09-11 04:06:45 +04:00
|
|
|
DrawableFrameRef
|
|
|
|
imgFrame::DrawableRef()
|
|
|
|
{
|
|
|
|
return DrawableFrameRef(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
RawAccessFrameRef
|
|
|
|
imgFrame::RawAccessRef()
|
|
|
|
{
|
|
|
|
return RawAccessFrameRef(this);
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:40:23 +03:00
|
|
|
void
|
|
|
|
imgFrame::SetRawAccessOnly()
|
|
|
|
{
|
2015-01-08 11:04:31 +03:00
|
|
|
AssertImageDataLocked();
|
|
|
|
|
2015-01-07 12:40:23 +03:00
|
|
|
// Lock our data and throw away the key.
|
|
|
|
LockImageData();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-13 17:30:02 +04:00
|
|
|
imgFrame::SurfaceWithFormat
|
2011-09-29 10:19:26 +04:00
|
|
|
imgFrame::SurfaceForDrawing(bool aDoPadding,
|
|
|
|
bool aDoPartialDecode,
|
|
|
|
bool aDoTile,
|
2014-08-23 00:12:38 +04:00
|
|
|
gfxContext* aContext,
|
2010-08-13 17:30:02 +04:00
|
|
|
const nsIntMargin& aPadding,
|
2014-03-02 20:17:26 +04:00
|
|
|
gfxRect& aImageRect,
|
2014-08-23 00:12:38 +04:00
|
|
|
ImageRegion& aRegion,
|
2014-04-20 05:28:38 +04:00
|
|
|
SourceSurface* aSurface)
|
2010-08-13 17:30:02 +04:00
|
|
|
{
|
2015-01-08 11:04:31 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-12 06:28:02 +03:00
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
2015-01-08 11:04:31 +03:00
|
|
|
|
2014-02-09 12:04:38 +04:00
|
|
|
IntSize size(int32_t(aImageRect.Width()), int32_t(aImageRect.Height()));
|
2010-08-13 17:30:02 +04:00
|
|
|
if (!aDoPadding && !aDoPartialDecode) {
|
|
|
|
NS_ASSERTION(!mSinglePixel, "This should already have been handled");
|
2015-03-29 17:59:15 +03:00
|
|
|
return SurfaceWithFormat(new gfxSurfaceDrawable(aSurface, size), mFormat);
|
2010-08-13 17:30:02 +04:00
|
|
|
}
|
|
|
|
|
2015-03-31 20:48:00 +03:00
|
|
|
gfxRect available = gfxRect(mDecoded.x, mDecoded.y, mDecoded.width,
|
|
|
|
mDecoded.height);
|
2010-08-13 17:30:02 +04:00
|
|
|
|
|
|
|
if (aDoTile || mSinglePixel) {
|
|
|
|
// Create a temporary surface.
|
|
|
|
// Give this surface an alpha channel because there are
|
|
|
|
// transparent pixels in the padding or undecoded area
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DrawTarget> target =
|
2014-04-20 05:28:38 +04:00
|
|
|
gfxPlatform::GetPlatform()->
|
|
|
|
CreateOffscreenContentDrawTarget(size, SurfaceFormat::B8G8R8A8);
|
2015-03-31 20:48:00 +03:00
|
|
|
if (!target) {
|
2010-08-13 17:30:02 +04:00
|
|
|
return SurfaceWithFormat();
|
2015-03-31 20:48:00 +03:00
|
|
|
}
|
2010-08-13 17:30:02 +04:00
|
|
|
|
|
|
|
// Fill 'available' with whatever we've got
|
|
|
|
if (mSinglePixel) {
|
2014-09-11 00:04:28 +04:00
|
|
|
target->FillRect(ToRect(aRegion.Intersect(available).Rect()),
|
|
|
|
ColorPattern(mSinglePixelColor),
|
2014-04-20 05:28:38 +04:00
|
|
|
DrawOptions(1.0f, CompositionOp::OP_SOURCE));
|
2010-08-13 17:30:02 +04:00
|
|
|
} else {
|
2014-04-20 05:28:38 +04:00
|
|
|
SurfacePattern pattern(aSurface,
|
2015-11-23 19:17:35 +03:00
|
|
|
aRegion.GetExtendMode(),
|
2014-09-18 23:53:02 +04:00
|
|
|
Matrix::Translation(mDecoded.x, mDecoded.y));
|
2014-09-11 00:04:28 +04:00
|
|
|
target->FillRect(ToRect(aRegion.Intersect(available).Rect()), pattern);
|
2010-08-13 17:30:02 +04:00
|
|
|
}
|
2012-03-24 02:10:50 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurface> newsurf = target->Snapshot();
|
2015-03-31 20:48:00 +03:00
|
|
|
return SurfaceWithFormat(new gfxSurfaceDrawable(newsurf, size),
|
|
|
|
target->GetFormat());
|
2010-08-13 17:30:02 +04: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-23 00:12:38 +04:00
|
|
|
gfxPoint paddingTopLeft(aPadding.left, aPadding.top);
|
|
|
|
aRegion = aRegion.Intersect(available) - paddingTopLeft;
|
|
|
|
aContext->Multiply(gfxMatrix::Translation(paddingTopLeft));
|
2010-08-13 17:30:02 +04:00
|
|
|
aImageRect = gfxRect(0, 0, mSize.width, mSize.height);
|
|
|
|
|
2015-09-23 21:49:05 +03:00
|
|
|
IntSize availableSize(mDecoded.width, mDecoded.height);
|
2014-03-02 20:17:26 +04:00
|
|
|
return SurfaceWithFormat(new gfxSurfaceDrawable(aSurface, availableSize),
|
2010-08-13 17:30:27 +04: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-21 05:50:15 +04:00
|
|
|
}
|
|
|
|
|
2014-08-23 00:12:38 +04:00
|
|
|
bool imgFrame::Draw(gfxContext* aContext, const ImageRegion& aRegion,
|
2015-10-06 03:18:10 +03:00
|
|
|
Filter 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-21 05:50:15 +04:00
|
|
|
{
|
2014-05-24 01:12:29 +04:00
|
|
|
PROFILER_LABEL("imgFrame", "Draw",
|
|
|
|
js::ProfileEntry::Category::GRAPHICS);
|
|
|
|
|
2015-01-08 11:04:31 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-08-23 00:12:38 +04: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-21 05:50:15 +04:00
|
|
|
NS_ASSERTION(!mPalettedImageData, "Directly drawing a paletted image!");
|
|
|
|
|
2015-01-12 06:28:02 +03:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2015-01-08 11:04:31 +03:00
|
|
|
|
2014-11-27 00:22:10 +03: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-12 06:28:02 +03: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-21 05:50:15 +04:00
|
|
|
|
2010-08-13 17:30:02 +04:00
|
|
|
if (mSinglePixel && !doPadding && !doPartialDecode) {
|
2014-04-20 05:28:38 +04:00
|
|
|
if (mSinglePixelColor.a == 0.0) {
|
|
|
|
return true;
|
|
|
|
}
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DrawTarget> dt = aContext->GetDrawTarget();
|
2014-08-23 00:12:38 +04:00
|
|
|
dt->FillRect(ToRect(aRegion.Rect()),
|
2014-06-10 10:02:22 +04:00
|
|
|
ColorPattern(mSinglePixelColor),
|
2015-09-25 08:38:58 +03:00
|
|
|
DrawOptions(1.0f, aContext->CurrentOp()));
|
2014-03-02 20:17:26 +04: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-21 05:50:15 +04:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurface> surf = GetSurfaceInternal();
|
2014-09-11 00:04:28 +04:00
|
|
|
if (!surf && !mSinglePixel) {
|
2014-04-20 05:28:38 +04:00
|
|
|
return false;
|
2014-03-02 20:17:26 +04:00
|
|
|
}
|
|
|
|
|
2014-11-27 00:22:10 +03:00
|
|
|
gfxRect imageRect(0, 0, mImageSize.width, mImageSize.height);
|
2014-08-23 00:12:38 +04:00
|
|
|
bool doTile = !imageRect.Contains(aRegion.Rect()) &&
|
2012-04-18 02:04:15 +04:00
|
|
|
!(aImageFlags & imgIContainer::FLAG_CLAMP);
|
2015-11-23 19:17:35 +03:00
|
|
|
|
2014-08-23 00:12:38 +04:00
|
|
|
ImageRegion region(aRegion);
|
2014-09-29 21:26:31 +04: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 17:30:02 +04:00
|
|
|
SurfaceWithFormat surfaceResult =
|
2014-08-23 00:12:38 +04:00
|
|
|
SurfaceForDrawing(doPadding, doPartialDecode, doTile, aContext,
|
2014-11-27 00:22:10 +03: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-21 05:50:15 +04:00
|
|
|
|
2010-08-13 17:30:02 +04:00
|
|
|
if (surfaceResult.IsValid()) {
|
2010-08-13 17:30:27 +04:00
|
|
|
gfxUtils::DrawPixelSnapped(aContext, surfaceResult.mDrawable,
|
2014-08-23 00:12:38 +04: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-21 05:50:15 +04:00
|
|
|
}
|
2014-03-02 20:17:26 +04: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-21 05:50:15 +04:00
|
|
|
}
|
|
|
|
|
2015-01-08 11:04:31 +03:00
|
|
|
nsresult
|
|
|
|
imgFrame::ImageUpdated(const nsIntRect& aUpdateRect)
|
|
|
|
{
|
2015-01-12 06:28:02 +03:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2015-01-08 11:04:31 +03: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-21 05:50:15 +04:00
|
|
|
{
|
2015-01-12 06:28:02 +03:00
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
2013-07-04 22:45:57 +04: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-21 05:50:15 +04:00
|
|
|
mDecoded.UnionRect(mDecoded, aUpdateRect);
|
|
|
|
|
|
|
|
// clamp to bounds, in case someone sends a bogus updateRect (I'm looking at
|
|
|
|
// you, gif decoder)
|
2015-04-21 18:22:30 +03: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-21 05:50:15 +04:00
|
|
|
mDecoded.IntersectRect(mDecoded, boundsRect);
|
|
|
|
|
2015-01-12 06:28:02 +03: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-21 05:50:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-01-08 11:04:31 +03:00
|
|
|
void
|
2015-01-12 06:28:02 +03:00
|
|
|
imgFrame::Finish(Opacity aFrameOpacity /* = Opacity::SOME_TRANSPARENCY */,
|
|
|
|
DisposalMethod aDisposalMethod /* = DisposalMethod::KEEP */,
|
|
|
|
int32_t aRawTimeout /* = 0 */,
|
|
|
|
BlendMethod aBlendMethod /* = BlendMethod::OVER */)
|
2015-01-08 11:04:31 +03:00
|
|
|
{
|
2015-01-12 06:28:02 +03:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2015-01-08 11:04:31 +03:00
|
|
|
MOZ_ASSERT(mLockCount > 0, "Image data should be locked");
|
|
|
|
|
|
|
|
if (aFrameOpacity == Opacity::OPAQUE) {
|
|
|
|
mHasNoAlpha = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDisposalMethod = aDisposalMethod;
|
|
|
|
mTimeout = aRawTimeout;
|
|
|
|
mBlendMethod = aBlendMethod;
|
|
|
|
ImageUpdatedInternal(GetRect());
|
|
|
|
}
|
|
|
|
|
2015-03-31 20:48:00 +03:00
|
|
|
nsIntRect
|
|
|
|
imgFrame::GetRect() 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-21 05:50:15 +04:00
|
|
|
{
|
2015-04-21 18:22:30 +03:00
|
|
|
return gfx::IntRect(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-21 05:50:15 +04:00
|
|
|
}
|
|
|
|
|
2014-08-23 00:49:54 +04:00
|
|
|
int32_t
|
|
|
|
imgFrame::GetStride() const
|
|
|
|
{
|
2015-01-12 06:28:02 +03:00
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
2015-01-08 11:04:31 +03:00
|
|
|
|
2014-08-23 00:49:54 +04:00
|
|
|
if (mImageSurface) {
|
|
|
|
return mImageSurface->Stride();
|
|
|
|
}
|
|
|
|
|
|
|
|
return VolatileSurfaceStride(mSize, mFormat);
|
|
|
|
}
|
|
|
|
|
2015-03-31 20:48:00 +03: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-21 05:50:15 +04:00
|
|
|
{
|
2015-01-12 06:28:02 +03: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-21 05:50:15 +04:00
|
|
|
return mFormat;
|
|
|
|
}
|
|
|
|
|
2015-03-31 20:48:00 +03: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-21 05:50:15 +04:00
|
|
|
{
|
2015-01-12 06:28:02 +03:00
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
2015-01-08 11:04:31 +03:00
|
|
|
|
2015-03-31 20:48:00 +03:00
|
|
|
if (mVBuf) {
|
2014-04-20 05:28:38 +04:00
|
|
|
return mSize.width * BytesPerPixel(mFormat);
|
2015-03-31 20:48:00 +03:00
|
|
|
}
|
2014-02-25 07:37:51 +04:00
|
|
|
|
2015-03-31 20:48:00 +03: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-21 05:50:15 +04:00
|
|
|
return mSize.width;
|
2015-03-31 20:48:00 +03:00
|
|
|
}
|
2010-05-22 08:10:14 +04: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-21 05:50:15 +04:00
|
|
|
}
|
|
|
|
|
2015-03-31 20:48:00 +03: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-21 05:50:15 +04:00
|
|
|
{
|
2010-05-22 08:10:14 +04: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-21 05:50:15 +04:00
|
|
|
}
|
|
|
|
|
2015-01-08 11:04:31 +03: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-21 05:50:15 +04:00
|
|
|
{
|
2015-01-12 06:28:02 +03:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2015-01-08 11:04:31 +03:00
|
|
|
GetImageDataInternal(aData, aLength);
|
|
|
|
}
|
2012-09-26 19:33:06 +04:00
|
|
|
|
2015-01-08 11:04:31 +03:00
|
|
|
void
|
|
|
|
imgFrame::GetImageDataInternal(uint8_t** aData, uint32_t* aLength) const
|
|
|
|
{
|
2015-01-12 06:28:02 +03:00
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
2015-01-08 11:04:31 +03:00
|
|
|
MOZ_ASSERT(mLockCount > 0, "Image data should be locked");
|
|
|
|
|
|
|
|
if (mImageSurface) {
|
2014-04-20 05:28:38 +04:00
|
|
|
*aData = mVBufPtr;
|
2015-03-31 20:48:00 +03:00
|
|
|
MOZ_ASSERT(*aData,
|
|
|
|
"mImageSurface is non-null, but mVBufPtr is null in GetImageData");
|
2015-01-08 11:04:31 +03:00
|
|
|
} 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-21 05:50:15 +04:00
|
|
|
*aData = mPalettedImageData + PaletteDataLength();
|
2015-03-31 20:48:00 +03:00
|
|
|
MOZ_ASSERT(*aData,
|
|
|
|
"mPalettedImageData is non-null, but result is null in GetImageData");
|
2015-01-08 11:04:31 +03:00
|
|
|
} else {
|
2015-03-31 20:48:00 +03:00
|
|
|
MOZ_ASSERT(false,
|
|
|
|
"Have neither mImageSurface nor mPalettedImageData in GetImageData");
|
2012-07-30 18:20:58 +04:00
|
|
|
*aData = nullptr;
|
2015-01-08 11:04:31 +03: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-21 05:50:15 +04:00
|
|
|
|
2015-01-08 11:04:31 +03: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-21 05:50:15 +04:00
|
|
|
}
|
|
|
|
|
2015-03-31 20:48:00 +03:00
|
|
|
uint8_t*
|
|
|
|
imgFrame::GetImageData() const
|
2013-06-14 17:42:01 +04:00
|
|
|
{
|
2015-03-31 20:48:00 +03:00
|
|
|
uint8_t* data;
|
2013-06-14 17:42:01 +04:00
|
|
|
uint32_t length;
|
|
|
|
GetImageData(&data, &length);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2015-03-31 20:48:00 +03: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-21 05:50:15 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04: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-21 05:50:15 +04:00
|
|
|
}
|
|
|
|
|
2015-03-31 20:48:00 +03: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-21 05:50:15 +04:00
|
|
|
{
|
2015-01-08 11:04:31 +03:00
|
|
|
AssertImageDataLocked();
|
2012-09-26 19:33:06 +04: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-21 05:50:15 +04:00
|
|
|
if (!mPalettedImageData) {
|
2012-07-30 18:20:58 +04: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-21 05:50:15 +04:00
|
|
|
*length = 0;
|
|
|
|
} else {
|
2015-03-31 20:48:00 +03: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-21 05:50:15 +04:00
|
|
|
*length = PaletteDataLength();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-31 20:48:00 +03:00
|
|
|
uint32_t*
|
|
|
|
imgFrame::GetPaletteData() const
|
2013-06-14 17:42:01 +04:00
|
|
|
{
|
|
|
|
uint32_t* data;
|
|
|
|
uint32_t length;
|
|
|
|
GetPaletteData(&data, &length);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2015-01-08 11:04:31 +03: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-21 05:50:15 +04:00
|
|
|
{
|
2015-01-12 06:28:02 +03:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2013-05-24 17:52:34 +04:00
|
|
|
|
2015-01-08 11:04:31 +03:00
|
|
|
MOZ_ASSERT(mLockCount >= 0, "Unbalanced locks and unlocks");
|
2012-09-26 19:33:06 +04:00
|
|
|
if (mLockCount < 0) {
|
2012-09-29 02:00:28 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-09-26 19:33:06 +04:00
|
|
|
}
|
2012-09-26 19:33:06 +04:00
|
|
|
|
|
|
|
mLockCount++;
|
|
|
|
|
|
|
|
// If we are not the first lock, there's nothing to do.
|
|
|
|
if (mLockCount != 1) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-01-08 11:04:31 +03: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 19:33:06 +04:00
|
|
|
// Paletted images don't have surfaces, so there's nothing to do.
|
2015-01-08 11:04:31 +03:00
|
|
|
if (mPalettedImageData) {
|
2012-09-26 19:33:06 +04:00
|
|
|
return NS_OK;
|
2015-01-08 11:04:31 +03:00
|
|
|
}
|
|
|
|
|
2015-09-20 02:21:02 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("It's illegal to re-lock an optimized imgFrame");
|
|
|
|
return NS_ERROR_FAILURE;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
}
|
|
|
|
|
2015-01-08 11:04:31 +03: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-21 05:50:15 +04:00
|
|
|
{
|
2015-01-08 11:04:31 +03:00
|
|
|
#ifdef DEBUG
|
2015-01-12 06:28:02 +03:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2015-01-08 11:04:31 +03:00
|
|
|
MOZ_ASSERT(mLockCount > 0, "Image data should be locked");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
class UnlockImageDataRunnable : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2015-01-08 12:28:21 +03:00
|
|
|
explicit UnlockImageDataRunnable(imgFrame* aTarget)
|
2015-01-08 11:04:31 +03:00
|
|
|
: mTarget(aTarget)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mTarget);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() { return mTarget->UnlockImageData(); }
|
|
|
|
|
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgFrame> mTarget;
|
2015-01-08 11:04:31 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
imgFrame::UnlockImageData()
|
|
|
|
{
|
2015-01-12 06:28:02 +03:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2013-05-24 17:52:34 +04:00
|
|
|
|
2014-09-19 06:26:01 +04:00
|
|
|
MOZ_ASSERT(mLockCount > 0, "Unlocking an unlocked image!");
|
|
|
|
if (mLockCount <= 0) {
|
2012-09-26 19:33:06 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-01-12 06:28:02 +03:00
|
|
|
MOZ_ASSERT(mLockCount > 1 || IsImageCompleteInternal() || mAborted,
|
|
|
|
"Should have marked complete or aborted before unlocking");
|
|
|
|
|
2014-09-19 06:26:01 +04: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 11:04:31 +03: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-24 02:43:03 +04: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-19 06:26:01 +04:00
|
|
|
// Convert the data surface to a GPU surface or a single color if possible.
|
|
|
|
// This will also release mImageSurface if possible.
|
|
|
|
Optimize();
|
2015-03-31 20:48:00 +03:00
|
|
|
|
2014-09-19 06:26:01 +04:00
|
|
|
// Allow the OS to release our data surface.
|
|
|
|
mVBufPtr = nullptr;
|
2012-09-26 19:33:06 +04:00
|
|
|
}
|
|
|
|
|
2014-09-19 06:26:01 +04:00
|
|
|
mLockCount--;
|
2014-02-25 07:37:51 +04: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-21 05:50:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-09-19 06:26:01 +04:00
|
|
|
void
|
|
|
|
imgFrame::SetOptimizable()
|
|
|
|
{
|
2015-01-08 11:04:31 +03:00
|
|
|
AssertImageDataLocked();
|
2015-07-31 17:29:10 +03:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2014-09-19 06:26:01 +04:00
|
|
|
mOptimizable = true;
|
2014-02-25 07:37:51 +04:00
|
|
|
}
|
|
|
|
|
2015-01-08 11:04:31 +03:00
|
|
|
Color
|
|
|
|
imgFrame::SinglePixelColor() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
return mSinglePixelColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
imgFrame::IsSinglePixel() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
return mSinglePixel;
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<SourceSurface>
|
2014-04-20 05:28:38 +04:00
|
|
|
imgFrame::GetSurface()
|
|
|
|
{
|
2015-01-12 06:28:02 +03:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2015-01-08 11:04:31 +03:00
|
|
|
return GetSurfaceInternal();
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<SourceSurface>
|
2015-01-08 11:04:31 +03:00
|
|
|
imgFrame::GetSurfaceInternal()
|
|
|
|
{
|
2015-01-12 06:28:02 +03:00
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
2015-01-08 11:04:31 +03:00
|
|
|
|
2014-04-20 05:28:38 +04:00
|
|
|
if (mOptSurface) {
|
2015-03-31 20:48:00 +03:00
|
|
|
if (mOptSurface->IsValid()) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurface> surf(mOptSurface);
|
2015-05-01 16:14:16 +03:00
|
|
|
return surf.forget();
|
2015-03-31 20:48:00 +03:00
|
|
|
} else {
|
2014-04-20 05:28:38 +04:00
|
|
|
mOptSurface = nullptr;
|
2015-03-31 20:48:00 +03:00
|
|
|
}
|
2014-04-20 05:28:38 +04:00
|
|
|
}
|
|
|
|
|
2015-03-31 20:48:00 +03:00
|
|
|
if (mImageSurface) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurface> surf(mImageSurface);
|
2015-05-01 16:14:16 +03:00
|
|
|
return surf.forget();
|
2015-03-31 20:48:00 +03:00
|
|
|
}
|
2014-04-20 05:28:38 +04:00
|
|
|
|
2015-03-31 20:48:00 +03:00
|
|
|
if (!mVBuf) {
|
2014-04-20 05:28:38 +04:00
|
|
|
return nullptr;
|
2015-03-31 20:48:00 +03:00
|
|
|
}
|
2014-04-20 05:28:38 +04:00
|
|
|
|
|
|
|
VolatileBufferPtr<char> buf(mVBuf);
|
2015-03-31 20:48:00 +03:00
|
|
|
if (buf.WasBufferPurged()) {
|
2014-04-20 05:28:38 +04:00
|
|
|
return nullptr;
|
2015-03-31 20:48:00 +03:00
|
|
|
}
|
2014-04-20 05:28:38 +04:00
|
|
|
|
|
|
|
return CreateLockedSurface(mVBuf, mSize, mFormat);
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<DrawTarget>
|
2014-08-23 00:49:54 +04:00
|
|
|
imgFrame::GetDrawTarget()
|
|
|
|
{
|
2015-01-12 06:28:02 +03:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2014-08-23 00:49:54 +04:00
|
|
|
|
2015-01-08 11:04:31 +03:00
|
|
|
uint8_t* data;
|
|
|
|
uint32_t length;
|
|
|
|
GetImageDataInternal(&data, &length);
|
2014-08-23 00:49:54 +04:00
|
|
|
if (!data) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t stride = GetStride();
|
|
|
|
return gfxPlatform::GetPlatform()->
|
|
|
|
CreateDrawTargetForData(data, mSize, stride, mFormat);
|
|
|
|
}
|
|
|
|
|
2015-01-08 11:04:31 +03: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-21 05:50:15 +04:00
|
|
|
{
|
2015-01-12 06:28:02 +03:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2015-01-08 11:04:31 +03: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-21 05:50:15 +04:00
|
|
|
|
2015-01-08 11:04:31 +03: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-21 05:50:15 +04:00
|
|
|
}
|
|
|
|
|
2015-01-08 11:04:31 +03: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-21 05:50:15 +04:00
|
|
|
{
|
2015-01-12 06:28:02 +03:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2015-01-08 11:04:31 +03:00
|
|
|
MOZ_ASSERT(mLockCount > 0, "Image data should be locked");
|
|
|
|
MOZ_ASSERT(!GetIsPaletted(), "GetScalingData can't handle paletted images");
|
2013-07-15 22:38:59 +04:00
|
|
|
|
2015-01-08 11:04:31 +03: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-21 05:50:15 +04:00
|
|
|
}
|
|
|
|
|
2015-01-12 06:28:02 +03:00
|
|
|
void
|
|
|
|
imgFrame::Abort()
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
|
|
|
|
mAborted = true;
|
|
|
|
|
|
|
|
// Wake up anyone who's waiting.
|
2015-01-16 02:11:36 +03:00
|
|
|
mMonitor.NotifyAll();
|
2015-01-12 06:28:02 +03:00
|
|
|
}
|
|
|
|
|
2015-01-08 11:04:31 +03:00
|
|
|
bool
|
2015-01-12 06:28:02 +03: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-21 05:50:15 +04:00
|
|
|
{
|
2015-01-12 06:28:02 +03: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-21 05:50:15 +04:00
|
|
|
}
|
2009-11-13 02:18:40 +03:00
|
|
|
|
2015-01-08 11:04:31 +03:00
|
|
|
bool
|
2015-01-12 06:28:02 +03:00
|
|
|
imgFrame::IsImageCompleteInternal() const
|
2012-03-24 02:10:50 +04:00
|
|
|
{
|
2015-01-12 06:28:02 +03:00
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
2015-01-08 11:04:31 +03:00
|
|
|
return mDecoded.IsEqualInterior(nsIntRect(mOffset.x, mOffset.y,
|
|
|
|
mSize.width, mSize.height));
|
2012-03-24 02:10:50 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool imgFrame::GetCompositingFailed() const
|
2009-11-13 02:18:40 +03:00
|
|
|
{
|
2015-01-08 11:04:31 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2009-11-13 02:18:40 +03:00
|
|
|
return mCompositingFailed;
|
|
|
|
}
|
|
|
|
|
2015-03-31 20:48:00 +03:00
|
|
|
void
|
|
|
|
imgFrame::SetCompositingFailed(bool val)
|
2009-11-13 02:18:40 +03:00
|
|
|
{
|
2015-01-08 11:04:31 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2009-11-13 02:18:40 +03:00
|
|
|
mCompositingFailed = val;
|
|
|
|
}
|
2010-03-12 13:08:25 +03:00
|
|
|
|
2015-07-29 07:02:45 +03:00
|
|
|
void
|
|
|
|
imgFrame::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
|
|
|
|
size_t& aHeapSizeOut,
|
|
|
|
size_t& aNonHeapSizeOut) const
|
2010-05-22 08:10:14 +04:00
|
|
|
{
|
2015-01-12 06:28:02 +03:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2015-01-08 11:04:31 +03:00
|
|
|
|
2015-07-29 07:02:45 +03:00
|
|
|
if (mPalettedImageData) {
|
|
|
|
aHeapSizeOut += aMallocSizeOf(mPalettedImageData);
|
2014-02-25 07:37:51 +04:00
|
|
|
}
|
2015-07-29 07:02:45 +03:00
|
|
|
if (mImageSurface) {
|
|
|
|
aHeapSizeOut += aMallocSizeOf(mImageSurface);
|
2010-05-22 08:10:14 +04:00
|
|
|
}
|
2015-07-29 07:02:45 +03:00
|
|
|
if (mOptSurface) {
|
|
|
|
aHeapSizeOut += aMallocSizeOf(mOptSurface);
|
2014-02-25 07:37:51 +04:00
|
|
|
}
|
|
|
|
|
2015-07-29 07:02:45 +03:00
|
|
|
if (mVBuf) {
|
|
|
|
aHeapSizeOut += aMallocSizeOf(mVBuf);
|
|
|
|
aHeapSizeOut += mVBuf->HeapSizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
aNonHeapSizeOut += mVBuf->NonHeapSizeOfExcludingThis();
|
2014-04-15 09:24:01 +04:00
|
|
|
}
|
2010-05-22 08:10:14 +04:00
|
|
|
}
|
2014-07-10 19:00:31 +04:00
|
|
|
|
|
|
|
} // namespace image
|
|
|
|
} // namespace mozilla
|