| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 | 9 |
| 10 #include "SkPictureImageFilter.h" | 10 #include "SkPictureImageFilter.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 SkPaint paint; | 29 SkPaint paint; |
| 30 paint.setAntiAlias(true); | 30 paint.setAntiAlias(true); |
| 31 sk_tool_utils::set_portable_typeface(&paint); | 31 sk_tool_utils::set_portable_typeface(&paint); |
| 32 paint.setColor(0xFFFFFFFF); | 32 paint.setColor(0xFFFFFFFF); |
| 33 paint.setTextSize(SkIntToScalar(96)); | 33 paint.setTextSize(SkIntToScalar(96)); |
| 34 const char* str = "e"; | 34 const char* str = "e"; |
| 35 canvas->drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70),
paint); | 35 canvas->drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70),
paint); |
| 36 fPicture.reset(recorder.endRecording()); | 36 fPicture.reset(recorder.endRecording()); |
| 37 } | 37 } |
| 38 | 38 |
| 39 virtual SkISize onISize() SK_OVERRIDE { return SkISize::Make(500, 150); } | 39 virtual SkISize onISize() SK_OVERRIDE { return SkISize::Make(400, 300); } |
| 40 | 40 |
| 41 virtual void onOnceBeforeDraw() SK_OVERRIDE { | 41 virtual void onOnceBeforeDraw() SK_OVERRIDE { |
| 42 this->makePicture(); | 42 this->makePicture(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 static void fillRectFiltered(SkCanvas* canvas, const SkRect& clipRect, SkIma
geFilter* filter) { | 45 static void fillRectFiltered(SkCanvas* canvas, const SkRect& clipRect, SkIma
geFilter* filter) { |
| 46 SkPaint paint; | 46 SkPaint paint; |
| 47 paint.setImageFilter(filter); | 47 paint.setImageFilter(filter); |
| 48 canvas->save(); | 48 canvas->save(); |
| 49 canvas->clipRect(clipRect); | 49 canvas->clipRect(clipRect); |
| 50 canvas->drawPaint(paint); | 50 canvas->drawPaint(paint); |
| 51 canvas->restore(); | 51 canvas->restore(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 54 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 55 canvas->clear(0x00000000); | 55 canvas->clear(0x00000000); |
| 56 { | 56 { |
| 57 SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30); | 57 SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30); |
| 58 SkRect emptyRect = SkRect::MakeXYWH(20, 20, 0, 0); | 58 SkRect emptyRect = SkRect::MakeXYWH(20, 20, 0, 0); |
| 59 SkRect bounds = SkRect::MakeXYWH(0, 0, 100, 100); | 59 SkRect bounds = SkRect::MakeXYWH(0, 0, 100, 100); |
| 60 SkAutoTUnref<SkImageFilter> pictureSource(SkPictureImageFilter::Crea
te(fPicture)); | 60 SkAutoTUnref<SkPictureImageFilter> pictureSource( |
| 61 SkAutoTUnref<SkImageFilter> pictureSourceSrcRect(SkPictureImageFilte
r::Create(fPicture, srcRect)); | 61 SkPictureImageFilter::Create(fPicture)); |
| 62 SkAutoTUnref<SkImageFilter> pictureSourceEmptyRect(SkPictureImageFil
ter::Create(fPicture, emptyRect)); | 62 SkAutoTUnref<SkPictureImageFilter> pictureSourceSrcRect( |
| 63 SkPictureImageFilter::Create(fPicture, srcRect)); |
| 64 SkAutoTUnref<SkPictureImageFilter> pictureSourceEmptyRect( |
| 65 SkPictureImageFilter::Create(fPicture, emptyRect)); |
| 66 SkAutoTUnref<SkPictureImageFilter> pictureSourceResampled( |
| 67 SkPictureImageFilter::Create(fPicture, 0, |
| 68 SkPictureImageFilter::kLocalSpace_PictureResolution, |
| 69 SkPaint::kNone_FilterLevel)); |
| 63 | 70 |
| 71 canvas->save(); |
| 64 // Draw the picture unscaled. | 72 // Draw the picture unscaled. |
| 65 fillRectFiltered(canvas, bounds, pictureSource); | 73 fillRectFiltered(canvas, bounds, pictureSource); |
| 66 canvas->translate(SkIntToScalar(100), 0); | 74 canvas->translate(SkIntToScalar(100), 0); |
| 67 | 75 |
| 68 // Draw an unscaled subset of the source picture. | 76 // Draw an unscaled subset of the source picture. |
| 69 fillRectFiltered(canvas, bounds, pictureSourceSrcRect); | 77 fillRectFiltered(canvas, bounds, pictureSourceSrcRect); |
| 70 canvas->translate(SkIntToScalar(100), 0); | 78 canvas->translate(SkIntToScalar(100), 0); |
| 71 | 79 |
| 72 // Draw the picture to an empty rect (should draw nothing). | 80 // Draw the picture to an empty rect (should draw nothing). |
| 73 fillRectFiltered(canvas, bounds, pictureSourceEmptyRect); | 81 fillRectFiltered(canvas, bounds, pictureSourceEmptyRect); |
| 74 canvas->translate(SkIntToScalar(100), 0); | 82 canvas->translate(SkIntToScalar(100), 0); |
| 83 |
| 84 canvas->restore(); |
| 85 |
| 86 // Draw the picture scaled |
| 87 canvas->translate(0, SkIntToScalar(100)); |
| 88 canvas->scale(200 / srcRect.width(), 200 / srcRect.height()); |
| 89 canvas->translate(-srcRect.fLeft, -srcRect.fTop); |
| 90 fillRectFiltered(canvas, srcRect, pictureSource); |
| 91 |
| 92 // Draw the picture scaled, but rasterized at original resolution |
| 93 canvas->translate(srcRect.width(), 0); |
| 94 fillRectFiltered(canvas, srcRect, pictureSourceResampled); |
| 75 } | 95 } |
| 76 } | 96 } |
| 77 | 97 |
| 78 // SkPictureImageFilter doesn't support serialization yet. | 98 // SkPictureImageFilter doesn't support serialization yet. |
| 79 virtual uint32_t onGetFlags() const SK_OVERRIDE { | 99 virtual uint32_t onGetFlags() const SK_OVERRIDE { |
| 80 return kSkipPicture_Flag | | 100 return kSkipPicture_Flag | |
| 81 kSkipPipe_Flag | | 101 kSkipPipe_Flag | |
| 82 kSkipPipeCrossProcess_Flag | | 102 kSkipPipeCrossProcess_Flag | |
| 83 kSkipTiled_Flag | | 103 kSkipTiled_Flag | |
| 84 kSkipScaledReplay_Flag; | 104 kSkipScaledReplay_Flag; |
| 85 } | 105 } |
| 86 | 106 |
| 87 private: | 107 private: |
| 88 SkAutoTUnref<SkPicture> fPicture; | 108 SkAutoTUnref<SkPicture> fPicture; |
| 89 typedef GM INHERITED; | 109 typedef GM INHERITED; |
| 90 }; | 110 }; |
| 91 | 111 |
| 92 /////////////////////////////////////////////////////////////////////////////// | 112 /////////////////////////////////////////////////////////////////////////////// |
| 93 | 113 |
| 94 DEF_GM( return new PictureImageFilterGM; ) | 114 DEF_GM( return new PictureImageFilterGM; ) |
| OLD | NEW |