2016-02-03 02:44:15 +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/SkImageFilter.h"
|
|
|
|
#include "include/core/SkImageInfo.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkRRect.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkSurface.h"
|
2019-08-02 19:21:23 +00:00
|
|
|
#include "include/effects/SkImageFilters.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkClipOpPriv.h"
|
|
|
|
#include "tools/ToolUtils.h"
|
2016-02-03 02:44:15 +00:00
|
|
|
|
|
|
|
#define WIDTH 512
|
|
|
|
#define HEIGHT 512
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
class ComplexClipBlurTiledGM : public GM {
|
|
|
|
public:
|
|
|
|
ComplexClipBlurTiledGM() {
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkString onShortName() override {
|
|
|
|
return SkString("complexclip_blur_tiled");
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() override {
|
|
|
|
return SkISize::Make(WIDTH, HEIGHT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
|
|
SkPaint blurPaint;
|
2019-08-02 19:21:23 +00:00
|
|
|
blurPaint.setImageFilter(SkImageFilters::Blur(5.0f, 5.0f, nullptr));
|
2016-04-04 11:31:25 +00:00
|
|
|
const SkScalar tileSize = SkIntToScalar(128);
|
2017-01-23 16:39:45 +00:00
|
|
|
SkRect bounds = canvas->getLocalClipBounds();
|
2016-04-04 11:31:25 +00:00
|
|
|
int ts = SkScalarCeilToInt(tileSize);
|
2016-02-03 02:44:15 +00:00
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(ts, ts);
|
2019-03-20 16:12:10 +00:00
|
|
|
auto tileSurface(ToolUtils::makeSurface(canvas, info));
|
2016-02-03 02:44:15 +00:00
|
|
|
SkCanvas* tileCanvas = tileSurface->getCanvas();
|
2016-04-04 11:31:25 +00:00
|
|
|
for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tileSize) {
|
|
|
|
for (SkScalar x = bounds.left(); x < bounds.right(); x += tileSize) {
|
2016-02-03 02:44:15 +00:00
|
|
|
tileCanvas->save();
|
|
|
|
tileCanvas->clear(0);
|
|
|
|
tileCanvas->translate(-x, -y);
|
|
|
|
SkRect rect = SkRect::MakeWH(WIDTH, HEIGHT);
|
|
|
|
tileCanvas->saveLayer(&rect, &blurPaint);
|
|
|
|
SkRRect rrect = SkRRect::MakeRectXY(rect.makeInset(20, 20), 25, 25);
|
2016-12-09 14:00:50 +00:00
|
|
|
tileCanvas->clipRRect(rrect, kDifference_SkClipOp, true);
|
2016-02-03 02:44:15 +00:00
|
|
|
SkPaint paint;
|
|
|
|
tileCanvas->drawRect(rect, paint);
|
|
|
|
tileCanvas->restore();
|
|
|
|
tileCanvas->restore();
|
2016-03-17 17:51:11 +00:00
|
|
|
canvas->drawImage(tileSurface->makeImageSnapshot().get(), x, y);
|
2016-02-03 02:44:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-04-04 11:31:25 +00:00
|
|
|
DEF_GM(return new ComplexClipBlurTiledGM;)
|
2016-02-03 02:44:15 +00:00
|
|
|
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace skiagm
|