| 1 |
/* |
| 2 |
* Copyright 2016 Google Inc. |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "gm/gm.h" |
| 9 |
#include "include/core/SkBlurTypes.h" |
| 10 |
#include "include/core/SkCanvas.h" |
| 11 |
#include "include/core/SkColor.h" |
| 12 |
#include "include/core/SkImageFilter.h" |
| 13 |
#include "include/core/SkMaskFilter.h" |
| 14 |
#include "include/core/SkPaint.h" |
| 15 |
#include "include/core/SkPathEffect.h" |
| 16 |
#include "include/core/SkPoint.h" |
| 17 |
#include "include/core/SkRegion.h" |
| 18 |
#include "include/core/SkShader.h" |
| 19 |
#include "include/core/SkSize.h" |
| 20 |
#include "include/core/SkString.h" |
| 21 |
#include "include/core/SkTileMode.h" |
| 22 |
#include "include/effects/SkDashPathEffect.h" |
| 23 |
#include "include/effects/SkGradient.h" |
| 24 |
#include "include/effects/SkImageFilters.h" |
| 25 |
|
| 26 |
class DrawRegionModesGM : public skiagm::GM { |
| 27 |
public: |
| 28 |
DrawRegionModesGM() {} |
| 29 |
|
| 30 |
protected: |
| 31 |
SkString getName() const override { return SkString("drawregionmodes"); } |
| 32 |
|
| 33 |
SkISize getISize() override { return SkISize::Make(375, 500); } |
| 34 |
|
| 35 |
void onOnceBeforeDraw() override { |
| 36 |
fRegion.op({50, 50, 100, 100}, SkRegion::kUnion_Op); |
| 37 |
fRegion.op({50, 100, 150, 150}, SkRegion::kUnion_Op); |
| 38 |
} |
| 39 |
|
| 40 |
void onDraw(SkCanvas* canvas) override { |
| 41 |
canvas->clear(SK_ColorGREEN); |
| 42 |
|
| 43 |
SkPaint paint; |
| 44 |
paint.setStyle(SkPaint::kFill_Style); |
| 45 |
paint.setColor(SK_ColorRED); |
| 46 |
paint.setAntiAlias(true); |
| 47 |
|
| 48 |
canvas->save(); |
| 49 |
canvas->translate(-50.0f, 75.0f); |
| 50 |
canvas->rotate(-45.0f); |
| 51 |
canvas->drawRegion(fRegion, paint); |
| 52 |
|
| 53 |
canvas->translate(125.0f, 125.0f); |
| 54 |
paint.setImageFilter(SkImageFilters::Blur(5.0f, 5.0f, nullptr, nullptr)); |
| 55 |
canvas->drawRegion(fRegion, paint); |
| 56 |
|
| 57 |
canvas->translate(-125.0f, 125.0f); |
| 58 |
paint.setImageFilter(nullptr); |
| 59 |
paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 5.0f)); |
| 60 |
canvas->drawRegion(fRegion, paint); |
| 61 |
|
| 62 |
canvas->translate(-125.0f, -125.0f); |
| 63 |
paint.setMaskFilter(nullptr); |
| 64 |
paint.setStyle(SkPaint::kStroke_Style); |
| 65 |
float intervals[] = { 5.0f, 5.0f }; |
| 66 |
paint.setPathEffect(SkDashPathEffect::Make(intervals, 2.5f)); |
| 67 |
canvas->drawRegion(fRegion, paint); |
| 68 |
|
| 69 |
canvas->restore(); |
| 70 |
|
| 71 |
canvas->translate(100, 325); |
| 72 |
paint.setPathEffect(nullptr); |
| 73 |
paint.setStyle(SkPaint::kFill_Style); |
| 74 |
const SkPoint points[] = { SkPoint::Make(50.0f, 50.0f), SkPoint::Make(150.0f, 150.0f) }; |
| 75 |
const SkColor4f colors[] = { SkColors::kBlue, SkColors::kYellow }; |
| 76 |
paint.setShader(SkShaders::LinearGradient(points, {{colors, {}, SkTileMode::kClamp}, {}})); |
| 77 |
canvas->drawRegion(fRegion, paint); |
| 78 |
} |
| 79 |
|
| 80 |
private: |
| 81 |
SkRegion fRegion; |
| 82 |
|
| 83 |
using INHERITED = skiagm::GM; |
| 84 |
}; |
| 85 |
DEF_GM( return new DrawRegionModesGM; ) |