Chromium Code Reviews| Index: src/core/SkRemote.h |
| diff --git a/src/core/SkRemote.h b/src/core/SkRemote.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a9bb33f22201f46123d31f32a0bf65b31bb34773 |
| --- /dev/null |
| +++ b/src/core/SkRemote.h |
| @@ -0,0 +1,180 @@ |
| +/* |
| + * Copyright 2015 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +#ifndef SkRemote_DEFINED |
| +#define SkRemote_DEFINED |
| + |
| +#include "SkCanvas.h" |
| +#include "SkPaint.h" |
| +#include "SkRemote_protocol.h" |
| +#include "SkTHash.h" |
| +#include "SkTypes.h" |
| + |
| +namespace SkRemote { |
| + |
| + struct Encoder { |
|
hal.canary
2015/10/16 16:57:54
/** describe class */
mtklein
2015/10/16 17:20:33
Left myself some TODOs. Not _quite_ confident eno
|
| + virtual ~Encoder() {} |
| + |
| + struct Misc { |
|
hal.canary
2015/10/16 16:57:55
Should this be SkRemote::Misc rather than SkRemote
mtklein
2015/10/16 17:21:36
Whoops, I seem to have clicked Cancel instead of S
|
| + SkColor fColor; |
| + SkFilterQuality fFilterQuality; |
| + bool fAntiAlias, fDither; |
| + |
| + static Misc CreateFrom(const SkPaint&); |
| + void applyTo(SkPaint*) const; |
| + }; |
| + |
| + struct Stroke { |
| + SkScalar fWidth, fMiter; |
| + SkPaint::Cap fCap; |
| + SkPaint::Join fJoin; |
| + |
| + static Stroke CreateFrom(const SkPaint&); |
| + void applyTo(SkPaint*) const; |
| + }; |
| + |
| + /* |
| + struct Text { |
| + SkScalar fSize, fScaleX, fSkewX; |
| + SkPaint::Align fAlign; |
| + SkPaint::Hinting fHinting; |
| + SkPaint::TextEncoding fEncoding; |
| + bool fAutoHinted, fDevKern, fEmbeddedBitmap, fFakeBold, fLcdRender, |
| + fLinear, fStrikeThru, fSubpixel, fUnderline, fVertical; |
| + |
| + static Text CreateFrom(const SkPaint&); |
| + void applyTo(SkPaint*) const; |
| + }; |
| + */ |
| + |
| + virtual void define(ID, const SkMatrix&) = 0; |
| + virtual void define(ID, const Misc&) = 0; |
| + virtual void define(ID, const SkPath&) = 0; |
| + virtual void define(ID, const Stroke&) = 0; |
| + |
| + virtual void undefine(ID) = 0; |
| + |
| + virtual void save() = 0; |
| + virtual void restore() = 0; |
| + |
| + virtual void setMatrix(ID matrix) = 0; |
| + |
| + virtual void clipPath(ID path, SkRegion::Op, bool aa) = 0; |
| + virtual void fillPath(ID path, ID misc) = 0; |
| + virtual void strokePath(ID path, ID misc, ID stroke) = 0; |
| + }; |
| + |
| + struct Cache; |
| + |
| + class LookupScope { |
|
hal.canary
2015/10/16 16:57:54
/** comments explaining what this class does. */
|
| + public: |
| + LookupScope(Cache* cache, Encoder* encoder) : fCache(cache), fEncoder(encoder) {} |
| + ~LookupScope() { for (ID id : fToUndefine) { fEncoder->undefine(id); } } |
| + void undefineWhenDone(ID id) { fToUndefine.push_back(id); } |
| + |
| + template <typename T> |
| + ID lookup(const T&); |
| + private: |
| + Cache* fCache; |
| + Encoder* fEncoder; |
| + SkSTArray<4, ID> fToUndefine; |
| + }; |
| + |
| + struct Cache { |
|
hal.canary
2015/10/16 16:57:54
/** describe class */
|
| + virtual ~Cache() {} |
| + |
| + static Cache* CreateNeverCache(); |
| + static Cache* CreateAlwaysCache(); |
| + |
| + virtual bool lookup(const SkMatrix&, ID*, LookupScope*) = 0; |
| + virtual bool lookup(const Encoder::Misc&, ID*, LookupScope*) = 0; |
| + virtual bool lookup(const SkPath&, ID*, LookupScope*) = 0; |
| + virtual bool lookup(const Encoder::Stroke&, ID*, LookupScope*) = 0; |
| + |
| + virtual void cleanup(Encoder*) = 0; |
| + }; |
| + |
| + class Client final : public SkCanvas { |
|
hal.canary
2015/10/16 16:57:54
/** describe class */
|
| + public: |
| + Client(Cache*, Encoder*); |
| + ~Client(); |
| + |
| + private: |
| + void willSave() override; |
| + void didRestore() override; |
| + |
| + void didConcat(const SkMatrix&) override; |
| + void didSetMatrix(const SkMatrix&) override; |
| + |
| + void onClipPath (const SkPath&, SkRegion::Op, ClipEdgeStyle) override; |
| + void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) override; |
| + void onClipRect (const SkRect&, SkRegion::Op, ClipEdgeStyle) override; |
| + |
| + void onDrawOval(const SkRect&, const SkPaint&) override; |
| + void onDrawPath(const SkPath&, const SkPaint&) override; |
| + void onDrawRect(const SkRect&, const SkPaint&) override; |
| + |
| + Cache* fCache; |
| + Encoder* fEncoder; |
| + }; |
| + |
| + class Server final : public Encoder { |
| + public: |
| + explicit Server(SkCanvas*); |
| + |
| + private: |
| + void define(ID, const SkMatrix&) override; |
| + void define(ID, const Misc&) override; |
| + void define(ID, const SkPath&) override; |
| + void define(ID, const Stroke&) override; |
| + |
| + void undefine(ID) override; |
| + |
| + void save() override; |
| + void restore() override; |
| + |
| + void setMatrix(ID matrix) override; |
| + |
| + void clipPath(ID path, SkRegion::Op, bool aa) override; |
| + void fillPath(ID path, ID misc) override; |
| + void strokePath(ID path, ID misc, ID stroke) override; |
| + |
| + template <typename T, Type kType> |
| + class IDMap { |
| + public: |
| + void set(const ID& id, const T& val) { |
| + SkASSERT(id.type() == kType); |
| + fMap.set(id, val); |
| + } |
| + |
| + void remove(const ID& id) { |
| + SkASSERT(id.type() == kType); |
| + fMap.remove(id); |
| + } |
| + |
| + const T& find(const ID& id) const { |
| + SkASSERT(id.type() == kType); |
| + T* val = fMap.find(id); |
| + SkASSERT(val != nullptr); |
| + return *val; |
| + } |
| + |
| + private: |
| + SkTHashMap<ID, T> fMap; |
| + }; |
| + |
| + IDMap<SkMatrix, Type::kMatrix> fMatrix; |
| + IDMap<Misc , Type::kMisc > fMisc; |
| + IDMap<SkPath , Type::kPath > fPath; |
| + IDMap<Stroke , Type::kStroke> fStroke; |
| + |
| + SkCanvas* fCanvas; |
| + }; |
| + |
| +} // namespace SkRemote |
| + |
| +#endif//SkRemote_DEFINED |