skia2/samplecode/SampleEffects.cpp
Ben Wagner 3ae1a307f6 Revert "Alloc glyph image correctly for SkMask::k3D_Format."
This reverts commit 6b26deb8d6.

Reason for revert: GPU bots failing

Original change's description:
> Alloc glyph image correctly for SkMask::k3D_Format.
> 
> This removes the no longer used outside Skia
> SK_SUPPORT_LEGACY_EMBOSSMASKFILTER define, and either deletes the code
> it guards or updates it to use the new emboss mask filter factory. This
> re-enables the code to test the emboss mask filter. Also added is a test
> to ensure that embossed text is drawn correctly, as before this glyphs
> did not allocate the proper amount of memory for the k3D_Format which
> this mask filter produces. This also fixes SkEmbossMask::Emboss to write
> the whole of the mul and add planes to avoid pixel differences and
> MemorySanitizer errors.
> 
> Change-Id: Ib492c72a19d6a27d140e3cd48179a3ca9ce313f5
> Reviewed-on: https://skia-review.googlesource.com/70260
> Commit-Queue: Ben Wagner <bungeman@google.com>
> Reviewed-by: Herb Derby <herb@google.com>

TBR=djsollen@google.com,bungeman@google.com,herb@google.com,reed@google.com

Change-Id: I8a9db6c00e0cb84bdd4833474a9ffffa6ecc606c
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/70920
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
2017-11-13 20:43:06 +00:00

122 lines
3.1 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 "SampleCode.h"
#include "SkBlurMask.h"
#include "SkBlurMaskFilter.h"
#include "SkCanvas.h"
#include "SkColorMatrixFilter.h"
#include "SkDiscretePathEffect.h"
#include "SkGradientShader.h"
#include "SkPaint.h"
#include "SkView.h"
//#define COLOR 0xFFFF8844
#define COLOR 0xFF888888
static void paint_proc0(SkPaint*) {
}
static void paint_proc1(SkPaint* paint) {
paint->setMaskFilter(SkBlurMaskFilter::Make(
kNormal_SkBlurStyle,
SkBlurMask::ConvertRadiusToSigma(2)));
}
static void paint_proc2(SkPaint* paint) {
#ifdef SK_SUPPORT_LEGACY_EMBOSSMASKFILTER
SkScalar dir[3] = { 1, 1, 1};
paint->setMaskFilter(
SkBlurMaskFilter::MakeEmboss(SkBlurMask::ConvertRadiusToSigma(1), dir, 0.1f, 0.05f));
#endif
}
static void paint_proc3(SkPaint* paint) {
SkColor colors[] = { SK_ColorRED, COLOR, SK_ColorBLUE };
SkPoint pts[] = { { 3, 0 }, { 7, 5 } };
paint->setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
SkShader::kMirror_TileMode));
}
static void paint_proc5(SkPaint* paint) {
paint_proc3(paint);
paint_proc2(paint);
}
typedef void (*PaintProc)(SkPaint*);
const PaintProc gPaintProcs[] = {
paint_proc0,
paint_proc1,
paint_proc2,
paint_proc3,
paint_proc5,
};
///////////////////////////////////////////////////////////////////////////////
class EffectsView : public SampleView {
public:
SkPath fPath;
SkPaint fPaint[SK_ARRAY_COUNT(gPaintProcs)];
EffectsView() {
size_t i;
const float pts[] = {
0, 0,
10, 0,
10, 5,
20, -5,
10, -15,
10, -10,
0, -10
};
fPath.moveTo(pts[0], pts[1]);
for (i = 2; i < SK_ARRAY_COUNT(pts); i += 2) {
fPath.lineTo(pts[i], pts[i+1]);
}
for (i = 0; i < SK_ARRAY_COUNT(gPaintProcs); i++) {
fPaint[i].setAntiAlias(true);
fPaint[i].setColor(COLOR);
gPaintProcs[i](&fPaint[i]);
}
SkColorMatrix cm;
cm.setRotate(SkColorMatrix::kG_Axis, 180);
cm.setIdentity();
this->setBGColor(0xFFDDDDDD);
}
protected:
// overrides from SkEventSink
virtual bool onQuery(SkEvent* evt) {
if (SampleCode::TitleQ(*evt)) {
SampleCode::TitleR(evt, "Effects");
return true;
}
return this->INHERITED::onQuery(evt);
}
virtual void onDrawContent(SkCanvas* canvas) {
canvas->scale(3, 3);
canvas->translate(10, 30);
for (size_t i = 0; i < SK_ARRAY_COUNT(fPaint); i++) {
canvas->drawPath(fPath, fPaint[i]);
canvas->translate(32, 0);
}
}
private:
typedef SampleView INHERITED;
};
///////////////////////////////////////////////////////////////////////////////
static SkView* MyFactory() { return new EffectsView; }
static SkViewRegister reg(MyFactory);