Implement crop rect for lighting image filters. Changes for the CPU path were fairly straightforward: use the bounds rectangle when traversing the pixels, not the source rectangle.
For the GPU path, this required modifying the signature of SkImageFilter::asNewEffect() to receive the bounds offset, so that the lighting filters could offset the light position by the offset. It also required modifying the base-class implementation of SkImageFilter::filterImageGPU() (which implements single-pass filters) to intersect against the bounds rect, to pass its offset to asNewEffect(), and to modify the caller's offset (so it's drawn in the correct place).
Note: this will require rebaselining the lighting GM. Six new test cases were added, to accommodate a cropped version of each lighting filter.
R=bsalomon@google.com, reed@google.com
Review URL: https://codereview.chromium.org/20426002
git-svn-id: http://skia.googlecode.com/svn/trunk@10379 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gm/lighting.cpp b/gm/lighting.cpp
index de5e330..f16e781 100644
--- a/gm/lighting.cpp
+++ b/gm/lighting.cpp
@@ -9,7 +9,7 @@
#include "SkLightingImageFilter.h"
#define WIDTH 330
-#define HEIGHT 220
+#define HEIGHT 440
namespace skiagm {
@@ -83,18 +83,28 @@
SkScalar surfaceScale = SkIntToScalar(1);
SkColor white(0xFFFFFFFF);
SkPaint paint;
- paint.setImageFilter(SkLightingImageFilter::CreatePointLitDiffuse(pointLocation, white, surfaceScale, kd))->unref();
- drawClippedBitmap(canvas, paint, 0, 0);
- paint.setImageFilter(SkLightingImageFilter::CreateDistantLitDiffuse(distantDirection, white, surfaceScale, kd))->unref();
- drawClippedBitmap(canvas, paint, 110, 0);
- paint.setImageFilter(SkLightingImageFilter::CreateSpotLitDiffuse(spotLocation, spotTarget, spotExponent, cutoffAngle, white, surfaceScale, kd))->unref();
- drawClippedBitmap(canvas, paint, 220, 0);
- paint.setImageFilter(SkLightingImageFilter::CreatePointLitSpecular(pointLocation, white, surfaceScale, ks, shininess))->unref();
- drawClippedBitmap(canvas, paint, 0, 110);
- paint.setImageFilter(SkLightingImageFilter::CreateDistantLitSpecular(distantDirection, white, surfaceScale, ks, shininess))->unref();
- drawClippedBitmap(canvas, paint, 110, 110);
- paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(spotLocation, spotTarget, spotExponent, cutoffAngle, white, surfaceScale, ks, shininess))->unref();
- drawClippedBitmap(canvas, paint, 220, 110);
+
+ SkIRect cropRect = SkIRect::MakeXYWH(20, 10, 60, 65);
+
+ int y = 0;
+ for (int i = 0; i < 2; i++) {
+ const SkIRect* cr = (i == 0) ? NULL : &cropRect;
+ paint.setImageFilter(SkLightingImageFilter::CreatePointLitDiffuse(pointLocation, white, surfaceScale, kd, NULL, cr))->unref();
+ drawClippedBitmap(canvas, paint, 0, y);
+ paint.setImageFilter(SkLightingImageFilter::CreateDistantLitDiffuse(distantDirection, white, surfaceScale, kd, NULL, cr))->unref();
+ drawClippedBitmap(canvas, paint, 110, y);
+ paint.setImageFilter(SkLightingImageFilter::CreateSpotLitDiffuse(spotLocation, spotTarget, spotExponent, cutoffAngle, white, surfaceScale, kd, NULL, cr))->unref();
+ drawClippedBitmap(canvas, paint, 220, y);
+
+ y += 110;
+ paint.setImageFilter(SkLightingImageFilter::CreatePointLitSpecular(pointLocation, white, surfaceScale, ks, shininess, NULL, cr))->unref();
+ drawClippedBitmap(canvas, paint, 0, y);
+ paint.setImageFilter(SkLightingImageFilter::CreateDistantLitSpecular(distantDirection, white, surfaceScale, ks, shininess, NULL, cr))->unref();
+ drawClippedBitmap(canvas, paint, 110, y);
+ paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(spotLocation, spotTarget, spotExponent, cutoffAngle, white, surfaceScale, ks, shininess, NULL, cr))->unref();
+ drawClippedBitmap(canvas, paint, 220, y);
+ y += 110;
+ }
}
private: