1 /* 2 * Copyright 2016 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "gm/gm.h" 9 #include "include/core/SkCanvas.h" 10 #include "include/core/SkPaint.h" 11 #include "include/core/SkRect.h" 12 #include "include/core/SkScalar.h" 13 #include "include/core/SkSize.h" 14 #include "include/core/SkString.h" 15 #include "include/utils/SkRandom.h" 16 #include "tools/ToolUtils.h" 17 18 class SimpleRectGM : public skiagm::GM { 19 public: SimpleRectGM()20 SimpleRectGM() {} 21 22 protected: onShortName()23 SkString onShortName() override { 24 SkString name; 25 name.printf("simplerect"); 26 return name; 27 } 28 onISize()29 SkISize onISize() override { 30 return SkISize::Make(800, 800); 31 } 32 onDraw(SkCanvas * canvas)33 void onDraw(SkCanvas* canvas) override { 34 canvas->translate(1, 1); // want to exercise non-identity ctm performance 35 36 const SkScalar min = -20; 37 const SkScalar max = 800; 38 const SkScalar size = 20; 39 40 SkRandom rand; 41 SkPaint paint; 42 for (int i = 0; i < 10000; i++) { 43 paint.setColor(ToolUtils::color_to_565(rand.nextU() | (0xFF << 24))); 44 SkScalar x = rand.nextRangeScalar(min, max); 45 SkScalar y = rand.nextRangeScalar(min, max); 46 SkScalar w = rand.nextRangeScalar(0, size); 47 SkScalar h = rand.nextRangeScalar(0, size); 48 canvas->drawRect(SkRect::MakeXYWH(x, y, w, h), paint); 49 } 50 } 51 onAnimate(double nanos)52 bool onAnimate(double nanos) override { return true; } 53 54 private: 55 56 using INHERITED = GM; 57 }; 58 DEF_GM(return new SimpleRectGM;) 59