Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/pipe/SkGPipeRead.cpp

Issue 1127993004: Revert of Revert of Revert of Make drawImage a virtual on SkDevice (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pipe/SkGPipePriv.h ('k') | src/pipe/SkGPipeWrite.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
185 /** 181 /**
186 * Access the shared heap. Only used in the case when bitmaps are not 182 * Access the shared heap. Only used in the case when bitmaps are not
187 * flattened. 183 * flattened.
188 */ 184 */
189 SkBitmapHeap* getSharedHeap() const { 185 SkBitmapHeap* getSharedHeap() const {
190 SkASSERT(!shouldFlattenBitmaps(fFlags)); 186 SkASSERT(!shouldFlattenBitmaps(fFlags));
191 return fSharedHeap; 187 return fSharedHeap;
192 } 188 }
193 189
194 void addTypeface() { 190 void addTypeface() {
195 size_t size = fReader->read32(); 191 size_t size = fReader->read32();
196 const void* data = fReader->skip(SkAlign4(size)); 192 const void* data = fReader->skip(SkAlign4(size));
197 SkMemoryStream stream(data, size, false); 193 SkMemoryStream stream(data, size, false);
198 *fTypefaces.append() = SkTypeface::Deserialize(&stream); 194 *fTypefaces.append() = SkTypeface::Deserialize(&stream);
199 } 195 }
200 196
201 SkTypeface* getTypeface(unsigned id) const { 197 SkTypeface* getTypeface(unsigned id) const {
202 return id ? fTypefaces[id - 1] : NULL; 198 return id ? fTypefaces[id - 1] : NULL;
203 } 199 }
204 200
205 const SkImage* getImage(int32_t slot) const {
206 return fImageHeap->get(slot);
207 }
208
209 private: 201 private:
210 void updateReader() { 202 void updateReader() {
211 if (NULL == fReader) { 203 if (NULL == fReader) {
212 return; 204 return;
213 } 205 }
214 bool crossProcess = SkToBool(fFlags & SkGPipeWriter::kCrossProcess_Flag) ; 206 bool crossProcess = SkToBool(fFlags & SkGPipeWriter::kCrossProcess_Flag) ;
215 fReader->setFlags(SkSetClearMask(fReader->getFlags(), crossProcess, 207 fReader->setFlags(SkSetClearMask(fReader->getFlags(), crossProcess,
216 SkReadBuffer::kCrossProcess_Flag)); 208 SkReadBuffer::kCrossProcess_Flag));
217 if (crossProcess) { 209 if (crossProcess) {
218 fReader->setFactoryArray(&fFactoryArray); 210 fReader->setFactoryArray(&fFactoryArray);
219 } else { 211 } else {
220 fReader->setFactoryArray(NULL); 212 fReader->setFactoryArray(NULL);
221 } 213 }
222 214
223 if (shouldFlattenBitmaps(fFlags)) { 215 if (shouldFlattenBitmaps(fFlags)) {
224 fReader->setBitmapStorage(this); 216 fReader->setBitmapStorage(this);
225 } else { 217 } else {
226 fReader->setBitmapStorage(fSharedHeap); 218 fReader->setBitmapStorage(fSharedHeap);
227 } 219 }
228 } 220 }
229 SkReadBuffer* fReader; 221 SkReadBuffer* fReader;
230 SkPaint fPaint; 222 SkPaint fPaint;
231 SkTDArray<SkFlattenable*> fFlatArray; 223 SkTDArray<SkFlattenable*> fFlatArray;
232 SkTDArray<SkTypeface*> fTypefaces; 224 SkTDArray<SkTypeface*> fTypefaces;
233 SkTDArray<SkFlattenable::Factory> fFactoryArray; 225 SkTDArray<SkFlattenable::Factory> fFactoryArray;
234 SkTDArray<SkBitmap*> fBitmaps; 226 SkTDArray<SkBitmap*> fBitmaps;
235 bool fSilent; 227 bool fSilent;
236 // Only used when sharing bitmaps with the writer. 228 // Only used when sharing bitmaps with the writer.
237 SkBitmapHeap* fSharedHeap; 229 SkBitmapHeap* fSharedHeap;
238 SkAutoTUnref<SkImageHeap> fImageHeap;
239 unsigned fFlags; 230 unsigned fFlags;
240 }; 231 };
241 232
242 /////////////////////////////////////////////////////////////////////////////// 233 ///////////////////////////////////////////////////////////////////////////////
243 234
244 template <typename T> const T* skip(SkReader32* reader, size_t count = 1) { 235 template <typename T> const T* skip(SkReader32* reader, size_t count = 1) {
245 size_t size = sizeof(T) * count; 236 size_t size = sizeof(T) * count;
246 SkASSERT(SkAlign4(size) == size); 237 SkASSERT(SkAlign4(size) == size);
247 return reinterpret_cast<const T*>(reader->skip(size)); 238 return reinterpret_cast<const T*>(reader->skip(size));
248 } 239 }
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 SkGPipeState* state) { 622 SkGPipeState* state) {
632 BitmapHolder holder(reader, op32, state); 623 BitmapHolder holder(reader, op32, state);
633 bool hasPaint = SkToBool(DrawOp_unpackFlags(op32) & kDrawBitmap_HasPaint_Dra wOpFlag); 624 bool hasPaint = SkToBool(DrawOp_unpackFlags(op32) & kDrawBitmap_HasPaint_Dra wOpFlag);
634 const SkIPoint* point = skip<SkIPoint>(reader); 625 const SkIPoint* point = skip<SkIPoint>(reader);
635 const SkBitmap* bitmap = holder.getBitmap(); 626 const SkBitmap* bitmap = holder.getBitmap();
636 if (state->shouldDraw()) { 627 if (state->shouldDraw()) {
637 canvas->drawSprite(*bitmap, point->fX, point->fY, hasPaint ? &state->pai nt() : NULL); 628 canvas->drawSprite(*bitmap, point->fX, point->fY, hasPaint ? &state->pai nt() : NULL);
638 } 629 }
639 } 630 }
640 631
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
670 /////////////////////////////////////////////////////////////////////////////// 632 ///////////////////////////////////////////////////////////////////////////////
671 633
672 static void drawPicture_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, 634 static void drawPicture_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32,
673 SkGPipeState* state) { 635 SkGPipeState* state) {
674 UNIMPLEMENTED 636 UNIMPLEMENTED
675 } 637 }
676 638
677 static void drawTextBlob_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, 639 static void drawTextBlob_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32,
678 SkGPipeState* state) { 640 SkGPipeState* state) {
679 SkScalar x = reader->readScalar(); 641 SkScalar x = reader->readScalar();
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 (void)reader->skip(bytes); 767 (void)reader->skip(bytes);
806 } 768 }
807 769
808 static void reportFlags_rp(SkCanvas*, SkReader32*, uint32_t op32, 770 static void reportFlags_rp(SkCanvas*, SkReader32*, uint32_t op32,
809 SkGPipeState* state) { 771 SkGPipeState* state) {
810 unsigned flags = DrawOp_unpackFlags(op32); 772 unsigned flags = DrawOp_unpackFlags(op32);
811 state->setFlags(flags); 773 state->setFlags(flags);
812 } 774 }
813 775
814 static void shareBitmapHeap_rp(SkCanvas*, SkReader32* reader, uint32_t, 776 static void shareBitmapHeap_rp(SkCanvas*, SkReader32* reader, uint32_t,
815 SkGPipeState* state) { 777 SkGPipeState* state) {
816 state->setSharedHeap(static_cast<SkBitmapHeap*>(reader->readPtr())); 778 state->setSharedHeap(static_cast<SkBitmapHeap*>(reader->readPtr()));
817 } 779 }
818 780
819 static void shareImageHeap_rp(SkCanvas*, SkReader32* reader, uint32_t, SkGPipeSt ate* state) {
820 state->setImageHeap(static_cast<SkImageHeap*>(reader->readPtr()));
821 }
822
823 static void done_rp(SkCanvas*, SkReader32*, uint32_t, SkGPipeState*) {} 781 static void done_rp(SkCanvas*, SkReader32*, uint32_t, SkGPipeState*) {}
824 782
825 typedef void (*ReadProc)(SkCanvas*, SkReader32*, uint32_t op32, SkGPipeState*); 783 typedef void (*ReadProc)(SkCanvas*, SkReader32*, uint32_t op32, SkGPipeState*);
826 784
827 static const ReadProc gReadTable[] = { 785 static const ReadProc gReadTable[] = {
828 skip_rp, 786 skip_rp,
829 clipPath_rp, 787 clipPath_rp,
830 clipRegion_rp, 788 clipRegion_rp,
831 clipRect_rp, 789 clipRect_rp,
832 clipRRect_rp, 790 clipRRect_rp,
833 concat_rp, 791 concat_rp,
834 drawBitmap_rp, 792 drawBitmap_rp,
835 drawBitmapNine_rp, 793 drawBitmapNine_rp,
836 drawBitmapRect_rp, 794 drawBitmapRect_rp,
837 drawDRRect_rp, 795 drawDRRect_rp,
838 drawImage_rp,
839 drawImageRect_rp,
840 drawOval_rp, 796 drawOval_rp,
841 drawPaint_rp, 797 drawPaint_rp,
842 drawPatch_rp, 798 drawPatch_rp,
843 drawPath_rp, 799 drawPath_rp,
844 drawPicture_rp, 800 drawPicture_rp,
845 drawPoints_rp, 801 drawPoints_rp,
846 drawPosText_rp, 802 drawPosText_rp,
847 drawPosTextH_rp, 803 drawPosTextH_rp,
848 drawRect_rp, 804 drawRect_rp,
849 drawRRect_rp, 805 drawRRect_rp,
(...skipping 15 matching lines...) Expand all
865 typeface_rp, 821 typeface_rp,
866 annotation_rp, 822 annotation_rp,
867 823
868 def_Typeface_rp, 824 def_Typeface_rp,
869 def_PaintFlat_rp, 825 def_PaintFlat_rp,
870 def_Bitmap_rp, 826 def_Bitmap_rp,
871 def_Factory_rp, 827 def_Factory_rp,
872 828
873 reportFlags_rp, 829 reportFlags_rp,
874 shareBitmapHeap_rp, 830 shareBitmapHeap_rp,
875 shareImageHeap_rp,
876 done_rp 831 done_rp
877 }; 832 };
878 833
879 /////////////////////////////////////////////////////////////////////////////// 834 ///////////////////////////////////////////////////////////////////////////////
880 835
881 SkGPipeState::SkGPipeState() 836 SkGPipeState::SkGPipeState()
882 : fReader(0) 837 : fReader(0)
883 , fSilent(false) 838 , fSilent(false)
884 , fSharedHeap(NULL) 839 , fSharedHeap(NULL)
885 , fFlags(0) { 840 , fFlags(0) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 status = kReadAtom_Status; 919 status = kReadAtom_Status;
965 break; 920 break;
966 } 921 }
967 } 922 }
968 923
969 if (bytesRead) { 924 if (bytesRead) {
970 *bytesRead = reader.offset(); 925 *bytesRead = reader.offset();
971 } 926 }
972 return status; 927 return status;
973 } 928 }
OLDNEW
« no previous file with comments | « src/pipe/SkGPipePriv.h ('k') | src/pipe/SkGPipeWrite.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698