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"
|
2019-05-26 17:31:53 +03:00
|
|
|
|
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"
|
2020-03-10 02:36:39 +03:00
|
|
|
#include "mozilla/StaticPrefs_browser.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
|
|
|
|
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) {
|
2019-12-26 00:27:46 +03:00
|
|
|
switch (aSurface->GetType()) {
|
|
|
|
case SurfaceType::DATA_SHARED:
|
|
|
|
case SurfaceType::DATA_ALIGNED: {
|
|
|
|
// Shared memory is never released until the surface itself is released.
|
|
|
|
// Similar for aligned/heap surfaces.
|
|
|
|
RefPtr<DataSourceSurface> surf(aSurface);
|
2017-01-18 21:31:20 +03:00
|
|
|
return surf.forget();
|
|
|
|
}
|
2019-12-26 00:27:46 +03:00
|
|
|
default: {
|
|
|
|
// Volatile memory requires us to map it first, and it is fallible.
|
|
|
|
DataSourceSurface::ScopedMap smap(aSurface,
|
|
|
|
DataSourceSurface::READ_WRITE);
|
|
|
|
if (smap.IsMapped()) {
|
|
|
|
return MakeAndAddRef<SourceSurfaceMappedData>(std::move(smap), size,
|
|
|
|
format);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2014-02-25 07:37:51 +04:00
|
|
|
}
|
|
|
|
|
2017-01-18 21:31:20 +03:00
|
|
|
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.
|
2019-06-26 06:24:21 +03:00
|
|
|
if (aIsAnimated && StaticPrefs::image_mem_animated_use_heap()) {
|
2018-02-22 22:26:29 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lets us avoid too many small images consuming all of the handles. The
|
|
|
|
// actual allocation checks for overflow.
|
2019-09-25 22:24:07 +03:00
|
|
|
int32_t bufferSize = (aStride * aSize.height) / 1024;
|
2019-06-26 06:24:21 +03:00
|
|
|
if (bufferSize < StaticPrefs::image_mem_volatile_min_threshold_kb()) {
|
2018-02-22 22:26:29 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-18 21:31:20 +03:00
|
|
|
static already_AddRefed<DataSourceSurface> AllocateBufferForImage(
|
2019-03-15 20:29:02 +03:00
|
|
|
const IntSize& size, SurfaceFormat format, bool aIsAnimated = false) {
|
2017-08-31 13:38:55 +03:00
|
|
|
int32_t stride = VolatileSurfaceStride(size, format);
|
|
|
|
|
2019-06-26 06:24:21 +03:00
|
|
|
if (gfxVars::GetUseWebRenderOrDefault() && StaticPrefs::image_mem_shared()) {
|
2018-09-17 22:06:29 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-03-13 05:48:38 +03:00
|
|
|
static bool GreenSurface(DataSourceSurface* aSurface, const IntSize& aSize,
|
|
|
|
SurfaceFormat aFormat) {
|
|
|
|
int32_t stride = aSurface->Stride();
|
|
|
|
uint32_t* surfaceData = reinterpret_cast<uint32_t*>(aSurface->GetData());
|
|
|
|
uint32_t surfaceDataLength = (stride * aSize.height) / sizeof(uint32_t);
|
|
|
|
|
|
|
|
// Start by assuming that GG is in the second byte and
|
|
|
|
// AA is in the final byte -- the most common case.
|
|
|
|
uint32_t color = mozilla::NativeEndian::swapFromBigEndian(0x00FF00FF);
|
|
|
|
|
|
|
|
// We are only going to handle this type of test under
|
|
|
|
// certain circumstances.
|
|
|
|
MOZ_ASSERT(surfaceData);
|
|
|
|
MOZ_ASSERT(aFormat == SurfaceFormat::B8G8R8A8 ||
|
|
|
|
aFormat == SurfaceFormat::B8G8R8X8 ||
|
|
|
|
aFormat == SurfaceFormat::R8G8B8A8 ||
|
|
|
|
aFormat == SurfaceFormat::R8G8B8X8 ||
|
|
|
|
aFormat == SurfaceFormat::A8R8G8B8 ||
|
|
|
|
aFormat == SurfaceFormat::X8R8G8B8);
|
|
|
|
MOZ_ASSERT((stride * aSize.height) % sizeof(uint32_t));
|
|
|
|
|
|
|
|
if (aFormat == SurfaceFormat::A8R8G8B8 ||
|
|
|
|
aFormat == SurfaceFormat::X8R8G8B8) {
|
|
|
|
color = mozilla::NativeEndian::swapFromBigEndian(0xFF00FF00);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < surfaceDataLength; i++) {
|
|
|
|
surfaceData[i] = color;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-11-12 21:22:33 +03:00
|
|
|
if (aFormat == SurfaceFormat::OS_RGBX) {
|
2016-07-01 04:59:29 +03:00
|
|
|
// 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
|
2019-09-12 12:00:52 +03:00
|
|
|
// we might not have gfxPlatform, so just memset every time 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;
|
|
|
|
}
|
|
|
|
|
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),
|
2019-03-15 20:29:02 +03:00
|
|
|
mNonPremult(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
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
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,
|
2019-03-15 20:29:02 +03:00
|
|
|
SurfaceFormat aFormat, bool 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
|
|
|
const Maybe<AnimationParams>& aAnimParams,
|
2019-03-15 20:29:02 +03:00
|
|
|
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.
|
2019-03-15 20:29:02 +03:00
|
|
|
if (!SurfaceCache::IsLegalSize(aImageSize)) {
|
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;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
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.
|
2019-03-15 20:29:02 +03:00
|
|
|
mDirtyRect = GetRect();
|
2018-09-17 22:06:28 +03:00
|
|
|
|
2018-05-29 15:36:11 +03:00
|
|
|
if (aAnimParams) {
|
|
|
|
mBlendRect = aAnimParams->mBlendRect;
|
|
|
|
mTimeout = aAnimParams->mTimeout;
|
|
|
|
mBlendMethod = aAnimParams->mBlendMethod;
|
|
|
|
mDisposalMethod = aAnimParams->mDisposalMethod;
|
|
|
|
} else {
|
2019-03-15 20:29:02 +03:00
|
|
|
mBlendRect = GetRect();
|
2016-07-31 00:47:49 +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
|
|
|
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(aAnimParams);
|
2019-11-12 21:22:33 +03:00
|
|
|
mFormat = SurfaceFormat::OS_RGBA;
|
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
|
|
|
} else {
|
|
|
|
mFormat = aFormat;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-03-15 20:29:02 +03:00
|
|
|
MOZ_ASSERT(!mLockedSurface, "Called imgFrame::InitForDecoder() twice?");
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
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
|
|
|
|
2019-03-15 20:29:02 +03:00
|
|
|
bool postFirstFrame = aAnimParams && aAnimParams->mFrameNum > 0;
|
|
|
|
mRawSurface = AllocateBufferForImage(mImageSize, mFormat, postFirstFrame);
|
|
|
|
if (!mRawSurface) {
|
|
|
|
mAborted = true;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2014-09-15 02:22:45 +04:00
|
|
|
|
2019-03-15 20:29:02 +03:00
|
|
|
if (StaticPrefs::browser_measurement_render_anims_and_video_solid() &&
|
|
|
|
aAnimParams) {
|
|
|
|
mBlankRawSurface = AllocateBufferForImage(mImageSize, mFormat);
|
|
|
|
if (!mBlankRawSurface) {
|
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
|
|
|
}
|
2019-03-15 20:29:02 +03:00
|
|
|
}
|
2016-07-01 04:59:29 +03:00
|
|
|
|
2019-03-15 20:29:02 +03:00
|
|
|
mLockedSurface = CreateLockedSurface(mRawSurface, mImageSize, mFormat);
|
|
|
|
if (!mLockedSurface) {
|
|
|
|
NS_WARNING("Failed to create LockedSurface");
|
|
|
|
mAborted = true;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2019-03-13 05:48:38 +03:00
|
|
|
|
2019-03-15 20:29:02 +03:00
|
|
|
if (mBlankRawSurface) {
|
|
|
|
mBlankLockedSurface =
|
|
|
|
CreateLockedSurface(mBlankRawSurface, mImageSize, mFormat);
|
|
|
|
if (!mBlankLockedSurface) {
|
|
|
|
NS_WARNING("Failed to create BlankLockedSurface");
|
2016-07-01 04:59:29 +03:00
|
|
|
mAborted = true;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2019-03-15 20:29:02 +03:00
|
|
|
}
|
2017-02-14 06:28:45 +03:00
|
|
|
|
2019-03-15 20:29:02 +03:00
|
|
|
if (!ClearSurface(mRawSurface, mImageSize, mFormat)) {
|
|
|
|
NS_WARNING("Could not clear allocated buffer");
|
|
|
|
mAborted = true;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2019-03-13 05:48:38 +03:00
|
|
|
|
2019-03-15 20:29:02 +03:00
|
|
|
if (mBlankRawSurface) {
|
|
|
|
if (!GreenSurface(mBlankRawSurface, mImageSize, mFormat)) {
|
|
|
|
NS_WARNING("Could not clear allocated blank buffer");
|
2017-02-14 06:28:45 +03:00
|
|
|
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(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;
|
2019-03-15 20:29:02 +03:00
|
|
|
mDirtyRect = GetRect();
|
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 NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-09-12 12:00:52 +03:00
|
|
|
nsresult imgFrame::InitWithDrawable(gfxDrawable* aDrawable,
|
|
|
|
const nsIntSize& aSize,
|
|
|
|
const SurfaceFormat aFormat,
|
|
|
|
SamplingFilter aSamplingFilter,
|
|
|
|
uint32_t aImageFlags,
|
|
|
|
gfx::BackendType aBackend) {
|
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;
|
2014-09-15 02:22:45 +04:00
|
|
|
mFormat = aFormat;
|
|
|
|
|
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
|
|
|
|
2019-03-15 20:29:02 +03:00
|
|
|
mRawSurface = AllocateBufferForImage(mImageSize, mFormat);
|
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;
|
|
|
|
}
|
|
|
|
|
2019-03-15 20:29:02 +03:00
|
|
|
mLockedSurface = CreateLockedSurface(mRawSurface, mImageSize, mFormat);
|
2017-01-18 21:31:20 +03:00
|
|
|
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
|
|
|
|
2019-03-15 20:29:02 +03:00
|
|
|
if (!ClearSurface(mRawSurface, mImageSize, 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(
|
2019-03-15 20:29:02 +03:00
|
|
|
mLockedSurface->GetData(), mImageSize, 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-08-19 14:16:27 +03:00
|
|
|
if (gfxPlatform::GetPlatform()->SupportsAzureContentForType(aBackend)) {
|
|
|
|
target = gfxPlatform::GetPlatform()->CreateDrawTargetForBackend(
|
|
|
|
aBackend, mImageSize, mFormat);
|
2016-09-15 14:53:12 +03:00
|
|
|
} else {
|
2019-08-19 14:16:27 +03:00
|
|
|
target = gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget(
|
|
|
|
mImageSize, 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.
|
2019-03-15 20:29:02 +03:00
|
|
|
gfxUtils::DrawPixelSnapped(ctx, aDrawable, SizeDouble(mImageSize),
|
|
|
|
ImageRegion::Create(ThebesRect(GetRect())),
|
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
|
|
|
|
2019-03-15 20:29:02 +03:00
|
|
|
if (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 {
|
|
|
|
mOptSurface = gfxPlatform::GetPlatform()
|
|
|
|
->ScreenReferenceDrawTarget()
|
|
|
|
->OptimizeSourceSurface(mLockedSurface);
|
|
|
|
}
|
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(
|
2019-11-12 21:22:33 +03:00
|
|
|
mImageSize, SurfaceFormat::OS_RGBA);
|
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!");
|
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.
|
2019-03-15 20:29:02 +03:00
|
|
|
IntRect updateRect = aUpdateRect.Intersect(GetRect());
|
2018-07-12 18:43:12 +03:00
|
|
|
if (updateRect.IsEmpty()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDecoded.UnionRect(mDecoded, updateRect);
|
|
|
|
|
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");
|
|
|
|
|
2019-03-15 20:29:02 +03:00
|
|
|
IntRect frameRect(GetRect());
|
|
|
|
if (!mDecoded.IsEqualEdges(frameRect)) {
|
2018-07-12 18:43:12 +03:00
|
|
|
// 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.
|
2019-03-15 20:29:02 +03:00
|
|
|
IntRect delta(0, 0, frameRect.width, 0);
|
2018-07-12 18:43:12 +03:00
|
|
|
if (mDecoded.y == 0) {
|
|
|
|
delta.y = mDecoded.height;
|
2019-03-15 20:29:02 +03:00
|
|
|
delta.height = frameRect.height - mDecoded.height;
|
|
|
|
} else if (mDecoded.y + mDecoded.height == frameRect.height) {
|
|
|
|
delta.height = frameRect.height - mDecoded.y;
|
2018-07-12 18:43:12 +03:00
|
|
|
} else {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Decoder only updated middle of image!");
|
2019-03-15 20:29:02 +03:00
|
|
|
delta = frameRect;
|
2018-07-12 18:43:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ImageUpdatedInternal(delta);
|
|
|
|
}
|
|
|
|
|
2019-03-15 20:29:02 +03:00
|
|
|
MOZ_ASSERT(mDecoded.IsEqualEdges(frameRect));
|
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) {
|
2019-03-15 20:29:02 +03:00
|
|
|
return mImageSize.width * BytesPerPixel(mFormat);
|
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 {
|
2019-03-15 20:29:02 +03:00
|
|
|
return GetImageBytesPerRow() * mImageSize.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");
|
2019-03-15 20:29:02 +03:00
|
|
|
MOZ_ASSERT(mLockedSurface);
|
2015-01-08 11:04:31 +03:00
|
|
|
|
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 {
|
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;
|
|
|
|
}
|
|
|
|
|
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;
|
2019-03-15 20:29:02 +03:00
|
|
|
if (mLockedSurface) {
|
2018-05-29 15:36:12 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-03-13 05:48:38 +03:00
|
|
|
if (mBlankLockedSurface) {
|
|
|
|
// We are going to return the blank surface because of the flags.
|
|
|
|
// We are including comments here that are copied from below
|
|
|
|
// just so that we are on the same page!
|
|
|
|
|
|
|
|
// 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, mBlankLockedSurface);
|
|
|
|
return surf.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<SourceSurface> surf(mBlankLockedSurface);
|
|
|
|
return surf.forget();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-03-15 20:29:02 +03:00
|
|
|
return CreateLockedSurface(mRawSurface, mImageSize, 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();
|
2019-03-15 20:29:02 +03:00
|
|
|
return mDecoded.IsEqualInterior(GetRect());
|
2012-03-24 02:10:50 +04: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;
|
2020-01-21 12:59:15 +03:00
|
|
|
|
2020-02-06 01:22:13 +03:00
|
|
|
metadata.mFinished = mFinished;
|
2017-01-18 21:31:20 +03:00
|
|
|
if (mLockedSurface) {
|
2020-02-06 01:22:13 +03:00
|
|
|
// The locked surface should only be present if we have mRawSurface. Hence
|
|
|
|
// we only need to get its allocation size to avoid double counting.
|
|
|
|
metadata.mHeapBytes += aMallocSizeOf(mLockedSurface);
|
|
|
|
metadata.AddType(mLockedSurface->GetType());
|
2010-05-22 08:10:14 +04:00
|
|
|
}
|
2015-07-29 07:02:45 +03:00
|
|
|
if (mOptSurface) {
|
2020-02-06 01:22:13 +03:00
|
|
|
metadata.mHeapBytes += aMallocSizeOf(mOptSurface);
|
|
|
|
|
|
|
|
SourceSurface::SizeOfInfo info;
|
|
|
|
mOptSurface->SizeOfExcludingThis(aMallocSizeOf, info);
|
|
|
|
metadata.Accumulate(info);
|
2014-02-25 07:37:51 +04:00
|
|
|
}
|
2017-01-18 21:31:20 +03:00
|
|
|
if (mRawSurface) {
|
2020-02-06 01:22:13 +03:00
|
|
|
metadata.mHeapBytes += aMallocSizeOf(mRawSurface);
|
|
|
|
|
|
|
|
SourceSurface::SizeOfInfo info;
|
|
|
|
mRawSurface->SizeOfExcludingThis(aMallocSizeOf, info);
|
|
|
|
metadata.Accumulate(info);
|
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)
|
2020-02-25 20:20:43 +03:00
|
|
|
: mParent(WrapNotNull(aParent)),
|
|
|
|
mSurface(WrapNotNull(aSurface)),
|
|
|
|
mType(SurfaceType::DATA) {
|
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
|
|
|
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
|