OLD | NEW |
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 | 7 |
8 #include "SkPictureRecord.h" | 8 #include "SkPictureRecord.h" |
9 #include "SkBBoxHierarchy.h" | 9 #include "SkBBoxHierarchy.h" |
10 #include "SkDevice.h" | 10 #include "SkDevice.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 fPictureRefs.unrefAll(); | 61 fPictureRefs.unrefAll(); |
62 } | 62 } |
63 | 63 |
64 /////////////////////////////////////////////////////////////////////////////// | 64 /////////////////////////////////////////////////////////////////////////////// |
65 | 65 |
66 // Return the offset of the paint inside a given op's byte stream. A zero | 66 // Return the offset of the paint inside a given op's byte stream. A zero |
67 // return value means there is no paint (and you really shouldn't be calling | 67 // return value means there is no paint (and you really shouldn't be calling |
68 // this method) | 68 // this method) |
69 static inline size_t getPaintOffset(DrawType op, size_t opSize) { | 69 static inline size_t getPaintOffset(DrawType op, size_t opSize) { |
70 // These offsets are where the paint would be if the op size doesn't overflo
w | 70 // These offsets are where the paint would be if the op size doesn't overflo
w |
71 static const uint8_t gPaintOffsets[LAST_DRAWTYPE_ENUM + 1] = { | 71 static const uint8_t gPaintOffsets[] = { |
72 0, // UNUSED - no paint | 72 0, // UNUSED - no paint |
73 0, // CLIP_PATH - no paint | 73 0, // CLIP_PATH - no paint |
74 0, // CLIP_REGION - no paint | 74 0, // CLIP_REGION - no paint |
75 0, // CLIP_RECT - no paint | 75 0, // CLIP_RECT - no paint |
76 0, // CLIP_RRECT - no paint | 76 0, // CLIP_RRECT - no paint |
77 0, // CONCAT - no paint | 77 0, // CONCAT - no paint |
78 1, // DRAW_BITMAP - right after op code | 78 1, // DRAW_BITMAP - right after op code |
79 1, // DRAW_BITMAP_MATRIX - right after op code | 79 1, // DRAW_BITMAP_MATRIX - right after op code |
80 1, // DRAW_BITMAP_NINE - right after op code | 80 1, // DRAW_BITMAP_NINE - right after op code |
81 1, // DRAW_BITMAP_RECT_TO_RECT - right after op code | 81 1, // DRAW_BITMAP_RECT_TO_RECT - right after op code |
(...skipping 24 matching lines...) Expand all Loading... |
106 0, // SKEW - no paint | 106 0, // SKEW - no paint |
107 0, // TRANSLATE - no paint | 107 0, // TRANSLATE - no paint |
108 0, // NOOP - no paint | 108 0, // NOOP - no paint |
109 0, // BEGIN_GROUP - no paint | 109 0, // BEGIN_GROUP - no paint |
110 0, // COMMENT - no paint | 110 0, // COMMENT - no paint |
111 0, // END_GROUP - no paint | 111 0, // END_GROUP - no paint |
112 1, // DRAWDRRECT - right after op code | 112 1, // DRAWDRRECT - right after op code |
113 0, // PUSH_CULL - no paint | 113 0, // PUSH_CULL - no paint |
114 0, // POP_CULL - no paint | 114 0, // POP_CULL - no paint |
115 1, // DRAW_PATCH - right after op code | 115 1, // DRAW_PATCH - right after op code |
| 116 1, // DRAW_PICTURE_MATRIX_PAINT - right after op code |
116 }; | 117 }; |
117 | 118 |
118 SK_COMPILE_ASSERT(sizeof(gPaintOffsets) == LAST_DRAWTYPE_ENUM + 1, | 119 SK_COMPILE_ASSERT(sizeof(gPaintOffsets) == LAST_DRAWTYPE_ENUM + 1, |
119 need_to_be_in_sync); | 120 need_to_be_in_sync); |
120 SkASSERT((unsigned)op <= (unsigned)LAST_DRAWTYPE_ENUM); | 121 SkASSERT((unsigned)op <= (unsigned)LAST_DRAWTYPE_ENUM); |
121 | 122 |
122 int overflow = 0; | 123 int overflow = 0; |
123 if (0 != (opSize & ~MASK_24) || opSize == MASK_24) { | 124 if (0 != (opSize & ~MASK_24) || opSize == MASK_24) { |
124 // This op's size overflows so an extra uint32_t will be written | 125 // This op's size overflows so an extra uint32_t will be written |
125 // after the op code | 126 // after the op code |
(...skipping 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1207 size_t size = 2 * kUInt32Size; | 1208 size_t size = 2 * kUInt32Size; |
1208 size_t initialOffset; | 1209 size_t initialOffset; |
1209 | 1210 |
1210 if (NULL == matrix && NULL == paint) { | 1211 if (NULL == matrix && NULL == paint) { |
1211 initialOffset = this->addDraw(DRAW_PICTURE, &size); | 1212 initialOffset = this->addDraw(DRAW_PICTURE, &size); |
1212 this->addPicture(picture); | 1213 this->addPicture(picture); |
1213 } else { | 1214 } else { |
1214 const SkMatrix& m = matrix ? *matrix : SkMatrix::I(); | 1215 const SkMatrix& m = matrix ? *matrix : SkMatrix::I(); |
1215 size += m.writeToMemory(NULL) + kUInt32Size; // matrix + paint | 1216 size += m.writeToMemory(NULL) + kUInt32Size; // matrix + paint |
1216 initialOffset = this->addDraw(DRAW_PICTURE_MATRIX_PAINT, &size); | 1217 initialOffset = this->addDraw(DRAW_PICTURE_MATRIX_PAINT, &size); |
| 1218 SkASSERT(initialOffset + getPaintOffset(DRAW_PICTURE_MATRIX_PAINT, size) |
| 1219 == fWriter.bytesWritten()); |
| 1220 this->addPaintPtr(paint); |
| 1221 this->addMatrix(m); |
1217 this->addPicture(picture); | 1222 this->addPicture(picture); |
1218 this->addMatrix(m); | |
1219 this->addPaintPtr(paint); | |
1220 } | 1223 } |
1221 this->validate(initialOffset, size); | 1224 this->validate(initialOffset, size); |
1222 } | 1225 } |
1223 | 1226 |
1224 void SkPictureRecord::drawVertices(VertexMode vmode, int vertexCount, | 1227 void SkPictureRecord::drawVertices(VertexMode vmode, int vertexCount, |
1225 const SkPoint vertices[], const SkPoint texs[], | 1228 const SkPoint vertices[], const SkPoint texs[], |
1226 const SkColor colors[], SkXfermode* xfer, | 1229 const SkColor colors[], SkXfermode* xfer, |
1227 const uint16_t indices[], int indexCount, | 1230 const uint16_t indices[], int indexCount, |
1228 const SkPaint& paint) { | 1231 const SkPaint& paint) { |
1229 uint32_t flags = 0; | 1232 uint32_t flags = 0; |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1510 } | 1513 } |
1511 | 1514 |
1512 void SkPictureRecord::addText(const void* text, size_t byteLength) { | 1515 void SkPictureRecord::addText(const void* text, size_t byteLength) { |
1513 fContentInfo.onDrawText(); | 1516 fContentInfo.onDrawText(); |
1514 addInt(SkToInt(byteLength)); | 1517 addInt(SkToInt(byteLength)); |
1515 fWriter.writePad(text, byteLength); | 1518 fWriter.writePad(text, byteLength); |
1516 } | 1519 } |
1517 | 1520 |
1518 /////////////////////////////////////////////////////////////////////////////// | 1521 /////////////////////////////////////////////////////////////////////////////// |
1519 | 1522 |
OLD | NEW |