Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
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
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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
|
|
|
|
2015-05-15 06:52:05 +03:00
|
|
|
#ifndef mozilla_image_imgFrame_h
|
|
|
|
#define mozilla_image_imgFrame_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
|
|
|
|
2016-06-25 01:20:32 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2015-01-12 06:28:02 +03:00
|
|
|
#include "mozilla/Monitor.h"
|
2014-09-11 04:06:45 +04:00
|
|
|
#include "mozilla/Move.h"
|
2018-05-29 15:36:11 +03:00
|
|
|
#include "AnimationParams.h"
|
2010-08-13 17:30:27 +04:00
|
|
|
#include "gfxDrawable.h"
|
2012-04-18 02:04:15 +04:00
|
|
|
#include "imgIContainer.h"
|
2015-01-08 11:04:31 +03:00
|
|
|
#include "MainThreadUtils.h"
|
2014-02-25 07:37:51 +04:00
|
|
|
|
2014-07-10 19:00:31 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace image {
|
|
|
|
|
2014-08-23 00:12:38 +04:00
|
|
|
class ImageRegion;
|
2014-09-11 04:06:45 +04:00
|
|
|
class DrawableFrameRef;
|
|
|
|
class RawAccessFrameRef;
|
2014-08-23 00:12:38 +04:00
|
|
|
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class Opacity : uint8_t { FULLY_OPAQUE, SOME_TRANSPARENCY };
|
2015-01-08 00:07:23 +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
|
|
|
class imgFrame {
|
2014-07-10 19:00:31 +04:00
|
|
|
typedef gfx::Color Color;
|
|
|
|
typedef gfx::DataSourceSurface DataSourceSurface;
|
2014-08-23 00:49:54 +04:00
|
|
|
typedef gfx::DrawTarget DrawTarget;
|
2016-05-25 19:01:18 +03:00
|
|
|
typedef gfx::SamplingFilter SamplingFilter;
|
2016-05-27 08:19:38 +03:00
|
|
|
typedef gfx::IntPoint IntPoint;
|
|
|
|
typedef gfx::IntRect IntRect;
|
2014-07-10 19:00:31 +04:00
|
|
|
typedef gfx::IntSize IntSize;
|
|
|
|
typedef gfx::SourceSurface SourceSurface;
|
|
|
|
typedef gfx::SurfaceFormat SurfaceFormat;
|
2014-04-20 05:28: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
|
|
|
public:
|
2014-08-23 00:49:54 +04:00
|
|
|
MOZ_DECLARE_REFCOUNTED_TYPENAME(imgFrame)
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(imgFrame)
|
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
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();
|
|
|
|
|
2014-09-15 02:22:45 +04:00
|
|
|
/**
|
|
|
|
* Initialize this imgFrame with an empty surface and prepare it for being
|
|
|
|
* written to by a decoder.
|
|
|
|
*
|
|
|
|
* This is appropriate for use with decoded images, but it should not be used
|
|
|
|
* when drawing content into an imgFrame, as it may use a different graphics
|
|
|
|
* backend than normal content drawing.
|
|
|
|
*/
|
2019-03-15 20:29:02 +03:00
|
|
|
nsresult InitForDecoder(const nsIntSize& aImageSize, SurfaceFormat aFormat,
|
Bug 1465619 - Part 6. Add support for recycling to imgFrame. r=tnikkel
Beyond the necessary reinitialization methods, we need to protect
ourselves from recycling a frame that some other entity in the browser
is still using. Generally speaking the animated surface will only be
used in imgFrame::Draw since we don't layerize animated images, which
will be safe. However with OMTP or blob recordings, we could retain a
reference to the surface outside the current stack context. Additional
if something calls RasterImage::GetImageContainer(AtSize) or
RasterImage::GetFrame(AtSize), it may also have a reference to the
surface for an indetermine period of time.
As such, if an imgFrame is a candidate for recycling, it will wrap
imgFrame::mLockedSurface in a RecyclingSourceSurface. Its job is to
track how many consumers there are still of the surface, so that after
we advance the animation, the decoder will know if there are still
outstanding consumers.
If the surface is still in use, it will block for a finite period of
time (the refresh interval) before giving up on reclaiming the surface,
and will allocate a new surface. The old surface can then remain in
circulation for as long as necessary without further blocking the
animation progression, since we stop recycling that surface/imgFrame.
Differential Revision: https://phabricator.services.mozilla.com/D7511
2018-06-04 02:42:09 +03:00
|
|
|
bool aNonPremult,
|
|
|
|
const Maybe<AnimationParams>& aAnimParams,
|
2019-03-15 20:29:02 +03:00
|
|
|
bool aShouldRecycle);
|
2014-09-15 02:22:45 +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
|
|
|
/**
|
|
|
|
* Reinitialize this imgFrame with the new parameters, but otherwise retain
|
|
|
|
* the underlying buffer.
|
|
|
|
*
|
|
|
|
* This is appropriate for use with animated images, where the decoder was
|
|
|
|
* given an IDecoderFrameRecycler object which may yield a recycled imgFrame
|
|
|
|
* that was discarded to save memory.
|
|
|
|
*/
|
|
|
|
nsresult InitForDecoderRecycle(const AnimationParams& aAnimParams);
|
2014-09-15 02:22:45 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize this imgFrame with a new surface and draw the provided
|
|
|
|
* gfxDrawable into it.
|
|
|
|
*
|
|
|
|
* This is appropriate to use when drawing content into an imgFrame, as it
|
|
|
|
* uses the same graphics backend as normal content drawing. The downside is
|
|
|
|
* that the underlying surface may not be stored in a volatile buffer on all
|
2014-11-27 00:22:10 +03:00
|
|
|
* platforms, and raw access to the surface (using RawAccessRef()) may be much
|
|
|
|
* more expensive than in the InitForDecoder() case.
|
2016-09-15 14:53:12 +03:00
|
|
|
*
|
|
|
|
* aBackend specifies the DrawTarget backend type this imgFrame is supposed
|
|
|
|
* to be drawn to.
|
2014-09-15 02:22:45 +04:00
|
|
|
*/
|
|
|
|
nsresult InitWithDrawable(gfxDrawable* aDrawable, const nsIntSize& aSize,
|
|
|
|
const SurfaceFormat aFormat,
|
2016-05-25 19:01:18 +03:00
|
|
|
SamplingFilter aSamplingFilter,
|
2019-08-19 14:16:27 +03:00
|
|
|
uint32_t aImageFlags, gfx::BackendType aBackend);
|
2014-09-15 02:22:45 +04:00
|
|
|
|
2014-09-11 04:06:45 +04:00
|
|
|
DrawableFrameRef DrawableRef();
|
2018-05-29 15:36:12 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a RawAccessFrameRef for the frame.
|
|
|
|
*
|
|
|
|
* @param aOnlyFinished If true, only return a valid RawAccessFrameRef if
|
|
|
|
* imgFrame::Finish has been called.
|
|
|
|
*/
|
|
|
|
RawAccessFrameRef RawAccessRef(bool aOnlyFinished = false);
|
2014-09-11 04:06:45 +04:00
|
|
|
|
2018-05-31 02:35:40 +03:00
|
|
|
/**
|
|
|
|
* Make this imgFrame permanently available for raw access.
|
|
|
|
*
|
|
|
|
* This is irrevocable, and should be avoided whenever possible, since it
|
|
|
|
* prevents this imgFrame from being optimized and makes it impossible for its
|
|
|
|
* volatile buffer to be freed.
|
|
|
|
*
|
|
|
|
* It is an error to call this without already holding a RawAccessFrameRef to
|
|
|
|
* this imgFrame.
|
|
|
|
*/
|
|
|
|
void SetRawAccessOnly();
|
|
|
|
|
2014-08-23 00:12:38 +04:00
|
|
|
bool Draw(gfxContext* aContext, const ImageRegion& aRegion,
|
2017-01-03 08:53:22 +03:00
|
|
|
SamplingFilter aSamplingFilter, uint32_t aImageFlags,
|
|
|
|
float 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
|
|
|
|
2015-03-31 20:48:00 +03:00
|
|
|
nsresult ImageUpdated(const nsIntRect& aUpdateRect);
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
|
2015-01-08 11:04:31 +03:00
|
|
|
/**
|
|
|
|
* Mark this imgFrame as completely decoded, and set final options.
|
|
|
|
*
|
2015-01-12 06:28:02 +03:00
|
|
|
* You must always call either Finish() or Abort() before releasing the last
|
|
|
|
* RawAccessFrameRef pointing to an imgFrame.
|
|
|
|
*
|
2015-01-08 11:04:31 +03:00
|
|
|
* @param aFrameOpacity Whether this imgFrame is opaque.
|
2017-02-08 23:48:59 +03:00
|
|
|
* @param aFinalize Finalize the underlying surface (e.g. so that it
|
|
|
|
* may be marked as read only if possible).
|
2015-01-08 11:04:31 +03:00
|
|
|
*/
|
2015-01-12 06:28:02 +03:00
|
|
|
void 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
|
|
|
|
|
|
|
/**
|
|
|
|
* Mark this imgFrame as aborted. This informs the imgFrame that if it isn't
|
|
|
|
* completely decoded now, it never will be.
|
|
|
|
*
|
|
|
|
* You must always call either Finish() or Abort() before releasing the last
|
|
|
|
* RawAccessFrameRef pointing to an imgFrame.
|
|
|
|
*/
|
|
|
|
void Abort();
|
|
|
|
|
2016-04-01 20:44:17 +03:00
|
|
|
/**
|
|
|
|
* Returns true if this imgFrame has been aborted.
|
|
|
|
*/
|
|
|
|
bool IsAborted() const;
|
|
|
|
|
2015-01-12 06:28:02 +03:00
|
|
|
/**
|
|
|
|
* Returns true if this imgFrame is completely decoded.
|
|
|
|
*/
|
2016-03-24 03:31:42 +03:00
|
|
|
bool IsFinished() const;
|
2015-01-12 06:28:02 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Blocks until this imgFrame is either completely decoded, or is marked as
|
|
|
|
* aborted.
|
|
|
|
*
|
|
|
|
* Note that calling this on the main thread _blocks the main thread_. Be very
|
|
|
|
* careful in your use of this method to avoid excessive main thread jank or
|
|
|
|
* deadlock.
|
|
|
|
*/
|
2016-03-24 03:31:42 +03:00
|
|
|
void WaitUntilFinished() const;
|
2015-01-08 11:04:31 +03:00
|
|
|
|
2015-05-06 08:19:30 +03:00
|
|
|
/**
|
|
|
|
* Returns the number of bytes per pixel this imgFrame requires. This is a
|
|
|
|
* worst-case value that does not take into account the effects of format
|
|
|
|
* changes caused by Optimize(), since an imgFrame is not optimized throughout
|
|
|
|
* its lifetime.
|
|
|
|
*/
|
2019-03-15 20:29:02 +03:00
|
|
|
uint32_t GetBytesPerPixel() const { return 4; }
|
2015-05-06 08:19:30 +03:00
|
|
|
|
2019-03-15 20:29:02 +03:00
|
|
|
const IntSize& GetSize() const { return mImageSize; }
|
|
|
|
IntRect GetRect() const { return IntRect(IntPoint(0, 0), mImageSize); }
|
2018-05-29 15:36:11 +03:00
|
|
|
const IntRect& GetBlendRect() const { return mBlendRect; }
|
|
|
|
IntRect GetBoundedBlendRect() const {
|
2019-03-15 20:29:02 +03:00
|
|
|
return mBlendRect.Intersect(GetRect());
|
2018-05-29 15:36:11 +03:00
|
|
|
}
|
|
|
|
FrameTimeout GetTimeout() const { return mTimeout; }
|
|
|
|
BlendMethod GetBlendMethod() const { return mBlendMethod; }
|
|
|
|
DisposalMethod GetDisposalMethod() const { return mDisposalMethod; }
|
|
|
|
bool FormatHasAlpha() const { return mFormat == SurfaceFormat::B8G8R8A8; }
|
2015-03-31 20:48:00 +03:00
|
|
|
void GetImageData(uint8_t** aData, uint32_t* length) const;
|
2013-06-14 17:42:01 +04:00
|
|
|
uint8_t* GetImageData() const;
|
2015-01-08 11:04:31 +03:00
|
|
|
|
2018-09-17 22:06:28 +03:00
|
|
|
const IntRect& GetDirtyRect() const { return mDirtyRect; }
|
|
|
|
void SetDirtyRect(const IntRect& aDirtyRect) { mDirtyRect = aDirtyRect; }
|
|
|
|
|
2014-09-19 06:26:01 +04:00
|
|
|
void SetOptimizable();
|
2014-02-25 07:37:51 +04:00
|
|
|
|
2017-02-08 23:48:59 +03:00
|
|
|
void FinalizeSurface();
|
2016-08-18 22:43:16 +03:00
|
|
|
already_AddRefed<SourceSurface> GetSourceSurface();
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
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-25 16:13:51 +03:00
|
|
|
struct AddSizeOfCbData {
|
|
|
|
AddSizeOfCbData()
|
|
|
|
: heap(0), nonHeap(0), handles(0), index(0), externalId(0) {}
|
|
|
|
|
|
|
|
size_t heap;
|
|
|
|
size_t nonHeap;
|
|
|
|
size_t handles;
|
|
|
|
size_t index;
|
|
|
|
uint64_t externalId;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::function<void(AddSizeOfCbData& aMetadata)> AddSizeOfCb;
|
|
|
|
|
|
|
|
void AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
|
|
|
|
const AddSizeOfCb& aCallback) const;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
|
2013-06-14 17:42:01 +04:00
|
|
|
private: // methods
|
2014-08-23 00:49:54 +04:00
|
|
|
~imgFrame();
|
|
|
|
|
2018-05-29 15:36:12 +03:00
|
|
|
/**
|
|
|
|
* Used when the caller desires raw access to the underlying frame buffer.
|
|
|
|
* If the locking succeeds, the data pointer to the start of the buffer is
|
|
|
|
* returned, else it returns nullptr.
|
|
|
|
*
|
|
|
|
* @param aOnlyFinished If true, only attempt to lock if imgFrame::Finish has
|
|
|
|
* been called.
|
|
|
|
*/
|
|
|
|
uint8_t* LockImageData(bool aOnlyFinished);
|
2014-11-27 00:22:10 +03:00
|
|
|
nsresult UnlockImageData();
|
2016-09-15 14:53:12 +03:00
|
|
|
nsresult Optimize(gfx::DrawTarget* aTarget);
|
2015-01-08 11:04:31 +03:00
|
|
|
|
|
|
|
void AssertImageDataLocked() const;
|
|
|
|
|
2016-03-24 03:31:42 +03:00
|
|
|
bool AreAllPixelsWritten() const;
|
2015-01-08 11:04:31 +03:00
|
|
|
nsresult ImageUpdatedInternal(const nsIntRect& aUpdateRect);
|
2015-03-31 20:48:00 +03:00
|
|
|
void GetImageDataInternal(uint8_t** aData, uint32_t* length) const;
|
2015-01-08 11:04:31 +03:00
|
|
|
uint32_t GetImageBytesPerRow() const;
|
|
|
|
uint32_t GetImageDataLength() const;
|
2017-02-08 23:48:59 +03:00
|
|
|
void FinalizeSurfaceInternal();
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* @param aTemporary If true, it will assume the caller does not require a
|
|
|
|
* wrapping RecycleSourceSurface to protect the underlying
|
|
|
|
* surface from recycling. The reference to the surface
|
|
|
|
* must be freed before releasing the main thread context.
|
|
|
|
*/
|
|
|
|
already_AddRefed<SourceSurface> GetSourceSurfaceInternal(bool aTemporary);
|
2015-01-08 11:04:31 +03:00
|
|
|
|
2010-08-13 17:30:02 +04:00
|
|
|
struct SurfaceWithFormat {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxDrawable> mDrawable;
|
2014-04-20 05:28:38 +04:00
|
|
|
SurfaceFormat mFormat;
|
2018-06-14 08:21:37 +03:00
|
|
|
SurfaceWithFormat() : mFormat(SurfaceFormat::UNKNOWN) {}
|
2014-04-20 05:28:38 +04:00
|
|
|
SurfaceWithFormat(gfxDrawable* aDrawable, SurfaceFormat aFormat)
|
2015-03-31 20:48:00 +03:00
|
|
|
: mDrawable(aDrawable), mFormat(aFormat) {}
|
2018-06-04 02:37:17 +03:00
|
|
|
SurfaceWithFormat(SurfaceWithFormat&& aOther)
|
|
|
|
: mDrawable(std::move(aOther.mDrawable)), mFormat(aOther.mFormat) {}
|
|
|
|
SurfaceWithFormat& operator=(SurfaceWithFormat&& aOther) {
|
|
|
|
mDrawable = std::move(aOther.mDrawable);
|
|
|
|
mFormat = aOther.mFormat;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
SurfaceWithFormat& operator=(const SurfaceWithFormat& aOther) = delete;
|
|
|
|
SurfaceWithFormat(const SurfaceWithFormat& aOther) = delete;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsValid() { return !!mDrawable; }
|
2010-08-13 17:30:02 +04:00
|
|
|
};
|
|
|
|
|
2016-07-31 00:49:03 +03:00
|
|
|
SurfaceWithFormat SurfaceForDrawing(bool aDoPartialDecode, bool aDoTile,
|
2014-08-23 00:12:38 +04:00
|
|
|
ImageRegion& aRegion,
|
2014-04-20 05:28:38 +04:00
|
|
|
SourceSurface* aSurface);
|
2010-03-12 13:08:25 +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
|
|
|
private: // data
|
2015-01-08 11:04:31 +03:00
|
|
|
friend class DrawableFrameRef;
|
|
|
|
friend class RawAccessFrameRef;
|
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
|
|
|
friend class RecyclingSourceSurface;
|
2015-01-08 11:04:31 +03:00
|
|
|
friend class UnlockImageDataRunnable;
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2015-01-12 06:28:02 +03:00
|
|
|
// Thread-safe mutable data, protected by mMonitor.
|
2015-01-08 11:04:31 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-01-12 06:28:02 +03:00
|
|
|
mutable Monitor mMonitor;
|
2015-01-08 11:04:31 +03:00
|
|
|
|
2017-01-18 21:31:20 +03:00
|
|
|
/**
|
|
|
|
* Surface which contains either a weak or a strong reference to its
|
|
|
|
* underlying data buffer. If it is a weak reference, and there are no strong
|
|
|
|
* references, the buffer may be released due to events such as low memory.
|
|
|
|
*/
|
|
|
|
RefPtr<DataSourceSurface> mRawSurface;
|
2019-03-13 05:48:38 +03:00
|
|
|
RefPtr<DataSourceSurface> mBlankRawSurface;
|
2017-01-18 21:31:20 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Refers to the same data as mRawSurface, but when set, it guarantees that
|
|
|
|
* we hold a strong reference to the underlying data buffer.
|
|
|
|
*/
|
|
|
|
RefPtr<DataSourceSurface> mLockedSurface;
|
2019-03-13 05:48:38 +03:00
|
|
|
RefPtr<DataSourceSurface> mBlankLockedSurface;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
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
|
|
|
/**
|
|
|
|
* Optimized copy of mRawSurface for the DrawTarget that will render it. This
|
|
|
|
* is unused if the DrawTarget is able to render DataSourceSurface buffers
|
|
|
|
* directly.
|
|
|
|
*/
|
|
|
|
RefPtr<SourceSurface> mOptSurface;
|
2015-01-08 11:04:31 +03:00
|
|
|
|
|
|
|
nsIntRect mDecoded;
|
|
|
|
|
|
|
|
//! Number of RawAccessFrameRefs currently alive for this imgFrame.
|
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
|
|
|
int16_t mLockCount;
|
|
|
|
|
|
|
|
//! Number of RecyclingSourceSurface's currently alive for this imgFrame.
|
|
|
|
int16_t mRecycleLockCount;
|
2015-01-08 11:04:31 +03:00
|
|
|
|
2015-01-12 06:28:02 +03:00
|
|
|
bool mAborted;
|
2016-03-24 03:31:42 +03:00
|
|
|
bool mFinished;
|
2015-07-31 17:29:10 +03:00
|
|
|
bool mOptimizable;
|
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
|
|
|
bool mShouldRecycle;
|
2015-01-08 11:04:31 +03:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Effectively const data, only mutated in the Init methods.
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-09-17 22:06:28 +03:00
|
|
|
//! The size of the buffer we are decoding to.
|
2014-11-27 00:22:10 +03:00
|
|
|
IntSize mImageSize;
|
2018-09-17 22:06:28 +03:00
|
|
|
|
|
|
|
//! The contents for the frame, as represented in the encoded image. This may
|
|
|
|
//! differ from mImageSize because it may be a partial frame. For the first
|
|
|
|
//! frame, this means we need to shift the data in place, and for animated
|
|
|
|
//! frames, it likely need to combine with a previous frame to get the full
|
|
|
|
//! contents.
|
2018-05-29 15:36:11 +03:00
|
|
|
IntRect mBlendRect;
|
|
|
|
|
2018-09-17 22:06:28 +03:00
|
|
|
//! This is the region that has changed between this frame and the previous
|
|
|
|
//! frame of an animation. For the first frame, this will be the same as
|
|
|
|
//! mFrameRect.
|
|
|
|
IntRect mDirtyRect;
|
|
|
|
|
2018-05-29 15:36:11 +03:00
|
|
|
//! The timeout for this frame.
|
|
|
|
FrameTimeout mTimeout;
|
|
|
|
|
|
|
|
DisposalMethod mDisposalMethod;
|
|
|
|
BlendMethod mBlendMethod;
|
|
|
|
SurfaceFormat mFormat;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
|
2015-01-08 11:04:31 +03:00
|
|
|
bool mNonPremult;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
};
|
|
|
|
|
2014-09-11 04:06:45 +04:00
|
|
|
/**
|
|
|
|
* A reference to an imgFrame that holds the imgFrame's surface in memory,
|
|
|
|
* allowing drawing. If you have a DrawableFrameRef |ref| and |if (ref)| returns
|
2016-08-18 22:43:16 +03:00
|
|
|
* true, then calls to Draw() and GetSourceSurface() are guaranteed to succeed.
|
2014-09-11 04:06:45 +04:00
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
class DrawableFrameRef final {
|
2017-01-18 21:31:20 +03:00
|
|
|
typedef gfx::DataSourceSurface DataSourceSurface;
|
|
|
|
|
2014-09-11 04:06:45 +04:00
|
|
|
public:
|
|
|
|
DrawableFrameRef() {}
|
|
|
|
|
|
|
|
explicit DrawableFrameRef(imgFrame* aFrame) : mFrame(aFrame) {
|
2017-03-15 15:08:47 +03:00
|
|
|
MOZ_ASSERT(aFrame);
|
|
|
|
MonitorAutoLock lock(aFrame->mMonitor);
|
|
|
|
|
2017-01-18 21:31:20 +03:00
|
|
|
if (aFrame->mRawSurface) {
|
2018-05-29 15:36:13 +03:00
|
|
|
mRef.emplace(aFrame->mRawSurface, DataSourceSurface::READ);
|
2017-01-18 21:31:20 +03:00
|
|
|
if (!mRef->IsMapped()) {
|
|
|
|
mFrame = nullptr;
|
2018-05-29 15:36:13 +03:00
|
|
|
mRef.reset();
|
2017-01-18 21:31:20 +03:00
|
|
|
}
|
|
|
|
} else {
|
2018-05-29 15:36:13 +03:00
|
|
|
MOZ_ASSERT(aFrame->mOptSurface);
|
2012-09-26 19:33:06 +04:00
|
|
|
}
|
2014-09-11 04:06:45 +04:00
|
|
|
}
|
2012-09-26 19:33:06 +04:00
|
|
|
|
2014-09-11 04:06:45 +04:00
|
|
|
DrawableFrameRef(DrawableFrameRef&& aOther)
|
|
|
|
: mFrame(aOther.mFrame.forget()), mRef(std::move(aOther.mRef)) {}
|
2012-09-26 19:33:06 +04:00
|
|
|
|
2014-09-11 04:06:45 +04:00
|
|
|
DrawableFrameRef& operator=(DrawableFrameRef&& aOther) {
|
|
|
|
MOZ_ASSERT(this != &aOther, "Self-moves are prohibited");
|
|
|
|
mFrame = aOther.mFrame.forget();
|
2018-05-30 22:15:35 +03:00
|
|
|
mRef = std::move(aOther.mRef);
|
2014-09-11 04:06:45 +04:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-02-03 19:52:36 +03:00
|
|
|
explicit operator bool() const { return bool(mFrame); }
|
2014-09-11 04:06:45 +04:00
|
|
|
|
|
|
|
imgFrame* operator->() {
|
|
|
|
MOZ_ASSERT(mFrame);
|
|
|
|
return mFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
const imgFrame* operator->() const {
|
|
|
|
MOZ_ASSERT(mFrame);
|
|
|
|
return mFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
imgFrame* get() { return mFrame; }
|
|
|
|
const imgFrame* get() const { return mFrame; }
|
|
|
|
|
|
|
|
void reset() {
|
|
|
|
mFrame = nullptr;
|
2018-05-29 15:36:13 +03:00
|
|
|
mRef.reset();
|
2014-09-11 04:06:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-07-01 04:57:03 +03:00
|
|
|
DrawableFrameRef(const DrawableFrameRef& aOther) = delete;
|
2018-05-29 15:36:13 +03:00
|
|
|
DrawableFrameRef& operator=(const DrawableFrameRef& aOther) = delete;
|
2015-07-01 04:57:03 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgFrame> mFrame;
|
2018-05-29 15:36:13 +03:00
|
|
|
Maybe<DataSourceSurface::ScopedMap> mRef;
|
2014-09-11 04:06:45 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A reference to an imgFrame that holds the imgFrame's surface in memory in a
|
|
|
|
* format appropriate for access as raw data. If you have a RawAccessFrameRef
|
2019-03-15 20:29:02 +03:00
|
|
|
* |ref| and |if (ref)| is true, then calls to GetImageData() is guaranteed to
|
|
|
|
* succeed. This guarantee is stronger than DrawableFrameRef, so everything that
|
|
|
|
* a valid DrawableFrameRef guarantees is also guaranteed by a valid
|
|
|
|
* RawAccessFrameRef.
|
2014-09-11 04:06:45 +04:00
|
|
|
*
|
|
|
|
* This may be considerably more expensive than is necessary just for drawing,
|
|
|
|
* so only use this when you need to read or write the raw underlying image data
|
|
|
|
* that the imgFrame holds.
|
2015-09-20 02:21:02 +03:00
|
|
|
*
|
|
|
|
* Once all an imgFrame's RawAccessFrameRefs go out of scope, new
|
|
|
|
* RawAccessFrameRefs cannot be created.
|
2014-09-11 04:06:45 +04:00
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
class RawAccessFrameRef final {
|
2014-09-11 04:06:45 +04:00
|
|
|
public:
|
2018-05-29 15:36:12 +03:00
|
|
|
RawAccessFrameRef() : mData(nullptr) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-05-29 15:36:12 +03:00
|
|
|
explicit RawAccessFrameRef(imgFrame* aFrame, bool aOnlyFinished)
|
2014-09-11 04:06:45 +04:00
|
|
|
: mFrame(aFrame), mData(nullptr) {
|
|
|
|
MOZ_ASSERT(mFrame, "Need a frame");
|
|
|
|
|
2018-05-29 15:36:12 +03:00
|
|
|
mData = mFrame->LockImageData(aOnlyFinished);
|
|
|
|
if (!mData) {
|
2014-09-11 04:06:45 +04:00
|
|
|
mFrame = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RawAccessFrameRef(RawAccessFrameRef&& aOther)
|
|
|
|
: mFrame(aOther.mFrame.forget()), mData(aOther.mData) {
|
2018-05-29 15:36:12 +03:00
|
|
|
aOther.mData = nullptr;
|
|
|
|
}
|
2014-09-11 04:06:45 +04:00
|
|
|
|
|
|
|
~RawAccessFrameRef() {
|
|
|
|
if (mFrame) {
|
|
|
|
mFrame->UnlockImageData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RawAccessFrameRef& operator=(RawAccessFrameRef&& aOther) {
|
|
|
|
MOZ_ASSERT(this != &aOther, "Self-moves are prohibited");
|
|
|
|
|
|
|
|
if (mFrame) {
|
|
|
|
mFrame->UnlockImageData();
|
|
|
|
}
|
|
|
|
|
|
|
|
mFrame = aOther.mFrame.forget();
|
2018-05-29 15:36:12 +03:00
|
|
|
mData = aOther.mData;
|
|
|
|
aOther.mData = nullptr;
|
2014-09-11 04:06:45 +04:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-02-03 19:52:36 +03:00
|
|
|
explicit operator bool() const { return bool(mFrame); }
|
2014-09-11 04:06:45 +04:00
|
|
|
|
|
|
|
imgFrame* operator->() {
|
|
|
|
MOZ_ASSERT(mFrame);
|
|
|
|
return mFrame.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
const imgFrame* operator->() const {
|
|
|
|
MOZ_ASSERT(mFrame);
|
|
|
|
return mFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
imgFrame* get() { return mFrame; }
|
|
|
|
const imgFrame* get() const { return mFrame; }
|
|
|
|
|
|
|
|
void reset() {
|
|
|
|
if (mFrame) {
|
|
|
|
mFrame->UnlockImageData();
|
|
|
|
}
|
|
|
|
mFrame = nullptr;
|
2018-05-29 15:36:12 +03:00
|
|
|
mData = nullptr;
|
2014-09-11 04:06:45 +04:00
|
|
|
}
|
|
|
|
|
2018-05-29 15:36:12 +03:00
|
|
|
uint8_t* Data() const { return mData; }
|
|
|
|
|
2014-09-11 04:06:45 +04:00
|
|
|
private:
|
2015-07-01 04:57:03 +03:00
|
|
|
RawAccessFrameRef(const RawAccessFrameRef& aOther) = delete;
|
2018-05-29 15:36:12 +03:00
|
|
|
RawAccessFrameRef& operator=(const RawAccessFrameRef& aOther) = delete;
|
2015-07-01 04:57:03 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgFrame> mFrame;
|
2018-05-29 15:36:12 +03:00
|
|
|
uint8_t* mData;
|
2014-09-11 04:06:45 +04:00
|
|
|
};
|
2014-07-10 19:00:31 +04:00
|
|
|
|
|
|
|
} // namespace image
|
|
|
|
} // namespace mozilla
|
2012-09-26 19:33:06 +04:00
|
|
|
|
2015-05-15 06:52:05 +03:00
|
|
|
#endif // mozilla_image_imgFrame_h
|