2015-05-21 17:33:09 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 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"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkBlendMode.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#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/SkRect.h"
|
2015-05-21 17:33:09 +00:00
|
|
|
|
|
|
|
DEF_SIMPLE_GM(PlusMergesAA, canvas, 256, 256) {
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorRED);
|
|
|
|
p.setAntiAlias(true); // <-- crucial to the test that we use AA
|
|
|
|
|
|
|
|
// Draw a two red squares.
|
|
|
|
canvas->drawRect(SkRect::MakeWH(100, 100), p);
|
|
|
|
canvas->drawRect(SkRect::MakeXYWH(150, 0, 100, 100), p);
|
|
|
|
|
|
|
|
p.setColor(0xf000ff00);
|
|
|
|
|
|
|
|
// We'll draw a green square on top of each using two triangles.
|
|
|
|
SkPath upperLeft;
|
|
|
|
upperLeft.lineTo(100, 0);
|
|
|
|
upperLeft.lineTo(0, 100);
|
|
|
|
upperLeft.lineTo(0, 0);
|
|
|
|
|
|
|
|
SkPath bottomRight;
|
|
|
|
bottomRight.moveTo(100, 0);
|
|
|
|
bottomRight.lineTo(100, 100);
|
|
|
|
bottomRight.lineTo(0, 100);
|
|
|
|
bottomRight.lineTo(100, 0);
|
|
|
|
|
|
|
|
// The left square is drawn simply with SrcOver. It will show a red seam.
|
|
|
|
canvas->drawPath(upperLeft, p);
|
|
|
|
canvas->drawPath(bottomRight, p);
|
|
|
|
|
|
|
|
// Using Plus on the right should merge the AA of seam together completely covering the red.
|
|
|
|
canvas->saveLayer(nullptr, nullptr);
|
2016-10-06 00:33:02 +00:00
|
|
|
p.setBlendMode(SkBlendMode::kPlus);
|
2015-05-21 17:33:09 +00:00
|
|
|
canvas->translate(150, 0);
|
|
|
|
canvas->drawPath(upperLeft, p);
|
|
|
|
canvas->drawPath(bottomRight, p);
|
|
|
|
canvas->restore();
|
|
|
|
}
|