OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkAnnotation.h" | 9 #include "SkAnnotation.h" |
10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
11 #include "SkBitmapHeap.h" | 11 #include "SkBitmapHeap.h" |
12 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
13 #include "SkColorFilter.h" | 13 #include "SkColorFilter.h" |
14 #include "SkData.h" | 14 #include "SkData.h" |
15 #include "SkDrawLooper.h" | 15 #include "SkDrawLooper.h" |
16 #include "SkGPipe.h" | 16 #include "SkGPipe.h" |
17 #include "SkGPipePriv.h" | 17 #include "SkGPipePriv.h" |
18 #include "SkImageFilter.h" | 18 #include "SkImageFilter.h" |
19 #include "SkMaskFilter.h" | 19 #include "SkMaskFilter.h" |
20 #include "SkOrderedWriteBuffer.h" | 20 #include "SkWriteBuffer.h" |
21 #include "SkPaint.h" | 21 #include "SkPaint.h" |
22 #include "SkPathEffect.h" | 22 #include "SkPathEffect.h" |
23 #include "SkPictureFlat.h" | 23 #include "SkPictureFlat.h" |
24 #include "SkRasterizer.h" | 24 #include "SkRasterizer.h" |
25 #include "SkRRect.h" | 25 #include "SkRRect.h" |
26 #include "SkShader.h" | 26 #include "SkShader.h" |
27 #include "SkStream.h" | 27 #include "SkStream.h" |
28 #include "SkTSearch.h" | 28 #include "SkTSearch.h" |
29 #include "SkTypeface.h" | 29 #include "SkTypeface.h" |
30 #include "SkWriter32.h" | 30 #include "SkWriter32.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 | 68 |
69 /////////////////////////////////////////////////////////////////////////////// | 69 /////////////////////////////////////////////////////////////////////////////// |
70 | 70 |
71 class FlattenableHeap : public SkFlatController { | 71 class FlattenableHeap : public SkFlatController { |
72 public: | 72 public: |
73 FlattenableHeap(int numFlatsToKeep, SkNamedFactorySet* fset, bool isCrossPro
cess) | 73 FlattenableHeap(int numFlatsToKeep, SkNamedFactorySet* fset, bool isCrossPro
cess) |
74 : fNumFlatsToKeep(numFlatsToKeep) { | 74 : fNumFlatsToKeep(numFlatsToKeep) { |
75 SkASSERT((isCrossProcess && fset != NULL) || (!isCrossProcess && NULL ==
fset)); | 75 SkASSERT((isCrossProcess && fset != NULL) || (!isCrossProcess && NULL ==
fset)); |
76 if (isCrossProcess) { | 76 if (isCrossProcess) { |
77 this->setNamedFactorySet(fset); | 77 this->setNamedFactorySet(fset); |
78 this->setWriteBufferFlags(SkFlattenableWriteBuffer::kCrossProcess_Fl
ag); | 78 this->setWriteBufferFlags(SkWriteBuffer::kCrossProcess_Flag); |
79 } | 79 } |
80 } | 80 } |
81 | 81 |
82 ~FlattenableHeap() { | 82 ~FlattenableHeap() { |
83 fPointers.freeAll(); | 83 fPointers.freeAll(); |
84 } | 84 } |
85 | 85 |
86 virtual void* allocThrow(size_t bytes) SK_OVERRIDE; | 86 virtual void* allocThrow(size_t bytes) SK_OVERRIDE; |
87 | 87 |
88 virtual void unalloc(void* ptr) SK_OVERRIDE; | 88 virtual void unalloc(void* ptr) SK_OVERRIDE; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 return potential; | 144 return potential; |
145 } | 145 } |
146 } | 146 } |
147 } | 147 } |
148 return NULL; | 148 return NULL; |
149 } | 149 } |
150 | 150 |
151 /////////////////////////////////////////////////////////////////////////////// | 151 /////////////////////////////////////////////////////////////////////////////// |
152 | 152 |
153 struct SkFlattenableTraits { | 153 struct SkFlattenableTraits { |
154 static void flatten(SkOrderedWriteBuffer& buffer, const SkFlattenable& flatt
enable) { | 154 static void flatten(SkWriteBuffer& buffer, const SkFlattenable& flattenable)
{ |
155 buffer.writeFlattenable(&flattenable); | 155 buffer.writeFlattenable(&flattenable); |
156 } | 156 } |
157 // No need to define unflatten if we never call it. | 157 // No need to define unflatten if we never call it. |
158 }; | 158 }; |
159 typedef SkFlatDictionary<SkFlattenable, SkFlattenableTraits> FlatDictionary; | 159 typedef SkFlatDictionary<SkFlattenable, SkFlattenableTraits> FlatDictionary; |
160 | 160 |
161 /////////////////////////////////////////////////////////////////////////////// | 161 /////////////////////////////////////////////////////////////////////////////// |
162 | 162 |
163 /** | 163 /** |
164 * If SkBitmaps are to be flattened to send to the reader, this class is | 164 * If SkBitmaps are to be flattened to send to the reader, this class is |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 size_t len = strlen(name); | 363 size_t len = strlen(name); |
364 if (this->needOpBytes(len)) { | 364 if (this->needOpBytes(len)) { |
365 this->writeOp(kDef_Factory_DrawOp); | 365 this->writeOp(kDef_Factory_DrawOp); |
366 fWriter.writeString(name, len); | 366 fWriter.writeString(name, len); |
367 } | 367 } |
368 } | 368 } |
369 } | 369 } |
370 | 370 |
371 bool SkGPipeCanvas::shuttleBitmap(const SkBitmap& bm, int32_t slot) { | 371 bool SkGPipeCanvas::shuttleBitmap(const SkBitmap& bm, int32_t slot) { |
372 SkASSERT(shouldFlattenBitmaps(fFlags)); | 372 SkASSERT(shouldFlattenBitmaps(fFlags)); |
373 SkOrderedWriteBuffer buffer; | 373 SkWriteBuffer buffer; |
374 buffer.setNamedFactoryRecorder(fFactorySet); | 374 buffer.setNamedFactoryRecorder(fFactorySet); |
375 buffer.writeBitmap(bm); | 375 buffer.writeBitmap(bm); |
376 this->flattenFactoryNames(); | 376 this->flattenFactoryNames(); |
377 uint32_t size = buffer.size(); | 377 uint32_t size = buffer.bytesWritten(); |
378 if (this->needOpBytes(size)) { | 378 if (this->needOpBytes(size)) { |
379 this->writeOp(kDef_Bitmap_DrawOp, 0, slot); | 379 this->writeOp(kDef_Bitmap_DrawOp, 0, slot); |
380 void* dst = static_cast<void*>(fWriter.reserve(size)); | 380 void* dst = static_cast<void*>(fWriter.reserve(size)); |
381 buffer.writeToMemory(dst); | 381 buffer.writeToMemory(dst); |
382 return true; | 382 return true; |
383 } | 383 } |
384 return false; | 384 return false; |
385 } | 385 } |
386 | 386 |
387 // return 0 for NULL (or unflattenable obj), or index-base-1 | 387 // return 0 for NULL (or unflattenable obj), or index-base-1 |
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1139 | 1139 |
1140 // | 1140 // |
1141 // Do these after we've written kPaintOp_DrawOp | 1141 // Do these after we've written kPaintOp_DrawOp |
1142 | 1142 |
1143 if (base.getAnnotation() != paint.getAnnotation()) { | 1143 if (base.getAnnotation() != paint.getAnnotation()) { |
1144 if (NULL == paint.getAnnotation()) { | 1144 if (NULL == paint.getAnnotation()) { |
1145 if (this->needOpBytes()) { | 1145 if (this->needOpBytes()) { |
1146 this->writeOp(kSetAnnotation_DrawOp, 0, 0); | 1146 this->writeOp(kSetAnnotation_DrawOp, 0, 0); |
1147 } | 1147 } |
1148 } else { | 1148 } else { |
1149 SkOrderedWriteBuffer buffer; | 1149 SkWriteBuffer buffer; |
1150 paint.getAnnotation()->writeToBuffer(buffer); | 1150 paint.getAnnotation()->writeToBuffer(buffer); |
1151 const size_t size = buffer.bytesWritten(); | 1151 const size_t size = buffer.bytesWritten(); |
1152 if (this->needOpBytes(size)) { | 1152 if (this->needOpBytes(size)) { |
1153 this->writeOp(kSetAnnotation_DrawOp, 0, size); | 1153 this->writeOp(kSetAnnotation_DrawOp, 0, size); |
1154 buffer.writeToMemory(fWriter.reserve(size)); | 1154 buffer.writeToMemory(fWriter.reserve(size)); |
1155 } | 1155 } |
1156 } | 1156 } |
1157 base.setAnnotation(paint.getAnnotation()); | 1157 base.setAnnotation(paint.getAnnotation()); |
1158 } | 1158 } |
1159 } | 1159 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1233 return fCanvas->shuttleBitmap(bitmap, slot); | 1233 return fCanvas->shuttleBitmap(bitmap, slot); |
1234 } | 1234 } |
1235 | 1235 |
1236 void BitmapShuttle::removeCanvas() { | 1236 void BitmapShuttle::removeCanvas() { |
1237 if (NULL == fCanvas) { | 1237 if (NULL == fCanvas) { |
1238 return; | 1238 return; |
1239 } | 1239 } |
1240 fCanvas->unref(); | 1240 fCanvas->unref(); |
1241 fCanvas = NULL; | 1241 fCanvas = NULL; |
1242 } | 1242 } |
OLD | NEW |