2016-08-25 20:54:30 +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-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkBlurTypes.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkImageFilter.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkMaskFilter.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPathEffect.h"
|
|
|
|
#include "include/core/SkPoint.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkRegion.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkTileMode.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/effects/SkDashPathEffect.h"
|
|
|
|
#include "include/effects/SkGradientShader.h"
|
2019-08-02 19:21:23 +00:00
|
|
|
#include "include/effects/SkImageFilters.h"
|
2016-08-25 20:54:30 +00:00
|
|
|
|
|
|
|
class DrawRegionModesGM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
DrawRegionModesGM() {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkString onShortName() override {
|
|
|
|
return SkString("drawregionmodes");
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() override {
|
|
|
|
return SkISize::Make(375, 500);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onOnceBeforeDraw() override {
|
2019-08-24 23:39:13 +00:00
|
|
|
fRegion.op({50, 50, 100, 100}, SkRegion::kUnion_Op);
|
|
|
|
fRegion.op({50, 100, 150, 150}, SkRegion::kUnion_Op);
|
2016-08-25 20:54:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
|
|
canvas->clear(SK_ColorGREEN);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setStyle(SkPaint::kFill_Style);
|
2018-04-20 16:43:18 +00:00
|
|
|
paint.setColor(SK_ColorRED);
|
2016-08-25 20:54:30 +00:00
|
|
|
paint.setAntiAlias(true);
|
|
|
|
|
2018-04-20 16:43:18 +00:00
|
|
|
canvas->save();
|
2016-08-25 20:54:30 +00:00
|
|
|
canvas->translate(-50.0f, 75.0f);
|
|
|
|
canvas->rotate(-45.0f);
|
|
|
|
canvas->drawRegion(fRegion, paint);
|
|
|
|
|
|
|
|
canvas->translate(125.0f, 125.0f);
|
2019-08-02 19:21:23 +00:00
|
|
|
paint.setImageFilter(SkImageFilters::Blur(5.0f, 5.0f, nullptr, nullptr));
|
2016-08-25 20:54:30 +00:00
|
|
|
canvas->drawRegion(fRegion, paint);
|
|
|
|
|
|
|
|
canvas->translate(-125.0f, 125.0f);
|
|
|
|
paint.setImageFilter(nullptr);
|
2018-08-17 12:10:27 +00:00
|
|
|
paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 5.0f));
|
2016-08-25 20:54:30 +00:00
|
|
|
canvas->drawRegion(fRegion, paint);
|
|
|
|
|
|
|
|
canvas->translate(-125.0f, -125.0f);
|
|
|
|
paint.setMaskFilter(nullptr);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
float intervals[] = { 5.0f, 5.0f };
|
|
|
|
paint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 2.5f));
|
|
|
|
canvas->drawRegion(fRegion, paint);
|
|
|
|
|
2018-04-20 16:43:18 +00:00
|
|
|
canvas->restore();
|
|
|
|
|
2016-08-25 20:54:30 +00:00
|
|
|
canvas->translate(100, 325);
|
|
|
|
paint.setPathEffect(nullptr);
|
|
|
|
paint.setStyle(SkPaint::kFill_Style);
|
|
|
|
SkPoint points[] = { SkPoint::Make(50.0f, 50.0f), SkPoint::Make(150.0f, 150.0f) };
|
|
|
|
SkColor colors[] = { SK_ColorBLUE, SK_ColorYELLOW };
|
|
|
|
paint.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 2,
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode::kClamp));
|
2016-08-25 20:54:30 +00:00
|
|
|
canvas->drawRegion(fRegion, paint);
|
|
|
|
}
|
|
|
|
|
2018-04-20 16:43:18 +00:00
|
|
|
private:
|
2016-08-25 20:54:30 +00:00
|
|
|
SkRegion fRegion;
|
|
|
|
|
|
|
|
typedef skiagm::GM INHERITED;
|
|
|
|
};
|
|
|
|
DEF_GM( return new DrawRegionModesGM; )
|