image/src/Image.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef MOZILLA_IMAGELIB_IMAGE_H_
michael@0 7 #define MOZILLA_IMAGELIB_IMAGE_H_
michael@0 8
michael@0 9 #include "mozilla/MemoryReporting.h"
michael@0 10 #include "imgIContainer.h"
michael@0 11 #include "imgStatusTracker.h"
michael@0 12 #include "ImageURL.h"
michael@0 13
michael@0 14 class nsIRequest;
michael@0 15 class nsIInputStream;
michael@0 16
michael@0 17 namespace mozilla {
michael@0 18 namespace image {
michael@0 19
michael@0 20 class Image : public imgIContainer
michael@0 21 {
michael@0 22 public:
michael@0 23 // Mimetype translation
michael@0 24 enum eDecoderType {
michael@0 25 eDecoderType_png = 0,
michael@0 26 eDecoderType_gif = 1,
michael@0 27 eDecoderType_jpeg = 2,
michael@0 28 eDecoderType_bmp = 3,
michael@0 29 eDecoderType_ico = 4,
michael@0 30 eDecoderType_icon = 5,
michael@0 31 eDecoderType_unknown = 6
michael@0 32 };
michael@0 33 static eDecoderType GetDecoderType(const char *aMimeType);
michael@0 34
michael@0 35 /**
michael@0 36 * Flags for Image initialization.
michael@0 37 *
michael@0 38 * Meanings:
michael@0 39 *
michael@0 40 * INIT_FLAG_NONE: Lack of flags
michael@0 41 *
michael@0 42 * INIT_FLAG_DISCARDABLE: The container should be discardable
michael@0 43 *
michael@0 44 * INIT_FLAG_DECODE_ON_DRAW: The container should decode on draw rather than
michael@0 45 * decoding on load.
michael@0 46 *
michael@0 47 * INIT_FLAG_MULTIPART: The container will be used to display a stream of
michael@0 48 * images in a multipart channel. If this flag is set, INIT_FLAG_DISCARDABLE
michael@0 49 * and INIT_FLAG_DECODE_ON_DRAW must not be set.
michael@0 50 */
michael@0 51 static const uint32_t INIT_FLAG_NONE = 0x0;
michael@0 52 static const uint32_t INIT_FLAG_DISCARDABLE = 0x1;
michael@0 53 static const uint32_t INIT_FLAG_DECODE_ON_DRAW = 0x2;
michael@0 54 static const uint32_t INIT_FLAG_MULTIPART = 0x4;
michael@0 55
michael@0 56 /**
michael@0 57 * Creates a new image container.
michael@0 58 *
michael@0 59 * @param aMimeType The mimetype of the image.
michael@0 60 * @param aFlags Initialization flags of the INIT_FLAG_* variety.
michael@0 61 */
michael@0 62 virtual nsresult Init(const char* aMimeType,
michael@0 63 uint32_t aFlags) = 0;
michael@0 64
michael@0 65 virtual already_AddRefed<imgStatusTracker> GetStatusTracker() = 0;
michael@0 66 virtual void SetStatusTracker(imgStatusTracker* aStatusTracker) {}
michael@0 67
michael@0 68 /**
michael@0 69 * The rectangle defining the location and size of the given frame.
michael@0 70 */
michael@0 71 virtual nsIntRect FrameRect(uint32_t aWhichFrame) = 0;
michael@0 72
michael@0 73 /**
michael@0 74 * The size, in bytes, occupied by the significant data portions of the image.
michael@0 75 * This includes both compressed source data and decoded frames.
michael@0 76 */
michael@0 77 virtual uint32_t SizeOfData() = 0;
michael@0 78
michael@0 79 /**
michael@0 80 * The components that make up SizeOfData().
michael@0 81 */
michael@0 82 virtual size_t HeapSizeOfSourceWithComputedFallback(mozilla::MallocSizeOf aMallocSizeOf) const = 0;
michael@0 83 virtual size_t HeapSizeOfDecodedWithComputedFallback(mozilla::MallocSizeOf aMallocSizeOf) const = 0;
michael@0 84 virtual size_t NonHeapSizeOfDecoded() const = 0;
michael@0 85 virtual size_t OutOfProcessSizeOfDecoded() const = 0;
michael@0 86
michael@0 87 virtual void IncrementAnimationConsumers() = 0;
michael@0 88 virtual void DecrementAnimationConsumers() = 0;
michael@0 89 #ifdef DEBUG
michael@0 90 virtual uint32_t GetAnimationConsumers() = 0;
michael@0 91 #endif
michael@0 92
michael@0 93 /**
michael@0 94 * Called from OnDataAvailable when the stream associated with the image has
michael@0 95 * received new image data. The arguments are the same as OnDataAvailable's,
michael@0 96 * but by separating this functionality into a different method we don't
michael@0 97 * interfere with subclasses which wish to implement nsIStreamListener.
michael@0 98 *
michael@0 99 * Images should not do anything that could send out notifications until they
michael@0 100 * have received their first OnImageDataAvailable notification; in
michael@0 101 * particular, this means that instantiating decoders should be deferred
michael@0 102 * until OnImageDataAvailable is called.
michael@0 103 */
michael@0 104 virtual nsresult OnImageDataAvailable(nsIRequest* aRequest,
michael@0 105 nsISupports* aContext,
michael@0 106 nsIInputStream* aInStr,
michael@0 107 uint64_t aSourceOffset,
michael@0 108 uint32_t aCount) = 0;
michael@0 109
michael@0 110 /**
michael@0 111 * Called from OnStopRequest when the image's underlying request completes.
michael@0 112 *
michael@0 113 * @param aRequest The completed request.
michael@0 114 * @param aContext Context from Necko's OnStopRequest.
michael@0 115 * @param aStatus A success or failure code.
michael@0 116 * @param aLastPart Whether this is the final part of the underlying request.
michael@0 117 */
michael@0 118 virtual nsresult OnImageDataComplete(nsIRequest* aRequest,
michael@0 119 nsISupports* aContext,
michael@0 120 nsresult aStatus,
michael@0 121 bool aLastPart) = 0;
michael@0 122
michael@0 123 /**
michael@0 124 * Called for multipart images to allow for any necessary reinitialization
michael@0 125 * when there's a new part to add.
michael@0 126 */
michael@0 127 virtual nsresult OnNewSourceData() = 0;
michael@0 128
michael@0 129 virtual void SetInnerWindowID(uint64_t aInnerWindowId) = 0;
michael@0 130 virtual uint64_t InnerWindowID() const = 0;
michael@0 131
michael@0 132 virtual bool HasError() = 0;
michael@0 133 virtual void SetHasError() = 0;
michael@0 134
michael@0 135 virtual ImageURL* GetURI() = 0;
michael@0 136 };
michael@0 137
michael@0 138 class ImageResource : public Image
michael@0 139 {
michael@0 140 public:
michael@0 141 already_AddRefed<imgStatusTracker> GetStatusTracker() MOZ_OVERRIDE {
michael@0 142 nsRefPtr<imgStatusTracker> statusTracker = mStatusTracker;
michael@0 143 MOZ_ASSERT(statusTracker);
michael@0 144 return statusTracker.forget();
michael@0 145 }
michael@0 146 void SetStatusTracker(imgStatusTracker* aStatusTracker) MOZ_OVERRIDE MOZ_FINAL {
michael@0 147 MOZ_ASSERT(aStatusTracker);
michael@0 148 MOZ_ASSERT(!mStatusTracker);
michael@0 149 mStatusTracker = aStatusTracker;
michael@0 150 }
michael@0 151 virtual uint32_t SizeOfData() MOZ_OVERRIDE;
michael@0 152
michael@0 153 virtual void IncrementAnimationConsumers() MOZ_OVERRIDE;
michael@0 154 virtual void DecrementAnimationConsumers() MOZ_OVERRIDE;
michael@0 155 #ifdef DEBUG
michael@0 156 virtual uint32_t GetAnimationConsumers() MOZ_OVERRIDE { return mAnimationConsumers; }
michael@0 157 #endif
michael@0 158
michael@0 159 virtual void SetInnerWindowID(uint64_t aInnerWindowId) MOZ_OVERRIDE {
michael@0 160 mInnerWindowId = aInnerWindowId;
michael@0 161 }
michael@0 162 virtual uint64_t InnerWindowID() const MOZ_OVERRIDE { return mInnerWindowId; }
michael@0 163
michael@0 164 virtual bool HasError() MOZ_OVERRIDE { return mError; }
michael@0 165 virtual void SetHasError() MOZ_OVERRIDE { mError = true; }
michael@0 166
michael@0 167 /*
michael@0 168 * Returns a non-AddRefed pointer to the URI associated with this image.
michael@0 169 * Illegal to use off-main-thread.
michael@0 170 */
michael@0 171 virtual ImageURL* GetURI() MOZ_OVERRIDE { return mURI.get(); }
michael@0 172
michael@0 173 protected:
michael@0 174 ImageResource(ImageURL* aURI);
michael@0 175
michael@0 176 // Shared functionality for implementors of imgIContainer. Every
michael@0 177 // implementation of attribute animationMode should forward here.
michael@0 178 nsresult GetAnimationModeInternal(uint16_t *aAnimationMode);
michael@0 179 nsresult SetAnimationModeInternal(uint16_t aAnimationMode);
michael@0 180
michael@0 181 /**
michael@0 182 * Decides whether animation should or should not be happening,
michael@0 183 * and makes sure the right thing is being done.
michael@0 184 */
michael@0 185 virtual void EvaluateAnimation();
michael@0 186
michael@0 187 /**
michael@0 188 * Extended by child classes, if they have additional
michael@0 189 * conditions for being able to animate.
michael@0 190 */
michael@0 191 virtual bool ShouldAnimate() {
michael@0 192 return mAnimationConsumers > 0 && mAnimationMode != kDontAnimMode;
michael@0 193 }
michael@0 194
michael@0 195 virtual nsresult StartAnimation() = 0;
michael@0 196 virtual nsresult StopAnimation() = 0;
michael@0 197
michael@0 198 // Member data shared by all implementations of this abstract class
michael@0 199 nsRefPtr<imgStatusTracker> mStatusTracker;
michael@0 200 nsRefPtr<ImageURL> mURI;
michael@0 201 uint64_t mInnerWindowId;
michael@0 202 uint32_t mAnimationConsumers;
michael@0 203 uint16_t mAnimationMode; // Enum values in imgIContainer
michael@0 204 bool mInitialized:1; // Have we been initalized?
michael@0 205 bool mAnimating:1; // Are we currently animating?
michael@0 206 bool mError:1; // Error handling
michael@0 207 };
michael@0 208
michael@0 209 } // namespace image
michael@0 210 } // namespace mozilla
michael@0 211
michael@0 212 #endif // MOZILLA_IMAGELIB_IMAGE_H_

mercurial