2011-12-21 14:27:14 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkPath.h"
|
|
|
|
|
|
|
|
/** Draw a 2px border around the target, then red behind the target;
|
|
|
|
set the clip to match the target, then draw >> the target in blue.
|
|
|
|
*/
|
|
|
|
|
2014-02-13 17:14:46 +00:00
|
|
|
static void draw(SkCanvas* canvas, SkRect& target, int x, int y) {
|
2011-12-21 14:27:14 +00:00
|
|
|
SkPaint borderPaint;
|
|
|
|
borderPaint.setColor(SkColorSetRGB(0x0, 0xDD, 0x0));
|
|
|
|
borderPaint.setAntiAlias(true);
|
|
|
|
SkPaint backgroundPaint;
|
|
|
|
backgroundPaint.setColor(SkColorSetRGB(0xDD, 0x0, 0x0));
|
|
|
|
backgroundPaint.setAntiAlias(true);
|
|
|
|
SkPaint foregroundPaint;
|
|
|
|
foregroundPaint.setColor(SkColorSetRGB(0x0, 0x0, 0xDD));
|
|
|
|
foregroundPaint.setAntiAlias(true);
|
|
|
|
|
|
|
|
canvas->save();
|
2011-12-28 19:40:48 +00:00
|
|
|
canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
|
|
|
|
target.inset(SkIntToScalar(-2), SkIntToScalar(-2));
|
2011-12-21 14:27:14 +00:00
|
|
|
canvas->drawRect(target, borderPaint);
|
2011-12-28 19:40:48 +00:00
|
|
|
target.inset(SkIntToScalar(2), SkIntToScalar(2));
|
2011-12-21 14:27:14 +00:00
|
|
|
canvas->drawRect(target, backgroundPaint);
|
|
|
|
canvas->clipRect(target, SkRegion::kIntersect_Op, true);
|
2011-12-28 19:40:48 +00:00
|
|
|
target.inset(SkIntToScalar(-4), SkIntToScalar(-4));
|
2011-12-21 14:27:14 +00:00
|
|
|
canvas->drawRect(target, foregroundPaint);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
2014-02-13 17:14:46 +00:00
|
|
|
static void draw_square(SkCanvas* canvas, int x, int y) {
|
2011-12-21 14:27:14 +00:00
|
|
|
SkRect target (SkRect::MakeWH(10 * SK_Scalar1, 10 * SK_Scalar1));
|
|
|
|
draw(canvas, target, x, y);
|
|
|
|
}
|
|
|
|
|
2014-02-13 17:14:46 +00:00
|
|
|
static void draw_column(SkCanvas* canvas, int x, int y) {
|
2011-12-21 14:27:14 +00:00
|
|
|
SkRect target (SkRect::MakeWH(1 * SK_Scalar1, 10 * SK_Scalar1));
|
|
|
|
draw(canvas, target, x, y);
|
|
|
|
}
|
|
|
|
|
2014-02-13 17:14:46 +00:00
|
|
|
static void draw_bar(SkCanvas* canvas, int x, int y) {
|
2011-12-21 14:27:14 +00:00
|
|
|
SkRect target (SkRect::MakeWH(10 * SK_Scalar1, 1 * SK_Scalar1));
|
|
|
|
draw(canvas, target, x, y);
|
|
|
|
}
|
|
|
|
|
2014-02-13 17:14:46 +00:00
|
|
|
static void draw_rect_tests(SkCanvas* canvas) {
|
2011-12-21 14:27:14 +00:00
|
|
|
draw_square(canvas, 10, 10);
|
|
|
|
draw_column(canvas, 30, 10);
|
|
|
|
draw_bar(canvas, 10, 30);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Test a set of clipping problems discovered while writing blitAntiRect,
|
|
|
|
and test all the code paths through the clipping blitters.
|
|
|
|
Each region should show as a blue center surrounded by a 2px green
|
|
|
|
border, with no red.
|
|
|
|
*/
|
|
|
|
|
2013-05-23 17:04:19 +00:00
|
|
|
class AAClipGM : public skiagm::GM {
|
2011-12-21 14:27:14 +00:00
|
|
|
public:
|
|
|
|
AAClipGM() {
|
2012-09-18 15:14:33 +00:00
|
|
|
|
2011-12-21 14:27:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2013-05-23 17:04:19 +00:00
|
|
|
virtual SkString onShortName() SK_OVERRIDE {
|
2011-12-21 14:27:14 +00:00
|
|
|
return SkString("aaclip");
|
|
|
|
}
|
|
|
|
|
2013-05-23 17:04:19 +00:00
|
|
|
virtual SkISize onISize() SK_OVERRIDE {
|
|
|
|
return SkISize::Make(640, 480);
|
2011-12-21 14:27:14 +00:00
|
|
|
}
|
|
|
|
|
2013-01-28 16:57:29 +00:00
|
|
|
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
2011-12-21 14:27:14 +00:00
|
|
|
// Initial pixel-boundary-aligned draw
|
|
|
|
draw_rect_tests(canvas);
|
|
|
|
|
|
|
|
// Repeat 4x with .2, .4, .6, .8 px offsets
|
|
|
|
canvas->translate(SK_Scalar1 / 5, SK_Scalar1 / 5);
|
2011-12-28 19:40:48 +00:00
|
|
|
canvas->translate(SkIntToScalar(50), 0);
|
2011-12-21 14:27:14 +00:00
|
|
|
draw_rect_tests(canvas);
|
|
|
|
|
|
|
|
canvas->translate(SK_Scalar1 / 5, SK_Scalar1 / 5);
|
2011-12-28 19:40:48 +00:00
|
|
|
canvas->translate(SkIntToScalar(50), 0);
|
2011-12-21 14:27:14 +00:00
|
|
|
draw_rect_tests(canvas);
|
|
|
|
|
|
|
|
canvas->translate(SK_Scalar1 / 5, SK_Scalar1 / 5);
|
2011-12-28 19:40:48 +00:00
|
|
|
canvas->translate(SkIntToScalar(50), 0);
|
2011-12-21 14:27:14 +00:00
|
|
|
draw_rect_tests(canvas);
|
|
|
|
|
|
|
|
canvas->translate(SK_Scalar1 / 5, SK_Scalar1 / 5);
|
2011-12-28 19:40:48 +00:00
|
|
|
canvas->translate(SkIntToScalar(50), 0);
|
2011-12-21 14:27:14 +00:00
|
|
|
draw_rect_tests(canvas);
|
|
|
|
}
|
|
|
|
|
2012-07-20 18:45:10 +00:00
|
|
|
virtual uint32_t onGetFlags() const { return kSkipPipe_Flag; }
|
|
|
|
|
2011-12-21 14:27:14 +00:00
|
|
|
private:
|
2013-05-23 17:04:19 +00:00
|
|
|
typedef skiagm::GM INHERITED;
|
2011-12-21 14:27:14 +00:00
|
|
|
};
|
|
|
|
|
2013-05-23 17:04:19 +00:00
|
|
|
DEF_GM( return SkNEW(AAClipGM); )
|