Chromium Code Reviews| 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)){ | |
|
reed1
2014/10/01 14:12:39
// We call the inherited because ... ?
Rémi Piotaix
2014/10/01 19:29:58
Done.
| |
| 840 this->INHERITED::drawImage(image, left, top, paint); | |
| 841 } else { | |
| 842 NOTIFY_SETUP(this); | |
| 843 size_t opBytesNeeded = sizeof(SkScalar) * 2; | |
| 844 | |
| 845 if (this->commonDrawImage(image, kDrawImage_DrawOp, 0, opBytesNeeded, pa int)) { | |
| 846 fWriter.writeScalar(left); | |
| 847 fWriter.writeScalar(top); | |
| 848 } | |
| 849 } | |
| 850 } | |
| 851 | |
| 852 void SkGPipeCanvas::drawImageRect(const SkImage* image, const SkRect* src, | |
| 853 const SkRect& dst, | |
| 854 const SkPaint* paint) { | |
| 855 if (is_cross_process(fFlags)){ | |
|
reed1
2014/10/01 14:12:39
// We call the inherited because ... ?
Rémi Piotaix
2014/10/01 19:29:58
Done.
| |
| 856 this->INHERITED::drawImageRect(image, src, dst, paint); | |
| 857 } else { | |
| 858 NOTIFY_SETUP(this); | |
| 859 size_t opBytesNeeded = sizeof (SkRect); | |
| 860 bool hasSrc = src != NULL; | |
| 861 unsigned flags; | |
| 862 if (hasSrc) { | |
| 863 flags = kDrawImage_HasSrcRect_DrawOpFlag; | |
| 864 opBytesNeeded += sizeof (SkRect); | |
| 865 } else { | |
| 866 flags = 0; | |
| 867 } | |
| 868 | |
| 869 if (this->commonDrawImage(image, kDrawImageRect_DrawOp, flags, opBytesNe eded, paint)) { | |
| 870 if (hasSrc) { | |
| 871 fWriter.writeRect(*src); | |
| 872 } | |
| 873 fWriter.writeRect(dst); | |
| 874 } | |
| 875 } | |
| 876 } | |
| 877 | |
| 802 void SkGPipeCanvas::drawBitmap(const SkBitmap& bm, SkScalar left, SkScalar top, | 878 void SkGPipeCanvas::drawBitmap(const SkBitmap& bm, SkScalar left, SkScalar top, |
| 803 const SkPaint* paint) { | 879 const SkPaint* paint) { |
| 804 NOTIFY_SETUP(this); | 880 NOTIFY_SETUP(this); |
| 805 size_t opBytesNeeded = sizeof(SkScalar) * 2; | 881 size_t opBytesNeeded = sizeof(SkScalar) * 2; |
| 806 | 882 |
| 807 if (this->commonDrawBitmap(bm, kDrawBitmap_DrawOp, 0, opBytesNeeded, paint)) { | 883 if (this->commonDrawBitmap(bm, kDrawBitmap_DrawOp, 0, opBytesNeeded, paint)) { |
| 808 fWriter.writeScalar(left); | 884 fWriter.writeScalar(left); |
| 809 fWriter.writeScalar(top); | 885 fWriter.writeScalar(top); |
| 810 } | 886 } |
| 811 } | 887 } |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1083 fWriter.write32(indexCount); | 1159 fWriter.write32(indexCount); |
| 1084 fWriter.writePad(indices, indexCount * sizeof(uint16_t)); | 1160 fWriter.writePad(indices, indexCount * sizeof(uint16_t)); |
| 1085 } | 1161 } |
| 1086 } | 1162 } |
| 1087 } | 1163 } |
| 1088 | 1164 |
| 1089 void SkGPipeCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4 ], | 1165 void SkGPipeCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4 ], |
| 1090 const SkPoint texCoords[4], SkXfermode* xmode, | 1166 const SkPoint texCoords[4], SkXfermode* xmode, |
| 1091 const SkPaint& paint) { | 1167 const SkPaint& paint) { |
| 1092 NOTIFY_SETUP(this); | 1168 NOTIFY_SETUP(this); |
| 1093 | 1169 |
| 1094 size_t size = SkPatchUtils::kNumCtrlPts * sizeof(SkPoint); | 1170 size_t size = SkPatchUtils::kNumCtrlPts * sizeof(SkPoint); |
| 1095 unsigned flags = 0; | 1171 unsigned flags = 0; |
| 1096 if (colors) { | 1172 if (colors) { |
| 1097 flags |= kDrawVertices_HasColors_DrawOpFlag; | 1173 flags |= kDrawVertices_HasColors_DrawOpFlag; |
| 1098 size += SkPatchUtils::kNumCorners * sizeof(SkColor); | 1174 size += SkPatchUtils::kNumCorners * sizeof(SkColor); |
| 1099 } | 1175 } |
| 1100 if (texCoords) { | 1176 if (texCoords) { |
| 1101 flags |= kDrawVertices_HasTexs_DrawOpFlag; | 1177 flags |= kDrawVertices_HasTexs_DrawOpFlag; |
| 1102 size += SkPatchUtils::kNumCorners * sizeof(SkPoint); | 1178 size += SkPatchUtils::kNumCorners * sizeof(SkPoint); |
| 1103 } | 1179 } |
| 1104 if (xmode) { | 1180 if (xmode) { |
| 1105 SkXfermode::Mode mode; | 1181 SkXfermode::Mode mode; |
| 1106 if (xmode->asMode(&mode) && SkXfermode::kModulate_Mode != mode) { | 1182 if (xmode->asMode(&mode) && SkXfermode::kModulate_Mode != mode) { |
| 1107 flags |= kDrawVertices_HasXfermode_DrawOpFlag; | 1183 flags |= kDrawVertices_HasXfermode_DrawOpFlag; |
| 1108 size += sizeof(int32_t); | 1184 size += sizeof(int32_t); |
| 1109 } | 1185 } |
| 1110 } | 1186 } |
| 1111 | 1187 |
| 1112 this->writePaint(paint); | 1188 this->writePaint(paint); |
| 1113 if (this->needOpBytes(size)) { | 1189 if (this->needOpBytes(size)) { |
| 1114 this->writeOp(kDrawPatch_DrawOp, flags, 0); | 1190 this->writeOp(kDrawPatch_DrawOp, flags, 0); |
| 1115 | 1191 |
| 1116 fWriter.write(cubics, SkPatchUtils::kNumCtrlPts * sizeof(SkPoint)); | 1192 fWriter.write(cubics, SkPatchUtils::kNumCtrlPts * sizeof(SkPoint)); |
| 1117 | 1193 |
| 1118 if (colors) { | 1194 if (colors) { |
| 1119 fWriter.write(colors, SkPatchUtils::kNumCorners * sizeof(SkColor)); | 1195 fWriter.write(colors, SkPatchUtils::kNumCorners * sizeof(SkColor)); |
| 1120 } | 1196 } |
| 1121 | 1197 |
| 1122 if (texCoords) { | 1198 if (texCoords) { |
| 1123 fWriter.write(texCoords, SkPatchUtils::kNumCorners * sizeof(SkPoint) ); | 1199 fWriter.write(texCoords, SkPatchUtils::kNumCorners * sizeof(SkPoint) ); |
| 1124 } | 1200 } |
| 1125 | 1201 |
| 1126 if (flags & kDrawVertices_HasXfermode_DrawOpFlag) { | 1202 if (flags & kDrawVertices_HasXfermode_DrawOpFlag) { |
| 1127 SkXfermode::Mode mode = SkXfermode::kModulate_Mode; | 1203 SkXfermode::Mode mode = SkXfermode::kModulate_Mode; |
| 1128 SkAssertResult(xmode->asMode(&mode)); | 1204 SkAssertResult(xmode->asMode(&mode)); |
| 1129 fWriter.write32(mode); | 1205 fWriter.write32(mode); |
| 1130 } | 1206 } |
| 1131 } | 1207 } |
| 1132 } | 1208 } |
| 1133 | 1209 |
| 1134 void SkGPipeCanvas::drawData(const void* ptr, size_t size) { | 1210 void SkGPipeCanvas::drawData(const void* ptr, size_t size) { |
| 1135 if (size && ptr) { | 1211 if (size && ptr) { |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1394 return fCanvas->shuttleBitmap(bitmap, slot); | 1470 return fCanvas->shuttleBitmap(bitmap, slot); |
| 1395 } | 1471 } |
| 1396 | 1472 |
| 1397 void BitmapShuttle::removeCanvas() { | 1473 void BitmapShuttle::removeCanvas() { |
| 1398 if (NULL == fCanvas) { | 1474 if (NULL == fCanvas) { |
| 1399 return; | 1475 return; |
| 1400 } | 1476 } |
| 1401 fCanvas->unref(); | 1477 fCanvas->unref(); |
| 1402 fCanvas = NULL; | 1478 fCanvas = NULL; |
| 1403 } | 1479 } |
| OLD | NEW |