2016-08-26 17:48:19 +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/SkCanvas.h"
|
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPoint.h"
|
|
|
|
#include "include/core/SkRRect.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "include/core/SkTileMode.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/effects/SkGradientShader.h"
|
2016-08-26 17:48:19 +00:00
|
|
|
|
2020-12-09 21:37:04 +00:00
|
|
|
// Exercises code in GrSurfaceDrawContext that attempts to replace a rrect clip/draw paint with
|
2016-10-27 18:47:55 +00:00
|
|
|
// draw rrect.
|
2016-08-26 17:48:19 +00:00
|
|
|
DEF_SIMPLE_GM(rrect_clip_draw_paint, canvas, 256, 256) {
|
|
|
|
SkRRect rrect = SkRRect::MakeRectXY(SkRect::MakeXYWH(10.f, 10.f, 236.f, 236.f), 30.f, 40.f);
|
|
|
|
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorRED);
|
|
|
|
|
|
|
|
SkMatrix zoomOut;
|
|
|
|
zoomOut.setScale(0.7f, 0.7f, 128.f, 128.f);
|
|
|
|
|
|
|
|
const SkRect layerRect = SkRect::MakeWH(256.f, 256.f);
|
|
|
|
canvas->saveLayer(layerRect, nullptr);
|
2016-09-21 18:15:07 +00:00
|
|
|
canvas->clipRRect(rrect, true);
|
2016-08-26 17:48:19 +00:00
|
|
|
canvas->drawPaint(p);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
canvas->concat(zoomOut);
|
|
|
|
p.setColor(SK_ColorBLUE);
|
|
|
|
canvas->saveLayer(layerRect, nullptr);
|
2016-09-21 18:15:07 +00:00
|
|
|
canvas->clipRRect(rrect, false);
|
2016-08-26 17:48:19 +00:00
|
|
|
canvas->drawPaint(p);
|
|
|
|
canvas->restore();
|
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr SkPoint kPts[] = {{0.f, 0.f}, {256.f, 256.f}};
|
|
|
|
constexpr SkColor kColors1[] = {SK_ColorCYAN, SK_ColorGREEN};
|
2019-04-03 14:27:45 +00:00
|
|
|
p.setShader(SkGradientShader::MakeLinear(kPts, kColors1, nullptr, 2, SkTileMode::kClamp));
|
2016-08-26 17:48:19 +00:00
|
|
|
canvas->concat(zoomOut);
|
|
|
|
canvas->saveLayer(layerRect, nullptr);
|
2016-09-21 18:15:07 +00:00
|
|
|
canvas->clipRRect(rrect, true);
|
2016-08-26 17:48:19 +00:00
|
|
|
canvas->drawPaint(p);
|
|
|
|
canvas->restore();
|
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr SkColor kColors2[] = {SK_ColorMAGENTA, SK_ColorGRAY};
|
2016-08-26 17:48:19 +00:00
|
|
|
p.setShader(SkGradientShader::MakeRadial({128.f, 128.f}, 128.f, kColors2, nullptr, 2,
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode::kClamp));
|
2016-08-26 17:48:19 +00:00
|
|
|
canvas->concat(zoomOut);
|
|
|
|
canvas->saveLayer(layerRect, nullptr);
|
2016-09-21 18:15:07 +00:00
|
|
|
canvas->clipRRect(rrect, false);
|
2016-08-26 17:48:19 +00:00
|
|
|
canvas->drawPaint(p);
|
|
|
|
canvas->restore();
|
|
|
|
}
|