2014-09-09 18:33:57 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
2014-09-09 18:33:57 +00:00
|
|
|
|
|
|
|
class ClipStrokeRectGM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
ClipStrokeRectGM() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2014-09-09 18:33:57 +00:00
|
|
|
return SkString("clip_strokerect");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2014-09-09 18:33:57 +00:00
|
|
|
return SkISize::Make(200, 400);
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2014-09-09 18:33:57 +00:00
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorRED);
|
|
|
|
p.setAntiAlias(true);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
p.setStrokeWidth(22);
|
|
|
|
|
|
|
|
SkRect r = SkRect::MakeXYWH(20, 20, 100, 100);
|
|
|
|
// setting the height of this to 19 causes failure
|
|
|
|
SkRect rect = SkRect::MakeXYWH(20, 0, 100, 20);
|
|
|
|
|
|
|
|
canvas->save();
|
2016-09-21 18:15:07 +00:00
|
|
|
canvas->clipRect(rect, true);
|
2014-09-09 18:33:57 +00:00
|
|
|
canvas->drawRect(r, p);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
p.setColor(SK_ColorBLUE);
|
|
|
|
p.setStrokeWidth(2);
|
|
|
|
canvas->drawRect(rect, p);
|
|
|
|
|
|
|
|
p.setColor(SK_ColorRED);
|
|
|
|
p.setAntiAlias(true);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
p.setStrokeWidth(22);
|
|
|
|
|
|
|
|
SkRect r2 = SkRect::MakeXYWH(20, 140, 100, 100);
|
|
|
|
// setting the height of this to 19 causes failure
|
|
|
|
SkRect rect2 = SkRect::MakeXYWH(20, 120, 100, 19);
|
|
|
|
|
|
|
|
canvas->save();
|
2016-09-21 18:15:07 +00:00
|
|
|
canvas->clipRect(rect2, true);
|
2014-09-09 18:33:57 +00:00
|
|
|
canvas->drawRect(r2, p);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
p.setColor(SK_ColorBLUE);
|
|
|
|
p.setStrokeWidth(2);
|
|
|
|
canvas->drawRect(rect2, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = skiagm::GM;
|
2014-09-09 18:33:57 +00:00
|
|
|
};
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_GM(return new ClipStrokeRectGM;)
|