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 "SkPaint.h" 10#include "SkPictureRecorder.h" 11 12static SkPicture* make_picture() { 13 SkPictureRecorder rec; 14 SkCanvas* canvas = rec.beginRecording(100, 100); 15 16 SkPaint paint; 17 paint.setAntiAlias(true); 18 SkPath path; 19 20 paint.setColor(0x800000FF); 21 canvas->drawRect(SkRect::MakeWH(100, 100), paint); 22 23 paint.setColor(0x80FF0000); 24 path.moveTo(0, 0); path.lineTo(100, 0); path.lineTo(100, 100); 25 canvas->drawPath(path, paint); 26 27 paint.setColor(0x8000FF00); 28 path.reset(); path.moveTo(0, 0); path.lineTo(100, 0); path.lineTo(0, 100); 29 canvas->drawPath(path, paint); 30 31 paint.setColor(0x80FFFFFF); 32 paint.setXfermodeMode(SkXfermode::kPlus_Mode); 33 canvas->drawRect(SkRect::MakeXYWH(25, 25, 50, 50), paint); 34 35 return rec.endRecording(); 36} 37 38// Exercise the optional arguments to drawPicture 39// 40class PictureGM : public skiagm::GM { 41public: 42 PictureGM() : fPicture(make_picture()) {} 43 44protected: 45 virtual SkString onShortName() SK_OVERRIDE { 46 return SkString("pictures"); 47 } 48 49 virtual SkISize onISize() SK_OVERRIDE { 50 return SkISize::Make(450, 120); 51 } 52 53 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 54 canvas->translate(10, 10); 55 56 SkMatrix matrix; 57 SkPaint paint; 58 59 canvas->drawPicture(fPicture); 60 61 matrix.setTranslate(110, 0); 62 canvas->drawPicture(fPicture, &matrix, NULL); 63 64 matrix.postTranslate(110, 0); 65 canvas->drawPicture(fPicture, &matrix, &paint); 66 67 paint.setAlpha(0x80); 68 matrix.postTranslate(110, 0); 69 canvas->drawPicture(fPicture, &matrix, &paint); 70 } 71 72private: 73 SkAutoTUnref<SkPicture> fPicture; 74 75 typedef skiagm::GM INHERITED; 76}; 77 78DEF_GM( return SkNEW(PictureGM); ) 79