d6889293dd
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:
Review URL: https://codereview.chromium.org/1821103004
150 lines
5.2 KiB
C++
150 lines
5.2 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 "gm.h"
|
|
#include "SkColorFilter.h"
|
|
|
|
#include "SkColorFilterImageFilter.h"
|
|
#include "SkDropShadowImageFilter.h"
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
static void draw_paint(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
|
|
SkPaint paint;
|
|
paint.setImageFilter(imf);
|
|
paint.setColor(SK_ColorBLACK);
|
|
canvas->save();
|
|
canvas->clipRect(r);
|
|
canvas->drawPaint(paint);
|
|
canvas->restore();
|
|
}
|
|
|
|
static void draw_path(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
|
|
SkPaint paint;
|
|
paint.setColor(SK_ColorGREEN);
|
|
paint.setImageFilter(imf);
|
|
paint.setAntiAlias(true);
|
|
canvas->save();
|
|
canvas->clipRect(r);
|
|
canvas->drawCircle(r.centerX(), r.centerY(), r.width()/3, paint);
|
|
canvas->restore();
|
|
}
|
|
|
|
static void draw_text(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
|
|
SkPaint paint;
|
|
paint.setImageFilter(imf);
|
|
paint.setColor(SK_ColorGREEN);
|
|
paint.setAntiAlias(true);
|
|
sk_tool_utils::set_portable_typeface(&paint);
|
|
paint.setTextSize(r.height()/2);
|
|
paint.setTextAlign(SkPaint::kCenter_Align);
|
|
canvas->save();
|
|
canvas->clipRect(r);
|
|
canvas->drawText("Text", 4, r.centerX(), r.centerY(), paint);
|
|
canvas->restore();
|
|
}
|
|
|
|
static void draw_bitmap(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
|
|
SkPaint paint;
|
|
|
|
SkIRect bounds;
|
|
r.roundOut(&bounds);
|
|
|
|
SkBitmap bm;
|
|
bm.allocN32Pixels(bounds.width(), bounds.height());
|
|
bm.eraseColor(SK_ColorTRANSPARENT);
|
|
SkCanvas c(bm);
|
|
draw_path(&c, r, nullptr);
|
|
|
|
paint.setImageFilter(imf);
|
|
canvas->save();
|
|
canvas->clipRect(r);
|
|
canvas->drawBitmap(bm, 0, 0, &paint);
|
|
canvas->restore();
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
class DropShadowImageFilterGM : public skiagm::GM {
|
|
public:
|
|
DropShadowImageFilterGM () {}
|
|
|
|
protected:
|
|
|
|
virtual SkString onShortName() {
|
|
return SkString("dropshadowimagefilter");
|
|
}
|
|
|
|
virtual SkISize onISize() { return SkISize::Make(400, 656); }
|
|
|
|
void draw_frame(SkCanvas* canvas, const SkRect& r) {
|
|
SkPaint paint;
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
paint.setColor(SK_ColorRED);
|
|
canvas->drawRect(r, paint);
|
|
}
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
|
void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = {
|
|
draw_bitmap, draw_path, draw_paint, draw_text
|
|
};
|
|
|
|
SkAutoTUnref<SkColorFilter> cf(
|
|
SkColorFilter::CreateModeFilter(SK_ColorMAGENTA, SkXfermode::kSrcIn_Mode));
|
|
SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get()));
|
|
SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)),
|
|
SkImageFilter::CropRect::kHasAll_CropEdge);
|
|
SkImageFilter::CropRect bogusRect(SkRect::Make(SkIRect::MakeXYWH(-100, -100, 10, 10)),
|
|
SkImageFilter::CropRect::kHasAll_CropEdge);
|
|
|
|
SkImageFilter* filters[] = {
|
|
nullptr,
|
|
SkDropShadowImageFilter::Create(7.0f, 0.0f, 0.0f, 3.0f, SK_ColorBLUE,
|
|
SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode),
|
|
SkDropShadowImageFilter::Create(0.0f, 7.0f, 3.0f, 0.0f, SK_ColorBLUE,
|
|
SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode),
|
|
SkDropShadowImageFilter::Create(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE,
|
|
SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode),
|
|
SkDropShadowImageFilter::Create(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE,
|
|
SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, cfif, nullptr),
|
|
SkDropShadowImageFilter::Create(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE,
|
|
SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, nullptr, &cropRect),
|
|
SkDropShadowImageFilter::Create(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE,
|
|
SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, nullptr, &bogusRect),
|
|
SkDropShadowImageFilter::Create(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE,
|
|
SkDropShadowImageFilter::kDrawShadowOnly_ShadowMode),
|
|
};
|
|
|
|
SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64));
|
|
SkScalar MARGIN = SkIntToScalar(16);
|
|
SkScalar DX = r.width() + MARGIN;
|
|
SkScalar DY = r.height() + MARGIN;
|
|
|
|
canvas->translate(MARGIN, MARGIN);
|
|
for (size_t j = 0; j < SK_ARRAY_COUNT(drawProc); ++j) {
|
|
canvas->save();
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
|
|
drawProc[j](canvas, r, filters[i]);
|
|
canvas->translate(0, DY);
|
|
}
|
|
canvas->restore();
|
|
canvas->translate(DX, 0);
|
|
}
|
|
|
|
for(size_t j = 0; j < SK_ARRAY_COUNT(filters); ++j) {
|
|
SkSafeUnref(filters[j]);
|
|
}
|
|
}
|
|
|
|
private:
|
|
typedef GM INHERITED;
|
|
};
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
DEF_GM( return new DropShadowImageFilterGM; )
|