From 81919d3c67c5cb74e6ff229d185e4508a9b03ef9 Mon Sep 17 00:00:00 2001 From: mtklein Date: Wed, 4 Nov 2015 08:19:24 -0800 Subject: [PATCH] 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 --- src/core/SkRemote.cpp | 147 ++++++++++++++++++++++------------- src/core/SkRemote.h | 36 +++++---- src/core/SkRemote_protocol.h | 1 + 3 files changed, 115 insertions(+), 69 deletions(-) diff --git a/src/core/SkRemote.cpp b/src/core/SkRemote.cpp index 236a1a8c24..1209be014c 100644 --- a/src/core/SkRemote.cpp +++ b/src/core/SkRemote.cpp @@ -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 @@ -572,19 +603,20 @@ namespace SkRemote { }; - IDMap fMatrix; - IDMap fMisc; - IDMap fPath; - IDMap fStroke; - ReffedIDMap fPathEffect; - ReffedIDMap fShader; - ReffedIDMap fXfermode; - ReffedIDMap fMaskFilter; - ReffedIDMap fColorFilter; - ReffedIDMap fRasterizer; - ReffedIDMap fDrawLooper; - ReffedIDMap fImageFilter; - ReffedIDMap fAnnotation; + IDMap fMatrix; + IDMap fMisc; + IDMap fPath; + IDMap fStroke; + ReffedIDMap fTextBlob; + ReffedIDMap fPathEffect; + ReffedIDMap fShader; + ReffedIDMap fXfermode; + ReffedIDMap fMaskFilter; + ReffedIDMap fColorFilter; + ReffedIDMap fRasterizer; + ReffedIDMap fDrawLooper; + ReffedIDMap fImageFilter; + ReffedIDMap 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 @@ -695,19 +735,20 @@ namespace SkRemote { SkTHashMap fMap; }; - SkTHashMap fMatrix; - SkTHashMap fMisc; - SkTHashMap fPath; - SkTHashMap fStroke; - RefKeyMap fPathEffect; - RefKeyMap fShader; - RefKeyMap fXfermode; - RefKeyMap fMaskFilter; - RefKeyMap fColorFilter; - RefKeyMap fRasterizer; - RefKeyMap fDrawLooper; - RefKeyMap fImageFilter; - RefKeyMap fAnnotation; + SkTHashMap fMatrix; + SkTHashMap fMisc; + SkTHashMap fPath; + SkTHashMap fStroke; + RefKeyMap fTextBlob; + RefKeyMap fPathEffect; + RefKeyMap fShader; + RefKeyMap fXfermode; + RefKeyMap fMaskFilter; + RefKeyMap fColorFilter; + RefKeyMap fRasterizer; + RefKeyMap fDrawLooper; + RefKeyMap fImageFilter; + RefKeyMap fAnnotation; Encoder* fWrapped; }; diff --git a/src/core/SkRemote.h b/src/core/SkRemote.h index b33309449c..924e63e220 100644 --- a/src/core/SkRemote.h +++ b/src/core/SkRemote.h @@ -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. diff --git a/src/core/SkRemote_protocol.h b/src/core/SkRemote_protocol.h index 6a37f09e09..19bdc33fdd 100644 --- a/src/core/SkRemote_protocol.h +++ b/src/core/SkRemote_protocol.h @@ -19,6 +19,7 @@ namespace SkRemote { kMisc, kPath, kStroke, + kTextBlob, kPathEffect, kShader, kXfermode,