b7dad44040
This reverts commit6dc14ded91
. Reason for revert: add flag to google3 Original change's description: > Revert "hide drawlooper from paint" > > This reverts commit766b42b7ba
. > > Reason for revert: afaict this is changing a lot of image filter GMs for the worse > > Original change's description: > > hide drawlooper from paint > > > > Bug: skia: 4783 > > > > Change-Id: I1d0ad1683a2e8345d8ea13db9b69b568ada827dc > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/228573 > > Reviewed-by: Florin Malita <fmalita@chromium.org> > > Commit-Queue: Mike Reed <reed@google.com> > > TBR=fmalita@chromium.org,reed@google.com > > Change-Id: I0bfd48ada3f8e48a774527caccf7abdb7a1cc470 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia: 4783 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/229005 > Reviewed-by: Robert Phillips <robertphillips@google.com> > Commit-Queue: Robert Phillips <robertphillips@google.com> TBR=robertphillips@google.com,fmalita@chromium.org,reed@google.com Change-Id: Ib3cd8941a63cd323b8872dd7fec1c953ab81cbdc Bug: skia: 4783 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/229010 Commit-Queue: Mike Reed <reed@google.com> Reviewed-by: Mike Reed <reed@google.com>
109 lines
3.2 KiB
C++
109 lines
3.2 KiB
C++
/*
|
|
* Copyright 2011 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "gm/gm.h"
|
|
#include "include/core/SkBlendMode.h"
|
|
#include "include/core/SkBlurTypes.h"
|
|
#include "include/core/SkCanvas.h"
|
|
#include "include/core/SkColor.h"
|
|
#include "include/core/SkDrawLooper.h"
|
|
#include "include/core/SkFont.h"
|
|
#include "include/core/SkMaskFilter.h"
|
|
#include "include/core/SkPaint.h"
|
|
#include "include/core/SkPoint.h"
|
|
#include "include/core/SkRefCnt.h"
|
|
#include "include/core/SkScalar.h"
|
|
#include "include/core/SkSize.h"
|
|
#include "include/core/SkString.h"
|
|
#include "include/core/SkTypeface.h"
|
|
#include "include/core/SkTypes.h"
|
|
#include "include/effects/SkLayerDrawLooper.h"
|
|
#include "src/core/SkBlurMask.h"
|
|
#include "tools/ToolUtils.h"
|
|
|
|
#ifdef SK_SUPPORT_LEGACY_DRAWLOOPER
|
|
|
|
#define WIDTH 200
|
|
#define HEIGHT 200
|
|
|
|
class DrawLooperGM : public skiagm::GM {
|
|
public:
|
|
DrawLooperGM() : fLooper(nullptr) {
|
|
this->setBGColor(0xFFDDDDDD);
|
|
}
|
|
|
|
protected:
|
|
virtual SkISize onISize() override {
|
|
return SkISize::Make(520, 160);
|
|
}
|
|
|
|
SkString onShortName() override {
|
|
return SkString("drawlooper");
|
|
}
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
this->init();
|
|
|
|
SkPaint paint;
|
|
paint.setAntiAlias(true);
|
|
paint.setLooper(fLooper);
|
|
|
|
SkFont font(ToolUtils::create_portable_typeface(), 72);
|
|
|
|
canvas->drawCircle(50, 50, 30, paint);
|
|
canvas->drawRect({ 150, 50, 200, 100 }, paint);
|
|
canvas->drawString("Looper", 230, 100, font, paint);
|
|
}
|
|
|
|
private:
|
|
sk_sp<SkDrawLooper> fLooper;
|
|
|
|
void init() {
|
|
if (fLooper) return;
|
|
|
|
constexpr struct {
|
|
SkColor fColor;
|
|
SkPaint::Style fStyle;
|
|
SkScalar fWidth;
|
|
SkScalar fOffset;
|
|
SkScalar fBlur;
|
|
} gParams[] = {
|
|
{ SK_ColorWHITE, SkPaint::kStroke_Style, SkIntToScalar(1)*3/4, 0, 0 },
|
|
{ SK_ColorRED, SkPaint::kStroke_Style, SkIntToScalar(4), 0, 0 },
|
|
{ SK_ColorBLUE, SkPaint::kFill_Style, 0, 0, 0 },
|
|
{ 0x88000000, SkPaint::kFill_Style, 0, SkIntToScalar(10), SkIntToScalar(3) }
|
|
};
|
|
|
|
SkLayerDrawLooper::Builder looperBuilder;
|
|
|
|
SkLayerDrawLooper::LayerInfo info;
|
|
info.fPaintBits = SkLayerDrawLooper::kStyle_Bit | SkLayerDrawLooper::kMaskFilter_Bit;
|
|
info.fColorMode = SkBlendMode::kSrc;
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gParams); i++) {
|
|
info.fOffset.set(gParams[i].fOffset, gParams[i].fOffset);
|
|
SkPaint* paint = looperBuilder.addLayer(info);
|
|
paint->setColor(gParams[i].fColor);
|
|
paint->setStyle(gParams[i].fStyle);
|
|
paint->setStrokeWidth(gParams[i].fWidth);
|
|
if (gParams[i].fBlur > 0) {
|
|
paint->setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle,
|
|
SkBlurMask::ConvertRadiusToSigma(gParams[i].fBlur)));
|
|
}
|
|
}
|
|
fLooper = looperBuilder.detach();
|
|
}
|
|
|
|
typedef GM INHERITED;
|
|
};
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
DEF_GM( return new DrawLooperGM; )
|
|
|
|
#endif
|