Moving 4 SkImageFilter derived classes from blink to skia
There were 4 classes in blink that derived from SkImageFilter :
- TileImageFilter -> SkTileImageFilter
- OffsetImageFilter -> SkOffsetImageFilter (already existed)
- FloodImageFilter -> SkFloodImageFilter
- CompositeImageFilter -> SkCompositeImageFilter
All functions were copied as is, without modification (except for warnings fixes), except for the offset filter, which was merged into the existing SkOffsetImageFilter class, as a special case when a crop rect is provided. Since the names won't clash with the names in blink, it should be easy to integrate them in blink later and fix issues, if needed.
BUG=
R=senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, reed@google.com, mtklein@google.com
Author: sugoi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/24157005
git-svn-id: http://skia.googlecode.com/svn/trunk@11475 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-09-26 16:09:28 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 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/SkBitmap.h"
|
|
|
|
#include "include/core/SkBlendMode.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkColorFilter.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkImage.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkImageFilter.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-08-02 19:21:23 +00:00
|
|
|
#include "include/effects/SkImageFilters.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/ToolUtils.h"
|
Moving 4 SkImageFilter derived classes from blink to skia
There were 4 classes in blink that derived from SkImageFilter :
- TileImageFilter -> SkTileImageFilter
- OffsetImageFilter -> SkOffsetImageFilter (already existed)
- FloodImageFilter -> SkFloodImageFilter
- CompositeImageFilter -> SkCompositeImageFilter
All functions were copied as is, without modification (except for warnings fixes), except for the offset filter, which was merged into the existing SkOffsetImageFilter class, as a special case when a crop rect is provided. Since the names won't clash with the names in blink, it should be easy to integrate them in blink later and fix issues, if needed.
BUG=
R=senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, reed@google.com, mtklein@google.com
Author: sugoi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/24157005
git-svn-id: http://skia.googlecode.com/svn/trunk@11475 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-09-26 16:09:28 +00:00
|
|
|
|
2019-05-01 21:28:53 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <utility>
|
|
|
|
|
Moving 4 SkImageFilter derived classes from blink to skia
There were 4 classes in blink that derived from SkImageFilter :
- TileImageFilter -> SkTileImageFilter
- OffsetImageFilter -> SkOffsetImageFilter (already existed)
- FloodImageFilter -> SkFloodImageFilter
- CompositeImageFilter -> SkCompositeImageFilter
All functions were copied as is, without modification (except for warnings fixes), except for the offset filter, which was merged into the existing SkOffsetImageFilter class, as a special case when a crop rect is provided. Since the names won't clash with the names in blink, it should be easy to integrate them in blink later and fix issues, if needed.
BUG=
R=senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, reed@google.com, mtklein@google.com
Author: sugoi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/24157005
git-svn-id: http://skia.googlecode.com/svn/trunk@11475 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-09-26 16:09:28 +00:00
|
|
|
#define WIDTH 400
|
2016-04-01 16:24:48 +00:00
|
|
|
#define HEIGHT 200
|
Moving 4 SkImageFilter derived classes from blink to skia
There were 4 classes in blink that derived from SkImageFilter :
- TileImageFilter -> SkTileImageFilter
- OffsetImageFilter -> SkOffsetImageFilter (already existed)
- FloodImageFilter -> SkFloodImageFilter
- CompositeImageFilter -> SkCompositeImageFilter
All functions were copied as is, without modification (except for warnings fixes), except for the offset filter, which was merged into the existing SkOffsetImageFilter class, as a special case when a crop rect is provided. Since the names won't clash with the names in blink, it should be easy to integrate them in blink later and fix issues, if needed.
BUG=
R=senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, reed@google.com, mtklein@google.com
Author: sugoi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/24157005
git-svn-id: http://skia.googlecode.com/svn/trunk@11475 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-09-26 16:09:28 +00:00
|
|
|
#define MARGIN 12
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
class TileImageFilterGM : public GM {
|
|
|
|
public:
|
2015-06-08 13:21:14 +00:00
|
|
|
TileImageFilterGM() {
|
Moving 4 SkImageFilter derived classes from blink to skia
There were 4 classes in blink that derived from SkImageFilter :
- TileImageFilter -> SkTileImageFilter
- OffsetImageFilter -> SkOffsetImageFilter (already existed)
- FloodImageFilter -> SkFloodImageFilter
- CompositeImageFilter -> SkCompositeImageFilter
All functions were copied as is, without modification (except for warnings fixes), except for the offset filter, which was merged into the existing SkOffsetImageFilter class, as a special case when a crop rect is provided. Since the names won't clash with the names in blink, it should be easy to integrate them in blink later and fix issues, if needed.
BUG=
R=senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, reed@google.com, mtklein@google.com
Author: sugoi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/24157005
git-svn-id: http://skia.googlecode.com/svn/trunk@11475 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-09-26 16:09:28 +00:00
|
|
|
this->setBGColor(0xFF000000);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-06-08 13:21:14 +00:00
|
|
|
SkString onShortName() override {
|
Moving 4 SkImageFilter derived classes from blink to skia
There were 4 classes in blink that derived from SkImageFilter :
- TileImageFilter -> SkTileImageFilter
- OffsetImageFilter -> SkOffsetImageFilter (already existed)
- FloodImageFilter -> SkFloodImageFilter
- CompositeImageFilter -> SkCompositeImageFilter
All functions were copied as is, without modification (except for warnings fixes), except for the offset filter, which was merged into the existing SkOffsetImageFilter class, as a special case when a crop rect is provided. Since the names won't clash with the names in blink, it should be easy to integrate them in blink later and fix issues, if needed.
BUG=
R=senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, reed@google.com, mtklein@google.com
Author: sugoi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/24157005
git-svn-id: http://skia.googlecode.com/svn/trunk@11475 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-09-26 16:09:28 +00:00
|
|
|
return SkString("tileimagefilter");
|
|
|
|
}
|
|
|
|
|
2019-07-18 16:36:54 +00:00
|
|
|
SkISize onISize() override {
|
2014-06-10 06:59:03 +00:00
|
|
|
return SkISize::Make(WIDTH, HEIGHT);
|
Moving 4 SkImageFilter derived classes from blink to skia
There were 4 classes in blink that derived from SkImageFilter :
- TileImageFilter -> SkTileImageFilter
- OffsetImageFilter -> SkOffsetImageFilter (already existed)
- FloodImageFilter -> SkFloodImageFilter
- CompositeImageFilter -> SkCompositeImageFilter
All functions were copied as is, without modification (except for warnings fixes), except for the offset filter, which was merged into the existing SkOffsetImageFilter class, as a special case when a crop rect is provided. Since the names won't clash with the names in blink, it should be easy to integrate them in blink later and fix issues, if needed.
BUG=
R=senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, reed@google.com, mtklein@google.com
Author: sugoi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/24157005
git-svn-id: http://skia.googlecode.com/svn/trunk@11475 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-09-26 16:09:28 +00:00
|
|
|
}
|
|
|
|
|
2015-06-08 13:21:14 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2016-03-17 17:51:11 +00:00
|
|
|
fBitmap = SkImage::MakeFromBitmap(
|
2019-03-20 16:12:10 +00:00
|
|
|
ToolUtils::create_string_bitmap(50, 50, 0xD000D000, 10, 45, 50, "e"));
|
2015-09-15 18:26:13 +00:00
|
|
|
|
2016-03-17 17:51:11 +00:00
|
|
|
fCheckerboard = SkImage::MakeFromBitmap(
|
2019-03-20 16:12:10 +00:00
|
|
|
ToolUtils::create_checkerboard_bitmap(80, 80, 0xFFA0A0A0, 0xFF404040, 8));
|
2015-06-08 13:21:14 +00:00
|
|
|
}
|
2015-01-26 19:24:32 +00:00
|
|
|
|
2015-06-08 13:21:14 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2015-04-09 18:13:24 +00:00
|
|
|
canvas->clear(SK_ColorBLACK);
|
2016-01-11 22:09:09 +00:00
|
|
|
SkPaint red;
|
|
|
|
red.setColor(SK_ColorRED);
|
|
|
|
red.setStyle(SkPaint::kStroke_Style);
|
|
|
|
SkPaint blue;
|
|
|
|
blue.setColor(SK_ColorBLUE);
|
|
|
|
blue.setStyle(SkPaint::kStroke_Style);
|
Moving 4 SkImageFilter derived classes from blink to skia
There were 4 classes in blink that derived from SkImageFilter :
- TileImageFilter -> SkTileImageFilter
- OffsetImageFilter -> SkOffsetImageFilter (already existed)
- FloodImageFilter -> SkFloodImageFilter
- CompositeImageFilter -> SkCompositeImageFilter
All functions were copied as is, without modification (except for warnings fixes), except for the offset filter, which was merged into the existing SkOffsetImageFilter class, as a special case when a crop rect is provided. Since the names won't clash with the names in blink, it should be easy to integrate them in blink later and fix issues, if needed.
BUG=
R=senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, reed@google.com, mtklein@google.com
Author: sugoi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/24157005
git-svn-id: http://skia.googlecode.com/svn/trunk@11475 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-09-26 16:09:28 +00:00
|
|
|
|
|
|
|
int x = 0, y = 0;
|
2019-04-17 20:03:30 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < 4; i++) {
|
|
|
|
sk_sp<SkImage> image = (i & 0x01) ? fCheckerboard : fBitmap;
|
|
|
|
SkRect srcRect = SkRect::MakeXYWH(SkIntToScalar(image->width()/4),
|
|
|
|
SkIntToScalar(image->height()/4),
|
|
|
|
SkIntToScalar(image->width()/(i+1)),
|
|
|
|
SkIntToScalar(image->height()/(i+1)));
|
|
|
|
SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(i * 8),
|
|
|
|
SkIntToScalar(i * 4),
|
|
|
|
SkIntToScalar(image->width() - i * 12),
|
|
|
|
SkIntToScalar(image->height()) - i * 12);
|
2019-08-02 19:21:23 +00:00
|
|
|
sk_sp<SkImageFilter> tileInput(SkImageFilters::Image(image));
|
|
|
|
sk_sp<SkImageFilter> filter(SkImageFilters::Tile(srcRect, dstRect,
|
|
|
|
std::move(tileInput)));
|
2019-04-17 20:03:30 +00:00
|
|
|
canvas->save();
|
|
|
|
canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setImageFilter(std::move(filter));
|
|
|
|
canvas->drawImage(fBitmap.get(), 0, 0, &paint);
|
|
|
|
canvas->drawRect(srcRect, red);
|
|
|
|
canvas->drawRect(dstRect, blue);
|
|
|
|
canvas->restore();
|
|
|
|
x += image->width() + MARGIN;
|
|
|
|
if (x + image->width() > WIDTH) {
|
|
|
|
x = 0;
|
|
|
|
y += image->height() + MARGIN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2019-04-30 16:18:54 +00:00
|
|
|
float matrix[20] = { 1, 0, 0, 0, 0,
|
|
|
|
0, 1, 0, 0, 0,
|
|
|
|
0, 0, 1, 0, 0,
|
|
|
|
0, 0, 0, 1, 0 };
|
2019-04-17 20:03:30 +00:00
|
|
|
|
|
|
|
SkRect srcRect = SkRect::MakeWH(SkIntToScalar(fBitmap->width()),
|
|
|
|
SkIntToScalar(fBitmap->height()));
|
|
|
|
SkRect dstRect = SkRect::MakeWH(SkIntToScalar(fBitmap->width() * 2),
|
|
|
|
SkIntToScalar(fBitmap->height() * 2));
|
2019-08-02 19:21:23 +00:00
|
|
|
sk_sp<SkImageFilter> tile(SkImageFilters::Tile(srcRect, dstRect, nullptr));
|
2019-04-30 16:18:54 +00:00
|
|
|
sk_sp<SkColorFilter> cf(SkColorFilters::Matrix(matrix));
|
2019-04-17 20:03:30 +00:00
|
|
|
|
|
|
|
SkPaint paint;
|
2019-08-02 19:21:23 +00:00
|
|
|
paint.setImageFilter(SkImageFilters::ColorFilter(std::move(cf), std::move(tile)));
|
Make SkImageFilter crop rects relative to the primitive origin, instead of relative to their parent's crop rect. This is required by SVG semantics, and is more sane anyway.
To do this, this patch changes the "offset/loc" parameter in filterImage() / onFilterImage() from an inout-param to an out-param only, so that the calling filter can know how much the input filter wants its result offset (and doesn't include the original primitive position). This offset can then be applied to the current filter's crop rect. (I've renamed the parameter "offset" in all cases to make this clear.) This makes the call sites in SkCanvas/SkGpuDevice responsible for applying the resulting offset to the primitive's position, which is actually a fairly small change.
This change also fixes SkTileImageFilter and SkOffsetImageFilter to correctly handle an input offset, which they weren't before. This required modifying the GM's, since they assumed the broken behaviour.
NOTE: this will require rebaselining the imagefiltersgraph test, since it has a new test case.
NOTE: this will "break" the Blink layout tests css3/filters/effect-reference-subregion-chained-hw.html and css3/filters/effect-reference-subregion-hw.html, but it actually makes them give correct results. It should be suppressed on the skia roll, and I'll rebaseline it.
R=reed@google.com
Review URL: https://codereview.chromium.org/112803004
git-svn-id: http://skia.googlecode.com/svn/trunk@12895 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-03 21:48:22 +00:00
|
|
|
canvas->save();
|
|
|
|
canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
|
2019-04-17 20:03:30 +00:00
|
|
|
canvas->clipRect(dstRect);
|
|
|
|
canvas->saveLayer(&dstRect, &paint);
|
|
|
|
canvas->drawImage(fBitmap.get(), 0, 0);
|
|
|
|
canvas->restore();
|
2016-01-11 22:09:09 +00:00
|
|
|
canvas->drawRect(srcRect, red);
|
|
|
|
canvas->drawRect(dstRect, blue);
|
Make SkImageFilter crop rects relative to the primitive origin, instead of relative to their parent's crop rect. This is required by SVG semantics, and is more sane anyway.
To do this, this patch changes the "offset/loc" parameter in filterImage() / onFilterImage() from an inout-param to an out-param only, so that the calling filter can know how much the input filter wants its result offset (and doesn't include the original primitive position). This offset can then be applied to the current filter's crop rect. (I've renamed the parameter "offset" in all cases to make this clear.) This makes the call sites in SkCanvas/SkGpuDevice responsible for applying the resulting offset to the primitive's position, which is actually a fairly small change.
This change also fixes SkTileImageFilter and SkOffsetImageFilter to correctly handle an input offset, which they weren't before. This required modifying the GM's, since they assumed the broken behaviour.
NOTE: this will require rebaselining the imagefiltersgraph test, since it has a new test case.
NOTE: this will "break" the Blink layout tests css3/filters/effect-reference-subregion-chained-hw.html and css3/filters/effect-reference-subregion-hw.html, but it actually makes them give correct results. It should be suppressed on the skia roll, and I'll rebaseline it.
R=reed@google.com
Review URL: https://codereview.chromium.org/112803004
git-svn-id: http://skia.googlecode.com/svn/trunk@12895 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-03 21:48:22 +00:00
|
|
|
canvas->restore();
|
Moving 4 SkImageFilter derived classes from blink to skia
There were 4 classes in blink that derived from SkImageFilter :
- TileImageFilter -> SkTileImageFilter
- OffsetImageFilter -> SkOffsetImageFilter (already existed)
- FloodImageFilter -> SkFloodImageFilter
- CompositeImageFilter -> SkCompositeImageFilter
All functions were copied as is, without modification (except for warnings fixes), except for the offset filter, which was merged into the existing SkOffsetImageFilter class, as a special case when a crop rect is provided. Since the names won't clash with the names in blink, it should be easy to integrate them in blink later and fix issues, if needed.
BUG=
R=senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, reed@google.com, mtklein@google.com
Author: sugoi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/24157005
git-svn-id: http://skia.googlecode.com/svn/trunk@11475 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-09-26 16:09:28 +00:00
|
|
|
}
|
2014-04-29 15:20:39 +00:00
|
|
|
|
2019-04-17 20:03:30 +00:00
|
|
|
// test that the crop rect properly applies to the tile image filter
|
|
|
|
{
|
|
|
|
canvas->translate(0, SkIntToScalar(100));
|
|
|
|
|
|
|
|
SkRect srcRect = SkRect::MakeXYWH(0, 0, 50, 50);
|
|
|
|
SkRect dstRect = SkRect::MakeXYWH(0, 0, 100, 100);
|
2019-08-02 19:21:23 +00:00
|
|
|
SkIRect cropRect = SkIRect::MakeXYWH(5, 5, 40, 40);
|
2019-04-17 20:03:30 +00:00
|
|
|
sk_sp<SkColorFilter> greenCF = SkColorFilters::Blend(SK_ColorGREEN, SkBlendMode::kSrc);
|
2019-08-02 19:21:23 +00:00
|
|
|
sk_sp<SkImageFilter> green(SkImageFilters::ColorFilter(std::move(greenCF),
|
2019-04-17 20:03:30 +00:00
|
|
|
nullptr,
|
|
|
|
&cropRect));
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorRED);
|
2019-08-02 19:21:23 +00:00
|
|
|
paint.setImageFilter(SkImageFilters::Tile(srcRect, dstRect, std::move(green)));
|
2019-04-17 20:03:30 +00:00
|
|
|
canvas->drawRect(dstRect, paint);
|
|
|
|
}
|
Moving 4 SkImageFilter derived classes from blink to skia
There were 4 classes in blink that derived from SkImageFilter :
- TileImageFilter -> SkTileImageFilter
- OffsetImageFilter -> SkOffsetImageFilter (already existed)
- FloodImageFilter -> SkFloodImageFilter
- CompositeImageFilter -> SkCompositeImageFilter
All functions were copied as is, without modification (except for warnings fixes), except for the offset filter, which was merged into the existing SkOffsetImageFilter class, as a special case when a crop rect is provided. Since the names won't clash with the names in blink, it should be easy to integrate them in blink later and fix issues, if needed.
BUG=
R=senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, reed@google.com, mtklein@google.com
Author: sugoi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/24157005
git-svn-id: http://skia.googlecode.com/svn/trunk@11475 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-09-26 16:09:28 +00:00
|
|
|
}
|
|
|
|
private:
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> fBitmap, fCheckerboard;
|
2015-06-08 13:21:14 +00:00
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GM;
|
Moving 4 SkImageFilter derived classes from blink to skia
There were 4 classes in blink that derived from SkImageFilter :
- TileImageFilter -> SkTileImageFilter
- OffsetImageFilter -> SkOffsetImageFilter (already existed)
- FloodImageFilter -> SkFloodImageFilter
- CompositeImageFilter -> SkCompositeImageFilter
All functions were copied as is, without modification (except for warnings fixes), except for the offset filter, which was merged into the existing SkOffsetImageFilter class, as a special case when a crop rect is provided. Since the names won't clash with the names in blink, it should be easy to integrate them in blink later and fix issues, if needed.
BUG=
R=senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, reed@google.com, mtklein@google.com
Author: sugoi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/24157005
git-svn-id: http://skia.googlecode.com/svn/trunk@11475 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-09-26 16:09:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_GM(return new TileImageFilterGM;)
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace skiagm
|