Make texteffects gm work through serialization and pipe.

Move Line2DPathEffect (now Sk_) into a separate header file so it can
be shared and initialized.

Switch to the shared version in SampleAll and SampleSlides.

Remove the skip pipe flag from texteffects, since it can now be serialized.

I have a separate change to turn serialization on by default at https://codereview.appspot.com/6498121/

Review URL: https://codereview.appspot.com/6503106

git-svn-id: http://skia.googlecode.com/svn/trunk@5512 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
scroggo@google.com 2012-09-12 18:53:49 +00:00
parent bfe1572f24
commit d8a6cc814f
7 changed files with 63 additions and 160 deletions

View File

@ -124,58 +124,13 @@ static void r8(SkLayerRasterizer* rast, SkPaint& p) {
rast->addLayer(p);
}
class Line2DPathEffect : public Sk2DPathEffect {
public:
Line2DPathEffect(SkScalar width, const SkMatrix& matrix)
: Sk2DPathEffect(matrix), fWidth(width) {}
virtual bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec* rec) SK_OVERRIDE {
if (this->INHERITED::filterPath(dst, src, rec)) {
rec->setStrokeStyle(fWidth);
return true;
}
return false;
}
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(Line2DPathEffect)
protected:
virtual void nextSpan(int u, int v, int ucount, SkPath* dst) {
if (ucount > 1) {
SkPoint src[2], dstP[2];
src[0].set(SkIntToScalar(u) + SK_ScalarHalf,
SkIntToScalar(v) + SK_ScalarHalf);
src[1].set(SkIntToScalar(u+ucount) + SK_ScalarHalf,
SkIntToScalar(v) + SK_ScalarHalf);
this->getMatrix().mapPoints(dstP, src, 2);
dst->moveTo(dstP[0]);
dst->lineTo(dstP[1]);
}
}
Line2DPathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {
fWidth = buffer.readScalar();
}
virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE {
this->INHERITED::flatten(buffer);
buffer.writeScalar(fWidth);
}
private:
SkScalar fWidth;
typedef Sk2DPathEffect INHERITED;
};
static void r9(SkLayerRasterizer* rast, SkPaint& p) {
rast->addLayer(p);
SkMatrix lattice;
lattice.setScale(SK_Scalar1, SK_Scalar1*6, 0, 0);
lattice.postRotate(SkIntToScalar(30), 0, 0);
p.setPathEffect(new Line2DPathEffect(SK_Scalar1*2, lattice))->unref();
p.setPathEffect(new SkLine2DPathEffect(SK_Scalar1*2, lattice))->unref();
p.setXfermodeMode(SkXfermode::kClear_Mode);
rast->addLayer(p);
@ -192,16 +147,6 @@ static const raster_proc gRastProcs[] = {
r0, r1, r2, r3, r4, r5, r6, r7, r8, r9
};
static const struct {
SkColor fMul, fAdd;
} gLightingColors[] = {
{ 0x808080, 0x800000 }, // general case
{ 0x707070, 0x707070 }, // no-pin case
{ 0xFFFFFF, 0x800000 }, // just-add case
{ 0x808080, 0x000000 }, // just-mul case
{ 0xFFFFFF, 0x000000 } // identity case
};
#include "SkXfermode.h"
static void apply_shader(SkPaint* paint, int index) {
@ -262,11 +207,6 @@ protected:
canvas->restore();
}
virtual uint32_t onGetFlags() const SK_OVERRIDE {
// want to skip serialization due to custom effects only defined here
return kSkipPipe_Flag;
}
private:
typedef skiagm::GM INHERITED;
};

View File

@ -58,6 +58,28 @@ private:
typedef SkPathEffect INHERITED;
};
class SkLine2DPathEffect : public Sk2DPathEffect {
public:
SkLine2DPathEffect(SkScalar width, const SkMatrix& matrix)
: Sk2DPathEffect(matrix), fWidth(width) {}
virtual bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec* rec) SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLine2DPathEffect)
protected:
virtual void nextSpan(int u, int v, int ucount, SkPath* dst) SK_OVERRIDE;
SkLine2DPathEffect(SkFlattenableReadBuffer&);
virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
private:
SkScalar fWidth;
typedef Sk2DPathEffect INHERITED;
};
class SkPath2DPathEffect : public Sk2DPathEffect {
public:
/**

View File

@ -206,60 +206,13 @@ static void r8(SkLayerRasterizer* rast, SkPaint& p) {
rast->addLayer(p);
}
class Line2DPathEffect : public Sk2DPathEffect {
public:
Line2DPathEffect(SkScalar width, const SkMatrix& matrix)
: Sk2DPathEffect(matrix), fWidth(width) {}
virtual bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec* rec) SK_OVERRIDE {
if (this->INHERITED::filterPath(dst, src, rec)) {
rec->setStrokeStyle(fWidth);
return true;
}
return false;
}
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(Line2DPathEffect)
protected:
virtual void nextSpan(int u, int v, int ucount, SkPath* dst) {
if (ucount > 1) {
SkPoint src[2], dstP[2];
src[0].set(SkIntToScalar(u) + SK_ScalarHalf,
SkIntToScalar(v) + SK_ScalarHalf);
src[1].set(SkIntToScalar(u+ucount) + SK_ScalarHalf,
SkIntToScalar(v) + SK_ScalarHalf);
this->getMatrix().mapPoints(dstP, src, 2);
dst->moveTo(dstP[0]);
dst->lineTo(dstP[1]);
}
}
Line2DPathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {
fWidth = buffer.readScalar();
}
virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE {
this->INHERITED::flatten(buffer);
buffer.writeScalar(fWidth);
}
private:
SkScalar fWidth;
typedef Sk2DPathEffect INHERITED;
};
SK_DEFINE_FLATTENABLE_REGISTRAR(Line2DPathEffect)
static void r9(SkLayerRasterizer* rast, SkPaint& p) {
rast->addLayer(p);
SkMatrix lattice;
lattice.setScale(SK_Scalar1, SK_Scalar1*6, 0, 0);
lattice.postRotate(SkIntToScalar(30), 0, 0);
p.setPathEffect(new Line2DPathEffect(SK_Scalar1*2, lattice))->unref();
p.setPathEffect(new SkLine2DPathEffect(SK_Scalar1*2, lattice))->unref();
p.setXfermodeMode(SkXfermode::kClear_Mode);
rast->addLayer(p);

View File

@ -598,54 +598,6 @@ static void r8(SkLayerRasterizer* rast, SkPaint& p)
rast->addLayer(p);
}
class Line2DPathEffect : public Sk2DPathEffect {
public:
Line2DPathEffect(SkScalar width, const SkMatrix& matrix)
: Sk2DPathEffect(matrix), fWidth(width) {}
virtual bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec* rec) SK_OVERRIDE {
if (this->INHERITED::filterPath(dst, src, rec)) {
rec->setStrokeStyle(fWidth);
return true;
}
return false;
}
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(Line2DPathEffect)
protected:
virtual void nextSpan(int u, int v, int ucount, SkPath* dst)
{
if (ucount > 1)
{
SkPoint src[2], dstP[2];
src[0].set(SkIntToScalar(u) + SK_ScalarHalf,
SkIntToScalar(v) + SK_ScalarHalf);
src[1].set(SkIntToScalar(u+ucount) + SK_ScalarHalf,
SkIntToScalar(v) + SK_ScalarHalf);
this->getMatrix().mapPoints(dstP, src, 2);
dst->moveTo(dstP[0]);
dst->lineTo(dstP[1]);
}
}
Line2DPathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer)
{
fWidth = buffer.readScalar();
}
virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE
{
this->INHERITED::flatten(buffer);
buffer.writeScalar(fWidth);
}
private:
SkScalar fWidth;
typedef Sk2DPathEffect INHERITED;
};
static void r9(SkLayerRasterizer* rast, SkPaint& p)
{
rast->addLayer(p);
@ -653,7 +605,7 @@ static void r9(SkLayerRasterizer* rast, SkPaint& p)
SkMatrix lattice;
lattice.setScale(SK_Scalar1, SK_Scalar1*6, 0, 0);
lattice.postRotate(SkIntToScalar(30), 0, 0);
p.setPathEffect(new Line2DPathEffect(SK_Scalar1*2, lattice))->unref();
p.setPathEffect(new SkLine2DPathEffect(SK_Scalar1*2, lattice))->unref();
p.setXfermodeMode(SkXfermode::kClear_Mode);
rast->addLayer(p);

View File

@ -221,7 +221,7 @@ void SkOrderedWriteBuffer::writeFlattenable(SkFlattenable* flattenable) {
this->writeFunctionPtr((void*)factory);
}
// make room for the size of the flatttened object
// make room for the size of the flattened object
(void)fWriter.reserve(sizeof(uint32_t));
// record the current size, so we can subtract after the object writes.
uint32_t offset = fWriter.size();

View File

@ -76,7 +76,42 @@ Sk2DPathEffect::Sk2DPathEffect(SkFlattenableReadBuffer& buffer) {
fMatrixIsInvertible = fMatrix.invert(&fInverse);
}
SK_DEFINE_FLATTENABLE_REGISTRAR(Sk2DPathEffect)
///////////////////////////////////////////////////////////////////////////////
bool SkLine2DPathEffect::filterPath(SkPath *dst, const SkPath &src, SkStrokeRec *rec) {
if (this->INHERITED::filterPath(dst, src, rec)) {
rec->setStrokeStyle(fWidth);
return true;
}
return false;
}
void SkLine2DPathEffect::nextSpan(int u, int v, int ucount, SkPath *dst) {
if (ucount > 1) {
SkPoint src[2], dstP[2];
src[0].set(SkIntToScalar(u) + SK_ScalarHalf, SkIntToScalar(v) + SK_ScalarHalf);
src[1].set(SkIntToScalar(u+ucount) + SK_ScalarHalf, SkIntToScalar(v) + SK_ScalarHalf);
this->getMatrix().mapPoints(dstP, src, 2);
dst->moveTo(dstP[0]);
dst->lineTo(dstP[1]);
}
}
SkLine2DPathEffect::SkLine2DPathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {
fWidth = buffer.readScalar();
}
void SkLine2DPathEffect::flatten(SkFlattenableWriteBuffer &buffer) const {
this->INHERITED::flatten(buffer);
buffer.writeScalar(fWidth);
}
SK_DEFINE_FLATTENABLE_REGISTRAR(SkLine2DPathEffect)
///////////////////////////////////////////////////////////////////////////////
SkPath2DPathEffect::SkPath2DPathEffect(const SkMatrix& m, const SkPath& p)

View File

@ -44,7 +44,6 @@
#include "SkLightingImageFilter.h"
#include "SkMagnifierImageFilter.h"
#include "SkMorphologyImageFilter.h"
#include "SkPathEffect.h"
#include "SkPixelXorXfermode.h"
#include "SkStippleMaskFilter.h"
#include "SkTableColorFilter.h"
@ -73,6 +72,8 @@ void SkFlattenable::InitializeFlattenables() {
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLayerDrawLooper)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLayerRasterizer)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPath1DPathEffect)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(Sk2DPathEffect)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLine2DPathEffect)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPath2DPathEffect)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPixelXorXfermode)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkStippleMaskFilter)