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