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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm.h"
|
2017-03-22 17:47:51 +00:00
|
|
|
#include "sk_tool_utils.h"
|
2015-12-10 21:29:14 +00:00
|
|
|
#include "SkBlurMaskFilter.h"
|
2016-12-12 15:02:12 +00:00
|
|
|
#include "SkClipOpPriv.h"
|
2015-12-10 21:29:14 +00:00
|
|
|
#include "SkColorFilter.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkRRect.h"
|
|
|
|
|
|
|
|
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() {
|
|
|
|
this->setBGColor(sk_tool_utils::color_to_565(0xFFCCCCCC));
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2016-04-04 17:02:58 +00:00
|
|
|
paint.setMaskFilter(SkBlurMaskFilter::Make(
|
2015-12-10 21:29:14 +00:00
|
|
|
kNormal_SkBlurStyle,
|
|
|
|
1.366025f,
|
2016-04-04 17:02:58 +00:00
|
|
|
SkBlurMaskFilter::kHighQuality_BlurFlag));
|
2016-03-22 17:17:23 +00:00
|
|
|
paint.setColorFilter(SkColorFilter::MakeModeFilter(
|
2015-12-10 21:29:14 +00:00
|
|
|
SK_ColorRED,
|
2016-10-28 19:42:34 +00:00
|
|
|
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
|
|
|
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
DEF_GM(return new BlurredClippedCircleGM;)
|
|
|
|
}
|