2012-12-19 05:59:30 +00: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 11:12:37 +00: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 01:50:15 +00:00
|
|
|
|
|
|
|
#include "imgFrame.h"
|
2014-08-22 20:12:38 +00:00
|
|
|
#include "ImageRegion.h"
|
2018-09-21 00:22:00 +00: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 01:50:15 +00:00
|
|
|
|
|
|
|
#include "prenv.h"
|
|
|
|
|
2014-02-09 08:04:38 +00:00
|
|
|
#include "gfx2DGlue.h"
|
2021-01-04 14:20:22 +00:00
|
|
|
#include "gfxContext.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 01:50:15 +00:00
|
|
|
#include "gfxPlatform.h"
|
2019-05-26 14:31:53 +00:00
|
|
|
|
2010-08-13 13:30:02 +00: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 01:50:15 +00:00
|
|
|
|
2014-11-28 03:55:57 +00:00
|
|
|
#include "MainThreadUtils.h"
|
2016-06-25 06:22:29 +00:00
|
|
|
#include "mozilla/CheckedInt.h"
|
|
|
|
#include "mozilla/gfx/Tools.h"
|
|
|
|
#include "mozilla/Likely.h"
|
2013-06-23 12:03:39 +00:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
Bug 1691589 - Reduce reliance on GeckoProfiler.h when only labels (and maybe markers) are needed - r=necko-reviewers,geckoview-reviewers,sg,agi,florian
There are no code changes, only #include changes.
It was a fairly mechanical process: Search for all "AUTO_PROFILER_LABEL", and in each file, if only labels are used, convert "GeckoProfiler.h" into "ProfilerLabels.h" (or just add that last one where needed).
In some files, there were also some marker calls but no other profiler-related calls, in these cases "GeckoProfiler.h" was replaced with both "ProfilerLabels.h" and "ProfilerMarkers.h", which still helps in reducing the use of the all-encompassing "GeckoProfiler.h".
Differential Revision: https://phabricator.services.mozilla.com/D104588
2021-02-16 04:44:19 +00:00
|
|
|
#include "mozilla/ProfilerLabels.h"
|
2020-03-09 23:36:39 +00:00
|
|
|
#include "mozilla/StaticPrefs_browser.h"
|
2013-09-07 02:15:49 +00: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-03 23:42:09 +00:00
|
|
|
#include "nsRefreshDriver.h"
|
2015-01-08 08:04:31 +00: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 01:50:15 +00:00
|
|
|
|
2020-06-11 17:49:13 +00:00
|
|
|
#include <algorithm> // for min, max
|
|
|
|
|
2014-07-10 15:00:31 +00:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
using namespace gfx;
|
|
|
|
|
|
|
|
namespace image {
|
2012-03-15 20:30:41 +00:00
|
|
|
|
2020-06-11 17:49:13 +00:00
|
|
|
/**
|
|
|
|
* This class is identical to SourceSurfaceSharedData but returns a different
|
|
|
|
* type so that SharedSurfacesChild is aware imagelib wants to recycle this
|
|
|
|
* surface for future animation frames.
|
|
|
|
*/
|
|
|
|
class RecyclingSourceSurfaceSharedData final : public SourceSurfaceSharedData {
|
|
|
|
public:
|
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(RecyclingSourceSurfaceSharedData,
|
|
|
|
override)
|
|
|
|
|
|
|
|
SurfaceType GetType() const override {
|
|
|
|
return SurfaceType::DATA_RECYCLING_SHARED;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-09-17 15:50:04 +00:00
|
|
|
static already_AddRefed<SourceSurfaceSharedData> AllocateBufferForImage(
|
|
|
|
const IntSize& size, SurfaceFormat format, bool aShouldRecycle = false) {
|
2014-06-10 19:44:04 +00:00
|
|
|
// Stride must be a multiple of four or cairo will complain.
|
2021-09-17 15:50:04 +00:00
|
|
|
int32_t stride = (size.width * BytesPerPixel(format) + 0x3) & ~0x3;
|
2021-09-03 19:13:35 +00:00
|
|
|
|
2021-09-17 15:50:04 +00:00
|
|
|
RefPtr<SourceSurfaceSharedData> newSurf;
|
|
|
|
if (aShouldRecycle) {
|
|
|
|
newSurf = new RecyclingSourceSurfaceSharedData();
|
2021-09-03 19:13:35 +00:00
|
|
|
} else {
|
2021-09-17 15:50:04 +00:00
|
|
|
newSurf = new SourceSurfaceSharedData();
|
|
|
|
}
|
|
|
|
if (!newSurf->Init(size, stride, format)) {
|
|
|
|
return nullptr;
|
2021-09-03 19:13:35 +00:00
|
|
|
}
|
2021-09-17 15:50:04 +00:00
|
|
|
return newSurf.forget();
|
2021-09-03 19:13:35 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 15:50:04 +00:00
|
|
|
static bool GreenSurface(SourceSurfaceSharedData* aSurface,
|
|
|
|
const IntSize& aSize, SurfaceFormat aFormat) {
|
2019-03-13 02:48:38 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-09-17 15:50:04 +00:00
|
|
|
static bool ClearSurface(SourceSurfaceSharedData* aSurface,
|
|
|
|
const IntSize& aSize, SurfaceFormat aFormat) {
|
2017-01-18 18:31:20 +00:00
|
|
|
int32_t stride = aSurface->Stride();
|
|
|
|
uint8_t* data = aSurface->GetData();
|
|
|
|
MOZ_ASSERT(data);
|
2016-07-01 01:59:29 +00:00
|
|
|
|
2019-11-12 18:22:33 +00:00
|
|
|
if (aFormat == SurfaceFormat::OS_RGBX) {
|
2016-07-01 01:59:29 +00: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 09:00:52 +00:00
|
|
|
// we might not have gfxPlatform, so just memset every time instead.
|
2017-01-18 18:31:20 +00:00
|
|
|
memset(data, 0xFF, stride * aSize.height);
|
|
|
|
} else if (aSurface->OnHeap()) {
|
2016-07-01 01:59:29 +00: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 18:31:20 +00:00
|
|
|
memset(data, 0, stride * aSize.height);
|
2016-07-01 01:59:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-08 08:04:31 +00:00
|
|
|
imgFrame::imgFrame()
|
2015-01-12 03:28:02 +00:00
|
|
|
: mMonitor("imgFrame"),
|
2015-01-08 08:04:31 +00:00
|
|
|
mDecoded(0, 0, 0, 0),
|
2015-01-12 03:28:02 +00:00
|
|
|
mAborted(false),
|
2016-03-24 00:31:42 +00:00
|
|
|
mFinished(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-03 23:42:09 +00:00
|
|
|
mShouldRecycle(false),
|
2018-05-29 12:36:11 +00:00
|
|
|
mTimeout(FrameTimeout::FromRawMilliseconds(100)),
|
|
|
|
mDisposalMethod(DisposalMethod::NOT_SPECIFIED),
|
|
|
|
mBlendMethod(BlendMethod::OVER),
|
2018-06-14 05:21:37 +00:00
|
|
|
mFormat(SurfaceFormat::UNKNOWN),
|
2019-03-15 17:29:02 +00:00
|
|
|
mNonPremult(false) {}
|
2018-11-30 10:46:48 +00: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 01:50:15 +00:00
|
|
|
imgFrame::~imgFrame() {
|
2015-01-12 03:28:02 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
2016-03-24 00:31:42 +00:00
|
|
|
MOZ_ASSERT(mAborted || AreAllPixelsWritten());
|
|
|
|
MOZ_ASSERT(mAborted || mFinished);
|
2015-01-12 03:28:02 +00: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 01:50:15 +00:00
|
|
|
}
|
|
|
|
|
2014-11-26 21:22:10 +00:00
|
|
|
nsresult imgFrame::InitForDecoder(const nsIntSize& aImageSize,
|
2019-03-15 17:29:02 +00: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-03 23:42:09 +00:00
|
|
|
const Maybe<AnimationParams>& aAnimParams,
|
2019-03-15 17:29:02 +00:00
|
|
|
bool aShouldRecycle) {
|
2014-09-14 22:22:45 +00:00
|
|
|
// Assert for properties that should be verified by decoders,
|
|
|
|
// warn for properties related to bad content.
|
2019-03-15 17:29:02 +00:00
|
|
|
if (!SurfaceCache::IsLegalSize(aImageSize)) {
|
2013-05-22 09:10:38 +00:00
|
|
|
NS_WARNING("Should have legal image size");
|
2015-01-12 03:28:02 +00: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 01:50:15 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2013-05-22 09:10:38 +00: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 01:50:15 +00:00
|
|
|
|
2015-03-29 14:59:08 +00: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 01:50:15 +00:00
|
|
|
|
2018-09-17 19:06:28 +00: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 17:29:02 +00:00
|
|
|
mDirtyRect = GetRect();
|
2018-09-17 19:06:28 +00:00
|
|
|
|
2018-05-29 12:36:11 +00:00
|
|
|
if (aAnimParams) {
|
|
|
|
mBlendRect = aAnimParams->mBlendRect;
|
|
|
|
mTimeout = aAnimParams->mTimeout;
|
|
|
|
mBlendMethod = aAnimParams->mBlendMethod;
|
|
|
|
mDisposalMethod = aAnimParams->mDisposalMethod;
|
|
|
|
} else {
|
2019-03-15 17:29:02 +00:00
|
|
|
mBlendRect = GetRect();
|
2016-07-30 21:47:49 +00: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-03 23:42:09 +00: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 18:22:33 +00: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-03 23:42:09 +00:00
|
|
|
} else {
|
|
|
|
mFormat = aFormat;
|
|
|
|
}
|
|
|
|
|
2015-01-08 08:04:31 +00: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-03 23:42:09 +00: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 01:50:15 +00:00
|
|
|
|
2021-09-17 15:50:04 +00:00
|
|
|
MOZ_ASSERT(!mRawSurface, "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 01:50:15 +00:00
|
|
|
|
2021-09-17 15:50:04 +00:00
|
|
|
mRawSurface = AllocateBufferForImage(mImageSize, mFormat, mShouldRecycle);
|
2019-03-15 17:29:02 +00:00
|
|
|
if (!mRawSurface) {
|
|
|
|
mAborted = true;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2014-09-14 22:22:45 +00:00
|
|
|
|
2019-03-15 17:29:02 +00:00
|
|
|
if (StaticPrefs::browser_measurement_render_anims_and_video_solid() &&
|
|
|
|
aAnimParams) {
|
|
|
|
mBlankRawSurface = AllocateBufferForImage(mImageSize, mFormat);
|
|
|
|
if (!mBlankRawSurface) {
|
2015-01-12 03:28:02 +00:00
|
|
|
mAborted = true;
|
2014-09-14 22:22:45 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2014-02-25 03:37:51 +00:00
|
|
|
}
|
2019-03-15 17:29:02 +00:00
|
|
|
}
|
2016-07-01 01:59:29 +00:00
|
|
|
|
2019-03-15 17:29:02 +00:00
|
|
|
if (!ClearSurface(mRawSurface, mImageSize, mFormat)) {
|
|
|
|
NS_WARNING("Could not clear allocated buffer");
|
|
|
|
mAborted = true;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2019-03-13 02:48:38 +00:00
|
|
|
|
2019-03-15 17:29:02 +00:00
|
|
|
if (mBlankRawSurface) {
|
|
|
|
if (!GreenSurface(mBlankRawSurface, mImageSize, mFormat)) {
|
|
|
|
NS_WARNING("Could not clear allocated blank buffer");
|
2017-02-14 03:28:45 +00:00
|
|
|
mAborted = true;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2014-09-14 22:22:45 +00: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-03 23:42:09 +00: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);
|
|
|
|
|
2021-09-17 15:50:04 +00:00
|
|
|
MOZ_ASSERT(mRawSurface);
|
2019-01-10 12:42:12 +00: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-03 23:42:09 +00:00
|
|
|
|
2020-06-11 17:49:13 +00:00
|
|
|
// Ensure we account for all internal references to the surface.
|
|
|
|
MozRefCountType internalRefs = 1;
|
2021-09-17 15:50:04 +00:00
|
|
|
if (mOptSurface == mRawSurface) {
|
2020-06-11 17:49:13 +00:00
|
|
|
++internalRefs;
|
|
|
|
}
|
|
|
|
|
2021-09-17 15:50:04 +00:00
|
|
|
if (mRawSurface->refCount() > internalRefs) {
|
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-03 23:42:09 +00:00
|
|
|
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.
|
2020-06-11 17:49:13 +00:00
|
|
|
int32_t refreshInterval =
|
|
|
|
std::max(std::min(nsRefreshDriver::DefaultInterval(), 20), 4);
|
|
|
|
TimeDuration waitInterval =
|
|
|
|
TimeDuration::FromMilliseconds(refreshInterval >> 2);
|
|
|
|
TimeStamp timeout =
|
|
|
|
TimeStamp::Now() + TimeDuration::FromMilliseconds(refreshInterval);
|
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-03 23:42:09 +00:00
|
|
|
while (true) {
|
2020-06-11 17:49:13 +00:00
|
|
|
mMonitor.Wait(waitInterval);
|
2021-09-17 15:50:04 +00:00
|
|
|
if (mRawSurface->refCount() <= internalRefs) {
|
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-03 23:42:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-06-11 17:49:13 +00:00
|
|
|
if (timeout <= TimeStamp::Now()) {
|
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-03 23:42:09 +00:00
|
|
|
// We couldn't secure the frame for recycling. It will allocate a new
|
|
|
|
// frame instead.
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mBlendRect = aAnimParams.mBlendRect;
|
|
|
|
mTimeout = aAnimParams.mTimeout;
|
|
|
|
mBlendMethod = aAnimParams.mBlendMethod;
|
|
|
|
mDisposalMethod = aAnimParams.mDisposalMethod;
|
2019-03-15 17:29:02 +00: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-03 23:42:09 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-09-12 09:00:52 +00:00
|
|
|
nsresult imgFrame::InitWithDrawable(gfxDrawable* aDrawable,
|
|
|
|
const nsIntSize& aSize,
|
|
|
|
const SurfaceFormat aFormat,
|
|
|
|
SamplingFilter aSamplingFilter,
|
|
|
|
uint32_t aImageFlags,
|
|
|
|
gfx::BackendType aBackend) {
|
2014-09-14 22:22:45 +00:00
|
|
|
// Assert for properties that should be verified by decoders,
|
|
|
|
// warn for properties related to bad content.
|
2018-09-21 00:22:00 +00:00
|
|
|
if (!SurfaceCache::IsLegalSize(aSize)) {
|
2014-09-14 22:22:45 +00:00
|
|
|
NS_WARNING("Should have legal image size");
|
2015-01-12 03:28:02 +00:00
|
|
|
mAborted = true;
|
2014-09-14 22:22:45 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-03-29 14:59:08 +00:00
|
|
|
mImageSize = aSize;
|
2014-09-14 22:22:45 +00:00
|
|
|
mFormat = aFormat;
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DrawTarget> target;
|
2014-09-14 22:22:45 +00:00
|
|
|
|
2017-11-24 13:10:03 +00:00
|
|
|
bool canUseDataSurface = Factory::DoesBackendSupportDataDrawtarget(aBackend);
|
2014-09-14 22:22:45 +00:00
|
|
|
if (canUseDataSurface) {
|
|
|
|
// It's safe to use data surfaces for content on this platform, so we can
|
|
|
|
// get away with using volatile buffers.
|
2021-09-17 15:50:04 +00:00
|
|
|
MOZ_ASSERT(!mRawSurface, "Called imgFrame::InitWithDrawable() twice?");
|
2014-09-14 22:22:45 +00:00
|
|
|
|
2019-03-15 17:29:02 +00:00
|
|
|
mRawSurface = AllocateBufferForImage(mImageSize, mFormat);
|
2017-01-18 18:31:20 +00:00
|
|
|
if (!mRawSurface) {
|
2015-01-12 03:28:02 +00:00
|
|
|
mAborted = true;
|
2014-09-14 22:22:45 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2019-03-15 17:29:02 +00:00
|
|
|
if (!ClearSurface(mRawSurface, mImageSize, mFormat)) {
|
2016-07-01 01:59:29 +00:00
|
|
|
NS_WARNING("Could not clear allocated buffer");
|
|
|
|
mAborted = true;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2016-08-11 21:54:08 +00:00
|
|
|
target = gfxPlatform::CreateDrawTargetForData(
|
2021-09-17 15:50:04 +00:00
|
|
|
mRawSurface->GetData(), mImageSize, mRawSurface->Stride(), mFormat);
|
2014-09-14 22:22:45 +00: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 11:16:27 +00:00
|
|
|
if (gfxPlatform::GetPlatform()->SupportsAzureContentForType(aBackend)) {
|
|
|
|
target = gfxPlatform::GetPlatform()->CreateDrawTargetForBackend(
|
|
|
|
aBackend, mImageSize, mFormat);
|
2016-09-15 11:53:12 +00:00
|
|
|
} else {
|
2019-08-19 11:16:27 +00:00
|
|
|
target = gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget(
|
|
|
|
mImageSize, mFormat);
|
2016-09-15 11:53:12 +00:00
|
|
|
}
|
2014-09-14 22:22:45 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 19:18:11 +00:00
|
|
|
if (!target || !target->IsValid()) {
|
2015-01-12 03:28:02 +00:00
|
|
|
mAborted = true;
|
2014-09-14 22:22:45 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw using the drawable the caller provided.
|
2016-06-06 23:39:56 +00:00
|
|
|
RefPtr<gfxContext> ctx = gfxContext::CreateOrNull(target);
|
2016-05-27 05:19:38 +00:00
|
|
|
MOZ_ASSERT(ctx); // Already checked the draw target above.
|
2019-03-15 17:29:02 +00:00
|
|
|
gfxUtils::DrawPixelSnapped(ctx, aDrawable, SizeDouble(mImageSize),
|
|
|
|
ImageRegion::Create(ThebesRect(GetRect())),
|
2016-05-25 16:01:18 +00:00
|
|
|
mFormat, aSamplingFilter, aImageFlags);
|
2014-09-14 22:22:45 +00:00
|
|
|
|
2021-09-17 15:50:04 +00:00
|
|
|
if (canUseDataSurface && !mRawSurface) {
|
|
|
|
NS_WARNING("Failed to create SourceSurfaceSharedData");
|
2015-01-12 03:28:02 +00:00
|
|
|
mAborted = true;
|
2014-09-14 22:22:45 +00: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 20:48:59 +00: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 01:50:15 +00:00
|
|
|
}
|
|
|
|
|
2015-01-12 03:28:02 +00:00
|
|
|
// If we reach this point, we should regard ourselves as complete.
|
|
|
|
mDecoded = GetRect();
|
2016-03-24 00:31:42 +00:00
|
|
|
mFinished = true;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
MOZ_ASSERT(AreAllPixelsWritten());
|
|
|
|
#endif
|
2015-01-12 03:28:02 +00: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 01:50:15 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-09-11 00:06:45 +00:00
|
|
|
DrawableFrameRef imgFrame::DrawableRef() { return DrawableFrameRef(this); }
|
|
|
|
|
2021-09-17 15:50:04 +00:00
|
|
|
RawAccessFrameRef imgFrame::RawAccessRef() { return RawAccessFrameRef(this); }
|
2018-05-30 23:35:40 +00:00
|
|
|
|
2010-08-13 13:30:02 +00:00
|
|
|
imgFrame::SurfaceWithFormat imgFrame::SurfaceForDrawing(
|
2016-07-30 21:49:03 +00:00
|
|
|
bool aDoPartialDecode, bool aDoTile, ImageRegion& aRegion,
|
2014-04-20 01:28:38 +00:00
|
|
|
SourceSurface* aSurface) {
|
2015-01-08 08:04:31 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-12 03:28:02 +00:00
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
2015-01-08 08:04:31 +00:00
|
|
|
|
2016-07-30 21:49:03 +00:00
|
|
|
if (!aDoPartialDecode) {
|
|
|
|
return SurfaceWithFormat(new gfxSurfaceDrawable(aSurface, mImageSize),
|
2016-10-01 03:11:59 +00:00
|
|
|
mFormat);
|
2010-08-13 13:30:02 +00:00
|
|
|
}
|
|
|
|
|
2017-12-20 21:46:28 +00:00
|
|
|
gfxRect available =
|
|
|
|
gfxRect(mDecoded.X(), mDecoded.Y(), mDecoded.Width(), mDecoded.Height());
|
2010-08-13 13:30:02 +00:00
|
|
|
|
2016-07-30 20:41:57 +00:00
|
|
|
if (aDoTile) {
|
2010-08-13 13:30:02 +00: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 05:24:48 +00:00
|
|
|
RefPtr<DrawTarget> target =
|
2016-07-30 21:49:03 +00:00
|
|
|
gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget(
|
2019-11-12 18:22:33 +00:00
|
|
|
mImageSize, SurfaceFormat::OS_RGBA);
|
2015-03-31 17:48:00 +00:00
|
|
|
if (!target) {
|
2010-08-13 13:30:02 +00:00
|
|
|
return SurfaceWithFormat();
|
2015-03-31 17:48:00 +00:00
|
|
|
}
|
2010-08-13 13:30:02 +00:00
|
|
|
|
2016-07-30 20:41:57 +00:00
|
|
|
SurfacePattern pattern(aSurface, aRegion.GetExtendMode(),
|
2017-12-20 21:46:28 +00:00
|
|
|
Matrix::Translation(mDecoded.X(), mDecoded.Y()));
|
2016-07-30 20:41:57 +00:00
|
|
|
target->FillRect(ToRect(aRegion.Intersect(available).Rect()), pattern);
|
2012-03-23 22:10:50 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SourceSurface> newsurf = target->Snapshot();
|
2016-07-30 21:49:03 +00:00
|
|
|
return SurfaceWithFormat(new gfxSurfaceDrawable(newsurf, mImageSize),
|
2015-03-31 17:48:00 +00:00
|
|
|
target->GetFormat());
|
2010-08-13 13:30:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Not tiling, and we have a surface, so we can account for
|
2016-07-30 21:49:03 +00:00
|
|
|
// a partial decode just by twiddling parameters.
|
|
|
|
aRegion = aRegion.Intersect(available);
|
2017-08-14 12:29:56 +00:00
|
|
|
IntSize availableSize(mDecoded.Width(), mDecoded.Height());
|
2016-07-30 21:49:03 +00:00
|
|
|
|
2014-03-02 16:17:26 +00:00
|
|
|
return SurfaceWithFormat(new gfxSurfaceDrawable(aSurface, availableSize),
|
2010-08-13 13:30:27 +00: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 01:50:15 +00:00
|
|
|
}
|
|
|
|
|
2014-08-22 20:12:38 +00:00
|
|
|
bool imgFrame::Draw(gfxContext* aContext, const ImageRegion& aRegion,
|
2017-01-03 05:53:22 +00: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 07:08:53 +00:00
|
|
|
AUTO_PROFILER_LABEL("imgFrame::Draw", GRAPHICS);
|
2014-05-23 21:12:29 +00:00
|
|
|
|
2015-01-08 08:04:31 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-08-22 20:12:38 +00: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 08:04:31 +00:00
|
|
|
|
2018-06-03 23:37:17 +00: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-03 23:42:09 +00: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-03 23:37:17 +00:00
|
|
|
RefPtr<SourceSurface> surf;
|
|
|
|
SurfaceWithFormat surfaceResult;
|
|
|
|
ImageRegion region(aRegion);
|
|
|
|
gfxRect imageRect(0, 0, mImageSize.width, mImageSize.height);
|
2014-11-26 21:22:10 +00:00
|
|
|
|
2018-06-03 23:37:17 +00:00
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
2016-09-15 11:53:12 +00:00
|
|
|
|
2018-06-03 23:37:17 +00:00
|
|
|
bool doPartialDecode = !AreAllPixelsWritten();
|
2014-03-02 16:17:26 +00: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-03 23:42:09 +00: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 12:42:12 +00:00
|
|
|
bool recording = drawTarget->GetBackendType() == BackendType::RECORDING;
|
2020-06-11 17:49:13 +00:00
|
|
|
RefPtr<SourceSurface> surf = GetSourceSurfaceInternal();
|
2018-06-03 23:37:17 +00:00
|
|
|
if (!surf) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-23 16:17:35 +00:00
|
|
|
|
2018-06-03 23:37:17 +00:00
|
|
|
bool doTile = !imageRect.Contains(aRegion.Rect()) &&
|
|
|
|
!(aImageFlags & imgIContainer::FLAG_CLAMP);
|
|
|
|
|
|
|
|
surfaceResult = SurfaceForDrawing(doPartialDecode, doTile, region, surf);
|
2019-01-10 12:42:12 +00: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-03 23:37:17 +00: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 01:50:15 +00:00
|
|
|
|
2010-08-13 13:30:02 +00:00
|
|
|
if (surfaceResult.IsValid()) {
|
2010-08-13 13:30:27 +00:00
|
|
|
gfxUtils::DrawPixelSnapped(aContext, surfaceResult.mDrawable,
|
2014-08-22 20:12:38 +00:00
|
|
|
imageRect.Size(), region, surfaceResult.mFormat,
|
2017-01-03 05:53:22 +00: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 01:50:15 +00:00
|
|
|
}
|
2017-02-08 20:48:59 +00:00
|
|
|
|
2014-03-02 16:17:26 +00: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 01:50:15 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 08:04:31 +00:00
|
|
|
nsresult imgFrame::ImageUpdated(const nsIntRect& aUpdateRect) {
|
2015-01-12 03:28:02 +00:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2015-01-08 08:04:31 +00:00
|
|
|
return ImageUpdatedInternal(aUpdateRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult imgFrame::ImageUpdatedInternal(const nsIntRect& aUpdateRect) {
|
2015-01-12 03:28:02 +00:00
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
2013-07-04 18:45:57 +00:00
|
|
|
|
2016-05-27 05:19:38 +00: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 17:29:02 +00:00
|
|
|
IntRect updateRect = aUpdateRect.Intersect(GetRect());
|
2018-07-12 15:43:12 +00:00
|
|
|
if (updateRect.IsEmpty()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDecoded.UnionRect(mDecoded, updateRect);
|
|
|
|
|
2017-12-01 11:59:21 +00:00
|
|
|
// Update our invalidation counters for any consumers watching for changes
|
|
|
|
// in the surface.
|
|
|
|
if (mRawSurface) {
|
2018-07-12 15:43:12 +00:00
|
|
|
mRawSurface->Invalidate(updateRect);
|
2017-12-01 11:59:21 +00: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 01:50:15 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-01-12 03:28:02 +00:00
|
|
|
void imgFrame::Finish(Opacity aFrameOpacity /* = Opacity::SOME_TRANSPARENCY */,
|
2017-02-08 20:48:59 +00:00
|
|
|
bool aFinalize /* = true */) {
|
2015-01-12 03:28:02 +00:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2015-01-08 08:04:31 +00:00
|
|
|
|
2019-03-15 17:29:02 +00:00
|
|
|
IntRect frameRect(GetRect());
|
|
|
|
if (!mDecoded.IsEqualEdges(frameRect)) {
|
2018-07-12 15:43:12 +00: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 17:29:02 +00:00
|
|
|
IntRect delta(0, 0, frameRect.width, 0);
|
2018-07-12 15:43:12 +00:00
|
|
|
if (mDecoded.y == 0) {
|
|
|
|
delta.y = mDecoded.height;
|
2019-03-15 17:29:02 +00:00
|
|
|
delta.height = frameRect.height - mDecoded.height;
|
|
|
|
} else if (mDecoded.y + mDecoded.height == frameRect.height) {
|
|
|
|
delta.height = frameRect.height - mDecoded.y;
|
2018-07-12 15:43:12 +00:00
|
|
|
} else {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Decoder only updated middle of image!");
|
2019-03-15 17:29:02 +00:00
|
|
|
delta = frameRect;
|
2018-07-12 15:43:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ImageUpdatedInternal(delta);
|
|
|
|
}
|
|
|
|
|
2019-03-15 17:29:02 +00:00
|
|
|
MOZ_ASSERT(mDecoded.IsEqualEdges(frameRect));
|
2017-02-08 20:48:59 +00:00
|
|
|
|
|
|
|
if (aFinalize) {
|
|
|
|
FinalizeSurfaceInternal();
|
|
|
|
}
|
|
|
|
|
2016-03-24 00:31:42 +00:00
|
|
|
mFinished = true;
|
|
|
|
|
|
|
|
// The image is now complete, wake up anyone who's waiting.
|
|
|
|
mMonitor.NotifyAll();
|
2015-01-08 08:04:31 +00:00
|
|
|
}
|
|
|
|
|
2015-03-31 17:48:00 +00:00
|
|
|
uint32_t imgFrame::GetImageBytesPerRow() const {
|
2015-01-12 03:28:02 +00:00
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
2015-01-08 08:04:31 +00:00
|
|
|
|
2017-01-18 18:31:20 +00:00
|
|
|
if (mRawSurface) {
|
2019-03-15 17:29:02 +00:00
|
|
|
return mImageSize.width * BytesPerPixel(mFormat);
|
2015-03-31 17:48:00 +00:00
|
|
|
}
|
2010-05-22 04:10:14 +00: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 01:50:15 +00:00
|
|
|
}
|
|
|
|
|
2015-03-31 17:48:00 +00:00
|
|
|
uint32_t imgFrame::GetImageDataLength() const {
|
2019-03-15 17:29:02 +00: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 01:50:15 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 08:04:31 +00:00
|
|
|
void imgFrame::GetImageData(uint8_t** aData, uint32_t* aLength) const {
|
2015-01-12 03:28:02 +00:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2015-01-08 08:04:31 +00:00
|
|
|
GetImageDataInternal(aData, aLength);
|
|
|
|
}
|
2012-09-26 15:33:06 +00:00
|
|
|
|
2015-01-08 08:04:31 +00:00
|
|
|
void imgFrame::GetImageDataInternal(uint8_t** aData, uint32_t* aLength) const {
|
2015-01-12 03:28:02 +00:00
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
2021-09-17 15:50:04 +00:00
|
|
|
MOZ_ASSERT(mRawSurface);
|
2015-01-08 08:04:31 +00:00
|
|
|
|
2021-09-17 15:50:04 +00:00
|
|
|
if (mRawSurface) {
|
2017-02-08 20:48:59 +00: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.
|
2021-09-17 15:50:04 +00:00
|
|
|
*aData = mRawSurface->GetData();
|
|
|
|
MOZ_ASSERT(*aData,
|
|
|
|
"mRawSurface is non-null, but GetData is null in GetImageData");
|
2015-01-08 08:04:31 +00:00
|
|
|
} else {
|
2012-07-30 14:20:58 +00:00
|
|
|
*aData = nullptr;
|
2015-01-08 08:04:31 +00: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 01:50:15 +00:00
|
|
|
|
2015-01-08 08:04:31 +00: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 01:50:15 +00:00
|
|
|
}
|
|
|
|
|
2015-03-31 17:48:00 +00:00
|
|
|
uint8_t* imgFrame::GetImageData() const {
|
|
|
|
uint8_t* data;
|
2013-06-14 13:42:01 +00:00
|
|
|
uint32_t length;
|
|
|
|
GetImageData(&data, &length);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2017-02-08 20:48:59 +00: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 18:47:17 +00:00
|
|
|
if (mShouldRecycle || !mRawSurface ||
|
|
|
|
mRawSurface->GetType() != SurfaceType::DATA_SHARED) {
|
2017-02-08 20:48:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-11 17:49:13 +00:00
|
|
|
auto* sharedSurf = static_cast<SourceSurfaceSharedData*>(mRawSurface.get());
|
2017-02-08 20:48:59 +00:00
|
|
|
sharedSurf->Finalize();
|
|
|
|
}
|
|
|
|
|
2015-06-17 14:00:52 +00:00
|
|
|
already_AddRefed<SourceSurface> imgFrame::GetSourceSurface() {
|
2015-01-12 03:28:02 +00:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2020-06-11 17:49:13 +00:00
|
|
|
return GetSourceSurfaceInternal();
|
2015-01-08 08:04:31 +00:00
|
|
|
}
|
|
|
|
|
2020-06-11 17:49:13 +00:00
|
|
|
already_AddRefed<SourceSurface> imgFrame::GetSourceSurfaceInternal() {
|
2015-01-12 03:28:02 +00:00
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
2015-01-08 08:04:31 +00:00
|
|
|
|
2014-04-20 01:28:38 +00:00
|
|
|
if (mOptSurface) {
|
2015-03-31 17:48:00 +00:00
|
|
|
if (mOptSurface->IsValid()) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SourceSurface> surf(mOptSurface);
|
2015-05-01 13:14:16 +00:00
|
|
|
return surf.forget();
|
2015-03-31 17:48:00 +00:00
|
|
|
}
|
2020-06-11 17:49:13 +00:00
|
|
|
mOptSurface = nullptr;
|
2014-04-20 01:28:38 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 15:50:04 +00:00
|
|
|
if (mBlankRawSurface) {
|
2019-03-13 02:48:38 +00:00
|
|
|
// 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!
|
2021-09-17 15:50:04 +00:00
|
|
|
RefPtr<SourceSurface> surf(mBlankRawSurface);
|
2019-03-13 02:48:38 +00:00
|
|
|
return surf.forget();
|
|
|
|
}
|
|
|
|
|
2021-09-17 15:50:04 +00:00
|
|
|
RefPtr<SourceSurface> surf(mRawSurface);
|
|
|
|
return surf.forget();
|
2014-04-20 01:28:38 +00:00
|
|
|
}
|
|
|
|
|
2015-01-12 03:28:02 +00:00
|
|
|
void imgFrame::Abort() {
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
|
|
|
|
mAborted = true;
|
|
|
|
|
|
|
|
// Wake up anyone who's waiting.
|
2015-01-15 23:11:36 +00:00
|
|
|
mMonitor.NotifyAll();
|
2015-01-12 03:28:02 +00:00
|
|
|
}
|
|
|
|
|
2016-04-01 17:44:17 +00:00
|
|
|
bool imgFrame::IsAborted() const {
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
return mAborted;
|
|
|
|
}
|
|
|
|
|
2016-03-24 00:31:42 +00:00
|
|
|
bool imgFrame::IsFinished() const {
|
2015-01-12 03:28:02 +00:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2016-03-24 00:31:42 +00:00
|
|
|
return mFinished;
|
2015-01-12 03:28:02 +00:00
|
|
|
}
|
|
|
|
|
2016-03-24 00:31:42 +00:00
|
|
|
void imgFrame::WaitUntilFinished() const {
|
2015-01-12 03:28:02 +00:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
// Return if we're aborted or complete.
|
2016-03-24 00:31:42 +00:00
|
|
|
if (mAborted || mFinished) {
|
2015-01-12 03:28:02 +00: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 01:50:15 +00:00
|
|
|
}
|
2009-11-12 23:18:40 +00:00
|
|
|
|
2016-03-24 00:31:42 +00:00
|
|
|
bool imgFrame::AreAllPixelsWritten() const {
|
2015-01-12 03:28:02 +00:00
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
2019-03-15 17:29:02 +00:00
|
|
|
return mDecoded.IsEqualInterior(GetRect());
|
2012-03-23 22:10:50 +00:00
|
|
|
}
|
|
|
|
|
2015-07-29 04:02:45 +00:00
|
|
|
void imgFrame::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
|
2018-09-25 13:13:51 +00:00
|
|
|
const AddSizeOfCb& aCallback) const {
|
2015-01-12 03:28:02 +00:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2015-01-08 08:04:31 +00:00
|
|
|
|
2018-09-25 13:13:51 +00:00
|
|
|
AddSizeOfCbData metadata;
|
2020-02-05 22:22:13 +00:00
|
|
|
metadata.mFinished = mFinished;
|
2021-05-20 12:31:27 +00:00
|
|
|
|
2015-07-29 04:02:45 +00:00
|
|
|
if (mOptSurface) {
|
2020-02-05 22:22:13 +00:00
|
|
|
metadata.mHeapBytes += aMallocSizeOf(mOptSurface);
|
|
|
|
|
|
|
|
SourceSurface::SizeOfInfo info;
|
|
|
|
mOptSurface->SizeOfExcludingThis(aMallocSizeOf, info);
|
|
|
|
metadata.Accumulate(info);
|
2014-02-25 03:37:51 +00:00
|
|
|
}
|
2017-01-18 18:31:20 +00:00
|
|
|
if (mRawSurface) {
|
2020-02-05 22:22:13 +00:00
|
|
|
metadata.mHeapBytes += aMallocSizeOf(mRawSurface);
|
|
|
|
|
|
|
|
SourceSurface::SizeOfInfo info;
|
|
|
|
mRawSurface->SizeOfExcludingThis(aMallocSizeOf, info);
|
|
|
|
metadata.Accumulate(info);
|
2014-04-15 05:24:01 +00:00
|
|
|
}
|
2018-09-25 13:13:51 +00:00
|
|
|
|
|
|
|
aCallback(metadata);
|
2010-05-22 04:10:14 +00:00
|
|
|
}
|
2014-07-10 15:00:31 +00:00
|
|
|
|
|
|
|
} // namespace image
|
|
|
|
} // namespace mozilla
|