| 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 "SkDevice.h" | 9 #include "SkDevice.h" |
| 10 #include "SkImage_Base.h" | 10 #include "SkImage_Base.h" |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 } | 580 } |
| 581 | 581 |
| 582 void SkPictureRecord::onDrawImageRect(const SkImage* image, const SkRect* src, c
onst SkRect& dst, | 582 void SkPictureRecord::onDrawImageRect(const SkImage* image, const SkRect* src, c
onst SkRect& dst, |
| 583 const SkPaint* paint, SrcRectConstraint co
nstraint) { | 583 const SkPaint* paint, SrcRectConstraint co
nstraint) { |
| 584 // id + paint_index + image_index + bool_for_src + constraint | 584 // id + paint_index + image_index + bool_for_src + constraint |
| 585 size_t size = 5 * kUInt32Size; | 585 size_t size = 5 * kUInt32Size; |
| 586 if (src) { | 586 if (src) { |
| 587 size += sizeof(*src); // + rect | 587 size += sizeof(*src); // + rect |
| 588 } | 588 } |
| 589 size += sizeof(dst); // + rect | 589 size += sizeof(dst); // + rect |
| 590 | 590 |
| 591 size_t initialOffset = this->addDraw(DRAW_IMAGE_RECT, &size); | 591 size_t initialOffset = this->addDraw(DRAW_IMAGE_RECT, &size); |
| 592 SkASSERT(initialOffset+get_paint_offset(DRAW_IMAGE_RECT, size) | 592 SkASSERT(initialOffset+get_paint_offset(DRAW_IMAGE_RECT, size) |
| 593 == fWriter.bytesWritten()); | 593 == fWriter.bytesWritten()); |
| 594 this->addPaintPtr(paint); | 594 this->addPaintPtr(paint); |
| 595 this->addImage(image); | 595 this->addImage(image); |
| 596 this->addRectPtr(src); // may be null | 596 this->addRectPtr(src); // may be null |
| 597 this->addRect(dst); | 597 this->addRect(dst); |
| 598 this->addInt(constraint); | 598 this->addInt(constraint); |
| 599 this->validate(initialOffset, size); | 599 this->validate(initialOffset, size); |
| 600 } | 600 } |
| 601 | 601 |
| 602 void SkPictureRecord::onDrawImageNine(const SkImage* img, const SkIRect& center,
const SkRect& dst, | 602 void SkPictureRecord::onDrawImageNine(const SkImage* img, const SkIRect& center,
const SkRect& dst, |
| 603 const SkPaint* paint) { | 603 const SkPaint* paint) { |
| 604 // id + paint_index + image_index + center + dst | 604 // id + paint_index + image_index + center + dst |
| 605 size_t size = 3 * kUInt32Size + sizeof(SkIRect) + sizeof(SkRect); | 605 size_t size = 3 * kUInt32Size + sizeof(SkIRect) + sizeof(SkRect); |
| 606 | 606 |
| 607 size_t initialOffset = this->addDraw(DRAW_IMAGE_NINE, &size); | 607 size_t initialOffset = this->addDraw(DRAW_IMAGE_NINE, &size); |
| 608 SkASSERT(initialOffset+get_paint_offset(DRAW_IMAGE_NINE, size) == fWriter.by
tesWritten()); | 608 SkASSERT(initialOffset+get_paint_offset(DRAW_IMAGE_NINE, size) == fWriter.by
tesWritten()); |
| 609 this->addPaintPtr(paint); | 609 this->addPaintPtr(paint); |
| 610 this->addImage(img); | 610 this->addImage(img); |
| 611 this->addIRect(center); | 611 this->addIRect(center); |
| 612 this->addRect(dst); | 612 this->addRect(dst); |
| 613 this->validate(initialOffset, size); | 613 this->validate(initialOffset, size); |
| 614 } | 614 } |
| 615 | 615 |
| 616 void SkPictureRecord::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& ce
nter, | 616 void SkPictureRecord::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& ce
nter, |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 uint32_t flags = 0; | 856 uint32_t flags = 0; |
| 857 if (colors) { | 857 if (colors) { |
| 858 flags |= DRAW_ATLAS_HAS_COLORS; | 858 flags |= DRAW_ATLAS_HAS_COLORS; |
| 859 size += count * sizeof(SkColor); | 859 size += count * sizeof(SkColor); |
| 860 size += sizeof(uint32_t); // xfermode::mode | 860 size += sizeof(uint32_t); // xfermode::mode |
| 861 } | 861 } |
| 862 if (cull) { | 862 if (cull) { |
| 863 flags |= DRAW_ATLAS_HAS_CULL; | 863 flags |= DRAW_ATLAS_HAS_CULL; |
| 864 size += sizeof(SkRect); | 864 size += sizeof(SkRect); |
| 865 } | 865 } |
| 866 | 866 |
| 867 size_t initialOffset = this->addDraw(DRAW_ATLAS, &size); | 867 size_t initialOffset = this->addDraw(DRAW_ATLAS, &size); |
| 868 SkASSERT(initialOffset+get_paint_offset(DRAW_ATLAS, size) == fWriter.bytesWr
itten()); | 868 SkASSERT(initialOffset+get_paint_offset(DRAW_ATLAS, size) == fWriter.bytesWr
itten()); |
| 869 this->addPaintPtr(paint); | 869 this->addPaintPtr(paint); |
| 870 this->addImage(atlas); | 870 this->addImage(atlas); |
| 871 this->addInt(flags); | 871 this->addInt(flags); |
| 872 this->addInt(count); | 872 this->addInt(count); |
| 873 fWriter.write(xform, count * sizeof(SkRSXform)); | 873 fWriter.write(xform, count * sizeof(SkRSXform)); |
| 874 fWriter.write(tex, count * sizeof(SkRect)); | 874 fWriter.write(tex, count * sizeof(SkRect)); |
| 875 | 875 |
| 876 // write optional parameters | 876 // write optional parameters |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 980 | 980 |
| 981 if (paint) { | 981 if (paint) { |
| 982 fPaints.push_back(*paint); | 982 fPaints.push_back(*paint); |
| 983 this->addInt(fPaints.count()); | 983 this->addInt(fPaints.count()); |
| 984 } else { | 984 } else { |
| 985 this->addInt(0); | 985 this->addInt(0); |
| 986 } | 986 } |
| 987 } | 987 } |
| 988 | 988 |
| 989 int SkPictureRecord::addPathToHeap(const SkPath& path) { | 989 int SkPictureRecord::addPathToHeap(const SkPath& path) { |
| 990 fPaths.push_back(path); | 990 if (int* n = fPaths.find(path)) { |
| 991 return fPaths.count(); | 991 return *n; |
| 992 } |
| 993 int n = fPaths.count() + 1; // 0 is reserved for null / error. |
| 994 fPaths.set(path, n); |
| 995 return n; |
| 992 } | 996 } |
| 993 | 997 |
| 994 void SkPictureRecord::addPath(const SkPath& path) { | 998 void SkPictureRecord::addPath(const SkPath& path) { |
| 995 this->addInt(this->addPathToHeap(path)); | 999 this->addInt(this->addPathToHeap(path)); |
| 996 } | 1000 } |
| 997 | 1001 |
| 998 void SkPictureRecord::addPatch(const SkPoint cubics[12]) { | 1002 void SkPictureRecord::addPatch(const SkPoint cubics[12]) { |
| 999 fWriter.write(cubics, SkPatchUtils::kNumCtrlPts * sizeof(SkPoint)); | 1003 fWriter.write(cubics, SkPatchUtils::kNumCtrlPts * sizeof(SkPoint)); |
| 1000 } | 1004 } |
| 1001 | 1005 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1060 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { | 1064 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { |
| 1061 int index = fTextBlobRefs.count(); | 1065 int index = fTextBlobRefs.count(); |
| 1062 *fTextBlobRefs.append() = blob; | 1066 *fTextBlobRefs.append() = blob; |
| 1063 blob->ref(); | 1067 blob->ref(); |
| 1064 // follow the convention of recording a 1-based index | 1068 // follow the convention of recording a 1-based index |
| 1065 this->addInt(index + 1); | 1069 this->addInt(index + 1); |
| 1066 } | 1070 } |
| 1067 | 1071 |
| 1068 /////////////////////////////////////////////////////////////////////////////// | 1072 /////////////////////////////////////////////////////////////////////////////// |
| 1069 | 1073 |
| OLD | NEW |