Home | History | Annotate | Download | only in gm
      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.h"
      9 
     10 // Draws big rects with clip (0, 0, 35, 35). The size of the rects is given by big.
     11 static void draw_big_rect(SkCanvas* canvas, SkScalar big, const SkPaint& rectPaint) {
     12     // Looks like this:
     13     // +--+-+----+-+----+
     14     // |  | |    | |    |
     15     // |--+-+----+-+----+
     16     // |--+-+----+-+----+
     17     // |  | |    | |    |
     18     // |  | |    +-+    |
     19     // +--+-+--+     +--+
     20     // +--+-+--+     +--+
     21     // |  | |    +-+    |
     22     // |  | |    | |    |
     23     // +--+-+----+-+----+
     24 
     25     canvas->clipRect({0, 0, 35, 35});
     26 
     27     // Align to pixel boundaries.
     28     canvas->translate(0.5, 0.5);
     29 
     30     SkRect horiz = SkRect::MakeLTRB(-big, 5, big, 10);
     31     canvas->drawRect(horiz, rectPaint);
     32 
     33     SkRect vert = SkRect::MakeLTRB(5, -big, 10, big);
     34     canvas->drawRect(vert, rectPaint);
     35 
     36     SkRect fromLeft = SkRect::MakeLTRB(-big, 20, 17, 25);
     37     canvas->drawRect(fromLeft, rectPaint);
     38 
     39     SkRect fromTop = SkRect::MakeLTRB(20, -big, 25, 17);
     40     canvas->drawRect(fromTop, rectPaint);
     41 
     42     SkRect fromRight = SkRect::MakeLTRB(28, 20, big, 25);
     43     canvas->drawRect(fromRight, rectPaint);
     44 
     45     SkRect fromBottom = SkRect::MakeLTRB(20, 28, 25, big);
     46     canvas->drawRect(fromBottom, rectPaint);
     47 
     48     SkRect leftBorder = SkRect::MakeLTRB(-2, -1, 0, 35);
     49     canvas->drawRect(leftBorder, rectPaint);
     50 
     51     SkRect topBorder = SkRect::MakeLTRB(-1, -2, 35, 0);
     52     canvas->drawRect(topBorder, rectPaint);
     53 
     54     SkRect rightBorder = SkRect::MakeLTRB(34, -1, 36, 35);
     55     canvas->drawRect(rightBorder, rectPaint);
     56 
     57     SkRect bottomBorder = SkRect::MakeLTRB(-1, 34, 35, 36);
     58     canvas->drawRect(bottomBorder, rectPaint);
     59 
     60     SkPaint outOfBoundsPaint;
     61     outOfBoundsPaint.setColor(SK_ColorRED);
     62     outOfBoundsPaint.setStyle(SkPaint::kStroke_Style);
     63     outOfBoundsPaint.setStrokeWidth(0);
     64 
     65     SkRect outOfBounds = SkRect::MakeLTRB(-1, -1, 35, 35);
     66     canvas->drawRect(outOfBounds, outOfBoundsPaint);
     67 }
     68 
     69 DEF_SIMPLE_GM(bigrect, canvas, 325, 125) {
     70     // Test with sizes:
     71     //   - reasonable size (for comparison),
     72     //   - outside the range of int32, and
     73     //   - outside the range of SkFixed.
     74     static const SkScalar sizes[] = {SkIntToScalar(100), 5e10f, 1e6f};
     75 
     76     for (int i = 0; i < 8; i++) {
     77         for (int j = 0; j < 3; j++) {
     78             canvas->save();
     79             canvas->translate(SkIntToScalar(i*40+5), SkIntToScalar(j*40+5));
     80 
     81             SkPaint paint;
     82             paint.setColor(SK_ColorBLUE);
     83             // These are the three parameters that affect the behavior of SkDraw::drawRect.
     84             if (i & 1) {
     85                 paint.setStyle(SkPaint::kFill_Style);
     86             } else {
     87                 paint.setStyle(SkPaint::kStroke_Style);
     88             }
     89             if (i & 2) {
     90                 paint.setStrokeWidth(1);
     91             } else {
     92                 paint.setStrokeWidth(0);
     93             }
     94             if (i & 4) {
     95                 paint.setAntiAlias(true);
     96             } else {
     97                 paint.setAntiAlias(false);
     98             }
     99 
    100             const SkScalar big = SkFloatToScalar(sizes[j]);
    101             draw_big_rect(canvas, big, paint);
    102             canvas->restore();
    103         }
    104     }
    105 }
    106