summaryrefslogtreecommitdiff
path: root/image/src/Image.cpp
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2014-05-21 11:38:25 +0200
committerwolfbeast <mcwerewolf@gmail.com>2014-05-21 11:38:25 +0200
commitd25ba7d760b017b038e5aa6c0a605b4a330eb68d (patch)
tree16ec27edc7d5f83986f16236d3a36a2682a0f37e /image/src/Image.cpp
parenta942906574671868daf122284a9c4689e6924f74 (diff)
downloadpalemoon-gre-d25ba7d760b017b038e5aa6c0a605b4a330eb68d.tar.gz
Recommit working copy to repo with proper line endings.
Diffstat (limited to 'image/src/Image.cpp')
-rw-r--r--image/src/Image.cpp152
1 files changed, 152 insertions, 0 deletions
diff --git a/image/src/Image.cpp b/image/src/Image.cpp
new file mode 100644
index 000000000..dbfd85d75
--- /dev/null
+++ b/image/src/Image.cpp
@@ -0,0 +1,152 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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/. */
+
+#include "nsMimeTypes.h"
+
+#include "Image.h"
+
+namespace mozilla {
+namespace image {
+
+// Constructor
+ImageResource::ImageResource(imgStatusTracker* aStatusTracker, nsIURI* aURI) :
+ mURI(aURI),
+ mInnerWindowId(0),
+ mAnimationConsumers(0),
+ mAnimationMode(kNormalAnimMode),
+ mInitialized(false),
+ mAnimating(false),
+ mError(false)
+{
+ if (aStatusTracker) {
+ mStatusTracker = aStatusTracker;
+ mStatusTracker->SetImage(this);
+ } else {
+ mStatusTracker = new imgStatusTracker(this);
+ }
+}
+
+uint32_t
+ImageResource::SizeOfData()
+{
+ if (mError)
+ return 0;
+
+ // This is not used by memory reporters, but for sizing the cache, which is
+ // why it uses |moz_malloc_size_of| rather than an
+ // |NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN|.
+ return uint32_t(HeapSizeOfSourceWithComputedFallback(moz_malloc_size_of) +
+ HeapSizeOfDecodedWithComputedFallback(moz_malloc_size_of) +
+ NonHeapSizeOfDecoded() +
+ OutOfProcessSizeOfDecoded());
+}
+
+// Translates a mimetype into a concrete decoder
+Image::eDecoderType
+Image::GetDecoderType(const char *aMimeType)
+{
+ // By default we don't know
+ eDecoderType rv = eDecoderType_unknown;
+
+ // PNG
+ if (!strcmp(aMimeType, IMAGE_PNG))
+ rv = eDecoderType_png;
+ else if (!strcmp(aMimeType, IMAGE_X_PNG))
+ rv = eDecoderType_png;
+
+ // GIF
+ else if (!strcmp(aMimeType, IMAGE_GIF))
+ rv = eDecoderType_gif;
+
+
+ // JPEG
+ else if (!strcmp(aMimeType, IMAGE_JPEG))
+ rv = eDecoderType_jpeg;
+ else if (!strcmp(aMimeType, IMAGE_PJPEG))
+ rv = eDecoderType_jpeg;
+ else if (!strcmp(aMimeType, IMAGE_JPG))
+ rv = eDecoderType_jpeg;
+
+ // BMP
+ else if (!strcmp(aMimeType, IMAGE_BMP))
+ rv = eDecoderType_bmp;
+ else if (!strcmp(aMimeType, IMAGE_BMP_MS))
+ rv = eDecoderType_bmp;
+
+
+ // ICO
+ else if (!strcmp(aMimeType, IMAGE_ICO))
+ rv = eDecoderType_ico;
+ else if (!strcmp(aMimeType, IMAGE_ICO_MS))
+ rv = eDecoderType_ico;
+
+ // Icon
+ else if (!strcmp(aMimeType, IMAGE_ICON_MS))
+ rv = eDecoderType_icon;
+
+#ifdef MOZ_WBMP
+ // WBMP
+ else if (!strcmp(aMimeType, IMAGE_WBMP))
+ rv = eDecoderType_wbmp;
+#endif
+
+ return rv;
+}
+
+void
+ImageResource::IncrementAnimationConsumers()
+{
+ mAnimationConsumers++;
+}
+
+void
+ImageResource::DecrementAnimationConsumers()
+{
+ NS_ABORT_IF_FALSE(mAnimationConsumers >= 1, "Invalid no. of animation consumers!");
+ mAnimationConsumers--;
+}
+
+nsresult
+ImageResource::GetAnimationModeInternal(uint16_t* aAnimationMode)
+{
+ if (mError)
+ return NS_ERROR_FAILURE;
+
+ NS_ENSURE_ARG_POINTER(aAnimationMode);
+
+ *aAnimationMode = mAnimationMode;
+ return NS_OK;
+}
+
+nsresult
+ImageResource::SetAnimationModeInternal(uint16_t aAnimationMode)
+{
+ if (mError)
+ return NS_ERROR_FAILURE;
+
+ NS_ASSERTION(aAnimationMode == kNormalAnimMode ||
+ aAnimationMode == kDontAnimMode ||
+ aAnimationMode == kLoopOnceAnimMode,
+ "Wrong Animation Mode is being set!");
+
+ mAnimationMode = aAnimationMode;
+
+ return NS_OK;
+}
+
+void
+ImageResource::EvaluateAnimation()
+{
+ if (!mAnimating && ShouldAnimate()) {
+ nsresult rv = StartAnimation();
+ mAnimating = NS_SUCCEEDED(rv);
+ } else if (mAnimating && !ShouldAnimate()) {
+ StopAnimation();
+ mAnimating = false;
+ }
+}
+
+} // namespace image
+} // namespace mozilla