OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkBitmapHeap.h" | 10 #include "SkBitmapHeap.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 * Needed to be a non-abstract subclass of SkBitmapHeapReader. | 171 * Needed to be a non-abstract subclass of SkBitmapHeapReader. |
172 */ | 172 */ |
173 void releaseRef(int32_t) override {} | 173 void releaseRef(int32_t) override {} |
174 | 174 |
175 void setSharedHeap(SkBitmapHeap* heap) { | 175 void setSharedHeap(SkBitmapHeap* heap) { |
176 SkASSERT(!shouldFlattenBitmaps(fFlags) || NULL == heap); | 176 SkASSERT(!shouldFlattenBitmaps(fFlags) || NULL == heap); |
177 SkRefCnt_SafeAssign(fSharedHeap, heap); | 177 SkRefCnt_SafeAssign(fSharedHeap, heap); |
178 this->updateReader(); | 178 this->updateReader(); |
179 } | 179 } |
180 | 180 |
| 181 void setImageHeap(SkImageHeap* heap) { |
| 182 fImageHeap.reset(SkRef(heap)); |
| 183 } |
| 184 |
181 /** | 185 /** |
182 * Access the shared heap. Only used in the case when bitmaps are not | 186 * Access the shared heap. Only used in the case when bitmaps are not |
183 * flattened. | 187 * flattened. |
184 */ | 188 */ |
185 SkBitmapHeap* getSharedHeap() const { | 189 SkBitmapHeap* getSharedHeap() const { |
186 SkASSERT(!shouldFlattenBitmaps(fFlags)); | 190 SkASSERT(!shouldFlattenBitmaps(fFlags)); |
187 return fSharedHeap; | 191 return fSharedHeap; |
188 } | 192 } |
189 | 193 |
190 void addTypeface() { | 194 void addTypeface() { |
191 size_t size = fReader->read32(); | 195 size_t size = fReader->read32(); |
192 const void* data = fReader->skip(SkAlign4(size)); | 196 const void* data = fReader->skip(SkAlign4(size)); |
193 SkMemoryStream stream(data, size, false); | 197 SkMemoryStream stream(data, size, false); |
194 *fTypefaces.append() = SkTypeface::Deserialize(&stream); | 198 *fTypefaces.append() = SkTypeface::Deserialize(&stream); |
195 } | 199 } |
196 | 200 |
197 SkTypeface* getTypeface(unsigned id) const { | 201 SkTypeface* getTypeface(unsigned id) const { |
198 return id ? fTypefaces[id - 1] : NULL; | 202 return id ? fTypefaces[id - 1] : NULL; |
199 } | 203 } |
200 | 204 |
| 205 const SkImage* getImage(int32_t slot) const { |
| 206 return fImageHeap->get(slot); |
| 207 } |
| 208 |
201 private: | 209 private: |
202 void updateReader() { | 210 void updateReader() { |
203 if (NULL == fReader) { | 211 if (NULL == fReader) { |
204 return; | 212 return; |
205 } | 213 } |
206 bool crossProcess = SkToBool(fFlags & SkGPipeWriter::kCrossProcess_Flag)
; | 214 bool crossProcess = SkToBool(fFlags & SkGPipeWriter::kCrossProcess_Flag)
; |
207 fReader->setFlags(SkSetClearMask(fReader->getFlags(), crossProcess, | 215 fReader->setFlags(SkSetClearMask(fReader->getFlags(), crossProcess, |
208 SkReadBuffer::kCrossProcess_Flag)); | 216 SkReadBuffer::kCrossProcess_Flag)); |
209 if (crossProcess) { | 217 if (crossProcess) { |
210 fReader->setFactoryArray(&fFactoryArray); | 218 fReader->setFactoryArray(&fFactoryArray); |
211 } else { | 219 } else { |
212 fReader->setFactoryArray(NULL); | 220 fReader->setFactoryArray(NULL); |
213 } | 221 } |
214 | 222 |
215 if (shouldFlattenBitmaps(fFlags)) { | 223 if (shouldFlattenBitmaps(fFlags)) { |
216 fReader->setBitmapStorage(this); | 224 fReader->setBitmapStorage(this); |
217 } else { | 225 } else { |
218 fReader->setBitmapStorage(fSharedHeap); | 226 fReader->setBitmapStorage(fSharedHeap); |
219 } | 227 } |
220 } | 228 } |
221 SkReadBuffer* fReader; | 229 SkReadBuffer* fReader; |
222 SkPaint fPaint; | 230 SkPaint fPaint; |
223 SkTDArray<SkFlattenable*> fFlatArray; | 231 SkTDArray<SkFlattenable*> fFlatArray; |
224 SkTDArray<SkTypeface*> fTypefaces; | 232 SkTDArray<SkTypeface*> fTypefaces; |
225 SkTDArray<SkFlattenable::Factory> fFactoryArray; | 233 SkTDArray<SkFlattenable::Factory> fFactoryArray; |
226 SkTDArray<SkBitmap*> fBitmaps; | 234 SkTDArray<SkBitmap*> fBitmaps; |
227 bool fSilent; | 235 bool fSilent; |
228 // Only used when sharing bitmaps with the writer. | 236 // Only used when sharing bitmaps with the writer. |
229 SkBitmapHeap* fSharedHeap; | 237 SkBitmapHeap* fSharedHeap; |
| 238 SkAutoTUnref<SkImageHeap> fImageHeap; |
230 unsigned fFlags; | 239 unsigned fFlags; |
231 }; | 240 }; |
232 | 241 |
233 /////////////////////////////////////////////////////////////////////////////// | 242 /////////////////////////////////////////////////////////////////////////////// |
234 | 243 |
235 template <typename T> const T* skip(SkReader32* reader, size_t count = 1) { | 244 template <typename T> const T* skip(SkReader32* reader, size_t count = 1) { |
236 size_t size = sizeof(T) * count; | 245 size_t size = sizeof(T) * count; |
237 SkASSERT(SkAlign4(size) == size); | 246 SkASSERT(SkAlign4(size) == size); |
238 return reinterpret_cast<const T*>(reader->skip(size)); | 247 return reinterpret_cast<const T*>(reader->skip(size)); |
239 } | 248 } |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 SkGPipeState* state) { | 631 SkGPipeState* state) { |
623 BitmapHolder holder(reader, op32, state); | 632 BitmapHolder holder(reader, op32, state); |
624 bool hasPaint = SkToBool(DrawOp_unpackFlags(op32) & kDrawBitmap_HasPaint_Dra
wOpFlag); | 633 bool hasPaint = SkToBool(DrawOp_unpackFlags(op32) & kDrawBitmap_HasPaint_Dra
wOpFlag); |
625 const SkIPoint* point = skip<SkIPoint>(reader); | 634 const SkIPoint* point = skip<SkIPoint>(reader); |
626 const SkBitmap* bitmap = holder.getBitmap(); | 635 const SkBitmap* bitmap = holder.getBitmap(); |
627 if (state->shouldDraw()) { | 636 if (state->shouldDraw()) { |
628 canvas->drawSprite(*bitmap, point->fX, point->fY, hasPaint ? &state->pai
nt() : NULL); | 637 canvas->drawSprite(*bitmap, point->fX, point->fY, hasPaint ? &state->pai
nt() : NULL); |
629 } | 638 } |
630 } | 639 } |
631 | 640 |
| 641 static void drawImage_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, Sk
GPipeState* state) { |
| 642 unsigned slot = DrawOp_unpackData(op32); |
| 643 unsigned flags = DrawOp_unpackFlags(op32); |
| 644 bool hasPaint = SkToBool(flags & kDrawBitmap_HasPaint_DrawOpFlag); |
| 645 SkScalar x = reader->readScalar(); |
| 646 SkScalar y = reader->readScalar(); |
| 647 const SkImage* image = state->getImage(slot); |
| 648 if (state->shouldDraw()) { |
| 649 canvas->drawImage(image, x, y, hasPaint ? &state->paint() : NULL); |
| 650 } |
| 651 } |
| 652 |
| 653 static void drawImageRect_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32
, |
| 654 SkGPipeState* state) { |
| 655 unsigned slot = DrawOp_unpackData(op32); |
| 656 unsigned flags = DrawOp_unpackFlags(op32); |
| 657 bool hasPaint = SkToBool(flags & kDrawBitmap_HasPaint_DrawOpFlag); |
| 658 bool hasSrc = SkToBool(flags & kDrawBitmap_HasSrcRect_DrawOpFlag); |
| 659 const SkRect* src = NULL; |
| 660 if (hasSrc) { |
| 661 src = skip<SkRect>(reader); |
| 662 } |
| 663 const SkRect* dst = skip<SkRect>(reader); |
| 664 const SkImage* image = state->getImage(slot); |
| 665 if (state->shouldDraw()) { |
| 666 canvas->drawImageRect(image, src, *dst, hasPaint ? &state->paint() : NUL
L); |
| 667 } |
| 668 } |
| 669 |
632 /////////////////////////////////////////////////////////////////////////////// | 670 /////////////////////////////////////////////////////////////////////////////// |
633 | 671 |
634 static void drawPicture_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, | 672 static void drawPicture_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
635 SkGPipeState* state) { | 673 SkGPipeState* state) { |
636 UNIMPLEMENTED | 674 UNIMPLEMENTED |
637 } | 675 } |
638 | 676 |
639 static void drawTextBlob_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, | 677 static void drawTextBlob_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
640 SkGPipeState* state) { | 678 SkGPipeState* state) { |
641 SkScalar x = reader->readScalar(); | 679 SkScalar x = reader->readScalar(); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 (void)reader->skip(bytes); | 805 (void)reader->skip(bytes); |
768 } | 806 } |
769 | 807 |
770 static void reportFlags_rp(SkCanvas*, SkReader32*, uint32_t op32, | 808 static void reportFlags_rp(SkCanvas*, SkReader32*, uint32_t op32, |
771 SkGPipeState* state) { | 809 SkGPipeState* state) { |
772 unsigned flags = DrawOp_unpackFlags(op32); | 810 unsigned flags = DrawOp_unpackFlags(op32); |
773 state->setFlags(flags); | 811 state->setFlags(flags); |
774 } | 812 } |
775 | 813 |
776 static void shareBitmapHeap_rp(SkCanvas*, SkReader32* reader, uint32_t, | 814 static void shareBitmapHeap_rp(SkCanvas*, SkReader32* reader, uint32_t, |
777 SkGPipeState* state) { | 815 SkGPipeState* state) { |
778 state->setSharedHeap(static_cast<SkBitmapHeap*>(reader->readPtr())); | 816 state->setSharedHeap(static_cast<SkBitmapHeap*>(reader->readPtr())); |
779 } | 817 } |
780 | 818 |
| 819 static void shareImageHeap_rp(SkCanvas*, SkReader32* reader, uint32_t, SkGPipeSt
ate* state) { |
| 820 state->setImageHeap(static_cast<SkImageHeap*>(reader->readPtr())); |
| 821 } |
| 822 |
781 static void done_rp(SkCanvas*, SkReader32*, uint32_t, SkGPipeState*) {} | 823 static void done_rp(SkCanvas*, SkReader32*, uint32_t, SkGPipeState*) {} |
782 | 824 |
783 typedef void (*ReadProc)(SkCanvas*, SkReader32*, uint32_t op32, SkGPipeState*); | 825 typedef void (*ReadProc)(SkCanvas*, SkReader32*, uint32_t op32, SkGPipeState*); |
784 | 826 |
785 static const ReadProc gReadTable[] = { | 827 static const ReadProc gReadTable[] = { |
786 skip_rp, | 828 skip_rp, |
787 clipPath_rp, | 829 clipPath_rp, |
788 clipRegion_rp, | 830 clipRegion_rp, |
789 clipRect_rp, | 831 clipRect_rp, |
790 clipRRect_rp, | 832 clipRRect_rp, |
791 concat_rp, | 833 concat_rp, |
792 drawBitmap_rp, | 834 drawBitmap_rp, |
793 drawBitmapNine_rp, | 835 drawBitmapNine_rp, |
794 drawBitmapRect_rp, | 836 drawBitmapRect_rp, |
795 drawDRRect_rp, | 837 drawDRRect_rp, |
| 838 drawImage_rp, |
| 839 drawImageRect_rp, |
796 drawOval_rp, | 840 drawOval_rp, |
797 drawPaint_rp, | 841 drawPaint_rp, |
798 drawPatch_rp, | 842 drawPatch_rp, |
799 drawPath_rp, | 843 drawPath_rp, |
800 drawPicture_rp, | 844 drawPicture_rp, |
801 drawPoints_rp, | 845 drawPoints_rp, |
802 drawPosText_rp, | 846 drawPosText_rp, |
803 drawPosTextH_rp, | 847 drawPosTextH_rp, |
804 drawRect_rp, | 848 drawRect_rp, |
805 drawRRect_rp, | 849 drawRRect_rp, |
(...skipping 15 matching lines...) Expand all Loading... |
821 typeface_rp, | 865 typeface_rp, |
822 annotation_rp, | 866 annotation_rp, |
823 | 867 |
824 def_Typeface_rp, | 868 def_Typeface_rp, |
825 def_PaintFlat_rp, | 869 def_PaintFlat_rp, |
826 def_Bitmap_rp, | 870 def_Bitmap_rp, |
827 def_Factory_rp, | 871 def_Factory_rp, |
828 | 872 |
829 reportFlags_rp, | 873 reportFlags_rp, |
830 shareBitmapHeap_rp, | 874 shareBitmapHeap_rp, |
| 875 shareImageHeap_rp, |
831 done_rp | 876 done_rp |
832 }; | 877 }; |
833 | 878 |
834 /////////////////////////////////////////////////////////////////////////////// | 879 /////////////////////////////////////////////////////////////////////////////// |
835 | 880 |
836 SkGPipeState::SkGPipeState() | 881 SkGPipeState::SkGPipeState() |
837 : fReader(0) | 882 : fReader(0) |
838 , fSilent(false) | 883 , fSilent(false) |
839 , fSharedHeap(NULL) | 884 , fSharedHeap(NULL) |
840 , fFlags(0) { | 885 , fFlags(0) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
919 status = kReadAtom_Status; | 964 status = kReadAtom_Status; |
920 break; | 965 break; |
921 } | 966 } |
922 } | 967 } |
923 | 968 |
924 if (bytesRead) { | 969 if (bytesRead) { |
925 *bytesRead = reader.offset(); | 970 *bytesRead = reader.offset(); |
926 } | 971 } |
927 return status; | 972 return status; |
928 } | 973 } |
OLD | NEW |