image/src/Image.cpp

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.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include "nsMimeTypes.h"
     8 #include "Image.h"
    10 namespace mozilla {
    11 namespace image {
    13 // Constructor
    14 ImageResource::ImageResource(ImageURL* aURI) :
    15   mURI(aURI),
    16   mInnerWindowId(0),
    17   mAnimationConsumers(0),
    18   mAnimationMode(kNormalAnimMode),
    19   mInitialized(false),
    20   mAnimating(false),
    21   mError(false)
    22 {
    23 }
    25 uint32_t
    26 ImageResource::SizeOfData()
    27 {
    28   if (mError)
    29     return 0;
    31   // This is not used by memory reporters, but for sizing the cache, which is
    32   // why it uses |moz_malloc_size_of| rather than a
    33   // |MOZ_DEFINE_MALLOC_SIZE_OF|.
    34   return uint32_t(HeapSizeOfSourceWithComputedFallback(moz_malloc_size_of) +
    35                   HeapSizeOfDecodedWithComputedFallback(moz_malloc_size_of) +
    36                   NonHeapSizeOfDecoded() +
    37                   OutOfProcessSizeOfDecoded());
    38 }
    40 // Translates a mimetype into a concrete decoder
    41 Image::eDecoderType
    42 Image::GetDecoderType(const char *aMimeType)
    43 {
    44   // By default we don't know
    45   eDecoderType rv = eDecoderType_unknown;
    47   // PNG
    48   if (!strcmp(aMimeType, IMAGE_PNG))
    49     rv = eDecoderType_png;
    50   else if (!strcmp(aMimeType, IMAGE_X_PNG))
    51     rv = eDecoderType_png;
    53   // GIF
    54   else if (!strcmp(aMimeType, IMAGE_GIF))
    55     rv = eDecoderType_gif;
    58   // JPEG
    59   else if (!strcmp(aMimeType, IMAGE_JPEG))
    60     rv = eDecoderType_jpeg;
    61   else if (!strcmp(aMimeType, IMAGE_PJPEG))
    62     rv = eDecoderType_jpeg;
    63   else if (!strcmp(aMimeType, IMAGE_JPG))
    64     rv = eDecoderType_jpeg;
    66   // BMP
    67   else if (!strcmp(aMimeType, IMAGE_BMP))
    68     rv = eDecoderType_bmp;
    69   else if (!strcmp(aMimeType, IMAGE_BMP_MS))
    70     rv = eDecoderType_bmp;
    73   // ICO
    74   else if (!strcmp(aMimeType, IMAGE_ICO))
    75     rv = eDecoderType_ico;
    76   else if (!strcmp(aMimeType, IMAGE_ICO_MS))
    77     rv = eDecoderType_ico;
    79   // Icon
    80   else if (!strcmp(aMimeType, IMAGE_ICON_MS))
    81     rv = eDecoderType_icon;
    83   return rv;
    84 }
    86 void
    87 ImageResource::IncrementAnimationConsumers()
    88 {
    89   MOZ_ASSERT(NS_IsMainThread(), "Main thread only to encourage serialization "
    90                                 "with DecrementAnimationConsumers");
    91   mAnimationConsumers++;
    92 }
    94 void
    95 ImageResource::DecrementAnimationConsumers()
    96 {
    97   MOZ_ASSERT(NS_IsMainThread(), "Main thread only to encourage serialization "
    98                                 "with IncrementAnimationConsumers");
    99   NS_ABORT_IF_FALSE(mAnimationConsumers >= 1, "Invalid no. of animation consumers!");
   100   mAnimationConsumers--;
   101 }
   103 nsresult
   104 ImageResource::GetAnimationModeInternal(uint16_t* aAnimationMode)
   105 {
   106   if (mError)
   107     return NS_ERROR_FAILURE;
   109   NS_ENSURE_ARG_POINTER(aAnimationMode);
   111   *aAnimationMode = mAnimationMode;
   112   return NS_OK;
   113 }
   115 nsresult
   116 ImageResource::SetAnimationModeInternal(uint16_t aAnimationMode)
   117 {
   118   if (mError)
   119     return NS_ERROR_FAILURE;
   121   NS_ASSERTION(aAnimationMode == kNormalAnimMode ||
   122                aAnimationMode == kDontAnimMode ||
   123                aAnimationMode == kLoopOnceAnimMode,
   124                "Wrong Animation Mode is being set!");
   126   mAnimationMode = aAnimationMode;
   128   return NS_OK;
   129 }
   131 void
   132 ImageResource::EvaluateAnimation()
   133 {
   134   if (!mAnimating && ShouldAnimate()) {
   135     nsresult rv = StartAnimation();
   136     mAnimating = NS_SUCCEEDED(rv);
   137   } else if (mAnimating && !ShouldAnimate()) {
   138     StopAnimation();
   139   }
   140 }
   142 } // namespace image
   143 } // namespace mozilla

mercurial