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

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

Issue 21564008: use SkTDynamicHash in picture recording (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: er, actually, the remove i removed was necessary Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « src/core/SkPictureFlat.h ('k') | src/core/SkPictureRecord.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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 fTypefacePlayback = playback; 87 fTypefacePlayback = playback;
88 } 88 }
89 89
90 SkNamedFactorySet* SkFlatController::setNamedFactorySet(SkNamedFactorySet* set) { 90 SkNamedFactorySet* SkFlatController::setNamedFactorySet(SkNamedFactorySet* set) {
91 SkRefCnt_SafeAssign(fFactorySet, set); 91 SkRefCnt_SafeAssign(fFactorySet, set);
92 return set; 92 return set;
93 } 93 }
94 94
95 /////////////////////////////////////////////////////////////////////////////// 95 ///////////////////////////////////////////////////////////////////////////////
96 96
97 void SkFlatData::stampHeaderAndSentinel(int index, int32_t size) { 97 SkFlatData* SkFlatData::Create(SkFlatController* controller,
98 fIndex = index; 98 const void* obj,
99 fFlatSize = size; 99 int index,
100 fChecksum = SkChecksum::Compute(this->data32(), size); 100 void (*flattenProc)(SkOrderedWriteBuffer&, const void*)) {
101 this->setTopBotUnwritten();
102 this->setSentinelAsCandidate();
103 }
104
105 SkFlatData* SkFlatData::Create(SkFlatController* controller, const void* obj,
106 int index, void (*flattenProc)(SkOrderedWriteBuffer&, const void*)) {
107 // a buffer of 256 bytes should be sufficient for most paints, regions, 101 // a buffer of 256 bytes should be sufficient for most paints, regions,
108 // and matrices. 102 // and matrices.
109 intptr_t storage[256]; 103 intptr_t storage[256];
110 SkOrderedWriteBuffer buffer(256, storage, sizeof(storage)); 104 SkOrderedWriteBuffer buffer(256, storage, sizeof(storage));
111 105
112 buffer.setBitmapHeap(controller->getBitmapHeap()); 106 buffer.setBitmapHeap(controller->getBitmapHeap());
113 buffer.setTypefaceRecorder(controller->getTypefaceSet()); 107 buffer.setTypefaceRecorder(controller->getTypefaceSet());
114 buffer.setNamedFactoryRecorder(controller->getNamedFactorySet()); 108 buffer.setNamedFactoryRecorder(controller->getNamedFactorySet());
115 buffer.setFlags(controller->getWriteBufferFlags()); 109 buffer.setFlags(controller->getWriteBufferFlags());
116 110
117 flattenProc(buffer, obj); 111 flattenProc(buffer, obj);
118 uint32_t size = buffer.size(); 112 uint32_t size = buffer.size();
119 SkASSERT(SkIsAlign4(size)); 113 SkASSERT(SkIsAlign4(size));
120 114
121 /** 115 // Allocate enough memory to hold SkFlatData struct and the flat data itself .
122 * Allocate enough memory to hold 116 size_t allocSize = sizeof(SkFlatData) + size;
123 * 1. SkFlatData struct
124 * 2. flattenProc's data (4-byte aligned)
125 * 3. 4-byte sentinel
126 */
127 size_t allocSize = sizeof(SkFlatData) + size + sizeof(uint32_t);
128 SkFlatData* result = (SkFlatData*) controller->allocThrow(allocSize); 117 SkFlatData* result = (SkFlatData*) controller->allocThrow(allocSize);
129 118
130 // put the serialized contents into the data section of the new allocation 119 // Put the serialized contents into the data section of the new allocation.
131 buffer.writeToMemory(result->data()); 120 buffer.writeToMemory(result->data());
132 result->stampHeaderAndSentinel(index, size); 121 // Stamp the index, size and checksum in the header.
122 result->stampHeader(index, size);
133 return result; 123 return result;
134 } 124 }
135 125
136 void SkFlatData::unflatten(void* result, 126 void SkFlatData::unflatten(void* result,
137 void (*unflattenProc)(SkOrderedReadBuffer&, void*), 127 void (*unflattenProc)(SkOrderedReadBuffer&, void*),
138 SkBitmapHeap* bitmapHeap, 128 SkBitmapHeap* bitmapHeap,
139 SkTypefacePlayback* facePlayback) const { 129 SkTypefacePlayback* facePlayback) const {
140 130
141 SkOrderedReadBuffer buffer(this->data(), fFlatSize); 131 SkOrderedReadBuffer buffer(this->data(), fFlatSize);
142 132
143 if (bitmapHeap) { 133 if (bitmapHeap) {
144 buffer.setBitmapStorage(bitmapHeap); 134 buffer.setBitmapStorage(bitmapHeap);
145 } 135 }
146 if (facePlayback) { 136 if (facePlayback) {
147 facePlayback->setupBuffer(buffer); 137 facePlayback->setupBuffer(buffer);
148 } 138 }
149 139
150 unflattenProc(buffer, result); 140 unflattenProc(buffer, result);
151 SkASSERT(fFlatSize == (int32_t)buffer.offset()); 141 SkASSERT(fFlatSize == (int32_t)buffer.offset());
152 } 142 }
OLDNEW
« no previous file with comments | « src/core/SkPictureFlat.h ('k') | src/core/SkPictureRecord.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698