| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "gm.h" | 8 #include "gm.h" |
| 9 #include "SkLightingImageFilter.h" | 9 #include "SkLightingImageFilter.h" |
| 10 | 10 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 const char* str = "e"; | 37 const char* str = "e"; |
| 38 canvas.drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70),
paint); | 38 canvas.drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70),
paint); |
| 39 } | 39 } |
| 40 | 40 |
| 41 virtual SkISize onISize() { | 41 virtual SkISize onISize() { |
| 42 return make_isize(WIDTH, HEIGHT); | 42 return make_isize(WIDTH, HEIGHT); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void drawClippedBitmap(SkCanvas* canvas, const SkPaint& paint, int x, int y)
{ | 45 void drawClippedBitmap(SkCanvas* canvas, const SkPaint& paint, int x, int y)
{ |
| 46 canvas->save(); | 46 canvas->save(); |
| 47 canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y), | 47 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
| 48 SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height()))); | 48 canvas->clipRect(SkRect::MakeWH( |
| 49 canvas->drawBitmap(fBitmap, SkIntToScalar(x), SkIntToScalar(y), &paint); | 49 SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height()))); |
| 50 canvas->drawBitmap(fBitmap, 0, 0, &paint); |
| 50 canvas->restore(); | 51 canvas->restore(); |
| 51 } | 52 } |
| 52 | 53 |
| 53 virtual void onDraw(SkCanvas* canvas) { | 54 virtual void onDraw(SkCanvas* canvas) { |
| 54 if (!fInitialized) { | 55 if (!fInitialized) { |
| 55 make_bitmap(); | 56 make_bitmap(); |
| 56 fInitialized = true; | 57 fInitialized = true; |
| 57 } | 58 } |
| 58 canvas->clear(0xFF101010); | 59 canvas->clear(0xFF101010); |
| 59 SkPaint checkPaint; | 60 SkPaint checkPaint; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 84 SkColor white(0xFFFFFFFF); | 85 SkColor white(0xFFFFFFFF); |
| 85 SkPaint paint; | 86 SkPaint paint; |
| 86 | 87 |
| 87 SkIRect cropRect = SkIRect::MakeXYWH(20, 10, 60, 65); | 88 SkIRect cropRect = SkIRect::MakeXYWH(20, 10, 60, 65); |
| 88 | 89 |
| 89 int y = 0; | 90 int y = 0; |
| 90 for (int i = 0; i < 2; i++) { | 91 for (int i = 0; i < 2; i++) { |
| 91 const SkIRect* cr = (i == 0) ? NULL : &cropRect; | 92 const SkIRect* cr = (i == 0) ? NULL : &cropRect; |
| 92 paint.setImageFilter(SkLightingImageFilter::CreatePointLitDiffuse(po
intLocation, white, surfaceScale, kd, NULL, cr))->unref(); | 93 paint.setImageFilter(SkLightingImageFilter::CreatePointLitDiffuse(po
intLocation, white, surfaceScale, kd, NULL, cr))->unref(); |
| 93 drawClippedBitmap(canvas, paint, 0, y); | 94 drawClippedBitmap(canvas, paint, 0, y); |
| 95 |
| 94 paint.setImageFilter(SkLightingImageFilter::CreateDistantLitDiffuse(
distantDirection, white, surfaceScale, kd, NULL, cr))->unref(); | 96 paint.setImageFilter(SkLightingImageFilter::CreateDistantLitDiffuse(
distantDirection, white, surfaceScale, kd, NULL, cr))->unref(); |
| 95 drawClippedBitmap(canvas, paint, 110, y); | 97 drawClippedBitmap(canvas, paint, 110, y); |
| 98 |
| 96 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitDiffuse(spo
tLocation, spotTarget, spotExponent, cutoffAngle, white, surfaceScale, kd, NULL,
cr))->unref(); | 99 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitDiffuse(spo
tLocation, spotTarget, spotExponent, cutoffAngle, white, surfaceScale, kd, NULL,
cr))->unref(); |
| 97 drawClippedBitmap(canvas, paint, 220, y); | 100 drawClippedBitmap(canvas, paint, 220, y); |
| 98 | 101 |
| 99 y += 110; | 102 y += 110; |
| 103 |
| 100 paint.setImageFilter(SkLightingImageFilter::CreatePointLitSpecular(p
ointLocation, white, surfaceScale, ks, shininess, NULL, cr))->unref(); | 104 paint.setImageFilter(SkLightingImageFilter::CreatePointLitSpecular(p
ointLocation, white, surfaceScale, ks, shininess, NULL, cr))->unref(); |
| 101 drawClippedBitmap(canvas, paint, 0, y); | 105 drawClippedBitmap(canvas, paint, 0, y); |
| 106 |
| 102 paint.setImageFilter(SkLightingImageFilter::CreateDistantLitSpecular
(distantDirection, white, surfaceScale, ks, shininess, NULL, cr))->unref(); | 107 paint.setImageFilter(SkLightingImageFilter::CreateDistantLitSpecular
(distantDirection, white, surfaceScale, ks, shininess, NULL, cr))->unref(); |
| 103 drawClippedBitmap(canvas, paint, 110, y); | 108 drawClippedBitmap(canvas, paint, 110, y); |
| 109 |
| 104 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(sp
otLocation, spotTarget, spotExponent, cutoffAngle, white, surfaceScale, ks, shin
iness, NULL, cr))->unref(); | 110 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(sp
otLocation, spotTarget, spotExponent, cutoffAngle, white, surfaceScale, ks, shin
iness, NULL, cr))->unref(); |
| 105 drawClippedBitmap(canvas, paint, 220, y); | 111 drawClippedBitmap(canvas, paint, 220, y); |
| 112 |
| 106 y += 110; | 113 y += 110; |
| 107 } | 114 } |
| 108 } | 115 } |
| 109 | 116 |
| 110 private: | 117 private: |
| 111 typedef GM INHERITED; | 118 typedef GM INHERITED; |
| 112 SkBitmap fBitmap; | 119 SkBitmap fBitmap; |
| 113 bool fInitialized; | 120 bool fInitialized; |
| 114 }; | 121 }; |
| 115 | 122 |
| 116 ////////////////////////////////////////////////////////////////////////////// | 123 ////////////////////////////////////////////////////////////////////////////// |
| 117 | 124 |
| 118 static GM* MyFactory(void*) { return new ImageLightingGM; } | 125 static GM* MyFactory(void*) { return new ImageLightingGM; } |
| 119 static GMRegistry reg(MyFactory); | 126 static GMRegistry reg(MyFactory); |
| 120 | 127 |
| 121 } | 128 } |
| OLD | NEW |