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