| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 SkDEBUGFAIL("never gets here"); | 52 SkDEBUGFAIL("never gets here"); |
| 53 return NULL; | 53 return NULL; |
| 54 } | 54 } |
| 55 | 55 |
| 56 static size_t writeTypeface(SkWriter32* writer, SkTypeface* typeface) { | 56 static size_t writeTypeface(SkWriter32* writer, SkTypeface* typeface) { |
| 57 SkASSERT(typeface); | 57 SkASSERT(typeface); |
| 58 SkDynamicMemoryWStream stream; | 58 SkDynamicMemoryWStream stream; |
| 59 typeface->serialize(&stream); | 59 typeface->serialize(&stream); |
| 60 size_t size = stream.getOffset(); | 60 size_t size = stream.getOffset(); |
| 61 if (writer) { | 61 if (writer) { |
| 62 writer->write32(size); | 62 writer->write32(SkToU32(size)); |
| 63 SkAutoDataUnref data(stream.copyToData()); | 63 SkAutoDataUnref data(stream.copyToData()); |
| 64 writer->writePad(data->data(), size); | 64 writer->writePad(data->data(), size); |
| 65 } | 65 } |
| 66 return 4 + SkAlign4(size); | 66 return 4 + SkAlign4(size); |
| 67 } | 67 } |
| 68 | 68 |
| 69 /////////////////////////////////////////////////////////////////////////////// | 69 /////////////////////////////////////////////////////////////////////////////// |
| 70 | 70 |
| 71 class FlattenableHeap : public SkFlatController { | 71 class FlattenableHeap : public SkFlatController { |
| 72 public: | 72 public: |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 } | 372 } |
| 373 } | 373 } |
| 374 } | 374 } |
| 375 | 375 |
| 376 bool SkGPipeCanvas::shuttleBitmap(const SkBitmap& bm, int32_t slot) { | 376 bool SkGPipeCanvas::shuttleBitmap(const SkBitmap& bm, int32_t slot) { |
| 377 SkASSERT(shouldFlattenBitmaps(fFlags)); | 377 SkASSERT(shouldFlattenBitmaps(fFlags)); |
| 378 SkWriteBuffer buffer; | 378 SkWriteBuffer buffer; |
| 379 buffer.setNamedFactoryRecorder(fFactorySet); | 379 buffer.setNamedFactoryRecorder(fFactorySet); |
| 380 buffer.writeBitmap(bm); | 380 buffer.writeBitmap(bm); |
| 381 this->flattenFactoryNames(); | 381 this->flattenFactoryNames(); |
| 382 uint32_t size = buffer.bytesWritten(); | 382 size_t size = buffer.bytesWritten(); |
| 383 if (this->needOpBytes(size)) { | 383 if (this->needOpBytes(size)) { |
| 384 this->writeOp(kDef_Bitmap_DrawOp, 0, slot); | 384 this->writeOp(kDef_Bitmap_DrawOp, 0, slot); |
| 385 void* dst = static_cast<void*>(fWriter.reserve(size)); | 385 void* dst = static_cast<void*>(fWriter.reserve(size)); |
| 386 buffer.writeToMemory(dst); | 386 buffer.writeToMemory(dst); |
| 387 return true; | 387 return true; |
| 388 } | 388 } |
| 389 return false; | 389 return false; |
| 390 } | 390 } |
| 391 | 391 |
| 392 // return 0 for NULL (or unflattenable obj), or index-base-1 | 392 // return 0 for NULL (or unflattenable obj), or index-base-1 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 bool SkGPipeCanvas::needOpBytes(size_t needed) { | 471 bool SkGPipeCanvas::needOpBytes(size_t needed) { |
| 472 if (fDone) { | 472 if (fDone) { |
| 473 return false; | 473 return false; |
| 474 } | 474 } |
| 475 | 475 |
| 476 needed += 4; // size of DrawOp atom | 476 needed += 4; // size of DrawOp atom |
| 477 if (fWriter.bytesWritten() + needed > fBlockSize) { | 477 if (fWriter.bytesWritten() + needed > fBlockSize) { |
| 478 // Before we wipe out any data that has already been written, read it | 478 // Before we wipe out any data that has already been written, read it |
| 479 // out. | 479 // out. |
| 480 this->doNotify(); | 480 this->doNotify(); |
| 481 size_t blockSize = SkMax32(MIN_BLOCK_SIZE, needed); | 481 size_t blockSize = SkTMax<size_t>(MIN_BLOCK_SIZE, needed); |
| 482 void* block = fController->requestBlock(blockSize, &fBlockSize); | 482 void* block = fController->requestBlock(blockSize, &fBlockSize); |
| 483 if (NULL == block) { | 483 if (NULL == block) { |
| 484 // Do not notify the readers, which would call this function again. | 484 // Do not notify the readers, which would call this function again. |
| 485 this->finish(false); | 485 this->finish(false); |
| 486 return false; | 486 return false; |
| 487 } | 487 } |
| 488 SkASSERT(SkIsAlign4(fBlockSize)); | 488 SkASSERT(SkIsAlign4(fBlockSize)); |
| 489 fWriter.reset(block, fBlockSize); | 489 fWriter.reset(block, fBlockSize); |
| 490 fBytesNotified = 0; | 490 fBytesNotified = 0; |
| 491 } | 491 } |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 } | 697 } |
| 698 } | 698 } |
| 699 | 699 |
| 700 void SkGPipeCanvas::drawPoints(PointMode mode, size_t count, | 700 void SkGPipeCanvas::drawPoints(PointMode mode, size_t count, |
| 701 const SkPoint pts[], const SkPaint& paint) { | 701 const SkPoint pts[], const SkPaint& paint) { |
| 702 if (count) { | 702 if (count) { |
| 703 NOTIFY_SETUP(this); | 703 NOTIFY_SETUP(this); |
| 704 this->writePaint(paint); | 704 this->writePaint(paint); |
| 705 if (this->needOpBytes(4 + count * sizeof(SkPoint))) { | 705 if (this->needOpBytes(4 + count * sizeof(SkPoint))) { |
| 706 this->writeOp(kDrawPoints_DrawOp, mode, 0); | 706 this->writeOp(kDrawPoints_DrawOp, mode, 0); |
| 707 fWriter.write32(count); | 707 fWriter.write32(SkToU32(count)); |
| 708 fWriter.write(pts, count * sizeof(SkPoint)); | 708 fWriter.write(pts, count * sizeof(SkPoint)); |
| 709 } | 709 } |
| 710 } | 710 } |
| 711 } | 711 } |
| 712 | 712 |
| 713 void SkGPipeCanvas::drawOval(const SkRect& rect, const SkPaint& paint) { | 713 void SkGPipeCanvas::drawOval(const SkRect& rect, const SkPaint& paint) { |
| 714 NOTIFY_SETUP(this); | 714 NOTIFY_SETUP(this); |
| 715 this->writePaint(paint); | 715 this->writePaint(paint); |
| 716 if (this->needOpBytes(sizeof(SkRect))) { | 716 if (this->needOpBytes(sizeof(SkRect))) { |
| 717 this->writeOp(kDrawOval_DrawOp); | 717 this->writeOp(kDrawOval_DrawOp); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 } | 848 } |
| 849 } | 849 } |
| 850 | 850 |
| 851 void SkGPipeCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x,
SkScalar y, | 851 void SkGPipeCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x,
SkScalar y, |
| 852 const SkPaint& paint) { | 852 const SkPaint& paint) { |
| 853 if (byteLength) { | 853 if (byteLength) { |
| 854 NOTIFY_SETUP(this); | 854 NOTIFY_SETUP(this); |
| 855 this->writePaint(paint); | 855 this->writePaint(paint); |
| 856 if (this->needOpBytes(4 + SkAlign4(byteLength) + 2 * sizeof(SkScalar)))
{ | 856 if (this->needOpBytes(4 + SkAlign4(byteLength) + 2 * sizeof(SkScalar)))
{ |
| 857 this->writeOp(kDrawText_DrawOp); | 857 this->writeOp(kDrawText_DrawOp); |
| 858 fWriter.write32(byteLength); | 858 fWriter.write32(SkToU32(byteLength)); |
| 859 fWriter.writePad(text, byteLength); | 859 fWriter.writePad(text, byteLength); |
| 860 fWriter.writeScalar(x); | 860 fWriter.writeScalar(x); |
| 861 fWriter.writeScalar(y); | 861 fWriter.writeScalar(y); |
| 862 } | 862 } |
| 863 } | 863 } |
| 864 } | 864 } |
| 865 | 865 |
| 866 void SkGPipeCanvas::onDrawPosText(const void* text, size_t byteLength, const SkP
oint pos[], | 866 void SkGPipeCanvas::onDrawPosText(const void* text, size_t byteLength, const SkP
oint pos[], |
| 867 const SkPaint& paint) { | 867 const SkPaint& paint) { |
| 868 if (byteLength) { | 868 if (byteLength) { |
| 869 NOTIFY_SETUP(this); | 869 NOTIFY_SETUP(this); |
| 870 this->writePaint(paint); | 870 this->writePaint(paint); |
| 871 int count = paint.textToGlyphs(text, byteLength, NULL); | 871 int count = paint.textToGlyphs(text, byteLength, NULL); |
| 872 if (this->needOpBytes(4 + SkAlign4(byteLength) + 4 + count * sizeof(SkPo
int))) { | 872 if (this->needOpBytes(4 + SkAlign4(byteLength) + 4 + count * sizeof(SkPo
int))) { |
| 873 this->writeOp(kDrawPosText_DrawOp); | 873 this->writeOp(kDrawPosText_DrawOp); |
| 874 fWriter.write32(byteLength); | 874 fWriter.write32(SkToU32(byteLength)); |
| 875 fWriter.writePad(text, byteLength); | 875 fWriter.writePad(text, byteLength); |
| 876 fWriter.write32(count); | 876 fWriter.write32(count); |
| 877 fWriter.write(pos, count * sizeof(SkPoint)); | 877 fWriter.write(pos, count * sizeof(SkPoint)); |
| 878 } | 878 } |
| 879 } | 879 } |
| 880 } | 880 } |
| 881 | 881 |
| 882 void SkGPipeCanvas::onDrawPosTextH(const void* text, size_t byteLength, const Sk
Scalar xpos[], | 882 void SkGPipeCanvas::onDrawPosTextH(const void* text, size_t byteLength, const Sk
Scalar xpos[], |
| 883 SkScalar constY, const SkPaint& paint) { | 883 SkScalar constY, const SkPaint& paint) { |
| 884 if (byteLength) { | 884 if (byteLength) { |
| 885 NOTIFY_SETUP(this); | 885 NOTIFY_SETUP(this); |
| 886 this->writePaint(paint); | 886 this->writePaint(paint); |
| 887 int count = paint.textToGlyphs(text, byteLength, NULL); | 887 int count = paint.textToGlyphs(text, byteLength, NULL); |
| 888 if (this->needOpBytes(4 + SkAlign4(byteLength) + 4 + count * sizeof(SkSc
alar) + 4)) { | 888 if (this->needOpBytes(4 + SkAlign4(byteLength) + 4 + count * sizeof(SkSc
alar) + 4)) { |
| 889 this->writeOp(kDrawPosTextH_DrawOp); | 889 this->writeOp(kDrawPosTextH_DrawOp); |
| 890 fWriter.write32(byteLength); | 890 fWriter.write32(SkToU32(byteLength)); |
| 891 fWriter.writePad(text, byteLength); | 891 fWriter.writePad(text, byteLength); |
| 892 fWriter.write32(count); | 892 fWriter.write32(count); |
| 893 fWriter.write(xpos, count * sizeof(SkScalar)); | 893 fWriter.write(xpos, count * sizeof(SkScalar)); |
| 894 fWriter.writeScalar(constY); | 894 fWriter.writeScalar(constY); |
| 895 } | 895 } |
| 896 } | 896 } |
| 897 } | 897 } |
| 898 | 898 |
| 899 void SkGPipeCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const
SkPath& path, | 899 void SkGPipeCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const
SkPath& path, |
| 900 const SkMatrix* matrix, const SkPaint& pain
t) { | 900 const SkMatrix* matrix, const SkPaint& pain
t) { |
| 901 if (byteLength) { | 901 if (byteLength) { |
| 902 NOTIFY_SETUP(this); | 902 NOTIFY_SETUP(this); |
| 903 unsigned flags = 0; | 903 unsigned flags = 0; |
| 904 size_t size = 4 + SkAlign4(byteLength) + path.writeToMemory(NULL); | 904 size_t size = 4 + SkAlign4(byteLength) + path.writeToMemory(NULL); |
| 905 if (matrix) { | 905 if (matrix) { |
| 906 flags |= kDrawTextOnPath_HasMatrix_DrawOpFlag; | 906 flags |= kDrawTextOnPath_HasMatrix_DrawOpFlag; |
| 907 size += matrix->writeToMemory(NULL); | 907 size += matrix->writeToMemory(NULL); |
| 908 } | 908 } |
| 909 this->writePaint(paint); | 909 this->writePaint(paint); |
| 910 if (this->needOpBytes(size)) { | 910 if (this->needOpBytes(size)) { |
| 911 this->writeOp(kDrawTextOnPath_DrawOp, flags, 0); | 911 this->writeOp(kDrawTextOnPath_DrawOp, flags, 0); |
| 912 | 912 |
| 913 fWriter.write32(byteLength); | 913 fWriter.write32(SkToU32(byteLength)); |
| 914 fWriter.writePad(text, byteLength); | 914 fWriter.writePad(text, byteLength); |
| 915 | 915 |
| 916 fWriter.writePath(path); | 916 fWriter.writePath(path); |
| 917 if (matrix) { | 917 if (matrix) { |
| 918 fWriter.writeMatrix(*matrix); | 918 fWriter.writeMatrix(*matrix); |
| 919 } | 919 } |
| 920 } | 920 } |
| 921 } | 921 } |
| 922 } | 922 } |
| 923 | 923 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 982 void SkGPipeCanvas::drawData(const void* ptr, size_t size) { | 982 void SkGPipeCanvas::drawData(const void* ptr, size_t size) { |
| 983 if (size && ptr) { | 983 if (size && ptr) { |
| 984 NOTIFY_SETUP(this); | 984 NOTIFY_SETUP(this); |
| 985 unsigned data = 0; | 985 unsigned data = 0; |
| 986 if (size < (1 << DRAWOPS_DATA_BITS)) { | 986 if (size < (1 << DRAWOPS_DATA_BITS)) { |
| 987 data = (unsigned)size; | 987 data = (unsigned)size; |
| 988 } | 988 } |
| 989 if (this->needOpBytes(4 + SkAlign4(size))) { | 989 if (this->needOpBytes(4 + SkAlign4(size))) { |
| 990 this->writeOp(kDrawData_DrawOp, 0, data); | 990 this->writeOp(kDrawData_DrawOp, 0, data); |
| 991 if (0 == data) { | 991 if (0 == data) { |
| 992 fWriter.write32(size); | 992 fWriter.write32(SkToU32(size)); |
| 993 } | 993 } |
| 994 fWriter.writePad(ptr, size); | 994 fWriter.writePad(ptr, size); |
| 995 } | 995 } |
| 996 } | 996 } |
| 997 } | 997 } |
| 998 | 998 |
| 999 void SkGPipeCanvas::beginCommentGroup(const char* description) { | 999 void SkGPipeCanvas::beginCommentGroup(const char* description) { |
| 1000 // ignore for now | 1000 // ignore for now |
| 1001 } | 1001 } |
| 1002 | 1002 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1132 } | 1132 } |
| 1133 SkASSERT(index >= 0 && index <= fFlatDictionary.count()); | 1133 SkASSERT(index >= 0 && index <= fFlatDictionary.count()); |
| 1134 if (index != fCurrFlatIndex[i] || replaced) { | 1134 if (index != fCurrFlatIndex[i] || replaced) { |
| 1135 *ptr++ = PaintOp_packOpFlagData(kFlatIndex_PaintOp, i, index); | 1135 *ptr++ = PaintOp_packOpFlagData(kFlatIndex_PaintOp, i, index); |
| 1136 fCurrFlatIndex[i] = index; | 1136 fCurrFlatIndex[i] = index; |
| 1137 } | 1137 } |
| 1138 } | 1138 } |
| 1139 | 1139 |
| 1140 size_t size = (char*)ptr - (char*)storage; | 1140 size_t size = (char*)ptr - (char*)storage; |
| 1141 if (size && this->needOpBytes(size)) { | 1141 if (size && this->needOpBytes(size)) { |
| 1142 this->writeOp(kPaintOp_DrawOp, 0, size); | 1142 this->writeOp(kPaintOp_DrawOp, 0, SkToU32(size)); |
| 1143 fWriter.write(storage, size); | 1143 fWriter.write(storage, size); |
| 1144 for (size_t i = 0; i < size/4; i++) { | 1144 for (size_t i = 0; i < size/4; i++) { |
| 1145 // SkDebugf("[%d] %08X\n", i, storage[i]); | 1145 // SkDebugf("[%d] %08X\n", i, storage[i]); |
| 1146 } | 1146 } |
| 1147 } | 1147 } |
| 1148 | 1148 |
| 1149 // | 1149 // |
| 1150 // Do these after we've written kPaintOp_DrawOp | 1150 // Do these after we've written kPaintOp_DrawOp |
| 1151 | 1151 |
| 1152 if (base.getAnnotation() != paint.getAnnotation()) { | 1152 if (base.getAnnotation() != paint.getAnnotation()) { |
| 1153 if (NULL == paint.getAnnotation()) { | 1153 if (NULL == paint.getAnnotation()) { |
| 1154 if (this->needOpBytes()) { | 1154 if (this->needOpBytes()) { |
| 1155 this->writeOp(kSetAnnotation_DrawOp, 0, 0); | 1155 this->writeOp(kSetAnnotation_DrawOp, 0, 0); |
| 1156 } | 1156 } |
| 1157 } else { | 1157 } else { |
| 1158 SkWriteBuffer buffer; | 1158 SkWriteBuffer buffer; |
| 1159 paint.getAnnotation()->writeToBuffer(buffer); | 1159 paint.getAnnotation()->writeToBuffer(buffer); |
| 1160 const size_t size = buffer.bytesWritten(); | 1160 const size_t size = buffer.bytesWritten(); |
| 1161 if (this->needOpBytes(size)) { | 1161 if (this->needOpBytes(size)) { |
| 1162 this->writeOp(kSetAnnotation_DrawOp, 0, size); | 1162 this->writeOp(kSetAnnotation_DrawOp, 0, SkToU32(size)); |
| 1163 buffer.writeToMemory(fWriter.reserve(size)); | 1163 buffer.writeToMemory(fWriter.reserve(size)); |
| 1164 } | 1164 } |
| 1165 } | 1165 } |
| 1166 base.setAnnotation(paint.getAnnotation()); | 1166 base.setAnnotation(paint.getAnnotation()); |
| 1167 } | 1167 } |
| 1168 } | 1168 } |
| 1169 | 1169 |
| 1170 /////////////////////////////////////////////////////////////////////////////// | 1170 /////////////////////////////////////////////////////////////////////////////// |
| 1171 | 1171 |
| 1172 #include "SkGPipe.h" | 1172 #include "SkGPipe.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1242 return fCanvas->shuttleBitmap(bitmap, slot); | 1242 return fCanvas->shuttleBitmap(bitmap, slot); |
| 1243 } | 1243 } |
| 1244 | 1244 |
| 1245 void BitmapShuttle::removeCanvas() { | 1245 void BitmapShuttle::removeCanvas() { |
| 1246 if (NULL == fCanvas) { | 1246 if (NULL == fCanvas) { |
| 1247 return; | 1247 return; |
| 1248 } | 1248 } |
| 1249 fCanvas->unref(); | 1249 fCanvas->unref(); |
| 1250 fCanvas = NULL; | 1250 fCanvas = NULL; |
| 1251 } | 1251 } |
| OLD | NEW |