1 /* 2 * Copyright 2015 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkRemote_DEFINED 9 #define SkRemote_DEFINED 10 11 #include "SkPaint.h" 12 #include "SkRegion.h" 13 #include "SkRemote_protocol.h" 14 #include "SkTypes.h" 15 16 class SkCanvas; 17 class SkMatrix; 18 class SkPath; 19 class SkShader; 20 class SkTextBlob; 21 class SkXfermode; 22 23 // TODO: document 24 25 namespace SkRemote { 26 27 // General purpose identifier. Holds a Type and a 56-bit value. 28 class ID { 29 public: 30 ID() {} 31 ID(Type type, uint64_t val) { 32 fVal = (uint64_t)type << 56 | val; 33 SkASSERT(this->type() == type && this->val() == val); 34 } 35 36 Type type() const { return (Type)(fVal >> 56); } 37 uint64_t val() const { return fVal & ~((uint64_t)0xFF << 56); } 38 39 bool operator==(ID o) const { return fVal == o.fVal; } 40 41 private: 42 uint64_t fVal; 43 }; 44 45 // Fields from SkPaint used by stroke, fill, and text draws. 46 struct Misc { 47 SkColor fColor; 48 SkFilterQuality fFilterQuality; 49 bool fAntiAlias, fDither; 50 51 static Misc CreateFrom(const SkPaint&); 52 void applyTo(SkPaint*) const; 53 }; 54 55 // Fields from SkPaint used by stroke draws only. 56 struct Stroke { 57 SkScalar fWidth, fMiter; 58 SkPaint::Cap fCap; 59 SkPaint::Join fJoin; 60 61 static Stroke CreateFrom(const SkPaint&); 62 void applyTo(SkPaint*) const; 63 }; 64 65 // TODO: document 66 struct Encoder { 67 virtual ~Encoder() {} 68 69 virtual ID define(const SkMatrix&) = 0; 70 virtual ID define(const Misc&) = 0; 71 virtual ID define(const SkPath&) = 0; 72 virtual ID define(const Stroke&) = 0; 73 virtual ID define(const SkTextBlob*) = 0; 74 virtual ID define(SkPathEffect*) = 0; 75 virtual ID define(SkShader*) = 0; 76 virtual ID define(SkXfermode*) = 0; 77 virtual ID define(SkMaskFilter*) = 0; 78 virtual ID define(SkColorFilter*) = 0; 79 virtual ID define(SkRasterizer*) = 0; 80 virtual ID define(SkDrawLooper*) = 0; 81 virtual ID define(SkImageFilter*) = 0; 82 virtual ID define(SkAnnotation*) = 0; 83 84 virtual void undefine(ID) = 0; 85 86 // TODO: do these all belong here in CommonIDs? 87 struct CommonIDs { 88 ID misc, patheffect, shader, xfermode, maskfilter, 89 colorfilter, rasterizer, looper, imagefilter, annotation; 90 }; 91 92 virtual void save() = 0; 93 virtual void restore() = 0; 94 virtual void saveLayer(ID bounds, CommonIDs, uint32_t saveLayerFlags) = 0; 95 96 virtual void setMatrix(ID matrix) = 0; 97 98 virtual void clipPath(ID path, SkRegion::Op, bool aa) = 0; 99 virtual void fillPath(ID path, CommonIDs) = 0; 100 virtual void strokePath(ID path, CommonIDs, ID stroke) = 0; 101 virtual void fillText(ID text, SkPoint, CommonIDs) = 0; 102 virtual void strokeText(ID text, SkPoint, CommonIDs, ID stroke) = 0; 103 }; 104 105 // None of these factories take ownership of their arguments. 106 107 // Returns a new SkCanvas that translates to the Encoder API. 108 SkCanvas* NewCanvas(Encoder*); 109 // Returns an Encoder that translates back to the SkCanvas API. 110 Encoder* NewDecoder(SkCanvas*); 111 // Wraps another Encoder with a cache. TODO: parameterize 112 Encoder* NewCachingEncoder(Encoder*); 113 114 } // namespace SkRemote 115 116 #endif//SkRemote_DEFINED 117