Chromium Code Reviews| 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 "SkImage_Base.h" | 9 #include "SkImage_Base.h" |
| 10 #include "SkPatchUtils.h" | 10 #include "SkPatchUtils.h" |
| (...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 860 | 860 |
| 861 size_t initialOffset = this->addDraw(DRAW_ANNOTATION, &size); | 861 size_t initialOffset = this->addDraw(DRAW_ANNOTATION, &size); |
| 862 this->addRect(rect); | 862 this->addRect(rect); |
| 863 fWriter.writeString(key); | 863 fWriter.writeString(key); |
| 864 fWriter.writeData(value); | 864 fWriter.writeData(value); |
| 865 this->validate(initialOffset, size); | 865 this->validate(initialOffset, size); |
| 866 } | 866 } |
| 867 | 867 |
| 868 /////////////////////////////////////////////////////////////////////////////// | 868 /////////////////////////////////////////////////////////////////////////////// |
| 869 | 869 |
| 870 template <typename T> int find_or_append_uniqueID(SkTDArray<const T*>& array, co nst T* obj) { | |
| 871 int index = array.select([&](const T* elem) { | |
| 872 return elem->uniqueID() == obj->uniqueID(); | |
| 873 }); | |
| 874 if (index < 0) { | |
| 875 index = array.count(); | |
|
mtklein
2016/08/29 14:34:46
Seems like we could return count instead of -1, so
reed1
2016/08/29 14:41:26
That would make this site a tiny bit simpler, but
| |
| 876 *array.append() = SkRef(obj); | |
| 877 } | |
| 878 return index; | |
| 879 } | |
| 880 | |
| 870 sk_sp<SkSurface> SkPictureRecord::onNewSurface(const SkImageInfo& info, const Sk SurfaceProps&) { | 881 sk_sp<SkSurface> SkPictureRecord::onNewSurface(const SkImageInfo& info, const Sk SurfaceProps&) { |
| 871 return nullptr; | 882 return nullptr; |
| 872 } | 883 } |
| 873 | 884 |
| 874 void SkPictureRecord::addImage(const SkImage* image) { | 885 void SkPictureRecord::addImage(const SkImage* image) { |
| 875 int index = fImageRefs.find(image); | 886 // convention for images is 0-based index |
| 876 if (index >= 0) { | 887 this->addInt(find_or_append_uniqueID(fImageRefs, image)); |
| 877 this->addInt(index); | |
| 878 } else { | |
| 879 *fImageRefs.append() = SkRef(image); | |
| 880 this->addInt(fImageRefs.count()-1); | |
| 881 } | |
| 882 } | 888 } |
| 883 | 889 |
| 884 void SkPictureRecord::addMatrix(const SkMatrix& matrix) { | 890 void SkPictureRecord::addMatrix(const SkMatrix& matrix) { |
| 885 fWriter.writeMatrix(matrix); | 891 fWriter.writeMatrix(matrix); |
| 886 } | 892 } |
| 887 | 893 |
| 888 void SkPictureRecord::addPaintPtr(const SkPaint* paint) { | 894 void SkPictureRecord::addPaintPtr(const SkPaint* paint) { |
| 889 fContentInfo.onAddPaintPtr(paint); | 895 fContentInfo.onAddPaintPtr(paint); |
| 890 | 896 |
| 891 if (paint) { | 897 if (paint) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 907 | 913 |
| 908 void SkPictureRecord::addPath(const SkPath& path) { | 914 void SkPictureRecord::addPath(const SkPath& path) { |
| 909 this->addInt(this->addPathToHeap(path)); | 915 this->addInt(this->addPathToHeap(path)); |
| 910 } | 916 } |
| 911 | 917 |
| 912 void SkPictureRecord::addPatch(const SkPoint cubics[12]) { | 918 void SkPictureRecord::addPatch(const SkPoint cubics[12]) { |
| 913 fWriter.write(cubics, SkPatchUtils::kNumCtrlPts * sizeof(SkPoint)); | 919 fWriter.write(cubics, SkPatchUtils::kNumCtrlPts * sizeof(SkPoint)); |
| 914 } | 920 } |
| 915 | 921 |
| 916 void SkPictureRecord::addPicture(const SkPicture* picture) { | 922 void SkPictureRecord::addPicture(const SkPicture* picture) { |
| 917 int index = fPictureRefs.find(picture); | |
| 918 if (index < 0) { // not found | |
| 919 index = fPictureRefs.count(); | |
| 920 *fPictureRefs.append() = picture; | |
| 921 picture->ref(); | |
| 922 } | |
| 923 // follow the convention of recording a 1-based index | 923 // follow the convention of recording a 1-based index |
| 924 this->addInt(index + 1); | 924 this->addInt(find_or_append_uniqueID(fPictureRefs, picture) + 1); |
| 925 } | 925 } |
| 926 | 926 |
| 927 void SkPictureRecord::addDrawable(SkDrawable* drawable) { | 927 void SkPictureRecord::addDrawable(SkDrawable* drawable) { |
| 928 int index = fDrawableRefs.find(drawable); | 928 int index = fDrawableRefs.find(drawable); |
| 929 if (index < 0) { // not found | 929 if (index < 0) { // not found |
| 930 index = fDrawableRefs.count(); | 930 index = fDrawableRefs.count(); |
| 931 *fDrawableRefs.append() = drawable; | 931 *fDrawableRefs.append() = drawable; |
| 932 drawable->ref(); | 932 drawable->ref(); |
| 933 } | 933 } |
| 934 // follow the convention of recording a 1-based index | 934 // follow the convention of recording a 1-based index |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 975 void SkPictureRecord::addRegion(const SkRegion& region) { | 975 void SkPictureRecord::addRegion(const SkRegion& region) { |
| 976 fWriter.writeRegion(region); | 976 fWriter.writeRegion(region); |
| 977 } | 977 } |
| 978 | 978 |
| 979 void SkPictureRecord::addText(const void* text, size_t byteLength) { | 979 void SkPictureRecord::addText(const void* text, size_t byteLength) { |
| 980 fContentInfo.onDrawText(); | 980 fContentInfo.onDrawText(); |
| 981 addInt(SkToInt(byteLength)); | 981 addInt(SkToInt(byteLength)); |
| 982 fWriter.writePad(text, byteLength); | 982 fWriter.writePad(text, byteLength); |
| 983 } | 983 } |
| 984 | 984 |
| 985 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { | 985 void SkPictureRecord::addTextBlob(const SkTextBlob* blob) { |
| 986 int index = fTextBlobRefs.count(); | |
| 987 *fTextBlobRefs.append() = blob; | |
| 988 blob->ref(); | |
| 989 // follow the convention of recording a 1-based index | 986 // follow the convention of recording a 1-based index |
| 990 this->addInt(index + 1); | 987 this->addInt(find_or_append_uniqueID(fTextBlobRefs, blob) + 1); |
| 991 } | 988 } |
| 992 | 989 |
| 993 /////////////////////////////////////////////////////////////////////////////// | 990 /////////////////////////////////////////////////////////////////////////////// |
| OLD | NEW |