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