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"
|
2014-02-25 07:37:51 +04:00
|
|
|
#include "mozilla/VolatileBuffer.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 BlendMethod : int8_t {
|
2015-01-08 00:07:23 +03: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-26 01:22:07 +03:00
|
|
|
};
|
2015-01-08 00:07:23 +03:00
|
|
|
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class DisposalMethod : int8_t {
|
2015-01-08 00:07:23 +03: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-26 01:22:07 +03:00
|
|
|
};
|
2015-01-08 00:07:23 +03: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
|
|
|
|
2016-07-20 02:22:34 +03:00
|
|
|
/**
|
|
|
|
* FrameTimeout wraps a frame timeout value (measured in milliseconds) after
|
|
|
|
* first normalizing it. This normalization is necessary because some tools
|
|
|
|
* generate incorrect frame timeout values which we nevertheless have to
|
|
|
|
* support. For this reason, code that deals with frame timeouts should always
|
|
|
|
* use a FrameTimeout value rather than the raw value from the image header.
|
|
|
|
*/
|
|
|
|
struct FrameTimeout
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return a FrameTimeout of zero. This should be used only for math
|
|
|
|
* involving FrameTimeout values. You can't obtain a zero FrameTimeout from
|
|
|
|
* FromRawMilliseconds().
|
|
|
|
*/
|
|
|
|
static FrameTimeout Zero() { return FrameTimeout(0); }
|
|
|
|
|
|
|
|
/// @return an infinite FrameTimeout.
|
|
|
|
static FrameTimeout Forever() { return FrameTimeout(-1); }
|
|
|
|
|
|
|
|
/// @return a FrameTimeout obtained by normalizing a raw timeout value.
|
|
|
|
static FrameTimeout FromRawMilliseconds(int32_t aRawMilliseconds)
|
|
|
|
{
|
|
|
|
// Normalize all infinite timeouts to the same value.
|
|
|
|
if (aRawMilliseconds < 0) {
|
|
|
|
return FrameTimeout::Forever();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Very small timeout values are problematic for two reasons: we don't want
|
|
|
|
// to burn energy redrawing animated images extremely fast, and broken tools
|
|
|
|
// generate these values when they actually want a "default" value, so such
|
|
|
|
// images won't play back right without normalization. For some context,
|
|
|
|
// see bug 890743, bug 125137, bug 139677, and bug 207059. The historical
|
|
|
|
// behavior of IE and Opera was:
|
|
|
|
// IE 6/Win:
|
|
|
|
// 10 - 50ms is normalized to 100ms.
|
|
|
|
// >50ms is used unnormalized.
|
|
|
|
// Opera 7 final/Win:
|
|
|
|
// 10ms is normalized to 100ms.
|
|
|
|
// >10ms is used unnormalized.
|
|
|
|
if (aRawMilliseconds >= 0 && aRawMilliseconds <= 10 ) {
|
|
|
|
return FrameTimeout(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The provided timeout value is OK as-is.
|
|
|
|
return FrameTimeout(aRawMilliseconds);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const FrameTimeout& aOther) const
|
|
|
|
{
|
|
|
|
return mTimeout == aOther.mTimeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const FrameTimeout& aOther) const { return !(*this == aOther); }
|
|
|
|
|
|
|
|
FrameTimeout operator+(const FrameTimeout& aOther)
|
|
|
|
{
|
|
|
|
if (*this == Forever() || aOther == Forever()) {
|
|
|
|
return Forever();
|
|
|
|
}
|
|
|
|
|
|
|
|
return FrameTimeout(mTimeout + aOther.mTimeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
FrameTimeout& operator+=(const FrameTimeout& aOther)
|
|
|
|
{
|
|
|
|
*this = *this + aOther;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return this FrameTimeout's value in milliseconds. Illegal to call on a
|
|
|
|
* an infinite FrameTimeout value.
|
|
|
|
*/
|
|
|
|
uint32_t AsMilliseconds() const
|
|
|
|
{
|
|
|
|
if (*this == Forever()) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Calling AsMilliseconds() on an infinite FrameTimeout");
|
|
|
|
return 100; // Fail to something sane.
|
|
|
|
}
|
|
|
|
|
|
|
|
return uint32_t(mTimeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return this FrameTimeout value encoded so that non-negative values
|
|
|
|
* represent a timeout in milliseconds, and -1 represents an infinite
|
|
|
|
* timeout.
|
|
|
|
*
|
|
|
|
* XXX(seth): This is a backwards compatibility hack that should be removed.
|
|
|
|
*/
|
|
|
|
int32_t AsEncodedValueDeprecated() const { return mTimeout; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
explicit FrameTimeout(int32_t aTimeout)
|
|
|
|
: mTimeout(aTimeout)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
int32_t mTimeout;
|
|
|
|
};
|
|
|
|
|
2015-01-08 11:04:31 +03: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,
|
2016-07-20 02:22:34 +03:00
|
|
|
FrameTimeout aTimeout, const nsIntRect& aRect,
|
2016-06-25 01:20:32 +03:00
|
|
|
BlendMethod aBlendMethod, const Maybe<gfx::IntRect>& aBlendRect,
|
|
|
|
DisposalMethod aDisposalMethod, bool aHasAlpha)
|
2015-01-08 11:04:31 +03:00
|
|
|
: mRawData(aRawData)
|
|
|
|
, mPaletteDataLength(aPaletteDataLength)
|
2016-07-20 02:22:34 +03:00
|
|
|
, mTimeout(aTimeout)
|
2015-01-08 11:04:31 +03:00
|
|
|
, mRect(aRect)
|
|
|
|
, mBlendMethod(aBlendMethod)
|
2016-06-25 01:20:32 +03:00
|
|
|
, mBlendRect(aBlendRect)
|
2015-01-08 11:04:31 +03:00
|
|
|
, mDisposalMethod(aDisposalMethod)
|
|
|
|
, mHasAlpha(aHasAlpha)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
uint8_t* mRawData;
|
|
|
|
uint32_t mPaletteDataLength;
|
2016-07-20 02:22:34 +03:00
|
|
|
FrameTimeout mTimeout;
|
2015-01-08 11:04:31 +03:00
|
|
|
nsIntRect mRect;
|
|
|
|
BlendMethod mBlendMethod;
|
2016-06-25 01:20:32 +03:00
|
|
|
Maybe<gfx::IntRect> mBlendRect;
|
2015-01-08 11:04:31 +03:00
|
|
|
DisposalMethod mDisposalMethod;
|
|
|
|
bool mHasAlpha;
|
|
|
|
};
|
|
|
|
|
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,
|
|
|
|
bool aNonPremult = false);
|
2014-09-15 02:22:45 +04:00
|
|
|
|
|
|
|
nsresult InitForDecoder(const nsIntSize& aSize,
|
|
|
|
SurfaceFormat aFormat,
|
|
|
|
uint8_t aPaletteDepth = 0)
|
|
|
|
{
|
2014-11-27 00:22:10 +03:00
|
|
|
return InitForDecoder(aSize, nsIntRect(0, 0, aSize.width, aSize.height),
|
2014-09-15 02:22:45 +04: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-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.
|
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,
|
2014-09-15 02:22:45 +04:00
|
|
|
uint32_t aImageFlags);
|
|
|
|
|
2014-09-11 04:06:45 +04:00
|
|
|
DrawableFrameRef DrawableRef();
|
|
|
|
RawAccessFrameRef RawAccessRef();
|
|
|
|
|
2015-01-07 12:40:23 +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,
|
2016-05-25 19:01:18 +03:00
|
|
|
SamplingFilter aSamplingFilter, 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 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.
|
|
|
|
* @param aDisposalMethod For animation frames, how this imgFrame is cleared
|
|
|
|
* from the compositing frame before the next frame is
|
|
|
|
* displayed.
|
2016-07-20 02:22:34 +03:00
|
|
|
* @param aTimeout For animation frames, the timeout before the next
|
|
|
|
* frame is displayed.
|
2015-01-08 11:04:31 +03:00
|
|
|
* @param aBlendMethod For animation frames, a blending method to be used
|
|
|
|
* when compositing this frame.
|
2016-06-25 01:20:32 +03:00
|
|
|
* @param aBlendRect For animation frames, if present, the subrect in
|
|
|
|
* which @aBlendMethod applies. Outside of this
|
|
|
|
* subrect, BlendMethod::OVER is always used.
|
2015-01-08 11:04:31 +03:00
|
|
|
*/
|
2015-01-12 06:28:02 +03:00
|
|
|
void Finish(Opacity aFrameOpacity = Opacity::SOME_TRANSPARENCY,
|
|
|
|
DisposalMethod aDisposalMethod = DisposalMethod::KEEP,
|
2016-07-20 02:22:34 +03:00
|
|
|
FrameTimeout aTimeout = FrameTimeout::FromRawMilliseconds(0),
|
2016-06-25 01:20:32 +03:00
|
|
|
BlendMethod aBlendMethod = BlendMethod::OVER,
|
|
|
|
const Maybe<IntRect>& aBlendRect = Nothing());
|
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; }
|
|
|
|
|
2015-04-28 21:46:17 +03:00
|
|
|
IntSize GetImageSize() const { return mImageSize; }
|
2016-05-27 08:19:38 +03:00
|
|
|
IntRect GetRect() const { return mFrameRect; }
|
|
|
|
IntSize GetSize() const { return mFrameRect.Size(); }
|
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
|
|
|
|
2015-01-08 11:04:31 +03:00
|
|
|
AnimationData GetAnimationData() const;
|
2015-01-08 00:07:23 +03: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
|
|
|
|
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,
|
|
|
|
size_t& aNonHeapSizeOut) 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();
|
|
|
|
|
2014-11-27 00:22:10 +03:00
|
|
|
nsresult LockImageData();
|
|
|
|
nsresult UnlockImageData();
|
2016-07-01 04:59:29 +03:00
|
|
|
bool CanOptimizeOpaqueImage();
|
2014-09-19 06:26:01 +04:00
|
|
|
nsresult Optimize();
|
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;
|
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;
|
2015-03-31 20:48:00 +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
|
|
|
|
2015-10-18 08:24:48 +03: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 05:50:15 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<VolatileBuffer> mVBuf;
|
2015-01-08 11:04:31 +03:00
|
|
|
VolatileBufferPtr<uint8_t> mVBufPtr;
|
|
|
|
|
|
|
|
nsIntRect mDecoded;
|
|
|
|
|
|
|
|
//! Number of RawAccessFrameRefs currently alive for this imgFrame.
|
|
|
|
int32_t mLockCount;
|
|
|
|
|
2016-07-20 02:22:34 +03:00
|
|
|
//! The timeout for this frame.
|
|
|
|
FrameTimeout mTimeout;
|
2015-01-08 11:04:31 +03:00
|
|
|
|
|
|
|
DisposalMethod mDisposalMethod;
|
|
|
|
BlendMethod mBlendMethod;
|
2016-06-25 01:20:32 +03:00
|
|
|
Maybe<IntRect> mBlendRect;
|
2015-01-08 11:04:31 +03:00
|
|
|
SurfaceFormat mFormat;
|
|
|
|
|
|
|
|
bool mHasNoAlpha;
|
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;
|
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
|
|
|
{
|
|
|
|
public:
|
|
|
|
DrawableFrameRef() { }
|
|
|
|
|
|
|
|
explicit DrawableFrameRef(imgFrame* aFrame)
|
|
|
|
: mFrame(aFrame)
|
|
|
|
, mRef(aFrame->mVBuf)
|
2012-09-26 19:33:06 +04:00
|
|
|
{
|
2014-09-11 04:06:45 +04:00
|
|
|
if (mRef.WasBufferPurged()) {
|
|
|
|
mFrame = nullptr;
|
|
|
|
mRef = nullptr;
|
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(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();
|
|
|
|
mRef = Move(aOther.mRef);
|
|
|
|
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;
|
|
|
|
mRef = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-07-01 04:57:03 +03:00
|
|
|
DrawableFrameRef(const DrawableFrameRef& aOther) = delete;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgFrame> mFrame;
|
2014-09-11 04:06:45 +04:00
|
|
|
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
|
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:
|
|
|
|
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 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-07-01 04:57:03 +03:00
|
|
|
RawAccessFrameRef(const RawAccessFrameRef& aOther) = delete;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgFrame> mFrame;
|
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
|