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