Home | History | Annotate | Download | only in gm
      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*) { 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             kSkipGPU_Flag           = 1 << 6,
     44         };
     45 
     46         void draw(SkCanvas*);
     47         void drawBackground(SkCanvas*);
     48         void drawContent(SkCanvas*);
     49 
     50         SkISize getISize() { return this->onISize(); }
     51         const char* shortName();
     52 
     53         uint32_t getFlags() const {
     54             return this->onGetFlags();
     55         }
     56 
     57         SkScalar width() {
     58             return SkIntToScalar(this->getISize().width());
     59         }
     60         SkScalar height() {
     61             return SkIntToScalar(this->getISize().height());
     62         }
     63 
     64         // TODO(vandebo) Instead of exposing this, we should run all the GMs
     65         // with and without an initial transform.
     66         // Most GMs will return the identity matrix, but some PDFs tests
     67         // require setting the initial transform.
     68         SkMatrix getInitialTransform() const {
     69             return this->onGetInitialTransform();
     70         }
     71 
     72         SkColor getBGColor() const { return fBGColor; }
     73         void setBGColor(SkColor);
     74 
     75         // helper: fill a rect in the specified color based on the
     76         // GM's getISize bounds.
     77         void drawSizeBounds(SkCanvas*, SkColor);
     78 
     79         static void SetResourcePath(const char* resourcePath) {
     80             gResourcePath = resourcePath;
     81         }
     82 
     83         static SkString& GetResourcePath() {
     84             return gResourcePath;
     85         }
     86 
     87         bool isCanvasDeferred() const { return fCanvasIsDeferred; }
     88         void setCanvasIsDeferred(bool isDeferred) {
     89             fCanvasIsDeferred = isDeferred;
     90         }
     91 
     92     protected:
     93         static SkString gResourcePath;
     94 
     95         virtual void onOnceBeforeDraw() {}
     96         virtual void onDraw(SkCanvas*) = 0;
     97         virtual void onDrawBackground(SkCanvas*);
     98         virtual SkISize onISize() = 0;
     99         virtual SkString onShortName() = 0;
    100         virtual uint32_t onGetFlags() const { return 0; }
    101         virtual SkMatrix onGetInitialTransform() const { return SkMatrix::I(); }
    102 
    103     private:
    104         SkString fShortName;
    105         SkColor  fBGColor;
    106         bool     fCanvasIsDeferred; // work-around problem in srcmode.cpp
    107         bool     fHaveCalledOnceBeforeDraw;
    108     };
    109 
    110     typedef SkTRegistry<GM*, void*> GMRegistry;
    111 }
    112 
    113 #endif
    114