2015-06-08 13:21:14 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 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 14:59:30 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkImage.h"
|
|
|
|
#include "include/core/SkImageFilter.h"
|
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#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"
|
|
|
|
#include "include/effects/SkImageSource.h"
|
|
|
|
#include "include/effects/SkTileImageFilter.h"
|
2015-06-08 13:21:14 +00:00
|
|
|
|
2019-05-01 14:59:30 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2016-03-17 17:51:11 +00:00
|
|
|
static sk_sp<SkImage> create_circle_texture(int size, SkColor color) {
|
2016-03-24 01:59:25 +00:00
|
|
|
auto surface(SkSurface::MakeRasterN32Premul(size, size));
|
2015-09-25 16:15:55 +00:00
|
|
|
SkCanvas* canvas = surface->getCanvas();
|
|
|
|
canvas->clear(0xFF000000);
|
Fix dst bound reported by SkTileImageFilter
In the example from the bug we had the filter DAG:
color filter (table)
0: xfermode filter (arith)
0: tile filter [0,80,34,114] -> [0,80,800,480]
0: color filter (table)
0: bitmap src 34x34 -> [0,80,34,114]
1: color filter (table)
0: picture filter [0, 80, 800, 480]
computeFastBounds was coming out of the DAG with a bound of [0,80,34,114] which didn't represent the pixels that would be drawn.
This CL updates SkTileImageFilter to correctly set the bound for the pixels it will hit.
BUG=493783
Committed: https://skia.googlesource.com/skia/+/05be93bbdf09576f7903130e3b106b0a8c7c4b4e
Committed: https://skia.googlesource.com/skia/+/0be685755f942baea26c66a87226b569fc17e960
Review URL: https://codereview.chromium.org/1152553006
2015-06-16 16:44:56 +00:00
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(color);
|
|
|
|
paint.setStrokeWidth(3);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
|
2015-09-25 16:15:55 +00:00
|
|
|
canvas->drawCircle(SkScalarHalf(size), SkScalarHalf(size), SkScalarHalf(size), paint);
|
|
|
|
|
2016-03-17 17:51:11 +00:00
|
|
|
return surface->makeImageSnapshot();
|
Fix dst bound reported by SkTileImageFilter
In the example from the bug we had the filter DAG:
color filter (table)
0: xfermode filter (arith)
0: tile filter [0,80,34,114] -> [0,80,800,480]
0: color filter (table)
0: bitmap src 34x34 -> [0,80,34,114]
1: color filter (table)
0: picture filter [0, 80, 800, 480]
computeFastBounds was coming out of the DAG with a bound of [0,80,34,114] which didn't represent the pixels that would be drawn.
This CL updates SkTileImageFilter to correctly set the bound for the pixels it will hit.
BUG=493783
Committed: https://skia.googlesource.com/skia/+/05be93bbdf09576f7903130e3b106b0a8c7c4b4e
Committed: https://skia.googlesource.com/skia/+/0be685755f942baea26c66a87226b569fc17e960
Review URL: https://codereview.chromium.org/1152553006
2015-06-16 16:44:56 +00:00
|
|
|
}
|
|
|
|
|
2015-06-08 13:21:14 +00:00
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
class BigTileImageFilterGM : public GM {
|
|
|
|
public:
|
|
|
|
BigTileImageFilterGM() {
|
|
|
|
this->setBGColor(0xFF000000);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
SkString onShortName() override {
|
|
|
|
return SkString("bigtileimagefilter");
|
|
|
|
}
|
|
|
|
|
2019-07-18 16:36:54 +00:00
|
|
|
SkISize onISize() override {
|
2015-06-08 13:21:14 +00:00
|
|
|
return SkISize::Make(kWidth, kHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onOnceBeforeDraw() override {
|
2016-03-17 17:51:11 +00:00
|
|
|
fRedImage = create_circle_texture(kBitmapSize, SK_ColorRED);
|
|
|
|
fGreenImage = create_circle_texture(kBitmapSize, SK_ColorGREEN);
|
2015-06-08 13:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
|
|
canvas->clear(SK_ColorBLACK);
|
|
|
|
|
Fix dst bound reported by SkTileImageFilter
In the example from the bug we had the filter DAG:
color filter (table)
0: xfermode filter (arith)
0: tile filter [0,80,34,114] -> [0,80,800,480]
0: color filter (table)
0: bitmap src 34x34 -> [0,80,34,114]
1: color filter (table)
0: picture filter [0, 80, 800, 480]
computeFastBounds was coming out of the DAG with a bound of [0,80,34,114] which didn't represent the pixels that would be drawn.
This CL updates SkTileImageFilter to correctly set the bound for the pixels it will hit.
BUG=493783
Committed: https://skia.googlesource.com/skia/+/05be93bbdf09576f7903130e3b106b0a8c7c4b4e
Committed: https://skia.googlesource.com/skia/+/0be685755f942baea26c66a87226b569fc17e960
Review URL: https://codereview.chromium.org/1152553006
2015-06-16 16:44:56 +00:00
|
|
|
{
|
|
|
|
SkPaint p;
|
2015-06-08 13:21:14 +00:00
|
|
|
|
2016-04-01 16:28:51 +00:00
|
|
|
const SkRect bound = SkRect::MakeIWH(kWidth, kHeight);
|
|
|
|
sk_sp<SkImageFilter> imageSource(SkImageSource::Make(fRedImage));
|
|
|
|
|
2016-04-15 14:57:40 +00:00
|
|
|
sk_sp<SkImageFilter> tif(SkTileImageFilter::Make(
|
2016-04-01 16:28:51 +00:00
|
|
|
SkRect::MakeIWH(kBitmapSize, kBitmapSize),
|
|
|
|
SkRect::MakeIWH(kWidth, kHeight),
|
2016-04-15 14:57:40 +00:00
|
|
|
std::move(imageSource)));
|
2016-04-01 16:28:51 +00:00
|
|
|
|
|
|
|
p.setImageFilter(std::move(tif));
|
2015-06-08 13:21:14 +00:00
|
|
|
|
Fix dst bound reported by SkTileImageFilter
In the example from the bug we had the filter DAG:
color filter (table)
0: xfermode filter (arith)
0: tile filter [0,80,34,114] -> [0,80,800,480]
0: color filter (table)
0: bitmap src 34x34 -> [0,80,34,114]
1: color filter (table)
0: picture filter [0, 80, 800, 480]
computeFastBounds was coming out of the DAG with a bound of [0,80,34,114] which didn't represent the pixels that would be drawn.
This CL updates SkTileImageFilter to correctly set the bound for the pixels it will hit.
BUG=493783
Committed: https://skia.googlesource.com/skia/+/05be93bbdf09576f7903130e3b106b0a8c7c4b4e
Committed: https://skia.googlesource.com/skia/+/0be685755f942baea26c66a87226b569fc17e960
Review URL: https://codereview.chromium.org/1152553006
2015-06-16 16:44:56 +00:00
|
|
|
canvas->saveLayer(&bound, &p);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkPaint p2;
|
|
|
|
|
2016-04-01 16:28:51 +00:00
|
|
|
const SkRect bound2 = SkRect::MakeIWH(kBitmapSize, kBitmapSize);
|
|
|
|
|
2016-04-15 14:57:40 +00:00
|
|
|
sk_sp<SkImageFilter> tif(SkTileImageFilter::Make(
|
2016-04-01 16:28:51 +00:00
|
|
|
SkRect::MakeIWH(kBitmapSize, kBitmapSize),
|
|
|
|
SkRect::MakeIWH(kBitmapSize, kBitmapSize),
|
|
|
|
nullptr));
|
Fix dst bound reported by SkTileImageFilter
In the example from the bug we had the filter DAG:
color filter (table)
0: xfermode filter (arith)
0: tile filter [0,80,34,114] -> [0,80,800,480]
0: color filter (table)
0: bitmap src 34x34 -> [0,80,34,114]
1: color filter (table)
0: picture filter [0, 80, 800, 480]
computeFastBounds was coming out of the DAG with a bound of [0,80,34,114] which didn't represent the pixels that would be drawn.
This CL updates SkTileImageFilter to correctly set the bound for the pixels it will hit.
BUG=493783
Committed: https://skia.googlesource.com/skia/+/05be93bbdf09576f7903130e3b106b0a8c7c4b4e
Committed: https://skia.googlesource.com/skia/+/0be685755f942baea26c66a87226b569fc17e960
Review URL: https://codereview.chromium.org/1152553006
2015-06-16 16:44:56 +00:00
|
|
|
|
2016-04-01 16:28:51 +00:00
|
|
|
p2.setImageFilter(std::move(tif));
|
Fix dst bound reported by SkTileImageFilter
In the example from the bug we had the filter DAG:
color filter (table)
0: xfermode filter (arith)
0: tile filter [0,80,34,114] -> [0,80,800,480]
0: color filter (table)
0: bitmap src 34x34 -> [0,80,34,114]
1: color filter (table)
0: picture filter [0, 80, 800, 480]
computeFastBounds was coming out of the DAG with a bound of [0,80,34,114] which didn't represent the pixels that would be drawn.
This CL updates SkTileImageFilter to correctly set the bound for the pixels it will hit.
BUG=493783
Committed: https://skia.googlesource.com/skia/+/05be93bbdf09576f7903130e3b106b0a8c7c4b4e
Committed: https://skia.googlesource.com/skia/+/0be685755f942baea26c66a87226b569fc17e960
Review URL: https://codereview.chromium.org/1152553006
2015-06-16 16:44:56 +00:00
|
|
|
|
|
|
|
canvas->translate(320, 320);
|
|
|
|
canvas->saveLayer(&bound2, &p2);
|
|
|
|
canvas->setMatrix(SkMatrix::I());
|
|
|
|
|
|
|
|
SkRect bound3 = SkRect::MakeXYWH(320, 320,
|
|
|
|
SkIntToScalar(kBitmapSize),
|
|
|
|
SkIntToScalar(kBitmapSize));
|
2016-03-17 17:51:11 +00:00
|
|
|
canvas->drawImageRect(fGreenImage.get(), bound2, bound3, nullptr,
|
2015-09-25 16:15:55 +00:00
|
|
|
SkCanvas::kStrict_SrcRectConstraint);
|
Fix dst bound reported by SkTileImageFilter
In the example from the bug we had the filter DAG:
color filter (table)
0: xfermode filter (arith)
0: tile filter [0,80,34,114] -> [0,80,800,480]
0: color filter (table)
0: bitmap src 34x34 -> [0,80,34,114]
1: color filter (table)
0: picture filter [0, 80, 800, 480]
computeFastBounds was coming out of the DAG with a bound of [0,80,34,114] which didn't represent the pixels that would be drawn.
This CL updates SkTileImageFilter to correctly set the bound for the pixels it will hit.
BUG=493783
Committed: https://skia.googlesource.com/skia/+/05be93bbdf09576f7903130e3b106b0a8c7c4b4e
Committed: https://skia.googlesource.com/skia/+/0be685755f942baea26c66a87226b569fc17e960
Review URL: https://codereview.chromium.org/1152553006
2015-06-16 16:44:56 +00:00
|
|
|
canvas->restore();
|
|
|
|
}
|
2015-06-08 13:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-09-01 18:24:54 +00:00
|
|
|
static constexpr int kWidth = 512;
|
|
|
|
static constexpr int kHeight = 512;
|
|
|
|
static constexpr int kBitmapSize = 64;
|
2015-06-08 13:21:14 +00:00
|
|
|
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> fRedImage;
|
|
|
|
sk_sp<SkImage> fGreenImage;
|
2015-06-08 13:21:14 +00:00
|
|
|
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_GM(return new BigTileImageFilterGM;)
|
2015-06-08 13:21:14 +00:00
|
|
|
}
|