Make CropRect immutable after construction.

BUG=
R=reed@google.com

Review URL: https://codereview.chromium.org/27490005

git-svn-id: http://skia.googlecode.com/svn/trunk@11819 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
senorblanco@chromium.org 2013-10-16 18:07:48 +00:00
parent 3e7e992a8a
commit 3f1f2a3a59
2 changed files with 28 additions and 25 deletions

View File

@ -31,9 +31,8 @@ class SK_API SkImageFilter : public SkFlattenable {
public:
SK_DECLARE_INST_COUNT(SkImageFilter)
struct CropRect {
SkRect fRect;
uint32_t fFlags;
class CropRect {
public:
enum CropEdge {
kHasLeft_CropEdge = 0x01,
kHasTop_CropEdge = 0x02,
@ -43,11 +42,11 @@ public:
};
CropRect() {}
explicit CropRect(const SkRect& rect, uint32_t flags = kHasAll_CropEdge) : fRect(rect), fFlags(flags) {}
// Returns true if any of the crop edges have been set.
bool isSet() const
{
return fFlags != 0x0;
}
uint32_t flags() const { return fFlags; }
const SkRect& rect() const { return fRect; }
private:
SkRect fRect;
uint32_t fFlags;
};
class Proxy {
@ -149,15 +148,16 @@ public:
}
/**
* Returns the crop rectangle of this filter. This is set at construction
* time, and determines which pixels from the input image will
* be processed. The size of this rectangle should be used as the size
* of the destination image. The origin of this rect should be used to
* offset access to the input images, and should also be added to the
* "offset" parameter in onFilterImage and filterImageGPU(). (The latter
* ensures that the resulting buffer is drawn in the correct location.)
* Returns whether any edges of the crop rect have been set. The crop
* rect is set at construction time, and determines which pixels from the
* input image will be processed. The size of the crop rect should be
* used as the size of the destination image. The origin of this rect
* should be used to offset access to the input images, and should also
* be added to the "offset" parameter in onFilterImage and
* filterImageGPU(). (The latter ensures that the resulting buffer is
* drawn in the correct location.)
*/
bool cropRectIsSet() const { return fCropRect.isSet(); }
bool cropRectIsSet() const { return fCropRect.flags() != 0x0; }
protected:
SkImageFilter(int inputCount, SkImageFilter** inputs, const CropRect* cropRect = NULL);

View File

@ -61,8 +61,10 @@ SkImageFilter::SkImageFilter(SkFlattenableReadBuffer& buffer)
fInputs[i] = NULL;
}
}
buffer.readRect(&fCropRect.fRect);
fCropRect.fFlags = buffer.readUInt();
SkRect rect;
buffer.readRect(&rect);
uint32_t flags = buffer.readUInt();
fCropRect = CropRect(rect, flags);
}
void SkImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
@ -74,8 +76,8 @@ void SkImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
buffer.writeFlattenable(input);
}
}
buffer.writeRect(fCropRect.fRect);
buffer.writeUInt(fCropRect.fFlags);
buffer.writeRect(fCropRect.rect());
buffer.writeUInt(fCropRect.flags());
}
bool SkImageFilter::filterImage(Proxy* proxy, const SkBitmap& src,
@ -158,14 +160,15 @@ bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMa
bool SkImageFilter::applyCropRect(SkIRect* rect, const SkMatrix& matrix) const {
SkRect cropRect;
matrix.mapRect(&cropRect, fCropRect.fRect);
matrix.mapRect(&cropRect, fCropRect.rect());
SkIRect cropRectI;
cropRect.roundOut(&cropRectI);
uint32_t flags = fCropRect.flags();
// If the original crop rect edges were unset, max out the new crop edges
if (!(fCropRect.fFlags & CropRect::kHasLeft_CropEdge)) cropRectI.fLeft = SK_MinS32;
if (!(fCropRect.fFlags & CropRect::kHasTop_CropEdge)) cropRectI.fTop = SK_MinS32;
if (!(fCropRect.fFlags & CropRect::kHasRight_CropEdge)) cropRectI.fRight = SK_MaxS32;
if (!(fCropRect.fFlags & CropRect::kHasBottom_CropEdge)) cropRectI.fBottom = SK_MaxS32;
if (!(flags & CropRect::kHasLeft_CropEdge)) cropRectI.fLeft = SK_MinS32;
if (!(flags & CropRect::kHasTop_CropEdge)) cropRectI.fTop = SK_MinS32;
if (!(flags & CropRect::kHasRight_CropEdge)) cropRectI.fRight = SK_MaxS32;
if (!(flags & CropRect::kHasBottom_CropEdge)) cropRectI.fBottom = SK_MaxS32;
return rect->intersect(cropRectI);
}