/image/src/Image.h

http://github.com/zpao/v8monkey · C Header · 169 lines · 66 code · 22 blank · 81 comment · 2 complexity · 9f9d19f880c4d63d224abb0c7a7b5dd1 MD5 · raw file

  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * The Original Code is mozilla.org code.
  16. *
  17. * The Initial Developer of the Original Code is
  18. * the Mozilla Foundation.
  19. * Portions created by the Initial Developer are Copyright (C) 2010.
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either the GNU General Public License Version 2 or later (the "GPL"), or
  26. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. #ifndef MOZILLA_IMAGELIB_IMAGE_H_
  38. #define MOZILLA_IMAGELIB_IMAGE_H_
  39. #include "imgIContainer.h"
  40. #include "imgStatusTracker.h"
  41. #include "prtypes.h"
  42. namespace mozilla {
  43. namespace image {
  44. class Image : public imgIContainer
  45. {
  46. public:
  47. // From NS_DECL_IMGICONTAINER:
  48. NS_SCRIPTABLE NS_IMETHOD GetAnimationMode(PRUint16 *aAnimationMode);
  49. NS_SCRIPTABLE NS_IMETHOD SetAnimationMode(PRUint16 aAnimationMode);
  50. imgStatusTracker& GetStatusTracker() { return *mStatusTracker; }
  51. /**
  52. * Flags for Image initialization.
  53. *
  54. * Meanings:
  55. *
  56. * INIT_FLAG_NONE: Lack of flags
  57. *
  58. * INIT_FLAG_DISCARDABLE: The container should be discardable
  59. *
  60. * INIT_FLAG_DECODE_ON_DRAW: The container should decode on draw rather than
  61. * decoding on load.
  62. *
  63. * INIT_FLAG_MULTIPART: The container will be used to display a stream of
  64. * images in a multipart channel. If this flag is set, INIT_FLAG_DISCARDABLE
  65. * and INIT_FLAG_DECODE_ON_DRAW must not be set.
  66. */
  67. static const PRUint32 INIT_FLAG_NONE = 0x0;
  68. static const PRUint32 INIT_FLAG_DISCARDABLE = 0x1;
  69. static const PRUint32 INIT_FLAG_DECODE_ON_DRAW = 0x2;
  70. static const PRUint32 INIT_FLAG_MULTIPART = 0x4;
  71. /**
  72. * Creates a new image container.
  73. *
  74. * @param aObserver Observer to send decoder and animation notifications to.
  75. * @param aMimeType The mimetype of the image.
  76. * @param aFlags Initialization flags of the INIT_FLAG_* variety.
  77. */
  78. virtual nsresult Init(imgIDecoderObserver* aObserver,
  79. const char* aMimeType,
  80. const char* aURIString,
  81. PRUint32 aFlags) = 0;
  82. /**
  83. * The rectangle defining the location and size of the currently displayed
  84. * frame.
  85. */
  86. virtual void GetCurrentFrameRect(nsIntRect& aRect) = 0;
  87. /**
  88. * The size, in bytes, occupied by the significant data portions of the image.
  89. * This includes both compressed source data and decoded frames.
  90. */
  91. PRUint32 GetDataSize();
  92. /**
  93. * The components that make up GetDataSize().
  94. */
  95. virtual PRUint32 GetDecodedHeapSize() = 0;
  96. virtual PRUint32 GetDecodedNonheapSize() = 0;
  97. virtual PRUint32 GetDecodedOutOfProcessSize() = 0;
  98. virtual PRUint32 GetSourceHeapSize() = 0;
  99. // Mimetype translation
  100. enum eDecoderType {
  101. eDecoderType_png = 0,
  102. eDecoderType_gif = 1,
  103. eDecoderType_jpeg = 2,
  104. eDecoderType_bmp = 3,
  105. eDecoderType_ico = 4,
  106. eDecoderType_icon = 5,
  107. eDecoderType_unknown = 6
  108. };
  109. static eDecoderType GetDecoderType(const char *aMimeType);
  110. void IncrementAnimationConsumers();
  111. void DecrementAnimationConsumers();
  112. #ifdef DEBUG
  113. PRUint32 GetAnimationConsumers() { return mAnimationConsumers; }
  114. #endif
  115. void SetInnerWindowID(PRUint64 aInnerWindowId) {
  116. mInnerWindowId = aInnerWindowId;
  117. }
  118. PRUint64 InnerWindowID() const { return mInnerWindowId; }
  119. bool HasError() { return mError; }
  120. protected:
  121. Image(imgStatusTracker* aStatusTracker);
  122. /**
  123. * Decides whether animation should or should not be happening,
  124. * and makes sure the right thing is being done.
  125. */
  126. virtual void EvaluateAnimation();
  127. virtual nsresult StartAnimation() = 0;
  128. virtual nsresult StopAnimation() = 0;
  129. PRUint64 mInnerWindowId;
  130. // Member data shared by all implementations of this abstract class
  131. nsAutoPtr<imgStatusTracker> mStatusTracker;
  132. PRUint32 mAnimationConsumers;
  133. PRUint16 mAnimationMode; // Enum values in imgIContainer
  134. bool mInitialized:1; // Have we been initalized?
  135. bool mAnimating:1; // Are we currently animating?
  136. bool mError:1; // Error handling
  137. /**
  138. * Extended by child classes, if they have additional
  139. * conditions for being able to animate
  140. */
  141. virtual bool ShouldAnimate() {
  142. return mAnimationConsumers > 0 && mAnimationMode != kDontAnimMode;
  143. }
  144. };
  145. } // namespace image
  146. } // namespace mozilla
  147. #endif // MOZILLA_IMAGELIB_IMAGE_H_