epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 10 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 11 | #include "SkCanvas.h" |
reed@google.com | 8a85d0c | 2011-06-24 19:12:12 +0000 | [diff] [blame] | 12 | #include "SkData.h" |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 13 | #include "SkDevice.h" |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 14 | #include "SkPaint.h" |
reed@google.com | 75a0972 | 2012-05-10 12:56:16 +0000 | [diff] [blame] | 15 | #include "SkPathEffect.h" |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 16 | #include "SkGPipe.h" |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 17 | #include "SkGPipePriv.h" |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 18 | #include "SkImageFilter.h" |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 19 | #include "SkStream.h" |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 20 | #include "SkTSearch.h" |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 21 | #include "SkTypeface.h" |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 22 | #include "SkWriter32.h" |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 23 | #include "SkColorFilter.h" |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame] | 24 | #include "SkDrawLooper.h" |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 25 | #include "SkMaskFilter.h" |
| 26 | #include "SkRasterizer.h" |
| 27 | #include "SkShader.h" |
djsollen@google.com | 2b2ede3 | 2012-04-12 13:24:04 +0000 | [diff] [blame] | 28 | #include "SkOrderedWriteBuffer.h" |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 29 | |
| 30 | static SkFlattenable* get_paintflat(const SkPaint& paint, unsigned paintFlat) { |
| 31 | SkASSERT(paintFlat < kCount_PaintFlats); |
| 32 | switch (paintFlat) { |
| 33 | case kColorFilter_PaintFlat: return paint.getColorFilter(); |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame] | 34 | case kDrawLooper_PaintFlat: return paint.getLooper(); |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 35 | case kMaskFilter_PaintFlat: return paint.getMaskFilter(); |
| 36 | case kPathEffect_PaintFlat: return paint.getPathEffect(); |
| 37 | case kRasterizer_PaintFlat: return paint.getRasterizer(); |
| 38 | case kShader_PaintFlat: return paint.getShader(); |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 39 | case kImageFilter_PaintFlat: return paint.getImageFilter(); |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 40 | case kXfermode_PaintFlat: return paint.getXfermode(); |
| 41 | } |
tomhudson@google.com | 0c00f21 | 2011-12-28 14:59:50 +0000 | [diff] [blame] | 42 | SkDEBUGFAIL("never gets here"); |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 43 | return NULL; |
| 44 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 45 | |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 46 | static size_t writeTypeface(SkWriter32* writer, SkTypeface* typeface) { |
| 47 | SkASSERT(typeface); |
| 48 | SkDynamicMemoryWStream stream; |
| 49 | typeface->serialize(&stream); |
| 50 | size_t size = stream.getOffset(); |
| 51 | if (writer) { |
| 52 | writer->write32(size); |
reed@google.com | 8a85d0c | 2011-06-24 19:12:12 +0000 | [diff] [blame] | 53 | SkAutoDataUnref data(stream.copyToData()); |
robertphillips@google.com | 59f46b8 | 2012-07-10 17:30:58 +0000 | [diff] [blame^] | 54 | writer->writePad(data->data(), size); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 55 | } |
scroggo@google.com | 5af9b20 | 2012-06-04 17:17:36 +0000 | [diff] [blame] | 56 | return 4 + SkAlign4(size); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 57 | } |
| 58 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 59 | /////////////////////////////////////////////////////////////////////////////// |
| 60 | |
scroggo@google.com | 8ae3c7f | 2012-06-13 17:47:52 +0000 | [diff] [blame] | 61 | /* |
| 62 | * Shared heap for storing large things that can be shared, for a stream |
| 63 | * used by multiple readers. |
| 64 | * TODO: Make the allocations all come from cross process safe address space |
| 65 | * TODO: Store paths (others?) |
| 66 | * TODO: Allow reclaiming of memory. Will require us to know when all readers |
| 67 | * have used the object. |
| 68 | */ |
| 69 | class Heap { |
| 70 | public: |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 71 | Heap(bool shallow) : fCanDoShallowCopies(shallow) {} |
scroggo@google.com | 8ae3c7f | 2012-06-13 17:47:52 +0000 | [diff] [blame] | 72 | ~Heap() { |
| 73 | for (int i = 0; i < fBitmaps.count(); i++) { |
| 74 | delete fBitmaps[i].fBitmap; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | /* |
| 79 | * Add a copy of a bitmap to the heap. |
| 80 | * @param bm The SkBitmap to be copied and placed in the heap. |
| 81 | * @return void* Pointer to the heap's copy of the bitmap. If NULL, |
| 82 | * the bitmap could not be copied. |
| 83 | */ |
scroggo@google.com | 4f1f6bf | 2012-07-02 13:35:09 +0000 | [diff] [blame] | 84 | const SkBitmap* addBitmap(const SkBitmap& orig) { |
| 85 | const uint32_t genID = orig.getGenerationID(); |
| 86 | SkPixelRef* sharedPixelRef = NULL; |
scroggo@google.com | 8ae3c7f | 2012-06-13 17:47:52 +0000 | [diff] [blame] | 87 | for (int i = fBitmaps.count() - 1; i >= 0; i--) { |
scroggo@google.com | 6ea165d | 2012-07-03 14:52:08 +0000 | [diff] [blame] | 88 | SkBitmap* storedBitmap = fBitmaps[i].fBitmap; |
scroggo@google.com | 8ae3c7f | 2012-06-13 17:47:52 +0000 | [diff] [blame] | 89 | if (genID == fBitmaps[i].fGenID) { |
scroggo@google.com | 6ea165d | 2012-07-03 14:52:08 +0000 | [diff] [blame] | 90 | if (orig.pixelRefOffset() != storedBitmap->pixelRefOffset() |
| 91 | || orig.width() != storedBitmap->width() |
| 92 | || orig.height() != storedBitmap->height()) { |
scroggo@google.com | 4f1f6bf | 2012-07-02 13:35:09 +0000 | [diff] [blame] | 93 | // In this case, the bitmaps share a pixelRef, but have |
scroggo@google.com | 6ea165d | 2012-07-03 14:52:08 +0000 | [diff] [blame] | 94 | // different offsets or sizes. Keep track of the other |
| 95 | // bitmap so that instead of making another copy of the |
| 96 | // pixelRef we can use the copy we already made. |
| 97 | sharedPixelRef = storedBitmap->pixelRef(); |
scroggo@google.com | 4f1f6bf | 2012-07-02 13:35:09 +0000 | [diff] [blame] | 98 | break; |
| 99 | } |
scroggo@google.com | 6ea165d | 2012-07-03 14:52:08 +0000 | [diff] [blame] | 100 | return storedBitmap; |
scroggo@google.com | 8ae3c7f | 2012-06-13 17:47:52 +0000 | [diff] [blame] | 101 | } |
| 102 | } |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 103 | SkBitmap* copy; |
| 104 | // If the bitmap is mutable, we still need to do a deep copy, since the |
| 105 | // caller may modify it afterwards. That said, if the bitmap is mutable, |
| 106 | // but has no pixelRef, the copy constructor actually does a deep copy. |
scroggo@google.com | 4f1f6bf | 2012-07-02 13:35:09 +0000 | [diff] [blame] | 107 | if (fCanDoShallowCopies && (orig.isImmutable() || !orig.pixelRef())) { |
| 108 | copy = new SkBitmap(orig); |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 109 | } else { |
scroggo@google.com | 4f1f6bf | 2012-07-02 13:35:09 +0000 | [diff] [blame] | 110 | if (sharedPixelRef != NULL) { |
| 111 | // Do a shallow copy of the bitmap to get the width, height, etc |
| 112 | copy = new SkBitmap(orig); |
| 113 | // Replace the pixelRef with the copy that was already made, and |
| 114 | // use the appropriate offset. |
| 115 | copy->setPixelRef(sharedPixelRef, orig.pixelRefOffset()); |
| 116 | } else { |
| 117 | copy = new SkBitmap(); |
| 118 | if (!orig.copyTo(copy, orig.getConfig())) { |
| 119 | delete copy; |
| 120 | return NULL; |
| 121 | } |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 122 | } |
scroggo@google.com | 8ae3c7f | 2012-06-13 17:47:52 +0000 | [diff] [blame] | 123 | } |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 124 | BitmapInfo* info = fBitmaps.append(); |
| 125 | info->fBitmap = copy; |
| 126 | info->fGenID = genID; |
| 127 | return copy; |
scroggo@google.com | 8ae3c7f | 2012-06-13 17:47:52 +0000 | [diff] [blame] | 128 | } |
| 129 | private: |
| 130 | struct BitmapInfo { |
| 131 | SkBitmap* fBitmap; |
| 132 | // Store the generation ID of the original bitmap, since copying does |
| 133 | // not copy this field, so fBitmap's generation ID will not be useful |
| 134 | // for comparing. |
| 135 | uint32_t fGenID; |
| 136 | }; |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 137 | SkTDArray<BitmapInfo> fBitmaps; |
| 138 | const bool fCanDoShallowCopies; |
scroggo@google.com | 8ae3c7f | 2012-06-13 17:47:52 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | /////////////////////////////////////////////////////////////////////////////// |
| 142 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 143 | class SkGPipeCanvas : public SkCanvas { |
| 144 | public: |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 145 | SkGPipeCanvas(SkGPipeController*, SkWriter32*, SkFactorySet*, uint32_t flags); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 146 | virtual ~SkGPipeCanvas(); |
| 147 | |
| 148 | void finish() { |
| 149 | if (!fDone) { |
reed@google.com | dbccc88 | 2011-07-08 18:53:39 +0000 | [diff] [blame] | 150 | if (this->needOpBytes()) { |
| 151 | this->writeOp(kDone_DrawOp); |
| 152 | this->doNotify(); |
| 153 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 154 | fDone = true; |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | // overrides from SkCanvas |
scroggo@google.com | 3b45cd5 | 2012-04-18 13:57:47 +0000 | [diff] [blame] | 159 | virtual int save(SaveFlags) SK_OVERRIDE; |
| 160 | virtual int saveLayer(const SkRect* bounds, const SkPaint*, |
| 161 | SaveFlags) SK_OVERRIDE; |
| 162 | virtual void restore() SK_OVERRIDE; |
| 163 | virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE; |
| 164 | virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE; |
| 165 | virtual bool rotate(SkScalar degrees) SK_OVERRIDE; |
| 166 | virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE; |
| 167 | virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE; |
| 168 | virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE; |
| 169 | virtual bool clipRect(const SkRect& rect, SkRegion::Op op, |
| 170 | bool doAntiAlias = false) SK_OVERRIDE; |
| 171 | virtual bool clipPath(const SkPath& path, SkRegion::Op op, |
| 172 | bool doAntiAlias = false) SK_OVERRIDE; |
| 173 | virtual bool clipRegion(const SkRegion& region, SkRegion::Op op) SK_OVERRIDE; |
| 174 | virtual void clear(SkColor) SK_OVERRIDE; |
| 175 | virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 176 | virtual void drawPoints(PointMode, size_t count, const SkPoint pts[], |
scroggo@google.com | 3b45cd5 | 2012-04-18 13:57:47 +0000 | [diff] [blame] | 177 | const SkPaint&) SK_OVERRIDE; |
| 178 | virtual void drawRect(const SkRect& rect, const SkPaint&) SK_OVERRIDE; |
| 179 | virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 180 | virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top, |
scroggo@google.com | 3b45cd5 | 2012-04-18 13:57:47 +0000 | [diff] [blame] | 181 | const SkPaint*) SK_OVERRIDE; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 182 | virtual void drawBitmapRect(const SkBitmap&, const SkIRect* src, |
scroggo@google.com | 3b45cd5 | 2012-04-18 13:57:47 +0000 | [diff] [blame] | 183 | const SkRect& dst, const SkPaint*) SK_OVERRIDE; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 184 | virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&, |
scroggo@google.com | 3b45cd5 | 2012-04-18 13:57:47 +0000 | [diff] [blame] | 185 | const SkPaint*) SK_OVERRIDE; |
scroggo@google.com | 5a2e879 | 2012-04-20 17:39:51 +0000 | [diff] [blame] | 186 | virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
| 187 | const SkRect& dst, const SkPaint* paint = NULL) SK_OVERRIDE; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 188 | virtual void drawSprite(const SkBitmap&, int left, int top, |
scroggo@google.com | 3b45cd5 | 2012-04-18 13:57:47 +0000 | [diff] [blame] | 189 | const SkPaint*) SK_OVERRIDE; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 190 | virtual void drawText(const void* text, size_t byteLength, SkScalar x, |
scroggo@google.com | 3b45cd5 | 2012-04-18 13:57:47 +0000 | [diff] [blame] | 191 | SkScalar y, const SkPaint&) SK_OVERRIDE; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 192 | virtual void drawPosText(const void* text, size_t byteLength, |
scroggo@google.com | 3b45cd5 | 2012-04-18 13:57:47 +0000 | [diff] [blame] | 193 | const SkPoint pos[], const SkPaint&) SK_OVERRIDE; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 194 | virtual void drawPosTextH(const void* text, size_t byteLength, |
scroggo@google.com | 3b45cd5 | 2012-04-18 13:57:47 +0000 | [diff] [blame] | 195 | const SkScalar xpos[], SkScalar constY, |
| 196 | const SkPaint&) SK_OVERRIDE; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 197 | virtual void drawTextOnPath(const void* text, size_t byteLength, |
| 198 | const SkPath& path, const SkMatrix* matrix, |
scroggo@google.com | 3b45cd5 | 2012-04-18 13:57:47 +0000 | [diff] [blame] | 199 | const SkPaint&) SK_OVERRIDE; |
| 200 | virtual void drawPicture(SkPicture& picture) SK_OVERRIDE; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 201 | virtual void drawVertices(VertexMode, int vertexCount, |
| 202 | const SkPoint vertices[], const SkPoint texs[], |
| 203 | const SkColor colors[], SkXfermode*, |
| 204 | const uint16_t indices[], int indexCount, |
scroggo@google.com | 3b45cd5 | 2012-04-18 13:57:47 +0000 | [diff] [blame] | 205 | const SkPaint&) SK_OVERRIDE; |
| 206 | virtual void drawData(const void*, size_t) SK_OVERRIDE; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 207 | |
| 208 | private: |
scroggo@google.com | 8ae3c7f | 2012-06-13 17:47:52 +0000 | [diff] [blame] | 209 | Heap fHeap; |
reed@google.com | dde0956 | 2011-05-23 12:21:05 +0000 | [diff] [blame] | 210 | SkFactorySet* fFactorySet; // optional, only used if cross-process |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 211 | SkGPipeController* fController; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 212 | SkWriter32& fWriter; |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 213 | size_t fBlockSize; // amount allocated for writer |
| 214 | size_t fBytesNotified; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 215 | bool fDone; |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 216 | uint32_t fFlags; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 217 | |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 218 | SkRefCntSet fTypefaceSet; |
| 219 | |
| 220 | uint32_t getTypefaceID(SkTypeface*); |
| 221 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 222 | inline void writeOp(DrawOps op, unsigned flags, unsigned data) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 223 | fWriter.write32(DrawOp_packOpFlagData(op, flags, data)); |
| 224 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 225 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 226 | inline void writeOp(DrawOps op) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 227 | fWriter.write32(DrawOp_packOpFlagData(op, 0, 0)); |
| 228 | } |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 229 | |
| 230 | bool needOpBytes(size_t size = 0); |
| 231 | |
| 232 | inline void doNotify() { |
| 233 | if (!fDone) { |
| 234 | size_t bytes = fWriter.size() - fBytesNotified; |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 235 | if (bytes > 0) { |
| 236 | fController->notifyWritten(bytes); |
| 237 | fBytesNotified += bytes; |
| 238 | } |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 239 | } |
| 240 | } |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 241 | |
| 242 | struct FlatData { |
| 243 | uint32_t fIndex; // always > 0 |
scroggo@google.com | d3ba5cc | 2012-07-09 16:05:53 +0000 | [diff] [blame] | 244 | PaintFlats fPaintFlat; // deliberately before fSize so that Compare |
| 245 | // will ignore it. |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 246 | uint32_t fSize; |
| 247 | |
| 248 | void* data() { return (char*)this + sizeof(*this); } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 249 | |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 250 | static int Compare(const FlatData* a, const FlatData* b) { |
| 251 | return memcmp(&a->fSize, &b->fSize, a->fSize + sizeof(a->fSize)); |
| 252 | } |
| 253 | }; |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 254 | |
| 255 | SkTDArray<FlatData*> fBitmapArray; |
| 256 | int flattenToIndex(const SkBitmap&); |
| 257 | |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 258 | SkTDArray<FlatData*> fFlatArray; |
scroggo@google.com | d3ba5cc | 2012-07-09 16:05:53 +0000 | [diff] [blame] | 259 | size_t fBytesOfFlatData; |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 260 | int fCurrFlatIndex[kCount_PaintFlats]; |
| 261 | int flattenToIndex(SkFlattenable* obj, PaintFlats); |
scroggo@google.com | d3ba5cc | 2012-07-09 16:05:53 +0000 | [diff] [blame] | 262 | int flattenableToReplace(const FlatData& newFlat); |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 263 | |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 264 | SkPaint fPaint; |
| 265 | void writePaint(const SkPaint&); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 266 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 267 | class AutoPipeNotify { |
| 268 | public: |
| 269 | AutoPipeNotify(SkGPipeCanvas* canvas) : fCanvas(canvas) {} |
| 270 | ~AutoPipeNotify() { fCanvas->doNotify(); } |
| 271 | private: |
| 272 | SkGPipeCanvas* fCanvas; |
| 273 | }; |
| 274 | friend class AutoPipeNotify; |
| 275 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 276 | typedef SkCanvas INHERITED; |
| 277 | }; |
| 278 | |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 279 | int SkGPipeCanvas::flattenToIndex(const SkBitmap & bitmap) { |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 280 | SkASSERT(shouldFlattenBitmaps(fFlags)); |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 281 | SkOrderedWriteBuffer tmpWriter(1024); |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 282 | tmpWriter.setFlags((SkFlattenableWriteBuffer::Flags) |
| 283 | (SkFlattenableWriteBuffer::kInlineFactoryNames_Flag |
| 284 | | SkFlattenableWriteBuffer::kCrossProcess_Flag)); |
| 285 | tmpWriter.setFactoryRecorder(fFactorySet); |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 286 | bitmap.flatten(tmpWriter); |
| 287 | |
| 288 | size_t len = tmpWriter.size(); |
| 289 | size_t allocSize = len + sizeof(FlatData); |
| 290 | |
| 291 | SkAutoSMalloc<1024> storage(allocSize); |
| 292 | FlatData* flat = (FlatData*)storage.get(); |
| 293 | flat->fSize = len; |
| 294 | tmpWriter.flatten(flat->data()); |
| 295 | |
| 296 | int index = SkTSearch<FlatData>((const FlatData**)fBitmapArray.begin(), |
| 297 | fBitmapArray.count(), flat, sizeof(flat), |
| 298 | &FlatData::Compare); |
| 299 | if (index < 0) { |
| 300 | index = ~index; |
| 301 | FlatData* copy = (FlatData*)sk_malloc_throw(allocSize); |
| 302 | memcpy(copy, flat, allocSize); |
| 303 | // For bitmaps, we can use zero based indices, since we will never ask |
| 304 | // for a NULL bitmap (unlike with paint flattenables). |
| 305 | copy->fIndex = fBitmapArray.count(); |
| 306 | *fBitmapArray.insert(index) = copy; |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 307 | if (this->needOpBytes(len)) { |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 308 | this->writeOp(kDef_Bitmap_DrawOp, 0, copy->fIndex); |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 309 | fWriter.write(copy->data(), len); |
| 310 | } |
| 311 | } |
| 312 | return fBitmapArray[index]->fIndex; |
| 313 | } |
| 314 | |
scroggo@google.com | d3ba5cc | 2012-07-09 16:05:53 +0000 | [diff] [blame] | 315 | // Return -1 if there is no need to replace a flattenable, or there was not an |
| 316 | // appropriate one to replace. Otherwise return the index of a flattenable to |
| 317 | // replace. |
| 318 | int SkGPipeCanvas::flattenableToReplace(const FlatData& newFlat) { |
| 319 | // For now, set an arbitrary limit on the size of FlatData we have stored. |
| 320 | // Note that this is currently a soft limit. If we have reached the limit, |
| 321 | // we replace one, but do not ensure that we return to below the limit. |
| 322 | if (fBytesOfFlatData + fFlatArray.bytes() > 1024) { |
| 323 | for (int i = 0; i < fFlatArray.count(); i++) { |
| 324 | // Only replace the same paint flat. Since a paint can only have |
| 325 | // one of each type, replacing one of the same type means that |
| 326 | // we will not be purging a flat on the same paint. |
| 327 | if (newFlat.fPaintFlat == fFlatArray[i]->fPaintFlat) { |
| 328 | return i; |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | return -1; |
| 333 | } |
| 334 | |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 335 | // return 0 for NULL (or unflattenable obj), or index-base-1 |
scroggo@google.com | d3ba5cc | 2012-07-09 16:05:53 +0000 | [diff] [blame] | 336 | // return ~(index-base-1) if an old flattenable was replaced |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 337 | int SkGPipeCanvas::flattenToIndex(SkFlattenable* obj, PaintFlats paintflat) { |
| 338 | if (NULL == obj) { |
| 339 | return 0; |
| 340 | } |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 341 | |
djsollen@google.com | 2b2ede3 | 2012-04-12 13:24:04 +0000 | [diff] [blame] | 342 | SkOrderedWriteBuffer tmpWriter(1024); |
scroggo@google.com | 5a2e879 | 2012-04-20 17:39:51 +0000 | [diff] [blame] | 343 | |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 344 | if (fFlags & SkGPipeWriter::kCrossProcess_Flag) { |
| 345 | tmpWriter.setFlags((SkFlattenableWriteBuffer::Flags) |
| 346 | (SkFlattenableWriteBuffer::kInlineFactoryNames_Flag |
| 347 | | SkFlattenableWriteBuffer::kCrossProcess_Flag)); |
| 348 | tmpWriter.setFactoryRecorder(fFactorySet); |
| 349 | } else { |
| 350 | // Needed for bitmap shaders. |
| 351 | tmpWriter.setFlags(SkFlattenableWriteBuffer::kForceFlattenBitmapPixels_Flag); |
| 352 | } |
reed@google.com | dde0956 | 2011-05-23 12:21:05 +0000 | [diff] [blame] | 353 | |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 354 | tmpWriter.writeFlattenable(obj); |
| 355 | size_t len = tmpWriter.size(); |
| 356 | size_t allocSize = len + sizeof(FlatData); |
| 357 | |
| 358 | SkAutoSMalloc<1024> storage(allocSize); |
| 359 | FlatData* flat = (FlatData*)storage.get(); |
| 360 | flat->fSize = len; |
| 361 | tmpWriter.flatten(flat->data()); |
| 362 | |
| 363 | int index = SkTSearch<FlatData>((const FlatData**)fFlatArray.begin(), |
scroggo@google.com | d3ba5cc | 2012-07-09 16:05:53 +0000 | [diff] [blame] | 364 | fFlatArray.count(), flat, sizeof(FlatData*), |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 365 | &FlatData::Compare); |
scroggo@google.com | d3ba5cc | 2012-07-09 16:05:53 +0000 | [diff] [blame] | 366 | bool replacedAFlat = false; |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 367 | if (index < 0) { |
| 368 | index = ~index; |
| 369 | FlatData* copy = (FlatData*)sk_malloc_throw(allocSize); |
| 370 | memcpy(copy, flat, allocSize); |
scroggo@google.com | d3ba5cc | 2012-07-09 16:05:53 +0000 | [diff] [blame] | 371 | copy->fPaintFlat = paintflat; |
| 372 | int indexToReplace = this->flattenableToReplace(*copy); |
| 373 | if (indexToReplace >= 0) { |
| 374 | replacedAFlat = true; |
| 375 | FlatData* oldData = fFlatArray[indexToReplace]; |
| 376 | copy->fIndex = oldData->fIndex; |
| 377 | fBytesOfFlatData -= (sizeof(FlatData) + oldData->fSize); |
| 378 | sk_free(oldData); |
| 379 | fFlatArray.remove(indexToReplace); |
| 380 | if (indexToReplace < index) { |
| 381 | index--; |
| 382 | } |
| 383 | } |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 384 | *fFlatArray.insert(index) = copy; |
scroggo@google.com | d3ba5cc | 2012-07-09 16:05:53 +0000 | [diff] [blame] | 385 | fBytesOfFlatData += allocSize; |
| 386 | if (!replacedAFlat) { |
| 387 | // Call this after the insert, so that count() will have been grown |
| 388 | // (unless we replaced one, in which case fIndex has already been |
| 389 | // set properly). |
| 390 | copy->fIndex = fFlatArray.count(); |
| 391 | // SkDebugf("--- add flattenable[%d] size=%d index=%d\n", paintflat, len, copy->fIndex); |
| 392 | } |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 393 | |
| 394 | if (this->needOpBytes(len)) { |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame] | 395 | this->writeOp(kDef_Flattenable_DrawOp, paintflat, copy->fIndex); |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 396 | fWriter.write(copy->data(), len); |
| 397 | } |
| 398 | } |
scroggo@google.com | d3ba5cc | 2012-07-09 16:05:53 +0000 | [diff] [blame] | 399 | int retVal = fFlatArray[index]->fIndex; |
| 400 | if (replacedAFlat) { |
| 401 | retVal = ~retVal; |
| 402 | } |
| 403 | return retVal; |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 404 | } |
| 405 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 406 | /////////////////////////////////////////////////////////////////////////////// |
| 407 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 408 | #define MIN_BLOCK_SIZE (16 * 1024) |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 409 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 410 | SkGPipeCanvas::SkGPipeCanvas(SkGPipeController* controller, |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 411 | SkWriter32* writer, SkFactorySet* fset, uint32_t flags) |
scroggo@google.com | d3ba5cc | 2012-07-09 16:05:53 +0000 | [diff] [blame] | 412 | : fHeap(!(flags & SkGPipeWriter::kCrossProcess_Flag)), fWriter(*writer), fFlags(flags) |
| 413 | , fBytesOfFlatData(0){ |
reed@google.com | 67908f2 | 2011-06-27 14:47:50 +0000 | [diff] [blame] | 414 | fFactorySet = fset; |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 415 | fController = controller; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 416 | fDone = false; |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 417 | fBlockSize = 0; // need first block from controller |
scroggo@google.com | 5a2e879 | 2012-04-20 17:39:51 +0000 | [diff] [blame] | 418 | fBytesNotified = 0; |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 419 | sk_bzero(fCurrFlatIndex, sizeof(fCurrFlatIndex)); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 420 | |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 421 | // we need a device to limit our clip |
| 422 | // should the caller give us the bounds? |
yangsu@google.com | 06b4da16 | 2011-06-17 15:04:40 +0000 | [diff] [blame] | 423 | // We don't allocate pixels for the bitmap |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 424 | SkBitmap bitmap; |
| 425 | bitmap.setConfig(SkBitmap::kARGB_8888_Config, 32767, 32767); |
yangsu@google.com | 06b4da16 | 2011-06-17 15:04:40 +0000 | [diff] [blame] | 426 | SkDevice* device = SkNEW_ARGS(SkDevice, (bitmap)); |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 427 | this->setDevice(device)->unref(); |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 428 | // Tell the reader the appropriate flags to use. |
| 429 | if (this->needOpBytes()) { |
| 430 | this->writeOp(kReportFlags_DrawOp, fFlags, 0); |
| 431 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | SkGPipeCanvas::~SkGPipeCanvas() { |
| 435 | this->finish(); |
| 436 | |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 437 | fFlatArray.freeAll(); |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 438 | fBitmapArray.freeAll(); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 439 | } |
| 440 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 441 | bool SkGPipeCanvas::needOpBytes(size_t needed) { |
| 442 | if (fDone) { |
| 443 | return false; |
| 444 | } |
| 445 | |
| 446 | needed += 4; // size of DrawOp atom |
| 447 | if (fWriter.size() + needed > fBlockSize) { |
scroggo@google.com | 5a2e879 | 2012-04-20 17:39:51 +0000 | [diff] [blame] | 448 | // Before we wipe out any data that has already been written, read it |
| 449 | // out. |
| 450 | this->doNotify(); |
| 451 | size_t blockSize = SkMax32(MIN_BLOCK_SIZE, needed); |
| 452 | void* block = fController->requestBlock(blockSize, &fBlockSize); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 453 | if (NULL == block) { |
| 454 | fDone = true; |
| 455 | return false; |
| 456 | } |
| 457 | fWriter.reset(block, fBlockSize); |
| 458 | fBytesNotified = 0; |
| 459 | } |
| 460 | return true; |
| 461 | } |
| 462 | |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 463 | uint32_t SkGPipeCanvas::getTypefaceID(SkTypeface* face) { |
| 464 | uint32_t id = 0; // 0 means default/null typeface |
| 465 | if (face) { |
| 466 | id = fTypefaceSet.find(face); |
| 467 | if (0 == id) { |
| 468 | id = fTypefaceSet.add(face); |
| 469 | size_t size = writeTypeface(NULL, face); |
| 470 | if (this->needOpBytes(size)) { |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 471 | this->writeOp(kDef_Typeface_DrawOp); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 472 | writeTypeface(&fWriter, face); |
| 473 | } |
| 474 | } |
| 475 | } |
| 476 | return id; |
| 477 | } |
| 478 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 479 | /////////////////////////////////////////////////////////////////////////////// |
| 480 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 481 | #define NOTIFY_SETUP(canvas) \ |
| 482 | AutoPipeNotify apn(canvas) |
| 483 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 484 | int SkGPipeCanvas::save(SaveFlags flags) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 485 | NOTIFY_SETUP(this); |
| 486 | if (this->needOpBytes()) { |
| 487 | this->writeOp(kSave_DrawOp, 0, flags); |
| 488 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 489 | return this->INHERITED::save(flags); |
| 490 | } |
| 491 | |
| 492 | int SkGPipeCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, |
| 493 | SaveFlags saveFlags) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 494 | NOTIFY_SETUP(this); |
| 495 | size_t size = 0; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 496 | unsigned opFlags = 0; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 497 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 498 | if (bounds) { |
| 499 | opFlags |= kSaveLayer_HasBounds_DrawOpFlag; |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 500 | size += sizeof(SkRect); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 501 | } |
| 502 | if (paint) { |
| 503 | opFlags |= kSaveLayer_HasPaint_DrawOpFlag; |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 504 | this->writePaint(*paint); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 505 | } |
| 506 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 507 | if (this->needOpBytes(size)) { |
| 508 | this->writeOp(kSaveLayer_DrawOp, opFlags, saveFlags); |
| 509 | if (bounds) { |
| 510 | fWriter.writeRect(*bounds); |
| 511 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 512 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 513 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 514 | // we just pass on the save, so we don't create a layer |
| 515 | return this->INHERITED::save(saveFlags); |
| 516 | } |
| 517 | |
| 518 | void SkGPipeCanvas::restore() { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 519 | NOTIFY_SETUP(this); |
| 520 | if (this->needOpBytes()) { |
| 521 | this->writeOp(kRestore_DrawOp); |
| 522 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 523 | this->INHERITED::restore(); |
| 524 | } |
| 525 | |
| 526 | bool SkGPipeCanvas::translate(SkScalar dx, SkScalar dy) { |
| 527 | if (dx || dy) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 528 | NOTIFY_SETUP(this); |
| 529 | if (this->needOpBytes(2 * sizeof(SkScalar))) { |
| 530 | this->writeOp(kTranslate_DrawOp); |
| 531 | fWriter.writeScalar(dx); |
| 532 | fWriter.writeScalar(dy); |
| 533 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 534 | } |
| 535 | return this->INHERITED::translate(dx, dy); |
| 536 | } |
| 537 | |
| 538 | bool SkGPipeCanvas::scale(SkScalar sx, SkScalar sy) { |
| 539 | if (sx || sy) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 540 | NOTIFY_SETUP(this); |
| 541 | if (this->needOpBytes(2 * sizeof(SkScalar))) { |
| 542 | this->writeOp(kScale_DrawOp); |
| 543 | fWriter.writeScalar(sx); |
| 544 | fWriter.writeScalar(sy); |
| 545 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 546 | } |
| 547 | return this->INHERITED::scale(sx, sy); |
| 548 | } |
| 549 | |
| 550 | bool SkGPipeCanvas::rotate(SkScalar degrees) { |
| 551 | if (degrees) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 552 | NOTIFY_SETUP(this); |
| 553 | if (this->needOpBytes(sizeof(SkScalar))) { |
| 554 | this->writeOp(kRotate_DrawOp); |
| 555 | fWriter.writeScalar(degrees); |
| 556 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 557 | } |
| 558 | return this->INHERITED::rotate(degrees); |
| 559 | } |
| 560 | |
| 561 | bool SkGPipeCanvas::skew(SkScalar sx, SkScalar sy) { |
| 562 | if (sx || sy) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 563 | NOTIFY_SETUP(this); |
| 564 | if (this->needOpBytes(2 * sizeof(SkScalar))) { |
| 565 | this->writeOp(kSkew_DrawOp); |
| 566 | fWriter.writeScalar(sx); |
| 567 | fWriter.writeScalar(sy); |
| 568 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 569 | } |
| 570 | return this->INHERITED::skew(sx, sy); |
| 571 | } |
| 572 | |
| 573 | bool SkGPipeCanvas::concat(const SkMatrix& matrix) { |
| 574 | if (!matrix.isIdentity()) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 575 | NOTIFY_SETUP(this); |
djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 576 | if (this->needOpBytes(matrix.writeToMemory(NULL))) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 577 | this->writeOp(kConcat_DrawOp); |
djsollen@google.com | 2b2ede3 | 2012-04-12 13:24:04 +0000 | [diff] [blame] | 578 | fWriter.writeMatrix(matrix); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 579 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 580 | } |
| 581 | return this->INHERITED::concat(matrix); |
| 582 | } |
| 583 | |
| 584 | void SkGPipeCanvas::setMatrix(const SkMatrix& matrix) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 585 | NOTIFY_SETUP(this); |
djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 586 | if (this->needOpBytes(matrix.writeToMemory(NULL))) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 587 | this->writeOp(kSetMatrix_DrawOp); |
djsollen@google.com | 2b2ede3 | 2012-04-12 13:24:04 +0000 | [diff] [blame] | 588 | fWriter.writeMatrix(matrix); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 589 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 590 | this->INHERITED::setMatrix(matrix); |
| 591 | } |
| 592 | |
scroggo@google.com | 3b45cd5 | 2012-04-18 13:57:47 +0000 | [diff] [blame] | 593 | bool SkGPipeCanvas::clipRect(const SkRect& rect, SkRegion::Op rgnOp, |
| 594 | bool doAntiAlias) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 595 | NOTIFY_SETUP(this); |
scroggo@google.com | 3b45cd5 | 2012-04-18 13:57:47 +0000 | [diff] [blame] | 596 | if (this->needOpBytes(sizeof(SkRect)) + sizeof(bool)) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 597 | this->writeOp(kClipRect_DrawOp, 0, rgnOp); |
| 598 | fWriter.writeRect(rect); |
scroggo@google.com | 3b45cd5 | 2012-04-18 13:57:47 +0000 | [diff] [blame] | 599 | fWriter.writeBool(doAntiAlias); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 600 | } |
scroggo@google.com | 3b45cd5 | 2012-04-18 13:57:47 +0000 | [diff] [blame] | 601 | return this->INHERITED::clipRect(rect, rgnOp, doAntiAlias); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 602 | } |
| 603 | |
scroggo@google.com | 3b45cd5 | 2012-04-18 13:57:47 +0000 | [diff] [blame] | 604 | bool SkGPipeCanvas::clipPath(const SkPath& path, SkRegion::Op rgnOp, |
| 605 | bool doAntiAlias) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 606 | NOTIFY_SETUP(this); |
djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 607 | if (this->needOpBytes(path.writeToMemory(NULL)) + sizeof(bool)) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 608 | this->writeOp(kClipPath_DrawOp, 0, rgnOp); |
djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 609 | fWriter.writePath(path); |
scroggo@google.com | 3b45cd5 | 2012-04-18 13:57:47 +0000 | [diff] [blame] | 610 | fWriter.writeBool(doAntiAlias); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 611 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 612 | // we just pass on the bounds of the path |
scroggo@google.com | 3b45cd5 | 2012-04-18 13:57:47 +0000 | [diff] [blame] | 613 | return this->INHERITED::clipRect(path.getBounds(), rgnOp, doAntiAlias); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | bool SkGPipeCanvas::clipRegion(const SkRegion& region, SkRegion::Op rgnOp) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 617 | NOTIFY_SETUP(this); |
djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 618 | if (this->needOpBytes(region.writeToMemory(NULL))) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 619 | this->writeOp(kClipRegion_DrawOp, 0, rgnOp); |
djsollen@google.com | 2b2ede3 | 2012-04-12 13:24:04 +0000 | [diff] [blame] | 620 | fWriter.writeRegion(region); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 621 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 622 | return this->INHERITED::clipRegion(region, rgnOp); |
| 623 | } |
| 624 | |
| 625 | /////////////////////////////////////////////////////////////////////////////// |
| 626 | |
| 627 | void SkGPipeCanvas::clear(SkColor color) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 628 | NOTIFY_SETUP(this); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 629 | unsigned flags = 0; |
| 630 | if (color) { |
| 631 | flags |= kClear_HasColor_DrawOpFlag; |
| 632 | } |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 633 | if (this->needOpBytes(sizeof(SkColor))) { |
| 634 | this->writeOp(kDrawClear_DrawOp, flags, 0); |
| 635 | if (color) { |
| 636 | fWriter.write32(color); |
| 637 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 638 | } |
| 639 | } |
| 640 | |
| 641 | void SkGPipeCanvas::drawPaint(const SkPaint& paint) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 642 | NOTIFY_SETUP(this); |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 643 | this->writePaint(paint); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 644 | if (this->needOpBytes()) { |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 645 | this->writeOp(kDrawPaint_DrawOp); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 646 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | void SkGPipeCanvas::drawPoints(PointMode mode, size_t count, |
| 650 | const SkPoint pts[], const SkPaint& paint) { |
| 651 | if (count) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 652 | NOTIFY_SETUP(this); |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 653 | this->writePaint(paint); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 654 | if (this->needOpBytes(4 + count * sizeof(SkPoint))) { |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 655 | this->writeOp(kDrawPoints_DrawOp, mode, 0); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 656 | fWriter.write32(count); |
| 657 | fWriter.write(pts, count * sizeof(SkPoint)); |
| 658 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 659 | } |
| 660 | } |
| 661 | |
| 662 | void SkGPipeCanvas::drawRect(const SkRect& rect, const SkPaint& paint) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 663 | NOTIFY_SETUP(this); |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 664 | this->writePaint(paint); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 665 | if (this->needOpBytes(sizeof(SkRect))) { |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 666 | this->writeOp(kDrawRect_DrawOp); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 667 | fWriter.writeRect(rect); |
| 668 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | void SkGPipeCanvas::drawPath(const SkPath& path, const SkPaint& paint) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 672 | NOTIFY_SETUP(this); |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 673 | this->writePaint(paint); |
djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 674 | if (this->needOpBytes(path.writeToMemory(NULL))) { |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 675 | this->writeOp(kDrawPath_DrawOp); |
djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 676 | fWriter.writePath(path); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 677 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 678 | } |
| 679 | |
scroggo@google.com | 5a2e879 | 2012-04-20 17:39:51 +0000 | [diff] [blame] | 680 | void SkGPipeCanvas::drawBitmap(const SkBitmap& bm, SkScalar left, SkScalar top, |
| 681 | const SkPaint* paint) { |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 682 | bool flatten = shouldFlattenBitmaps(fFlags); |
| 683 | const void* ptr = 0; |
| 684 | int bitmapIndex = 0; |
| 685 | if (flatten) { |
| 686 | bitmapIndex = this->flattenToIndex(bm); |
| 687 | } else { |
| 688 | ptr = fHeap.addBitmap(bm); |
| 689 | if (NULL == ptr) { |
| 690 | return; |
| 691 | } |
scroggo@google.com | 8ae3c7f | 2012-06-13 17:47:52 +0000 | [diff] [blame] | 692 | } |
| 693 | |
scroggo@google.com | 5a2e879 | 2012-04-20 17:39:51 +0000 | [diff] [blame] | 694 | NOTIFY_SETUP(this); |
| 695 | if (paint) { |
| 696 | this->writePaint(*paint); |
| 697 | } |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 698 | |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 699 | size_t opBytesNeeded = sizeof(SkScalar) * 2 + sizeof(bool); |
| 700 | if (!flatten) { |
| 701 | opBytesNeeded += sizeof(void*); |
| 702 | } |
| 703 | if (this->needOpBytes(opBytesNeeded)) { |
| 704 | this->writeOp(kDrawBitmap_DrawOp, 0, bitmapIndex); |
| 705 | if (!flatten) { |
| 706 | fWriter.writePtr(const_cast<void*>(ptr)); |
| 707 | } |
scroggo@google.com | 5a2e879 | 2012-04-20 17:39:51 +0000 | [diff] [blame] | 708 | fWriter.writeBool(paint != NULL); |
| 709 | fWriter.writeScalar(left); |
| 710 | fWriter.writeScalar(top); |
| 711 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 712 | } |
| 713 | |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 714 | void SkGPipeCanvas::drawBitmapRect(const SkBitmap& bm, const SkIRect* src, |
| 715 | const SkRect& dst, const SkPaint* paint) { |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 716 | bool flatten = shouldFlattenBitmaps(fFlags); |
| 717 | const void* ptr = 0; |
| 718 | int bitmapIndex = 0; |
| 719 | if (flatten) { |
| 720 | bitmapIndex = this->flattenToIndex(bm); |
| 721 | } else { |
| 722 | ptr = fHeap.addBitmap(bm); |
| 723 | if (NULL == ptr) { |
| 724 | return; |
| 725 | } |
scroggo@google.com | 8ae3c7f | 2012-06-13 17:47:52 +0000 | [diff] [blame] | 726 | } |
| 727 | |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 728 | NOTIFY_SETUP(this); |
| 729 | if (paint) { |
| 730 | this->writePaint(*paint); |
| 731 | } |
| 732 | |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 733 | size_t opBytesNeeded = sizeof(SkRect) + sizeof(bool) * 2; |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 734 | bool hasSrc = src != NULL; |
| 735 | if (hasSrc) { |
| 736 | opBytesNeeded += sizeof(int32_t) * 4; |
| 737 | } |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 738 | if (!flatten) { |
| 739 | opBytesNeeded += sizeof(void*); |
| 740 | } |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 741 | if (this->needOpBytes(opBytesNeeded)) { |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 742 | this->writeOp(kDrawBitmapRect_DrawOp, 0, bitmapIndex); |
| 743 | if (!flatten) { |
| 744 | fWriter.writePtr(const_cast<void*>(ptr)); |
| 745 | } |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 746 | fWriter.writeBool(paint != NULL); |
| 747 | fWriter.writeBool(hasSrc); |
| 748 | if (hasSrc) { |
| 749 | fWriter.write32(src->fLeft); |
| 750 | fWriter.write32(src->fTop); |
| 751 | fWriter.write32(src->fRight); |
| 752 | fWriter.write32(src->fBottom); |
| 753 | } |
| 754 | fWriter.writeRect(dst); |
| 755 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | void SkGPipeCanvas::drawBitmapMatrix(const SkBitmap&, const SkMatrix&, |
| 759 | const SkPaint*) { |
| 760 | UNIMPLEMENTED |
| 761 | } |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 762 | |
| 763 | void SkGPipeCanvas::drawBitmapNine(const SkBitmap& bm, const SkIRect& center, |
scroggo@google.com | 5a2e879 | 2012-04-20 17:39:51 +0000 | [diff] [blame] | 764 | const SkRect& dst, const SkPaint* paint) { |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 765 | bool flatten = shouldFlattenBitmaps(fFlags); |
| 766 | const void* ptr = 0; |
| 767 | int bitmapIndex = 0; |
| 768 | if (flatten) { |
| 769 | bitmapIndex = this->flattenToIndex(bm); |
| 770 | } else { |
| 771 | ptr = fHeap.addBitmap(bm); |
| 772 | if (NULL == ptr) { |
| 773 | return; |
| 774 | } |
scroggo@google.com | 8ae3c7f | 2012-06-13 17:47:52 +0000 | [diff] [blame] | 775 | } |
| 776 | |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 777 | NOTIFY_SETUP(this); |
| 778 | if (paint) { |
| 779 | this->writePaint(*paint); |
| 780 | } |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 781 | |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 782 | size_t opBytesNeeded = sizeof(int32_t) * 4 + sizeof(bool) + sizeof(SkRect); |
| 783 | if (!flatten) { |
| 784 | opBytesNeeded += sizeof(void*); |
| 785 | } |
| 786 | if (this->needOpBytes(opBytesNeeded)) { |
| 787 | this->writeOp(kDrawBitmapNine_DrawOp, 0, bitmapIndex); |
| 788 | if (!flatten) { |
| 789 | fWriter.writePtr(const_cast<void*>(ptr)); |
| 790 | } |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 791 | fWriter.writeBool(paint != NULL); |
| 792 | fWriter.write32(center.fLeft); |
| 793 | fWriter.write32(center.fTop); |
| 794 | fWriter.write32(center.fRight); |
| 795 | fWriter.write32(center.fBottom); |
| 796 | fWriter.writeRect(dst); |
| 797 | } |
scroggo@google.com | 5a2e879 | 2012-04-20 17:39:51 +0000 | [diff] [blame] | 798 | } |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 799 | |
| 800 | void SkGPipeCanvas::drawSprite(const SkBitmap& bm, int left, int top, |
| 801 | const SkPaint* paint) { |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 802 | bool flatten = shouldFlattenBitmaps(fFlags); |
| 803 | const void* ptr = 0; |
| 804 | int bitmapIndex = 0; |
| 805 | if (flatten) { |
| 806 | bitmapIndex = this->flattenToIndex(bm); |
| 807 | } else { |
| 808 | ptr = fHeap.addBitmap(bm); |
| 809 | if (NULL == ptr) { |
| 810 | return; |
| 811 | } |
scroggo@google.com | 8ae3c7f | 2012-06-13 17:47:52 +0000 | [diff] [blame] | 812 | } |
| 813 | |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 814 | NOTIFY_SETUP(this); |
| 815 | if (paint) { |
| 816 | this->writePaint(*paint); |
| 817 | } |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 818 | |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 819 | size_t opBytesNeeded = sizeof(int32_t) * 2 + sizeof(bool); |
| 820 | if (!flatten) { |
| 821 | opBytesNeeded += sizeof(void*); |
| 822 | } |
| 823 | if (this->needOpBytes(opBytesNeeded)) { |
| 824 | this->writeOp(kDrawSprite_DrawOp, 0, bitmapIndex); |
| 825 | if (!flatten) { |
| 826 | fWriter.writePtr(const_cast<void*>(ptr)); |
| 827 | } |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 828 | fWriter.writeBool(paint != NULL); |
| 829 | fWriter.write32(left); |
| 830 | fWriter.write32(top); |
| 831 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 832 | } |
| 833 | |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 834 | void SkGPipeCanvas::drawText(const void* text, size_t byteLength, SkScalar x, |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 835 | SkScalar y, const SkPaint& paint) { |
| 836 | if (byteLength) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 837 | NOTIFY_SETUP(this); |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 838 | this->writePaint(paint); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 839 | if (this->needOpBytes(4 + SkAlign4(byteLength) + 2 * sizeof(SkScalar))) { |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 840 | this->writeOp(kDrawText_DrawOp); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 841 | fWriter.write32(byteLength); |
| 842 | fWriter.writePad(text, byteLength); |
| 843 | fWriter.writeScalar(x); |
| 844 | fWriter.writeScalar(y); |
| 845 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 846 | } |
| 847 | } |
| 848 | |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 849 | void SkGPipeCanvas::drawPosText(const void* text, size_t byteLength, |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 850 | const SkPoint pos[], const SkPaint& paint) { |
| 851 | if (byteLength) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 852 | NOTIFY_SETUP(this); |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 853 | this->writePaint(paint); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 854 | int count = paint.textToGlyphs(text, byteLength, NULL); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 855 | if (this->needOpBytes(4 + SkAlign4(byteLength) + 4 + count * sizeof(SkPoint))) { |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 856 | this->writeOp(kDrawPosText_DrawOp); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 857 | fWriter.write32(byteLength); |
| 858 | fWriter.writePad(text, byteLength); |
| 859 | fWriter.write32(count); |
| 860 | fWriter.write(pos, count * sizeof(SkPoint)); |
| 861 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 862 | } |
| 863 | } |
| 864 | |
| 865 | void SkGPipeCanvas::drawPosTextH(const void* text, size_t byteLength, |
| 866 | const SkScalar xpos[], SkScalar constY, |
| 867 | const SkPaint& paint) { |
| 868 | if (byteLength) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 869 | NOTIFY_SETUP(this); |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 870 | this->writePaint(paint); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 871 | int count = paint.textToGlyphs(text, byteLength, NULL); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 872 | if (this->needOpBytes(4 + SkAlign4(byteLength) + 4 + count * sizeof(SkScalar) + 4)) { |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 873 | this->writeOp(kDrawPosTextH_DrawOp); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 874 | fWriter.write32(byteLength); |
| 875 | fWriter.writePad(text, byteLength); |
| 876 | fWriter.write32(count); |
| 877 | fWriter.write(xpos, count * sizeof(SkScalar)); |
| 878 | fWriter.writeScalar(constY); |
| 879 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 880 | } |
| 881 | } |
| 882 | |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 883 | void SkGPipeCanvas::drawTextOnPath(const void* text, size_t byteLength, |
| 884 | const SkPath& path, const SkMatrix* matrix, |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 885 | const SkPaint& paint) { |
| 886 | if (byteLength) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 887 | NOTIFY_SETUP(this); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 888 | unsigned flags = 0; |
djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 889 | size_t size = 4 + SkAlign4(byteLength) + path.writeToMemory(NULL); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 890 | if (matrix) { |
| 891 | flags |= kDrawTextOnPath_HasMatrix_DrawOpFlag; |
djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 892 | size += matrix->writeToMemory(NULL); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 893 | } |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 894 | this->writePaint(paint); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 895 | if (this->needOpBytes(size)) { |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 896 | this->writeOp(kDrawTextOnPath_DrawOp, flags, 0); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 897 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 898 | fWriter.write32(byteLength); |
| 899 | fWriter.writePad(text, byteLength); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 900 | |
djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 901 | fWriter.writePath(path); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 902 | if (matrix) { |
djsollen@google.com | 2b2ede3 | 2012-04-12 13:24:04 +0000 | [diff] [blame] | 903 | fWriter.writeMatrix(*matrix); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 904 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 905 | } |
| 906 | } |
| 907 | } |
| 908 | |
| 909 | void SkGPipeCanvas::drawPicture(SkPicture& picture) { |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame] | 910 | // we want to playback the picture into individual draw calls |
| 911 | this->INHERITED::drawPicture(picture); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 912 | } |
| 913 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 914 | void SkGPipeCanvas::drawVertices(VertexMode mode, int vertexCount, |
| 915 | const SkPoint vertices[], const SkPoint texs[], |
| 916 | const SkColor colors[], SkXfermode*, |
| 917 | const uint16_t indices[], int indexCount, |
| 918 | const SkPaint& paint) { |
| 919 | if (0 == vertexCount) { |
| 920 | return; |
| 921 | } |
| 922 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 923 | NOTIFY_SETUP(this); |
| 924 | size_t size = 4 + vertexCount * sizeof(SkPoint); |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 925 | this->writePaint(paint); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 926 | unsigned flags = 0; |
| 927 | if (texs) { |
| 928 | flags |= kDrawVertices_HasTexs_DrawOpFlag; |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 929 | size += vertexCount * sizeof(SkPoint); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 930 | } |
| 931 | if (colors) { |
| 932 | flags |= kDrawVertices_HasColors_DrawOpFlag; |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 933 | size += vertexCount * sizeof(SkColor); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 934 | } |
| 935 | if (indices && indexCount > 0) { |
| 936 | flags |= kDrawVertices_HasIndices_DrawOpFlag; |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 937 | size += 4 + SkAlign4(indexCount * sizeof(uint16_t)); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 938 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 939 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 940 | if (this->needOpBytes(size)) { |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 941 | this->writeOp(kDrawVertices_DrawOp, flags, 0); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 942 | fWriter.write32(mode); |
| 943 | fWriter.write32(vertexCount); |
| 944 | fWriter.write(vertices, vertexCount * sizeof(SkPoint)); |
| 945 | if (texs) { |
| 946 | fWriter.write(texs, vertexCount * sizeof(SkPoint)); |
| 947 | } |
| 948 | if (colors) { |
| 949 | fWriter.write(colors, vertexCount * sizeof(SkColor)); |
| 950 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 951 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 952 | // TODO: flatten xfermode |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 953 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 954 | if (indices && indexCount > 0) { |
| 955 | fWriter.write32(indexCount); |
| 956 | fWriter.writePad(indices, indexCount * sizeof(uint16_t)); |
| 957 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 958 | } |
| 959 | } |
| 960 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 961 | void SkGPipeCanvas::drawData(const void* ptr, size_t size) { |
| 962 | if (size && ptr) { |
| 963 | NOTIFY_SETUP(this); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 964 | unsigned data = 0; |
| 965 | if (size < (1 << DRAWOPS_DATA_BITS)) { |
| 966 | data = (unsigned)size; |
| 967 | } |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 968 | if (this->needOpBytes(4 + SkAlign4(size))) { |
| 969 | this->writeOp(kDrawData_DrawOp, 0, data); |
| 970 | if (0 == data) { |
| 971 | fWriter.write32(size); |
| 972 | } |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 973 | fWriter.writePad(ptr, size); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 974 | } |
| 975 | } |
| 976 | } |
| 977 | |
| 978 | /////////////////////////////////////////////////////////////////////////////// |
| 979 | |
| 980 | template <typename T> uint32_t castToU32(T value) { |
| 981 | union { |
| 982 | T fSrc; |
| 983 | uint32_t fDst; |
| 984 | } data; |
| 985 | data.fSrc = value; |
| 986 | return data.fDst; |
| 987 | } |
| 988 | |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 989 | void SkGPipeCanvas::writePaint(const SkPaint& paint) { |
| 990 | SkPaint& base = fPaint; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 991 | uint32_t storage[32]; |
| 992 | uint32_t* ptr = storage; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 993 | |
| 994 | if (base.getFlags() != paint.getFlags()) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 995 | *ptr++ = PaintOp_packOpData(kFlags_PaintOp, paint.getFlags()); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 996 | base.setFlags(paint.getFlags()); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 997 | } |
| 998 | if (base.getColor() != paint.getColor()) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 999 | *ptr++ = PaintOp_packOp(kColor_PaintOp); |
| 1000 | *ptr++ = paint.getColor(); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 1001 | base.setColor(paint.getColor()); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1002 | } |
| 1003 | if (base.getStyle() != paint.getStyle()) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1004 | *ptr++ = PaintOp_packOpData(kStyle_PaintOp, paint.getStyle()); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 1005 | base.setStyle(paint.getStyle()); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1006 | } |
| 1007 | if (base.getStrokeJoin() != paint.getStrokeJoin()) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1008 | *ptr++ = PaintOp_packOpData(kJoin_PaintOp, paint.getStrokeJoin()); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 1009 | base.setStrokeJoin(paint.getStrokeJoin()); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1010 | } |
| 1011 | if (base.getStrokeCap() != paint.getStrokeCap()) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1012 | *ptr++ = PaintOp_packOpData(kCap_PaintOp, paint.getStrokeCap()); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 1013 | base.setStrokeCap(paint.getStrokeCap()); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1014 | } |
| 1015 | if (base.getStrokeWidth() != paint.getStrokeWidth()) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1016 | *ptr++ = PaintOp_packOp(kWidth_PaintOp); |
| 1017 | *ptr++ = castToU32(paint.getStrokeWidth()); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 1018 | base.setStrokeWidth(paint.getStrokeWidth()); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1019 | } |
| 1020 | if (base.getStrokeMiter() != paint.getStrokeMiter()) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1021 | *ptr++ = PaintOp_packOp(kMiter_PaintOp); |
| 1022 | *ptr++ = castToU32(paint.getStrokeMiter()); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 1023 | base.setStrokeMiter(paint.getStrokeMiter()); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1024 | } |
| 1025 | if (base.getTextEncoding() != paint.getTextEncoding()) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1026 | *ptr++ = PaintOp_packOpData(kEncoding_PaintOp, paint.getTextEncoding()); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 1027 | base.setTextEncoding(paint.getTextEncoding()); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1028 | } |
| 1029 | if (base.getHinting() != paint.getHinting()) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1030 | *ptr++ = PaintOp_packOpData(kHinting_PaintOp, paint.getHinting()); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 1031 | base.setHinting(paint.getHinting()); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1032 | } |
| 1033 | if (base.getTextAlign() != paint.getTextAlign()) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1034 | *ptr++ = PaintOp_packOpData(kAlign_PaintOp, paint.getTextAlign()); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 1035 | base.setTextAlign(paint.getTextAlign()); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1036 | } |
| 1037 | if (base.getTextSize() != paint.getTextSize()) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1038 | *ptr++ = PaintOp_packOp(kTextSize_PaintOp); |
| 1039 | *ptr++ = castToU32(paint.getTextSize()); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 1040 | base.setTextSize(paint.getTextSize()); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1041 | } |
| 1042 | if (base.getTextScaleX() != paint.getTextScaleX()) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1043 | *ptr++ = PaintOp_packOp(kTextScaleX_PaintOp); |
| 1044 | *ptr++ = castToU32(paint.getTextScaleX()); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 1045 | base.setTextScaleX(paint.getTextScaleX()); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1046 | } |
| 1047 | if (base.getTextSkewX() != paint.getTextSkewX()) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1048 | *ptr++ = PaintOp_packOp(kTextSkewX_PaintOp); |
| 1049 | *ptr++ = castToU32(paint.getTextSkewX()); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 1050 | base.setTextSkewX(paint.getTextSkewX()); |
| 1051 | } |
| 1052 | |
| 1053 | if (!SkTypeface::Equal(base.getTypeface(), paint.getTypeface())) { |
| 1054 | uint32_t id = this->getTypefaceID(paint.getTypeface()); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 1055 | *ptr++ = PaintOp_packOpData(kTypeface_PaintOp, id); |
| 1056 | base.setTypeface(paint.getTypeface()); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1057 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1058 | |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 1059 | for (int i = 0; i < kCount_PaintFlats; i++) { |
| 1060 | int index = this->flattenToIndex(get_paintflat(paint, i), (PaintFlats)i); |
scroggo@google.com | d3ba5cc | 2012-07-09 16:05:53 +0000 | [diff] [blame] | 1061 | bool replaced = index < 0; |
| 1062 | if (replaced) { |
| 1063 | index = ~index; |
| 1064 | } |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 1065 | SkASSERT(index >= 0 && index <= fFlatArray.count()); |
scroggo@google.com | d3ba5cc | 2012-07-09 16:05:53 +0000 | [diff] [blame] | 1066 | if (index != fCurrFlatIndex[i] || replaced) { |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 1067 | *ptr++ = PaintOp_packOpFlagData(kFlatIndex_PaintOp, i, index); |
| 1068 | fCurrFlatIndex[i] = index; |
| 1069 | } |
| 1070 | } |
| 1071 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 1072 | size_t size = (char*)ptr - (char*)storage; |
| 1073 | if (size && this->needOpBytes(size)) { |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 1074 | this->writeOp(kPaintOp_DrawOp, 0, size); |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 1075 | fWriter.write(storage, size); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1076 | for (size_t i = 0; i < size/4; i++) { |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 1077 | // SkDebugf("[%d] %08X\n", i, storage[i]); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1078 | } |
| 1079 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | /////////////////////////////////////////////////////////////////////////////// |
| 1083 | |
| 1084 | #include "SkGPipe.h" |
| 1085 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 1086 | SkGPipeWriter::SkGPipeWriter() : fWriter(0) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1087 | fCanvas = NULL; |
| 1088 | } |
| 1089 | |
| 1090 | SkGPipeWriter::~SkGPipeWriter() { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 1091 | this->endRecording(); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1092 | SkSafeUnref(fCanvas); |
| 1093 | } |
| 1094 | |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 1095 | SkCanvas* SkGPipeWriter::startRecording(SkGPipeController* controller, uint32_t flags) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1096 | if (NULL == fCanvas) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 1097 | fWriter.reset(NULL, 0); |
reed@google.com | dde0956 | 2011-05-23 12:21:05 +0000 | [diff] [blame] | 1098 | fFactorySet.reset(); |
| 1099 | fCanvas = SkNEW_ARGS(SkGPipeCanvas, (controller, &fWriter, |
| 1100 | (flags & kCrossProcess_Flag) ? |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 1101 | &fFactorySet : NULL, flags)); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1102 | } |
| 1103 | return fCanvas; |
| 1104 | } |
| 1105 | |
| 1106 | void SkGPipeWriter::endRecording() { |
| 1107 | if (fCanvas) { |
| 1108 | fCanvas->finish(); |
| 1109 | fCanvas->unref(); |
| 1110 | fCanvas = NULL; |
| 1111 | } |
| 1112 | } |
| 1113 | |