| 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" | 
| 11 #include "SkPatchUtils.h" | 11 #include "SkPatchUtils.h" | 
| 12 #include "SkPixelRef.h" | 12 #include "SkPixelRef.h" | 
| 13 #include "SkRRect.h" | 13 #include "SkRRect.h" | 
|  | 14 #include "SkRSXform.h" | 
| 14 #include "SkTextBlob.h" | 15 #include "SkTextBlob.h" | 
| 15 #include "SkTSearch.h" | 16 #include "SkTSearch.h" | 
| 16 | 17 | 
| 17 #define HEAP_BLOCK_SIZE 4096 | 18 #define HEAP_BLOCK_SIZE 4096 | 
| 18 | 19 | 
| 19 enum { | 20 enum { | 
| 20     // just need a value that save or getSaveCount would never return | 21     // just need a value that save or getSaveCount would never return | 
| 21     kNoInitialSave = -1, | 22     kNoInitialSave = -1, | 
| 22 }; | 23 }; | 
| 23 | 24 | 
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 92         0,  // COMMENT - no paint | 93         0,  // COMMENT - no paint | 
| 93         0,  // END_GROUP - no paint | 94         0,  // END_GROUP - no paint | 
| 94         1,  // DRAWDRRECT - right after op code | 95         1,  // DRAWDRRECT - right after op code | 
| 95         0,  // PUSH_CULL - no paint | 96         0,  // PUSH_CULL - no paint | 
| 96         0,  // POP_CULL - no paint | 97         0,  // POP_CULL - no paint | 
| 97         1,  // DRAW_PATCH - right after op code | 98         1,  // DRAW_PATCH - right after op code | 
| 98         1,  // DRAW_PICTURE_MATRIX_PAINT - right after op code | 99         1,  // DRAW_PICTURE_MATRIX_PAINT - right after op code | 
| 99         1,  // DRAW_TEXT_BLOB- right after op code | 100         1,  // DRAW_TEXT_BLOB- right after op code | 
| 100         1,  // DRAW_IMAGE - right after op code | 101         1,  // DRAW_IMAGE - right after op code | 
| 101         1,  // DRAW_IMAGE_RECT - right after op code | 102         1,  // DRAW_IMAGE_RECT - right after op code | 
|  | 103         1,  // DRAW_ATLAS - right after op code | 
| 102     }; | 104     }; | 
| 103 | 105 | 
| 104     SK_COMPILE_ASSERT(sizeof(gPaintOffsets) == LAST_DRAWTYPE_ENUM + 1, | 106     SK_COMPILE_ASSERT(sizeof(gPaintOffsets) == LAST_DRAWTYPE_ENUM + 1, | 
| 105                       need_to_be_in_sync); | 107                       need_to_be_in_sync); | 
| 106     SkASSERT((unsigned)op <= (unsigned)LAST_DRAWTYPE_ENUM); | 108     SkASSERT((unsigned)op <= (unsigned)LAST_DRAWTYPE_ENUM); | 
| 107 | 109 | 
| 108     int overflow = 0; | 110     int overflow = 0; | 
| 109     if (0 != (opSize & ~MASK_24) || opSize == MASK_24) { | 111     if (0 != (opSize & ~MASK_24) || opSize == MASK_24) { | 
| 110         // This op's size overflows so an extra uint32_t will be written | 112         // This op's size overflows so an extra uint32_t will be written | 
| 111         // after the op code | 113         // after the op code | 
| (...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 827         fWriter.write(texCoords, SkPatchUtils::kNumCorners * sizeof(SkPoint)); | 829         fWriter.write(texCoords, SkPatchUtils::kNumCorners * sizeof(SkPoint)); | 
| 828     } | 830     } | 
| 829     if (flag & DRAW_VERTICES_HAS_XFER) { | 831     if (flag & DRAW_VERTICES_HAS_XFER) { | 
| 830         SkXfermode::Mode mode = SkXfermode::kModulate_Mode; | 832         SkXfermode::Mode mode = SkXfermode::kModulate_Mode; | 
| 831         xmode->asMode(&mode); | 833         xmode->asMode(&mode); | 
| 832         this->addInt(mode); | 834         this->addInt(mode); | 
| 833     } | 835     } | 
| 834     this->validate(initialOffset, size); | 836     this->validate(initialOffset, size); | 
| 835 } | 837 } | 
| 836 | 838 | 
|  | 839 void SkPictureRecord::onDrawAtlas(const SkImage* atlas, const SkRSXform xform[],
       const SkRect tex[], | 
|  | 840                                   const SkColor colors[], int count, SkXfermode:
      :Mode mode, | 
|  | 841                                   const SkRect* cull, const SkPaint* paint) { | 
|  | 842     // [op + paint-index + atlas-index + flags + count] + [xform] + [tex] + [*co
      lors + mode] + cull | 
|  | 843     size_t size = 5 * kUInt32Size + count * sizeof(SkRSXform) + count * sizeof(S
      kRect); | 
|  | 844     uint32_t flags = 0; | 
|  | 845     if (colors) { | 
|  | 846         flags |= DRAW_ATLAS_HAS_COLORS; | 
|  | 847         size += count * sizeof(SkColor); | 
|  | 848         size += sizeof(uint32_t);   // xfermode::mode | 
|  | 849     } | 
|  | 850     if (cull) { | 
|  | 851         flags |= DRAW_ATLAS_HAS_CULL; | 
|  | 852         size += sizeof(SkRect); | 
|  | 853     } | 
|  | 854 | 
|  | 855     size_t initialOffset = this->addDraw(DRAW_ATLAS, &size); | 
|  | 856     SkASSERT(initialOffset+get_paint_offset(DRAW_ATLAS, size) == fWriter.bytesWr
      itten()); | 
|  | 857     this->addPaintPtr(paint); | 
|  | 858     this->addImage(atlas); | 
|  | 859     this->addInt(flags); | 
|  | 860     this->addInt(count); | 
|  | 861     fWriter.write(xform, count * sizeof(SkRSXform)); | 
|  | 862     fWriter.write(tex, count * sizeof(SkRect)); | 
|  | 863 | 
|  | 864     // write optional parameters | 
|  | 865     if (colors) { | 
|  | 866         fWriter.write(colors, count * sizeof(SkColor)); | 
|  | 867         this->addInt(mode); | 
|  | 868     } | 
|  | 869     if (cull) { | 
|  | 870         fWriter.write(cull, sizeof(SkRect)); | 
|  | 871     } | 
|  | 872     this->validate(initialOffset, size); | 
|  | 873 } | 
|  | 874 | 
| 837 /////////////////////////////////////////////////////////////////////////////// | 875 /////////////////////////////////////////////////////////////////////////////// | 
| 838 | 876 | 
| 839 SkSurface* SkPictureRecord::onNewSurface(const SkImageInfo& info, const SkSurfac
      eProps&) { | 877 SkSurface* SkPictureRecord::onNewSurface(const SkImageInfo& info, const SkSurfac
      eProps&) { | 
| 840     return NULL; | 878     return NULL; | 
| 841 } | 879 } | 
| 842 | 880 | 
| 843 // If we already have a stored, can we reuse it instead of also storing b? | 881 // If we already have a stored, can we reuse it instead of also storing b? | 
| 844 static bool equivalent(const SkBitmap& a, const SkBitmap& b) { | 882 static bool equivalent(const SkBitmap& a, const SkBitmap& b) { | 
| 845     if (a.info() != b.info() || a.pixelRefOrigin() != b.pixelRefOrigin()) { | 883     if (a.info() != b.info() || a.pixelRefOrigin() != b.pixelRefOrigin()) { | 
| 846         // Requiring a.info() == b.info() may be overkill in some cases (alphaty
      pe mismatch), | 884         // Requiring a.info() == b.info() may be overkill in some cases (alphaty
      pe mismatch), | 
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1010 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { | 1048 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { | 
| 1011     int index = fTextBlobRefs.count(); | 1049     int index = fTextBlobRefs.count(); | 
| 1012     *fTextBlobRefs.append() = blob; | 1050     *fTextBlobRefs.append() = blob; | 
| 1013     blob->ref(); | 1051     blob->ref(); | 
| 1014     // follow the convention of recording a 1-based index | 1052     // follow the convention of recording a 1-based index | 
| 1015     this->addInt(index + 1); | 1053     this->addInt(index + 1); | 
| 1016 } | 1054 } | 
| 1017 | 1055 | 
| 1018 /////////////////////////////////////////////////////////////////////////////// | 1056 /////////////////////////////////////////////////////////////////////////////// | 
| 1019 | 1057 | 
| OLD | NEW | 
|---|