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
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 11:12:37 +00: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 01:50:15 +00:00
|
|
|
|
2015-05-15 03:52:05 +00: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 01:50:15 +00:00
|
|
|
|
2013-06-23 12:03:39 +00:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2015-01-12 03:28:02 +00:00
|
|
|
#include "mozilla/Monitor.h"
|
2014-09-11 00:06:45 +00:00
|
|
|
#include "mozilla/Move.h"
|
2014-02-25 03:37:51 +00:00
|
|
|
#include "mozilla/VolatileBuffer.h"
|
2010-08-13 13:30:27 +00:00
|
|
|
#include "gfxDrawable.h"
|
2012-04-17 22:04:15 +00:00
|
|
|
#include "imgIContainer.h"
|
2015-01-08 08:04:31 +00:00
|
|
|
#include "MainThreadUtils.h"
|
2014-02-25 03:37:51 +00:00
|
|
|
|
2014-07-10 15:00:31 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace image {
|
|
|
|
|
2014-08-22 20:12:38 +00:00
|
|
|
class ImageRegion;
|
2014-09-11 00:06:45 +00:00
|
|
|
class DrawableFrameRef;
|
|
|
|
class RawAccessFrameRef;
|
2014-08-22 20:12:38 +00:00
|
|
|
|
2015-01-25 22:22:07 +00:00
|
|
|
enum class BlendMethod : int8_t {
|
2015-01-07 21:07:23 +00:00
|
|
|
// All color components of the frame, including alpha, overwrite the current
|
|
|
|
// contents of the frame's output buffer region.
|
|
|
|
SOURCE,
|
|
|
|
|
|
|
|
// The frame should be composited onto the output buffer based on its alpha,
|
|
|
|
// using a simple OVER operation.
|
|
|
|
OVER
|
2015-01-25 22:22:07 +00:00
|
|
|
};
|
2015-01-07 21:07:23 +00:00
|
|
|
|
2015-01-25 22:22:07 +00:00
|
|
|
enum class DisposalMethod : int8_t {
|
2015-01-07 21:07:23 +00:00
|
|
|
CLEAR_ALL = -1, // Clear the whole image, revealing what's underneath.
|
|
|
|
NOT_SPECIFIED, // Leave the frame and let the new frame draw on top.
|
|
|
|
KEEP, // Leave the frame and let the new frame draw on top.
|
|
|
|
CLEAR, // Clear the frame's area, revealing what's underneath.
|
|
|
|
RESTORE_PREVIOUS // Restore the previous (composited) frame.
|
2015-01-25 22:22:07 +00:00
|
|
|
};
|
2015-01-07 21:07:23 +00:00
|
|
|
|
2015-01-25 22:22:07 +00:00
|
|
|
enum class Opacity : uint8_t {
|
2015-01-07 21:07:23 +00:00
|
|
|
OPAQUE,
|
|
|
|
SOME_TRANSPARENCY
|
2015-01-25 22:22:07 +00:00
|
|
|
};
|
2015-01-07 21:07:23 +00:00
|
|
|
|
2015-01-08 08:04:31 +00:00
|
|
|
/**
|
|
|
|
* AnimationData contains all of the information necessary for using an imgFrame
|
|
|
|
* as part of an animation.
|
|
|
|
*
|
|
|
|
* It includes pointers to the raw image data of the underlying imgFrame, but
|
|
|
|
* does not own that data. A RawAccessFrameRef for the underlying imgFrame must
|
|
|
|
* outlive the AnimationData for it to remain valid.
|
|
|
|
*/
|
|
|
|
struct AnimationData
|
|
|
|
{
|
|
|
|
AnimationData(uint8_t* aRawData, uint32_t aPaletteDataLength,
|
|
|
|
int32_t aRawTimeout, const nsIntRect& aRect,
|
|
|
|
BlendMethod aBlendMethod, DisposalMethod aDisposalMethod,
|
|
|
|
bool aHasAlpha)
|
|
|
|
: mRawData(aRawData)
|
|
|
|
, mPaletteDataLength(aPaletteDataLength)
|
|
|
|
, mRawTimeout(aRawTimeout)
|
|
|
|
, mRect(aRect)
|
|
|
|
, mBlendMethod(aBlendMethod)
|
|
|
|
, mDisposalMethod(aDisposalMethod)
|
|
|
|
, mHasAlpha(aHasAlpha)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
uint8_t* mRawData;
|
|
|
|
uint32_t mPaletteDataLength;
|
|
|
|
int32_t mRawTimeout;
|
|
|
|
nsIntRect mRect;
|
|
|
|
BlendMethod mBlendMethod;
|
|
|
|
DisposalMethod mDisposalMethod;
|
|
|
|
bool mHasAlpha;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ScalingData contains all of the information necessary for performing
|
|
|
|
* high-quality (CPU-based) scaling an imgFrame.
|
|
|
|
*
|
|
|
|
* It includes pointers to the raw image data of the underlying imgFrame, but
|
|
|
|
* does not own that data. A RawAccessFrameRef for the underlying imgFrame must
|
|
|
|
* outlive the ScalingData for it to remain valid.
|
|
|
|
*/
|
|
|
|
struct ScalingData
|
|
|
|
{
|
|
|
|
ScalingData(uint8_t* aRawData,
|
|
|
|
gfx::IntSize aSize,
|
|
|
|
uint32_t aBytesPerRow,
|
|
|
|
gfx::SurfaceFormat aFormat)
|
|
|
|
: mRawData(aRawData)
|
|
|
|
, mSize(aSize)
|
|
|
|
, mBytesPerRow(aBytesPerRow)
|
|
|
|
, mFormat(aFormat)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
uint8_t* mRawData;
|
|
|
|
gfx::IntSize mSize;
|
|
|
|
uint32_t mBytesPerRow;
|
|
|
|
gfx::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 01:50:15 +00:00
|
|
|
class imgFrame
|
|
|
|
{
|
2014-07-10 15:00:31 +00:00
|
|
|
typedef gfx::Color Color;
|
|
|
|
typedef gfx::DataSourceSurface DataSourceSurface;
|
2014-08-22 20:49:54 +00:00
|
|
|
typedef gfx::DrawTarget DrawTarget;
|
2014-07-10 15:00:31 +00:00
|
|
|
typedef gfx::IntSize IntSize;
|
|
|
|
typedef gfx::SourceSurface SourceSurface;
|
|
|
|
typedef gfx::SurfaceFormat SurfaceFormat;
|
2014-04-20 01:28: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
|
|
|
public:
|
2014-08-22 20:49:54 +00: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 01:50:15 +00:00
|
|
|
imgFrame();
|
|
|
|
|
2014-09-14 22:22:45 +00: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-26 21:22:10 +00:00
|
|
|
nsresult InitForDecoder(const nsIntSize& aImageSize,
|
|
|
|
const nsIntRect& aRect,
|
2014-09-14 22:22:45 +00:00
|
|
|
SurfaceFormat aFormat,
|
2015-01-08 08:04:31 +00:00
|
|
|
uint8_t aPaletteDepth = 0,
|
|
|
|
bool aNonPremult = false);
|
2014-09-14 22:22:45 +00:00
|
|
|
|
|
|
|
nsresult InitForDecoder(const nsIntSize& aSize,
|
|
|
|
SurfaceFormat aFormat,
|
|
|
|
uint8_t aPaletteDepth = 0)
|
|
|
|
{
|
2014-11-26 21:22:10 +00:00
|
|
|
return InitForDecoder(aSize, nsIntRect(0, 0, aSize.width, aSize.height),
|
2014-09-14 22:22:45 +00:00
|
|
|
aFormat, aPaletteDepth);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-26 21:22:10 +00:00
|
|
|
* platforms, and raw access to the surface (using RawAccessRef()) may be much
|
|
|
|
* more expensive than in the InitForDecoder() case.
|
2014-09-14 22:22:45 +00:00
|
|
|
*/
|
|
|
|
nsresult InitWithDrawable(gfxDrawable* aDrawable,
|
|
|
|
const nsIntSize& aSize,
|
|
|
|
const SurfaceFormat aFormat,
|
|
|
|
GraphicsFilter aFilter,
|
|
|
|
uint32_t aImageFlags);
|
|
|
|
|
2015-01-15 23:11:36 +00:00
|
|
|
/**
|
|
|
|
* Reinitializes an existing imgFrame with new parameters. You must be holding
|
|
|
|
* a RawAccessFrameRef to the imgFrame, and it must never have been written
|
|
|
|
* to, marked finished, or aborted.
|
|
|
|
*
|
|
|
|
* XXX(seth): We will remove this in bug 1117607.
|
|
|
|
*/
|
|
|
|
nsresult ReinitForDecoder(const nsIntSize& aImageSize,
|
|
|
|
const nsIntRect& aRect,
|
|
|
|
SurfaceFormat aFormat,
|
|
|
|
uint8_t aPaletteDepth = 0,
|
|
|
|
bool aNonPremult = false);
|
|
|
|
|
2014-09-11 00:06:45 +00:00
|
|
|
DrawableFrameRef DrawableRef();
|
|
|
|
RawAccessFrameRef RawAccessRef();
|
|
|
|
|
2015-01-07 09:40:23 +00: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-22 20:12:38 +00:00
|
|
|
bool Draw(gfxContext* aContext, const ImageRegion& aRegion,
|
2014-11-26 21:22:10 +00:00
|
|
|
GraphicsFilter aFilter, uint32_t aImageFlags);
|
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
|
|
|
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 01:50:15 +00:00
|
|
|
|
2015-01-08 08:04:31 +00:00
|
|
|
/**
|
|
|
|
* Mark this imgFrame as completely decoded, and set final options.
|
|
|
|
*
|
2015-01-12 03:28:02 +00:00
|
|
|
* You must always call either Finish() or Abort() before releasing the last
|
|
|
|
* RawAccessFrameRef pointing to an imgFrame.
|
|
|
|
*
|
2015-01-08 08:04:31 +00:00
|
|
|
* @param aFrameOpacity Whether this imgFrame is opaque.
|
|
|
|
* @param aDisposalMethod For animation frames, how this imgFrame is cleared
|
|
|
|
* from the compositing frame before the next frame is
|
|
|
|
* displayed.
|
|
|
|
* @param aRawTimeout For animation frames, the timeout in milliseconds
|
|
|
|
* before the next frame is displayed. This timeout is
|
|
|
|
* not necessarily the timeout that will actually be
|
|
|
|
* used; see FrameAnimator::GetTimeoutForFrame.
|
|
|
|
* @param aBlendMethod For animation frames, a blending method to be used
|
|
|
|
* when compositing this frame.
|
|
|
|
*/
|
2015-01-12 03:28:02 +00:00
|
|
|
void Finish(Opacity aFrameOpacity = Opacity::SOME_TRANSPARENCY,
|
|
|
|
DisposalMethod aDisposalMethod = DisposalMethod::KEEP,
|
|
|
|
int32_t aRawTimeout = 0,
|
|
|
|
BlendMethod aBlendMethod = BlendMethod::OVER);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if this imgFrame is completely decoded.
|
|
|
|
*/
|
|
|
|
bool IsImageComplete() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
void WaitUntilComplete() const;
|
2015-01-08 08:04:31 +00:00
|
|
|
|
2015-05-06 05:19:30 +00: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; }
|
|
|
|
|
2015-04-28 18:46:17 +00:00
|
|
|
IntSize GetImageSize() const { return mImageSize; }
|
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
|
|
|
nsIntRect GetRect() const;
|
2014-08-22 20:49:54 +00:00
|
|
|
IntSize GetSize() const { return mSize; }
|
2014-09-19 21:53:29 +00:00
|
|
|
bool NeedsPadding() const { return mOffset != nsIntPoint(0, 0); }
|
2015-03-31 17:48:00 +00:00
|
|
|
void GetImageData(uint8_t** aData, uint32_t* length) const;
|
2013-06-14 13:42:01 +00:00
|
|
|
uint8_t* GetImageData() const;
|
2015-01-08 08:04:31 +00:00
|
|
|
|
|
|
|
bool GetIsPaletted() const;
|
2015-03-31 17:48:00 +00:00
|
|
|
void GetPaletteData(uint32_t** aPalette, uint32_t* length) const;
|
2013-06-14 13:42:01 +00:00
|
|
|
uint32_t* GetPaletteData() const;
|
2015-01-08 08:04:31 +00: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 01:50:15 +00:00
|
|
|
|
2015-01-08 08:04:31 +00:00
|
|
|
/**
|
|
|
|
* Get the SurfaceFormat for this imgFrame.
|
|
|
|
*
|
|
|
|
* This should only be used for assertions.
|
|
|
|
*/
|
|
|
|
SurfaceFormat GetFormat() const;
|
2015-01-07 21:07:23 +00:00
|
|
|
|
2015-01-08 08:04:31 +00:00
|
|
|
AnimationData GetAnimationData() const;
|
|
|
|
ScalingData GetScalingData() const;
|
2015-01-07 21:07:23 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool GetCompositingFailed() const;
|
|
|
|
void SetCompositingFailed(bool val);
|
2009-11-12 23:18:40 +00:00
|
|
|
|
2014-09-19 02:26:01 +00:00
|
|
|
void SetOptimizable();
|
2014-02-25 03:37:51 +00:00
|
|
|
|
2015-01-08 08:04:31 +00:00
|
|
|
Color SinglePixelColor() const;
|
|
|
|
bool IsSinglePixel() const;
|
|
|
|
|
2014-07-10 15:00:31 +00:00
|
|
|
TemporaryRef<SourceSurface> GetSurface();
|
2014-08-22 20:49:54 +00:00
|
|
|
TemporaryRef<DrawTarget> GetDrawTarget();
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
|
2014-11-27 02:00:15 +00:00
|
|
|
size_t SizeOfExcludingThis(gfxMemoryLocation aLocation,
|
|
|
|
MallocSizeOf aMallocSizeOf) 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 01:50:15 +00:00
|
|
|
|
2013-06-14 13:42:01 +00:00
|
|
|
private: // methods
|
|
|
|
|
2014-08-22 20:49:54 +00:00
|
|
|
~imgFrame();
|
|
|
|
|
2014-11-26 21:22:10 +00:00
|
|
|
nsresult LockImageData();
|
|
|
|
nsresult UnlockImageData();
|
2014-09-19 02:26:01 +00:00
|
|
|
nsresult Optimize();
|
2015-01-08 08:04:31 +00:00
|
|
|
nsresult Deoptimize();
|
|
|
|
|
|
|
|
void AssertImageDataLocked() const;
|
|
|
|
|
2015-01-12 03:28:02 +00:00
|
|
|
bool IsImageCompleteInternal() const;
|
2015-01-08 08:04:31 +00:00
|
|
|
nsresult ImageUpdatedInternal(const nsIntRect& aUpdateRect);
|
2015-03-31 17:48:00 +00:00
|
|
|
void GetImageDataInternal(uint8_t** aData, uint32_t* length) const;
|
2015-01-08 08:04:31 +00:00
|
|
|
uint32_t GetImageBytesPerRow() const;
|
|
|
|
uint32_t GetImageDataLength() const;
|
|
|
|
int32_t GetStride() const;
|
|
|
|
TemporaryRef<SourceSurface> GetSurfaceInternal();
|
|
|
|
|
|
|
|
uint32_t PaletteDataLength() const
|
|
|
|
{
|
2015-01-22 21:29:36 +00:00
|
|
|
return mPaletteDepth ? (size_t(1) << mPaletteDepth) * sizeof(uint32_t)
|
2015-01-08 08:04:31 +00:00
|
|
|
: 0;
|
|
|
|
}
|
2014-09-19 02:26:01 +00:00
|
|
|
|
2010-08-13 13:30:02 +00:00
|
|
|
struct SurfaceWithFormat {
|
2010-08-13 13:30:27 +00:00
|
|
|
nsRefPtr<gfxDrawable> mDrawable;
|
2014-04-20 01:28:38 +00:00
|
|
|
SurfaceFormat mFormat;
|
2015-03-31 17:48:00 +00:00
|
|
|
SurfaceWithFormat() { }
|
2014-04-20 01:28:38 +00:00
|
|
|
SurfaceWithFormat(gfxDrawable* aDrawable, SurfaceFormat aFormat)
|
2015-03-31 17:48:00 +00:00
|
|
|
: mDrawable(aDrawable), mFormat(aFormat)
|
|
|
|
{ }
|
2011-09-29 06:19:26 +00:00
|
|
|
bool IsValid() { return !!mDrawable; }
|
2010-08-13 13:30:02 +00:00
|
|
|
};
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
SurfaceWithFormat SurfaceForDrawing(bool aDoPadding,
|
|
|
|
bool aDoPartialDecode,
|
|
|
|
bool aDoTile,
|
2014-08-22 20:12:38 +00:00
|
|
|
gfxContext* aContext,
|
2010-08-13 13:30:02 +00:00
|
|
|
const nsIntMargin& aPadding,
|
2014-03-02 16:17:26 +00:00
|
|
|
gfxRect& aImageRect,
|
2014-08-22 20:12:38 +00:00
|
|
|
ImageRegion& aRegion,
|
2014-04-20 01:28:38 +00:00
|
|
|
SourceSurface* aSurface);
|
2010-03-12 10:08:25 +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
|
|
|
private: // data
|
2015-01-08 08:04:31 +00:00
|
|
|
friend class DrawableFrameRef;
|
|
|
|
friend class RawAccessFrameRef;
|
|
|
|
friend class UnlockImageDataRunnable;
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2015-01-12 03:28:02 +00:00
|
|
|
// Thread-safe mutable data, protected by mMonitor.
|
2015-01-08 08:04:31 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-01-12 03:28:02 +00:00
|
|
|
mutable Monitor mMonitor;
|
2015-01-08 08:04:31 +00:00
|
|
|
|
2014-07-10 15:00:31 +00:00
|
|
|
RefPtr<DataSourceSurface> mImageSurface;
|
|
|
|
RefPtr<SourceSurface> mOptSurface;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
|
2015-01-08 08:04:31 +00:00
|
|
|
RefPtr<VolatileBuffer> mVBuf;
|
|
|
|
VolatileBufferPtr<uint8_t> mVBufPtr;
|
|
|
|
|
|
|
|
nsIntRect mDecoded;
|
|
|
|
|
|
|
|
//! Number of RawAccessFrameRefs currently alive for this imgFrame.
|
|
|
|
int32_t mLockCount;
|
|
|
|
|
|
|
|
//! Raw timeout for this frame. (See FrameAnimator::GetTimeoutForFrame.)
|
|
|
|
int32_t mTimeout; // -1 means display forever.
|
|
|
|
|
|
|
|
DisposalMethod mDisposalMethod;
|
|
|
|
BlendMethod mBlendMethod;
|
|
|
|
SurfaceFormat mFormat;
|
|
|
|
|
|
|
|
bool mHasNoAlpha;
|
2015-01-12 03:28:02 +00:00
|
|
|
bool mAborted;
|
2015-01-08 08:04:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Effectively const data, only mutated in the Init methods.
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-11-26 21:22:10 +00:00
|
|
|
IntSize mImageSize;
|
2014-04-20 01:28:38 +00:00
|
|
|
IntSize mSize;
|
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
|
|
|
nsIntPoint mOffset;
|
|
|
|
|
|
|
|
// 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 15:56:38 +00:00
|
|
|
uint8_t* mPalettedImageData;
|
2015-01-08 08:04:31 +00: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 01:50:15 +00:00
|
|
|
|
2015-01-08 08:04:31 +00: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 01:50:15 +00:00
|
|
|
|
|
|
|
|
2015-01-08 08:04:31 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Main-thread-only mutable data.
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2012-09-26 15:33:06 +00:00
|
|
|
|
2015-01-08 08:04:31 +00:00
|
|
|
// Note that the data stored in gfx::Color is *non-alpha-premultiplied*.
|
|
|
|
Color mSinglePixelColor;
|
2014-02-25 03:37:51 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mSinglePixel;
|
|
|
|
bool mCompositingFailed;
|
2014-09-19 02:26:01 +00:00
|
|
|
bool mOptimizable;
|
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-09-11 00:06:45 +00: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
|
|
|
|
* true, then calls to Draw() and GetSurface() are guaranteed to succeed.
|
|
|
|
*/
|
2015-03-21 16:28:04 +00:00
|
|
|
class DrawableFrameRef final
|
2014-09-11 00:06:45 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
DrawableFrameRef() { }
|
|
|
|
|
|
|
|
explicit DrawableFrameRef(imgFrame* aFrame)
|
|
|
|
: mFrame(aFrame)
|
|
|
|
, mRef(aFrame->mVBuf)
|
2012-09-26 15:33:06 +00:00
|
|
|
{
|
2014-09-11 00:06:45 +00:00
|
|
|
if (mRef.WasBufferPurged()) {
|
|
|
|
mFrame = nullptr;
|
|
|
|
mRef = nullptr;
|
2012-09-26 15:33:06 +00:00
|
|
|
}
|
2014-09-11 00:06:45 +00:00
|
|
|
}
|
2012-09-26 15:33:06 +00:00
|
|
|
|
2014-09-11 00:06:45 +00:00
|
|
|
DrawableFrameRef(DrawableFrameRef&& aOther)
|
|
|
|
: mFrame(aOther.mFrame.forget())
|
|
|
|
, mRef(Move(aOther.mRef))
|
|
|
|
{ }
|
2012-09-26 15:33:06 +00:00
|
|
|
|
2014-09-11 00:06:45 +00:00
|
|
|
DrawableFrameRef& operator=(DrawableFrameRef&& aOther)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(this != &aOther, "Self-moves are prohibited");
|
|
|
|
mFrame = aOther.mFrame.forget();
|
|
|
|
mRef = Move(aOther.mRef);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-02-03 16:52:36 +00:00
|
|
|
explicit operator bool() const { return bool(mFrame); }
|
2014-09-11 00:06:45 +00: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;
|
|
|
|
mRef = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsRefPtr<imgFrame> mFrame;
|
|
|
|
VolatileBufferPtr<uint8_t> mRef;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* |ref| and |if (ref)| is true, then calls to GetImageData(), GetPaletteData(),
|
|
|
|
* and GetDrawTarget() are guaranteed to succeed. This guarantee is stronger
|
|
|
|
* than DrawableFrameRef, so everything that a valid DrawableFrameRef guarantees
|
|
|
|
* is also guaranteed by a valid RawAccessFrameRef.
|
|
|
|
*
|
|
|
|
* 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-03-21 16:28:04 +00:00
|
|
|
class RawAccessFrameRef final
|
2014-09-11 00:06:45 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
RawAccessFrameRef() { }
|
|
|
|
|
|
|
|
explicit RawAccessFrameRef(imgFrame* aFrame)
|
|
|
|
: mFrame(aFrame)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mFrame, "Need a frame");
|
|
|
|
|
|
|
|
if (NS_FAILED(mFrame->LockImageData())) {
|
|
|
|
mFrame->UnlockImageData();
|
|
|
|
mFrame = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RawAccessFrameRef(RawAccessFrameRef&& aOther)
|
|
|
|
: mFrame(aOther.mFrame.forget())
|
|
|
|
{ }
|
|
|
|
|
|
|
|
~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();
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-02-03 16:52:36 +00:00
|
|
|
explicit operator bool() const { return bool(mFrame); }
|
2014-09-11 00:06:45 +00: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsRefPtr<imgFrame> mFrame;
|
|
|
|
};
|
2014-07-10 15:00:31 +00:00
|
|
|
|
|
|
|
} // namespace image
|
|
|
|
} // namespace mozilla
|
2012-09-26 15:33:06 +00:00
|
|
|
|
2015-05-15 03:52:05 +00:00
|
|
|
#endif // mozilla_image_imgFrame_h
|