1c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org/*
2c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org * Copyright 2013 Google Inc.
3c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org *
4c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org * Use of this source code is governed by a BSD-style license that can be
5c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org * found in the LICENSE file.
6c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org */
7c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org
8c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org/**
9c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org * Pathologically simple drawing tests, designed to generate consistent
10c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org * output images across platforms for gm/tests/run.sh
11c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org */
12c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org
13c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org#include "gm.h"
14c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org#include "SkCanvas.h"
15c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org#include "SkPaint.h"
16c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org
17c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.orgclass SelfTestGM : public skiagm::GM {
18c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.orgpublic:
19c8263e704135436f71a585801966294d6deadeebepoger@google.com    SelfTestGM(const char name[], SkColor color, uint32_t flags) :
20c8263e704135436f71a585801966294d6deadeebepoger@google.com        fName(name), fColor(color), fFlags(flags) {}
21c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org    const static int kWidth = 300;
22c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org    const static int kHeight = 200;
23c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org
24c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.orgprotected:
25c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org    SkString onShortName() {
26c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org        return fName;
27c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org    }
28c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org
29f539318f0d3dba743ec1886d5d9df0fb1be628a1tfarina    SkISize onISize() { return SkISize::Make(kWidth, kHeight); }
30c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org
31c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org    virtual void onDraw(SkCanvas* canvas) {
32c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org        SkPaint paint;
33c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org        paint.setStyle(SkPaint::kFill_Style);
34c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org        paint.setColor(fColor);
35c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org        canvas->drawRectCoords(0, 0, SkIntToScalar(kWidth), SkIntToScalar(kHeight), paint);
36c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org    }
37c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org
38c8263e704135436f71a585801966294d6deadeebepoger@google.com    virtual uint32_t onGetFlags() const { return fFlags; }
39c8263e704135436f71a585801966294d6deadeebepoger@google.com
40c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.orgprivate:
41c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org    const SkString fName;
42c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org    const SkColor fColor;
43c8263e704135436f71a585801966294d6deadeebepoger@google.com    const uint32_t fFlags;
44c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org};
45c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org
46c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org//////////////////////////////////////////////////////////////////////////////
47c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org
48b9ba1eadc839fb346a5bcf5f7a38b775e1069586epoger@google.com// We use translucent colors to make sure we are properly handling cases like
49b9ba1eadc839fb346a5bcf5f7a38b775e1069586epoger@google.com// those which caused https://code.google.com/p/skia/issues/detail?id=1079
50b9ba1eadc839fb346a5bcf5f7a38b775e1069586epoger@google.com// ('gm generating spurious pixel_error messages as of r7258')
51b9ba1eadc839fb346a5bcf5f7a38b775e1069586epoger@google.comstatic SkColor kTranslucentGreen = 0x7700EE00;
52b9ba1eadc839fb346a5bcf5f7a38b775e1069586epoger@google.comstatic SkColor kTranslucentBlue  = 0x770000DD;
53b9ba1eadc839fb346a5bcf5f7a38b775e1069586epoger@google.com
54c8263e704135436f71a585801966294d6deadeebepoger@google.comstatic skiagm::GM* F1(void*) {
55c8263e704135436f71a585801966294d6deadeebepoger@google.com    return new SelfTestGM("selftest1", kTranslucentGreen, 0);
56c8263e704135436f71a585801966294d6deadeebepoger@google.com}
57c8263e704135436f71a585801966294d6deadeebepoger@google.comstatic skiagm::GM* F2(void*) {
58c8263e704135436f71a585801966294d6deadeebepoger@google.com    return new SelfTestGM("selftest2", kTranslucentBlue,  skiagm::GM::kSkipPipe_Flag);
59c8263e704135436f71a585801966294d6deadeebepoger@google.com}
60c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.org
61c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.orgstatic skiagm::GMRegistry gR1(F1);
62c61c3c310185f6ffaefce194a079159423945191commit-bot@chromium.orgstatic skiagm::GMRegistry gR2(F2);
63