| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkBitmapSource.h" | |
| 10 #include "SkBlurImageFilter.h" | 9 #include "SkBlurImageFilter.h" |
| 11 #include "SkDropShadowImageFilter.h" | 10 #include "SkDropShadowImageFilter.h" |
| 11 #include "SkImageSource.h" |
| 12 #include "SkOffsetImageFilter.h" | 12 #include "SkOffsetImageFilter.h" |
| 13 #include "SkPictureImageFilter.h" | 13 #include "SkPictureImageFilter.h" |
| 14 #include "SkPictureRecorder.h" | 14 #include "SkPictureRecorder.h" |
| 15 #include "SkRandom.h" | 15 #include "SkRandom.h" |
| 16 #include "SkSurface.h" |
| 16 | 17 |
| 17 namespace skiagm { | 18 namespace skiagm { |
| 18 | 19 |
| 19 // Each method of this type must draw its geometry inside 'r' using 'p' | 20 // Each method of this type must draw its geometry inside 'r' using 'p' |
| 20 typedef void(*drawMth)(SkCanvas* canvas, const SkRect& r, const SkPaint& p); | 21 typedef void(*drawMth)(SkCanvas* canvas, const SkRect& r, const SkPaint& p); |
| 21 | 22 |
| 22 static void draw_rect(SkCanvas* canvas, const SkRect& r, const SkPaint& p) { | 23 static void draw_rect(SkCanvas* canvas, const SkRect& r, const SkPaint& p) { |
| 23 canvas->drawRect(r, p); | 24 canvas->drawRect(r, p); |
| 24 } | 25 } |
| 25 | 26 |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 c->drawRect(SkRect::MakeWH(10, 10), blackFill); | 245 c->drawRect(SkRect::MakeWH(10, 10), blackFill); |
| 245 pic.reset(rec.endRecording()); | 246 pic.reset(rec.endRecording()); |
| 246 } | 247 } |
| 247 | 248 |
| 248 SkAutoTUnref<SkPictureImageFilter> pif(SkPictureImageFilter::Create(pic)
); | 249 SkAutoTUnref<SkPictureImageFilter> pif(SkPictureImageFilter::Create(pic)
); |
| 249 | 250 |
| 250 SkTArray<SkPaint> pifPaints; | 251 SkTArray<SkPaint> pifPaints; |
| 251 create_paints(pif, &pifPaints); | 252 create_paints(pif, &pifPaints); |
| 252 | 253 |
| 253 //----------- | 254 //----------- |
| 254 // Paints with a BitmapSource as a source | 255 // Paints with a SkImageSource as a source |
| 255 SkBitmap bm; | |
| 256 | 256 |
| 257 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(10, 10)); |
| 257 { | 258 { |
| 258 SkPaint p; | 259 SkPaint p; |
| 259 bm.allocN32Pixels(10, 10); | 260 SkCanvas* temp = surface->getCanvas(); |
| 260 SkCanvas temp(bm); | 261 temp->clear(SK_ColorYELLOW); |
| 261 temp.clear(SK_ColorYELLOW); | |
| 262 p.setColor(SK_ColorBLUE); | 262 p.setColor(SK_ColorBLUE); |
| 263 temp.drawRect(SkRect::MakeLTRB(5, 5, 10, 10), p); | 263 temp->drawRect(SkRect::MakeLTRB(5, 5, 10, 10), p); |
| 264 p.setColor(SK_ColorGREEN); | 264 p.setColor(SK_ColorGREEN); |
| 265 temp.drawRect(SkRect::MakeLTRB(5, 0, 10, 5), p); | 265 temp->drawRect(SkRect::MakeLTRB(5, 0, 10, 5), p); |
| 266 } | 266 } |
| 267 | 267 |
| 268 SkAutoTUnref<SkBitmapSource> bms(SkBitmapSource::Create(bm)); | 268 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); |
| 269 SkAutoTUnref<SkImageFilter> imageSource(SkImageSource::Create(image)); |
| 269 | 270 |
| 270 SkTArray<SkPaint> bmsPaints; | 271 SkTArray<SkPaint> bmsPaints; |
| 271 create_paints(bms, &bmsPaints); | 272 create_paints(imageSource, &bmsPaints); |
| 272 | 273 |
| 273 //----------- | 274 //----------- |
| 274 SkASSERT(paints.count() == kNumVertTiles); | 275 SkASSERT(paints.count() == kNumVertTiles); |
| 275 SkASSERT(paints.count() == pifPaints.count()); | 276 SkASSERT(paints.count() == pifPaints.count()); |
| 276 SkASSERT(paints.count() == bmsPaints.count()); | 277 SkASSERT(paints.count() == bmsPaints.count()); |
| 277 | 278 |
| 278 // horizontal separators | 279 // horizontal separators |
| 279 for (int i = 1; i < paints.count(); ++i) { | 280 for (int i = 1; i < paints.count(); ++i) { |
| 280 canvas->drawLine(0, | 281 canvas->drawLine(0, |
| 281 i*SkIntToScalar(kTileHeight), | 282 i*SkIntToScalar(kTileHeight), |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 } | 317 } |
| 317 | 318 |
| 318 private: | 319 private: |
| 319 typedef GM INHERITED; | 320 typedef GM INHERITED; |
| 320 }; | 321 }; |
| 321 | 322 |
| 322 ////////////////////////////////////////////////////////////////////////////// | 323 ////////////////////////////////////////////////////////////////////////////// |
| 323 | 324 |
| 324 DEF_GM(return new ImageFilterFastBoundGM;) | 325 DEF_GM(return new ImageFilterFastBoundGM;) |
| 325 } | 326 } |
| OLD | NEW |