Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: src/core/SkPictureData.cpp

Issue 459043002: Cleaning up SkPicture-related classes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkPictureData.h ('k') | src/core/SkPictureFlat.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 #include <new> 7 #include <new>
8 #include "SkBBoxHierarchy.h" 8 #include "SkBBoxHierarchy.h"
9 #include "SkDrawPictureCallback.h" 9 #include "SkDrawPictureCallback.h"
10 #include "SkPictureData.h" 10 #include "SkPictureData.h"
(...skipping 22 matching lines...) Expand all
33 for (int i = 0; i < fPathHeap->count(); i++) { 33 for (int i = 0; i < fPathHeap->count(); i++) {
34 (*fPathHeap.get())[i].updateBoundsCache(); 34 (*fPathHeap.get())[i].updateBoundsCache();
35 } 35 }
36 } 36 }
37 } 37 }
38 38
39 SkPictureData::SkPictureData(const SkPictureRecord& record, 39 SkPictureData::SkPictureData(const SkPictureRecord& record,
40 const SkPictInfo& info, 40 const SkPictInfo& info,
41 bool deepCopyOps) 41 bool deepCopyOps)
42 : fInfo(info) { 42 : fInfo(info) {
43 #ifdef SK_DEBUG_SIZE
44 size_t overallBytes, bitmapBytes, matricesBytes,
45 paintBytes, pathBytes, pictureBytes, regionBytes;
46 int bitmaps = record.bitmaps(&bitmapBytes);
47 int matrices = record.matrices(&matricesBytes);
48 int paints = record.paints(&paintBytes);
49 int paths = record.paths(&pathBytes);
50 int pictures = record.pictures(&pictureBytes);
51 int regions = record.regions(&regionBytes);
52 SkDebugf("picture record mem used %zd (stream %zd) ", record.size(),
53 record.streamlen());
54 if (bitmaps != 0)
55 SkDebugf("bitmaps size %zd (bitmaps:%d) ", bitmapBytes, bitmaps);
56 if (matrices != 0)
57 SkDebugf("matrices size %zd (matrices:%d) ", matricesBytes, matrices);
58 if (paints != 0)
59 SkDebugf("paints size %zd (paints:%d) ", paintBytes, paints);
60 if (paths != 0)
61 SkDebugf("paths size %zd (paths:%d) ", pathBytes, paths);
62 if (pictures != 0)
63 SkDebugf("pictures size %zd (pictures:%d) ", pictureBytes, pictures);
64 if (regions != 0)
65 SkDebugf("regions size %zd (regions:%d) ", regionBytes, regions);
66 if (record.fPointWrites != 0)
67 SkDebugf("points size %zd (points:%d) ", record.fPointBytes, record.fPoi ntWrites);
68 if (record.fRectWrites != 0)
69 SkDebugf("rects size %zd (rects:%d) ", record.fRectBytes, record.fRectWr ites);
70 if (record.fTextWrites != 0)
71 SkDebugf("text size %zd (text strings:%d) ", record.fTextBytes, record.f TextWrites);
72
73 SkDebugf("\n");
74 #endif
75 #ifdef SK_DEBUG_DUMP
76 record.dumpMatrices();
77 record.dumpPaints();
78 #endif
79 43
80 this->init(); 44 this->init();
81 45
82 fOpData = record.opData(deepCopyOps); 46 fOpData = record.opData(deepCopyOps);
83 47
84 fBoundingHierarchy = record.fBoundingHierarchy; 48 fBoundingHierarchy = record.fBoundingHierarchy;
85 fStateTree = record.fStateTree; 49 fStateTree = record.fStateTree;
86 50
87 SkSafeRef(fBoundingHierarchy); 51 SkSafeRef(fBoundingHierarchy);
88 SkSafeRef(fStateTree); 52 SkSafeRef(fStateTree);
(...skipping 16 matching lines...) Expand all
105 69
106 const SkTDArray<const SkPicture* >& pictures = record.getPictureRefs(); 70 const SkTDArray<const SkPicture* >& pictures = record.getPictureRefs();
107 fPictureCount = pictures.count(); 71 fPictureCount = pictures.count();
108 if (fPictureCount > 0) { 72 if (fPictureCount > 0) {
109 fPictureRefs = SkNEW_ARRAY(const SkPicture*, fPictureCount); 73 fPictureRefs = SkNEW_ARRAY(const SkPicture*, fPictureCount);
110 for (int i = 0; i < fPictureCount; i++) { 74 for (int i = 0; i < fPictureCount; i++) {
111 fPictureRefs[i] = pictures[i]; 75 fPictureRefs[i] = pictures[i];
112 fPictureRefs[i]->ref(); 76 fPictureRefs[i]->ref();
113 } 77 }
114 } 78 }
115
116 #ifdef SK_DEBUG_SIZE
117 int overall = fPlayback->size(&overallBytes);
118 bitmaps = fPlayback->bitmaps(&bitmapBytes);
119 paints = fPlayback->paints(&paintBytes);
120 paths = fPlayback->paths(&pathBytes);
121 pictures = fPlayback->pictures(&pictureBytes);
122 regions = fPlayback->regions(&regionBytes);
123 SkDebugf("playback size %zd (objects:%d) ", overallBytes, overall);
124 if (bitmaps != 0)
125 SkDebugf("bitmaps size %zd (bitmaps:%d) ", bitmapBytes, bitmaps);
126 if (paints != 0)
127 SkDebugf("paints size %zd (paints:%d) ", paintBytes, paints);
128 if (paths != 0)
129 SkDebugf("paths size %zd (paths:%d) ", pathBytes, paths);
130 if (pictures != 0)
131 SkDebugf("pictures size %zd (pictures:%d) ", pictureBytes, pictures);
132 if (regions != 0)
133 SkDebugf("regions size %zd (regions:%d) ", regionBytes, regions);
134 SkDebugf("\n");
135 #endif
136 } 79 }
137 80
138 #ifdef SK_SUPPORT_LEGACY_PICTURE_CLONE 81 #ifdef SK_SUPPORT_LEGACY_PICTURE_CLONE
139 SkPictureData::SkPictureData(const SkPictureData& src, SkPictCopyInfo* deepCopyI nfo) 82 SkPictureData::SkPictureData(const SkPictureData& src, SkPictCopyInfo* deepCopyI nfo)
140 : fInfo(src.fInfo) { 83 : fInfo(src.fInfo) {
141 this->init(); 84 this->init();
142 85
143 fBitmapHeap.reset(SkSafeRef(src.fBitmapHeap.get())); 86 fBitmapHeap.reset(SkSafeRef(src.fBitmapHeap.get()));
144 fPathHeap.reset(SkSafeRef(src.fPathHeap.get())); 87 fPathHeap.reset(SkSafeRef(src.fPathHeap.get()));
145 88
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 SkSafeUnref(fStateTree); 154 SkSafeUnref(fStateTree);
212 155
213 for (int i = 0; i < fPictureCount; i++) { 156 for (int i = 0; i < fPictureCount; i++) {
214 fPictureRefs[i]->unref(); 157 fPictureRefs[i]->unref();
215 } 158 }
216 SkDELETE_ARRAY(fPictureRefs); 159 SkDELETE_ARRAY(fPictureRefs);
217 160
218 SkDELETE(fFactoryPlayback); 161 SkDELETE(fFactoryPlayback);
219 } 162 }
220 163
221 void SkPictureData::dumpSize() const {
222 SkDebugf("--- picture size: ops=%d bitmaps=%d [%d] paints=%d [%d]\n",
223 fOpData->size(),
224 SafeCount(fBitmaps), SafeCount(fBitmaps) * sizeof(SkBitmap),
225 SafeCount(fPaints), SafeCount(fPaints) * sizeof(SkPaint));
226 SkDebugf("--- picture size: paths=%d\n",
227 SafeCount(fPathHeap.get()));
228 }
229
230 bool SkPictureData::containsBitmaps() const { 164 bool SkPictureData::containsBitmaps() const {
231 if (fBitmaps && fBitmaps->count() > 0) { 165 if (fBitmaps && fBitmaps->count() > 0) {
232 return true; 166 return true;
233 } 167 }
234 for (int i = 0; i < fPictureCount; ++i) { 168 for (int i = 0; i < fPictureCount; ++i) {
235 if (fPictureRefs[i]->willPlayBackBitmaps()) { 169 if (fPictureRefs[i]->willPlayBackBitmaps()) {
236 return true; 170 return true;
237 } 171 }
238 } 172 }
239 return false; 173 return false;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 214
281 size_t size = compute_chunk_size(array, count); 215 size_t size = compute_chunk_size(array, count);
282 216
283 // TODO: write_tag_size should really take a size_t 217 // TODO: write_tag_size should really take a size_t
284 write_tag_size(stream, SK_PICT_FACTORY_TAG, (uint32_t) size); 218 write_tag_size(stream, SK_PICT_FACTORY_TAG, (uint32_t) size);
285 SkDEBUGCODE(size_t start = stream->bytesWritten()); 219 SkDEBUGCODE(size_t start = stream->bytesWritten());
286 stream->write32(count); 220 stream->write32(count);
287 221
288 for (int i = 0; i < count; i++) { 222 for (int i = 0; i < count; i++) {
289 const char* name = SkFlattenable::FactoryToName(array[i]); 223 const char* name = SkFlattenable::FactoryToName(array[i]);
290 // SkDebugf("---- write factories [%d] %p <%s>\n", i, array[i], name);
291 if (NULL == name || 0 == *name) { 224 if (NULL == name || 0 == *name) {
292 stream->writePackedUInt(0); 225 stream->writePackedUInt(0);
293 } else { 226 } else {
294 size_t len = strlen(name); 227 size_t len = strlen(name);
295 stream->writePackedUInt(len); 228 stream->writePackedUInt(len);
296 stream->write(name, len); 229 stream->write(name, len);
297 } 230 }
298 } 231 }
299 232
300 SkASSERT(size == (stream->bytesWritten() - start)); 233 SkASSERT(size == (stream->bytesWritten() - start));
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 return this->suitableForGpuRasterization(context, reason, 613 return this->suitableForGpuRasterization(context, reason,
681 context->getRecommendedSampleCo unt(config, dpi)); 614 context->getRecommendedSampleCo unt(config, dpi));
682 } else { 615 } else {
683 return this->suitableForGpuRasterization(NULL, reason); 616 return this->suitableForGpuRasterization(NULL, reason);
684 } 617 }
685 } 618 }
686 619
687 #endif 620 #endif
688 /////////////////////////////////////////////////////////////////////////////// 621 ///////////////////////////////////////////////////////////////////////////////
689 622
690 #ifdef SK_DEBUG_SIZE
691 int SkPictureData::size(size_t* sizePtr) {
692 int objects = bitmaps(sizePtr);
693 objects += paints(sizePtr);
694 objects += paths(sizePtr);
695 objects += pictures(sizePtr);
696 objects += regions(sizePtr);
697 *sizePtr = fOpData.size();
698 return objects;
699 }
700 623
701 int SkPictureData::bitmaps(size_t* size) {
702 size_t result = 0;
703 for (int index = 0; index < fBitmapCount; index++) {
704 // const SkBitmap& bitmap = fBitmaps[index];
705 result += sizeof(SkBitmap); // bitmap->size();
706 }
707 *size = result;
708 return fBitmapCount;
709 }
710
711 int SkPictureData::paints(size_t* size) {
712 size_t result = 0;
713 for (int index = 0; index < fPaintCount; index++) {
714 // const SkPaint& paint = fPaints[index];
715 result += sizeof(SkPaint); // paint->size();
716 }
717 *size = result;
718 return fPaintCount;
719 }
720
721 int SkPictureData::paths(size_t* size) {
722 size_t result = 0;
723 for (int index = 0; index < fPathCount; index++) {
724 const SkPath& path = fPaths[index];
725 result += path.flatten(NULL);
726 }
727 *size = result;
728 return fPathCount;
729 }
730 #endif
731
732 #ifdef SK_DEBUG_DUMP
733 void SkPictureData::dumpBitmap(const SkBitmap& bitmap) const {
734 char pBuffer[DUMP_BUFFER_SIZE];
735 char* bufferPtr = pBuffer;
736 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
737 "BitmapData bitmap%p = {", &bitmap);
738 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
739 "{kWidth, %d}, ", bitmap.width());
740 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
741 "{kHeight, %d}, ", bitmap.height());
742 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
743 "{kRowBytes, %d}, ", bitmap.rowBytes());
744 // start here;
745 SkDebugf("%s{0}};\n", pBuffer);
746 }
747
748 void dumpMatrix(const SkMatrix& matrix) const {
749 SkMatrix defaultMatrix;
750 defaultMatrix.reset();
751 char pBuffer[DUMP_BUFFER_SIZE];
752 char* bufferPtr = pBuffer;
753 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
754 "MatrixData matrix%p = {", &matrix);
755 SkScalar scaleX = matrix.getScaleX();
756 if (scaleX != defaultMatrix.getScaleX())
757 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
758 "{kScaleX, %g}, ", SkScalarToFloat(scaleX));
759 SkScalar scaleY = matrix.getScaleY();
760 if (scaleY != defaultMatrix.getScaleY())
761 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
762 "{kScaleY, %g}, ", SkScalarToFloat(scaleY));
763 SkScalar skewX = matrix.getSkewX();
764 if (skewX != defaultMatrix.getSkewX())
765 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
766 "{kSkewX, %g}, ", SkScalarToFloat(skewX));
767 SkScalar skewY = matrix.getSkewY();
768 if (skewY != defaultMatrix.getSkewY())
769 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
770 "{kSkewY, %g}, ", SkScalarToFloat(skewY));
771 SkScalar translateX = matrix.getTranslateX();
772 if (translateX != defaultMatrix.getTranslateX())
773 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
774 "{kTranslateX, %g}, ", SkScalarToFloat(translateX));
775 SkScalar translateY = matrix.getTranslateY();
776 if (translateY != defaultMatrix.getTranslateY())
777 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
778 "{kTranslateY, %g}, ", SkScalarToFloat(translateY));
779 SkScalar perspX = matrix.getPerspX();
780 if (perspX != defaultMatrix.getPerspX())
781 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
782 "{kPerspX, %g}, ", perspX);
783 SkScalar perspY = matrix.getPerspY();
784 if (perspY != defaultMatrix.getPerspY())
785 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
786 "{kPerspY, %g}, ", perspY);
787 SkDebugf("%s{0}};\n", pBuffer);
788 }
789
790 void dumpPaint(const SkPaint& paint) const {
791 SkPaint defaultPaint;
792 char pBuffer[DUMP_BUFFER_SIZE];
793 char* bufferPtr = pBuffer;
794 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
795 "PaintPointers paintPtrs%p = {", &paint);
796 const SkTypeface* typeface = paint.getTypeface();
797 if (typeface != defaultPaint.getTypeface())
798 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
799 "{kTypeface, %p}, ", typeface);
800 const SkPathEffect* pathEffect = paint.getPathEffect();
801 if (pathEffect != defaultPaint.getPathEffect())
802 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
803 "{kPathEffect, %p}, ", pathEffect);
804 const SkShader* shader = paint.getShader();
805 if (shader != defaultPaint.getShader())
806 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
807 "{kShader, %p}, ", shader);
808 const SkXfermode* xfermode = paint.getXfermode();
809 if (xfermode != defaultPaint.getXfermode())
810 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
811 "{kXfermode, %p}, ", xfermode);
812 const SkMaskFilter* maskFilter = paint.getMaskFilter();
813 if (maskFilter != defaultPaint.getMaskFilter())
814 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
815 "{kMaskFilter, %p}, ", maskFilter);
816 const SkColorFilter* colorFilter = paint.getColorFilter();
817 if (colorFilter != defaultPaint.getColorFilter())
818 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
819 "{kColorFilter, %p}, ", colorFilter);
820 const SkRasterizer* rasterizer = paint.getRasterizer();
821 if (rasterizer != defaultPaint.getRasterizer())
822 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
823 "{kRasterizer, %p}, ", rasterizer);
824 const SkDrawLooper* drawLooper = paint.getLooper();
825 if (drawLooper != defaultPaint.getLooper())
826 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
827 "{kDrawLooper, %p}, ", drawLooper);
828 SkDebugf("%s{0}};\n", pBuffer);
829 bufferPtr = pBuffer;
830 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
831 "PaintScalars paintScalars%p = {", &paint);
832 SkScalar textSize = paint.getTextSize();
833 if (textSize != defaultPaint.getTextSize())
834 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
835 "{kTextSize, %g}, ", SkScalarToFloat(textSize));
836 SkScalar textScaleX = paint.getTextScaleX();
837 if (textScaleX != defaultPaint.getTextScaleX())
838 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
839 "{kTextScaleX, %g}, ", SkScalarToFloat(textScaleX));
840 SkScalar textSkewX = paint.getTextSkewX();
841 if (textSkewX != defaultPaint.getTextSkewX())
842 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
843 "{kTextSkewX, %g}, ", SkScalarToFloat(textSkewX));
844 SkScalar strokeWidth = paint.getStrokeWidth();
845 if (strokeWidth != defaultPaint.getStrokeWidth())
846 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
847 "{kStrokeWidth, %g}, ", SkScalarToFloat(strokeWidth));
848 SkScalar strokeMiter = paint.getStrokeMiter();
849 if (strokeMiter != defaultPaint.getStrokeMiter())
850 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
851 "{kStrokeMiter, %g}, ", SkScalarToFloat(strokeMiter));
852 SkDebugf("%s{0}};\n", pBuffer);
853 bufferPtr = pBuffer;
854 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
855 "PaintInts = paintInts%p = {", &paint);
856 unsigned color = paint.getColor();
857 if (color != defaultPaint.getColor())
858 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
859 "{kColor, 0x%x}, ", color);
860 unsigned flags = paint.getFlags();
861 if (flags != defaultPaint.getFlags())
862 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
863 "{kFlags, 0x%x}, ", flags);
864 int align = paint.getTextAlign();
865 if (align != defaultPaint.getTextAlign())
866 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
867 "{kAlign, 0x%x}, ", align);
868 int strokeCap = paint.getStrokeCap();
869 if (strokeCap != defaultPaint.getStrokeCap())
870 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
871 "{kStrokeCap, 0x%x}, ", strokeCap);
872 int strokeJoin = paint.getStrokeJoin();
873 if (strokeJoin != defaultPaint.getStrokeJoin())
874 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
875 "{kAlign, 0x%x}, ", strokeJoin);
876 int style = paint.getStyle();
877 if (style != defaultPaint.getStyle())
878 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
879 "{kStyle, 0x%x}, ", style);
880 int textEncoding = paint.getTextEncoding();
881 if (textEncoding != defaultPaint.getTextEncoding())
882 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
883 "{kTextEncoding, 0x%x}, ", textEncoding);
884 SkDebugf("%s{0}};\n", pBuffer);
885
886 SkDebugf("PaintData paint%p = {paintPtrs%p, paintScalars%p, paintInts%p};\n" ,
887 &paint, &paint, &paint, &paint);
888 }
889
890 void SkPictureData::dumpPath(const SkPath& path) const {
891 SkDebugf("path dump unimplemented\n");
892 }
893
894 void SkPictureData::dumpPicture(const SkPicture& picture) const {
895 SkDebugf("picture dump unimplemented\n");
896 }
897
898 void SkPictureData::dumpRegion(const SkRegion& region) const {
899 SkDebugf("region dump unimplemented\n");
900 }
901
902 int SkPictureData::dumpDrawType(char* bufferPtr, char* buffer, DrawType drawType ) {
903 return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
904 "k%s, ", DrawTypeToString(drawType));
905 }
906
907 int SkPictureData::dumpInt(char* bufferPtr, char* buffer, char* name) {
908 return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
909 "%s:%d, ", name, getInt());
910 }
911
912 int SkPictureData::dumpRect(char* bufferPtr, char* buffer, char* name) {
913 const SkRect* rect = fReader.skipRect();
914 return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
915 "%s:{l:%g t:%g r:%g b:%g}, ", name, SkScalarToFloat(rect.fLeft),
916 SkScalarToFloat(rect.fTop),
917 SkScalarToFloat(rect.fRight), SkScalarToFloat(rect.fBottom));
918 }
919
920 int SkPictureData::dumpPoint(char* bufferPtr, char* buffer, char* name) {
921 SkPoint pt;
922 getPoint(&pt);
923 return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
924 "%s:{x:%g y:%g}, ", name, SkScalarToFloat(pt.fX),
925 SkScalarToFloat(pt.fY));
926 }
927
928 void SkPictureData::dumpPointArray(char** bufferPtrPtr, char* buffer, int count) {
929 char* bufferPtr = *bufferPtrPtr;
930 const SkPoint* pts = (const SkPoint*)fReadStream.getAtPos();
931 fReadStream.skip(sizeof(SkPoint) * count);
932 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
933 "count:%d {", count);
934 for (int index = 0; index < count; index++)
935 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer) ,
936 "{x:%g y:%g}, ", SkScalarToFloat(pts[index].fX),
937 SkScalarToFloat(pts[index].fY));
938 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
939 "} ");
940 *bufferPtrPtr = bufferPtr;
941 }
942
943 int SkPictureData::dumpPtr(char* bufferPtr, char* buffer, char* name, void* ptr) {
944 return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
945 "%s:%p, ", name, ptr);
946 }
947
948 int SkPictureData::dumpRectPtr(char* bufferPtr, char* buffer, char* name) {
949 char result;
950 fReadStream.read(&result, sizeof(result));
951 if (result)
952 return dumpRect(bufferPtr, buffer, name);
953 else
954 return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
955 "%s:NULL, ", name);
956 }
957
958 int SkPictureData::dumpScalar(char* bufferPtr, char* buffer, char* name) {
959 return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer),
960 "%s:%d, ", name, getScalar());
961 }
962
963 void SkPictureData::dumpText(char** bufferPtrPtr, char* buffer) {
964 char* bufferPtr = *bufferPtrPtr;
965 int length = getInt();
966 bufferPtr += dumpDrawType(bufferPtr, buffer);
967 fReadStream.skipToAlign4();
968 char* text = (char*) fReadStream.getAtPos();
969 fReadStream.skip(length);
970 bufferPtr += dumpInt(bufferPtr, buffer, "length");
971 int limit = DUMP_BUFFER_SIZE - (bufferPtr - buffer) - 2;
972 length >>= 1;
973 if (limit > length)
974 limit = length;
975 if (limit > 0) {
976 *bufferPtr++ = '"';
977 for (int index = 0; index < limit; index++) {
978 *bufferPtr++ = *(unsigned short*) text;
979 text += sizeof(unsigned short);
980 }
981 *bufferPtr++ = '"';
982 }
983 *bufferPtrPtr = bufferPtr;
984 }
985
986 #define DUMP_DRAWTYPE(drawType) \
987 bufferPtr += dumpDrawType(bufferPtr, buffer, drawType)
988
989 #define DUMP_INT(name) \
990 bufferPtr += dumpInt(bufferPtr, buffer, #name)
991
992 #define DUMP_RECT_PTR(name) \
993 bufferPtr += dumpRectPtr(bufferPtr, buffer, #name)
994
995 #define DUMP_POINT(name) \
996 bufferPtr += dumpRect(bufferPtr, buffer, #name)
997
998 #define DUMP_RECT(name) \
999 bufferPtr += dumpRect(bufferPtr, buffer, #name)
1000
1001 #define DUMP_POINT_ARRAY(count) \
1002 dumpPointArray(&bufferPtr, buffer, count)
1003
1004 #define DUMP_PTR(name, ptr) \
1005 bufferPtr += dumpPtr(bufferPtr, buffer, #name, (void*) ptr)
1006
1007 #define DUMP_SCALAR(name) \
1008 bufferPtr += dumpScalar(bufferPtr, buffer, #name)
1009
1010 #define DUMP_TEXT() \
1011 dumpText(&bufferPtr, buffer)
1012
1013 void SkPictureData::dumpStream() {
1014 SkDebugf("RecordStream stream = {\n");
1015 DrawType drawType;
1016 fReadStream.rewind();
1017 char buffer[DUMP_BUFFER_SIZE], * bufferPtr;
1018 while (fReadStream.read(&drawType, sizeof(drawType))) {
1019 bufferPtr = buffer;
1020 DUMP_DRAWTYPE(drawType);
1021 switch (drawType) {
1022 case CLIP_PATH: {
1023 DUMP_PTR(SkPath, &getPath());
1024 DUMP_INT(SkRegion::Op);
1025 DUMP_INT(offsetToRestore);
1026 } break;
1027 case CLIP_REGION: {
1028 DUMP_INT(SkRegion::Op);
1029 DUMP_INT(offsetToRestore);
1030 } break;
1031 case CLIP_RECT: {
1032 DUMP_RECT(rect);
1033 DUMP_INT(SkRegion::Op);
1034 DUMP_INT(offsetToRestore);
1035 } break;
1036 case CONCAT:
1037 break;
1038 case DRAW_BITMAP: {
1039 DUMP_PTR(SkPaint, getPaint());
1040 DUMP_PTR(SkBitmap, &getBitmap());
1041 DUMP_SCALAR(left);
1042 DUMP_SCALAR(top);
1043 } break;
1044 case DRAW_PAINT:
1045 DUMP_PTR(SkPaint, getPaint());
1046 break;
1047 case DRAW_PATH: {
1048 DUMP_PTR(SkPaint, getPaint());
1049 DUMP_PTR(SkPath, &getPath());
1050 } break;
1051 case DRAW_PICTURE: {
1052 DUMP_PTR(SkPicture, &getPicture());
1053 } break;
1054 case DRAW_POINTS: {
1055 DUMP_PTR(SkPaint, getPaint());
1056 (void)getInt(); // PointMode
1057 size_t count = getInt();
1058 fReadStream.skipToAlign4();
1059 DUMP_POINT_ARRAY(count);
1060 } break;
1061 case DRAW_POS_TEXT: {
1062 DUMP_PTR(SkPaint, getPaint());
1063 DUMP_TEXT();
1064 size_t points = getInt();
1065 fReadStream.skipToAlign4();
1066 DUMP_POINT_ARRAY(points);
1067 } break;
1068 case DRAW_POS_TEXT_H: {
1069 DUMP_PTR(SkPaint, getPaint());
1070 DUMP_TEXT();
1071 size_t points = getInt();
1072 fReadStream.skipToAlign4();
1073 DUMP_SCALAR(top);
1074 DUMP_SCALAR(bottom);
1075 DUMP_SCALAR(constY);
1076 DUMP_POINT_ARRAY(points);
1077 } break;
1078 case DRAW_RECT: {
1079 DUMP_PTR(SkPaint, getPaint());
1080 DUMP_RECT(rect);
1081 } break;
1082 case DRAW_SPRITE: {
1083 DUMP_PTR(SkPaint, getPaint());
1084 DUMP_PTR(SkBitmap, &getBitmap());
1085 DUMP_SCALAR(left);
1086 DUMP_SCALAR(top);
1087 } break;
1088 case DRAW_TEXT: {
1089 DUMP_PTR(SkPaint, getPaint());
1090 DUMP_TEXT();
1091 DUMP_SCALAR(x);
1092 DUMP_SCALAR(y);
1093 } break;
1094 case DRAW_TEXT_ON_PATH: {
1095 DUMP_PTR(SkPaint, getPaint());
1096 DUMP_TEXT();
1097 DUMP_PTR(SkPath, &getPath());
1098 } break;
1099 case RESTORE:
1100 break;
1101 case ROTATE:
1102 DUMP_SCALAR(rotate);
1103 break;
1104 case SAVE:
1105 DUMP_INT(SkCanvas::SaveFlags);
1106 break;
1107 case SAVE_LAYER: {
1108 DUMP_RECT_PTR(layer);
1109 DUMP_PTR(SkPaint, getPaint());
1110 DUMP_INT(SkCanvas::SaveFlags);
1111 } break;
1112 case SCALE: {
1113 DUMP_SCALAR(sx);
1114 DUMP_SCALAR(sy);
1115 } break;
1116 case SKEW: {
1117 DUMP_SCALAR(sx);
1118 DUMP_SCALAR(sy);
1119 } break;
1120 case TRANSLATE: {
1121 DUMP_SCALAR(dx);
1122 DUMP_SCALAR(dy);
1123 } break;
1124 default:
1125 SkASSERT(0);
1126 }
1127 SkDebugf("%s\n", buffer);
1128 }
1129 }
1130
1131 void SkPictureData::dump() const {
1132 char pBuffer[DUMP_BUFFER_SIZE];
1133 char* bufferPtr = pBuffer;
1134 int index;
1135 if (fBitmapCount > 0)
1136 SkDebugf("// bitmaps (%d)\n", fBitmapCount);
1137 for (index = 0; index < fBitmapCount; index++) {
1138 const SkBitmap& bitmap = fBitmaps[index];
1139 dumpBitmap(bitmap);
1140 }
1141 if (fBitmapCount > 0)
1142 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
1143 "Bitmaps bitmaps = {");
1144 for (index = 0; index < fBitmapCount; index++)
1145 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
1146 "bitmap%p, ", &fBitmaps[index]);
1147 if (fBitmapCount > 0)
1148 SkDebugf("%s0};\n", pBuffer);
1149
1150
1151 if (fPaintCount > 0)
1152 SkDebugf("// paints (%d)\n", fPaintCount);
1153 for (index = 0; index < fPaintCount; index++) {
1154 const SkPaint& paint = fPaints[index];
1155 dumpPaint(paint);
1156 }
1157 bufferPtr = pBuffer;
1158 if (fPaintCount > 0)
1159 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
1160 "Paints paints = {");
1161 for (index = 0; index < fPaintCount; index++)
1162 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
1163 "paint%p, ", &fPaints[index]);
1164 if (fPaintCount > 0)
1165 SkDebugf("%s0};\n", pBuffer);
1166
1167 for (index = 0; index < fPathCount; index++) {
1168 const SkPath& path = fPaths[index];
1169 dumpPath(path);
1170 }
1171 bufferPtr = pBuffer;
1172 if (fPathCount > 0)
1173 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
1174 "Paths paths = {");
1175 for (index = 0; index < fPathCount; index++)
1176 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
1177 "path%p, ", &fPaths[index]);
1178 if (fPathCount > 0)
1179 SkDebugf("%s0};\n", pBuffer);
1180
1181 for (index = 0; index < fPictureCount; index++) {
1182 dumpPicture(*fPictureRefs[index]);
1183 }
1184 bufferPtr = pBuffer;
1185 if (fPictureCount > 0)
1186 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
1187 "Pictures pictures = {");
1188 for (index = 0; index < fPictureCount; index++)
1189 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
1190 "picture%p, ", fPictureRefs[index]);
1191 if (fPictureCount > 0)
1192 SkDebugf("%s0};\n", pBuffer);
1193
1194 const_cast<SkPictureData*>(this)->dumpStream();
1195 }
1196
1197 #endif
OLDNEW
« no previous file with comments | « src/core/SkPictureData.h ('k') | src/core/SkPictureFlat.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698