| 1 |
/* |
| 2 |
* Copyright 2018 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/SkBlendMode.h" |
| 10 |
#include "include/core/SkBlurTypes.h" |
| 11 |
#include "include/core/SkCanvas.h" |
| 12 |
#include "include/core/SkColor.h" |
| 13 |
#include "include/core/SkCoverageMode.h" |
| 14 |
#include "include/core/SkFont.h" |
| 15 |
#include "include/core/SkImage.h" |
| 16 |
#include "include/core/SkImageFilter.h" |
| 17 |
#include "include/core/SkImageInfo.h" |
| 18 |
#include "include/core/SkMaskFilter.h" |
| 19 |
#include "include/core/SkMatrix.h" |
| 20 |
#include "include/core/SkPaint.h" |
| 21 |
#include "include/core/SkPath.h" |
| 22 |
#include "include/core/SkPicture.h" |
| 23 |
#include "include/core/SkPictureRecorder.h" |
| 24 |
#include "include/core/SkPoint.h" |
| 25 |
#include "include/core/SkRect.h" |
| 26 |
#include "include/core/SkRefCnt.h" |
| 27 |
#include "include/core/SkScalar.h" |
| 28 |
#include "include/core/SkShader.h" |
| 29 |
#include "include/core/SkString.h" |
| 30 |
#include "include/core/SkSurface.h" |
| 31 |
#include "include/core/SkTileMode.h" |
| 32 |
#include "include/core/SkTypes.h" |
| 33 |
#include "include/effects/SkGradient.h" |
| 34 |
#include "include/effects/SkImageFilters.h" |
| 35 |
#include "include/effects/SkShaderMaskFilter.h" |
| 36 |
#include "include/utils/SkTextUtils.h" |
| 37 |
#include "src/core/SkBlendModePriv.h" |
| 38 |
#include "tools/Resources.h" |
| 39 |
#include "tools/ToolUtils.h" |
| 40 |
|
| 41 |
#include <initializer_list> |
| 42 |
|
| 43 |
static sk_sp<SkShader> make_shader(const SkRect& r) { |
| 44 |
const SkPoint pts[] = { |
| 45 |
{ r.fLeft, r.fTop }, { r.fRight, r.fBottom }, |
| 46 |
}; |
| 47 |
const SkColor4f colors[] = { {0,0,0,0}, SkColors::kWhite }; |
| 48 |
return SkShaders::LinearGradient(pts, {{colors, {}, SkTileMode::kRepeat}, {}}); |
| 49 |
} |
| 50 |
|
| 51 |
DEF_SIMPLE_GM(shadermaskfilter_gradient, canvas, 512, 512) { |
| 52 |
SkRect r = { 0, 0, 100, 150 }; |
| 53 |
auto shader = make_shader(r); |
| 54 |
auto mf = SkShaderMaskFilter::Make(shader); |
| 55 |
|
| 56 |
canvas->translate(20, 20); |
| 57 |
canvas->scale(2, 2); |
| 58 |
|
| 59 |
SkPaint paint; |
| 60 |
paint.setMaskFilter(mf); |
| 61 |
paint.setColor(SK_ColorRED); |
| 62 |
paint.setAntiAlias(true); |
| 63 |
canvas->drawOval(r, paint); |
| 64 |
} |