OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2013 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 |
| 10 #include "SkPictureSource.h" |
| 11 |
| 12 // This GM exercises the SkPictureSource ImageFilter class. |
| 13 |
| 14 class PictureSourceGM : public skiagm::GM { |
| 15 public: |
| 16 PictureSourceGM() { |
| 17 } |
| 18 |
| 19 protected: |
| 20 virtual SkString onShortName() SK_OVERRIDE { |
| 21 return SkString("picturesource"); |
| 22 } |
| 23 |
| 24 void makePicture() { |
| 25 SkCanvas* canvas = fPicture.beginRecording(100, 100); |
| 26 canvas->clear(0x00000000); |
| 27 SkPaint paint; |
| 28 paint.setAntiAlias(true); |
| 29 paint.setColor(0xFFFFFFFF); |
| 30 paint.setTextSize(SkIntToScalar(96)); |
| 31 const char* str = "e"; |
| 32 canvas->drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70),
paint); |
| 33 } |
| 34 |
| 35 virtual SkISize onISize() SK_OVERRIDE { return SkISize::Make(500, 150); } |
| 36 |
| 37 virtual void onOnceBeforeDraw() SK_OVERRIDE { |
| 38 this->makePicture(); |
| 39 } |
| 40 |
| 41 static void fillRectFiltered(SkCanvas* canvas, const SkRect& clipRect, SkIma
geFilter* filter) { |
| 42 SkPaint paint; |
| 43 paint.setImageFilter(filter); |
| 44 canvas->save(); |
| 45 canvas->clipRect(clipRect); |
| 46 canvas->drawPaint(paint); |
| 47 canvas->restore(); |
| 48 } |
| 49 |
| 50 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 51 canvas->clear(0x00000000); |
| 52 { |
| 53 SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30); |
| 54 SkRect emptyRect = SkRect::MakeXYWH(20, 20, 0, 0); |
| 55 SkRect bounds = SkRect::MakeXYWH(0, 0, 100, 100); |
| 56 SkAutoTUnref<SkImageFilter> pictureSource(new SkPictureSource(fPictu
re)); |
| 57 SkAutoTUnref<SkImageFilter> pictureSourceSrcRect(new SkPictureSource
(fPicture, srcRect)); |
| 58 SkAutoTUnref<SkImageFilter> pictureSourceEmptyRect(new SkPictureSour
ce(fPicture, emptyRect)); |
| 59 |
| 60 // Draw the picture unscaled. |
| 61 fillRectFiltered(canvas, bounds, pictureSource); |
| 62 canvas->translate(SkIntToScalar(100), 0); |
| 63 |
| 64 // Draw an unscaled subset of the source picture. |
| 65 fillRectFiltered(canvas, bounds, pictureSourceSrcRect); |
| 66 canvas->translate(SkIntToScalar(100), 0); |
| 67 |
| 68 // Draw the picture to an empty rect (should draw nothing). |
| 69 fillRectFiltered(canvas, bounds, pictureSourceEmptyRect); |
| 70 canvas->translate(SkIntToScalar(100), 0); |
| 71 } |
| 72 } |
| 73 |
| 74 private: |
| 75 SkPicture fPicture; |
| 76 typedef GM INHERITED; |
| 77 }; |
| 78 |
| 79 /////////////////////////////////////////////////////////////////////////////// |
| 80 |
| 81 DEF_GM( return new PictureSourceGM; ) |
OLD | NEW |