d053ce9c54
Reason for revert:
guard has now landed in chrome
Original issue's description:
> Revert of Revert[2] of "switch colorfilters to sk_sp (patchset #11 id:200001 of https://codereview.chromium.o… (patchset #3 id:40001 of https://codereview.chromium.org/1825073002/ )
>
> Reason for revert:
> CreateModeFilter not compiling
>
> Original issue's description:
> > Revert[2] of "switch colorfilters to sk_sp (patchset #11 id:200001 of https://codereview.chromium.org/1822623002/ )"
> >
> > Fixed legacy withColorFilter to call new(er) make method
> >
> > This reverts commit 1eb81db650
.
> >
> > BUG=skia:
> > GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1825073002
> >
> > TBR=
> >
> > Committed: https://skia.googlesource.com/skia/+/4c9776b046dd5e9e46e2d1ce35154855c8fcb381
>
> TBR=
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=skia:
>
> Committed: https://skia.googlesource.com/skia/+/d6889293dd0942f27f9593f679722c956831f2c4
TBR=
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=skia:
Review URL: https://codereview.chromium.org/1827433002
121 lines
4.4 KiB
C++
121 lines
4.4 KiB
C++
/*
|
|
* Copyright 2013 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "sk_tool_utils.h"
|
|
#include "SkColorFilterImageFilter.h"
|
|
#include "SkColorMatrixFilter.h"
|
|
#include "SkImage.h"
|
|
#include "SkImageSource.h"
|
|
#include "SkTileImageFilter.h"
|
|
#include "gm.h"
|
|
|
|
#define WIDTH 400
|
|
#define HEIGHT 100
|
|
#define MARGIN 12
|
|
|
|
namespace skiagm {
|
|
|
|
class TileImageFilterGM : public GM {
|
|
public:
|
|
TileImageFilterGM() {
|
|
this->setBGColor(0xFF000000);
|
|
}
|
|
|
|
protected:
|
|
SkString onShortName() override {
|
|
return SkString("tileimagefilter");
|
|
}
|
|
|
|
SkISize onISize() override{
|
|
return SkISize::Make(WIDTH, HEIGHT);
|
|
}
|
|
|
|
void onOnceBeforeDraw() override {
|
|
fBitmap = SkImage::MakeFromBitmap(
|
|
sk_tool_utils::create_string_bitmap(50, 50, 0xD000D000, 10, 45, 50, "e"));
|
|
|
|
fCheckerboard = SkImage::MakeFromBitmap(
|
|
sk_tool_utils::create_checkerboard_bitmap(80, 80,
|
|
sk_tool_utils::color_to_565(0xFFA0A0A0),
|
|
sk_tool_utils::color_to_565(0xFF404040),
|
|
8));
|
|
}
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
canvas->clear(SK_ColorBLACK);
|
|
SkPaint red;
|
|
red.setColor(SK_ColorRED);
|
|
red.setStyle(SkPaint::kStroke_Style);
|
|
SkPaint blue;
|
|
blue.setColor(SK_ColorBLUE);
|
|
blue.setStyle(SkPaint::kStroke_Style);
|
|
|
|
int x = 0, y = 0;
|
|
for (size_t i = 0; i < 4; i++) {
|
|
SkImage* image = (i & 0x01) ? fCheckerboard.get() : fBitmap.get();
|
|
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);
|
|
SkAutoTUnref<SkImageFilter> tileInput(SkImageSource::Create(image));
|
|
SkAutoTUnref<SkImageFilter> filter(
|
|
SkTileImageFilter::Create(srcRect, dstRect, tileInput));
|
|
canvas->save();
|
|
canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
|
|
SkPaint paint;
|
|
paint.setImageFilter(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;
|
|
}
|
|
}
|
|
|
|
SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0,
|
|
0, SK_Scalar1, 0, 0, 0,
|
|
0, 0, SK_Scalar1, 0, 0,
|
|
0, 0, 0, SK_Scalar1, 0 };
|
|
|
|
SkRect srcRect = SkRect::MakeWH(SkIntToScalar(fBitmap->width()),
|
|
SkIntToScalar(fBitmap->height()));
|
|
SkRect dstRect = SkRect::MakeWH(SkIntToScalar(fBitmap->width() * 2),
|
|
SkIntToScalar(fBitmap->height() * 2));
|
|
SkAutoTUnref<SkImageFilter> tile(SkTileImageFilter::Create(srcRect, dstRect, nullptr));
|
|
auto cf(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
|
|
|
|
SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get(), tile.get()));
|
|
SkPaint paint;
|
|
paint.setImageFilter(cfif);
|
|
canvas->save();
|
|
canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
|
|
canvas->clipRect(dstRect);
|
|
canvas->saveLayer(&dstRect, &paint);
|
|
canvas->drawImage(fBitmap.get(), 0, 0);
|
|
canvas->restore();
|
|
canvas->drawRect(srcRect, red);
|
|
canvas->drawRect(dstRect, blue);
|
|
canvas->restore();
|
|
}
|
|
private:
|
|
sk_sp<SkImage> fBitmap, fCheckerboard;
|
|
|
|
typedef GM INHERITED;
|
|
};
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
DEF_GM(return new TileImageFilterGM;)
|
|
}
|