OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2014 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include "gm.h" | |
9 #include "SkDropShadowImageFilter.h" | |
10 #include "SkPictureRecorder.h" | |
11 | |
12 #define TILE 128 | |
13 #define WIDTH 200 | |
14 #define HEIGHT 400 | |
15 #define DX 4 | |
16 #define DY 4 | |
17 #define SIGMA 3 | |
18 #define OFFSET (WIDTH + 10) | |
19 | |
20 // This GM is a regression test for http://skbug.com/2957 and http://crbug.com/4 15468. | |
robertphillips
2014/09/23 16:36:38
// It draws a clipped rect in a layer which, in tu
| |
21 struct ImageBlurTiled2GM : public skiagm::GM { | |
robertphillips
2014/09/23 16:36:38
SK_OVERRIDE on these two ?
| |
22 virtual SkString onShortName() { return SkString("imageblurtiled2"); } | |
Stephen White
2014/09/23 16:03:51
Nit: this GM should probably be renamed dropshadow
mtklein
2014/09/23 17:43:13
Very good idea. Done.
| |
23 virtual SkISize onISize() { | |
24 return SkISize::Make(WIDTH + OFFSET + DX + 3 * SIGMA, HEIGHT + DY + 3 * SIGMA); | |
25 } | |
26 | |
robertphillips
2014/09/23 16:36:38
Just make this "const SkPicture* create_picture();
| |
27 void drawInto(SkCanvas* canvas) const { | |
28 SkPaint layerPaint; | |
29 layerPaint.setImageFilter( | |
30 SkDropShadowImageFilter::Create(OFFSET, DX, DY, SIGMA, SK_ColorB LACK))->unref(); | |
31 | |
32 SkPaint green; | |
33 green.setColor(SK_ColorGREEN); | |
34 | |
35 canvas->saveLayer(NULL, &layerPaint); | |
36 canvas->clipRect(SkRect::MakeWH(WIDTH, HEIGHT)); | |
37 canvas->drawRect(SkRect::MakeWH(WIDTH, HEIGHT), green); | |
38 canvas->restore(); | |
39 } | |
40 | |
robertphillips
2014/09/23 16:36:38
SK_OVERRIDE ?
| |
41 virtual void onDraw(SkCanvas* canvas) { | |
42 SkPictureRecorder recorder; | |
43 const SkTileGridFactory::TileGridInfo info = { { TILE, TILE }, {0, 0}, { 0, 0} }; | |
44 SkTileGridFactory factory(info); | |
45 | |
46 this->drawInto(recorder.beginRecording(WIDTH + OFFSET, HEIGHT, &factory) ); | |
47 SkAutoTUnref<const SkPicture> pic(recorder.endRecording()); | |
48 | |
49 SkRect bounds = { 0, 0, 0, 0 }; | |
50 SkAssertResult(canvas->getClipBounds(&bounds)); | |
51 | |
52 for (SkScalar y = bounds.top() ; y < bounds.bottom(); y += TILE) { | |
robertphillips
2014/09/23 16:36:38
indent here?
| |
53 for (SkScalar x = bounds.left(); x < bounds.right() ; x += TILE) { | |
54 canvas->save(); | |
55 canvas->clipRect(SkRect::MakeXYWH(x, y, TILE, TILE)); | |
56 canvas->drawPicture(pic); | |
57 canvas->restore(); | |
58 } | |
59 } | |
60 } | |
robertphillips
2014/09/23 16:36:38
private:
typedef GM INHERITED;
?
| |
61 }; | |
robertphillips
2014/09/23 16:36:38
virtual uint32_t onGetFlags() const SK_OVERRIDE {
| |
62 DEF_GM(return new ImageBlurTiled2GM); | |
OLD | NEW |