SkRecord: text blobs

Other text as blobs to follow.

https://gold.skia.org/search2?issue=1417703009&unt=true&query=source_type%3Dgm&master=false&include=true

BUG=skia:

Review URL: https://codereview.chromium.org/1417703009
This commit is contained in:
mtklein 2015-11-04 08:19:24 -08:00 committed by Commit bot
parent 7f97a76b80
commit 81919d3c67
3 changed files with 115 additions and 69 deletions

View File

@ -20,6 +20,7 @@
#include "SkRemote.h"
#include "SkShader.h"
#include "SkTHash.h"
#include "SkTextBlob.h"
namespace SkRemote {
@ -358,6 +359,22 @@ namespace SkRemote {
}
}
void onDrawTextBlob(const SkTextBlob* text,
SkScalar x,
SkScalar y,
const SkPaint& paint) override {
SkPoint offset{x,y};
auto t = this->id(text);
auto common = this->commonIDs(paint);
if (paint.getStyle() == SkPaint::kFill_Style) {
fEncoder->fillText(t, offset, common);
} else {
// TODO: handle kStrokeAndFill_Style
fEncoder->strokeText(t, offset, common, this->id(Stroke::CreateFrom(paint)));
}
}
void onDrawText(const void* text, size_t byteLength,
SkScalar x, SkScalar y, const SkPaint& paint) override {
// Text-as-paths is a temporary hack.
@ -432,19 +449,20 @@ namespace SkRemote {
}
#define O override
ID define(const SkMatrix& v) O {return this->define(Type::kMatrix, &fMatrix, v);}
ID define(const Misc& v) O {return this->define(Type::kMisc, &fMisc, v);}
ID define(const SkPath& v) O {return this->define(Type::kPath, &fPath, v);}
ID define(const Stroke& v) O {return this->define(Type::kStroke, &fStroke, v);}
ID define(SkPathEffect* v) O {return this->define(Type::kPathEffect, &fPathEffect, v);}
ID define(SkShader* v) O {return this->define(Type::kShader, &fShader, v);}
ID define(SkXfermode* v) O {return this->define(Type::kXfermode, &fXfermode, v);}
ID define(SkMaskFilter* v) O {return this->define(Type::kMaskFilter, &fMaskFilter, v);}
ID define(SkColorFilter* v) O {return this->define(Type::kColorFilter, &fColorFilter, v);}
ID define(SkRasterizer* v) O {return this->define(Type::kRasterizer, &fRasterizer, v);}
ID define(SkDrawLooper* v) O {return this->define(Type::kDrawLooper, &fDrawLooper, v);}
ID define(SkImageFilter* v) O {return this->define(Type::kImageFilter, &fImageFilter, v);}
ID define(SkAnnotation* v) O {return this->define(Type::kAnnotation, &fAnnotation, v);}
ID define(const SkMatrix& v)O{return this->define(Type::kMatrix, &fMatrix, v);}
ID define(const Misc& v)O{return this->define(Type::kMisc, &fMisc, v);}
ID define(const SkPath& v)O{return this->define(Type::kPath, &fPath, v);}
ID define(const Stroke& v)O{return this->define(Type::kStroke, &fStroke, v);}
ID define(const SkTextBlob* v)O{return this->define(Type::kTextBlob, &fTextBlob, v);}
ID define(SkPathEffect* v)O{return this->define(Type::kPathEffect, &fPathEffect, v);}
ID define(SkShader* v)O{return this->define(Type::kShader, &fShader, v);}
ID define(SkXfermode* v)O{return this->define(Type::kXfermode, &fXfermode, v);}
ID define(SkMaskFilter* v)O{return this->define(Type::kMaskFilter, &fMaskFilter, v);}
ID define(SkColorFilter* v)O{return this->define(Type::kColorFilter, &fColorFilter, v);}
ID define(SkRasterizer* v)O{return this->define(Type::kRasterizer, &fRasterizer, v);}
ID define(SkDrawLooper* v)O{return this->define(Type::kDrawLooper, &fDrawLooper, v);}
ID define(SkImageFilter* v)O{return this->define(Type::kImageFilter, &fImageFilter, v);}
ID define(SkAnnotation* v)O{return this->define(Type::kAnnotation, &fAnnotation, v);}
#undef O
@ -454,6 +472,7 @@ namespace SkRemote {
case Type::kMisc: return fMisc .remove(id);
case Type::kPath: return fPath .remove(id);
case Type::kStroke: return fStroke .remove(id);
case Type::kTextBlob: return fTextBlob .remove(id);
case Type::kPathEffect: return fPathEffect .remove(id);
case Type::kShader: return fShader .remove(id);
case Type::kXfermode: return fXfermode .remove(id);
@ -506,6 +525,18 @@ namespace SkRemote {
fStroke.find(stroke).applyTo(&paint);
fCanvas->drawPath(fPath.find(path), paint);
}
void fillText(ID text, SkPoint offset, CommonIDs common) override {
SkPaint paint;
paint.setStyle(SkPaint::kFill_Style);
this->applyCommon(common, &paint);
fCanvas->drawTextBlob(fTextBlob.find(text), offset.x(), offset.y(), paint);
}
void strokeText(ID text, SkPoint offset, CommonIDs common, ID stroke) override {
SkPaint paint;
this->applyCommon(common, &paint);
fStroke.find(stroke).applyTo(&paint);
fCanvas->drawTextBlob(fTextBlob.find(text), offset.x(), offset.y(), paint);
}
// Maps ID -> T.
template <typename T, Type kType>
@ -572,19 +603,20 @@ namespace SkRemote {
};
IDMap<SkMatrix , Type::kMatrix > fMatrix;
IDMap<Misc , Type::kMisc > fMisc;
IDMap<SkPath , Type::kPath > fPath;
IDMap<Stroke , Type::kStroke > fStroke;
ReffedIDMap<SkPathEffect , Type::kPathEffect > fPathEffect;
ReffedIDMap<SkShader , Type::kShader > fShader;
ReffedIDMap<SkXfermode , Type::kXfermode > fXfermode;
ReffedIDMap<SkMaskFilter , Type::kMaskFilter > fMaskFilter;
ReffedIDMap<SkColorFilter, Type::kColorFilter> fColorFilter;
ReffedIDMap<SkRasterizer , Type::kRasterizer > fRasterizer;
ReffedIDMap<SkDrawLooper , Type::kDrawLooper > fDrawLooper;
ReffedIDMap<SkImageFilter, Type::kImageFilter> fImageFilter;
ReffedIDMap<SkAnnotation , Type::kAnnotation > fAnnotation;
IDMap<SkMatrix , Type::kMatrix > fMatrix;
IDMap<Misc , Type::kMisc > fMisc;
IDMap<SkPath , Type::kPath > fPath;
IDMap<Stroke , Type::kStroke > fStroke;
ReffedIDMap<const SkTextBlob, Type::kTextBlob > fTextBlob;
ReffedIDMap<SkPathEffect , Type::kPathEffect > fPathEffect;
ReffedIDMap<SkShader , Type::kShader > fShader;
ReffedIDMap<SkXfermode , Type::kXfermode > fXfermode;
ReffedIDMap<SkMaskFilter , Type::kMaskFilter > fMaskFilter;
ReffedIDMap<SkColorFilter , Type::kColorFilter> fColorFilter;
ReffedIDMap<SkRasterizer , Type::kRasterizer > fRasterizer;
ReffedIDMap<SkDrawLooper , Type::kDrawLooper > fDrawLooper;
ReffedIDMap<SkImageFilter , Type::kImageFilter> fImageFilter;
ReffedIDMap<SkAnnotation , Type::kAnnotation > fAnnotation;
SkCanvas* fCanvas;
uint64_t fNextID = 0;
@ -610,8 +642,9 @@ namespace SkRemote {
fMatrix .foreach(undef);
fMisc .foreach(undef);
fPath .foreach(undef);
fPathEffect .foreach(undef);
fStroke .foreach(undef);
fTextBlob .foreach(undef);
fPathEffect .foreach(undef);
fShader .foreach(undef);
fXfermode .foreach(undef);
fMaskFilter .foreach(undef);
@ -632,19 +665,20 @@ namespace SkRemote {
return id;
}
ID define(const SkMatrix& v) override { return this->define(&fMatrix , v); }
ID define(const Misc& v) override { return this->define(&fMisc , v); }
ID define(const SkPath& v) override { return this->define(&fPath , v); }
ID define(const Stroke& v) override { return this->define(&fStroke , v); }
ID define(SkPathEffect* v) override { return this->define(&fPathEffect , v); }
ID define(SkShader* v) override { return this->define(&fShader , v); }
ID define(SkXfermode* v) override { return this->define(&fXfermode , v); }
ID define(SkMaskFilter* v) override { return this->define(&fMaskFilter , v); }
ID define(SkColorFilter* v) override { return this->define(&fColorFilter, v); }
ID define(SkRasterizer* v) override { return this->define(&fRasterizer , v); }
ID define(SkDrawLooper* v) override { return this->define(&fDrawLooper , v); }
ID define(SkImageFilter* v) override { return this->define(&fImageFilter, v); }
ID define(SkAnnotation* v) override { return this->define(&fAnnotation , v); }
ID define(const SkMatrix& v) override { return this->define(&fMatrix , v); }
ID define(const Misc& v) override { return this->define(&fMisc , v); }
ID define(const SkPath& v) override { return this->define(&fPath , v); }
ID define(const Stroke& v) override { return this->define(&fStroke , v); }
ID define(const SkTextBlob* v) override { return this->define(&fTextBlob , v); }
ID define(SkPathEffect* v) override { return this->define(&fPathEffect , v); }
ID define(SkShader* v) override { return this->define(&fShader , v); }
ID define(SkXfermode* v) override { return this->define(&fXfermode , v); }
ID define(SkMaskFilter* v) override { return this->define(&fMaskFilter , v); }
ID define(SkColorFilter* v) override { return this->define(&fColorFilter, v); }
ID define(SkRasterizer* v) override { return this->define(&fRasterizer , v); }
ID define(SkDrawLooper* v) override { return this->define(&fDrawLooper , v); }
ID define(SkImageFilter* v) override { return this->define(&fImageFilter, v); }
ID define(SkAnnotation* v) override { return this->define(&fAnnotation , v); }
void undefine(ID) override {}
@ -665,6 +699,12 @@ namespace SkRemote {
void strokePath(ID path, CommonIDs common, ID stroke) override {
fWrapped->strokePath(path, common, stroke);
}
void fillText(ID text, SkPoint offset, CommonIDs common) override {
fWrapped->fillText(text, offset, common);
}
void strokeText(ID text, SkPoint offset, CommonIDs common, ID stroke) override {
fWrapped->strokeText(text, offset, common, stroke);
}
// Maps const T* -> ID, and refs the key.
template <typename T, Type kType>
@ -695,19 +735,20 @@ namespace SkRemote {
SkTHashMap<const T*, ID> fMap;
};
SkTHashMap<SkMatrix, ID> fMatrix;
SkTHashMap<Misc, ID, MiscHash> fMisc;
SkTHashMap<SkPath, ID> fPath;
SkTHashMap<Stroke, ID> fStroke;
RefKeyMap<SkPathEffect , Type::kPathEffect > fPathEffect;
RefKeyMap<SkShader , Type::kShader > fShader;
RefKeyMap<SkXfermode , Type::kXfermode > fXfermode;
RefKeyMap<SkMaskFilter , Type::kMaskFilter > fMaskFilter;
RefKeyMap<SkColorFilter, Type::kColorFilter> fColorFilter;
RefKeyMap<SkRasterizer , Type::kRasterizer > fRasterizer;
RefKeyMap<SkDrawLooper , Type::kDrawLooper > fDrawLooper;
RefKeyMap<SkImageFilter, Type::kImageFilter> fImageFilter;
RefKeyMap<SkAnnotation , Type::kAnnotation > fAnnotation;
SkTHashMap<SkMatrix, ID> fMatrix;
SkTHashMap<Misc, ID, MiscHash> fMisc;
SkTHashMap<SkPath, ID> fPath;
SkTHashMap<Stroke, ID> fStroke;
RefKeyMap<const SkTextBlob, Type::kTextBlob > fTextBlob;
RefKeyMap<SkPathEffect , Type::kPathEffect > fPathEffect;
RefKeyMap<SkShader , Type::kShader > fShader;
RefKeyMap<SkXfermode , Type::kXfermode > fXfermode;
RefKeyMap<SkMaskFilter , Type::kMaskFilter > fMaskFilter;
RefKeyMap<SkColorFilter , Type::kColorFilter> fColorFilter;
RefKeyMap<SkRasterizer , Type::kRasterizer > fRasterizer;
RefKeyMap<SkDrawLooper , Type::kDrawLooper > fDrawLooper;
RefKeyMap<SkImageFilter , Type::kImageFilter> fImageFilter;
RefKeyMap<SkAnnotation , Type::kAnnotation > fAnnotation;
Encoder* fWrapped;
};

View File

@ -17,6 +17,7 @@ class SkCanvas;
class SkMatrix;
class SkPath;
class SkShader;
class SkTextBlob;
class SkXfermode;
// TODO: document
@ -65,19 +66,20 @@ namespace SkRemote {
struct Encoder {
virtual ~Encoder() {}
virtual ID define(const SkMatrix&) = 0;
virtual ID define(const Misc&) = 0;
virtual ID define(const SkPath&) = 0;
virtual ID define(const Stroke&) = 0;
virtual ID define(SkPathEffect*) = 0;
virtual ID define(SkShader*) = 0;
virtual ID define(SkXfermode*) = 0;
virtual ID define(SkMaskFilter*) = 0;
virtual ID define(SkColorFilter*) = 0;
virtual ID define(SkRasterizer*) = 0;
virtual ID define(SkDrawLooper*) = 0;
virtual ID define(SkImageFilter*) = 0;
virtual ID define(SkAnnotation*) = 0;
virtual ID define(const SkMatrix&) = 0;
virtual ID define(const Misc&) = 0;
virtual ID define(const SkPath&) = 0;
virtual ID define(const Stroke&) = 0;
virtual ID define(const SkTextBlob*) = 0;
virtual ID define(SkPathEffect*) = 0;
virtual ID define(SkShader*) = 0;
virtual ID define(SkXfermode*) = 0;
virtual ID define(SkMaskFilter*) = 0;
virtual ID define(SkColorFilter*) = 0;
virtual ID define(SkRasterizer*) = 0;
virtual ID define(SkDrawLooper*) = 0;
virtual ID define(SkImageFilter*) = 0;
virtual ID define(SkAnnotation*) = 0;
virtual void undefine(ID) = 0;
@ -93,9 +95,11 @@ namespace SkRemote {
virtual void setMatrix(ID matrix) = 0;
virtual void clipPath(ID path, SkRegion::Op, bool aa) = 0;
virtual void fillPath(ID path, CommonIDs) = 0;
virtual void strokePath(ID path, CommonIDs, ID stroke) = 0;
virtual void clipPath(ID path, SkRegion::Op, bool aa) = 0;
virtual void fillPath(ID path, CommonIDs) = 0;
virtual void strokePath(ID path, CommonIDs, ID stroke) = 0;
virtual void fillText(ID text, SkPoint, CommonIDs) = 0;
virtual void strokeText(ID text, SkPoint, CommonIDs, ID stroke) = 0;
};
// None of these factories take ownership of their arguments.

View File

@ -19,6 +19,7 @@ namespace SkRemote {
kMisc,
kPath,
kStroke,
kTextBlob,
kPathEffect,
kShader,
kXfermode,