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

Side by Side Diff: src/core/SkPictureFlat.cpp

Issue 123213004: Function pointers -> templates in SkPictureFlat. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: align storage Created 6 years, 11 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/core/SkPictureFlat.h ('k') | src/core/SkPicturePlayback.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 #include "SkPictureFlat.h" 8 #include "SkPictureFlat.h"
9 9
10 #include "SkChecksum.h" 10 #include "SkChecksum.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 83
84 void SkFlatController::setTypefacePlayback(SkTypefacePlayback* playback) { 84 void SkFlatController::setTypefacePlayback(SkTypefacePlayback* playback) {
85 fTypefacePlayback = playback; 85 fTypefacePlayback = playback;
86 } 86 }
87 87
88 SkNamedFactorySet* SkFlatController::setNamedFactorySet(SkNamedFactorySet* set) { 88 SkNamedFactorySet* SkFlatController::setNamedFactorySet(SkNamedFactorySet* set) {
89 SkRefCnt_SafeAssign(fFactorySet, set); 89 SkRefCnt_SafeAssign(fFactorySet, set);
90 return set; 90 return set;
91 } 91 }
92 92
93 ///////////////////////////////////////////////////////////////////////////////
94
95 SkFlatData* SkFlatData::Create(SkFlatController* controller,
96 const void* obj,
97 int index,
98 void (*flattenProc)(SkOrderedWriteBuffer&, const void*)) {
99 // a buffer of 256 bytes should be sufficient for most paints, regions,
100 // and matrices.
101 intptr_t storage[256];
102 SkOrderedWriteBuffer buffer(256, storage, sizeof(storage));
103
104 buffer.setBitmapHeap(controller->getBitmapHeap());
105 buffer.setTypefaceRecorder(controller->getTypefaceSet());
106 buffer.setNamedFactoryRecorder(controller->getNamedFactorySet());
107 buffer.setFlags(controller->getWriteBufferFlags());
108
109 flattenProc(buffer, obj);
110 uint32_t size = buffer.size();
111 SkASSERT(SkIsAlign4(size));
112
113 // Allocate enough memory to hold SkFlatData struct and the flat data itself .
114 size_t allocSize = sizeof(SkFlatData) + size;
115 SkFlatData* result = (SkFlatData*) controller->allocThrow(allocSize);
116
117 // Put the serialized contents into the data section of the new allocation.
118 buffer.writeToMemory(result->data());
119 // Stamp the index, size and checksum in the header.
120 result->stampHeader(index, size);
121 return result;
122 }
123
124 void SkFlatData::unflatten(void* result,
125 void (*unflattenProc)(SkOrderedReadBuffer&, void*),
126 SkBitmapHeap* bitmapHeap,
127 SkTypefacePlayback* facePlayback) const {
128
129 SkOrderedReadBuffer buffer(this->data(), fFlatSize);
130
131 if (bitmapHeap) {
132 buffer.setBitmapStorage(bitmapHeap);
133 }
134 if (facePlayback) {
135 facePlayback->setupBuffer(buffer);
136 }
137
138 unflattenProc(buffer, result);
139 SkASSERT(fFlatSize == (int32_t)buffer.offset());
140 }
OLDNEW
« no previous file with comments | « src/core/SkPictureFlat.h ('k') | src/core/SkPicturePlayback.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698