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 {
|
2016-03-10 02:39:02 +03:00
|
|
|
FULLY_OPAQUE,
|
2015-01-08 00:07:23 +03:00
|
|
|
SOME_TRANSPARENCY
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
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.
|
|
|
|
*/
|
2014-11-27 00:22:10 +03:00
|
|
|
nsresult InitForDecoder(const nsIntSize& aImageSize,
|
|
|
|
const nsIntRect& aRect,
|
2014-09-15 02:22:45 +04:00
|
|
|
SurfaceFormat aFormat,
|
2015-01-08 11:04:31 +03:00
|
|
|
uint8_t aPaletteDepth = 0,
|
2017-01-18 21:31:20 +03:00
|
|
|
bool aNonPremult = false,
|
2018-05-29 15:36:11 +03:00
|
|
|
const Maybe<AnimationParams>& aAnimParams = Nothing());
|
2014-09-15 02:22:45 +04:00
|
|
|
|
2017-01-18 21:31:20 +03:00
|
|
|
nsresult InitForAnimator(const nsIntSize& aSize,
|
|
|
|
SurfaceFormat aFormat)
|
2014-09-15 02:22:45 +04:00
|
|
|
{
|
2018-05-29 15:36:11 +03:00
|
|
|
nsIntRect frameRect(0, 0, aSize.width, aSize.height);
|
|
|
|
AnimationParams animParams { frameRect, FrameTimeout::Forever(),
|
|
|
|
/* aFrameNum */ 1, BlendMethod::OVER,
|
|
|
|
DisposalMethod::NOT_SPECIFIED };
|
|
|
|
return InitForDecoder(aSize, frameRect,
|
|
|
|
aFormat, 0, false, Some(animParams));
|
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,
|
2016-09-15 14:53:12 +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.
|
|
|
|
*/
|
|
|
|
uint32_t GetBytesPerPixel() const { return GetIsPaletted() ? 1 : 4; }
|
|
|
|
|
2018-05-29 15:36:11 +03:00
|
|
|
const IntSize& GetImageSize() const { return mImageSize; }
|
|
|
|
const IntRect& GetRect() const { return mFrameRect; }
|
2016-05-27 08:19:38 +03:00
|
|
|
IntSize GetSize() const { return mFrameRect.Size(); }
|
2018-05-29 15:36:11 +03:00
|
|
|
const IntRect& GetBlendRect() const { return mBlendRect; }
|
|
|
|
IntRect GetBoundedBlendRect() const { return mBlendRect.Intersect(mFrameRect); }
|
|
|
|
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
|
|
|
|
|
|
|
bool GetIsPaletted() const;
|
2015-03-31 20:48:00 +03:00
|
|
|
void GetPaletteData(uint32_t** aPalette, uint32_t* length) const;
|
2013-06-14 17:42:01 +04:00
|
|
|
uint32_t* GetPaletteData() const;
|
2015-01-08 11:04:31 +03:00
|
|
|
uint8_t GetPaletteDepth() const { return mPaletteDepth; }
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetCompositingFailed() const;
|
|
|
|
void SetCompositingFailed(bool val);
|
2009-11-13 02:18:40 +03:00
|
|
|
|
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
|
|
|
|
2015-07-29 07:02:45 +03:00
|
|
|
void AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf, size_t& aHeapSizeOut,
|
2017-02-22 17:30:22 +03:00
|
|
|
size_t& aNonHeapSizeOut,
|
2018-02-22 22:26:29 +03:00
|
|
|
size_t& aExtHandlesOut) 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();
|
2016-08-18 22:43:16 +03:00
|
|
|
already_AddRefed<SourceSurface> GetSourceSurfaceInternal();
|
2015-01-08 11:04:31 +03:00
|
|
|
|
|
|
|
uint32_t PaletteDataLength() const
|
|
|
|
{
|
2015-01-23 00:29:36 +03:00
|
|
|
return mPaletteDepth ? (size_t(1) << mPaletteDepth) * sizeof(uint32_t)
|
2015-01-08 11:04:31 +03:00
|
|
|
: 0;
|
|
|
|
}
|
2014-09-19 06:26:01 +04: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-04-13 16:01:28 +03:00
|
|
|
SurfaceWithFormat() { }
|
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)
|
|
|
|
{ }
|
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,
|
2011-09-29 10:19:26 +04:00
|
|
|
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;
|
|
|
|
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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
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.
|
|
|
|
int32_t mLockCount;
|
|
|
|
|
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;
|
2015-01-08 11:04:31 +03:00
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Effectively const data, only mutated in the Init methods.
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-11-27 00:22:10 +03:00
|
|
|
IntSize mImageSize;
|
2016-05-27 08:19:38 +03:00
|
|
|
IntRect mFrameRect;
|
2018-05-29 15:36:11 +03:00
|
|
|
IntRect mBlendRect;
|
|
|
|
|
|
|
|
//! 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
|
|
|
|
|
|
|
// The palette and image data for images that are paletted, since Cairo
|
|
|
|
// doesn't support these images.
|
|
|
|
// The paletted data comes first, then the image data itself.
|
|
|
|
// Total length is PaletteDataLength() + GetImageDataLength().
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t* mPalettedImageData;
|
2015-01-08 11:04:31 +03:00
|
|
|
uint8_t mPaletteDepth;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
|
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
|
|
|
|
|
|
|
|
2015-01-08 11:04:31 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Main-thread-only mutable data.
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2012-09-26 19:33:06 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mCompositingFailed;
|
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
|
2014-09-11 04:06:45 +04:00
|
|
|
{
|
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)
|
2012-09-26 19:33:06 +04:00
|
|
|
{
|
2017-03-15 15:08:47 +03:00
|
|
|
MOZ_ASSERT(aFrame);
|
|
|
|
MonitorAutoLock lock(aFrame->mMonitor);
|
2018-05-29 15:36:13 +03:00
|
|
|
MOZ_ASSERT(!aFrame->GetIsPaletted(), "Paletted must use RawAccessFrameRef");
|
2017-03-15 15:08:47 +03:00
|
|
|
|
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())
|
2018-05-30 22:15:35 +03:00
|
|
|
, mRef(std::move(aOther.mRef))
|
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& 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
|
2016-05-26 21:33:38 +03:00
|
|
|
* |ref| and |if (ref)| is true, then calls to GetImageData() and
|
|
|
|
* GetPaletteData() are 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) { }
|
2014-09-11 04:06:45 +04: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)
|
2018-05-29 15:36:12 +03:00
|
|
|
, mData(nullptr)
|
2014-09-11 04:06:45 +04:00
|
|
|
{
|
|
|
|
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())
|
2018-05-29 15:36:12 +03:00
|
|
|
, mData(aOther.mData)
|
|
|
|
{
|
|
|
|
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; }
|
|
|
|
uint32_t PaletteDataLength() const { return mFrame->PaletteDataLength(); }
|
|
|
|
|
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
|