Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(707)

Unified Diff: src/core/SkImageFilter.cpp

Issue 1218993002: refactor code to apply the croprect (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkImageFilter.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkImageFilter.cpp
diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp
index 178d892b610235be8583b28e8648e6c2f27fd39c..fb7d8b28c098482719341b15aab42a63b61f3be7 100644
--- a/src/core/SkImageFilter.cpp
+++ b/src/core/SkImageFilter.cpp
@@ -33,6 +33,64 @@
enum { kDefaultCacheSize = 128 * 1024 * 1024 };
#endif
+#ifndef SK_IGNORE_TO_STRING
+void SkImageFilter::CropRect::toString(SkString* str) const {
+ if (!fFlags) {
+ return;
+ }
+
+ str->appendf("cropRect (");
+ if (fFlags & CropRect::kHasLeft_CropEdge) {
+ str->appendf("%.2f, ", fRect.fLeft);
+ } else {
+ str->appendf("X, ");
+ }
+ if (fFlags & CropRect::kHasTop_CropEdge) {
+ str->appendf("%.2f, ", fRect.fTop);
+ } else {
+ str->appendf("X, ");
+ }
+ if (fFlags & CropRect::kHasRight_CropEdge) {
+ str->appendf("%.2f, ", fRect.fRight);
+ } else {
+ str->appendf("X, ");
+ }
+ if (fFlags & CropRect::kHasBottom_CropEdge) {
+ str->appendf("%.2f", fRect.fBottom);
+ } else {
+ str->appendf("X");
+ }
+ str->appendf(") ");
+}
+#endif
+
+bool SkImageFilter::CropRect::applyTo(const SkIRect& imageBounds, const Context& ctx,
+ SkIRect* cropped) const {
+ *cropped = imageBounds;
+ if (fFlags) {
+ SkRect devCropR;
+ ctx.ctm().mapRect(&devCropR, fRect);
+ const SkIRect devICropR = devCropR.roundOut();
+
+ // Compute the left/top first, in case we have to read them to compute right/bottom
+ if (fFlags & kHasLeft_CropEdge) {
+ cropped->fLeft = devICropR.fLeft;
+ }
+ if (fFlags & kHasTop_CropEdge) {
+ cropped->fTop = devICropR.fTop;
+ }
+ if (fFlags & kHasRight_CropEdge) {
+ cropped->fRight = cropped->fLeft + devICropR.width();
+ }
+ if (fFlags & kHasBottom_CropEdge) {
+ cropped->fBottom = cropped->fTop + devICropR.height();
+ }
+ }
+ return cropped->intersect(ctx.clipBounds());
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
static int32_t next_image_filter_unique_id() {
static int32_t gImageFilterUniqueID;
@@ -298,27 +356,7 @@ bool SkImageFilter::applyCropRect(const Context& ctx, const SkBitmap& src,
SkIRect srcBounds;
src.getBounds(&srcBounds);
srcBounds.offset(srcOffset);
- SkRect cropRect;
- ctx.ctm().mapRect(&cropRect, fCropRect.rect());
- const SkIRect cropRectI = cropRect.roundOut();
- uint32_t flags = fCropRect.flags();
- if (flags & CropRect::kHasLeft_CropEdge) {
- srcBounds.fLeft = cropRectI.fLeft;
- }
- if (flags & CropRect::kHasTop_CropEdge) {
- srcBounds.fTop = cropRectI.fTop;
- }
- if (flags & CropRect::kHasRight_CropEdge) {
- srcBounds.fRight = srcBounds.fLeft + cropRectI.width();
- }
- if (flags & CropRect::kHasBottom_CropEdge) {
- srcBounds.fBottom = srcBounds.fTop + cropRectI.height();
- }
- if (!srcBounds.intersect(ctx.clipBounds())) {
- return false;
- }
- *bounds = srcBounds;
- return true;
+ return fCropRect.applyTo(srcBounds, ctx, bounds);
}
bool SkImageFilter::applyCropRect(const Context& ctx, Proxy* proxy, const SkBitmap& src,
@@ -326,26 +364,10 @@ bool SkImageFilter::applyCropRect(const Context& ctx, Proxy* proxy, const SkBitm
SkIRect srcBounds;
src.getBounds(&srcBounds);
srcBounds.offset(*srcOffset);
- SkRect cropRect;
- ctx.ctm().mapRect(&cropRect, fCropRect.rect());
- const SkIRect cropRectI = cropRect.roundOut();
- uint32_t flags = fCropRect.flags();
- *bounds = srcBounds;
- if (flags & CropRect::kHasLeft_CropEdge) {
- bounds->fLeft = cropRectI.fLeft;
- }
- if (flags & CropRect::kHasTop_CropEdge) {
- bounds->fTop = cropRectI.fTop;
- }
- if (flags & CropRect::kHasRight_CropEdge) {
- bounds->fRight = bounds->fLeft + cropRectI.width();
- }
- if (flags & CropRect::kHasBottom_CropEdge) {
- bounds->fBottom = bounds->fTop + cropRectI.height();
- }
- if (!bounds->intersect(ctx.clipBounds())) {
+ if (!fCropRect.applyTo(srcBounds, ctx, bounds)) {
return false;
}
+
if (srcBounds.contains(*bounds)) {
*dst = src;
return true;
« no previous file with comments | « include/core/SkImageFilter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698