Bug 1187118 - [WIP] move FrameTimeout into a seperate header;
MozReview-Commit-ID: 6JvSd2ArYPk
new file mode 100644
--- /dev/null
+++ b/image/FrameTimeout.cpp
@@ -0,0 +1,110 @@
+/* -*- 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 "FrameTimeout.h"
+//#include "mozilla/MemoryReporting.h"
+//#include "mozilla/Monitor.h"
+//#include "mozilla/Move.h"
+//#include "gfxDrawable.h"
+//#include "imgIContainer.h"
+//#include "MainThreadUtils.h"
+//#include "nsAutoPtr.h"
+
+namespace mozilla {
+namespace image {
+
+/* static */ FrameTimeout
+FrameTimeout::Zero()
+{
+ return FrameTimeout(0);
+}
+
+/* static */ FrameTimeout
+FrameTimeout::Forever()
+{
+ return FrameTimeout(-1);
+}
+
+
+/* static */ FrameTimeout
+FrameTimeout::FromRawMilliseconds(int32_t aRawMilliseconds)
+{
+ // Normalize all infinite timeouts to the same value.
+ if (aRawMilliseconds < 0) {
+ return FrameTimeout::Forever();
+ }
+
+ // Very small timeout values are problematic for two reasons: we don't want
+ // to burn energy redrawing animated images extremely fast, and broken tools
+ // generate these values when they actually want a "default" value, so such
+ // images won't play back right without normalization. For some context,
+ // see bug 890743, bug 125137, bug 139677, and bug 207059. The historical
+ // behavior of IE and Opera was:
+ // IE 6/Win:
+ // 10 - 50ms is normalized to 100ms.
+ // >50ms is used unnormalized.
+ // Opera 7 final/Win:
+ // 10ms is normalized to 100ms.
+ // >10ms is used unnormalized.
+ if (aRawMilliseconds >= 0 && aRawMilliseconds <= 10 ) {
+ return FrameTimeout(100);
+ }
+
+ // The provided timeout value is OK as-is.
+ return FrameTimeout(aRawMilliseconds);
+}
+
+bool
+FrameTimeout::operator==(const FrameTimeout& aOther) const
+{
+ return mTimeout == aOther.mTimeout;
+}
+
+bool
+FrameTimeout::operator!=(const FrameTimeout& aOther) const
+{
+ return !(*this == aOther);
+}
+
+FrameTimeout
+FrameTimeout::operator+(const FrameTimeout& aOther)
+{
+ if (*this == Forever() || aOther == Forever()) {
+ return Forever();
+ }
+
+ return FrameTimeout(mTimeout + aOther.mTimeout);
+}
+
+FrameTimeout& FrameTimeout::operator+=(const FrameTimeout& aOther)
+{
+ *this = *this + aOther;
+ return *this;
+}
+
+uint32_t
+FrameTimeout::AsMilliseconds() const
+{
+ if (*this == Forever()) {
+ MOZ_ASSERT_UNREACHABLE("Calling AsMilliseconds() on an infinite FrameTimeout");
+ return 100; // Fail to something sane.
+ }
+
+ return uint32_t(mTimeout);
+}
+
+int32_t
+FrameTimeout::AsEncodedValueDeprecated() const
+{
+ return mTimeout;
+}
+
+FrameTimeout::FrameTimeout(int32_t aTimeout)
+ : mTimeout(aTimeout)
+{ }
+
+} // namespace image
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/image/FrameTimeout.h
@@ -0,0 +1,76 @@
+/* -*- 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/. */
+
+#ifndef mozilla_image_frametimeout_h
+#define mozilla_image_frametimeout_h
+
+#include "mozilla/Assertions.h"
+//#include "mozilla/MemoryReporting.h"
+//#include "mozilla/Monitor.h"
+//#include "mozilla/Move.h"
+//#include "gfxDrawable.h"
+//#include "imgIContainer.h"
+//#include "MainThreadUtils.h"
+//#include "nsAutoPtr.h"
+
+namespace mozilla {
+namespace image {
+
+/**
+ * FrameTimeout wraps a frame timeout value (measured in milliseconds) after
+ * first normalizing it. This normalization is necessary because some tools
+ * generate incorrect frame timeout values which we nevertheless have to
+ * support. For this reason, code that deals with frame timeouts should always
+ * use a FrameTimeout value rather than the raw value from the image header.
+ */
+struct FrameTimeout
+{
+ /**
+ * @return a FrameTimeout of zero. This should be used only for math
+ * involving FrameTimeout values. You can't obtain a zero FrameTimeout from
+ * FromRawMilliseconds().
+ */
+ static FrameTimeout Zero();
+
+ /// @return an infinite FrameTimeout.
+ static FrameTimeout Forever();
+
+ /// @return a FrameTimeout obtained by normalizing a raw timeout value.
+ static FrameTimeout FromRawMilliseconds(int32_t aRawMilliseconds);
+
+ bool operator==(const FrameTimeout& aOther) const;
+
+ bool operator!=(const FrameTimeout& aOther) const;
+
+ FrameTimeout operator+(const FrameTimeout& aOther);
+
+ FrameTimeout& operator+=(const FrameTimeout& aOther);
+
+ /**
+ * @return this FrameTimeout's value in milliseconds. Illegal to call on a
+ * an infinite FrameTimeout value.
+ */
+ uint32_t AsMilliseconds() const;
+
+ /**
+ * @return this FrameTimeout value encoded so that non-negative values
+ * represent a timeout in milliseconds, and -1 represents an infinite
+ * timeout.
+ *
+ * XXX(seth): This is a backwards compatibility hack that should be removed.
+ */
+ int32_t AsEncodedValueDeprecated() const;
+
+private:
+ explicit FrameTimeout(int32_t aTimeout);
+
+ int32_t mTimeout;
+};
+
+} // namespace image
+} // namespace mozilla
+
+#endif // mozilla_image_frametimeout_h
--- a/image/ImageMetadata.h
+++ b/image/ImageMetadata.h
@@ -3,16 +3,17 @@
* 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/. */
#ifndef mozilla_image_ImageMetadata_h
#define mozilla_image_ImageMetadata_h
#include <stdint.h>
+#include "FrameTimeout.h"
#include "mozilla/Maybe.h"
#include "nsSize.h"
#include "Orientation.h"
namespace mozilla {
namespace image {
class RasterImage;
--- a/image/imgFrame.h
+++ b/image/imgFrame.h
@@ -6,16 +6,17 @@
#ifndef mozilla_image_imgFrame_h
#define mozilla_image_imgFrame_h
#include "mozilla/Maybe.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/Monitor.h"
#include "mozilla/Move.h"
+#include "FrameTimeout.h"
#include "gfxDrawable.h"
#include "imgIContainer.h"
#include "MainThreadUtils.h"
#include "nsAutoPtr.h"
namespace mozilla {
namespace image {
@@ -42,116 +43,16 @@ enum class DisposalMethod : int8_t {
};
enum class Opacity : uint8_t {
FULLY_OPAQUE,
SOME_TRANSPARENCY
};
/**
- * FrameTimeout wraps a frame timeout value (measured in milliseconds) after
- * first normalizing it. This normalization is necessary because some tools
- * generate incorrect frame timeout values which we nevertheless have to
- * support. For this reason, code that deals with frame timeouts should always
- * use a FrameTimeout value rather than the raw value from the image header.
- */
-struct FrameTimeout
-{
- /**
- * @return a FrameTimeout of zero. This should be used only for math
- * involving FrameTimeout values. You can't obtain a zero FrameTimeout from
- * FromRawMilliseconds().
- */
- static FrameTimeout Zero() { return FrameTimeout(0); }
-
- /// @return an infinite FrameTimeout.
- static FrameTimeout Forever() { return FrameTimeout(-1); }
-
- /// @return a FrameTimeout obtained by normalizing a raw timeout value.
- static FrameTimeout FromRawMilliseconds(int32_t aRawMilliseconds)
- {
- // Normalize all infinite timeouts to the same value.
- if (aRawMilliseconds < 0) {
- return FrameTimeout::Forever();
- }
-
- // Very small timeout values are problematic for two reasons: we don't want
- // to burn energy redrawing animated images extremely fast, and broken tools
- // generate these values when they actually want a "default" value, so such
- // images won't play back right without normalization. For some context,
- // see bug 890743, bug 125137, bug 139677, and bug 207059. The historical
- // behavior of IE and Opera was:
- // IE 6/Win:
- // 10 - 50ms is normalized to 100ms.
- // >50ms is used unnormalized.
- // Opera 7 final/Win:
- // 10ms is normalized to 100ms.
- // >10ms is used unnormalized.
- if (aRawMilliseconds >= 0 && aRawMilliseconds <= 10 ) {
- return FrameTimeout(100);
- }
-
- // The provided timeout value is OK as-is.
- return FrameTimeout(aRawMilliseconds);
- }
-
- bool operator==(const FrameTimeout& aOther) const
- {
- return mTimeout == aOther.mTimeout;
- }
-
- bool operator!=(const FrameTimeout& aOther) const { return !(*this == aOther); }
-
- FrameTimeout operator+(const FrameTimeout& aOther)
- {
- if (*this == Forever() || aOther == Forever()) {
- return Forever();
- }
-
- return FrameTimeout(mTimeout + aOther.mTimeout);
- }
-
- FrameTimeout& operator+=(const FrameTimeout& aOther)
- {
- *this = *this + aOther;
- return *this;
- }
-
- /**
- * @return this FrameTimeout's value in milliseconds. Illegal to call on a
- * an infinite FrameTimeout value.
- */
- uint32_t AsMilliseconds() const
- {
- if (*this == Forever()) {
- MOZ_ASSERT_UNREACHABLE("Calling AsMilliseconds() on an infinite FrameTimeout");
- return 100; // Fail to something sane.
- }
-
- return uint32_t(mTimeout);
- }
-
- /**
- * @return this FrameTimeout value encoded so that non-negative values
- * represent a timeout in milliseconds, and -1 represents an infinite
- * timeout.
- *
- * XXX(seth): This is a backwards compatibility hack that should be removed.
- */
- int32_t AsEncodedValueDeprecated() const { return mTimeout; }
-
-private:
- explicit FrameTimeout(int32_t aTimeout)
- : mTimeout(aTimeout)
- { }
-
- int32_t mTimeout;
-};
-
-/**
* AnimationData contains all of the information necessary for using an imgFrame
* as part of an animation.
*
* It includes pointers to the raw image data of the underlying imgFrame, but
* does not own that data. A RawAccessFrameRef for the underlying imgFrame must
* outlive the AnimationData for it to remain valid.
*/
struct AnimationData
--- a/image/moz.build
+++ b/image/moz.build
@@ -32,16 +32,17 @@ XPIDL_SOURCES += [
'imgITools.idl',
'nsIIconURI.idl',
]
XPIDL_MODULE = 'imglib2'
EXPORTS += [
'DrawResult.h',
+ 'FrameTimeout.h',
'ImageCacheKey.h',
'ImageLogging.h',
'ImageOps.h',
'ImageRegion.h',
'imgLoader.h',
'imgRequest.h',
'imgRequestProxy.h',
'IProgressObserver.h',
@@ -53,16 +54,17 @@ UNIFIED_SOURCES += [
'AnimationSurfaceProvider.cpp',
'ClippedImage.cpp',
'DecodedSurfaceProvider.cpp',
'DecodePool.cpp',
'Decoder.cpp',
'DecoderFactory.cpp',
'DynamicImage.cpp',
'FrameAnimator.cpp',
+ 'FrameTimeout.cpp',
'FrozenImage.cpp',
'IDecodingTask.cpp',
'Image.cpp',
'ImageCacheKey.cpp',
'ImageFactory.cpp',
'ImageOps.cpp',
'ImageWrapper.cpp',
'imgFrame.cpp',