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

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

Issue 19564007: Start from scratch on a faster SkFlatDictionary. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: fix windows build by making AllocScratch static Created 7 years, 5 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
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) {
98 fIndex = index;
99 fFlatSize = size;
100 fChecksum = SkChecksum::Compute(this->data32(), size);
101 this->setTopBotUnwritten();
102 this->setSentinelAsCandidate();
103 }
104
97 SkFlatData* SkFlatData::Create(SkFlatController* controller, const void* obj, 105 SkFlatData* SkFlatData::Create(SkFlatController* controller, const void* obj,
98 int index, void (*flattenProc)(SkOrderedWriteBuffer&, const void*)) { 106 int index, void (*flattenProc)(SkOrderedWriteBuffer&, const void*)) {
99 // a buffer of 256 bytes should be sufficient for most paints, regions, 107 // a buffer of 256 bytes should be sufficient for most paints, regions,
100 // and matrices. 108 // and matrices.
101 intptr_t storage[256]; 109 intptr_t storage[256];
102 SkOrderedWriteBuffer buffer(256, storage, sizeof(storage)); 110 SkOrderedWriteBuffer buffer(256, storage, sizeof(storage));
103 111
104 buffer.setBitmapHeap(controller->getBitmapHeap()); 112 buffer.setBitmapHeap(controller->getBitmapHeap());
105 buffer.setTypefaceRecorder(controller->getTypefaceSet()); 113 buffer.setTypefaceRecorder(controller->getTypefaceSet());
106 buffer.setNamedFactoryRecorder(controller->getNamedFactorySet()); 114 buffer.setNamedFactoryRecorder(controller->getNamedFactorySet());
107 buffer.setFlags(controller->getWriteBufferFlags()); 115 buffer.setFlags(controller->getWriteBufferFlags());
108 116
109 flattenProc(buffer, obj); 117 flattenProc(buffer, obj);
110 uint32_t size = buffer.size(); 118 uint32_t size = buffer.size();
111 SkASSERT(SkIsAlign4(size)); 119 SkASSERT(SkIsAlign4(size));
112 120
113 /** 121 /**
114 * Allocate enough memory to hold 122 * Allocate enough memory to hold
115 * 1. SkFlatData struct 123 * 1. SkFlatData struct
116 * 2. flattenProc's data (4-byte aligned) 124 * 2. flattenProc's data (4-byte aligned)
117 * 3. 4-byte sentinel 125 * 3. 4-byte sentinel
118 */ 126 */
119 size_t allocSize = sizeof(SkFlatData) + size + sizeof(uint32_t); 127 size_t allocSize = sizeof(SkFlatData) + size + sizeof(uint32_t);
120 SkFlatData* result = (SkFlatData*) controller->allocThrow(allocSize); 128 SkFlatData* result = (SkFlatData*) controller->allocThrow(allocSize);
121 129
122 result->setIndex(index);
123 result->setTopBotUnwritten();
124 result->fFlatSize = size;
125
126 // put the serialized contents into the data section of the new allocation 130 // put the serialized contents into the data section of the new allocation
127 buffer.writeToMemory(result->data()); 131 buffer.writeToMemory(result->data());
128 result->fChecksum = SkChecksum::Compute(result->data32(), size); 132 result->stampHeaderAndSentinel(index, size);
129 result->setSentinelAsCandidate();
130 return result; 133 return result;
131 } 134 }
132 135
133 void SkFlatData::unflatten(void* result, 136 void SkFlatData::unflatten(void* result,
134 void (*unflattenProc)(SkOrderedReadBuffer&, void*), 137 void (*unflattenProc)(SkOrderedReadBuffer&, void*),
135 SkBitmapHeap* bitmapHeap, 138 SkBitmapHeap* bitmapHeap,
136 SkTypefacePlayback* facePlayback) const { 139 SkTypefacePlayback* facePlayback) const {
137 140
138 SkOrderedReadBuffer buffer(this->data(), fFlatSize); 141 SkOrderedReadBuffer buffer(this->data(), fFlatSize);
139 142
140 if (bitmapHeap) { 143 if (bitmapHeap) {
141 buffer.setBitmapStorage(bitmapHeap); 144 buffer.setBitmapStorage(bitmapHeap);
142 } 145 }
143 if (facePlayback) { 146 if (facePlayback) {
144 facePlayback->setupBuffer(buffer); 147 facePlayback->setupBuffer(buffer);
145 } 148 }
146 149
147 unflattenProc(buffer, result); 150 unflattenProc(buffer, result);
148 SkASSERT(fFlatSize == (int32_t)buffer.offset()); 151 SkASSERT(fFlatSize == (int32_t)buffer.offset());
149 } 152 }
OLDNEW
« src/core/SkPictureFlat.h ('K') | « src/core/SkPictureFlat.h ('k') | tests/Writer32Test.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698