| 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/SkCanvas.h" |
| 10 |
#include "include/core/SkColor.h" |
| 11 |
#include "include/core/SkMatrix.h" |
| 12 |
#include "include/core/SkPaint.h" |
| 13 |
#include "include/core/SkPoint.h" |
| 14 |
#include "include/core/SkRRect.h" |
| 15 |
#include "include/core/SkRect.h" |
| 16 |
#include "include/core/SkShader.h" |
| 17 |
#include "include/core/SkTileMode.h" |
| 18 |
#include "include/effects/SkGradient.h" |
| 19 |
|
| 20 |
// Exercises code in skgpu::V1::SurfaceDrawContext that attempts to replace a rrect clip/draw |
| 21 |
// paint with draw rrect. |
| 22 |
DEF_SIMPLE_GM(rrect_clip_draw_paint, canvas, 256, 256) { |
| 23 |
SkRRect rrect = SkRRect::MakeRectXY(SkRect::MakeXYWH(10.f, 10.f, 236.f, 236.f), 30.f, 40.f); |
| 24 |
|
| 25 |
SkPaint p; |
| 26 |
p.setColor(SK_ColorRED); |
| 27 |
|
| 28 |
SkMatrix zoomOut; |
| 29 |
zoomOut.setScale(0.7f, 0.7f, 128.f, 128.f); |
| 30 |
|
| 31 |
const SkRect layerRect = SkRect::MakeWH(256.f, 256.f); |
| 32 |
canvas->saveLayer(layerRect, nullptr); |
| 33 |
canvas->clipRRect(rrect, true); |
| 34 |
canvas->drawPaint(p); |
| 35 |
canvas->restore(); |
| 36 |
|
| 37 |
canvas->concat(zoomOut); |
| 38 |
p.setColor(SK_ColorBLUE); |
| 39 |
canvas->saveLayer(layerRect, nullptr); |
| 40 |
canvas->clipRRect(rrect, false); |
| 41 |
canvas->drawPaint(p); |
| 42 |
canvas->restore(); |
| 43 |
|
| 44 |
constexpr SkPoint kPts[] = {{0.f, 0.f}, {256.f, 256.f}}; |
| 45 |
constexpr SkColor4f kColors1[] = {SkColors::kCyan, SkColors::kGreen}; |
| 46 |
p.setShader(SkShaders::LinearGradient(kPts, {{kColors1, {}, SkTileMode::kClamp}, {}})); |
| 47 |
canvas->concat(zoomOut); |
| 48 |
canvas->saveLayer(layerRect, nullptr); |
| 49 |
canvas->clipRRect(rrect, true); |
| 50 |
canvas->drawPaint(p); |
| 51 |
canvas->restore(); |
| 52 |
|
| 53 |
constexpr float compat_gray = 0x88/255.f; |
| 54 |
constexpr SkColor4f kColors2[] = { |
| 55 |
SkColors::kMagenta, {compat_gray, compat_gray, compat_gray, 1}}; |
| 56 |
p.setShader(SkShaders::RadialGradient({128.f, 128.f}, 128.f, |
| 57 |
{{kColors2, {}, SkTileMode::kClamp}, {}})); |
| 58 |
canvas->concat(zoomOut); |
| 59 |
canvas->saveLayer(layerRect, nullptr); |
| 60 |
canvas->clipRRect(rrect, false); |
| 61 |
canvas->drawPaint(p); |
| 62 |
canvas->restore(); |
| 63 |
} |