2010-08-13 21:09:48 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2010-08-13 21:09:48 -07:00
|
|
|
|
|
|
|
#ifndef MOZILLA_IMAGELIB_IMAGE_H_
|
|
|
|
#define MOZILLA_IMAGELIB_IMAGE_H_
|
|
|
|
|
2013-06-23 05:03:39 -07:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2010-08-13 21:09:48 -07:00
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "imgStatusTracker.h"
|
2013-09-28 11:28:42 -07:00
|
|
|
#include "ImageURL.h"
|
2013-09-07 06:01:08 -07:00
|
|
|
|
|
|
|
class nsIRequest;
|
|
|
|
class nsIInputStream;
|
2010-08-13 21:09:48 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
2012-01-06 08:02:27 -08:00
|
|
|
namespace image {
|
2010-08-13 21:09:48 -07:00
|
|
|
|
|
|
|
class Image : public imgIContainer
|
|
|
|
{
|
|
|
|
public:
|
2012-12-19 14:24:32 -08:00
|
|
|
// Mimetype translation
|
|
|
|
enum eDecoderType {
|
|
|
|
eDecoderType_png = 0,
|
|
|
|
eDecoderType_gif = 1,
|
|
|
|
eDecoderType_jpeg = 2,
|
|
|
|
eDecoderType_bmp = 3,
|
|
|
|
eDecoderType_ico = 4,
|
|
|
|
eDecoderType_icon = 5,
|
2013-07-22 19:31:24 -07:00
|
|
|
eDecoderType_unknown = 6
|
2012-12-19 14:24:32 -08:00
|
|
|
};
|
|
|
|
static eDecoderType GetDecoderType(const char *aMimeType);
|
2010-08-13 21:09:48 -07:00
|
|
|
|
2010-08-13 21:09:49 -07:00
|
|
|
/**
|
|
|
|
* Flags for Image initialization.
|
|
|
|
*
|
|
|
|
* Meanings:
|
|
|
|
*
|
|
|
|
* INIT_FLAG_NONE: Lack of flags
|
|
|
|
*
|
|
|
|
* INIT_FLAG_DISCARDABLE: The container should be discardable
|
|
|
|
*
|
|
|
|
* INIT_FLAG_DECODE_ON_DRAW: The container should decode on draw rather than
|
|
|
|
* decoding on load.
|
|
|
|
*
|
|
|
|
* INIT_FLAG_MULTIPART: The container will be used to display a stream of
|
|
|
|
* images in a multipart channel. If this flag is set, INIT_FLAG_DISCARDABLE
|
|
|
|
* and INIT_FLAG_DECODE_ON_DRAW must not be set.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
static const uint32_t INIT_FLAG_NONE = 0x0;
|
|
|
|
static const uint32_t INIT_FLAG_DISCARDABLE = 0x1;
|
|
|
|
static const uint32_t INIT_FLAG_DECODE_ON_DRAW = 0x2;
|
|
|
|
static const uint32_t INIT_FLAG_MULTIPART = 0x4;
|
2010-08-13 21:09:49 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new image container.
|
|
|
|
*
|
|
|
|
* @param aMimeType The mimetype of the image.
|
|
|
|
* @param aFlags Initialization flags of the INIT_FLAG_* variety.
|
|
|
|
*/
|
2013-02-12 19:00:03 -08:00
|
|
|
virtual nsresult Init(const char* aMimeType,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFlags) = 0;
|
2010-08-13 21:09:49 -07:00
|
|
|
|
2012-12-19 14:24:32 -08:00
|
|
|
virtual imgStatusTracker& GetStatusTracker() = 0;
|
|
|
|
|
2010-08-13 21:09:49 -07:00
|
|
|
/**
|
2013-02-04 16:06:14 -08:00
|
|
|
* The rectangle defining the location and size of the given frame.
|
2010-08-13 21:09:49 -07:00
|
|
|
*/
|
2013-02-04 16:06:14 -08:00
|
|
|
virtual nsIntRect FrameRect(uint32_t aWhichFrame) = 0;
|
2010-08-13 21:09:49 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The size, in bytes, occupied by the significant data portions of the image.
|
|
|
|
* This includes both compressed source data and decoded frames.
|
|
|
|
*/
|
2012-12-19 14:24:32 -08:00
|
|
|
virtual uint32_t SizeOfData() = 0;
|
2010-10-06 08:37:12 -07:00
|
|
|
|
|
|
|
/**
|
2012-02-19 19:51:48 -08:00
|
|
|
* The components that make up SizeOfData().
|
2013-03-29 13:14:19 -07:00
|
|
|
*/
|
2013-06-23 05:03:39 -07:00
|
|
|
virtual size_t HeapSizeOfSourceWithComputedFallback(mozilla::MallocSizeOf aMallocSizeOf) const = 0;
|
|
|
|
virtual size_t HeapSizeOfDecodedWithComputedFallback(mozilla::MallocSizeOf aMallocSizeOf) const = 0;
|
2012-02-19 19:51:48 -08:00
|
|
|
virtual size_t NonHeapSizeOfDecoded() const = 0;
|
|
|
|
virtual size_t OutOfProcessSizeOfDecoded() const = 0;
|
2010-08-11 17:49:50 -07:00
|
|
|
|
2012-12-19 14:24:32 -08:00
|
|
|
virtual void IncrementAnimationConsumers() = 0;
|
|
|
|
virtual void DecrementAnimationConsumers() = 0;
|
2010-09-07 17:33:02 -07:00
|
|
|
#ifdef DEBUG
|
2012-12-19 14:24:32 -08:00
|
|
|
virtual uint32_t GetAnimationConsumers() = 0;
|
2010-09-07 17:33:02 -07:00
|
|
|
#endif
|
|
|
|
|
2012-12-17 14:05:18 -08:00
|
|
|
/**
|
|
|
|
* Called from OnDataAvailable when the stream associated with the image has
|
|
|
|
* received new image data. The arguments are the same as OnDataAvailable's,
|
|
|
|
* but by separating this functionality into a different method we don't
|
|
|
|
* interfere with subclasses which wish to implement nsIStreamListener.
|
|
|
|
*
|
|
|
|
* Images should not do anything that could send out notifications until they
|
|
|
|
* have received their first OnImageDataAvailable notification; in
|
|
|
|
* particular, this means that instantiating decoders should be deferred
|
|
|
|
* until OnImageDataAvailable is called.
|
|
|
|
*/
|
|
|
|
virtual nsresult OnImageDataAvailable(nsIRequest* aRequest,
|
|
|
|
nsISupports* aContext,
|
|
|
|
nsIInputStream* aInStr,
|
|
|
|
uint64_t aSourceOffset,
|
|
|
|
uint32_t aCount) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called from OnStopRequest when the image's underlying request completes.
|
2013-02-13 18:41:10 -08:00
|
|
|
*
|
|
|
|
* @param aRequest The completed request.
|
|
|
|
* @param aContext Context from Necko's OnStopRequest.
|
|
|
|
* @param aStatus A success or failure code.
|
|
|
|
* @param aLastPart Whether this is the final part of the underlying request.
|
2012-12-17 14:05:18 -08:00
|
|
|
*/
|
|
|
|
virtual nsresult OnImageDataComplete(nsIRequest* aRequest,
|
|
|
|
nsISupports* aContext,
|
2013-02-13 18:41:10 -08:00
|
|
|
nsresult aStatus,
|
|
|
|
bool aLastPart) = 0;
|
2012-12-17 14:05:18 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called for multipart images to allow for any necessary reinitialization
|
|
|
|
* when there's a new part to add.
|
|
|
|
*/
|
|
|
|
virtual nsresult OnNewSourceData() = 0;
|
|
|
|
|
2012-12-19 14:24:32 -08:00
|
|
|
virtual void SetInnerWindowID(uint64_t aInnerWindowId) = 0;
|
|
|
|
virtual uint64_t InnerWindowID() const = 0;
|
|
|
|
|
|
|
|
virtual bool HasError() = 0;
|
|
|
|
virtual void SetHasError() = 0;
|
|
|
|
|
2013-09-28 11:28:42 -07:00
|
|
|
virtual ImageURL* GetURI() = 0;
|
2012-12-19 14:24:32 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
class ImageResource : public Image
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual imgStatusTracker& GetStatusTracker() MOZ_OVERRIDE { return *mStatusTracker; }
|
|
|
|
virtual uint32_t SizeOfData() MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
virtual void IncrementAnimationConsumers() MOZ_OVERRIDE;
|
|
|
|
virtual void DecrementAnimationConsumers() MOZ_OVERRIDE;
|
|
|
|
#ifdef DEBUG
|
|
|
|
virtual uint32_t GetAnimationConsumers() MOZ_OVERRIDE { return mAnimationConsumers; }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
virtual void SetInnerWindowID(uint64_t aInnerWindowId) MOZ_OVERRIDE {
|
2011-08-24 13:44:35 -07:00
|
|
|
mInnerWindowId = aInnerWindowId;
|
2010-12-20 08:21:59 -08:00
|
|
|
}
|
2012-12-19 14:24:32 -08:00
|
|
|
virtual uint64_t InnerWindowID() const MOZ_OVERRIDE { return mInnerWindowId; }
|
2010-12-20 08:21:59 -08:00
|
|
|
|
2012-12-19 14:24:32 -08:00
|
|
|
virtual bool HasError() MOZ_OVERRIDE { return mError; }
|
|
|
|
virtual void SetHasError() MOZ_OVERRIDE { mError = true; }
|
2012-12-14 15:42:18 -08:00
|
|
|
|
2012-12-19 13:28:54 -08:00
|
|
|
/*
|
|
|
|
* Returns a non-AddRefed pointer to the URI associated with this image.
|
2013-09-11 17:01:59 -07:00
|
|
|
* Illegal to use off-main-thread.
|
2012-12-19 13:28:54 -08:00
|
|
|
*/
|
2013-09-28 11:28:42 -07:00
|
|
|
virtual ImageURL* GetURI() MOZ_OVERRIDE { return mURI.get(); }
|
2012-12-19 13:28:54 -08:00
|
|
|
|
2010-08-13 21:09:48 -07:00
|
|
|
protected:
|
2013-09-28 11:28:42 -07:00
|
|
|
ImageResource(imgStatusTracker* aStatusTracker,
|
|
|
|
ImageURL* aURI);
|
2010-08-13 21:09:48 -07:00
|
|
|
|
2012-10-19 13:27:11 -07:00
|
|
|
// Shared functionality for implementors of imgIContainer. Every
|
|
|
|
// implementation of attribute animationMode should forward here.
|
|
|
|
nsresult GetAnimationModeInternal(uint16_t *aAnimationMode);
|
|
|
|
nsresult SetAnimationModeInternal(uint16_t aAnimationMode);
|
|
|
|
|
2010-09-07 17:33:02 -07:00
|
|
|
/**
|
|
|
|
* Decides whether animation should or should not be happening,
|
|
|
|
* and makes sure the right thing is being done.
|
|
|
|
*/
|
|
|
|
virtual void EvaluateAnimation();
|
|
|
|
|
2012-12-19 14:24:32 -08:00
|
|
|
/**
|
|
|
|
* Extended by child classes, if they have additional
|
|
|
|
* conditions for being able to animate.
|
|
|
|
*/
|
|
|
|
virtual bool ShouldAnimate() {
|
|
|
|
return mAnimationConsumers > 0 && mAnimationMode != kDontAnimMode;
|
|
|
|
}
|
|
|
|
|
2010-09-07 17:33:02 -07:00
|
|
|
virtual nsresult StartAnimation() = 0;
|
|
|
|
virtual nsresult StopAnimation() = 0;
|
|
|
|
|
2010-08-13 21:09:48 -07:00
|
|
|
// Member data shared by all implementations of this abstract class
|
2013-09-11 17:01:59 -07:00
|
|
|
nsRefPtr<imgStatusTracker> mStatusTracker;
|
2013-09-28 11:28:42 -07:00
|
|
|
nsRefPtr<ImageURL> mURI;
|
2013-09-11 17:01:59 -07:00
|
|
|
uint64_t mInnerWindowId;
|
|
|
|
uint32_t mAnimationConsumers;
|
|
|
|
uint16_t mAnimationMode; // Enum values in imgIContainer
|
|
|
|
bool mInitialized:1; // Have we been initalized?
|
|
|
|
bool mAnimating:1; // Are we currently animating?
|
|
|
|
bool mError:1; // Error handling
|
2010-08-13 21:09:48 -07:00
|
|
|
};
|
|
|
|
|
2012-01-06 08:02:27 -08:00
|
|
|
} // namespace image
|
2010-08-13 21:09:48 -07:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // MOZILLA_IMAGELIB_IMAGE_H_
|