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 "SkSize.h" 16 #include "SkString.h" 17 #include "SkTRegistry.h" 18 19 #define DEF_GM(code) \ 20 static skiagm::GM* SK_MACRO_APPEND_LINE(F_)(void* p) { code; } \ 21 static skiagm::GMRegistry SK_MACRO_APPEND_LINE(R_)(SK_MACRO_APPEND_LINE(F_)); 22 23 namespace skiagm { 24 25 static inline SkISize make_isize(int w, int h) { 26 SkISize sz; 27 sz.set(w, h); 28 return sz; 29 } 30 31 class GM { 32 public: 33 GM(); 34 virtual ~GM(); 35 36 enum Flags { 37 kSkipPDF_Flag = 1 << 0, 38 kSkipPicture_Flag = 1 << 1, 39 kSkipPipe_Flag = 1 << 2, 40 kSkipTiled_Flag = 1 << 3, 41 kSkip565_Flag = 1 << 4, 42 kSkipScaledReplay_Flag = 1 << 5, 43 }; 44 45 void draw(SkCanvas*); 46 void drawBackground(SkCanvas*); 47 void drawContent(SkCanvas*); 48 49 SkISize getISize() { return this->onISize(); } 50 const char* shortName(); 51 52 uint32_t getFlags() const { 53 return this->onGetFlags(); 54 } 55 56 SkScalar width() { 57 return SkIntToScalar(this->getISize().width()); 58 } 59 SkScalar height() { 60 return SkIntToScalar(this->getISize().width()); 61 } 62 63 // TODO(vandebo) Instead of exposing this, we should run all the GMs 64 // with and without an initial transform. 65 // Most GMs will return the identity matrix, but some PDFs tests 66 // require setting the initial transform. 67 SkMatrix getInitialTransform() const { 68 return this->onGetInitialTransform(); 69 } 70 71 SkColor getBGColor() const { return fBGColor; } 72 void setBGColor(SkColor); 73 74 // helper: fill a rect in the specified color based on the 75 // GM's getISize bounds. 76 void drawSizeBounds(SkCanvas*, SkColor); 77 78 static void SetResourcePath(const char* resourcePath) { 79 gResourcePath = resourcePath; 80 } 81 82 bool isCanvasDeferred() const { return fCanvasIsDeferred; } 83 void setCanvasIsDeferred(bool isDeferred) { 84 fCanvasIsDeferred = isDeferred; 85 } 86 87 protected: 88 static SkString gResourcePath; 89 90 virtual void onOnceBeforeDraw() {} 91 virtual void onDraw(SkCanvas*) = 0; 92 virtual void onDrawBackground(SkCanvas*); 93 virtual SkISize onISize() = 0; 94 virtual SkString onShortName() = 0; 95 virtual uint32_t onGetFlags() const { return 0; } 96 virtual SkMatrix onGetInitialTransform() const { return SkMatrix::I(); } 97 98 private: 99 SkString fShortName; 100 SkColor fBGColor; 101 bool fCanvasIsDeferred; // work-around problem in srcmode.cpp 102 bool fHaveCalledOnceBeforeDraw; 103 }; 104 105 typedef SkTRegistry<GM*, void*> GMRegistry; 106 } 107 108 #endif 109