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 | |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 9 | #include "SkAnnotation.h" |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 10 | #include "SkBitmapDevice.h" |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 11 | #include "SkBitmapHeap.h" |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 12 | #include "SkCanvas.h" |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 13 | #include "SkColorFilter.h" |
reed@google.com | 8a85d0c | 2011-06-24 19:12:12 +0000 | [diff] [blame] | 14 | #include "SkData.h" |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 15 | #include "SkDrawLooper.h" |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 16 | #include "SkGPipe.h" |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 17 | #include "SkGPipePriv.h" |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 18 | #include "SkImageFilter.h" |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 19 | #include "SkMaskFilter.h" |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 20 | #include "SkWriteBuffer.h" |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 21 | #include "SkPaint.h" |
| 22 | #include "SkPathEffect.h" |
| 23 | #include "SkPictureFlat.h" |
| 24 | #include "SkRasterizer.h" |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 25 | #include "SkRRect.h" |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 26 | #include "SkShader.h" |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 27 | #include "SkStream.h" |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 28 | #include "SkTSearch.h" |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 29 | #include "SkTypeface.h" |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 30 | #include "SkWriter32.h" |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 31 | |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 32 | enum { |
| 33 | kSizeOfFlatRRect = sizeof(SkRect) + 4 * sizeof(SkVector) |
| 34 | }; |
| 35 | |
scroggo@google.com | 0c3e5fe | 2012-08-01 19:34:20 +0000 | [diff] [blame] | 36 | static bool isCrossProcess(uint32_t flags) { |
| 37 | return SkToBool(flags & SkGPipeWriter::kCrossProcess_Flag); |
| 38 | } |
| 39 | |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 40 | static SkFlattenable* get_paintflat(const SkPaint& paint, unsigned paintFlat) { |
| 41 | SkASSERT(paintFlat < kCount_PaintFlats); |
| 42 | switch (paintFlat) { |
| 43 | case kColorFilter_PaintFlat: return paint.getColorFilter(); |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame] | 44 | case kDrawLooper_PaintFlat: return paint.getLooper(); |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 45 | case kMaskFilter_PaintFlat: return paint.getMaskFilter(); |
| 46 | case kPathEffect_PaintFlat: return paint.getPathEffect(); |
| 47 | case kRasterizer_PaintFlat: return paint.getRasterizer(); |
| 48 | case kShader_PaintFlat: return paint.getShader(); |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 49 | case kImageFilter_PaintFlat: return paint.getImageFilter(); |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 50 | case kXfermode_PaintFlat: return paint.getXfermode(); |
| 51 | } |
tomhudson@google.com | 0c00f21 | 2011-12-28 14:59:50 +0000 | [diff] [blame] | 52 | SkDEBUGFAIL("never gets here"); |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 53 | return NULL; |
| 54 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 55 | |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 56 | static size_t writeTypeface(SkWriter32* writer, SkTypeface* typeface) { |
| 57 | SkASSERT(typeface); |
| 58 | SkDynamicMemoryWStream stream; |
| 59 | typeface->serialize(&stream); |
| 60 | size_t size = stream.getOffset(); |
| 61 | if (writer) { |
commit-bot@chromium.org | b45bd1f | 2014-04-24 18:17:30 +0000 | [diff] [blame] | 62 | writer->write32(SkToU32(size)); |
reed@google.com | 8a85d0c | 2011-06-24 19:12:12 +0000 | [diff] [blame] | 63 | SkAutoDataUnref data(stream.copyToData()); |
robertphillips@google.com | 59f46b8 | 2012-07-10 17:30:58 +0000 | [diff] [blame] | 64 | writer->writePad(data->data(), size); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 65 | } |
scroggo@google.com | 5af9b20 | 2012-06-04 17:17:36 +0000 | [diff] [blame] | 66 | return 4 + SkAlign4(size); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 67 | } |
| 68 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 69 | /////////////////////////////////////////////////////////////////////////////// |
| 70 | |
scroggo@google.com | 4dffc59 | 2012-07-17 16:49:40 +0000 | [diff] [blame] | 71 | class FlattenableHeap : public SkFlatController { |
| 72 | public: |
scroggo@google.com | 664fab1 | 2012-08-14 19:22:05 +0000 | [diff] [blame] | 73 | FlattenableHeap(int numFlatsToKeep, SkNamedFactorySet* fset, bool isCrossProcess) |
commit-bot@chromium.org | a2bd2d1 | 2014-01-30 22:16:32 +0000 | [diff] [blame] | 74 | : INHERITED(isCrossProcess ? SkWriteBuffer::kCrossProcess_Flag : 0) |
| 75 | , fNumFlatsToKeep(numFlatsToKeep) { |
scroggo@google.com | 664fab1 | 2012-08-14 19:22:05 +0000 | [diff] [blame] | 76 | SkASSERT((isCrossProcess && fset != NULL) || (!isCrossProcess && NULL == fset)); |
| 77 | if (isCrossProcess) { |
| 78 | this->setNamedFactorySet(fset); |
scroggo@google.com | 664fab1 | 2012-08-14 19:22:05 +0000 | [diff] [blame] | 79 | } |
scroggo@google.com | 0c3e5fe | 2012-08-01 19:34:20 +0000 | [diff] [blame] | 80 | } |
scroggo@google.com | 4dffc59 | 2012-07-17 16:49:40 +0000 | [diff] [blame] | 81 | |
| 82 | ~FlattenableHeap() { |
| 83 | fPointers.freeAll(); |
| 84 | } |
| 85 | |
| 86 | virtual void* allocThrow(size_t bytes) SK_OVERRIDE; |
| 87 | |
| 88 | virtual void unalloc(void* ptr) SK_OVERRIDE; |
| 89 | |
scroggo@google.com | 7ca2443 | 2012-08-14 15:48:43 +0000 | [diff] [blame] | 90 | void setBitmapStorage(SkBitmapHeap* heap) { |
| 91 | this->setBitmapHeap(heap); |
| 92 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 93 | |
scroggo@google.com | 4dffc59 | 2012-07-17 16:49:40 +0000 | [diff] [blame] | 94 | const SkFlatData* flatToReplace() const; |
| 95 | |
| 96 | // Mark an SkFlatData as one that should not be returned by flatToReplace. |
| 97 | // Takes the result of SkFlatData::index() as its parameter. |
| 98 | void markFlatForKeeping(int index) { |
| 99 | *fFlatsThatMustBeKept.append() = index; |
| 100 | } |
| 101 | |
| 102 | void markAllFlatsSafeToDelete() { |
| 103 | fFlatsThatMustBeKept.reset(); |
| 104 | } |
| 105 | |
| 106 | private: |
| 107 | // Keep track of the indices (i.e. the result of SkFlatData::index()) of |
| 108 | // flats that must be kept, since they are on the current paint. |
| 109 | SkTDArray<int> fFlatsThatMustBeKept; |
| 110 | SkTDArray<void*> fPointers; |
| 111 | const int fNumFlatsToKeep; |
commit-bot@chromium.org | a2bd2d1 | 2014-01-30 22:16:32 +0000 | [diff] [blame] | 112 | |
| 113 | typedef SkFlatController INHERITED; |
scroggo@google.com | 4dffc59 | 2012-07-17 16:49:40 +0000 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | void FlattenableHeap::unalloc(void* ptr) { |
| 117 | int indexToRemove = fPointers.rfind(ptr); |
| 118 | if (indexToRemove >= 0) { |
| 119 | sk_free(ptr); |
| 120 | fPointers.remove(indexToRemove); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | void* FlattenableHeap::allocThrow(size_t bytes) { |
| 125 | void* ptr = sk_malloc_throw(bytes); |
| 126 | *fPointers.append() = ptr; |
| 127 | return ptr; |
| 128 | } |
| 129 | |
| 130 | const SkFlatData* FlattenableHeap::flatToReplace() const { |
| 131 | // First, determine whether we should replace one. |
| 132 | if (fPointers.count() > fNumFlatsToKeep) { |
| 133 | // Look through the flattenable heap. |
| 134 | // TODO: Return the LRU flat. |
| 135 | for (int i = 0; i < fPointers.count(); i++) { |
| 136 | SkFlatData* potential = (SkFlatData*)fPointers[i]; |
| 137 | // Make sure that it is not one that must be kept. |
| 138 | bool mustKeep = false; |
| 139 | for (int j = 0; j < fFlatsThatMustBeKept.count(); j++) { |
| 140 | if (potential->index() == fFlatsThatMustBeKept[j]) { |
| 141 | mustKeep = true; |
| 142 | break; |
| 143 | } |
| 144 | } |
| 145 | if (!mustKeep) { |
| 146 | return potential; |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | return NULL; |
| 151 | } |
| 152 | |
| 153 | /////////////////////////////////////////////////////////////////////////////// |
| 154 | |
commit-bot@chromium.org | 07adb63 | 2014-01-02 22:20:49 +0000 | [diff] [blame] | 155 | struct SkFlattenableTraits { |
commit-bot@chromium.org | 186c0cc | 2014-02-18 16:15:05 +0000 | [diff] [blame] | 156 | static void Flatten(SkWriteBuffer& buffer, const SkFlattenable& flattenable) { |
commit-bot@chromium.org | 07adb63 | 2014-01-02 22:20:49 +0000 | [diff] [blame] | 157 | buffer.writeFlattenable(&flattenable); |
scroggo@google.com | 4dffc59 | 2012-07-17 16:49:40 +0000 | [diff] [blame] | 158 | } |
commit-bot@chromium.org | 07adb63 | 2014-01-02 22:20:49 +0000 | [diff] [blame] | 159 | // No need to define unflatten if we never call it. |
scroggo@google.com | 4dffc59 | 2012-07-17 16:49:40 +0000 | [diff] [blame] | 160 | }; |
commit-bot@chromium.org | 07adb63 | 2014-01-02 22:20:49 +0000 | [diff] [blame] | 161 | typedef SkFlatDictionary<SkFlattenable, SkFlattenableTraits> FlatDictionary; |
scroggo@google.com | 4dffc59 | 2012-07-17 16:49:40 +0000 | [diff] [blame] | 162 | |
| 163 | /////////////////////////////////////////////////////////////////////////////// |
| 164 | |
scroggo@google.com | 59c3ab6 | 2013-11-12 14:32:38 +0000 | [diff] [blame] | 165 | /** |
| 166 | * If SkBitmaps are to be flattened to send to the reader, this class is |
| 167 | * provided to the SkBitmapHeap to tell the SkGPipeCanvas to do so. |
| 168 | */ |
| 169 | class BitmapShuttle : public SkBitmapHeap::ExternalStorage { |
| 170 | public: |
| 171 | BitmapShuttle(SkGPipeCanvas*); |
| 172 | |
| 173 | ~BitmapShuttle(); |
| 174 | |
| 175 | virtual bool insert(const SkBitmap& bitmap, int32_t slot) SK_OVERRIDE; |
| 176 | |
| 177 | /** |
| 178 | * Remove the SkGPipeCanvas used for insertion. After this, calls to |
| 179 | * insert will crash. |
| 180 | */ |
| 181 | void removeCanvas(); |
| 182 | |
| 183 | private: |
| 184 | SkGPipeCanvas* fCanvas; |
| 185 | }; |
| 186 | |
| 187 | /////////////////////////////////////////////////////////////////////////////// |
| 188 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 189 | class SkGPipeCanvas : public SkCanvas { |
| 190 | public: |
junov@chromium.org | a8db8fe | 2012-08-15 19:49:22 +0000 | [diff] [blame] | 191 | SkGPipeCanvas(SkGPipeController*, SkWriter32*, uint32_t flags, |
| 192 | uint32_t width, uint32_t height); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 193 | virtual ~SkGPipeCanvas(); |
| 194 | |
scroggo@google.com | 59c3ab6 | 2013-11-12 14:32:38 +0000 | [diff] [blame] | 195 | /** |
| 196 | * Called when nothing else is to be written to the stream. Any repeated |
| 197 | * calls are ignored. |
| 198 | * |
| 199 | * @param notifyReaders Whether to send a message to the reader(s) that |
| 200 | * the writer is through sending commands. Should generally be true, |
| 201 | * unless there is an error which prevents further messages from |
| 202 | * being sent. |
| 203 | */ |
| 204 | void finish(bool notifyReaders) { |
| 205 | if (fDone) { |
| 206 | return; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 207 | } |
scroggo@google.com | 59c3ab6 | 2013-11-12 14:32:38 +0000 | [diff] [blame] | 208 | if (notifyReaders && this->needOpBytes()) { |
| 209 | this->writeOp(kDone_DrawOp); |
| 210 | this->doNotify(); |
| 211 | } |
| 212 | if (shouldFlattenBitmaps(fFlags)) { |
| 213 | // The following circular references exist: |
| 214 | // fFlattenableHeap -> fWriteBuffer -> fBitmapStorage -> fExternalStorage -> fCanvas |
| 215 | // fBitmapHeap -> fExternalStorage -> fCanvas |
| 216 | // fFlattenableHeap -> fBitmapStorage -> fExternalStorage -> fCanvas |
| 217 | |
| 218 | // Break them all by destroying the final link to this SkGPipeCanvas. |
| 219 | fBitmapShuttle->removeCanvas(); |
| 220 | } |
| 221 | fDone = true; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 222 | } |
| 223 | |
junov@chromium.org | 77eec24 | 2012-07-18 17:54:45 +0000 | [diff] [blame] | 224 | void flushRecording(bool detachCurrentBlock); |
junov@chromium.org | 2e14ba8 | 2012-08-07 14:26:57 +0000 | [diff] [blame] | 225 | size_t freeMemoryIfPossible(size_t bytesToFree); |
junov@chromium.org | 77eec24 | 2012-07-18 17:54:45 +0000 | [diff] [blame] | 226 | |
scroggo@google.com | 15011ee | 2012-07-26 20:03:32 +0000 | [diff] [blame] | 227 | size_t storageAllocatedForRecording() { |
scroggo@google.com | d5d158b | 2012-08-14 20:38:28 +0000 | [diff] [blame] | 228 | return (NULL == fBitmapHeap) ? 0 : fBitmapHeap->bytesAllocated(); |
scroggo@google.com | 15011ee | 2012-07-26 20:03:32 +0000 | [diff] [blame] | 229 | } |
| 230 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 231 | // overrides from SkCanvas |
junov@chromium.org | fbe9c8f | 2012-07-18 20:22:52 +0000 | [diff] [blame] | 232 | virtual bool isDrawingToLayer() const SK_OVERRIDE; |
scroggo@google.com | 3b45cd5 | 2012-04-18 13:57:47 +0000 | [diff] [blame] | 233 | virtual void clear(SkColor) SK_OVERRIDE; |
| 234 | virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 235 | virtual void drawPoints(PointMode, size_t count, const SkPoint pts[], |
scroggo@google.com | 3b45cd5 | 2012-04-18 13:57:47 +0000 | [diff] [blame] | 236 | const SkPaint&) SK_OVERRIDE; |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 237 | virtual void drawOval(const SkRect&, const SkPaint&) SK_OVERRIDE; |
bsalomon@google.com | 7ce564c | 2013-10-22 16:54:15 +0000 | [diff] [blame] | 238 | virtual void drawRect(const SkRect& rect, const SkPaint&) SK_OVERRIDE; |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 239 | virtual void drawRRect(const SkRRect&, const SkPaint&) SK_OVERRIDE; |
bsalomon@google.com | 7ce564c | 2013-10-22 16:54:15 +0000 | [diff] [blame] | 240 | virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 241 | virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top, |
scroggo@google.com | 3b45cd5 | 2012-04-18 13:57:47 +0000 | [diff] [blame] | 242 | const SkPaint*) SK_OVERRIDE; |
reed@google.com | 7112173 | 2012-09-18 15:14:33 +0000 | [diff] [blame] | 243 | virtual void drawBitmapRectToRect(const SkBitmap&, const SkRect* src, |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 244 | const SkRect& dst, const SkPaint* paint, |
commit-bot@chromium.org | eed779d | 2013-08-16 10:24:37 +0000 | [diff] [blame] | 245 | DrawBitmapRectFlags flags) SK_OVERRIDE; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 246 | virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&, |
scroggo@google.com | 3b45cd5 | 2012-04-18 13:57:47 +0000 | [diff] [blame] | 247 | const SkPaint*) SK_OVERRIDE; |
scroggo@google.com | 5a2e879 | 2012-04-20 17:39:51 +0000 | [diff] [blame] | 248 | virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
| 249 | const SkRect& dst, const SkPaint* paint = NULL) SK_OVERRIDE; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 250 | virtual void drawSprite(const SkBitmap&, int left, int top, |
scroggo@google.com | 3b45cd5 | 2012-04-18 13:57:47 +0000 | [diff] [blame] | 251 | const SkPaint*) SK_OVERRIDE; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 252 | virtual void drawVertices(VertexMode, int vertexCount, |
| 253 | const SkPoint vertices[], const SkPoint texs[], |
| 254 | const SkColor colors[], SkXfermode*, |
| 255 | const uint16_t indices[], int indexCount, |
scroggo@google.com | 3b45cd5 | 2012-04-18 13:57:47 +0000 | [diff] [blame] | 256 | const SkPaint&) SK_OVERRIDE; |
dandov | 963137b | 2014-08-07 07:49:53 -0700 | [diff] [blame] | 257 | virtual void drawPatch(const SkPatch& patch, const SkPaint& paint) SK_OVERRIDE; |
scroggo@google.com | 3b45cd5 | 2012-04-18 13:57:47 +0000 | [diff] [blame] | 258 | virtual void drawData(const void*, size_t) SK_OVERRIDE; |
robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 259 | virtual void beginCommentGroup(const char* description) SK_OVERRIDE; |
| 260 | virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE; |
| 261 | virtual void endCommentGroup() SK_OVERRIDE; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 262 | |
scroggo@google.com | 3e26bd0 | 2012-08-14 15:20:01 +0000 | [diff] [blame] | 263 | /** |
| 264 | * Flatten an SkBitmap to send to the reader, where it will be referenced |
| 265 | * according to slot. |
| 266 | */ |
| 267 | bool shuttleBitmap(const SkBitmap&, int32_t slot); |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 268 | |
| 269 | protected: |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 270 | virtual void willSave() SK_OVERRIDE; |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 271 | virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE; |
| 272 | virtual void willRestore() SK_OVERRIDE; |
| 273 | |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 274 | virtual void didConcat(const SkMatrix&) SK_OVERRIDE; |
| 275 | virtual void didSetMatrix(const SkMatrix&) SK_OVERRIDE; |
| 276 | |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 277 | virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE; |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 278 | virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
| 279 | const SkPaint&) SK_OVERRIDE; |
| 280 | virtual void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[], |
| 281 | const SkPaint&) SK_OVERRIDE; |
| 282 | virtual void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], |
| 283 | SkScalar constY, const SkPaint&) SK_OVERRIDE; |
| 284 | virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path, |
| 285 | const SkMatrix* matrix, const SkPaint&) SK_OVERRIDE; |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 286 | |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 287 | virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; |
| 288 | virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; |
| 289 | virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; |
| 290 | virtual void onClipRegion(const SkRegion&, SkRegion::Op) SK_OVERRIDE; |
| 291 | |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 292 | virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) SK_OVERRIDE; |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 293 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 294 | private: |
commit-bot@chromium.org | d9ea09e | 2014-03-25 17:32:26 +0000 | [diff] [blame] | 295 | void recordTranslate(const SkMatrix&); |
| 296 | void recordScale(const SkMatrix&); |
| 297 | void recordConcat(const SkMatrix&); |
| 298 | |
junov@chromium.org | fbe9c8f | 2012-07-18 20:22:52 +0000 | [diff] [blame] | 299 | enum { |
| 300 | kNoSaveLayer = -1, |
| 301 | }; |
scroggo@google.com | 0c3e5fe | 2012-08-01 19:34:20 +0000 | [diff] [blame] | 302 | SkNamedFactorySet* fFactorySet; |
| 303 | int fFirstSaveLayerStackLevel; |
scroggo@google.com | d9d2967 | 2012-08-14 17:21:34 +0000 | [diff] [blame] | 304 | SkBitmapHeap* fBitmapHeap; |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 305 | SkGPipeController* fController; |
scroggo@google.com | 0c3e5fe | 2012-08-01 19:34:20 +0000 | [diff] [blame] | 306 | SkWriter32& fWriter; |
| 307 | size_t fBlockSize; // amount allocated for writer |
| 308 | size_t fBytesNotified; |
| 309 | bool fDone; |
scroggo@google.com | 3e26bd0 | 2012-08-14 15:20:01 +0000 | [diff] [blame] | 310 | const uint32_t fFlags; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 311 | |
scroggo@google.com | 0c3e5fe | 2012-08-01 19:34:20 +0000 | [diff] [blame] | 312 | SkRefCntSet fTypefaceSet; |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 313 | |
| 314 | uint32_t getTypefaceID(SkTypeface*); |
| 315 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 316 | inline void writeOp(DrawOps op, unsigned flags, unsigned data) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 317 | fWriter.write32(DrawOp_packOpFlagData(op, flags, data)); |
| 318 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 319 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 320 | inline void writeOp(DrawOps op) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 321 | fWriter.write32(DrawOp_packOpFlagData(op, 0, 0)); |
| 322 | } |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 323 | |
| 324 | bool needOpBytes(size_t size = 0); |
| 325 | |
| 326 | inline void doNotify() { |
| 327 | if (!fDone) { |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 328 | size_t bytes = fWriter.bytesWritten() - fBytesNotified; |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 329 | if (bytes > 0) { |
| 330 | fController->notifyWritten(bytes); |
| 331 | fBytesNotified += bytes; |
| 332 | } |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 333 | } |
| 334 | } |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 335 | |
scroggo@google.com | 0c3e5fe | 2012-08-01 19:34:20 +0000 | [diff] [blame] | 336 | // Should be called after any calls to an SkFlatDictionary::findAndReplace |
| 337 | // if a new SkFlatData was added when in cross process mode |
| 338 | void flattenFactoryNames(); |
| 339 | |
scroggo@google.com | 59c3ab6 | 2013-11-12 14:32:38 +0000 | [diff] [blame] | 340 | FlattenableHeap fFlattenableHeap; |
| 341 | FlatDictionary fFlatDictionary; |
| 342 | SkAutoTUnref<BitmapShuttle> fBitmapShuttle; |
| 343 | int fCurrFlatIndex[kCount_PaintFlats]; |
| 344 | |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 345 | int flattenToIndex(SkFlattenable* obj, PaintFlats); |
| 346 | |
scroggo@google.com | 3e26bd0 | 2012-08-14 15:20:01 +0000 | [diff] [blame] | 347 | // Common code used by drawBitmap*. Behaves differently depending on the |
| 348 | // type of SkBitmapHeap being used, which is determined by the flags used. |
| 349 | bool commonDrawBitmap(const SkBitmap& bm, DrawOps op, unsigned flags, |
| 350 | size_t opBytesNeeded, const SkPaint* paint); |
scroggo@google.com | 58be682 | 2012-07-30 14:40:01 +0000 | [diff] [blame] | 351 | |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 352 | SkPaint fPaint; |
| 353 | void writePaint(const SkPaint&); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 354 | |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 355 | class AutoPipeNotify { |
| 356 | public: |
| 357 | AutoPipeNotify(SkGPipeCanvas* canvas) : fCanvas(canvas) {} |
| 358 | ~AutoPipeNotify() { fCanvas->doNotify(); } |
| 359 | private: |
| 360 | SkGPipeCanvas* fCanvas; |
| 361 | }; |
| 362 | friend class AutoPipeNotify; |
| 363 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 364 | typedef SkCanvas INHERITED; |
| 365 | }; |
| 366 | |
scroggo@google.com | 0c3e5fe | 2012-08-01 19:34:20 +0000 | [diff] [blame] | 367 | void SkGPipeCanvas::flattenFactoryNames() { |
| 368 | const char* name; |
| 369 | while ((name = fFactorySet->getNextAddedFactoryName()) != NULL) { |
| 370 | size_t len = strlen(name); |
commit-bot@chromium.org | d049017 | 2014-05-14 15:12:08 +0000 | [diff] [blame] | 371 | if (this->needOpBytes(SkWriter32::WriteStringSize(name, len))) { |
scroggo@google.com | 0c3e5fe | 2012-08-01 19:34:20 +0000 | [diff] [blame] | 372 | this->writeOp(kDef_Factory_DrawOp); |
| 373 | fWriter.writeString(name, len); |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | |
scroggo@google.com | 3e26bd0 | 2012-08-14 15:20:01 +0000 | [diff] [blame] | 378 | bool SkGPipeCanvas::shuttleBitmap(const SkBitmap& bm, int32_t slot) { |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 379 | SkASSERT(shouldFlattenBitmaps(fFlags)); |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 380 | SkWriteBuffer buffer; |
scroggo@google.com | 3e26bd0 | 2012-08-14 15:20:01 +0000 | [diff] [blame] | 381 | buffer.setNamedFactoryRecorder(fFactorySet); |
scroggo@google.com | 74b7ffd | 2013-04-30 02:32:41 +0000 | [diff] [blame] | 382 | buffer.writeBitmap(bm); |
scroggo@google.com | 3e26bd0 | 2012-08-14 15:20:01 +0000 | [diff] [blame] | 383 | this->flattenFactoryNames(); |
commit-bot@chromium.org | b45bd1f | 2014-04-24 18:17:30 +0000 | [diff] [blame] | 384 | size_t size = buffer.bytesWritten(); |
scroggo@google.com | 3e26bd0 | 2012-08-14 15:20:01 +0000 | [diff] [blame] | 385 | if (this->needOpBytes(size)) { |
| 386 | this->writeOp(kDef_Bitmap_DrawOp, 0, slot); |
| 387 | void* dst = static_cast<void*>(fWriter.reserve(size)); |
| 388 | buffer.writeToMemory(dst); |
| 389 | return true; |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 390 | } |
scroggo@google.com | 3e26bd0 | 2012-08-14 15:20:01 +0000 | [diff] [blame] | 391 | return false; |
scroggo@google.com | d3ba5cc | 2012-07-09 16:05:53 +0000 | [diff] [blame] | 392 | } |
| 393 | |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 394 | // return 0 for NULL (or unflattenable obj), or index-base-1 |
scroggo@google.com | d3ba5cc | 2012-07-09 16:05:53 +0000 | [diff] [blame] | 395 | // return ~(index-base-1) if an old flattenable was replaced |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 396 | int SkGPipeCanvas::flattenToIndex(SkFlattenable* obj, PaintFlats paintflat) { |
scroggo@google.com | d5d158b | 2012-08-14 20:38:28 +0000 | [diff] [blame] | 397 | SkASSERT(!fDone && fBitmapHeap != NULL); |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 398 | if (NULL == obj) { |
| 399 | return 0; |
| 400 | } |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 401 | |
scroggo@google.com | d9d2967 | 2012-08-14 17:21:34 +0000 | [diff] [blame] | 402 | fBitmapHeap->deferAddingOwners(); |
scroggo@google.com | 4dffc59 | 2012-07-17 16:49:40 +0000 | [diff] [blame] | 403 | bool added, replaced; |
scroggo@google.com | 664fab1 | 2012-08-14 19:22:05 +0000 | [diff] [blame] | 404 | const SkFlatData* flat = fFlatDictionary.findAndReplace(*obj, fFlattenableHeap.flatToReplace(), |
| 405 | &added, &replaced); |
scroggo@google.com | d9d2967 | 2012-08-14 17:21:34 +0000 | [diff] [blame] | 406 | fBitmapHeap->endAddingOwnersDeferral(added); |
scroggo@google.com | 4dffc59 | 2012-07-17 16:49:40 +0000 | [diff] [blame] | 407 | int index = flat->index(); |
scroggo@google.com | 0c3e5fe | 2012-08-01 19:34:20 +0000 | [diff] [blame] | 408 | if (added) { |
| 409 | if (isCrossProcess(fFlags)) { |
| 410 | this->flattenFactoryNames(); |
| 411 | } |
| 412 | size_t flatSize = flat->flatSize(); |
| 413 | if (this->needOpBytes(flatSize)) { |
| 414 | this->writeOp(kDef_Flattenable_DrawOp, paintflat, index); |
| 415 | fWriter.write(flat->data(), flatSize); |
| 416 | } |
scroggo@google.com | 4dffc59 | 2012-07-17 16:49:40 +0000 | [diff] [blame] | 417 | } |
| 418 | if (replaced) { |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 419 | index = ~index; |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 420 | } |
scroggo@google.com | 4dffc59 | 2012-07-17 16:49:40 +0000 | [diff] [blame] | 421 | return index; |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 422 | } |
| 423 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 424 | /////////////////////////////////////////////////////////////////////////////// |
| 425 | |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 426 | #define MIN_BLOCK_SIZE (16 * 1024) |
scroggo@google.com | 4dffc59 | 2012-07-17 16:49:40 +0000 | [diff] [blame] | 427 | #define BITMAPS_TO_KEEP 5 |
| 428 | #define FLATTENABLES_TO_KEEP 10 |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 429 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 430 | SkGPipeCanvas::SkGPipeCanvas(SkGPipeController* controller, |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 431 | SkWriter32* writer, uint32_t flags, |
junov@chromium.org | a8db8fe | 2012-08-15 19:49:22 +0000 | [diff] [blame] | 432 | uint32_t width, uint32_t height) |
commit-bot@chromium.org | 403f8d7 | 2014-02-17 15:24:26 +0000 | [diff] [blame] | 433 | : SkCanvas(width, height) |
| 434 | , fFactorySet(isCrossProcess(flags) ? SkNEW(SkNamedFactorySet) : NULL) |
| 435 | , fWriter(*writer) |
| 436 | , fFlags(flags) |
| 437 | , fFlattenableHeap(FLATTENABLES_TO_KEEP, fFactorySet, isCrossProcess(flags)) |
| 438 | , fFlatDictionary(&fFlattenableHeap) |
| 439 | { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 440 | fController = controller; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 441 | fDone = false; |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 442 | fBlockSize = 0; // need first block from controller |
scroggo@google.com | 5a2e879 | 2012-04-20 17:39:51 +0000 | [diff] [blame] | 443 | fBytesNotified = 0; |
junov@chromium.org | fbe9c8f | 2012-07-18 20:22:52 +0000 | [diff] [blame] | 444 | fFirstSaveLayerStackLevel = kNoSaveLayer; |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 445 | sk_bzero(fCurrFlatIndex, sizeof(fCurrFlatIndex)); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 446 | |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 447 | // Tell the reader the appropriate flags to use. |
| 448 | if (this->needOpBytes()) { |
| 449 | this->writeOp(kReportFlags_DrawOp, fFlags, 0); |
| 450 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 451 | |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 452 | if (shouldFlattenBitmaps(flags)) { |
scroggo@google.com | 59c3ab6 | 2013-11-12 14:32:38 +0000 | [diff] [blame] | 453 | fBitmapShuttle.reset(SkNEW_ARGS(BitmapShuttle, (this))); |
| 454 | fBitmapHeap = SkNEW_ARGS(SkBitmapHeap, (fBitmapShuttle.get(), BITMAPS_TO_KEEP)); |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 455 | } else { |
scroggo@google.com | d9d2967 | 2012-08-14 17:21:34 +0000 | [diff] [blame] | 456 | fBitmapHeap = SkNEW_ARGS(SkBitmapHeap, |
scroggo@google.com | 3e26bd0 | 2012-08-14 15:20:01 +0000 | [diff] [blame] | 457 | (BITMAPS_TO_KEEP, controller->numberOfReaders())); |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 458 | if (this->needOpBytes(sizeof(void*))) { |
scroggo@google.com | d9d2967 | 2012-08-14 17:21:34 +0000 | [diff] [blame] | 459 | this->writeOp(kShareBitmapHeap_DrawOp); |
| 460 | fWriter.writePtr(static_cast<void*>(fBitmapHeap)); |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 461 | } |
| 462 | } |
scroggo@google.com | d9d2967 | 2012-08-14 17:21:34 +0000 | [diff] [blame] | 463 | fFlattenableHeap.setBitmapStorage(fBitmapHeap); |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 464 | this->doNotify(); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | SkGPipeCanvas::~SkGPipeCanvas() { |
scroggo@google.com | 59c3ab6 | 2013-11-12 14:32:38 +0000 | [diff] [blame] | 468 | this->finish(true); |
scroggo@google.com | 0c3e5fe | 2012-08-01 19:34:20 +0000 | [diff] [blame] | 469 | SkSafeUnref(fFactorySet); |
scroggo@google.com | d9d2967 | 2012-08-14 17:21:34 +0000 | [diff] [blame] | 470 | SkSafeUnref(fBitmapHeap); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 471 | } |
| 472 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 473 | bool SkGPipeCanvas::needOpBytes(size_t needed) { |
| 474 | if (fDone) { |
| 475 | return false; |
| 476 | } |
| 477 | |
| 478 | needed += 4; // size of DrawOp atom |
commit-bot@chromium.org | d049017 | 2014-05-14 15:12:08 +0000 | [diff] [blame] | 479 | needed = SkAlign4(needed); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 480 | if (fWriter.bytesWritten() + needed > fBlockSize) { |
mtklein | 6d88e6c | 2014-07-30 09:17:54 -0700 | [diff] [blame] | 481 | // Before we wipe out any data that has already been written, read it out. |
scroggo@google.com | 5a2e879 | 2012-04-20 17:39:51 +0000 | [diff] [blame] | 482 | this->doNotify(); |
mtklein | 6d88e6c | 2014-07-30 09:17:54 -0700 | [diff] [blame] | 483 | |
| 484 | // If we're going to allocate a new block, allocate enough to make it worthwhile. |
| 485 | needed = SkTMax<size_t>(MIN_BLOCK_SIZE, needed); |
| 486 | |
commit-bot@chromium.org | d049017 | 2014-05-14 15:12:08 +0000 | [diff] [blame] | 487 | void* block = fController->requestBlock(needed, &fBlockSize); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 488 | if (NULL == block) { |
scroggo@google.com | 59c3ab6 | 2013-11-12 14:32:38 +0000 | [diff] [blame] | 489 | // Do not notify the readers, which would call this function again. |
| 490 | this->finish(false); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 491 | return false; |
| 492 | } |
scroggo@google.com | 460a23e | 2012-08-16 17:56:49 +0000 | [diff] [blame] | 493 | SkASSERT(SkIsAlign4(fBlockSize)); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 494 | fWriter.reset(block, fBlockSize); |
| 495 | fBytesNotified = 0; |
| 496 | } |
| 497 | return true; |
| 498 | } |
| 499 | |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 500 | uint32_t SkGPipeCanvas::getTypefaceID(SkTypeface* face) { |
| 501 | uint32_t id = 0; // 0 means default/null typeface |
| 502 | if (face) { |
| 503 | id = fTypefaceSet.find(face); |
| 504 | if (0 == id) { |
| 505 | id = fTypefaceSet.add(face); |
| 506 | size_t size = writeTypeface(NULL, face); |
| 507 | if (this->needOpBytes(size)) { |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 508 | this->writeOp(kDef_Typeface_DrawOp); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 509 | writeTypeface(&fWriter, face); |
| 510 | } |
| 511 | } |
| 512 | } |
| 513 | return id; |
| 514 | } |
| 515 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 516 | /////////////////////////////////////////////////////////////////////////////// |
| 517 | |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 518 | #define NOTIFY_SETUP(canvas) \ |
| 519 | AutoPipeNotify apn(canvas) |
| 520 | |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 521 | void SkGPipeCanvas::willSave() { |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 522 | NOTIFY_SETUP(this); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 523 | if (this->needOpBytes()) { |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 524 | this->writeOp(kSave_DrawOp); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 525 | } |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 526 | |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 527 | this->INHERITED::willSave(); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 528 | } |
| 529 | |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 530 | SkCanvas::SaveLayerStrategy SkGPipeCanvas::willSaveLayer(const SkRect* bounds, const SkPaint* paint, |
| 531 | SaveFlags saveFlags) { |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 532 | NOTIFY_SETUP(this); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 533 | size_t size = 0; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 534 | unsigned opFlags = 0; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 535 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 536 | if (bounds) { |
| 537 | opFlags |= kSaveLayer_HasBounds_DrawOpFlag; |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 538 | size += sizeof(SkRect); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 539 | } |
| 540 | if (paint) { |
| 541 | opFlags |= kSaveLayer_HasPaint_DrawOpFlag; |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 542 | this->writePaint(*paint); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 543 | } |
| 544 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 545 | if (this->needOpBytes(size)) { |
| 546 | this->writeOp(kSaveLayer_DrawOp, opFlags, saveFlags); |
| 547 | if (bounds) { |
| 548 | fWriter.writeRect(*bounds); |
| 549 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 550 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 551 | |
junov@chromium.org | fbe9c8f | 2012-07-18 20:22:52 +0000 | [diff] [blame] | 552 | if (kNoSaveLayer == fFirstSaveLayerStackLevel){ |
| 553 | fFirstSaveLayerStackLevel = this->getSaveCount(); |
| 554 | } |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 555 | |
| 556 | this->INHERITED::willSaveLayer(bounds, paint, saveFlags); |
| 557 | // we don't create a layer |
| 558 | return kNoLayer_SaveLayerStrategy; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 559 | } |
| 560 | |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 561 | void SkGPipeCanvas::willRestore() { |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 562 | NOTIFY_SETUP(this); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 563 | if (this->needOpBytes()) { |
| 564 | this->writeOp(kRestore_DrawOp); |
| 565 | } |
junov@chromium.org | fbe9c8f | 2012-07-18 20:22:52 +0000 | [diff] [blame] | 566 | |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 567 | if (this->getSaveCount() - 1 == fFirstSaveLayerStackLevel){ |
junov@chromium.org | fbe9c8f | 2012-07-18 20:22:52 +0000 | [diff] [blame] | 568 | fFirstSaveLayerStackLevel = kNoSaveLayer; |
| 569 | } |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 570 | |
| 571 | this->INHERITED::willRestore(); |
junov@chromium.org | fbe9c8f | 2012-07-18 20:22:52 +0000 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | bool SkGPipeCanvas::isDrawingToLayer() const { |
| 575 | return kNoSaveLayer != fFirstSaveLayerStackLevel; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 576 | } |
| 577 | |
commit-bot@chromium.org | d9ea09e | 2014-03-25 17:32:26 +0000 | [diff] [blame] | 578 | void SkGPipeCanvas::recordTranslate(const SkMatrix& m) { |
| 579 | if (this->needOpBytes(2 * sizeof(SkScalar))) { |
| 580 | this->writeOp(kTranslate_DrawOp); |
| 581 | fWriter.writeScalar(m.getTranslateX()); |
| 582 | fWriter.writeScalar(m.getTranslateY()); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 583 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 584 | } |
| 585 | |
commit-bot@chromium.org | d9ea09e | 2014-03-25 17:32:26 +0000 | [diff] [blame] | 586 | void SkGPipeCanvas::recordScale(const SkMatrix& m) { |
| 587 | if (this->needOpBytes(2 * sizeof(SkScalar))) { |
| 588 | this->writeOp(kScale_DrawOp); |
| 589 | fWriter.writeScalar(m.getScaleX()); |
| 590 | fWriter.writeScalar(m.getScaleY()); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 591 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 592 | } |
| 593 | |
commit-bot@chromium.org | d9ea09e | 2014-03-25 17:32:26 +0000 | [diff] [blame] | 594 | void SkGPipeCanvas::recordConcat(const SkMatrix& m) { |
| 595 | if (this->needOpBytes(m.writeToMemory(NULL))) { |
| 596 | this->writeOp(kConcat_DrawOp); |
| 597 | fWriter.writeMatrix(m); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 598 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 599 | } |
| 600 | |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 601 | void SkGPipeCanvas::didConcat(const SkMatrix& matrix) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 602 | if (!matrix.isIdentity()) { |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 603 | NOTIFY_SETUP(this); |
commit-bot@chromium.org | d9ea09e | 2014-03-25 17:32:26 +0000 | [diff] [blame] | 604 | switch (matrix.getType()) { |
| 605 | case SkMatrix::kTranslate_Mask: |
| 606 | this->recordTranslate(matrix); |
| 607 | break; |
| 608 | case SkMatrix::kScale_Mask: |
| 609 | this->recordScale(matrix); |
| 610 | break; |
| 611 | default: |
| 612 | this->recordConcat(matrix); |
| 613 | break; |
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 | } |
commit-bot@chromium.org | d9ea09e | 2014-03-25 17:32:26 +0000 | [diff] [blame] | 616 | |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 617 | this->INHERITED::didConcat(matrix); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 618 | } |
| 619 | |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 620 | void SkGPipeCanvas::didSetMatrix(const SkMatrix& matrix) { |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 621 | NOTIFY_SETUP(this); |
djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 622 | if (this->needOpBytes(matrix.writeToMemory(NULL))) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 623 | this->writeOp(kSetMatrix_DrawOp); |
djsollen@google.com | 2b2ede3 | 2012-04-12 13:24:04 +0000 | [diff] [blame] | 624 | fWriter.writeMatrix(matrix); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 625 | } |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 626 | this->INHERITED::didSetMatrix(matrix); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 627 | } |
| 628 | |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 629 | void SkGPipeCanvas::onClipRect(const SkRect& rect, SkRegion::Op rgnOp, |
| 630 | ClipEdgeStyle edgeStyle) { |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 631 | NOTIFY_SETUP(this); |
scroggo@google.com | 460a23e | 2012-08-16 17:56:49 +0000 | [diff] [blame] | 632 | if (this->needOpBytes(sizeof(SkRect))) { |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 633 | unsigned flags = 0; |
| 634 | if (kSoft_ClipEdgeStyle == edgeStyle) { |
| 635 | flags = kClip_HasAntiAlias_DrawOpFlag; |
| 636 | } |
scroggo@google.com | 460a23e | 2012-08-16 17:56:49 +0000 | [diff] [blame] | 637 | this->writeOp(kClipRect_DrawOp, flags, rgnOp); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 638 | fWriter.writeRect(rect); |
| 639 | } |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 640 | this->INHERITED::onClipRect(rect, rgnOp, edgeStyle); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 641 | } |
| 642 | |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 643 | void SkGPipeCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op rgnOp, |
| 644 | ClipEdgeStyle edgeStyle) { |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 645 | NOTIFY_SETUP(this); |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 646 | if (this->needOpBytes(kSizeOfFlatRRect)) { |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 647 | unsigned flags = 0; |
| 648 | if (kSoft_ClipEdgeStyle == edgeStyle) { |
| 649 | flags = kClip_HasAntiAlias_DrawOpFlag; |
| 650 | } |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 651 | this->writeOp(kClipRRect_DrawOp, flags, rgnOp); |
| 652 | fWriter.writeRRect(rrect); |
| 653 | } |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 654 | this->INHERITED::onClipRRect(rrect, rgnOp, edgeStyle); |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 655 | } |
| 656 | |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 657 | void SkGPipeCanvas::onClipPath(const SkPath& path, SkRegion::Op rgnOp, |
| 658 | ClipEdgeStyle edgeStyle) { |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 659 | NOTIFY_SETUP(this); |
scroggo@google.com | 460a23e | 2012-08-16 17:56:49 +0000 | [diff] [blame] | 660 | if (this->needOpBytes(path.writeToMemory(NULL))) { |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 661 | unsigned flags = 0; |
| 662 | if (kSoft_ClipEdgeStyle == edgeStyle) { |
| 663 | flags = kClip_HasAntiAlias_DrawOpFlag; |
| 664 | } |
scroggo@google.com | 460a23e | 2012-08-16 17:56:49 +0000 | [diff] [blame] | 665 | this->writeOp(kClipPath_DrawOp, flags, rgnOp); |
djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 666 | fWriter.writePath(path); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 667 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 668 | // we just pass on the bounds of the path |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 669 | this->INHERITED::onClipRect(path.getBounds(), rgnOp, edgeStyle); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 670 | } |
| 671 | |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 672 | void SkGPipeCanvas::onClipRegion(const SkRegion& region, SkRegion::Op rgnOp) { |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 673 | NOTIFY_SETUP(this); |
djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 674 | if (this->needOpBytes(region.writeToMemory(NULL))) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 675 | this->writeOp(kClipRegion_DrawOp, 0, rgnOp); |
djsollen@google.com | 2b2ede3 | 2012-04-12 13:24:04 +0000 | [diff] [blame] | 676 | fWriter.writeRegion(region); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 677 | } |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 678 | this->INHERITED::onClipRegion(region, rgnOp); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | /////////////////////////////////////////////////////////////////////////////// |
| 682 | |
| 683 | void SkGPipeCanvas::clear(SkColor color) { |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 684 | NOTIFY_SETUP(this); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 685 | unsigned flags = 0; |
| 686 | if (color) { |
| 687 | flags |= kClear_HasColor_DrawOpFlag; |
| 688 | } |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 689 | if (this->needOpBytes(sizeof(SkColor))) { |
| 690 | this->writeOp(kDrawClear_DrawOp, flags, 0); |
| 691 | if (color) { |
| 692 | fWriter.write32(color); |
| 693 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 694 | } |
| 695 | } |
| 696 | |
| 697 | void SkGPipeCanvas::drawPaint(const SkPaint& paint) { |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 698 | NOTIFY_SETUP(this); |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 699 | this->writePaint(paint); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 700 | if (this->needOpBytes()) { |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 701 | this->writeOp(kDrawPaint_DrawOp); |
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 | |
| 705 | void SkGPipeCanvas::drawPoints(PointMode mode, size_t count, |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 706 | const SkPoint pts[], const SkPaint& paint) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 707 | if (count) { |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 708 | NOTIFY_SETUP(this); |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 709 | this->writePaint(paint); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 710 | if (this->needOpBytes(4 + count * sizeof(SkPoint))) { |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 711 | this->writeOp(kDrawPoints_DrawOp, mode, 0); |
commit-bot@chromium.org | b45bd1f | 2014-04-24 18:17:30 +0000 | [diff] [blame] | 712 | fWriter.write32(SkToU32(count)); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 713 | fWriter.write(pts, count * sizeof(SkPoint)); |
| 714 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 715 | } |
| 716 | } |
| 717 | |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 718 | void SkGPipeCanvas::drawOval(const SkRect& rect, const SkPaint& paint) { |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 719 | NOTIFY_SETUP(this); |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 720 | this->writePaint(paint); |
| 721 | if (this->needOpBytes(sizeof(SkRect))) { |
| 722 | this->writeOp(kDrawOval_DrawOp); |
| 723 | fWriter.writeRect(rect); |
| 724 | } |
| 725 | } |
| 726 | |
bsalomon@google.com | 7ce564c | 2013-10-22 16:54:15 +0000 | [diff] [blame] | 727 | void SkGPipeCanvas::drawRect(const SkRect& rect, const SkPaint& paint) { |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 728 | NOTIFY_SETUP(this); |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 729 | this->writePaint(paint); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 730 | if (this->needOpBytes(sizeof(SkRect))) { |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 731 | this->writeOp(kDrawRect_DrawOp); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 732 | fWriter.writeRect(rect); |
| 733 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 734 | } |
| 735 | |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 736 | void SkGPipeCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 737 | NOTIFY_SETUP(this); |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 738 | this->writePaint(paint); |
| 739 | if (this->needOpBytes(kSizeOfFlatRRect)) { |
| 740 | this->writeOp(kDrawRRect_DrawOp); |
| 741 | fWriter.writeRRect(rrect); |
| 742 | } |
| 743 | } |
| 744 | |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 745 | void SkGPipeCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, |
| 746 | const SkPaint& paint) { |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 747 | NOTIFY_SETUP(this); |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 748 | this->writePaint(paint); |
| 749 | if (this->needOpBytes(kSizeOfFlatRRect * 2)) { |
| 750 | this->writeOp(kDrawDRRect_DrawOp); |
| 751 | fWriter.writeRRect(outer); |
| 752 | fWriter.writeRRect(inner); |
| 753 | } |
| 754 | } |
| 755 | |
bsalomon@google.com | 7ce564c | 2013-10-22 16:54:15 +0000 | [diff] [blame] | 756 | void SkGPipeCanvas::drawPath(const SkPath& path, const SkPaint& paint) { |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 757 | NOTIFY_SETUP(this); |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 758 | this->writePaint(paint); |
djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 759 | if (this->needOpBytes(path.writeToMemory(NULL))) { |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 760 | this->writeOp(kDrawPath_DrawOp); |
djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 761 | fWriter.writePath(path); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 762 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 763 | } |
| 764 | |
scroggo@google.com | 3e26bd0 | 2012-08-14 15:20:01 +0000 | [diff] [blame] | 765 | bool SkGPipeCanvas::commonDrawBitmap(const SkBitmap& bm, DrawOps op, |
| 766 | unsigned flags, |
| 767 | size_t opBytesNeeded, |
| 768 | const SkPaint* paint) { |
commit-bot@chromium.org | 44803fb | 2014-05-14 15:38:25 +0000 | [diff] [blame] | 769 | if (fDone) { |
| 770 | return false; |
| 771 | } |
| 772 | |
scroggo@google.com | 58be682 | 2012-07-30 14:40:01 +0000 | [diff] [blame] | 773 | if (paint != NULL) { |
scroggo@google.com | 460a23e | 2012-08-16 17:56:49 +0000 | [diff] [blame] | 774 | flags |= kDrawBitmap_HasPaint_DrawOpFlag; |
scroggo@google.com | 58be682 | 2012-07-30 14:40:01 +0000 | [diff] [blame] | 775 | this->writePaint(*paint); |
| 776 | } |
commit-bot@chromium.org | 44803fb | 2014-05-14 15:38:25 +0000 | [diff] [blame] | 777 | // This needs to run first so its calls to needOpBytes() and its writes |
| 778 | // don't interlace with the needOpBytes() and write below. |
| 779 | SkASSERT(fBitmapHeap != NULL); |
| 780 | int32_t bitmapIndex = fBitmapHeap->insert(bm); |
| 781 | if (SkBitmapHeap::INVALID_SLOT == bitmapIndex) { |
| 782 | return false; |
| 783 | } |
| 784 | |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 785 | if (this->needOpBytes(opBytesNeeded)) { |
| 786 | this->writeOp(op, flags, bitmapIndex); |
scroggo@google.com | 58be682 | 2012-07-30 14:40:01 +0000 | [diff] [blame] | 787 | return true; |
| 788 | } |
| 789 | return false; |
| 790 | } |
| 791 | |
| 792 | void SkGPipeCanvas::drawBitmap(const SkBitmap& bm, SkScalar left, SkScalar top, |
| 793 | const SkPaint* paint) { |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 794 | NOTIFY_SETUP(this); |
scroggo@google.com | 58be682 | 2012-07-30 14:40:01 +0000 | [diff] [blame] | 795 | size_t opBytesNeeded = sizeof(SkScalar) * 2; |
| 796 | |
scroggo@google.com | 3e26bd0 | 2012-08-14 15:20:01 +0000 | [diff] [blame] | 797 | if (this->commonDrawBitmap(bm, kDrawBitmap_DrawOp, 0, opBytesNeeded, paint)) { |
scroggo@google.com | 5a2e879 | 2012-04-20 17:39:51 +0000 | [diff] [blame] | 798 | fWriter.writeScalar(left); |
| 799 | fWriter.writeScalar(top); |
| 800 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 801 | } |
| 802 | |
reed@google.com | 7112173 | 2012-09-18 15:14:33 +0000 | [diff] [blame] | 803 | void SkGPipeCanvas::drawBitmapRectToRect(const SkBitmap& bm, const SkRect* src, |
commit-bot@chromium.org | eed779d | 2013-08-16 10:24:37 +0000 | [diff] [blame] | 804 | const SkRect& dst, const SkPaint* paint, |
| 805 | DrawBitmapRectFlags dbmrFlags) { |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 806 | NOTIFY_SETUP(this); |
scroggo@google.com | 58be682 | 2012-07-30 14:40:01 +0000 | [diff] [blame] | 807 | size_t opBytesNeeded = sizeof(SkRect); |
| 808 | bool hasSrc = src != NULL; |
| 809 | unsigned flags; |
| 810 | if (hasSrc) { |
scroggo@google.com | 460a23e | 2012-08-16 17:56:49 +0000 | [diff] [blame] | 811 | flags = kDrawBitmap_HasSrcRect_DrawOpFlag; |
scroggo@google.com | 58be682 | 2012-07-30 14:40:01 +0000 | [diff] [blame] | 812 | opBytesNeeded += sizeof(int32_t) * 4; |
| 813 | } else { |
| 814 | flags = 0; |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 815 | } |
commit-bot@chromium.org | eed779d | 2013-08-16 10:24:37 +0000 | [diff] [blame] | 816 | if (dbmrFlags & kBleed_DrawBitmapRectFlag) { |
| 817 | flags |= kDrawBitmap_Bleed_DrawOpFlag; |
| 818 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 819 | |
reed@google.com | 7112173 | 2012-09-18 15:14:33 +0000 | [diff] [blame] | 820 | if (this->commonDrawBitmap(bm, kDrawBitmapRectToRect_DrawOp, flags, opBytesNeeded, paint)) { |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 821 | if (hasSrc) { |
reed@google.com | 7112173 | 2012-09-18 15:14:33 +0000 | [diff] [blame] | 822 | fWriter.writeRect(*src); |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 823 | } |
| 824 | fWriter.writeRect(dst); |
| 825 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 826 | } |
| 827 | |
scroggo@google.com | 58be682 | 2012-07-30 14:40:01 +0000 | [diff] [blame] | 828 | void SkGPipeCanvas::drawBitmapMatrix(const SkBitmap& bm, const SkMatrix& matrix, |
| 829 | const SkPaint* paint) { |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 830 | NOTIFY_SETUP(this); |
scroggo@google.com | 58be682 | 2012-07-30 14:40:01 +0000 | [diff] [blame] | 831 | size_t opBytesNeeded = matrix.writeToMemory(NULL); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 832 | |
scroggo@google.com | 3e26bd0 | 2012-08-14 15:20:01 +0000 | [diff] [blame] | 833 | if (this->commonDrawBitmap(bm, kDrawBitmapMatrix_DrawOp, 0, opBytesNeeded, paint)) { |
scroggo@google.com | 58be682 | 2012-07-30 14:40:01 +0000 | [diff] [blame] | 834 | fWriter.writeMatrix(matrix); |
| 835 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 836 | } |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 837 | |
| 838 | void SkGPipeCanvas::drawBitmapNine(const SkBitmap& bm, const SkIRect& center, |
scroggo@google.com | 5a2e879 | 2012-04-20 17:39:51 +0000 | [diff] [blame] | 839 | const SkRect& dst, const SkPaint* paint) { |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 840 | NOTIFY_SETUP(this); |
scroggo@google.com | 58be682 | 2012-07-30 14:40:01 +0000 | [diff] [blame] | 841 | size_t opBytesNeeded = sizeof(int32_t) * 4 + sizeof(SkRect); |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 842 | |
scroggo@google.com | 3e26bd0 | 2012-08-14 15:20:01 +0000 | [diff] [blame] | 843 | if (this->commonDrawBitmap(bm, kDrawBitmapNine_DrawOp, 0, opBytesNeeded, paint)) { |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 844 | fWriter.write32(center.fLeft); |
| 845 | fWriter.write32(center.fTop); |
| 846 | fWriter.write32(center.fRight); |
| 847 | fWriter.write32(center.fBottom); |
| 848 | fWriter.writeRect(dst); |
| 849 | } |
scroggo@google.com | 5a2e879 | 2012-04-20 17:39:51 +0000 | [diff] [blame] | 850 | } |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 851 | |
| 852 | void SkGPipeCanvas::drawSprite(const SkBitmap& bm, int left, int top, |
| 853 | const SkPaint* paint) { |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 854 | NOTIFY_SETUP(this); |
scroggo@google.com | 58be682 | 2012-07-30 14:40:01 +0000 | [diff] [blame] | 855 | size_t opBytesNeeded = sizeof(int32_t) * 2; |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 856 | |
scroggo@google.com | 3e26bd0 | 2012-08-14 15:20:01 +0000 | [diff] [blame] | 857 | if (this->commonDrawBitmap(bm, kDrawSprite_DrawOp, 0, opBytesNeeded, paint)) { |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 858 | fWriter.write32(left); |
| 859 | fWriter.write32(top); |
| 860 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 861 | } |
| 862 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 863 | void SkGPipeCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
| 864 | const SkPaint& paint) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 865 | if (byteLength) { |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 866 | NOTIFY_SETUP(this); |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 867 | this->writePaint(paint); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 868 | if (this->needOpBytes(4 + SkAlign4(byteLength) + 2 * sizeof(SkScalar))) { |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 869 | this->writeOp(kDrawText_DrawOp); |
commit-bot@chromium.org | b45bd1f | 2014-04-24 18:17:30 +0000 | [diff] [blame] | 870 | fWriter.write32(SkToU32(byteLength)); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 871 | fWriter.writePad(text, byteLength); |
| 872 | fWriter.writeScalar(x); |
| 873 | fWriter.writeScalar(y); |
| 874 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 875 | } |
| 876 | } |
| 877 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 878 | void SkGPipeCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[], |
| 879 | const SkPaint& paint) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 880 | if (byteLength) { |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 881 | NOTIFY_SETUP(this); |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 882 | this->writePaint(paint); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 883 | int count = paint.textToGlyphs(text, byteLength, NULL); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 884 | if (this->needOpBytes(4 + SkAlign4(byteLength) + 4 + count * sizeof(SkPoint))) { |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 885 | this->writeOp(kDrawPosText_DrawOp); |
commit-bot@chromium.org | b45bd1f | 2014-04-24 18:17:30 +0000 | [diff] [blame] | 886 | fWriter.write32(SkToU32(byteLength)); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 887 | fWriter.writePad(text, byteLength); |
| 888 | fWriter.write32(count); |
| 889 | fWriter.write(pos, count * sizeof(SkPoint)); |
| 890 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 891 | } |
| 892 | } |
| 893 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 894 | void SkGPipeCanvas::onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], |
| 895 | SkScalar constY, const SkPaint& paint) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 896 | if (byteLength) { |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 897 | NOTIFY_SETUP(this); |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 898 | this->writePaint(paint); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 899 | int count = paint.textToGlyphs(text, byteLength, NULL); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 900 | if (this->needOpBytes(4 + SkAlign4(byteLength) + 4 + count * sizeof(SkScalar) + 4)) { |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 901 | this->writeOp(kDrawPosTextH_DrawOp); |
commit-bot@chromium.org | b45bd1f | 2014-04-24 18:17:30 +0000 | [diff] [blame] | 902 | fWriter.write32(SkToU32(byteLength)); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 903 | fWriter.writePad(text, byteLength); |
| 904 | fWriter.write32(count); |
| 905 | fWriter.write(xpos, count * sizeof(SkScalar)); |
| 906 | fWriter.writeScalar(constY); |
| 907 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 908 | } |
| 909 | } |
| 910 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 911 | void SkGPipeCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path, |
| 912 | const SkMatrix* matrix, const SkPaint& paint) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 913 | if (byteLength) { |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 914 | NOTIFY_SETUP(this); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 915 | unsigned flags = 0; |
djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 916 | size_t size = 4 + SkAlign4(byteLength) + path.writeToMemory(NULL); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 917 | if (matrix) { |
| 918 | flags |= kDrawTextOnPath_HasMatrix_DrawOpFlag; |
djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 919 | size += matrix->writeToMemory(NULL); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 920 | } |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 921 | this->writePaint(paint); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 922 | if (this->needOpBytes(size)) { |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 923 | this->writeOp(kDrawTextOnPath_DrawOp, flags, 0); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 924 | |
commit-bot@chromium.org | b45bd1f | 2014-04-24 18:17:30 +0000 | [diff] [blame] | 925 | fWriter.write32(SkToU32(byteLength)); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 926 | fWriter.writePad(text, byteLength); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 927 | |
djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 928 | fWriter.writePath(path); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 929 | if (matrix) { |
djsollen@google.com | 2b2ede3 | 2012-04-12 13:24:04 +0000 | [diff] [blame] | 930 | fWriter.writeMatrix(*matrix); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 931 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 932 | } |
| 933 | } |
| 934 | } |
| 935 | |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 936 | void SkGPipeCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix, |
| 937 | const SkPaint* paint) { |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame] | 938 | // we want to playback the picture into individual draw calls |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 939 | // |
| 940 | // todo: do we always have to unroll? If the pipe is not cross-process, seems like |
| 941 | // we could just ref the picture and move on...? <reed, scroggo> |
| 942 | // |
| 943 | this->INHERITED::onDrawPicture(picture, matrix, paint); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 944 | } |
| 945 | |
reed@google.com | 85e143c | 2013-12-30 15:51:25 +0000 | [diff] [blame] | 946 | void SkGPipeCanvas::drawVertices(VertexMode vmode, int vertexCount, |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 947 | const SkPoint vertices[], const SkPoint texs[], |
reed@google.com | 85e143c | 2013-12-30 15:51:25 +0000 | [diff] [blame] | 948 | const SkColor colors[], SkXfermode* xfer, |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 949 | const uint16_t indices[], int indexCount, |
| 950 | const SkPaint& paint) { |
| 951 | if (0 == vertexCount) { |
| 952 | return; |
| 953 | } |
| 954 | |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 955 | NOTIFY_SETUP(this); |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 956 | this->writePaint(paint); |
commit-bot@chromium.org | d049017 | 2014-05-14 15:12:08 +0000 | [diff] [blame] | 957 | |
| 958 | unsigned flags = 0; // packs with the op, so needs no extra space |
| 959 | |
| 960 | size_t size = 0; |
| 961 | size += 4; // vmode |
| 962 | size += 4; // vertex count |
| 963 | size += vertexCount * sizeof(SkPoint); // vertices |
| 964 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 965 | if (texs) { |
| 966 | flags |= kDrawVertices_HasTexs_DrawOpFlag; |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 967 | size += vertexCount * sizeof(SkPoint); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 968 | } |
| 969 | if (colors) { |
| 970 | flags |= kDrawVertices_HasColors_DrawOpFlag; |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 971 | size += vertexCount * sizeof(SkColor); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 972 | } |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 973 | if (xfer && !SkXfermode::IsMode(xfer, SkXfermode::kModulate_Mode)) { |
| 974 | flags |= kDrawVertices_HasXfermode_DrawOpFlag; |
commit-bot@chromium.org | d049017 | 2014-05-14 15:12:08 +0000 | [diff] [blame] | 975 | size += sizeof(int32_t); // SkXfermode::Mode |
| 976 | } |
| 977 | if (indices && indexCount > 0) { |
| 978 | flags |= kDrawVertices_HasIndices_DrawOpFlag; |
| 979 | size += 4; // index count |
| 980 | size += SkAlign4(indexCount * sizeof(uint16_t)); // indices |
reed@google.com | 85e143c | 2013-12-30 15:51:25 +0000 | [diff] [blame] | 981 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 982 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 983 | if (this->needOpBytes(size)) { |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 984 | this->writeOp(kDrawVertices_DrawOp, flags, 0); |
reed@google.com | 85e143c | 2013-12-30 15:51:25 +0000 | [diff] [blame] | 985 | fWriter.write32(vmode); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 986 | fWriter.write32(vertexCount); |
| 987 | fWriter.write(vertices, vertexCount * sizeof(SkPoint)); |
commit-bot@chromium.org | d049017 | 2014-05-14 15:12:08 +0000 | [diff] [blame] | 988 | if (flags & kDrawVertices_HasTexs_DrawOpFlag) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 989 | fWriter.write(texs, vertexCount * sizeof(SkPoint)); |
| 990 | } |
commit-bot@chromium.org | d049017 | 2014-05-14 15:12:08 +0000 | [diff] [blame] | 991 | if (flags & kDrawVertices_HasColors_DrawOpFlag) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 992 | fWriter.write(colors, vertexCount * sizeof(SkColor)); |
| 993 | } |
reed@google.com | 85e143c | 2013-12-30 15:51:25 +0000 | [diff] [blame] | 994 | if (flags & kDrawVertices_HasXfermode_DrawOpFlag) { |
| 995 | SkXfermode::Mode mode = SkXfermode::kModulate_Mode; |
commit-bot@chromium.org | d049017 | 2014-05-14 15:12:08 +0000 | [diff] [blame] | 996 | SkAssertResult(xfer->asMode(&mode)); |
reed@google.com | 85e143c | 2013-12-30 15:51:25 +0000 | [diff] [blame] | 997 | fWriter.write32(mode); |
| 998 | } |
commit-bot@chromium.org | d049017 | 2014-05-14 15:12:08 +0000 | [diff] [blame] | 999 | if (flags & kDrawVertices_HasIndices_DrawOpFlag) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 1000 | fWriter.write32(indexCount); |
| 1001 | fWriter.writePad(indices, indexCount * sizeof(uint16_t)); |
| 1002 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1003 | } |
| 1004 | } |
| 1005 | |
dandov | 963137b | 2014-08-07 07:49:53 -0700 | [diff] [blame] | 1006 | void SkGPipeCanvas::drawPatch(const SkPatch& patch, const SkPaint& paint) { |
| 1007 | NOTIFY_SETUP(this); |
| 1008 | this->writePaint(paint); |
| 1009 | if (this->needOpBytes(patch.writeToMemory(NULL))) { |
| 1010 | this->writeOp(kDrawPatch_DrawOp); |
| 1011 | fWriter.writePatch(patch); |
| 1012 | } |
| 1013 | } |
| 1014 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 1015 | void SkGPipeCanvas::drawData(const void* ptr, size_t size) { |
| 1016 | if (size && ptr) { |
commit-bot@chromium.org | f700fb2 | 2014-05-14 14:50:57 +0000 | [diff] [blame] | 1017 | NOTIFY_SETUP(this); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1018 | unsigned data = 0; |
| 1019 | if (size < (1 << DRAWOPS_DATA_BITS)) { |
| 1020 | data = (unsigned)size; |
| 1021 | } |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 1022 | if (this->needOpBytes(4 + SkAlign4(size))) { |
| 1023 | this->writeOp(kDrawData_DrawOp, 0, data); |
| 1024 | if (0 == data) { |
commit-bot@chromium.org | b45bd1f | 2014-04-24 18:17:30 +0000 | [diff] [blame] | 1025 | fWriter.write32(SkToU32(size)); |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 1026 | } |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 1027 | fWriter.writePad(ptr, size); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1028 | } |
| 1029 | } |
| 1030 | } |
| 1031 | |
robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 1032 | void SkGPipeCanvas::beginCommentGroup(const char* description) { |
| 1033 | // ignore for now |
| 1034 | } |
| 1035 | |
| 1036 | void SkGPipeCanvas::addComment(const char* kywd, const char* value) { |
| 1037 | // ignore for now |
| 1038 | } |
| 1039 | |
| 1040 | void SkGPipeCanvas::endCommentGroup() { |
| 1041 | // ignore for now |
| 1042 | } |
| 1043 | |
junov@chromium.org | 77eec24 | 2012-07-18 17:54:45 +0000 | [diff] [blame] | 1044 | void SkGPipeCanvas::flushRecording(bool detachCurrentBlock) { |
commit-bot@chromium.org | d049017 | 2014-05-14 15:12:08 +0000 | [diff] [blame] | 1045 | this->doNotify(); |
junov@chromium.org | 77eec24 | 2012-07-18 17:54:45 +0000 | [diff] [blame] | 1046 | if (detachCurrentBlock) { |
| 1047 | // force a new block to be requested for the next recorded command |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1048 | fBlockSize = 0; |
junov@chromium.org | 77eec24 | 2012-07-18 17:54:45 +0000 | [diff] [blame] | 1049 | } |
| 1050 | } |
| 1051 | |
junov@chromium.org | 2e14ba8 | 2012-08-07 14:26:57 +0000 | [diff] [blame] | 1052 | size_t SkGPipeCanvas::freeMemoryIfPossible(size_t bytesToFree) { |
scroggo@google.com | d5d158b | 2012-08-14 20:38:28 +0000 | [diff] [blame] | 1053 | return (NULL == fBitmapHeap) ? 0 : fBitmapHeap->freeMemoryIfPossible(bytesToFree); |
junov@chromium.org | 2e14ba8 | 2012-08-07 14:26:57 +0000 | [diff] [blame] | 1054 | } |
| 1055 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1056 | /////////////////////////////////////////////////////////////////////////////// |
| 1057 | |
| 1058 | template <typename T> uint32_t castToU32(T value) { |
| 1059 | union { |
| 1060 | T fSrc; |
| 1061 | uint32_t fDst; |
| 1062 | } data; |
| 1063 | data.fSrc = value; |
| 1064 | return data.fDst; |
| 1065 | } |
| 1066 | |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 1067 | void SkGPipeCanvas::writePaint(const SkPaint& paint) { |
scroggo@google.com | d5d158b | 2012-08-14 20:38:28 +0000 | [diff] [blame] | 1068 | if (fDone) { |
| 1069 | return; |
| 1070 | } |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 1071 | SkPaint& base = fPaint; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1072 | uint32_t storage[32]; |
| 1073 | uint32_t* ptr = storage; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1074 | |
| 1075 | if (base.getFlags() != paint.getFlags()) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1076 | *ptr++ = PaintOp_packOpData(kFlags_PaintOp, paint.getFlags()); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 1077 | base.setFlags(paint.getFlags()); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1078 | } |
| 1079 | if (base.getColor() != paint.getColor()) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1080 | *ptr++ = PaintOp_packOp(kColor_PaintOp); |
| 1081 | *ptr++ = paint.getColor(); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 1082 | base.setColor(paint.getColor()); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1083 | } |
commit-bot@chromium.org | 85faf50 | 2014-04-16 12:58:02 +0000 | [diff] [blame] | 1084 | if (base.getFilterLevel() != paint.getFilterLevel()) { |
| 1085 | *ptr++ = PaintOp_packOpData(kFilterLevel_PaintOp, paint.getFilterLevel()); |
| 1086 | base.setFilterLevel(paint.getFilterLevel()); |
| 1087 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1088 | if (base.getStyle() != paint.getStyle()) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1089 | *ptr++ = PaintOp_packOpData(kStyle_PaintOp, paint.getStyle()); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 1090 | base.setStyle(paint.getStyle()); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1091 | } |
| 1092 | if (base.getStrokeJoin() != paint.getStrokeJoin()) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1093 | *ptr++ = PaintOp_packOpData(kJoin_PaintOp, paint.getStrokeJoin()); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 1094 | base.setStrokeJoin(paint.getStrokeJoin()); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1095 | } |
| 1096 | if (base.getStrokeCap() != paint.getStrokeCap()) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1097 | *ptr++ = PaintOp_packOpData(kCap_PaintOp, paint.getStrokeCap()); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 1098 | base.setStrokeCap(paint.getStrokeCap()); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1099 | } |
| 1100 | if (base.getStrokeWidth() != paint.getStrokeWidth()) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1101 | *ptr++ = PaintOp_packOp(kWidth_PaintOp); |
| 1102 | *ptr++ = castToU32(paint.getStrokeWidth()); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 1103 | base.setStrokeWidth(paint.getStrokeWidth()); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1104 | } |
| 1105 | if (base.getStrokeMiter() != paint.getStrokeMiter()) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1106 | *ptr++ = PaintOp_packOp(kMiter_PaintOp); |
| 1107 | *ptr++ = castToU32(paint.getStrokeMiter()); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 1108 | base.setStrokeMiter(paint.getStrokeMiter()); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1109 | } |
| 1110 | if (base.getTextEncoding() != paint.getTextEncoding()) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1111 | *ptr++ = PaintOp_packOpData(kEncoding_PaintOp, paint.getTextEncoding()); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 1112 | base.setTextEncoding(paint.getTextEncoding()); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1113 | } |
| 1114 | if (base.getHinting() != paint.getHinting()) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1115 | *ptr++ = PaintOp_packOpData(kHinting_PaintOp, paint.getHinting()); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 1116 | base.setHinting(paint.getHinting()); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1117 | } |
| 1118 | if (base.getTextAlign() != paint.getTextAlign()) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1119 | *ptr++ = PaintOp_packOpData(kAlign_PaintOp, paint.getTextAlign()); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 1120 | base.setTextAlign(paint.getTextAlign()); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1121 | } |
| 1122 | if (base.getTextSize() != paint.getTextSize()) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1123 | *ptr++ = PaintOp_packOp(kTextSize_PaintOp); |
| 1124 | *ptr++ = castToU32(paint.getTextSize()); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 1125 | base.setTextSize(paint.getTextSize()); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1126 | } |
| 1127 | if (base.getTextScaleX() != paint.getTextScaleX()) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1128 | *ptr++ = PaintOp_packOp(kTextScaleX_PaintOp); |
| 1129 | *ptr++ = castToU32(paint.getTextScaleX()); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 1130 | base.setTextScaleX(paint.getTextScaleX()); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1131 | } |
| 1132 | if (base.getTextSkewX() != paint.getTextSkewX()) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1133 | *ptr++ = PaintOp_packOp(kTextSkewX_PaintOp); |
| 1134 | *ptr++ = castToU32(paint.getTextSkewX()); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 1135 | base.setTextSkewX(paint.getTextSkewX()); |
| 1136 | } |
| 1137 | |
| 1138 | if (!SkTypeface::Equal(base.getTypeface(), paint.getTypeface())) { |
scroggo@google.com | 0c3e5fe | 2012-08-01 19:34:20 +0000 | [diff] [blame] | 1139 | if (isCrossProcess(fFlags)) { |
scroggo@google.com | 3cb969f | 2012-07-27 20:39:19 +0000 | [diff] [blame] | 1140 | uint32_t id = this->getTypefaceID(paint.getTypeface()); |
| 1141 | *ptr++ = PaintOp_packOpData(kTypeface_PaintOp, id); |
| 1142 | } else if (this->needOpBytes(sizeof(void*))) { |
| 1143 | // Add to the set for ref counting. |
| 1144 | fTypefaceSet.add(paint.getTypeface()); |
| 1145 | // It is safe to write the typeface to the stream before the rest |
| 1146 | // of the paint unless we ever send a kReset_PaintOp, which we |
| 1147 | // currently never do. |
| 1148 | this->writeOp(kSetTypeface_DrawOp); |
| 1149 | fWriter.writePtr(paint.getTypeface()); |
| 1150 | } |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 1151 | base.setTypeface(paint.getTypeface()); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1152 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1153 | |
scroggo@google.com | 4dffc59 | 2012-07-17 16:49:40 +0000 | [diff] [blame] | 1154 | // This is a new paint, so all old flats can be safely purged, if necessary. |
| 1155 | fFlattenableHeap.markAllFlatsSafeToDelete(); |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 1156 | for (int i = 0; i < kCount_PaintFlats; i++) { |
| 1157 | int index = this->flattenToIndex(get_paintflat(paint, i), (PaintFlats)i); |
scroggo@google.com | d3ba5cc | 2012-07-09 16:05:53 +0000 | [diff] [blame] | 1158 | bool replaced = index < 0; |
| 1159 | if (replaced) { |
| 1160 | index = ~index; |
| 1161 | } |
scroggo@google.com | 4dffc59 | 2012-07-17 16:49:40 +0000 | [diff] [blame] | 1162 | // Store the index of any flat that needs to be kept. 0 means no flat. |
| 1163 | if (index > 0) { |
| 1164 | fFlattenableHeap.markFlatForKeeping(index); |
| 1165 | } |
| 1166 | SkASSERT(index >= 0 && index <= fFlatDictionary.count()); |
scroggo@google.com | d3ba5cc | 2012-07-09 16:05:53 +0000 | [diff] [blame] | 1167 | if (index != fCurrFlatIndex[i] || replaced) { |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 1168 | *ptr++ = PaintOp_packOpFlagData(kFlatIndex_PaintOp, i, index); |
| 1169 | fCurrFlatIndex[i] = index; |
| 1170 | } |
| 1171 | } |
| 1172 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 1173 | size_t size = (char*)ptr - (char*)storage; |
| 1174 | if (size && this->needOpBytes(size)) { |
commit-bot@chromium.org | b45bd1f | 2014-04-24 18:17:30 +0000 | [diff] [blame] | 1175 | this->writeOp(kPaintOp_DrawOp, 0, SkToU32(size)); |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 1176 | fWriter.write(storage, size); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1177 | for (size_t i = 0; i < size/4; i++) { |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 1178 | // SkDebugf("[%d] %08X\n", i, storage[i]); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1179 | } |
| 1180 | } |
reed@google.com | 0cd2ac6 | 2013-10-14 20:02:44 +0000 | [diff] [blame] | 1181 | |
| 1182 | // |
| 1183 | // Do these after we've written kPaintOp_DrawOp |
skia.committer@gmail.com | fbc58a3 | 2013-10-15 07:02:27 +0000 | [diff] [blame] | 1184 | |
reed@google.com | 0cd2ac6 | 2013-10-14 20:02:44 +0000 | [diff] [blame] | 1185 | if (base.getAnnotation() != paint.getAnnotation()) { |
| 1186 | if (NULL == paint.getAnnotation()) { |
commit-bot@chromium.org | 89ff3dd | 2013-10-29 20:29:38 +0000 | [diff] [blame] | 1187 | if (this->needOpBytes()) { |
| 1188 | this->writeOp(kSetAnnotation_DrawOp, 0, 0); |
| 1189 | } |
reed@google.com | 0cd2ac6 | 2013-10-14 20:02:44 +0000 | [diff] [blame] | 1190 | } else { |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 1191 | SkWriteBuffer buffer; |
reed@google.com | 0cd2ac6 | 2013-10-14 20:02:44 +0000 | [diff] [blame] | 1192 | paint.getAnnotation()->writeToBuffer(buffer); |
commit-bot@chromium.org | 89ff3dd | 2013-10-29 20:29:38 +0000 | [diff] [blame] | 1193 | const size_t size = buffer.bytesWritten(); |
| 1194 | if (this->needOpBytes(size)) { |
commit-bot@chromium.org | b45bd1f | 2014-04-24 18:17:30 +0000 | [diff] [blame] | 1195 | this->writeOp(kSetAnnotation_DrawOp, 0, SkToU32(size)); |
commit-bot@chromium.org | 89ff3dd | 2013-10-29 20:29:38 +0000 | [diff] [blame] | 1196 | buffer.writeToMemory(fWriter.reserve(size)); |
| 1197 | } |
reed@google.com | 0cd2ac6 | 2013-10-14 20:02:44 +0000 | [diff] [blame] | 1198 | } |
commit-bot@chromium.org | 40258a5 | 2013-10-29 19:23:26 +0000 | [diff] [blame] | 1199 | base.setAnnotation(paint.getAnnotation()); |
reed@google.com | 0cd2ac6 | 2013-10-14 20:02:44 +0000 | [diff] [blame] | 1200 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | /////////////////////////////////////////////////////////////////////////////// |
| 1204 | |
| 1205 | #include "SkGPipe.h" |
| 1206 | |
scroggo@google.com | 3cb969f | 2012-07-27 20:39:19 +0000 | [diff] [blame] | 1207 | SkGPipeController::~SkGPipeController() { |
| 1208 | SkSafeUnref(fCanvas); |
| 1209 | } |
| 1210 | |
| 1211 | void SkGPipeController::setCanvas(SkGPipeCanvas* canvas) { |
| 1212 | SkRefCnt_SafeAssign(fCanvas, canvas); |
| 1213 | } |
| 1214 | |
| 1215 | /////////////////////////////////////////////////////////////////////////////// |
| 1216 | |
| 1217 | SkGPipeWriter::SkGPipeWriter() |
scroggo@google.com | 0c3e5fe | 2012-08-01 19:34:20 +0000 | [diff] [blame] | 1218 | : fWriter(0) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1219 | fCanvas = NULL; |
| 1220 | } |
| 1221 | |
| 1222 | SkGPipeWriter::~SkGPipeWriter() { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 1223 | this->endRecording(); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1224 | } |
| 1225 | |
junov@chromium.org | a8db8fe | 2012-08-15 19:49:22 +0000 | [diff] [blame] | 1226 | SkCanvas* SkGPipeWriter::startRecording(SkGPipeController* controller, uint32_t flags, |
| 1227 | uint32_t width, uint32_t height) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1228 | if (NULL == fCanvas) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 1229 | fWriter.reset(NULL, 0); |
junov@chromium.org | a8db8fe | 2012-08-15 19:49:22 +0000 | [diff] [blame] | 1230 | fCanvas = SkNEW_ARGS(SkGPipeCanvas, (controller, &fWriter, flags, width, height)); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1231 | } |
scroggo@google.com | 3cb969f | 2012-07-27 20:39:19 +0000 | [diff] [blame] | 1232 | controller->setCanvas(fCanvas); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1233 | return fCanvas; |
| 1234 | } |
| 1235 | |
| 1236 | void SkGPipeWriter::endRecording() { |
| 1237 | if (fCanvas) { |
scroggo@google.com | 59c3ab6 | 2013-11-12 14:32:38 +0000 | [diff] [blame] | 1238 | fCanvas->finish(true); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 1239 | fCanvas->unref(); |
| 1240 | fCanvas = NULL; |
| 1241 | } |
| 1242 | } |
| 1243 | |
junov@chromium.org | 2e14ba8 | 2012-08-07 14:26:57 +0000 | [diff] [blame] | 1244 | void SkGPipeWriter::flushRecording(bool detachCurrentBlock) { |
| 1245 | if (fCanvas) { |
| 1246 | fCanvas->flushRecording(detachCurrentBlock); |
| 1247 | } |
junov@chromium.org | 77eec24 | 2012-07-18 17:54:45 +0000 | [diff] [blame] | 1248 | } |
| 1249 | |
junov@chromium.org | 2e14ba8 | 2012-08-07 14:26:57 +0000 | [diff] [blame] | 1250 | size_t SkGPipeWriter::freeMemoryIfPossible(size_t bytesToFree) { |
| 1251 | if (fCanvas) { |
| 1252 | return fCanvas->freeMemoryIfPossible(bytesToFree); |
| 1253 | } |
| 1254 | return 0; |
| 1255 | } |
| 1256 | |
| 1257 | size_t SkGPipeWriter::storageAllocatedForRecording() const { |
scroggo@google.com | 15011ee | 2012-07-26 20:03:32 +0000 | [diff] [blame] | 1258 | return NULL == fCanvas ? 0 : fCanvas->storageAllocatedForRecording(); |
| 1259 | } |
| 1260 | |
scroggo@google.com | 3e26bd0 | 2012-08-14 15:20:01 +0000 | [diff] [blame] | 1261 | /////////////////////////////////////////////////////////////////////////////// |
| 1262 | |
| 1263 | BitmapShuttle::BitmapShuttle(SkGPipeCanvas* canvas) { |
| 1264 | SkASSERT(canvas != NULL); |
| 1265 | fCanvas = canvas; |
| 1266 | fCanvas->ref(); |
| 1267 | } |
| 1268 | |
| 1269 | BitmapShuttle::~BitmapShuttle() { |
scroggo@google.com | 59c3ab6 | 2013-11-12 14:32:38 +0000 | [diff] [blame] | 1270 | this->removeCanvas(); |
scroggo@google.com | 3e26bd0 | 2012-08-14 15:20:01 +0000 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | bool BitmapShuttle::insert(const SkBitmap& bitmap, int32_t slot) { |
scroggo@google.com | 59c3ab6 | 2013-11-12 14:32:38 +0000 | [diff] [blame] | 1274 | SkASSERT(fCanvas != NULL); |
scroggo@google.com | 3e26bd0 | 2012-08-14 15:20:01 +0000 | [diff] [blame] | 1275 | return fCanvas->shuttleBitmap(bitmap, slot); |
| 1276 | } |
scroggo@google.com | 59c3ab6 | 2013-11-12 14:32:38 +0000 | [diff] [blame] | 1277 | |
| 1278 | void BitmapShuttle::removeCanvas() { |
| 1279 | if (NULL == fCanvas) { |
| 1280 | return; |
| 1281 | } |
| 1282 | fCanvas->unref(); |
| 1283 | fCanvas = NULL; |
| 1284 | } |