Wed, 31 Dec 2014 06:09:35 +0100
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 | #include "nsMimeTypes.h" |
michael@0 | 7 | |
michael@0 | 8 | #include "Image.h" |
michael@0 | 9 | |
michael@0 | 10 | namespace mozilla { |
michael@0 | 11 | namespace image { |
michael@0 | 12 | |
michael@0 | 13 | // Constructor |
michael@0 | 14 | ImageResource::ImageResource(ImageURL* aURI) : |
michael@0 | 15 | mURI(aURI), |
michael@0 | 16 | mInnerWindowId(0), |
michael@0 | 17 | mAnimationConsumers(0), |
michael@0 | 18 | mAnimationMode(kNormalAnimMode), |
michael@0 | 19 | mInitialized(false), |
michael@0 | 20 | mAnimating(false), |
michael@0 | 21 | mError(false) |
michael@0 | 22 | { |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | uint32_t |
michael@0 | 26 | ImageResource::SizeOfData() |
michael@0 | 27 | { |
michael@0 | 28 | if (mError) |
michael@0 | 29 | return 0; |
michael@0 | 30 | |
michael@0 | 31 | // This is not used by memory reporters, but for sizing the cache, which is |
michael@0 | 32 | // why it uses |moz_malloc_size_of| rather than a |
michael@0 | 33 | // |MOZ_DEFINE_MALLOC_SIZE_OF|. |
michael@0 | 34 | return uint32_t(HeapSizeOfSourceWithComputedFallback(moz_malloc_size_of) + |
michael@0 | 35 | HeapSizeOfDecodedWithComputedFallback(moz_malloc_size_of) + |
michael@0 | 36 | NonHeapSizeOfDecoded() + |
michael@0 | 37 | OutOfProcessSizeOfDecoded()); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | // Translates a mimetype into a concrete decoder |
michael@0 | 41 | Image::eDecoderType |
michael@0 | 42 | Image::GetDecoderType(const char *aMimeType) |
michael@0 | 43 | { |
michael@0 | 44 | // By default we don't know |
michael@0 | 45 | eDecoderType rv = eDecoderType_unknown; |
michael@0 | 46 | |
michael@0 | 47 | // PNG |
michael@0 | 48 | if (!strcmp(aMimeType, IMAGE_PNG)) |
michael@0 | 49 | rv = eDecoderType_png; |
michael@0 | 50 | else if (!strcmp(aMimeType, IMAGE_X_PNG)) |
michael@0 | 51 | rv = eDecoderType_png; |
michael@0 | 52 | |
michael@0 | 53 | // GIF |
michael@0 | 54 | else if (!strcmp(aMimeType, IMAGE_GIF)) |
michael@0 | 55 | rv = eDecoderType_gif; |
michael@0 | 56 | |
michael@0 | 57 | |
michael@0 | 58 | // JPEG |
michael@0 | 59 | else if (!strcmp(aMimeType, IMAGE_JPEG)) |
michael@0 | 60 | rv = eDecoderType_jpeg; |
michael@0 | 61 | else if (!strcmp(aMimeType, IMAGE_PJPEG)) |
michael@0 | 62 | rv = eDecoderType_jpeg; |
michael@0 | 63 | else if (!strcmp(aMimeType, IMAGE_JPG)) |
michael@0 | 64 | rv = eDecoderType_jpeg; |
michael@0 | 65 | |
michael@0 | 66 | // BMP |
michael@0 | 67 | else if (!strcmp(aMimeType, IMAGE_BMP)) |
michael@0 | 68 | rv = eDecoderType_bmp; |
michael@0 | 69 | else if (!strcmp(aMimeType, IMAGE_BMP_MS)) |
michael@0 | 70 | rv = eDecoderType_bmp; |
michael@0 | 71 | |
michael@0 | 72 | |
michael@0 | 73 | // ICO |
michael@0 | 74 | else if (!strcmp(aMimeType, IMAGE_ICO)) |
michael@0 | 75 | rv = eDecoderType_ico; |
michael@0 | 76 | else if (!strcmp(aMimeType, IMAGE_ICO_MS)) |
michael@0 | 77 | rv = eDecoderType_ico; |
michael@0 | 78 | |
michael@0 | 79 | // Icon |
michael@0 | 80 | else if (!strcmp(aMimeType, IMAGE_ICON_MS)) |
michael@0 | 81 | rv = eDecoderType_icon; |
michael@0 | 82 | |
michael@0 | 83 | return rv; |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | void |
michael@0 | 87 | ImageResource::IncrementAnimationConsumers() |
michael@0 | 88 | { |
michael@0 | 89 | MOZ_ASSERT(NS_IsMainThread(), "Main thread only to encourage serialization " |
michael@0 | 90 | "with DecrementAnimationConsumers"); |
michael@0 | 91 | mAnimationConsumers++; |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | void |
michael@0 | 95 | ImageResource::DecrementAnimationConsumers() |
michael@0 | 96 | { |
michael@0 | 97 | MOZ_ASSERT(NS_IsMainThread(), "Main thread only to encourage serialization " |
michael@0 | 98 | "with IncrementAnimationConsumers"); |
michael@0 | 99 | NS_ABORT_IF_FALSE(mAnimationConsumers >= 1, "Invalid no. of animation consumers!"); |
michael@0 | 100 | mAnimationConsumers--; |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | nsresult |
michael@0 | 104 | ImageResource::GetAnimationModeInternal(uint16_t* aAnimationMode) |
michael@0 | 105 | { |
michael@0 | 106 | if (mError) |
michael@0 | 107 | return NS_ERROR_FAILURE; |
michael@0 | 108 | |
michael@0 | 109 | NS_ENSURE_ARG_POINTER(aAnimationMode); |
michael@0 | 110 | |
michael@0 | 111 | *aAnimationMode = mAnimationMode; |
michael@0 | 112 | return NS_OK; |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | nsresult |
michael@0 | 116 | ImageResource::SetAnimationModeInternal(uint16_t aAnimationMode) |
michael@0 | 117 | { |
michael@0 | 118 | if (mError) |
michael@0 | 119 | return NS_ERROR_FAILURE; |
michael@0 | 120 | |
michael@0 | 121 | NS_ASSERTION(aAnimationMode == kNormalAnimMode || |
michael@0 | 122 | aAnimationMode == kDontAnimMode || |
michael@0 | 123 | aAnimationMode == kLoopOnceAnimMode, |
michael@0 | 124 | "Wrong Animation Mode is being set!"); |
michael@0 | 125 | |
michael@0 | 126 | mAnimationMode = aAnimationMode; |
michael@0 | 127 | |
michael@0 | 128 | return NS_OK; |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | void |
michael@0 | 132 | ImageResource::EvaluateAnimation() |
michael@0 | 133 | { |
michael@0 | 134 | if (!mAnimating && ShouldAnimate()) { |
michael@0 | 135 | nsresult rv = StartAnimation(); |
michael@0 | 136 | mAnimating = NS_SUCCEEDED(rv); |
michael@0 | 137 | } else if (mAnimating && !ShouldAnimate()) { |
michael@0 | 138 | StopAnimation(); |
michael@0 | 139 | } |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | } // namespace image |
michael@0 | 143 | } // namespace mozilla |