2015-12-10 21:29:14 +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 14:59:30 +00:00
|
|
|
#include "include/core/SkBlendMode.h"
|
|
|
|
#include "include/core/SkBlurTypes.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColor.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkColorFilter.h"
|
|
|
|
#include "include/core/SkMaskFilter.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRRect.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkClipOpPriv.h"
|
2015-12-10 21:29:14 +00:00
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
// This GM reproduces the precision artifacts seen in crbug.com/560651.
|
|
|
|
// It draws a largish blurred circle with its center clipped out.
|
|
|
|
class BlurredClippedCircleGM : public GM {
|
|
|
|
public:
|
|
|
|
BlurredClippedCircleGM() {
|
2018-08-16 14:17:03 +00:00
|
|
|
this->setBGColor(0xFFCCCCCC);
|
2015-12-10 21:29:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
SkString onShortName() override {
|
|
|
|
return SkString("blurredclippedcircle");
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() override {
|
|
|
|
return SkISize::Make(kWidth, kHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
|
|
SkPaint whitePaint;
|
|
|
|
whitePaint.setColor(SK_ColorWHITE);
|
2016-10-06 00:33:02 +00:00
|
|
|
whitePaint.setBlendMode(SkBlendMode::kSrc);
|
2015-12-10 21:29:14 +00:00
|
|
|
whitePaint.setAntiAlias(true);
|
|
|
|
|
|
|
|
// This scale exercises precision limits in the circle blur effect (crbug.com/560651)
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr float kScale = 2.0f;
|
2015-12-10 21:29:14 +00:00
|
|
|
canvas->scale(kScale, kScale);
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
SkRect clipRect1 = SkRect::MakeLTRB(0, 0,
|
|
|
|
SkIntToScalar(kWidth), SkIntToScalar(kHeight));
|
|
|
|
|
2016-09-20 15:42:38 +00:00
|
|
|
canvas->clipRect(clipRect1);
|
2015-12-10 21:29:14 +00:00
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
|
2016-09-20 15:42:38 +00:00
|
|
|
canvas->clipRect(clipRect1);
|
2015-12-10 21:29:14 +00:00
|
|
|
canvas->drawRect(clipRect1, whitePaint);
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
|
|
|
|
SkRect clipRect2 = SkRect::MakeLTRB(8, 8, 288, 288);
|
|
|
|
SkRRect clipRRect = SkRRect::MakeOval(clipRect2);
|
2016-12-09 14:00:50 +00:00
|
|
|
canvas->clipRRect(clipRRect, kDifference_SkClipOp, true);
|
2015-12-10 21:29:14 +00:00
|
|
|
|
|
|
|
SkRect r = SkRect::MakeLTRB(4, 4, 292, 292);
|
|
|
|
SkRRect rr = SkRRect::MakeOval(r);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
|
2018-03-14 17:01:17 +00:00
|
|
|
paint.setMaskFilter(SkMaskFilter::MakeBlur(
|
2015-12-10 21:29:14 +00:00
|
|
|
kNormal_SkBlurStyle,
|
2018-03-14 17:01:17 +00:00
|
|
|
1.366025f));
|
2019-04-08 20:23:20 +00:00
|
|
|
paint.setColorFilter(SkColorFilters::Blend(SK_ColorRED,
|
|
|
|
SkBlendMode::kSrcIn));
|
2015-12-10 21:29:14 +00:00
|
|
|
paint.setAntiAlias(true);
|
|
|
|
|
|
|
|
canvas->drawRRect(rr, paint);
|
|
|
|
|
|
|
|
canvas->restore();
|
|
|
|
canvas->restore();
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-09-01 18:24:54 +00:00
|
|
|
static constexpr int kWidth = 1164;
|
|
|
|
static constexpr int kHeight = 802;
|
2015-12-10 21:29:14 +00:00
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GM;
|
2015-12-10 21:29:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
DEF_GM(return new BlurredClippedCircleGM;)
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace skiagm
|