2015-01-14 17:44:02 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm.h"
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
// This GM exercises the use case found in crbug.com/423834.
|
|
|
|
// The following pattern:
|
2015-02-10 16:16:55 +00:00
|
|
|
// save();
|
|
|
|
// clipRect(rect, noAA);
|
|
|
|
// drawRect(bigRect, noAA);
|
|
|
|
// restore();
|
|
|
|
//
|
|
|
|
// drawRect(rect, noAA);
|
2015-01-14 17:44:02 +00:00
|
|
|
// can leave 1 pixel wide remnants of the first rect.
|
|
|
|
class ClipDrawDrawGM : public GM {
|
|
|
|
public:
|
2015-06-15 13:51:08 +00:00
|
|
|
ClipDrawDrawGM() { this->setBGColor(sk_tool_utils::color_to_565(0xFFCCCCCC)); }
|
2015-01-14 17:44:02 +00:00
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override { return SkString("clipdrawdraw"); }
|
2015-01-14 17:44:02 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override { return SkISize::Make(512, 512); }
|
2015-01-14 17:44:02 +00:00
|
|
|
|
2015-02-10 16:16:55 +00:00
|
|
|
static void Draw(SkCanvas* canvas, const SkRect& rect) {
|
2015-01-14 17:44:02 +00:00
|
|
|
SkPaint p;
|
|
|
|
p.setAntiAlias(false);
|
|
|
|
|
2015-02-10 16:16:55 +00:00
|
|
|
const SkRect bigRect = SkRect::MakeWH(600, 600);
|
2015-01-14 17:44:02 +00:00
|
|
|
|
|
|
|
canvas->save();
|
2015-02-10 16:16:55 +00:00
|
|
|
// draw a black rect through the clip
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipRect(rect);
|
|
|
|
canvas->drawRect(bigRect, p);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
// now draw the white rect on top
|
|
|
|
p.setColor(SK_ColorWHITE);
|
|
|
|
canvas->drawRect(rect, p);
|
2015-01-14 17:44:02 +00:00
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2015-02-10 16:16:55 +00:00
|
|
|
// Vertical remnant
|
|
|
|
const SkRect rect1 = SkRect::MakeLTRB(136.5f, 137.5f, 338.5f, 293.5f);
|
|
|
|
|
|
|
|
// Horizontal remnant
|
|
|
|
// 179.488 rounds the right way (i.e., 179), 179.499 rounds the wrong way (i.e., 180)
|
|
|
|
const SkRect rect2 = SkRect::MakeLTRB(207.5f, 179.499f, 530.5f, 429.5f);
|
|
|
|
|
|
|
|
Draw(canvas, rect1);
|
|
|
|
Draw(canvas, rect2);
|
2015-01-14 17:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
DEF_GM(return SkNEW(ClipDrawDrawGM);)
|
|
|
|
|
|
|
|
}
|