2016-12-12 22:39:55 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2019-05-01 21:28:53 +00:00
|
|
|
|
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"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkPath.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkRRect.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
2020-06-25 20:19:03 +00:00
|
|
|
#include "src/core/SkCanvasPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkClipOpPriv.h"
|
2016-12-12 22:39:55 +00:00
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
2020-06-25 20:19:03 +00:00
|
|
|
// This test exercise SkCanvas::androidFramework_replaceClip behavior
|
2016-12-12 22:39:55 +00:00
|
|
|
class ComplexClip4GM : public GM {
|
|
|
|
public:
|
|
|
|
ComplexClip4GM(bool aaclip)
|
|
|
|
: fDoAAClip(aaclip) {
|
|
|
|
this->setBGColor(0xFFDEDFDE);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2020-07-21 21:03:56 +00:00
|
|
|
SkString onShortName() override {
|
2016-12-12 22:39:55 +00:00
|
|
|
SkString str;
|
|
|
|
str.printf("complexclip4_%s",
|
|
|
|
fDoAAClip ? "aa" : "bw");
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2020-07-21 21:03:56 +00:00
|
|
|
SkISize onISize() override { return SkISize::Make(970, 780); }
|
2016-12-12 22:39:55 +00:00
|
|
|
|
2020-06-25 20:19:03 +00:00
|
|
|
// Android Framework will still support the legacy kReplace SkClipOp on older devices, so
|
|
|
|
// this represents how to do so while also respecting the device restriction using the newer
|
|
|
|
// androidFramework_replaceClip() API.
|
|
|
|
void emulateDeviceRestriction(SkCanvas* canvas, const SkIRect& deviceRestriction) {
|
|
|
|
// or any other device-space rect intersection
|
|
|
|
SkCanvasPriv::ReplaceClip(canvas, deviceRestriction);
|
|
|
|
// save for later replace clip ops
|
|
|
|
fDeviceRestriction = deviceRestriction;
|
|
|
|
}
|
|
|
|
|
|
|
|
void emulateClipRectReplace(SkCanvas* canvas,
|
|
|
|
const SkRect& clipRect,
|
|
|
|
bool aa) {
|
|
|
|
SkCanvasPriv::ReplaceClip(canvas, fDeviceRestriction);
|
|
|
|
canvas->clipRect(clipRect, SkClipOp::kIntersect, aa);
|
|
|
|
}
|
|
|
|
|
|
|
|
void emulateClipRRectReplace(SkCanvas* canvas,
|
|
|
|
const SkRRect& clipRRect,
|
|
|
|
bool aa) {
|
|
|
|
SkCanvasPriv::ReplaceClip(canvas, fDeviceRestriction);
|
|
|
|
canvas->clipRRect(clipRRect, SkClipOp::kIntersect, aa);
|
|
|
|
}
|
|
|
|
|
|
|
|
void emulateClipPathReplace(SkCanvas* canvas,
|
|
|
|
const SkPath& path,
|
|
|
|
bool aa) {
|
|
|
|
SkCanvasPriv::ReplaceClip(canvas, fDeviceRestriction);
|
|
|
|
canvas->clipPath(path, SkClipOp::kIntersect, aa);
|
|
|
|
}
|
|
|
|
|
2020-07-21 21:03:56 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2016-12-12 22:39:55 +00:00
|
|
|
SkPaint p;
|
|
|
|
p.setAntiAlias(fDoAAClip);
|
|
|
|
p.setColor(SK_ColorYELLOW);
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
// draw a yellow rect through a rect clip
|
|
|
|
canvas->save();
|
2020-06-25 20:19:03 +00:00
|
|
|
emulateDeviceRestriction(canvas, SkIRect::MakeLTRB(100, 100, 300, 300));
|
2016-12-12 22:39:55 +00:00
|
|
|
canvas->drawColor(SK_ColorGREEN);
|
2020-06-25 20:19:03 +00:00
|
|
|
emulateClipRectReplace(canvas, SkRect::MakeLTRB(100, 200, 400, 500), fDoAAClip);
|
2016-12-12 22:39:55 +00:00
|
|
|
canvas->drawRect(SkRect::MakeLTRB(100, 200, 400, 500), p);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
// draw a yellow rect through a diamond clip
|
|
|
|
canvas->save();
|
2020-06-25 20:19:03 +00:00
|
|
|
emulateDeviceRestriction(canvas, SkIRect::MakeLTRB(500, 100, 800, 300));
|
2016-12-12 22:39:55 +00:00
|
|
|
canvas->drawColor(SK_ColorGREEN);
|
|
|
|
|
2020-08-17 18:14:13 +00:00
|
|
|
SkPath pathClip = SkPath::Polygon({
|
|
|
|
{650, 200},
|
|
|
|
{900, 300},
|
|
|
|
{650, 400},
|
|
|
|
{650, 300},
|
|
|
|
}, true);
|
2020-06-25 20:19:03 +00:00
|
|
|
emulateClipPathReplace(canvas, pathClip, fDoAAClip);
|
2016-12-12 22:39:55 +00:00
|
|
|
canvas->drawRect(SkRect::MakeLTRB(500, 200, 900, 500), p);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
// draw a yellow rect through a round rect clip
|
|
|
|
canvas->save();
|
2020-06-25 20:19:03 +00:00
|
|
|
emulateDeviceRestriction(canvas, SkIRect::MakeLTRB(500, 500, 800, 700));
|
2016-12-12 22:39:55 +00:00
|
|
|
canvas->drawColor(SK_ColorGREEN);
|
|
|
|
|
2020-06-25 20:19:03 +00:00
|
|
|
emulateClipRRectReplace(
|
|
|
|
canvas, SkRRect::MakeOval(SkRect::MakeLTRB(500, 600, 900, 750)), fDoAAClip);
|
2016-12-12 22:39:55 +00:00
|
|
|
canvas->drawRect(SkRect::MakeLTRB(500, 600, 900, 750), p);
|
|
|
|
canvas->restore();
|
|
|
|
|
2020-06-25 20:19:03 +00:00
|
|
|
// fill the clip with yellow color showing that androidFramework_replaceClip is
|
|
|
|
// in device space
|
2016-12-12 22:39:55 +00:00
|
|
|
canvas->save();
|
|
|
|
canvas->clipRect(SkRect::MakeLTRB(100, 400, 300, 750),
|
|
|
|
kIntersect_SkClipOp, fDoAAClip);
|
|
|
|
canvas->drawColor(SK_ColorGREEN);
|
2020-06-25 20:19:03 +00:00
|
|
|
// should not affect the device-space clip
|
|
|
|
canvas->rotate(20.f);
|
|
|
|
canvas->translate(50.f, 50.f);
|
|
|
|
emulateDeviceRestriction(canvas, SkIRect::MakeLTRB(150, 450, 250, 700));
|
2016-12-12 22:39:55 +00:00
|
|
|
canvas->drawColor(SK_ColorYELLOW);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
private:
|
2020-06-25 20:19:03 +00:00
|
|
|
SkIRect fDeviceRestriction;
|
|
|
|
bool fDoAAClip;
|
2016-12-12 22:39:55 +00:00
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GM;
|
2016-12-12 22:39:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
DEF_GM(return new ComplexClip4GM(false);)
|
|
|
|
DEF_GM(return new ComplexClip4GM(true);)
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace skiagm
|