From f77987538784f7fb9020714488f7aef9580a80ef Mon Sep 17 00:00:00 2001 From: Seth Fowler Date: Tue, 26 Mar 2013 11:56:46 -0700 Subject: [PATCH] Bug 826093 (Part 2) - Create a static utility class for image operations. r=joe, sr=bz --- image/src/ClippedImage.h | 2 +- image/src/FrozenImage.h | 2 +- image/src/ImageFactory.cpp | 8 ------ image/src/ImageFactory.h | 8 ------ image/src/ImageOps.cpp | 48 ++++++++++++++++++++++++++++++++++ image/src/ImageOps.h | 49 +++++++++++++++++++++++++++++++++++ image/src/Makefile.in | 2 ++ image/src/imgRequestProxy.cpp | 4 +-- 8 files changed, 103 insertions(+), 20 deletions(-) create mode 100644 image/src/ImageOps.cpp create mode 100644 image/src/ImageOps.h diff --git a/image/src/ClippedImage.h b/image/src/ClippedImage.h index 26f94154608b..45e37a7e2380 100644 --- a/image/src/ClippedImage.h +++ b/image/src/ClippedImage.h @@ -73,7 +73,7 @@ private: Maybe mShouldClip; // Memoized ShouldClip() if present. friend class DrawSingleTileCallback; - friend class ImageFactory; + friend class ImageOps; }; } // namespace image diff --git a/image/src/FrozenImage.h b/image/src/FrozenImage.h index 077caa04027e..b4cc255c839a 100644 --- a/image/src/FrozenImage.h +++ b/image/src/FrozenImage.h @@ -62,7 +62,7 @@ protected: FrozenImage(Image* aImage) : ImageWrapper(aImage) { } private: - friend class ImageFactory; + friend class ImageOps; }; } // namespace image diff --git a/image/src/ImageFactory.cpp b/image/src/ImageFactory.cpp index e44416b669bb..92ed5a526c4a 100644 --- a/image/src/ImageFactory.cpp +++ b/image/src/ImageFactory.cpp @@ -21,7 +21,6 @@ #include "imgStatusTracker.h" #include "RasterImage.h" #include "VectorImage.h" -#include "FrozenImage.h" #include "Image.h" #include "nsMediaFragmentURIParser.h" @@ -175,13 +174,6 @@ GetContentSize(nsIRequest* aRequest) return 0; } -/* static */ already_AddRefed -ImageFactory::Freeze(Image* aImage) -{ - nsRefPtr frozenImage = new FrozenImage(aImage); - return frozenImage.forget(); -} - /* static */ already_AddRefed ImageFactory::CreateRasterImage(nsIRequest* aRequest, imgStatusTracker* aStatusTracker, diff --git a/image/src/ImageFactory.h b/image/src/ImageFactory.h index 716ac9797610..dedac3fb6158 100644 --- a/image/src/ImageFactory.h +++ b/image/src/ImageFactory.h @@ -46,14 +46,6 @@ public: */ static already_AddRefed CreateAnonymousImage(const nsCString& aMimeType); - /** - * Creates a version of an existing image which does not animate and is frozen - * at the first frame. - * - * @param aImage The existing image. - */ - static already_AddRefed Freeze(Image* aImage); - private: // Factory functions that create specific types of image containers. static already_AddRefed CreateRasterImage(nsIRequest* aRequest, diff --git a/image/src/ImageOps.cpp b/image/src/ImageOps.cpp new file mode 100644 index 000000000000..add83a89f990 --- /dev/null +++ b/image/src/ImageOps.cpp @@ -0,0 +1,48 @@ +/* -*- 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 "imgIContainer.h" +#include "ClippedImage.h" +#include "FrozenImage.h" +#include "Image.h" + +#include "ImageOps.h" + +namespace mozilla { +namespace image { + +/* static */ already_AddRefed +ImageOps::Freeze(Image* aImage) +{ + nsRefPtr frozenImage = new FrozenImage(aImage); + return frozenImage.forget(); +} + +/* static */ already_AddRefed +ImageOps::Freeze(imgIContainer* aImage) +{ + nsCOMPtr frozenImage = + new FrozenImage(static_cast(aImage)); + return frozenImage.forget(); +} + +/* static */ already_AddRefed +ImageOps::Clip(Image* aImage, nsIntRect aClip) +{ + nsRefPtr clippedImage = new ClippedImage(aImage, aClip); + return clippedImage.forget(); +} + +/* static */ already_AddRefed +ImageOps::Clip(imgIContainer* aImage, nsIntRect aClip) +{ + nsCOMPtr clippedImage = + new ClippedImage(static_cast(aImage), aClip); + return clippedImage.forget(); +} + +} // namespace image +} // namespace mozilla diff --git a/image/src/ImageOps.h b/image/src/ImageOps.h new file mode 100644 index 000000000000..e68571f19a03 --- /dev/null +++ b/image/src/ImageOps.h @@ -0,0 +1,49 @@ +/* -*- 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_IMAGELIB_IMAGEOPS_H_ +#define MOZILLA_IMAGELIB_IMAGEOPS_H_ + +#include "nsCOMPtr.h" +#include "nsRect.h" + +class imgIContainer; + +namespace mozilla { +namespace image { + +class Image; + +class ImageOps +{ +public: + /** + * Creates a version of an existing image which does not animate and is frozen + * at the first frame. + * + * @param aImage The existing image. + */ + static already_AddRefed Freeze(Image* aImage); + static already_AddRefed Freeze(imgIContainer* aImage); + + /** + * Creates a clipped version of an existing image. Animation is unaffected. + * + * @param aImage The existing image. + * @param aClip The rectangle to clip the image against. + */ + static already_AddRefed Clip(Image* aImage, nsIntRect aClip); + static already_AddRefed Clip(imgIContainer* aImage, nsIntRect aClip); + +private: + // This is a static utility class, so disallow instantiation. + virtual ~ImageOps() = 0; +}; + +} // namespace image +} // namespace mozilla + +#endif // MOZILLA_IMAGELIB_IMAGEOPS_H_ diff --git a/image/src/Makefile.in b/image/src/Makefile.in index c855fa92318c..897a40f02bdb 100644 --- a/image/src/Makefile.in +++ b/image/src/Makefile.in @@ -20,12 +20,14 @@ FAIL_ON_WARNINGS = 1 EXPORTS = imgLoader.h \ imgRequest.h \ imgRequestProxy.h \ + ImageOps.h \ $(NULL) CPPSRCS = \ Image.cpp \ ImageFactory.cpp \ ImageMetadata.cpp \ + ImageOps.cpp \ ImageWrapper.cpp \ ClippedImage.cpp \ Decoder.cpp \ diff --git a/image/src/imgRequestProxy.cpp b/image/src/imgRequestProxy.cpp index d6ad4a34d0df..d5e995422541 100644 --- a/image/src/imgRequestProxy.cpp +++ b/image/src/imgRequestProxy.cpp @@ -18,7 +18,7 @@ #include "nsCRT.h" #include "Image.h" -#include "ImageFactory.h" +#include "ImageOps.h" #include "nsError.h" #include "ImageLogging.h" @@ -915,7 +915,7 @@ imgRequestProxy::GetStaticRequest(imgRequestProxy** aReturn) } // We are animated. We need to create a frozen version of this image. - nsRefPtr frozenImage = ImageFactory::Freeze(image); + nsRefPtr frozenImage = ImageOps::Freeze(image); // Create a static imgRequestProxy with our new extracted frame. nsCOMPtr currentPrincipal;