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; |
253 virtual void drawSprite(const SkBitmap&, int left, int top, | 258 virtual void drawSprite(const SkBitmap&, int left, int top, |
254 const SkPaint*) SK_OVERRIDE; | 259 const SkPaint*) SK_OVERRIDE; |
255 virtual void drawVertices(VertexMode, int vertexCount, | 260 virtual void drawVertices(VertexMode, int vertexCount, |
256 const SkPoint vertices[], const SkPoint texs[], | 261 const SkPoint vertices[], const SkPoint texs[], |
257 const SkColor colors[], SkXfermode*, | 262 const SkColor colors[], SkXfermode*, |
258 const uint16_t indices[], int indexCount, | 263 const uint16_t indices[], int indexCount, |
259 const SkPaint&) SK_OVERRIDE; | 264 const SkPaint&) SK_OVERRIDE; |
260 virtual void drawData(const void*, size_t) SK_OVERRIDE; | 265 virtual void drawData(const void*, size_t) SK_OVERRIDE; |
261 virtual void beginCommentGroup(const char* description) SK_OVERRIDE; | 266 virtual void beginCommentGroup(const char* description) SK_OVERRIDE; |
262 virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE; | 267 virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 SkAutoTUnref<BitmapShuttle> fBitmapShuttle; | 357 SkAutoTUnref<BitmapShuttle> fBitmapShuttle; |
353 int fCurrFlatIndex[kCount_PaintFlats]; | 358 int fCurrFlatIndex[kCount_PaintFlats]; |
354 | 359 |
355 int flattenToIndex(SkFlattenable* obj, PaintFlats); | 360 int flattenToIndex(SkFlattenable* obj, PaintFlats); |
356 | 361 |
357 // Common code used by drawBitmap*. Behaves differently depending on the | 362 // Common code used by drawBitmap*. Behaves differently depending on the |
358 // type of SkBitmapHeap being used, which is determined by the flags used. | 363 // type of SkBitmapHeap being used, which is determined by the flags used. |
359 bool commonDrawBitmap(const SkBitmap& bm, DrawOps op, unsigned flags, | 364 bool commonDrawBitmap(const SkBitmap& bm, DrawOps op, unsigned flags, |
360 size_t opBytesNeeded, const SkPaint* paint); | 365 size_t opBytesNeeded, const SkPaint* paint); |
361 | 366 |
| 367 bool commonDrawImage(const SkImage* image, DrawOps op, unsigned flags, |
| 368 size_t opBytesNeeded, const SkPaint* paint); |
| 369 |
362 SkPaint fPaint; | 370 SkPaint fPaint; |
363 void writePaint(const SkPaint&); | 371 void writePaint(const SkPaint&); |
364 | 372 |
365 class AutoPipeNotify { | 373 class AutoPipeNotify { |
366 public: | 374 public: |
367 AutoPipeNotify(SkGPipeCanvas* canvas) : fCanvas(canvas) {} | 375 AutoPipeNotify(SkGPipeCanvas* canvas) : fCanvas(canvas) {} |
368 ~AutoPipeNotify() { fCanvas->doNotify(); } | 376 ~AutoPipeNotify() { fCanvas->doNotify(); } |
369 private: | 377 private: |
370 SkGPipeCanvas* fCanvas; | 378 SkGPipeCanvas* fCanvas; |
371 }; | 379 }; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 fBitmapHeap = SkNEW_ARGS(SkBitmapHeap, (fBitmapShuttle.get(), BITMAPS_TO
_KEEP)); | 472 fBitmapHeap = SkNEW_ARGS(SkBitmapHeap, (fBitmapShuttle.get(), BITMAPS_TO
_KEEP)); |
465 } else { | 473 } else { |
466 fBitmapHeap = SkNEW_ARGS(SkBitmapHeap, | 474 fBitmapHeap = SkNEW_ARGS(SkBitmapHeap, |
467 (BITMAPS_TO_KEEP, controller->numberOfReaders()
)); | 475 (BITMAPS_TO_KEEP, controller->numberOfReaders()
)); |
468 if (this->needOpBytes(sizeof(void*))) { | 476 if (this->needOpBytes(sizeof(void*))) { |
469 this->writeOp(kShareBitmapHeap_DrawOp); | 477 this->writeOp(kShareBitmapHeap_DrawOp); |
470 fWriter.writePtr(static_cast<void*>(fBitmapHeap)); | 478 fWriter.writePtr(static_cast<void*>(fBitmapHeap)); |
471 } | 479 } |
472 } | 480 } |
473 fFlattenableHeap.setBitmapStorage(fBitmapHeap); | 481 fFlattenableHeap.setBitmapStorage(fBitmapHeap); |
| 482 |
474 this->doNotify(); | 483 this->doNotify(); |
475 } | 484 } |
476 | 485 |
477 SkGPipeCanvas::~SkGPipeCanvas() { | 486 SkGPipeCanvas::~SkGPipeCanvas() { |
478 this->finish(true); | 487 this->finish(true); |
479 SkSafeUnref(fFactorySet); | 488 SkSafeUnref(fFactorySet); |
480 SkSafeUnref(fBitmapHeap); | 489 SkSafeUnref(fBitmapHeap); |
481 } | 490 } |
482 | 491 |
483 bool SkGPipeCanvas::needOpBytes(size_t needed) { | 492 bool SkGPipeCanvas::needOpBytes(size_t needed) { |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 return false; | 801 return false; |
793 } | 802 } |
794 | 803 |
795 if (this->needOpBytes(opBytesNeeded)) { | 804 if (this->needOpBytes(opBytesNeeded)) { |
796 this->writeOp(op, flags, bitmapIndex); | 805 this->writeOp(op, flags, bitmapIndex); |
797 return true; | 806 return true; |
798 } | 807 } |
799 return false; | 808 return false; |
800 } | 809 } |
801 | 810 |
| 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 |
802 void SkGPipeCanvas::drawBitmap(const SkBitmap& bm, SkScalar left, SkScalar top, | 884 void SkGPipeCanvas::drawBitmap(const SkBitmap& bm, SkScalar left, SkScalar top, |
803 const SkPaint* paint) { | 885 const SkPaint* paint) { |
804 NOTIFY_SETUP(this); | 886 NOTIFY_SETUP(this); |
805 size_t opBytesNeeded = sizeof(SkScalar) * 2; | 887 size_t opBytesNeeded = sizeof(SkScalar) * 2; |
806 | 888 |
807 if (this->commonDrawBitmap(bm, kDrawBitmap_DrawOp, 0, opBytesNeeded, paint))
{ | 889 if (this->commonDrawBitmap(bm, kDrawBitmap_DrawOp, 0, opBytesNeeded, paint))
{ |
808 fWriter.writeScalar(left); | 890 fWriter.writeScalar(left); |
809 fWriter.writeScalar(top); | 891 fWriter.writeScalar(top); |
810 } | 892 } |
811 } | 893 } |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1083 fWriter.write32(indexCount); | 1165 fWriter.write32(indexCount); |
1084 fWriter.writePad(indices, indexCount * sizeof(uint16_t)); | 1166 fWriter.writePad(indices, indexCount * sizeof(uint16_t)); |
1085 } | 1167 } |
1086 } | 1168 } |
1087 } | 1169 } |
1088 | 1170 |
1089 void SkGPipeCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4
], | 1171 void SkGPipeCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4
], |
1090 const SkPoint texCoords[4], SkXfermode* xmode, | 1172 const SkPoint texCoords[4], SkXfermode* xmode, |
1091 const SkPaint& paint) { | 1173 const SkPaint& paint) { |
1092 NOTIFY_SETUP(this); | 1174 NOTIFY_SETUP(this); |
1093 | 1175 |
1094 size_t size = SkPatchUtils::kNumCtrlPts * sizeof(SkPoint); | 1176 size_t size = SkPatchUtils::kNumCtrlPts * sizeof(SkPoint); |
1095 unsigned flags = 0; | 1177 unsigned flags = 0; |
1096 if (colors) { | 1178 if (colors) { |
1097 flags |= kDrawVertices_HasColors_DrawOpFlag; | 1179 flags |= kDrawVertices_HasColors_DrawOpFlag; |
1098 size += SkPatchUtils::kNumCorners * sizeof(SkColor); | 1180 size += SkPatchUtils::kNumCorners * sizeof(SkColor); |
1099 } | 1181 } |
1100 if (texCoords) { | 1182 if (texCoords) { |
1101 flags |= kDrawVertices_HasTexs_DrawOpFlag; | 1183 flags |= kDrawVertices_HasTexs_DrawOpFlag; |
1102 size += SkPatchUtils::kNumCorners * sizeof(SkPoint); | 1184 size += SkPatchUtils::kNumCorners * sizeof(SkPoint); |
1103 } | 1185 } |
1104 if (xmode) { | 1186 if (xmode) { |
1105 SkXfermode::Mode mode; | 1187 SkXfermode::Mode mode; |
1106 if (xmode->asMode(&mode) && SkXfermode::kModulate_Mode != mode) { | 1188 if (xmode->asMode(&mode) && SkXfermode::kModulate_Mode != mode) { |
1107 flags |= kDrawVertices_HasXfermode_DrawOpFlag; | 1189 flags |= kDrawVertices_HasXfermode_DrawOpFlag; |
1108 size += sizeof(int32_t); | 1190 size += sizeof(int32_t); |
1109 } | 1191 } |
1110 } | 1192 } |
1111 | 1193 |
1112 this->writePaint(paint); | 1194 this->writePaint(paint); |
1113 if (this->needOpBytes(size)) { | 1195 if (this->needOpBytes(size)) { |
1114 this->writeOp(kDrawPatch_DrawOp, flags, 0); | 1196 this->writeOp(kDrawPatch_DrawOp, flags, 0); |
1115 | 1197 |
1116 fWriter.write(cubics, SkPatchUtils::kNumCtrlPts * sizeof(SkPoint)); | 1198 fWriter.write(cubics, SkPatchUtils::kNumCtrlPts * sizeof(SkPoint)); |
1117 | 1199 |
1118 if (colors) { | 1200 if (colors) { |
1119 fWriter.write(colors, SkPatchUtils::kNumCorners * sizeof(SkColor)); | 1201 fWriter.write(colors, SkPatchUtils::kNumCorners * sizeof(SkColor)); |
1120 } | 1202 } |
1121 | 1203 |
1122 if (texCoords) { | 1204 if (texCoords) { |
1123 fWriter.write(texCoords, SkPatchUtils::kNumCorners * sizeof(SkPoint)
); | 1205 fWriter.write(texCoords, SkPatchUtils::kNumCorners * sizeof(SkPoint)
); |
1124 } | 1206 } |
1125 | 1207 |
1126 if (flags & kDrawVertices_HasXfermode_DrawOpFlag) { | 1208 if (flags & kDrawVertices_HasXfermode_DrawOpFlag) { |
1127 SkXfermode::Mode mode = SkXfermode::kModulate_Mode; | 1209 SkXfermode::Mode mode = SkXfermode::kModulate_Mode; |
1128 SkAssertResult(xmode->asMode(&mode)); | 1210 SkAssertResult(xmode->asMode(&mode)); |
1129 fWriter.write32(mode); | 1211 fWriter.write32(mode); |
1130 } | 1212 } |
1131 } | 1213 } |
1132 } | 1214 } |
1133 | 1215 |
1134 void SkGPipeCanvas::drawData(const void* ptr, size_t size) { | 1216 void SkGPipeCanvas::drawData(const void* ptr, size_t size) { |
1135 if (size && ptr) { | 1217 if (size && ptr) { |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1394 return fCanvas->shuttleBitmap(bitmap, slot); | 1476 return fCanvas->shuttleBitmap(bitmap, slot); |
1395 } | 1477 } |
1396 | 1478 |
1397 void BitmapShuttle::removeCanvas() { | 1479 void BitmapShuttle::removeCanvas() { |
1398 if (NULL == fCanvas) { | 1480 if (NULL == fCanvas) { |
1399 return; | 1481 return; |
1400 } | 1482 } |
1401 fCanvas->unref(); | 1483 fCanvas->unref(); |
1402 fCanvas = NULL; | 1484 fCanvas = NULL; |
1403 } | 1485 } |
OLD | NEW |