, fNextMisc (Type::kMisc)
, fNextPath (Type::kPath)
, fNextStroke (Type::kStroke)
+ , fNextShader (Type::kShader)
, fNextXfermode(Type::kXfermode)
{}
void cleanup(Encoder*) override {}
bool lookup(const Stroke&, ID* id, LookupScope* ls) override {
return Helper(&fNextStroke, id, ls);
}
+ bool lookup(const SkShader* shader, ID* id, LookupScope* ls) override {
+ if (!shader) {
+ *id = ID(Type::kShader);
+ return true; // Null IDs are always defined.
+ }
+ return Helper(&fNextShader, id, ls);
+ }
bool lookup(const SkXfermode* xfermode, ID* id, LookupScope* ls) override {
if (!xfermode) {
*id = ID(Type::kXfermode);
fNextMisc,
fNextPath,
fNextStroke,
+ fNextShader,
fNextXfermode;
};
return new NeverCache;
, fNextMisc (Type::kMisc)
, fNextPath (Type::kPath)
, fNextStroke (Type::kStroke)
+ , fNextShader (Type::kShader)
, fNextXfermode(Type::kXfermode)
{}
fMisc .foreach(undef);
fPath .foreach(undef);
fStroke .foreach(undef);
+ fShader .foreach(undef);
fXfermode.foreach(undef);
}
bool lookup(const Stroke& stroke, ID* id, LookupScope*) override {
return always_cache_lookup(stroke, &fStroke, &fNextStroke, id);
}
+ bool lookup(const SkShader* shader, ID* id, LookupScope*) override {
+ return always_cache_lookup(shader, &fShader, &fNextShader, id);
+ }
bool lookup(const SkXfermode* xfermode, ID* id, LookupScope*) override {
return always_cache_lookup(xfermode, &fXfermode, &fNextXfermode, id);
}
SkTHashMap<Misc, ID, MiscHash> fMisc;
SkTHashMap<SkPath, ID> fPath;
SkTHashMap<Stroke, ID> fStroke;
+ RefKeyMap<SkShader, Type::kShader> fShader;
RefKeyMap<SkXfermode, Type::kXfermode> fXfermode;
ID fNextMatrix,
fNextMisc,
fNextPath,
fNextStroke,
+ fNextShader,
fNextXfermode;
};
return new AlwaysCache;
LookupScope ls(fCache, fEncoder);
ID p = ls.lookup(path),
m = ls.lookup(Misc::CreateFrom(paint)),
+ s = ls.lookup(paint.getShader()),
x = ls.lookup(paint.getXfermode());
if (paint.getStyle() == SkPaint::kFill_Style) {
- fEncoder->fillPath(p, m, x);
+ fEncoder->fillPath(p, m, s, x);
} else {
// TODO: handle kStrokeAndFill_Style
- fEncoder->strokePath(p, m, x, ls.lookup(Stroke::CreateFrom(paint)));
+ fEncoder->strokePath(p, m, s, x, ls.lookup(Stroke::CreateFrom(paint)));
}
}
void Server::define(ID id, const Misc& v) { fMisc .set(id, v); }
void Server::define(ID id, const SkPath& v) { fPath .set(id, v); }
void Server::define(ID id, const Stroke& v) { fStroke .set(id, v); }
+ void Server::define(ID id, SkShader* v) { fShader .set(id, v); }
void Server::define(ID id, SkXfermode* v) { fXfermode.set(id, v); }
void Server::undefine(ID id) {
case Type::kMisc: return fMisc .remove(id);
case Type::kPath: return fPath .remove(id);
case Type::kStroke: return fStroke .remove(id);
+ case Type::kShader: return fShader .remove(id);
case Type::kXfermode: return fXfermode.remove(id);
case Type::kNone: SkASSERT(false);
void Server::clipPath(ID path, SkRegion::Op op, bool aa) {
fCanvas->clipPath(fPath.find(path), op, aa);
}
- void Server::fillPath(ID path, ID misc, ID xfermode) {
+ void Server::fillPath(ID path, ID misc, ID shader, ID xfermode) {
SkPaint paint;
paint.setStyle(SkPaint::kFill_Style);
fMisc.find(misc).applyTo(&paint);
+ paint.setShader (fShader .find(shader));
paint.setXfermode(fXfermode.find(xfermode));
fCanvas->drawPath(fPath.find(path), paint);
}
- void Server::strokePath(ID path, ID misc, ID xfermode, ID stroke) {
+ void Server::strokePath(ID path, ID misc, ID shader, ID xfermode, ID stroke) {
SkPaint paint;
paint.setStyle(SkPaint::kStroke_Style);
fMisc .find(misc ).applyTo(&paint);
fStroke.find(stroke).applyTo(&paint);
+ paint.setShader (fShader .find(shader));
paint.setXfermode(fXfermode.find(xfermode));
fCanvas->drawPath(fPath.find(path), paint);
}
#include "SkCanvas.h"
#include "SkPaint.h"
#include "SkRemote_protocol.h"
+#include "SkShader.h"
#include "SkTHash.h"
#include "SkTypes.h"
virtual void define(ID, const Misc&) = 0;
virtual void define(ID, const SkPath&) = 0;
virtual void define(ID, const Stroke&) = 0;
+ virtual void define(ID, SkShader*) = 0;
virtual void define(ID, SkXfermode*) = 0;
virtual void undefine(ID) = 0;
virtual void setMatrix(ID matrix) = 0;
- // TODO: struct CommonIDs { ID misc; ID xfermode; ... }
+ // TODO: struct CommonIDs { ID misc, shader, xfermode; ... }
// for IDs that affect both fill + stroke?
- virtual void clipPath(ID path, SkRegion::Op, bool aa) = 0;
- virtual void fillPath(ID path, ID misc, ID xfermode) = 0;
- virtual void strokePath(ID path, ID misc, ID xfermode, ID stroke) = 0;
+ virtual void clipPath(ID path, SkRegion::Op, bool aa) = 0;
+ virtual void fillPath(ID path, ID misc, ID shader, ID xfermode) = 0;
+ virtual void strokePath(ID path, ID misc, ID shader, ID xfermode, ID stroke) = 0;
};
class LookupScope;
virtual bool lookup(const Misc&, ID*, LookupScope*) = 0;
virtual bool lookup(const SkPath&, ID*, LookupScope*) = 0;
virtual bool lookup(const Stroke&, ID*, LookupScope*) = 0;
+ virtual bool lookup(const SkShader*, ID*, LookupScope*) = 0;
virtual bool lookup(const SkXfermode*, ID*, LookupScope*) = 0;
virtual void cleanup(Encoder*) = 0;
void define(ID, const Misc&) override;
void define(ID, const SkPath&) override;
void define(ID, const Stroke&) override;
+ void define(ID, SkShader*) override;
void define(ID, SkXfermode*) override;
void undefine(ID) override;
void setMatrix(ID matrix) override;
- void clipPath(ID path, SkRegion::Op, bool aa) override;
- void fillPath(ID path, ID misc, ID xfermode) override;
- void strokePath(ID path, ID misc, ID xfermode, ID stroke) override;
+ void clipPath(ID path, SkRegion::Op, bool aa) override;
+ void fillPath(ID path, ID misc, ID shader, ID xfermode) override;
+ void strokePath(ID path, ID misc, ID shader, ID xfermode, ID stroke) override;
// Maps ID -> T.
template <typename T, Type kType>
IDMap<Misc , Type::kMisc > fMisc;
IDMap<SkPath , Type::kPath > fPath;
IDMap<Stroke , Type::kStroke> fStroke;
+ ReffedIDMap<SkShader, Type::kShader> fShader;
ReffedIDMap<SkXfermode, Type::kXfermode> fXfermode;
SkCanvas* fCanvas;