mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 06:11:37 +00:00
Bug 826093 (Part 2) - Create a static utility class for image operations. r=joe, sr=bz
This commit is contained in:
parent
2144eccec0
commit
485f15bb87
@ -77,7 +77,7 @@ private:
|
||||
Maybe<bool> mShouldClip; // Memoized ShouldClip() if present.
|
||||
|
||||
friend class DrawSingleTileCallback;
|
||||
friend class ImageFactory;
|
||||
friend class ImageOps;
|
||||
};
|
||||
|
||||
} // namespace image
|
||||
|
@ -62,7 +62,7 @@ protected:
|
||||
FrozenImage(Image* aImage) : ImageWrapper(aImage) { }
|
||||
|
||||
private:
|
||||
friend class ImageFactory;
|
||||
friend class ImageOps;
|
||||
};
|
||||
|
||||
} // namespace image
|
||||
|
@ -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<Image>
|
||||
ImageFactory::Freeze(Image* aImage)
|
||||
{
|
||||
nsRefPtr<Image> frozenImage = new FrozenImage(aImage);
|
||||
return frozenImage.forget();
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed<Image>
|
||||
ImageFactory::CreateRasterImage(nsIRequest* aRequest,
|
||||
imgStatusTracker* aStatusTracker,
|
||||
|
@ -46,14 +46,6 @@ public:
|
||||
*/
|
||||
static already_AddRefed<Image> 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<Image> Freeze(Image* aImage);
|
||||
|
||||
private:
|
||||
// Factory functions that create specific types of image containers.
|
||||
static already_AddRefed<Image> CreateRasterImage(nsIRequest* aRequest,
|
||||
|
48
image/src/ImageOps.cpp
Normal file
48
image/src/ImageOps.cpp
Normal file
@ -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<Image>
|
||||
ImageOps::Freeze(Image* aImage)
|
||||
{
|
||||
nsRefPtr<Image> frozenImage = new FrozenImage(aImage);
|
||||
return frozenImage.forget();
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed<imgIContainer>
|
||||
ImageOps::Freeze(imgIContainer* aImage)
|
||||
{
|
||||
nsCOMPtr<imgIContainer> frozenImage =
|
||||
new FrozenImage(static_cast<Image*>(aImage));
|
||||
return frozenImage.forget();
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed<Image>
|
||||
ImageOps::Clip(Image* aImage, nsIntRect aClip)
|
||||
{
|
||||
nsRefPtr<Image> clippedImage = new ClippedImage(aImage, aClip);
|
||||
return clippedImage.forget();
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed<imgIContainer>
|
||||
ImageOps::Clip(imgIContainer* aImage, nsIntRect aClip)
|
||||
{
|
||||
nsCOMPtr<imgIContainer> clippedImage =
|
||||
new ClippedImage(static_cast<Image*>(aImage), aClip);
|
||||
return clippedImage.forget();
|
||||
}
|
||||
|
||||
} // namespace image
|
||||
} // namespace mozilla
|
49
image/src/ImageOps.h
Normal file
49
image/src/ImageOps.h
Normal file
@ -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<Image> Freeze(Image* aImage);
|
||||
static already_AddRefed<imgIContainer> 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<Image> Clip(Image* aImage, nsIntRect aClip);
|
||||
static already_AddRefed<imgIContainer> 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_
|
@ -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 \
|
||||
|
@ -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<Image> frozenImage = ImageFactory::Freeze(image);
|
||||
nsRefPtr<Image> frozenImage = ImageOps::Freeze(image);
|
||||
|
||||
// Create a static imgRequestProxy with our new extracted frame.
|
||||
nsCOMPtr<nsIPrincipal> currentPrincipal;
|
||||
|
Loading…
Reference in New Issue
Block a user