gm.h revision 6adce6783c5d7cbef276d04cc08a2b19789a0156
1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/*
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2011 Google Inc.
4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com *
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
7ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com */
800dae86f5872b60927b28a32b375bc01cd7c61c9reed@android.com#ifndef skiagm_DEFINED
900dae86f5872b60927b28a32b375bc01cd7c61c9reed@android.com#define skiagm_DEFINED
1000dae86f5872b60927b28a32b375bc01cd7c61c9reed@android.com
11d4af56c5f24a7bf0200e20a591d55f8c82fb9627epoger@google.com#include "SkBitmap.h"
121f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com#include "SkBitmapDevice.h"
13dd0ac281e920b01a63789893cc3e7422789658ddreed@android.com#include "SkCanvas.h"
14dd0ac281e920b01a63789893cc3e7422789658ddreed@android.com#include "SkPaint.h"
15dd0ac281e920b01a63789893cc3e7422789658ddreed@android.com#include "SkSize.h"
1600dae86f5872b60927b28a32b375bc01cd7c61c9reed@android.com#include "SkString.h"
1700dae86f5872b60927b28a32b375bc01cd7c61c9reed@android.com#include "SkTRegistry.h"
1800dae86f5872b60927b28a32b375bc01cd7c61c9reed@android.com
1962b50b7bb8395f9bc281a4d0ed20acc4813f1445mtklein@google.com#if SK_SUPPORT_GPU
2062b50b7bb8395f9bc281a4d0ed20acc4813f1445mtklein@google.com#include "GrContext.h"
2162b50b7bb8395f9bc281a4d0ed20acc4813f1445mtklein@google.com#endif
2262b50b7bb8395f9bc281a4d0ed20acc4813f1445mtklein@google.com
234117a24de4c2dedf47db44746f6636ade6e29deareed@google.com#define DEF_GM(code) \
240f0d9b720e1afef91d30c83b379725b8a53fafc8sugoi@google.com    static skiagm::GM*          SK_MACRO_APPEND_LINE(F_)(void*) { code; } \
254117a24de4c2dedf47db44746f6636ade6e29deareed@google.com    static skiagm::GMRegistry   SK_MACRO_APPEND_LINE(R_)(SK_MACRO_APPEND_LINE(F_));
264117a24de4c2dedf47db44746f6636ade6e29deareed@google.com
2700dae86f5872b60927b28a32b375bc01cd7c61c9reed@android.comnamespace skiagm {
28d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
295efdd0cb9cdf4c2017dc6ad70b2503bf04234d9bepoger@google.com    static inline SkISize make_isize(int w, int h) {
305efdd0cb9cdf4c2017dc6ad70b2503bf04234d9bepoger@google.com        SkISize sz;
315efdd0cb9cdf4c2017dc6ad70b2503bf04234d9bepoger@google.com        sz.set(w, h);
325efdd0cb9cdf4c2017dc6ad70b2503bf04234d9bepoger@google.com        return sz;
335efdd0cb9cdf4c2017dc6ad70b2503bf04234d9bepoger@google.com    }
3400dae86f5872b60927b28a32b375bc01cd7c61c9reed@android.com
3500dae86f5872b60927b28a32b375bc01cd7c61c9reed@android.com    class GM {
3600dae86f5872b60927b28a32b375bc01cd7c61c9reed@android.com    public:
3700dae86f5872b60927b28a32b375bc01cd7c61c9reed@android.com        GM();
3800dae86f5872b60927b28a32b375bc01cd7c61c9reed@android.com        virtual ~GM();
39d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
40fbc21172885fe1f028594bc9b181246c71eb106creed@google.com        enum Flags {
41805df1aa1ddba876e6d18f9d2207d04c09415f9dcommit-bot@chromium.org            kSkipPDF_Flag               = 1 << 0,
42805df1aa1ddba876e6d18f9d2207d04c09415f9dcommit-bot@chromium.org            kSkipPicture_Flag           = 1 << 1,
43805df1aa1ddba876e6d18f9d2207d04c09415f9dcommit-bot@chromium.org            kSkipPipe_Flag              = 1 << 2,
44805df1aa1ddba876e6d18f9d2207d04c09415f9dcommit-bot@chromium.org            kSkipPipeCrossProcess_Flag  = 1 << 3,
45805df1aa1ddba876e6d18f9d2207d04c09415f9dcommit-bot@chromium.org            kSkipTiled_Flag             = 1 << 4,
46805df1aa1ddba876e6d18f9d2207d04c09415f9dcommit-bot@chromium.org            kSkip565_Flag               = 1 << 5,
47805df1aa1ddba876e6d18f9d2207d04c09415f9dcommit-bot@chromium.org            kSkipScaledReplay_Flag      = 1 << 6,
48805df1aa1ddba876e6d18f9d2207d04c09415f9dcommit-bot@chromium.org            kSkipGPU_Flag               = 1 << 7,
490dcbece326ce2fa1f9046aa69a21bb99de08714avandebo@chromium.org            kSkipPDFRasterization_Flag  = 1 << 8,
5078a1078f17f4f0ae63415298517262a64f706af6commit-bot@chromium.org
5178a1078f17f4f0ae63415298517262a64f706af6commit-bot@chromium.org            kGPUOnly_Flag               = 1 << 9,
526adce6783c5d7cbef276d04cc08a2b19789a0156commit-bot@chromium.org
536adce6783c5d7cbef276d04cc08a2b19789a0156commit-bot@chromium.org            kAsBench_Flag               = 1 << 10, // Run the GM as a benchmark in the bench tool
54fbc21172885fe1f028594bc9b181246c71eb106creed@google.com        };
55fbc21172885fe1f028594bc9b181246c71eb106creed@google.com
5648dd1a26ec07c5baa04856202e4e7e2a53e4d7e5bsalomon@google.com        void draw(SkCanvas*);
5748dd1a26ec07c5baa04856202e4e7e2a53e4d7e5bsalomon@google.com        void drawBackground(SkCanvas*);
5848dd1a26ec07c5baa04856202e4e7e2a53e4d7e5bsalomon@google.com        void drawContent(SkCanvas*);
59d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com
608570b5c8695052378491b0c61e745d736fe85c8drobertphillips@google.com        SkISize getISize() { return this->onISize(); }
6148dd1a26ec07c5baa04856202e4e7e2a53e4d7e5bsalomon@google.com        const char* shortName();
6200dae86f5872b60927b28a32b375bc01cd7c61c9reed@android.com
63fbc21172885fe1f028594bc9b181246c71eb106creed@google.com        uint32_t getFlags() const {
64fbc21172885fe1f028594bc9b181246c71eb106creed@google.com            return this->onGetFlags();
65fbc21172885fe1f028594bc9b181246c71eb106creed@google.com        }
6679d3cb4ba74651ceaa862005a4244460e4662afdvandebo@chromium.org
67487b5606e2ddaf15d733b7d46fe2bfa2246aa51dreed@google.com        SkScalar width() {
68487b5606e2ddaf15d733b7d46fe2bfa2246aa51dreed@google.com            return SkIntToScalar(this->getISize().width());
69487b5606e2ddaf15d733b7d46fe2bfa2246aa51dreed@google.com        }
70487b5606e2ddaf15d733b7d46fe2bfa2246aa51dreed@google.com        SkScalar height() {
71ab02627ae75f49271837b05c64721eb454d78ce5scroggo@google.com            return SkIntToScalar(this->getISize().height());
72487b5606e2ddaf15d733b7d46fe2bfa2246aa51dreed@google.com        }
73487b5606e2ddaf15d733b7d46fe2bfa2246aa51dreed@google.com
7479d3cb4ba74651ceaa862005a4244460e4662afdvandebo@chromium.org        // TODO(vandebo) Instead of exposing this, we should run all the GMs
7579d3cb4ba74651ceaa862005a4244460e4662afdvandebo@chromium.org        // with and without an initial transform.
7679d3cb4ba74651ceaa862005a4244460e4662afdvandebo@chromium.org        // Most GMs will return the identity matrix, but some PDFs tests
7779d3cb4ba74651ceaa862005a4244460e4662afdvandebo@chromium.org        // require setting the initial transform.
7879d3cb4ba74651ceaa862005a4244460e4662afdvandebo@chromium.org        SkMatrix getInitialTransform() const {
79f4f9df4c193620167dc6f202f1b72245f4a260cdcommit-bot@chromium.org            SkMatrix matrix = fStarterMatrix;
80f4f9df4c193620167dc6f202f1b72245f4a260cdcommit-bot@chromium.org            matrix.preConcat(this->onGetInitialTransform());
81f4f9df4c193620167dc6f202f1b72245f4a260cdcommit-bot@chromium.org            return matrix;
8279d3cb4ba74651ceaa862005a4244460e4662afdvandebo@chromium.org        }
8379d3cb4ba74651ceaa862005a4244460e4662afdvandebo@chromium.org
84b4b49ccc41b717a4274470d73785f9b913d97b59reed@google.com        SkColor getBGColor() const { return fBGColor; }
8548dd1a26ec07c5baa04856202e4e7e2a53e4d7e5bsalomon@google.com        void setBGColor(SkColor);
8630db599c1de70b2832ff9ec05c266a4c9b515d94reed@google.com
872d6ef528e57928160aba6b628b2d84180ced97c3reed@google.com        // helper: fill a rect in the specified color based on the
882d6ef528e57928160aba6b628b2d84180ced97c3reed@google.com        // GM's getISize bounds.
892d6ef528e57928160aba6b628b2d84180ced97c3reed@google.com        void drawSizeBounds(SkCanvas*, SkColor);
902d6ef528e57928160aba6b628b2d84180ced97c3reed@google.com
91d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com        static void SetResourcePath(const char* resourcePath) {
92d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com            gResourcePath = resourcePath;
938570b5c8695052378491b0c61e745d736fe85c8drobertphillips@google.com        }
948570b5c8695052378491b0c61e745d736fe85c8drobertphillips@google.com
952bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com        static SkString& GetResourcePath() {
962bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com            return gResourcePath;
972bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com        }
982bbc2c945bb0ecf18fd6473af74ad1a2f5e727a7scroggo@google.com
99aef73617d1bcede80145a13639668f958a3863d8reed@google.com        bool isCanvasDeferred() const { return fCanvasIsDeferred; }
100aef73617d1bcede80145a13639668f958a3863d8reed@google.com        void setCanvasIsDeferred(bool isDeferred) {
101aef73617d1bcede80145a13639668f958a3863d8reed@google.com            fCanvasIsDeferred = isDeferred;
102aef73617d1bcede80145a13639668f958a3863d8reed@google.com        }
103aef73617d1bcede80145a13639668f958a3863d8reed@google.com
104f4f9df4c193620167dc6f202f1b72245f4a260cdcommit-bot@chromium.org    const SkMatrix& getStarterMatrix() { return fStarterMatrix; }
105f4f9df4c193620167dc6f202f1b72245f4a260cdcommit-bot@chromium.org    void setStarterMatrix(const SkMatrix& matrix) {
106f4f9df4c193620167dc6f202f1b72245f4a260cdcommit-bot@chromium.org        fStarterMatrix = matrix;
107f4f9df4c193620167dc6f202f1b72245f4a260cdcommit-bot@chromium.org    }
108f4f9df4c193620167dc6f202f1b72245f4a260cdcommit-bot@chromium.org
1098570b5c8695052378491b0c61e745d736fe85c8drobertphillips@google.com    protected:
1108570b5c8695052378491b0c61e745d736fe85c8drobertphillips@google.com        static SkString gResourcePath;
1118570b5c8695052378491b0c61e745d736fe85c8drobertphillips@google.com
1127775d66aa0e5958c9ea55ddb8317af4d9b019220reed@google.com        virtual void onOnceBeforeDraw() {}
1138570b5c8695052378491b0c61e745d736fe85c8drobertphillips@google.com        virtual void onDraw(SkCanvas*) = 0;
1148570b5c8695052378491b0c61e745d736fe85c8drobertphillips@google.com        virtual void onDrawBackground(SkCanvas*);
1158570b5c8695052378491b0c61e745d736fe85c8drobertphillips@google.com        virtual SkISize onISize() = 0;
1168015dd83ae37147bb630d4751030868051ad0caereed@android.com        virtual SkString onShortName() = 0;
117fbc21172885fe1f028594bc9b181246c71eb106creed@google.com        virtual uint32_t onGetFlags() const { return 0; }
11879d3cb4ba74651ceaa862005a4244460e4662afdvandebo@chromium.org        virtual SkMatrix onGetInitialTransform() const { return SkMatrix::I(); }
11979d3cb4ba74651ceaa862005a4244460e4662afdvandebo@chromium.org
1208015dd83ae37147bb630d4751030868051ad0caereed@android.com    private:
1218015dd83ae37147bb630d4751030868051ad0caereed@android.com        SkString fShortName;
12248dd1a26ec07c5baa04856202e4e7e2a53e4d7e5bsalomon@google.com        SkColor  fBGColor;
123aef73617d1bcede80145a13639668f958a3863d8reed@google.com        bool     fCanvasIsDeferred; // work-around problem in srcmode.cpp
1247775d66aa0e5958c9ea55ddb8317af4d9b019220reed@google.com        bool     fHaveCalledOnceBeforeDraw;
125f4f9df4c193620167dc6f202f1b72245f4a260cdcommit-bot@chromium.org        SkMatrix fStarterMatrix;
12600dae86f5872b60927b28a32b375bc01cd7c61c9reed@android.com    };
12700dae86f5872b60927b28a32b375bc01cd7c61c9reed@android.com
128bd6343b1d60d2a85e930f33f4b06b4502b3e8caamtklein@google.com    typedef SkTRegistry<GM*(*)(void*)> GMRegistry;
12900dae86f5872b60927b28a32b375bc01cd7c61c9reed@android.com}
13000dae86f5872b60927b28a32b375bc01cd7c61c9reed@android.com
13100dae86f5872b60927b28a32b375bc01cd7c61c9reed@android.com#endif
132