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