From 4e16bb2a322f2bd16cb1afd2f78c27e420a4b9db Mon Sep 17 00:00:00 2001 From: "senorblanco@chromium.org" Date: Fri, 26 Jul 2013 00:10:07 +0000 Subject: 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 --- gm/lighting.cpp | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'gm/lighting.cpp') diff --git a/gm/lighting.cpp b/gm/lighting.cpp index de5e3309c2..f16e781db0 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 @@ protected: 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: -- cgit v1.2.3