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"
|
2018-09-21 03:22:00 +03:00
|
|
|
#include "SurfaceCache.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"
|
2017-02-14 00:34:54 +03:00
|
|
|
#include "gfxPrefs.h"
|
2010-08-13 17:30:02 +04:00
|
|
|
#include "gfxUtils.h"
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
|
2013-03-18 18:25:50 +04:00
|
|
|
#include "GeckoProfiler.h"
|
2014-11-28 06:55:57 +03:00
|
|
|
#include "MainThreadUtils.h"
|
2016-06-25 09:22:29 +03:00
|
|
|
#include "mozilla/CheckedInt.h"
|
2018-03-14 21:19:13 +03:00
|
|
|
#include "mozilla/gfx/gfxVars.h"
|
2016-06-25 09:22:29 +03:00
|
|
|
#include "mozilla/gfx/Tools.h"
|
2018-02-22 22:26:29 +03:00
|
|
|
#include "mozilla/gfx/SourceSurfaceRawData.h"
|
Bug 1465619 - Part 6. Add support for recycling to imgFrame. r=tnikkel
Beyond the necessary reinitialization methods, we need to protect
ourselves from recycling a frame that some other entity in the browser
is still using. Generally speaking the animated surface will only be
used in imgFrame::Draw since we don't layerize animated images, which
will be safe. However with OMTP or blob recordings, we could retain a
reference to the surface outside the current stack context. Additional
if something calls RasterImage::GetImageContainer(AtSize) or
RasterImage::GetFrame(AtSize), it may also have a reference to the
surface for an indetermine period of time.
As such, if an imgFrame is a candidate for recycling, it will wrap
imgFrame::mLockedSurface in a RecyclingSourceSurface. Its job is to
track how many consumers there are still of the surface, so that after
we advance the animation, the decoder will know if there are still
outstanding consumers.
If the surface is still in use, it will block for a finite period of
time (the refresh interval) before giving up on reclaiming the surface,
and will allocate a new surface. The old surface can then remain in
circulation for as long as necessary without further blocking the
animation progression, since we stop recycling that surface/imgFrame.
Differential Revision: https://phabricator.services.mozilla.com/D7511
2018-06-04 02:42:09 +03:00
|
|
|
#include "mozilla/image/RecyclingSourceSurface.h"
|
2017-02-08 23:48:59 +03:00
|
|
|
#include "mozilla/layers/SourceSurfaceSharedData.h"
|
2017-01-18 21:31:20 +03:00
|
|
|
#include "mozilla/layers/SourceSurfaceVolatileData.h"
|
2016-06-25 09:22:29 +03:00
|
|
|
#include "mozilla/Likely.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-09-07 06:15:49 +04:00
|
|
|
#include "nsMargin.h"
|
Bug 1465619 - Part 6. Add support for recycling to imgFrame. r=tnikkel
Beyond the necessary reinitialization methods, we need to protect
ourselves from recycling a frame that some other entity in the browser
is still using. Generally speaking the animated surface will only be
used in imgFrame::Draw since we don't layerize animated images, which
will be safe. However with OMTP or blob recordings, we could retain a
reference to the surface outside the current stack context. Additional
if something calls RasterImage::GetImageContainer(AtSize) or
RasterImage::GetFrame(AtSize), it may also have a reference to the
surface for an indetermine period of time.
As such, if an imgFrame is a candidate for recycling, it will wrap
imgFrame::mLockedSurface in a RecyclingSourceSurface. Its job is to
track how many consumers there are still of the surface, so that after
we advance the animation, the decoder will know if there are still
outstanding consumers.
If the surface is still in use, it will block for a finite period of
time (the refresh interval) before giving up on reclaiming the surface,
and will allocate a new surface. The old surface can then remain in
circulation for as long as necessary without further blocking the
animation progression, since we stop recycling that surface/imgFrame.
Differential Revision: https://phabricator.services.mozilla.com/D7511
2018-06-04 02:42:09 +03:00
|
|
|
#include "nsRefreshDriver.h"
|
2015-01-08 11:04:31 +03:00
|
|
|
#include "nsThreadUtils.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
|
|
|
|
2017-01-18 21:31:20 +03:00
|
|
|
static void ScopedMapRelease(void* aMap) {
|
|
|
|
delete static_cast<DataSourceSurface::ScopedMap*>(aMap);
|
2014-02-25 07:37:51 +04:00
|
|
|
}
|
|
|
|
|
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> CreateLockedSurface(
|
2017-01-18 21:31:20 +03:00
|
|
|
DataSourceSurface* aSurface, const IntSize& size, SurfaceFormat format) {
|
2017-02-08 23:48:59 +03:00
|
|
|
// Shared memory is never released until the surface itself is released
|
|
|
|
if (aSurface->GetType() == SurfaceType::DATA_SHARED) {
|
|
|
|
RefPtr<DataSourceSurface> surf(aSurface);
|
|
|
|
return surf.forget();
|
|
|
|
}
|
|
|
|
|
2017-01-18 21:31:20 +03:00
|
|
|
DataSourceSurface::ScopedMap* smap =
|
|
|
|
new DataSourceSurface::ScopedMap(aSurface, DataSourceSurface::READ_WRITE);
|
|
|
|
if (smap->IsMapped()) {
|
|
|
|
// The ScopedMap is held by this DataSourceSurface.
|
|
|
|
RefPtr<DataSourceSurface> surf = Factory::CreateWrappingDataSourceSurface(
|
|
|
|
smap->GetData(), aSurface->Stride(), size, format, &ScopedMapRelease,
|
|
|
|
static_cast<void*>(smap));
|
|
|
|
if (surf) {
|
|
|
|
return surf.forget();
|
|
|
|
}
|
2014-02-25 07:37:51 +04:00
|
|
|
}
|
|
|
|
|
2017-01-18 21:31:20 +03:00
|
|
|
delete smap;
|
|
|
|
return nullptr;
|
2014-02-25 07:37:51 +04:00
|
|
|
}
|
|
|
|
|
2018-02-22 22:26:29 +03:00
|
|
|
static bool ShouldUseHeap(const IntSize& aSize, int32_t aStride,
|
|
|
|
bool aIsAnimated) {
|
|
|
|
// On some platforms (i.e. Android), a volatile buffer actually keeps a file
|
|
|
|
// handle active. We would like to avoid too many since we could easily
|
|
|
|
// exhaust the pool. However, other platforms we do not have the file handle
|
|
|
|
// problem, and additionally we may avoid a superfluous memset since the
|
|
|
|
// volatile memory starts out as zero-filled. Hence the knobs below.
|
|
|
|
|
|
|
|
// For as long as an animated image is retained, its frames will never be
|
|
|
|
// released to let the OS purge volatile buffers.
|
|
|
|
if (aIsAnimated && gfxPrefs::ImageMemAnimatedUseHeap()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lets us avoid too many small images consuming all of the handles. The
|
|
|
|
// actual allocation checks for overflow.
|
|
|
|
int32_t bufferSize = (aStride * aSize.width) / 1024;
|
|
|
|
if (bufferSize < gfxPrefs::ImageMemVolatileMinThresholdKB()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-18 21:31:20 +03:00
|
|
|
static already_AddRefed<DataSourceSurface> AllocateBufferForImage(
|
|
|
|
const IntSize& size, SurfaceFormat format, bool aIsAnimated = false,
|
2018-09-17 22:06:29 +03:00
|
|
|
bool aIsFullFrame = true) {
|
2017-08-31 13:38:55 +03:00
|
|
|
int32_t stride = VolatileSurfaceStride(size, format);
|
|
|
|
|
2018-09-17 22:06:29 +03:00
|
|
|
if (gfxVars::GetUseWebRenderOrDefault() && gfxPrefs::ImageMemShared() &&
|
|
|
|
aIsFullFrame) {
|
|
|
|
RefPtr<SourceSurfaceSharedData> newSurf = new SourceSurfaceSharedData();
|
|
|
|
if (newSurf->Init(size, stride, format)) {
|
|
|
|
return newSurf.forget();
|
|
|
|
}
|
|
|
|
} else if (ShouldUseHeap(size, stride, aIsAnimated)) {
|
2018-02-22 22:26:29 +03:00
|
|
|
RefPtr<SourceSurfaceAlignedRawData> newSurf =
|
|
|
|
new SourceSurfaceAlignedRawData();
|
|
|
|
if (newSurf->Init(size, format, false, 0, stride)) {
|
|
|
|
return newSurf.forget();
|
|
|
|
}
|
2017-02-08 23:48:59 +03:00
|
|
|
} else {
|
|
|
|
RefPtr<SourceSurfaceVolatileData> newSurf = new SourceSurfaceVolatileData();
|
|
|
|
if (newSurf->Init(size, stride, format)) {
|
|
|
|
return newSurf.forget();
|
|
|
|
}
|
2015-03-31 20:48:00 +03:00
|
|
|
}
|
2014-02-25 07:37:51 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-01-18 21:31:20 +03:00
|
|
|
static bool ClearSurface(DataSourceSurface* aSurface, const IntSize& aSize,
|
|
|
|
SurfaceFormat aFormat) {
|
|
|
|
int32_t stride = aSurface->Stride();
|
|
|
|
uint8_t* data = aSurface->GetData();
|
|
|
|
MOZ_ASSERT(data);
|
2016-07-01 04:59:29 +03:00
|
|
|
|
|
|
|
if (aFormat == SurfaceFormat::B8G8R8X8) {
|
|
|
|
// Skia doesn't support RGBX surfaces, so ensure the alpha value is set
|
|
|
|
// to opaque white. While it would be nice to only do this for Skia,
|
|
|
|
// imgFrame can run off main thread and past shutdown where
|
|
|
|
// we might not have gfxPlatform, so just memset everytime instead.
|
2017-01-18 21:31:20 +03:00
|
|
|
memset(data, 0xFF, stride * aSize.height);
|
|
|
|
} else if (aSurface->OnHeap()) {
|
2016-07-01 04:59:29 +03:00
|
|
|
// We only need to memset it if the buffer was allocated on the heap.
|
|
|
|
// Otherwise, it's allocated via mmap and refers to a zeroed page and will
|
|
|
|
// be COW once it's written to.
|
2017-01-18 21:31:20 +03:00
|
|
|
memset(data, 0, stride * aSize.height);
|
2016-07-01 04:59:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-27 00:22:10 +03:00
|
|
|
static bool AllowedImageAndFrameDimensions(const nsIntSize& aImageSize,
|
|
|
|
const nsIntRect& aFrameRect) {
|
2018-09-21 03:22:00 +03:00
|
|
|
if (!SurfaceCache::IsLegalSize(aImageSize)) {
|
2014-11-27 00:22:10 +03:00
|
|
|
return false;
|
|
|
|
}
|
2018-09-21 03:22:00 +03:00
|
|
|
if (!SurfaceCache::IsLegalSize(aFrameRect.Size())) {
|
2014-11-27 00:22:10 +03:00
|
|
|
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),
|
Bug 1465619 - Part 6. Add support for recycling to imgFrame. r=tnikkel
Beyond the necessary reinitialization methods, we need to protect
ourselves from recycling a frame that some other entity in the browser
is still using. Generally speaking the animated surface will only be
used in imgFrame::Draw since we don't layerize animated images, which
will be safe. However with OMTP or blob recordings, we could retain a
reference to the surface outside the current stack context. Additional
if something calls RasterImage::GetImageContainer(AtSize) or
RasterImage::GetFrame(AtSize), it may also have a reference to the
surface for an indetermine period of time.
As such, if an imgFrame is a candidate for recycling, it will wrap
imgFrame::mLockedSurface in a RecyclingSourceSurface. Its job is to
track how many consumers there are still of the surface, so that after
we advance the animation, the decoder will know if there are still
outstanding consumers.
If the surface is still in use, it will block for a finite period of
time (the refresh interval) before giving up on reclaiming the surface,
and will allocate a new surface. The old surface can then remain in
circulation for as long as necessary without further blocking the
animation progression, since we stop recycling that surface/imgFrame.
Differential Revision: https://phabricator.services.mozilla.com/D7511
2018-06-04 02:42:09 +03:00
|
|
|
mRecycleLockCount(0),
|
2015-01-12 06:28:02 +03:00
|
|
|
mAborted(false),
|
2016-03-24 03:31:42 +03:00
|
|
|
mFinished(false),
|
2015-07-31 17:29:10 +03:00
|
|
|
mOptimizable(false),
|
Bug 1465619 - Part 6. Add support for recycling to imgFrame. r=tnikkel
Beyond the necessary reinitialization methods, we need to protect
ourselves from recycling a frame that some other entity in the browser
is still using. Generally speaking the animated surface will only be
used in imgFrame::Draw since we don't layerize animated images, which
will be safe. However with OMTP or blob recordings, we could retain a
reference to the surface outside the current stack context. Additional
if something calls RasterImage::GetImageContainer(AtSize) or
RasterImage::GetFrame(AtSize), it may also have a reference to the
surface for an indetermine period of time.
As such, if an imgFrame is a candidate for recycling, it will wrap
imgFrame::mLockedSurface in a RecyclingSourceSurface. Its job is to
track how many consumers there are still of the surface, so that after
we advance the animation, the decoder will know if there are still
outstanding consumers.
If the surface is still in use, it will block for a finite period of
time (the refresh interval) before giving up on reclaiming the surface,
and will allocate a new surface. The old surface can then remain in
circulation for as long as necessary without further blocking the
animation progression, since we stop recycling that surface/imgFrame.
Differential Revision: https://phabricator.services.mozilla.com/D7511
2018-06-04 02:42:09 +03:00
|
|
|
mShouldRecycle(false),
|
2018-05-29 15:36:11 +03:00
|
|
|
mTimeout(FrameTimeout::FromRawMilliseconds(100)),
|
|
|
|
mDisposalMethod(DisposalMethod::NOT_SPECIFIED),
|
|
|
|
mBlendMethod(BlendMethod::OVER),
|
2018-06-14 08:21:37 +03:00
|
|
|
mFormat(SurfaceFormat::UNKNOWN),
|
2015-01-08 11:04:31 +03:00
|
|
|
mPalettedImageData(nullptr),
|
|
|
|
mPaletteDepth(0),
|
|
|
|
mNonPremult(false),
|
2018-09-17 22:06:29 +03:00
|
|
|
mIsFullFrame(false),
|
2015-01-08 11:04:31 +03:00
|
|
|
mCompositingFailed(false) {}
|
2018-11-30 13:46:48 +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
|
|
|
imgFrame::~imgFrame() {
|
2015-01-12 06:28:02 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
2016-03-24 03:31:42 +03:00
|
|
|
MOZ_ASSERT(mAborted || AreAllPixelsWritten());
|
|
|
|
MOZ_ASSERT(mAborted || mFinished);
|
2015-01-12 06:28:02 +03:00
|
|
|
#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-11-27 00:22:10 +03:00
|
|
|
nsresult imgFrame::InitForDecoder(const nsIntSize& aImageSize,
|
|
|
|
const nsIntRect& aRect, SurfaceFormat aFormat,
|
Bug 1465619 - Part 6. Add support for recycling to imgFrame. r=tnikkel
Beyond the necessary reinitialization methods, we need to protect
ourselves from recycling a frame that some other entity in the browser
is still using. Generally speaking the animated surface will only be
used in imgFrame::Draw since we don't layerize animated images, which
will be safe. However with OMTP or blob recordings, we could retain a
reference to the surface outside the current stack context. Additional
if something calls RasterImage::GetImageContainer(AtSize) or
RasterImage::GetFrame(AtSize), it may also have a reference to the
surface for an indetermine period of time.
As such, if an imgFrame is a candidate for recycling, it will wrap
imgFrame::mLockedSurface in a RecyclingSourceSurface. Its job is to
track how many consumers there are still of the surface, so that after
we advance the animation, the decoder will know if there are still
outstanding consumers.
If the surface is still in use, it will block for a finite period of
time (the refresh interval) before giving up on reclaiming the surface,
and will allocate a new surface. The old surface can then remain in
circulation for as long as necessary without further blocking the
animation progression, since we stop recycling that surface/imgFrame.
Differential Revision: https://phabricator.services.mozilla.com/D7511
2018-06-04 02:42:09 +03:00
|
|
|
uint8_t aPaletteDepth, bool aNonPremult,
|
|
|
|
const Maybe<AnimationParams>& aAnimParams,
|
|
|
|
bool aIsFullFrame, bool aShouldRecycle) {
|
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;
|
2016-05-27 08:19:38 +03:00
|
|
|
mFrameRect = aRect;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
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
|
|
|
|
2018-09-17 22:06:28 +03:00
|
|
|
// May be updated shortly after InitForDecoder by BlendAnimationFilter
|
|
|
|
// because it needs to take into consideration the previous frames to
|
|
|
|
// properly calculate. We start with the whole frame as dirty.
|
|
|
|
mDirtyRect = aRect;
|
|
|
|
|
2018-05-29 15:36:11 +03:00
|
|
|
if (aAnimParams) {
|
|
|
|
mBlendRect = aAnimParams->mBlendRect;
|
|
|
|
mTimeout = aAnimParams->mTimeout;
|
|
|
|
mBlendMethod = aAnimParams->mBlendMethod;
|
|
|
|
mDisposalMethod = aAnimParams->mDisposalMethod;
|
2018-09-17 22:06:29 +03:00
|
|
|
mIsFullFrame = aAnimParams->mFrameNum == 0 || aIsFullFrame;
|
2018-05-29 15:36:11 +03:00
|
|
|
} else {
|
|
|
|
mBlendRect = aRect;
|
2018-09-17 22:06:29 +03:00
|
|
|
mIsFullFrame = true;
|
2018-05-29 15:36:11 +03:00
|
|
|
}
|
|
|
|
|
2016-07-31 00:47:49 +03:00
|
|
|
// We only allow a non-trivial frame rect (i.e., a frame rect that doesn't
|
|
|
|
// cover the entire image) for paletted animation frames. We never draw those
|
|
|
|
// frames directly; we just use FrameAnimator to composite them and produce a
|
|
|
|
// BGRA surface that we actually draw. We enforce this here to make sure that
|
|
|
|
// imgFrame::Draw(), which is responsible for drawing all other kinds of
|
|
|
|
// frames, never has to deal with a non-trivial frame rect.
|
|
|
|
if (aPaletteDepth == 0 &&
|
|
|
|
!mFrameRect.IsEqualEdges(IntRect(IntPoint(), mImageSize))) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE(
|
|
|
|
"Creating a non-paletted imgFrame with a "
|
|
|
|
"non-trivial frame rect");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
Bug 1465619 - Part 6. Add support for recycling to imgFrame. r=tnikkel
Beyond the necessary reinitialization methods, we need to protect
ourselves from recycling a frame that some other entity in the browser
is still using. Generally speaking the animated surface will only be
used in imgFrame::Draw since we don't layerize animated images, which
will be safe. However with OMTP or blob recordings, we could retain a
reference to the surface outside the current stack context. Additional
if something calls RasterImage::GetImageContainer(AtSize) or
RasterImage::GetFrame(AtSize), it may also have a reference to the
surface for an indetermine period of time.
As such, if an imgFrame is a candidate for recycling, it will wrap
imgFrame::mLockedSurface in a RecyclingSourceSurface. Its job is to
track how many consumers there are still of the surface, so that after
we advance the animation, the decoder will know if there are still
outstanding consumers.
If the surface is still in use, it will block for a finite period of
time (the refresh interval) before giving up on reclaiming the surface,
and will allocate a new surface. The old surface can then remain in
circulation for as long as necessary without further blocking the
animation progression, since we stop recycling that surface/imgFrame.
Differential Revision: https://phabricator.services.mozilla.com/D7511
2018-06-04 02:42:09 +03:00
|
|
|
if (aShouldRecycle) {
|
|
|
|
// If we are recycling then we should always use BGRA for the underlying
|
|
|
|
// surface because if we use BGRX, the next frame composited into the
|
|
|
|
// surface could be BGRA and cause rendering problems.
|
|
|
|
MOZ_ASSERT(mIsFullFrame);
|
|
|
|
MOZ_ASSERT(aPaletteDepth == 0);
|
|
|
|
MOZ_ASSERT(aAnimParams);
|
|
|
|
mFormat = SurfaceFormat::B8G8R8A8;
|
|
|
|
} else {
|
|
|
|
mFormat = aFormat;
|
|
|
|
}
|
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
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
|
|
|
mPaletteDepth = aPaletteDepth;
|
2015-01-08 11:04:31 +03:00
|
|
|
mNonPremult = aNonPremult;
|
Bug 1465619 - Part 6. Add support for recycling to imgFrame. r=tnikkel
Beyond the necessary reinitialization methods, we need to protect
ourselves from recycling a frame that some other entity in the browser
is still using. Generally speaking the animated surface will only be
used in imgFrame::Draw since we don't layerize animated images, which
will be safe. However with OMTP or blob recordings, we could retain a
reference to the surface outside the current stack context. Additional
if something calls RasterImage::GetImageContainer(AtSize) or
RasterImage::GetFrame(AtSize), it may also have a reference to the
surface for an indetermine period of time.
As such, if an imgFrame is a candidate for recycling, it will wrap
imgFrame::mLockedSurface in a RecyclingSourceSurface. Its job is to
track how many consumers there are still of the surface, so that after
we advance the animation, the decoder will know if there are still
outstanding consumers.
If the surface is still in use, it will block for a finite period of
time (the refresh interval) before giving up on reclaiming the surface,
and will allocate a new surface. The old surface can then remain in
circulation for as long as necessary without further blocking the
animation progression, since we stop recycling that surface/imgFrame.
Differential Revision: https://phabricator.services.mozilla.com/D7511
2018-06-04 02:42:09 +03:00
|
|
|
mShouldRecycle = aShouldRecycle;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
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.
|
2016-06-01 21:59:47 +03:00
|
|
|
size_t dataSize = PaletteDataLength() + mFrameRect.Area();
|
|
|
|
mPalettedImageData =
|
|
|
|
static_cast<uint8_t*>(calloc(dataSize, sizeof(uint8_t)));
|
2015-03-31 20:48:00 +03:00
|
|
|
if (!mPalettedImageData) {
|
2016-06-01 21:59:47 +03:00
|
|
|
NS_WARNING("Call to calloc 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 {
|
2017-01-18 21:31:20 +03:00
|
|
|
MOZ_ASSERT(!mLockedSurface, "Called imgFrame::InitForDecoder() twice?");
|
2014-09-15 02:22:45 +04:00
|
|
|
|
2018-05-29 15:36:11 +03:00
|
|
|
bool postFirstFrame = aAnimParams && aAnimParams->mFrameNum > 0;
|
2018-09-17 22:06:29 +03:00
|
|
|
mRawSurface = AllocateBufferForImage(mFrameRect.Size(), mFormat,
|
|
|
|
postFirstFrame, mIsFullFrame);
|
2017-01-18 21:31:20 +03:00
|
|
|
if (!mRawSurface) {
|
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
|
|
|
}
|
2016-07-01 04:59:29 +03:00
|
|
|
|
2017-01-18 21:31:20 +03:00
|
|
|
mLockedSurface =
|
|
|
|
CreateLockedSurface(mRawSurface, mFrameRect.Size(), mFormat);
|
|
|
|
if (!mLockedSurface) {
|
|
|
|
NS_WARNING("Failed to create LockedSurface");
|
2016-07-01 04:59:29 +03:00
|
|
|
mAborted = true;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2017-02-14 06:28:45 +03:00
|
|
|
|
|
|
|
if (!ClearSurface(mRawSurface, mFrameRect.Size(), mFormat)) {
|
|
|
|
NS_WARNING("Could not clear allocated buffer");
|
|
|
|
mAborted = true;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2014-09-15 02:22:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
Bug 1465619 - Part 6. Add support for recycling to imgFrame. r=tnikkel
Beyond the necessary reinitialization methods, we need to protect
ourselves from recycling a frame that some other entity in the browser
is still using. Generally speaking the animated surface will only be
used in imgFrame::Draw since we don't layerize animated images, which
will be safe. However with OMTP or blob recordings, we could retain a
reference to the surface outside the current stack context. Additional
if something calls RasterImage::GetImageContainer(AtSize) or
RasterImage::GetFrame(AtSize), it may also have a reference to the
surface for an indetermine period of time.
As such, if an imgFrame is a candidate for recycling, it will wrap
imgFrame::mLockedSurface in a RecyclingSourceSurface. Its job is to
track how many consumers there are still of the surface, so that after
we advance the animation, the decoder will know if there are still
outstanding consumers.
If the surface is still in use, it will block for a finite period of
time (the refresh interval) before giving up on reclaiming the surface,
and will allocate a new surface. The old surface can then remain in
circulation for as long as necessary without further blocking the
animation progression, since we stop recycling that surface/imgFrame.
Differential Revision: https://phabricator.services.mozilla.com/D7511
2018-06-04 02:42:09 +03:00
|
|
|
nsresult imgFrame::InitForDecoderRecycle(const AnimationParams& aAnimParams) {
|
|
|
|
// We want to recycle this frame, but there is no guarantee that consumers are
|
|
|
|
// done with it in a timely manner. Let's ensure they are done with it first.
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
|
|
|
|
MOZ_ASSERT(mIsFullFrame);
|
|
|
|
MOZ_ASSERT(mLockCount > 0);
|
|
|
|
MOZ_ASSERT(mLockedSurface);
|
2019-01-10 15:42:12 +03:00
|
|
|
|
|
|
|
if (!mShouldRecycle) {
|
|
|
|
// This frame either was never marked as recyclable, or the flag was cleared
|
|
|
|
// for a caller which does not support recycling.
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
Bug 1465619 - Part 6. Add support for recycling to imgFrame. r=tnikkel
Beyond the necessary reinitialization methods, we need to protect
ourselves from recycling a frame that some other entity in the browser
is still using. Generally speaking the animated surface will only be
used in imgFrame::Draw since we don't layerize animated images, which
will be safe. However with OMTP or blob recordings, we could retain a
reference to the surface outside the current stack context. Additional
if something calls RasterImage::GetImageContainer(AtSize) or
RasterImage::GetFrame(AtSize), it may also have a reference to the
surface for an indetermine period of time.
As such, if an imgFrame is a candidate for recycling, it will wrap
imgFrame::mLockedSurface in a RecyclingSourceSurface. Its job is to
track how many consumers there are still of the surface, so that after
we advance the animation, the decoder will know if there are still
outstanding consumers.
If the surface is still in use, it will block for a finite period of
time (the refresh interval) before giving up on reclaiming the surface,
and will allocate a new surface. The old surface can then remain in
circulation for as long as necessary without further blocking the
animation progression, since we stop recycling that surface/imgFrame.
Differential Revision: https://phabricator.services.mozilla.com/D7511
2018-06-04 02:42:09 +03:00
|
|
|
|
|
|
|
if (mRecycleLockCount > 0) {
|
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
// We should never be both decoding and recycling on the main thread. Sync
|
|
|
|
// decoding can only be used to produce the first set of frames. Those
|
|
|
|
// either never use recycling because advancing was blocked (main thread
|
|
|
|
// is busy) or we were auto-advancing (to seek to a frame) and the frames
|
|
|
|
// were never accessed (and thus cannot have recycle locks).
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Recycling/decoding on the main thread?");
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We don't want to wait forever to reclaim the frame because we have no
|
|
|
|
// idea why it is still held. It is possibly due to OMTP. Since we are off
|
|
|
|
// the main thread, and we generally have frames already buffered for the
|
|
|
|
// animation, we can afford to wait a short period of time to hopefully
|
|
|
|
// complete the transaction and reclaim the buffer.
|
|
|
|
//
|
|
|
|
// We choose to wait for, at most, the refresh driver interval, so that we
|
|
|
|
// won't skip more than one frame. If the frame is still in use due to
|
|
|
|
// outstanding transactions, we are already skipping frames. If the frame
|
|
|
|
// is still in use for some other purpose, it won't be returned to the pool
|
|
|
|
// and its owner can hold onto it forever without additional impact here.
|
|
|
|
TimeDuration timeout =
|
|
|
|
TimeDuration::FromMilliseconds(nsRefreshDriver::DefaultInterval());
|
|
|
|
while (true) {
|
|
|
|
TimeStamp start = TimeStamp::Now();
|
|
|
|
mMonitor.Wait(timeout);
|
|
|
|
if (mRecycleLockCount == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeDuration delta = TimeStamp::Now() - start;
|
|
|
|
if (delta >= timeout) {
|
|
|
|
// We couldn't secure the frame for recycling. It will allocate a new
|
|
|
|
// frame instead.
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
timeout -= delta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mBlendRect = aAnimParams.mBlendRect;
|
|
|
|
mTimeout = aAnimParams.mTimeout;
|
|
|
|
mBlendMethod = aAnimParams.mBlendMethod;
|
|
|
|
mDisposalMethod = aAnimParams.mDisposalMethod;
|
|
|
|
mDirtyRect = mFrameRect;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-01-18 09:56:43 +03:00
|
|
|
nsresult imgFrame::InitWithDrawable(
|
|
|
|
gfxDrawable* aDrawable, const nsIntSize& aSize, const SurfaceFormat aFormat,
|
|
|
|
SamplingFilter aSamplingFilter, uint32_t aImageFlags,
|
|
|
|
gfx::BackendType aBackend, DrawTarget* aTargetDT) {
|
2014-09-15 02:22:45 +04:00
|
|
|
// Assert for properties that should be verified by decoders,
|
|
|
|
// warn for properties related to bad content.
|
2018-09-21 03:22:00 +03:00
|
|
|
if (!SurfaceCache::IsLegalSize(aSize)) {
|
2014-09-15 02:22:45 +04:00
|
|
|
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;
|
2016-05-27 08:19:38 +03:00
|
|
|
mFrameRect = IntRect(IntPoint(0, 0), aSize);
|
2014-09-15 02:22:45 +04:00
|
|
|
|
|
|
|
mFormat = aFormat;
|
|
|
|
mPaletteDepth = 0;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DrawTarget> target;
|
2014-09-15 02:22:45 +04:00
|
|
|
|
2017-11-24 16:10:03 +03:00
|
|
|
bool canUseDataSurface = Factory::DoesBackendSupportDataDrawtarget(aBackend);
|
2014-09-15 02:22:45 +04:00
|
|
|
if (canUseDataSurface) {
|
|
|
|
// It's safe to use data surfaces for content on this platform, so we can
|
|
|
|
// get away with using volatile buffers.
|
2017-01-18 21:31:20 +03:00
|
|
|
MOZ_ASSERT(!mLockedSurface, "Called imgFrame::InitWithDrawable() twice?");
|
2014-09-15 02:22:45 +04:00
|
|
|
|
2017-01-18 21:31:20 +03:00
|
|
|
mRawSurface = AllocateBufferForImage(mFrameRect.Size(), mFormat);
|
|
|
|
if (!mRawSurface) {
|
2015-01-12 06:28:02 +03:00
|
|
|
mAborted = true;
|
2014-09-15 02:22:45 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2017-01-18 21:31:20 +03:00
|
|
|
mLockedSurface =
|
|
|
|
CreateLockedSurface(mRawSurface, mFrameRect.Size(), mFormat);
|
|
|
|
if (!mLockedSurface) {
|
|
|
|
NS_WARNING("Failed to create LockedSurface");
|
2015-01-12 06:28:02 +03:00
|
|
|
mAborted = true;
|
2014-09-15 02:22:45 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2016-07-01 04:59:29 +03:00
|
|
|
|
2017-01-18 21:31:20 +03:00
|
|
|
if (!ClearSurface(mRawSurface, mFrameRect.Size(), mFormat)) {
|
2016-07-01 04:59:29 +03:00
|
|
|
NS_WARNING("Could not clear allocated buffer");
|
|
|
|
mAborted = true;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2016-08-12 00:54:08 +03:00
|
|
|
target = gfxPlatform::CreateDrawTargetForData(
|
2017-01-18 21:31:20 +03:00
|
|
|
mLockedSurface->GetData(), mFrameRect.Size(), mLockedSurface->Stride(),
|
2016-08-12 00:54:08 +03:00
|
|
|
mFormat);
|
2014-09-15 02:22:45 +04:00
|
|
|
} 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?");
|
|
|
|
|
2019-01-18 09:56:43 +03:00
|
|
|
if (aTargetDT && !gfxVars::UseWebRender()) {
|
|
|
|
target = aTargetDT->CreateSimilarDrawTarget(mFrameRect.Size(), mFormat);
|
2016-09-15 14:53:12 +03:00
|
|
|
} else {
|
2019-01-18 09:56:43 +03:00
|
|
|
if (gfxPlatform::GetPlatform()->SupportsAzureContentForType(aBackend)) {
|
|
|
|
target = gfxPlatform::GetPlatform()->CreateDrawTargetForBackend(
|
|
|
|
aBackend, mFrameRect.Size(), mFormat);
|
|
|
|
} else {
|
|
|
|
target = gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget(
|
|
|
|
mFrameRect.Size(), mFormat);
|
|
|
|
}
|
2016-09-15 14:53:12 +03:00
|
|
|
}
|
2014-09-15 02:22:45 +04:00
|
|
|
}
|
|
|
|
|
2016-04-12 22:18:11 +03:00
|
|
|
if (!target || !target->IsValid()) {
|
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.
|
2016-06-07 02:39:56 +03:00
|
|
|
RefPtr<gfxContext> ctx = gfxContext::CreateOrNull(target);
|
2016-05-27 08:19:38 +03:00
|
|
|
MOZ_ASSERT(ctx); // Already checked the draw target above.
|
2017-06-28 18:41:21 +03:00
|
|
|
gfxUtils::DrawPixelSnapped(ctx, aDrawable, SizeDouble(mFrameRect.Size()),
|
2016-05-27 08:19:38 +03:00
|
|
|
ImageRegion::Create(ThebesRect(mFrameRect)),
|
2016-05-25 19:01:18 +03:00
|
|
|
mFormat, aSamplingFilter, aImageFlags);
|
2014-09-15 02:22:45 +04:00
|
|
|
|
2017-01-18 21:31:20 +03:00
|
|
|
if (canUseDataSurface && !mLockedSurface) {
|
2014-09-15 02:22:45 +04:00
|
|
|
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();
|
2017-02-08 23:48:59 +03:00
|
|
|
} else {
|
|
|
|
FinalizeSurface();
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
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();
|
2016-03-24 03:31:42 +03:00
|
|
|
mFinished = true;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
MOZ_ASSERT(AreAllPixelsWritten());
|
|
|
|
#endif
|
2015-01-12 06:28:02 +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
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-09-15 14:53:12 +03:00
|
|
|
nsresult imgFrame::Optimize(DrawTarget* aTarget) {
|
2013-05-24 17:52:34 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-12 06:28:02 +03:00
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2016-09-15 14:53:12 +03:00
|
|
|
if (mLockCount > 0 || !mOptimizable) {
|
|
|
|
// Don't optimize right now.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-05-24 17:52:34 +04:00
|
|
|
|
2016-06-20 16:46:00 +03:00
|
|
|
// Check whether image optimization is disabled -- not thread safe!
|
|
|
|
static bool gDisableOptimize = false;
|
|
|
|
static bool hasCheckedOptimize = false;
|
|
|
|
if (!hasCheckedOptimize) {
|
|
|
|
if (PR_GetEnv("MOZ_DISABLE_IMAGE_OPTIMIZE")) {
|
|
|
|
gDisableOptimize = true;
|
|
|
|
}
|
|
|
|
hasCheckedOptimize = true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2016-09-15 14:53:12 +03:00
|
|
|
if (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
|
|
|
|
2016-07-30 23:41:57 +03:00
|
|
|
if (mPalettedImageData || mOptSurface) {
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
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
|
|
|
|
2016-07-30 23:41:57 +03:00
|
|
|
// XXX(seth): It's currently unclear if there's any reason why we can't
|
|
|
|
// optimize non-premult surfaces. We should look into removing this.
|
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
|
|
|
}
|
2019-01-18 09:56:43 +03:00
|
|
|
if (!gfxVars::UseWebRender()) {
|
|
|
|
mOptSurface = aTarget->OptimizeSourceSurface(mLockedSurface);
|
|
|
|
} else {
|
2019-01-24 11:11:00 +03:00
|
|
|
mOptSurface = gfxPlatform::GetPlatform()
|
|
|
|
->ScreenReferenceDrawTarget()
|
|
|
|
->OptimizeSourceSurface(mLockedSurface);
|
2019-01-18 09:56:43 +03:00
|
|
|
}
|
2017-01-18 21:31:20 +03:00
|
|
|
if (mOptSurface == mLockedSurface) {
|
2014-04-20 05:28:38 +04:00
|
|
|
mOptSurface = nullptr;
|
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
|
|
|
|
|
|
|
if (mOptSurface) {
|
2017-01-18 21:31:20 +03:00
|
|
|
// There's no reason to keep our original surface around if we have an
|
2016-08-10 00:47:26 +03:00
|
|
|
// optimized surface. Release our reference to it. This will leave
|
2017-01-18 21:31:20 +03:00
|
|
|
// |mLockedSurface| as the only thing keeping it alive, so it'll get freed
|
|
|
|
// below.
|
|
|
|
mRawSurface = 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
|
|
|
}
|
|
|
|
|
2017-01-18 21:31:20 +03:00
|
|
|
// Release all strong references to the surface's memory. If the underlying
|
|
|
|
// surface is volatile, this will allow the operating system to free the
|
|
|
|
// memory if it needs to.
|
|
|
|
mLockedSurface = nullptr;
|
2016-09-15 14:53:12 +03:00
|
|
|
mOptimizable = false;
|
2014-09-19 06:26:01 +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-11 04:06:45 +04:00
|
|
|
DrawableFrameRef imgFrame::DrawableRef() { return DrawableFrameRef(this); }
|
|
|
|
|
2018-05-29 15:36:12 +03:00
|
|
|
RawAccessFrameRef imgFrame::RawAccessRef(bool aOnlyFinished /*= false*/) {
|
|
|
|
return RawAccessFrameRef(this, aOnlyFinished);
|
2014-09-11 04:06:45 +04:00
|
|
|
}
|
|
|
|
|
2018-05-31 02:35:40 +03:00
|
|
|
void imgFrame::SetRawAccessOnly() {
|
|
|
|
AssertImageDataLocked();
|
|
|
|
|
|
|
|
// Lock our data and throw away the key.
|
|
|
|
LockImageData(false);
|
|
|
|
}
|
|
|
|
|
2010-08-13 17:30:02 +04:00
|
|
|
imgFrame::SurfaceWithFormat imgFrame::SurfaceForDrawing(
|
2016-07-31 00:49:03 +03:00
|
|
|
bool aDoPartialDecode, bool aDoTile, ImageRegion& aRegion,
|
2014-04-20 05:28:38 +04:00
|
|
|
SourceSurface* aSurface) {
|
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
|
|
|
|
2016-07-31 00:49:03 +03:00
|
|
|
if (!aDoPartialDecode) {
|
|
|
|
return SurfaceWithFormat(new gfxSurfaceDrawable(aSurface, mImageSize),
|
2016-10-01 06:11:59 +03:00
|
|
|
mFormat);
|
2010-08-13 17:30:02 +04:00
|
|
|
}
|
|
|
|
|
2017-12-21 00:46:28 +03:00
|
|
|
gfxRect available =
|
|
|
|
gfxRect(mDecoded.X(), mDecoded.Y(), mDecoded.Width(), mDecoded.Height());
|
2010-08-13 17:30:02 +04:00
|
|
|
|
2016-07-30 23:41:57 +03:00
|
|
|
if (aDoTile) {
|
2010-08-13 17:30:02 +04:00
|
|
|
// 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 =
|
2016-07-31 00:49:03 +03:00
|
|
|
gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget(
|
|
|
|
mImageSize, 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
|
|
|
|
2016-07-30 23:41:57 +03:00
|
|
|
SurfacePattern pattern(aSurface, aRegion.GetExtendMode(),
|
2017-12-21 00:46:28 +03:00
|
|
|
Matrix::Translation(mDecoded.X(), mDecoded.Y()));
|
2016-07-30 23:41:57 +03:00
|
|
|
target->FillRect(ToRect(aRegion.Intersect(available).Rect()), pattern);
|
2012-03-24 02:10:50 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurface> newsurf = target->Snapshot();
|
2016-07-31 00:49:03 +03:00
|
|
|
return SurfaceWithFormat(new gfxSurfaceDrawable(newsurf, mImageSize),
|
2015-03-31 20:48:00 +03:00
|
|
|
target->GetFormat());
|
2010-08-13 17:30:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Not tiling, and we have a surface, so we can account for
|
2016-07-31 00:49:03 +03:00
|
|
|
// a partial decode just by twiddling parameters.
|
|
|
|
aRegion = aRegion.Intersect(available);
|
2017-08-14 15:29:56 +03:00
|
|
|
IntSize availableSize(mDecoded.Width(), mDecoded.Height());
|
2016-07-31 00:49:03 +03:00
|
|
|
|
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,
|
2017-01-03 08:53:22 +03:00
|
|
|
SamplingFilter aSamplingFilter, uint32_t aImageFlags,
|
|
|
|
float aOpacity) {
|
Bug 1375392 - Tweak the PROFILER_LABEL* macros. r=mstange.
This patch makes the following changes to the macros.
- Removes PROFILER_LABEL_FUNC. It's only suitable for use in functions outside
classes, due to PROFILER_FUNCTION_NAME not getting class names, and it was
mostly misused.
- Removes PROFILER_FUNCTION_NAME. It's no longer used, and __func__ is
universally available now anyway.
- Combines the first two string literal arguments of PROFILER_LABEL and
PROFILER_LABEL_DYNAMIC into a single argument. There was no good reason for
them to be separate, and it forced a '::' in the label, which isn't always
appropriate. Also, the meaning of the "name_space" argument was interpreted
in an interesting variety of ways.
- Adds an "AUTO_" prefix to PROFILER_LABEL and PROFILER_LABEL_DYNAMIC, to make
it clearer they construct RAII objects rather than just being function calls.
(I myself have screwed up the scoping because of this in the past.)
- Fills in the 'js::ProfileEntry::Category::' qualifier within the macro, so
the caller doesn't need to. This makes a *lot* more of the uses fit onto a
single line.
The patch also makes the following changes to the macro uses (beyond those
required by the changes described above).
- Fixes a bunch of labels that had gotten out of sync with the name of the
class and/or function that encloses them.
- Removes a useless PROFILER_LABEL use within a trivial scope in
EventStateManager::DispatchMouseOrPointerEvent(). It clearly wasn't serving
any useful purpose. It also serves as extra evidence that the AUTO_ prefix is
a good idea.
- Tweaks DecodePool::SyncRunIf{Preferred,Possible} so that the labelling is
done within them, instead of at their callsites, because that's a more
standard way of doing things.
--HG--
extra : rebase_source : 318d1bc6fc1425a94aacbf489dd46e4f83211de4
2017-06-22 10:08:53 +03:00
|
|
|
AUTO_PROFILER_LABEL("imgFrame::Draw", GRAPHICS);
|
2014-05-24 01:12:29 +04:00
|
|
|
|
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!");
|
2016-07-31 00:49:03 +03:00
|
|
|
MOZ_ASSERT(mFrameRect.IsEqualEdges(IntRect(IntPoint(), mImageSize)),
|
|
|
|
"Directly drawing an image with a non-trivial frame rect!");
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
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
|
|
|
|
2016-07-31 00:49:03 +03:00
|
|
|
if (mPalettedImageData) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Directly drawing a paletted image!");
|
|
|
|
return false;
|
|
|
|
}
|
2015-01-08 11:04:31 +03:00
|
|
|
|
2018-06-04 02:37:17 +03:00
|
|
|
// Perform the draw and freeing of the surface outside the lock. We want to
|
Bug 1465619 - Part 6. Add support for recycling to imgFrame. r=tnikkel
Beyond the necessary reinitialization methods, we need to protect
ourselves from recycling a frame that some other entity in the browser
is still using. Generally speaking the animated surface will only be
used in imgFrame::Draw since we don't layerize animated images, which
will be safe. However with OMTP or blob recordings, we could retain a
reference to the surface outside the current stack context. Additional
if something calls RasterImage::GetImageContainer(AtSize) or
RasterImage::GetFrame(AtSize), it may also have a reference to the
surface for an indetermine period of time.
As such, if an imgFrame is a candidate for recycling, it will wrap
imgFrame::mLockedSurface in a RecyclingSourceSurface. Its job is to
track how many consumers there are still of the surface, so that after
we advance the animation, the decoder will know if there are still
outstanding consumers.
If the surface is still in use, it will block for a finite period of
time (the refresh interval) before giving up on reclaiming the surface,
and will allocate a new surface. The old surface can then remain in
circulation for as long as necessary without further blocking the
animation progression, since we stop recycling that surface/imgFrame.
Differential Revision: https://phabricator.services.mozilla.com/D7511
2018-06-04 02:42:09 +03:00
|
|
|
// avoid contention with the decoder if we can. The surface may also attempt
|
|
|
|
// to relock the monitor if it is freed (e.g. RecyclingSourceSurface).
|
2018-06-04 02:37:17 +03:00
|
|
|
RefPtr<SourceSurface> surf;
|
|
|
|
SurfaceWithFormat surfaceResult;
|
|
|
|
ImageRegion region(aRegion);
|
|
|
|
gfxRect imageRect(0, 0, mImageSize.width, mImageSize.height);
|
2014-11-27 00:22:10 +03:00
|
|
|
|
2018-06-04 02:37:17 +03:00
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
2016-09-15 14:53:12 +03:00
|
|
|
|
2018-06-04 02:37:17 +03:00
|
|
|
// Possibly convert this image into a GPU texture, this may also cause our
|
|
|
|
// mLockedSurface to be released and the OS to release the underlying
|
|
|
|
// memory.
|
|
|
|
Optimize(aContext->GetDrawTarget());
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
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
|
|
|
|
2018-06-04 02:37:17 +03:00
|
|
|
bool doPartialDecode = !AreAllPixelsWritten();
|
2014-03-02 20:17:26 +04:00
|
|
|
|
Bug 1465619 - Part 6. Add support for recycling to imgFrame. r=tnikkel
Beyond the necessary reinitialization methods, we need to protect
ourselves from recycling a frame that some other entity in the browser
is still using. Generally speaking the animated surface will only be
used in imgFrame::Draw since we don't layerize animated images, which
will be safe. However with OMTP or blob recordings, we could retain a
reference to the surface outside the current stack context. Additional
if something calls RasterImage::GetImageContainer(AtSize) or
RasterImage::GetFrame(AtSize), it may also have a reference to the
surface for an indetermine period of time.
As such, if an imgFrame is a candidate for recycling, it will wrap
imgFrame::mLockedSurface in a RecyclingSourceSurface. Its job is to
track how many consumers there are still of the surface, so that after
we advance the animation, the decoder will know if there are still
outstanding consumers.
If the surface is still in use, it will block for a finite period of
time (the refresh interval) before giving up on reclaiming the surface,
and will allocate a new surface. The old surface can then remain in
circulation for as long as necessary without further blocking the
animation progression, since we stop recycling that surface/imgFrame.
Differential Revision: https://phabricator.services.mozilla.com/D7511
2018-06-04 02:42:09 +03:00
|
|
|
// Most draw targets will just use the surface only during DrawPixelSnapped
|
|
|
|
// but captures/recordings will retain a reference outside this stack
|
|
|
|
// context. While in theory a decoder thread could be trying to recycle this
|
|
|
|
// frame at this very moment, in practice the only way we can get here is if
|
|
|
|
// this frame is the current frame of the animation. Since we can only
|
|
|
|
// advance on the main thread, we know nothing else will try to use it.
|
|
|
|
DrawTarget* drawTarget = aContext->GetDrawTarget();
|
2019-01-10 15:42:12 +03:00
|
|
|
bool recording = drawTarget->GetBackendType() == BackendType::RECORDING;
|
|
|
|
bool temporary = !drawTarget->IsCaptureDT() && !recording;
|
Bug 1465619 - Part 6. Add support for recycling to imgFrame. r=tnikkel
Beyond the necessary reinitialization methods, we need to protect
ourselves from recycling a frame that some other entity in the browser
is still using. Generally speaking the animated surface will only be
used in imgFrame::Draw since we don't layerize animated images, which
will be safe. However with OMTP or blob recordings, we could retain a
reference to the surface outside the current stack context. Additional
if something calls RasterImage::GetImageContainer(AtSize) or
RasterImage::GetFrame(AtSize), it may also have a reference to the
surface for an indetermine period of time.
As such, if an imgFrame is a candidate for recycling, it will wrap
imgFrame::mLockedSurface in a RecyclingSourceSurface. Its job is to
track how many consumers there are still of the surface, so that after
we advance the animation, the decoder will know if there are still
outstanding consumers.
If the surface is still in use, it will block for a finite period of
time (the refresh interval) before giving up on reclaiming the surface,
and will allocate a new surface. The old surface can then remain in
circulation for as long as necessary without further blocking the
animation progression, since we stop recycling that surface/imgFrame.
Differential Revision: https://phabricator.services.mozilla.com/D7511
2018-06-04 02:42:09 +03:00
|
|
|
RefPtr<SourceSurface> surf = GetSourceSurfaceInternal(temporary);
|
2018-06-04 02:37:17 +03:00
|
|
|
if (!surf) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-23 19:17:35 +03:00
|
|
|
|
2018-06-04 02:37:17 +03:00
|
|
|
bool doTile = !imageRect.Contains(aRegion.Rect()) &&
|
|
|
|
!(aImageFlags & imgIContainer::FLAG_CLAMP);
|
|
|
|
|
|
|
|
surfaceResult = SurfaceForDrawing(doPartialDecode, doTile, region, surf);
|
2019-01-10 15:42:12 +03:00
|
|
|
|
|
|
|
// If we are recording, then we cannot recycle the surface. The blob
|
|
|
|
// rasterizer is not properly synchronized for recycling in the compositor
|
|
|
|
// process. The easiest thing to do is just mark the frames it consumes as
|
|
|
|
// non-recyclable.
|
|
|
|
if (recording && surfaceResult.IsValid()) {
|
|
|
|
mShouldRecycle = false;
|
|
|
|
}
|
2018-06-04 02:37:17 +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
|
|
|
|
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,
|
2017-01-03 08:53:22 +03:00
|
|
|
aSamplingFilter, aImageFlags, aOpacity);
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
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
|
|
|
}
|
2017-02-08 23:48:59 +03: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) {
|
2015-01-12 06:28:02 +03:00
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
2013-07-04 22:45:57 +04:00
|
|
|
|
2016-05-27 08:19:38 +03:00
|
|
|
// Clamp to the frame rect to ensure that decoder bugs don't result in a
|
|
|
|
// decoded rect that extends outside the bounds of the frame rect.
|
2018-07-12 18:43:12 +03:00
|
|
|
IntRect updateRect = mFrameRect.Intersect(aUpdateRect);
|
|
|
|
if (updateRect.IsEmpty()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDecoded.UnionRect(mDecoded, updateRect);
|
|
|
|
|
|
|
|
// Paletted images cannot invalidate.
|
|
|
|
if (mPalettedImageData) {
|
|
|
|
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-21 05:50:15 +04:00
|
|
|
|
2017-12-01 14:59:21 +03:00
|
|
|
// Update our invalidation counters for any consumers watching for changes
|
|
|
|
// in the surface.
|
|
|
|
if (mRawSurface) {
|
2018-07-12 18:43:12 +03:00
|
|
|
mRawSurface->Invalidate(updateRect);
|
2017-12-01 14:59:21 +03:00
|
|
|
}
|
|
|
|
if (mLockedSurface && mRawSurface != mLockedSurface) {
|
2018-07-12 18:43:12 +03:00
|
|
|
mLockedSurface->Invalidate(updateRect);
|
2017-12-01 14:59:21 +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
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-01-12 06:28:02 +03:00
|
|
|
void imgFrame::Finish(Opacity aFrameOpacity /* = Opacity::SOME_TRANSPARENCY */,
|
2017-02-08 23:48:59 +03:00
|
|
|
bool aFinalize /* = true */) {
|
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");
|
|
|
|
|
2018-07-12 18:43:12 +03:00
|
|
|
if (mPalettedImageData) {
|
|
|
|
ImageUpdatedInternal(mFrameRect);
|
|
|
|
} else if (!mDecoded.IsEqualEdges(mFrameRect)) {
|
|
|
|
// The decoder should have produced rows starting from either the bottom or
|
|
|
|
// the top of the image. We need to calculate the region for which we have
|
|
|
|
// not yet invalidated.
|
|
|
|
IntRect delta(0, 0, mFrameRect.width, 0);
|
|
|
|
if (mDecoded.y == 0) {
|
|
|
|
delta.y = mDecoded.height;
|
|
|
|
delta.height = mFrameRect.height - mDecoded.height;
|
|
|
|
} else if (mDecoded.y + mDecoded.height == mFrameRect.height) {
|
|
|
|
delta.height = mFrameRect.height - mDecoded.y;
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Decoder only updated middle of image!");
|
|
|
|
delta = mFrameRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageUpdatedInternal(delta);
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(mDecoded.IsEqualEdges(mFrameRect));
|
2017-02-08 23:48:59 +03:00
|
|
|
|
|
|
|
if (aFinalize) {
|
|
|
|
FinalizeSurfaceInternal();
|
|
|
|
}
|
|
|
|
|
2016-03-24 03:31:42 +03:00
|
|
|
mFinished = true;
|
|
|
|
|
|
|
|
// The image is now complete, wake up anyone who's waiting.
|
|
|
|
mMonitor.NotifyAll();
|
2015-01-08 11:04:31 +03:00
|
|
|
}
|
|
|
|
|
2015-03-31 20:48:00 +03:00
|
|
|
uint32_t imgFrame::GetImageBytesPerRow() const {
|
2015-01-12 06:28:02 +03:00
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
2015-01-08 11:04:31 +03:00
|
|
|
|
2017-01-18 21:31:20 +03:00
|
|
|
if (mRawSurface) {
|
2017-08-14 15:29:56 +03:00
|
|
|
return mFrameRect.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) {
|
2017-08-14 15:29:56 +03:00
|
|
|
return mFrameRect.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 {
|
2017-08-14 15:29:56 +03:00
|
|
|
return GetImageBytesPerRow() * mFrameRect.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 {
|
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");
|
|
|
|
|
2017-01-18 21:31:20 +03:00
|
|
|
if (mLockedSurface) {
|
2017-02-08 23:48:59 +03:00
|
|
|
// TODO: This is okay for now because we only realloc shared surfaces on
|
|
|
|
// the main thread after decoding has finished, but if animations want to
|
|
|
|
// read frame data off the main thread, we will need to reconsider this.
|
2017-01-18 21:31:20 +03:00
|
|
|
*aData = mLockedSurface->GetData();
|
2015-03-31 20:48:00 +03:00
|
|
|
MOZ_ASSERT(
|
|
|
|
*aData,
|
2017-01-18 21:31:20 +03:00
|
|
|
"mLockedSurface is non-null, but GetData 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,
|
2017-01-18 21:31:20 +03:00
|
|
|
"Have neither mLockedSurface 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 {
|
|
|
|
uint8_t* data;
|
2013-06-14 17:42:01 +04:00
|
|
|
uint32_t length;
|
|
|
|
GetImageData(&data, &length);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
bool imgFrame::GetIsPaletted() const { 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 {
|
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;
|
|
|
|
}
|
|
|
|
|
2018-05-29 15:36:12 +03:00
|
|
|
uint8_t* imgFrame::LockImageData(bool aOnlyFinished) {
|
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");
|
2018-05-29 15:36:12 +03:00
|
|
|
if (mLockCount < 0 || (aOnlyFinished && !mFinished)) {
|
|
|
|
return nullptr;
|
2012-09-26 19:33:06 +04:00
|
|
|
}
|
|
|
|
|
2018-05-29 15:36:12 +03:00
|
|
|
uint8_t* data;
|
|
|
|
if (mPalettedImageData) {
|
|
|
|
data = mPalettedImageData;
|
|
|
|
} else if (mLockedSurface) {
|
|
|
|
data = mLockedSurface->GetData();
|
|
|
|
} else {
|
|
|
|
data = nullptr;
|
2015-01-08 11:04:31 +03:00
|
|
|
}
|
|
|
|
|
2018-05-29 15:36:12 +03:00
|
|
|
// If the raw data is still available, we should get a valid pointer for it.
|
|
|
|
if (!data) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("It's illegal to re-lock an optimized imgFrame");
|
|
|
|
return nullptr;
|
2015-01-08 11:04:31 +03:00
|
|
|
}
|
|
|
|
|
2018-05-29 15:36:12 +03:00
|
|
|
++mLockCount;
|
|
|
|
return data;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
}
|
|
|
|
|
2015-01-08 11:04:31 +03:00
|
|
|
void imgFrame::AssertImageDataLocked() const {
|
|
|
|
#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
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-03-24 03:31:42 +03:00
|
|
|
MOZ_ASSERT(mLockCount > 1 || mFinished || mAborted,
|
|
|
|
"Should have Finish()'d or aborted before unlocking");
|
2015-01-12 06:28:02 +03: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
|
|
|
}
|
|
|
|
|
2017-02-08 23:48:59 +03:00
|
|
|
void imgFrame::FinalizeSurface() {
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
FinalizeSurfaceInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
void imgFrame::FinalizeSurfaceInternal() {
|
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
|
|
|
|
|
|
|
// Not all images will have mRawSurface to finalize (i.e. paletted images).
|
2018-10-01 21:47:17 +03:00
|
|
|
if (mShouldRecycle || !mRawSurface ||
|
|
|
|
mRawSurface->GetType() != SurfaceType::DATA_SHARED) {
|
2017-02-08 23:48:59 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto sharedSurf = static_cast<SourceSurfaceSharedData*>(mRawSurface.get());
|
|
|
|
sharedSurf->Finalize();
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<SourceSurface> imgFrame::GetSourceSurface() {
|
2015-01-12 06:28:02 +03:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
Bug 1465619 - Part 6. Add support for recycling to imgFrame. r=tnikkel
Beyond the necessary reinitialization methods, we need to protect
ourselves from recycling a frame that some other entity in the browser
is still using. Generally speaking the animated surface will only be
used in imgFrame::Draw since we don't layerize animated images, which
will be safe. However with OMTP or blob recordings, we could retain a
reference to the surface outside the current stack context. Additional
if something calls RasterImage::GetImageContainer(AtSize) or
RasterImage::GetFrame(AtSize), it may also have a reference to the
surface for an indetermine period of time.
As such, if an imgFrame is a candidate for recycling, it will wrap
imgFrame::mLockedSurface in a RecyclingSourceSurface. Its job is to
track how many consumers there are still of the surface, so that after
we advance the animation, the decoder will know if there are still
outstanding consumers.
If the surface is still in use, it will block for a finite period of
time (the refresh interval) before giving up on reclaiming the surface,
and will allocate a new surface. The old surface can then remain in
circulation for as long as necessary without further blocking the
animation progression, since we stop recycling that surface/imgFrame.
Differential Revision: https://phabricator.services.mozilla.com/D7511
2018-06-04 02:42:09 +03:00
|
|
|
return GetSourceSurfaceInternal(/* aTemporary */ false);
|
2015-01-08 11:04:31 +03:00
|
|
|
}
|
|
|
|
|
Bug 1465619 - Part 6. Add support for recycling to imgFrame. r=tnikkel
Beyond the necessary reinitialization methods, we need to protect
ourselves from recycling a frame that some other entity in the browser
is still using. Generally speaking the animated surface will only be
used in imgFrame::Draw since we don't layerize animated images, which
will be safe. However with OMTP or blob recordings, we could retain a
reference to the surface outside the current stack context. Additional
if something calls RasterImage::GetImageContainer(AtSize) or
RasterImage::GetFrame(AtSize), it may also have a reference to the
surface for an indetermine period of time.
As such, if an imgFrame is a candidate for recycling, it will wrap
imgFrame::mLockedSurface in a RecyclingSourceSurface. Its job is to
track how many consumers there are still of the surface, so that after
we advance the animation, the decoder will know if there are still
outstanding consumers.
If the surface is still in use, it will block for a finite period of
time (the refresh interval) before giving up on reclaiming the surface,
and will allocate a new surface. The old surface can then remain in
circulation for as long as necessary without further blocking the
animation progression, since we stop recycling that surface/imgFrame.
Differential Revision: https://phabricator.services.mozilla.com/D7511
2018-06-04 02:42:09 +03:00
|
|
|
already_AddRefed<SourceSurface> imgFrame::GetSourceSurfaceInternal(
|
|
|
|
bool aTemporary) {
|
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
|
|
|
}
|
|
|
|
|
2017-01-18 21:31:20 +03:00
|
|
|
if (mLockedSurface) {
|
Bug 1465619 - Part 6. Add support for recycling to imgFrame. r=tnikkel
Beyond the necessary reinitialization methods, we need to protect
ourselves from recycling a frame that some other entity in the browser
is still using. Generally speaking the animated surface will only be
used in imgFrame::Draw since we don't layerize animated images, which
will be safe. However with OMTP or blob recordings, we could retain a
reference to the surface outside the current stack context. Additional
if something calls RasterImage::GetImageContainer(AtSize) or
RasterImage::GetFrame(AtSize), it may also have a reference to the
surface for an indetermine period of time.
As such, if an imgFrame is a candidate for recycling, it will wrap
imgFrame::mLockedSurface in a RecyclingSourceSurface. Its job is to
track how many consumers there are still of the surface, so that after
we advance the animation, the decoder will know if there are still
outstanding consumers.
If the surface is still in use, it will block for a finite period of
time (the refresh interval) before giving up on reclaiming the surface,
and will allocate a new surface. The old surface can then remain in
circulation for as long as necessary without further blocking the
animation progression, since we stop recycling that surface/imgFrame.
Differential Revision: https://phabricator.services.mozilla.com/D7511
2018-06-04 02:42:09 +03:00
|
|
|
// We don't need to create recycling wrapper for some callers because they
|
|
|
|
// promise to release the surface immediately after.
|
|
|
|
if (!aTemporary && mShouldRecycle) {
|
|
|
|
RefPtr<SourceSurface> surf =
|
|
|
|
new RecyclingSourceSurface(this, mLockedSurface);
|
|
|
|
return surf.forget();
|
|
|
|
}
|
|
|
|
|
2017-01-18 21:31:20 +03:00
|
|
|
RefPtr<SourceSurface> surf(mLockedSurface);
|
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
|
|
|
|
Bug 1465619 - Part 6. Add support for recycling to imgFrame. r=tnikkel
Beyond the necessary reinitialization methods, we need to protect
ourselves from recycling a frame that some other entity in the browser
is still using. Generally speaking the animated surface will only be
used in imgFrame::Draw since we don't layerize animated images, which
will be safe. However with OMTP or blob recordings, we could retain a
reference to the surface outside the current stack context. Additional
if something calls RasterImage::GetImageContainer(AtSize) or
RasterImage::GetFrame(AtSize), it may also have a reference to the
surface for an indetermine period of time.
As such, if an imgFrame is a candidate for recycling, it will wrap
imgFrame::mLockedSurface in a RecyclingSourceSurface. Its job is to
track how many consumers there are still of the surface, so that after
we advance the animation, the decoder will know if there are still
outstanding consumers.
If the surface is still in use, it will block for a finite period of
time (the refresh interval) before giving up on reclaiming the surface,
and will allocate a new surface. The old surface can then remain in
circulation for as long as necessary without further blocking the
animation progression, since we stop recycling that surface/imgFrame.
Differential Revision: https://phabricator.services.mozilla.com/D7511
2018-06-04 02:42:09 +03:00
|
|
|
MOZ_ASSERT(!mShouldRecycle, "Should recycle but no locked surface!");
|
|
|
|
|
2017-02-08 18:51:08 +03:00
|
|
|
if (!mRawSurface) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-01-18 21:31:20 +03:00
|
|
|
return CreateLockedSurface(mRawSurface, mFrameRect.Size(), mFormat);
|
2014-04-20 05:28:38 +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
|
|
|
}
|
|
|
|
|
2016-04-01 20:44:17 +03:00
|
|
|
bool imgFrame::IsAborted() const {
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
return mAborted;
|
|
|
|
}
|
|
|
|
|
2016-03-24 03:31:42 +03:00
|
|
|
bool imgFrame::IsFinished() const {
|
2015-01-12 06:28:02 +03:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2016-03-24 03:31:42 +03:00
|
|
|
return mFinished;
|
2015-01-12 06:28:02 +03:00
|
|
|
}
|
|
|
|
|
2016-03-24 03:31:42 +03:00
|
|
|
void imgFrame::WaitUntilFinished() const {
|
2015-01-12 06:28:02 +03:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
// Return if we're aborted or complete.
|
2016-03-24 03:31:42 +03:00
|
|
|
if (mAborted || mFinished) {
|
2015-01-12 06:28:02 +03:00
|
|
|
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
|
|
|
|
2016-03-24 03:31:42 +03:00
|
|
|
bool imgFrame::AreAllPixelsWritten() const {
|
2015-01-12 06:28:02 +03:00
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
2016-05-27 08:19:38 +03:00
|
|
|
return mDecoded.IsEqualInterior(mFrameRect);
|
2012-03-24 02:10:50 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool imgFrame::GetCompositingFailed() const {
|
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) {
|
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,
|
2018-09-25 16:13:51 +03:00
|
|
|
const AddSizeOfCb& aCallback) const {
|
2015-01-12 06:28:02 +03:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2015-01-08 11:04:31 +03:00
|
|
|
|
2018-09-25 16:13:51 +03:00
|
|
|
AddSizeOfCbData metadata;
|
2015-07-29 07:02:45 +03:00
|
|
|
if (mPalettedImageData) {
|
2018-09-25 16:13:51 +03:00
|
|
|
metadata.heap += aMallocSizeOf(mPalettedImageData);
|
2014-02-25 07:37:51 +04:00
|
|
|
}
|
2017-01-18 21:31:20 +03:00
|
|
|
if (mLockedSurface) {
|
2018-09-25 16:13:51 +03:00
|
|
|
metadata.heap += aMallocSizeOf(mLockedSurface);
|
2010-05-22 08:10:14 +04:00
|
|
|
}
|
2015-07-29 07:02:45 +03:00
|
|
|
if (mOptSurface) {
|
2018-09-25 16:13:51 +03:00
|
|
|
metadata.heap += aMallocSizeOf(mOptSurface);
|
2014-02-25 07:37:51 +04:00
|
|
|
}
|
2017-01-18 21:31:20 +03:00
|
|
|
if (mRawSurface) {
|
2018-09-25 16:13:51 +03:00
|
|
|
metadata.heap += aMallocSizeOf(mRawSurface);
|
|
|
|
mRawSurface->AddSizeOfExcludingThis(aMallocSizeOf, metadata.heap,
|
|
|
|
metadata.nonHeap, metadata.handles,
|
|
|
|
metadata.externalId);
|
2014-04-15 09:24:01 +04:00
|
|
|
}
|
2018-09-25 16:13:51 +03:00
|
|
|
|
|
|
|
aCallback(metadata);
|
2010-05-22 08:10:14 +04:00
|
|
|
}
|
2014-07-10 19:00:31 +04:00
|
|
|
|
Bug 1465619 - Part 6. Add support for recycling to imgFrame. r=tnikkel
Beyond the necessary reinitialization methods, we need to protect
ourselves from recycling a frame that some other entity in the browser
is still using. Generally speaking the animated surface will only be
used in imgFrame::Draw since we don't layerize animated images, which
will be safe. However with OMTP or blob recordings, we could retain a
reference to the surface outside the current stack context. Additional
if something calls RasterImage::GetImageContainer(AtSize) or
RasterImage::GetFrame(AtSize), it may also have a reference to the
surface for an indetermine period of time.
As such, if an imgFrame is a candidate for recycling, it will wrap
imgFrame::mLockedSurface in a RecyclingSourceSurface. Its job is to
track how many consumers there are still of the surface, so that after
we advance the animation, the decoder will know if there are still
outstanding consumers.
If the surface is still in use, it will block for a finite period of
time (the refresh interval) before giving up on reclaiming the surface,
and will allocate a new surface. The old surface can then remain in
circulation for as long as necessary without further blocking the
animation progression, since we stop recycling that surface/imgFrame.
Differential Revision: https://phabricator.services.mozilla.com/D7511
2018-06-04 02:42:09 +03:00
|
|
|
RecyclingSourceSurface::RecyclingSourceSurface(imgFrame* aParent,
|
|
|
|
DataSourceSurface* aSurface)
|
|
|
|
: mParent(aParent), mSurface(aSurface), mType(SurfaceType::DATA) {
|
|
|
|
mParent->mMonitor.AssertCurrentThreadOwns();
|
|
|
|
++mParent->mRecycleLockCount;
|
2018-10-01 21:47:17 +03:00
|
|
|
|
|
|
|
if (aSurface->GetType() == SurfaceType::DATA_SHARED) {
|
|
|
|
mType = SurfaceType::DATA_RECYCLING_SHARED;
|
|
|
|
}
|
Bug 1465619 - Part 6. Add support for recycling to imgFrame. r=tnikkel
Beyond the necessary reinitialization methods, we need to protect
ourselves from recycling a frame that some other entity in the browser
is still using. Generally speaking the animated surface will only be
used in imgFrame::Draw since we don't layerize animated images, which
will be safe. However with OMTP or blob recordings, we could retain a
reference to the surface outside the current stack context. Additional
if something calls RasterImage::GetImageContainer(AtSize) or
RasterImage::GetFrame(AtSize), it may also have a reference to the
surface for an indetermine period of time.
As such, if an imgFrame is a candidate for recycling, it will wrap
imgFrame::mLockedSurface in a RecyclingSourceSurface. Its job is to
track how many consumers there are still of the surface, so that after
we advance the animation, the decoder will know if there are still
outstanding consumers.
If the surface is still in use, it will block for a finite period of
time (the refresh interval) before giving up on reclaiming the surface,
and will allocate a new surface. The old surface can then remain in
circulation for as long as necessary without further blocking the
animation progression, since we stop recycling that surface/imgFrame.
Differential Revision: https://phabricator.services.mozilla.com/D7511
2018-06-04 02:42:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
RecyclingSourceSurface::~RecyclingSourceSurface() {
|
|
|
|
MonitorAutoLock lock(mParent->mMonitor);
|
|
|
|
MOZ_ASSERT(mParent->mRecycleLockCount > 0);
|
|
|
|
if (--mParent->mRecycleLockCount == 0) {
|
|
|
|
mParent->mMonitor.NotifyAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-10 19:00:31 +04:00
|
|
|
} // namespace image
|
|
|
|
} // namespace mozilla
|