1 2 /* 3 * Copyright 2011 Google Inc. 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 #ifndef skiagm_DEFINED 9 #define skiagm_DEFINED 10 11 #include "SkBitmap.h" 12 #include "SkCanvas.h" 13 #include "SkDevice.h" 14 #include "SkPaint.h" 15 #include "SkRefCnt.h" 16 #include "SkSize.h" 17 #include "SkString.h" 18 #include "SkTRegistry.h" 19 20 namespace skiagm { 21 22 static inline SkISize make_isize(int w, int h) { 23 SkISize sz; 24 sz.set(w, h); 25 return sz; 26 } 27 28 class GM { 29 public: 30 GM(); 31 virtual ~GM(); 32 33 enum Flags { 34 kSkipPDF_Flag = 1 << 0, 35 kSkipPicture_Flag = 1 << 1 36 }; 37 38 void draw(SkCanvas*); 39 void drawBackground(SkCanvas*); 40 void drawContent(SkCanvas*); 41 42 SkISize getISize() { return this->onISize(); } 43 const char* shortName(); 44 45 uint32_t getFlags() const { 46 return this->onGetFlags(); 47 } 48 49 SkColor getBGColor() const { return fBGColor; } 50 void setBGColor(SkColor); 51 52 // helper: fill a rect in the specified color based on the 53 // GM's getISize bounds. 54 void drawSizeBounds(SkCanvas*, SkColor); 55 56 protected: 57 virtual void onDraw(SkCanvas*) = 0; 58 virtual void onDrawBackground(SkCanvas*); 59 virtual SkISize onISize() = 0; 60 virtual SkString onShortName() = 0; 61 virtual uint32_t onGetFlags() const { return 0; } 62 63 private: 64 SkString fShortName; 65 SkColor fBGColor; 66 }; 67 68 typedef SkTRegistry<GM*, void*> GMRegistry; 69 } 70 71 #endif 72