Home | History | Annotate | Download | only in gm
      1 /*
      2  * Copyright 2014 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 // This GM exercises the use case found in crbug.com/423834.
     11 // The following pattern:
     12 //    save();
     13 //    clipRect(rect, noAA);
     14 //    drawRect(bigRect, noAA);
     15 //    restore();
     16 //
     17 //    drawRect(rect, noAA);
     18 // can leave 1 pixel wide remnants of the first rect.
     19 static void Draw(SkCanvas* canvas, const SkRect& rect) {
     20         SkPaint p;
     21         p.setAntiAlias(false);
     22 
     23         const SkRect bigRect = SkRect::MakeWH(600, 600);
     24 
     25         canvas->save();
     26             // draw a black rect through the clip
     27             canvas->save();
     28                 canvas->clipRect(rect);
     29                 canvas->drawRect(bigRect, p);
     30             canvas->restore();
     31 
     32             // now draw the white rect on top
     33             p.setColor(SK_ColorWHITE);
     34             canvas->drawRect(rect, p);
     35         canvas->restore();
     36 }
     37 
     38 DEF_SIMPLE_GM_BG(clipdrawdraw, canvas, 512, 512,
     39                  sk_tool_utils::color_to_565(0xFFCCCCCC)) {
     40         // Vertical remnant
     41         const SkRect rect1 = SkRect::MakeLTRB(136.5f, 137.5f, 338.5f, 293.5f);
     42 
     43         // Horizontal remnant
     44         // 179.488 rounds the right way (i.e., 179), 179.499 rounds the wrong way (i.e., 180)
     45         const SkRect rect2 = SkRect::MakeLTRB(207.5f, 179.499f, 530.5f, 429.5f);
     46 
     47         Draw(canvas, rect1);
     48         Draw(canvas, rect2);
     49 }
     50