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" |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE; | 243 virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE; |
244 virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top, | 244 virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top, |
245 const SkPaint*) SK_OVERRIDE; | 245 const SkPaint*) SK_OVERRIDE; |
246 virtual void drawBitmapRectToRect(const SkBitmap&, const SkRect* src, | 246 virtual void drawBitmapRectToRect(const SkBitmap&, const SkRect* src, |
247 const SkRect& dst, const SkPaint* paint, | 247 const SkRect& dst, const SkPaint* paint, |
248 DrawBitmapRectFlags flags) SK_OVERRIDE; | 248 DrawBitmapRectFlags flags) SK_OVERRIDE; |
249 virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&, | 249 virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&, |
250 const SkPaint*) SK_OVERRIDE; | 250 const SkPaint*) SK_OVERRIDE; |
251 virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, | 251 virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
252 const SkRect& dst, const SkPaint* paint = NULL)
SK_OVERRIDE; | 252 const SkRect& dst, const SkPaint* paint = NULL)
SK_OVERRIDE; |
253 virtual void drawImage(const SkImage* image, SkScalar left, SkScalar top, | |
254 const SkPaint* paint) SK_OVERRIDE; | |
255 virtual void drawImageRect(const SkImage* image, const SkRect* src, | |
256 const SkRect& dst, | |
257 const SkPaint* paint) SK_OVERRIDE; | |
258 virtual void drawSprite(const SkBitmap&, int left, int top, | 253 virtual void drawSprite(const SkBitmap&, int left, int top, |
259 const SkPaint*) SK_OVERRIDE; | 254 const SkPaint*) SK_OVERRIDE; |
260 virtual void drawVertices(VertexMode, int vertexCount, | 255 virtual void drawVertices(VertexMode, int vertexCount, |
261 const SkPoint vertices[], const SkPoint texs[], | 256 const SkPoint vertices[], const SkPoint texs[], |
262 const SkColor colors[], SkXfermode*, | 257 const SkColor colors[], SkXfermode*, |
263 const uint16_t indices[], int indexCount, | 258 const uint16_t indices[], int indexCount, |
264 const SkPaint&) SK_OVERRIDE; | 259 const SkPaint&) SK_OVERRIDE; |
265 virtual void drawData(const void*, size_t) SK_OVERRIDE; | 260 virtual void drawData(const void*, size_t) SK_OVERRIDE; |
266 virtual void beginCommentGroup(const char* description) SK_OVERRIDE; | 261 virtual void beginCommentGroup(const char* description) SK_OVERRIDE; |
267 virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE; | 262 virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 SkAutoTUnref<BitmapShuttle> fBitmapShuttle; | 352 SkAutoTUnref<BitmapShuttle> fBitmapShuttle; |
358 int fCurrFlatIndex[kCount_PaintFlats]; | 353 int fCurrFlatIndex[kCount_PaintFlats]; |
359 | 354 |
360 int flattenToIndex(SkFlattenable* obj, PaintFlats); | 355 int flattenToIndex(SkFlattenable* obj, PaintFlats); |
361 | 356 |
362 // Common code used by drawBitmap*. Behaves differently depending on the | 357 // Common code used by drawBitmap*. Behaves differently depending on the |
363 // type of SkBitmapHeap being used, which is determined by the flags used. | 358 // type of SkBitmapHeap being used, which is determined by the flags used. |
364 bool commonDrawBitmap(const SkBitmap& bm, DrawOps op, unsigned flags, | 359 bool commonDrawBitmap(const SkBitmap& bm, DrawOps op, unsigned flags, |
365 size_t opBytesNeeded, const SkPaint* paint); | 360 size_t opBytesNeeded, const SkPaint* paint); |
366 | 361 |
367 bool commonDrawImage(const SkImage* image, DrawOps op, unsigned flags, | |
368 size_t opBytesNeeded, const SkPaint* paint); | |
369 | |
370 SkPaint fPaint; | 362 SkPaint fPaint; |
371 void writePaint(const SkPaint&); | 363 void writePaint(const SkPaint&); |
372 | 364 |
373 class AutoPipeNotify { | 365 class AutoPipeNotify { |
374 public: | 366 public: |
375 AutoPipeNotify(SkGPipeCanvas* canvas) : fCanvas(canvas) {} | 367 AutoPipeNotify(SkGPipeCanvas* canvas) : fCanvas(canvas) {} |
376 ~AutoPipeNotify() { fCanvas->doNotify(); } | 368 ~AutoPipeNotify() { fCanvas->doNotify(); } |
377 private: | 369 private: |
378 SkGPipeCanvas* fCanvas; | 370 SkGPipeCanvas* fCanvas; |
379 }; | 371 }; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 fBitmapHeap = SkNEW_ARGS(SkBitmapHeap, (fBitmapShuttle.get(), BITMAPS_TO
_KEEP)); | 464 fBitmapHeap = SkNEW_ARGS(SkBitmapHeap, (fBitmapShuttle.get(), BITMAPS_TO
_KEEP)); |
473 } else { | 465 } else { |
474 fBitmapHeap = SkNEW_ARGS(SkBitmapHeap, | 466 fBitmapHeap = SkNEW_ARGS(SkBitmapHeap, |
475 (BITMAPS_TO_KEEP, controller->numberOfReaders()
)); | 467 (BITMAPS_TO_KEEP, controller->numberOfReaders()
)); |
476 if (this->needOpBytes(sizeof(void*))) { | 468 if (this->needOpBytes(sizeof(void*))) { |
477 this->writeOp(kShareBitmapHeap_DrawOp); | 469 this->writeOp(kShareBitmapHeap_DrawOp); |
478 fWriter.writePtr(static_cast<void*>(fBitmapHeap)); | 470 fWriter.writePtr(static_cast<void*>(fBitmapHeap)); |
479 } | 471 } |
480 } | 472 } |
481 fFlattenableHeap.setBitmapStorage(fBitmapHeap); | 473 fFlattenableHeap.setBitmapStorage(fBitmapHeap); |
482 | |
483 this->doNotify(); | 474 this->doNotify(); |
484 } | 475 } |
485 | 476 |
486 SkGPipeCanvas::~SkGPipeCanvas() { | 477 SkGPipeCanvas::~SkGPipeCanvas() { |
487 this->finish(true); | 478 this->finish(true); |
488 SkSafeUnref(fFactorySet); | 479 SkSafeUnref(fFactorySet); |
489 SkSafeUnref(fBitmapHeap); | 480 SkSafeUnref(fBitmapHeap); |
490 } | 481 } |
491 | 482 |
492 bool SkGPipeCanvas::needOpBytes(size_t needed) { | 483 bool SkGPipeCanvas::needOpBytes(size_t needed) { |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 return false; | 792 return false; |
802 } | 793 } |
803 | 794 |
804 if (this->needOpBytes(opBytesNeeded)) { | 795 if (this->needOpBytes(opBytesNeeded)) { |
805 this->writeOp(op, flags, bitmapIndex); | 796 this->writeOp(op, flags, bitmapIndex); |
806 return true; | 797 return true; |
807 } | 798 } |
808 return false; | 799 return false; |
809 } | 800 } |
810 | 801 |
811 bool SkGPipeCanvas::commonDrawImage(const SkImage* image, DrawOps op, | |
812 unsigned flags, | |
813 size_t opBytesNeeded, | |
814 const SkPaint* paint) { | |
815 if (fDone) { | |
816 return false; | |
817 } | |
818 | |
819 if (paint != NULL) { | |
820 flags |= kDrawBitmap_HasPaint_DrawOpFlag; | |
821 this->writePaint(*paint); | |
822 } | |
823 | |
824 opBytesNeeded += sizeof (SkImage*); | |
825 | |
826 if (this->needOpBytes(opBytesNeeded)) { | |
827 this->writeOp(op, flags, 0); | |
828 | |
829 image->ref(); // The SkGPipeReader will have to call unref() | |
830 fWriter.writePtr(static_cast<void*>(const_cast<SkImage*>(image))); | |
831 | |
832 return true; | |
833 } | |
834 return false; | |
835 } | |
836 | |
837 void SkGPipeCanvas::drawImage(const SkImage* image, SkScalar left, SkScalar top, | |
838 const SkPaint* paint) { | |
839 if (is_cross_process(fFlags)){ | |
840 // If the SkGPipe is cross-process, we will have to flatten the data in
the SkImage, so | |
841 // fallback to the default implementation in SkCanvas (which calls SkIma
ge::draw()) | |
842 // https://code.google.com//p/skia/issues/detail?id=2985 | |
843 this->INHERITED::drawImage(image, left, top, paint); | |
844 } else { | |
845 NOTIFY_SETUP(this); | |
846 size_t opBytesNeeded = sizeof(SkScalar) * 2; | |
847 | |
848 if (this->commonDrawImage(image, kDrawImage_DrawOp, 0, opBytesNeeded, pa
int)) { | |
849 fWriter.writeScalar(left); | |
850 fWriter.writeScalar(top); | |
851 } | |
852 } | |
853 } | |
854 | |
855 void SkGPipeCanvas::drawImageRect(const SkImage* image, const SkRect* src, | |
856 const SkRect& dst, | |
857 const SkPaint* paint) { | |
858 if (is_cross_process(fFlags)){ | |
859 // If the SkGPipe is cross-process, we will have to flatten the data in
the SkImage, so | |
860 // fallback to the default implementation in SkCanvas (which calls SkIma
ge::drawRect()) | |
861 // https://code.google.com//p/skia/issues/detail?id=2985 | |
862 this->INHERITED::drawImageRect(image, src, dst, paint); | |
863 } else { | |
864 NOTIFY_SETUP(this); | |
865 size_t opBytesNeeded = sizeof (SkRect); | |
866 bool hasSrc = src != NULL; | |
867 unsigned flags; | |
868 if (hasSrc) { | |
869 flags = kDrawImage_HasSrcRect_DrawOpFlag; | |
870 opBytesNeeded += sizeof (SkRect); | |
871 } else { | |
872 flags = 0; | |
873 } | |
874 | |
875 if (this->commonDrawImage(image, kDrawImageRect_DrawOp, flags, opBytesNe
eded, paint)) { | |
876 if (hasSrc) { | |
877 fWriter.writeRect(*src); | |
878 } | |
879 fWriter.writeRect(dst); | |
880 } | |
881 } | |
882 } | |
883 | |
884 void SkGPipeCanvas::drawBitmap(const SkBitmap& bm, SkScalar left, SkScalar top, | 802 void SkGPipeCanvas::drawBitmap(const SkBitmap& bm, SkScalar left, SkScalar top, |
885 const SkPaint* paint) { | 803 const SkPaint* paint) { |
886 NOTIFY_SETUP(this); | 804 NOTIFY_SETUP(this); |
887 size_t opBytesNeeded = sizeof(SkScalar) * 2; | 805 size_t opBytesNeeded = sizeof(SkScalar) * 2; |
888 | 806 |
889 if (this->commonDrawBitmap(bm, kDrawBitmap_DrawOp, 0, opBytesNeeded, paint))
{ | 807 if (this->commonDrawBitmap(bm, kDrawBitmap_DrawOp, 0, opBytesNeeded, paint))
{ |
890 fWriter.writeScalar(left); | 808 fWriter.writeScalar(left); |
891 fWriter.writeScalar(top); | 809 fWriter.writeScalar(top); |
892 } | 810 } |
893 } | 811 } |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1165 fWriter.write32(indexCount); | 1083 fWriter.write32(indexCount); |
1166 fWriter.writePad(indices, indexCount * sizeof(uint16_t)); | 1084 fWriter.writePad(indices, indexCount * sizeof(uint16_t)); |
1167 } | 1085 } |
1168 } | 1086 } |
1169 } | 1087 } |
1170 | 1088 |
1171 void SkGPipeCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4
], | 1089 void SkGPipeCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4
], |
1172 const SkPoint texCoords[4], SkXfermode* xmode, | 1090 const SkPoint texCoords[4], SkXfermode* xmode, |
1173 const SkPaint& paint) { | 1091 const SkPaint& paint) { |
1174 NOTIFY_SETUP(this); | 1092 NOTIFY_SETUP(this); |
1175 | 1093 |
1176 size_t size = SkPatchUtils::kNumCtrlPts * sizeof(SkPoint); | 1094 size_t size = SkPatchUtils::kNumCtrlPts * sizeof(SkPoint); |
1177 unsigned flags = 0; | 1095 unsigned flags = 0; |
1178 if (colors) { | 1096 if (colors) { |
1179 flags |= kDrawVertices_HasColors_DrawOpFlag; | 1097 flags |= kDrawVertices_HasColors_DrawOpFlag; |
1180 size += SkPatchUtils::kNumCorners * sizeof(SkColor); | 1098 size += SkPatchUtils::kNumCorners * sizeof(SkColor); |
1181 } | 1099 } |
1182 if (texCoords) { | 1100 if (texCoords) { |
1183 flags |= kDrawVertices_HasTexs_DrawOpFlag; | 1101 flags |= kDrawVertices_HasTexs_DrawOpFlag; |
1184 size += SkPatchUtils::kNumCorners * sizeof(SkPoint); | 1102 size += SkPatchUtils::kNumCorners * sizeof(SkPoint); |
1185 } | 1103 } |
1186 if (xmode) { | 1104 if (xmode) { |
1187 SkXfermode::Mode mode; | 1105 SkXfermode::Mode mode; |
1188 if (xmode->asMode(&mode) && SkXfermode::kModulate_Mode != mode) { | 1106 if (xmode->asMode(&mode) && SkXfermode::kModulate_Mode != mode) { |
1189 flags |= kDrawVertices_HasXfermode_DrawOpFlag; | 1107 flags |= kDrawVertices_HasXfermode_DrawOpFlag; |
1190 size += sizeof(int32_t); | 1108 size += sizeof(int32_t); |
1191 } | 1109 } |
1192 } | 1110 } |
1193 | 1111 |
1194 this->writePaint(paint); | 1112 this->writePaint(paint); |
1195 if (this->needOpBytes(size)) { | 1113 if (this->needOpBytes(size)) { |
1196 this->writeOp(kDrawPatch_DrawOp, flags, 0); | 1114 this->writeOp(kDrawPatch_DrawOp, flags, 0); |
1197 | 1115 |
1198 fWriter.write(cubics, SkPatchUtils::kNumCtrlPts * sizeof(SkPoint)); | 1116 fWriter.write(cubics, SkPatchUtils::kNumCtrlPts * sizeof(SkPoint)); |
1199 | 1117 |
1200 if (colors) { | 1118 if (colors) { |
1201 fWriter.write(colors, SkPatchUtils::kNumCorners * sizeof(SkColor)); | 1119 fWriter.write(colors, SkPatchUtils::kNumCorners * sizeof(SkColor)); |
1202 } | 1120 } |
1203 | 1121 |
1204 if (texCoords) { | 1122 if (texCoords) { |
1205 fWriter.write(texCoords, SkPatchUtils::kNumCorners * sizeof(SkPoint)
); | 1123 fWriter.write(texCoords, SkPatchUtils::kNumCorners * sizeof(SkPoint)
); |
1206 } | 1124 } |
1207 | 1125 |
1208 if (flags & kDrawVertices_HasXfermode_DrawOpFlag) { | 1126 if (flags & kDrawVertices_HasXfermode_DrawOpFlag) { |
1209 SkXfermode::Mode mode = SkXfermode::kModulate_Mode; | 1127 SkXfermode::Mode mode = SkXfermode::kModulate_Mode; |
1210 SkAssertResult(xmode->asMode(&mode)); | 1128 SkAssertResult(xmode->asMode(&mode)); |
1211 fWriter.write32(mode); | 1129 fWriter.write32(mode); |
1212 } | 1130 } |
1213 } | 1131 } |
1214 } | 1132 } |
1215 | 1133 |
1216 void SkGPipeCanvas::drawData(const void* ptr, size_t size) { | 1134 void SkGPipeCanvas::drawData(const void* ptr, size_t size) { |
1217 if (size && ptr) { | 1135 if (size && ptr) { |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1476 return fCanvas->shuttleBitmap(bitmap, slot); | 1394 return fCanvas->shuttleBitmap(bitmap, slot); |
1477 } | 1395 } |
1478 | 1396 |
1479 void BitmapShuttle::removeCanvas() { | 1397 void BitmapShuttle::removeCanvas() { |
1480 if (NULL == fCanvas) { | 1398 if (NULL == fCanvas) { |
1481 return; | 1399 return; |
1482 } | 1400 } |
1483 fCanvas->unref(); | 1401 fCanvas->unref(); |
1484 fCanvas = NULL; | 1402 fCanvas = NULL; |
1485 } | 1403 } |
OLD | NEW |