OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2007 The Android Open Source Project | 3 * Copyright 2007 The Android Open Source Project |
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 "SkPictureFlat.h" | 10 #include "SkPictureFlat.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 /////////////////////////////////////////////////////////////////////////////// | 124 /////////////////////////////////////////////////////////////////////////////// |
125 | 125 |
126 SkPicture::SkPicture() | 126 SkPicture::SkPicture() |
127 : fAccelData(NULL) { | 127 : fAccelData(NULL) { |
128 this->needsNewGenID(); | 128 this->needsNewGenID(); |
129 fPlayback = NULL; | 129 fPlayback = NULL; |
130 fWidth = fHeight = 0; | 130 fWidth = fHeight = 0; |
131 } | 131 } |
132 | 132 |
133 SkPicture::SkPicture(int width, int height, | 133 SkPicture::SkPicture(int width, int height, |
134 SkPictureRecord& record, | 134 const SkPictureRecord& record, |
135 bool deepCopyOps) | 135 bool deepCopyOps) |
136 : fWidth(width) | 136 : fWidth(width) |
137 , fHeight(height) | 137 , fHeight(height) |
138 , fAccelData(NULL) { | 138 , fAccelData(NULL) { |
139 this->needsNewGenID(); | 139 this->needsNewGenID(); |
140 | 140 |
141 fPathHeap.reset(SkSafeRef(record.pathHeap())); | |
142 | |
143 SkPictInfo info; | 141 SkPictInfo info; |
144 this->createHeader(&info); | 142 this->createHeader(&info); |
145 fPlayback = SkNEW_ARGS(SkPicturePlayback, (this, record, info, deepCopyOps)) ; | 143 fPlayback = SkNEW_ARGS(SkPicturePlayback, (record, info, deepCopyOps)); |
146 } | 144 } |
147 | 145 |
148 SkPicture::SkPicture(const SkPicture& src) | 146 SkPicture::SkPicture(const SkPicture& src) |
149 : INHERITED() | 147 : INHERITED() |
150 , fAccelData(NULL) { | 148 , fAccelData(NULL) { |
151 this->needsNewGenID(); | 149 this->needsNewGenID(); |
152 fWidth = src.fWidth; | 150 fWidth = src.fWidth; |
153 fHeight = src.fHeight; | 151 fHeight = src.fHeight; |
154 | 152 |
155 /* We want to copy the src's playback. However, if that hasn't been built | |
156 yet, we need to fake a call to endRecording() without actually calling | |
157 it (since it is destructive, and we don't want to change src). | |
158 */ | |
159 if (src.fPlayback) { | 153 if (src.fPlayback) { |
160 fPlayback = SkNEW_ARGS(SkPicturePlayback, (this, *src.fPlayback)); | 154 fPlayback = SkNEW_ARGS(SkPicturePlayback, (*src.fPlayback)); |
161 fUniqueID = src.uniqueID(); // need to call method to ensure != 0 | 155 fUniqueID = src.uniqueID(); // need to call method to ensure != 0 |
162 } else { | 156 } else { |
163 fPlayback = NULL; | 157 fPlayback = NULL; |
164 } | 158 } |
165 | |
166 fPathHeap.reset(SkSafeRef(src.fPathHeap.get())); | |
167 } | |
168 | |
169 const SkPath& SkPicture::getPath(int index) const { | |
170 return (*fPathHeap.get())[index]; | |
171 } | |
172 | |
173 int SkPicture::addPathToHeap(const SkPath& path) { | |
174 if (NULL == fPathHeap) { | |
175 fPathHeap.reset(SkNEW(SkPathHeap)); | |
176 } | |
177 #ifdef SK_DEDUP_PICTURE_PATHS | |
178 return fPathHeap->insert(path); | |
179 #else | |
180 return fPathHeap->append(path); | |
181 #endif | |
182 } | |
183 | |
184 void SkPicture::initForPlayback() const { | |
185 // ensure that the paths bounds are pre-computed | |
186 if (NULL != fPathHeap.get()) { | |
187 for (int i = 0; i < fPathHeap->count(); i++) { | |
188 (*fPathHeap.get())[i].updateBoundsCache(); | |
189 } | |
190 } | |
191 } | |
192 | |
193 void SkPicture::dumpSize() const { | |
194 SkDebugf("--- picture size: paths=%d\n", | |
195 SafeCount(fPathHeap.get())); | |
196 } | 159 } |
197 | 160 |
198 SkPicture::~SkPicture() { | 161 SkPicture::~SkPicture() { |
199 SkDELETE(fPlayback); | 162 SkDELETE(fPlayback); |
200 SkSafeUnref(fAccelData); | 163 SkSafeUnref(fAccelData); |
201 } | 164 } |
202 | 165 |
203 void SkPicture::swap(SkPicture& other) { | 166 void SkPicture::swap(SkPicture& other) { |
204 SkTSwap(fUniqueID, other.fUniqueID); | 167 SkTSwap(fUniqueID, other.fUniqueID); |
205 SkTSwap(fPlayback, other.fPlayback); | 168 SkTSwap(fPlayback, other.fPlayback); |
206 SkTSwap(fAccelData, other.fAccelData); | 169 SkTSwap(fAccelData, other.fAccelData); |
207 SkTSwap(fWidth, other.fWidth); | 170 SkTSwap(fWidth, other.fWidth); |
208 SkTSwap(fHeight, other.fHeight); | 171 SkTSwap(fHeight, other.fHeight); |
209 fPathHeap.swap(&other.fPathHeap); | |
210 } | 172 } |
211 | 173 |
212 SkPicture* SkPicture::clone() const { | 174 SkPicture* SkPicture::clone() const { |
213 SkPicture* clonedPicture = SkNEW(SkPicture); | 175 SkPicture* clonedPicture = SkNEW(SkPicture); |
214 this->clone(clonedPicture, 1); | 176 this->clone(clonedPicture, 1); |
215 return clonedPicture; | 177 return clonedPicture; |
216 } | 178 } |
217 | 179 |
218 void SkPicture::clone(SkPicture* pictures, int count) const { | 180 void SkPicture::clone(SkPicture* pictures, int count) const { |
219 SkPictCopyInfo copyInfo; | 181 SkPictCopyInfo copyInfo; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 copyInfo.paintData[i] = NULL; | 228 copyInfo.paintData[i] = NULL; |
267 } | 229 } |
268 } | 230 } |
269 SkASSERT(SafeCount(fPlayback->fBitmapHeap.get()) == heapSize); | 231 SkASSERT(SafeCount(fPlayback->fBitmapHeap.get()) == heapSize); |
270 | 232 |
271 // needed to create typeface playback | 233 // needed to create typeface playback |
272 copyInfo.controller.setupPlaybacks(); | 234 copyInfo.controller.setupPlaybacks(); |
273 copyInfo.initialized = true; | 235 copyInfo.initialized = true; |
274 } | 236 } |
275 | 237 |
276 clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (clone, *fPlayback, ©Info)); | 238 clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (*fPlayback, ©I nfo)); |
277 clone->fUniqueID = this->uniqueID(); // need to call method to ensur e != 0 | 239 clone->fUniqueID = this->uniqueID(); // need to call method to ensur e != 0 |
278 } else { | 240 } else { |
279 clone->fPlayback = NULL; | 241 clone->fPlayback = NULL; |
280 } | 242 } |
281 | |
282 clone->fPathHeap.reset(SkSafeRef(fPathHeap.get())); | |
283 } | 243 } |
284 } | 244 } |
285 | 245 |
286 SkPicture::AccelData::Domain SkPicture::AccelData::GenerateDomain() { | 246 SkPicture::AccelData::Domain SkPicture::AccelData::GenerateDomain() { |
287 static int32_t gNextID = 0; | 247 static int32_t gNextID = 0; |
288 | 248 |
289 int32_t id = sk_atomic_inc(&gNextID); | 249 int32_t id = sk_atomic_inc(&gNextID); |
290 if (id >= 1 << (8 * sizeof(Domain))) { | 250 if (id >= 1 << (8 * sizeof(Domain))) { |
291 SK_CRASH(); | 251 SK_CRASH(); |
292 } | 252 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
382 this->needsNewGenID(); | 342 this->needsNewGenID(); |
383 } | 343 } |
384 | 344 |
385 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro c) { | 345 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro c) { |
386 SkPictInfo info; | 346 SkPictInfo info; |
387 | 347 |
388 if (!InternalOnly_StreamIsSKP(stream, &info)) { | 348 if (!InternalOnly_StreamIsSKP(stream, &info)) { |
389 return NULL; | 349 return NULL; |
390 } | 350 } |
391 | 351 |
392 SkPicture* newPict = SkNEW_ARGS(SkPicture, (NULL, info.fWidth, info.fHeight) ); | |
393 | |
394 // Check to see if there is a playback to recreate. | 352 // Check to see if there is a playback to recreate. |
395 if (stream->readBool()) { | 353 if (stream->readBool()) { |
396 SkPicturePlayback* playback = SkPicturePlayback::CreateFromStream(newPic t, stream, | 354 SkPicturePlayback* playback = SkPicturePlayback::CreateFromStream(stream , info, proc); |
397 info, proc); | |
398 if (NULL == playback) { | 355 if (NULL == playback) { |
399 SkDELETE(newPict); | |
400 return NULL; | 356 return NULL; |
401 } | 357 } |
402 newPict->fPlayback = playback; | 358 |
359 return SkNEW_ARGS(SkPicture, (playback, info.fWidth, info.fHeight)); | |
403 } | 360 } |
404 | 361 |
405 return newPict; | 362 return NULL; |
mtklein
2014/06/11 21:12:58
Same deal?
| |
406 } | 363 } |
407 | 364 |
408 SkPicture* SkPicture::CreateFromBuffer(SkReadBuffer& buffer) { | 365 SkPicture* SkPicture::CreateFromBuffer(SkReadBuffer& buffer) { |
409 SkPictInfo info; | 366 SkPictInfo info; |
410 | 367 |
411 if (!InternalOnly_BufferIsSKP(buffer, &info)) { | 368 if (!InternalOnly_BufferIsSKP(buffer, &info)) { |
412 return NULL; | 369 return NULL; |
413 } | 370 } |
414 | 371 |
415 SkPicture* newPict = SkNEW_ARGS(SkPicture, (NULL, info.fWidth, info.fHeight) ); | |
416 | |
417 // Check to see if there is a playback to recreate. | 372 // Check to see if there is a playback to recreate. |
418 if (buffer.readBool()) { | 373 if (buffer.readBool()) { |
419 SkPicturePlayback* playback = SkPicturePlayback::CreateFromBuffer(newPic t, buffer, info); | 374 SkPicturePlayback* playback = SkPicturePlayback::CreateFromBuffer(buffer , info); |
420 if (NULL == playback) { | 375 if (NULL == playback) { |
421 SkDELETE(newPict); | |
422 return NULL; | 376 return NULL; |
423 } | 377 } |
424 newPict->fPlayback = playback; | 378 |
379 return SkNEW_ARGS(SkPicture, (playback, info.fWidth, info.fHeight)); | |
425 } | 380 } |
426 | 381 |
427 return newPict; | 382 return NULL; |
428 } | 383 } |
429 | 384 |
430 void SkPicture::createHeader(SkPictInfo* info) const { | 385 void SkPicture::createHeader(SkPictInfo* info) const { |
431 // Copy magic bytes at the beginning of the header | 386 // Copy magic bytes at the beginning of the header |
432 SkASSERT(sizeof(kMagic) == 8); | 387 SkASSERT(sizeof(kMagic) == 8); |
433 SkASSERT(sizeof(kMagic) == sizeof(info->fMagic)); | 388 SkASSERT(sizeof(kMagic) == sizeof(info->fMagic)); |
434 memcpy(info->fMagic, kMagic, sizeof(kMagic)); | 389 memcpy(info->fMagic, kMagic, sizeof(kMagic)); |
435 | 390 |
436 // Set picture info after magic bytes in the header | 391 // Set picture info after magic bytes in the header |
437 info->fVersion = CURRENT_PICTURE_VERSION; | 392 info->fVersion = CURRENT_PICTURE_VERSION; |
(...skipping 29 matching lines...) Expand all Loading... | |
467 void SkPicture::WriteTagSize(SkWriteBuffer& buffer, uint32_t tag, size_t size) { | 422 void SkPicture::WriteTagSize(SkWriteBuffer& buffer, uint32_t tag, size_t size) { |
468 buffer.writeUInt(tag); | 423 buffer.writeUInt(tag); |
469 buffer.writeUInt(SkToU32(size)); | 424 buffer.writeUInt(SkToU32(size)); |
470 } | 425 } |
471 | 426 |
472 void SkPicture::WriteTagSize(SkWStream* stream, uint32_t tag, size_t size) { | 427 void SkPicture::WriteTagSize(SkWStream* stream, uint32_t tag, size_t size) { |
473 stream->write32(tag); | 428 stream->write32(tag); |
474 stream->write32(SkToU32(size)); | 429 stream->write32(SkToU32(size)); |
475 } | 430 } |
476 | 431 |
477 bool SkPicture::parseBufferTag(SkReadBuffer& buffer, | |
478 uint32_t tag, | |
479 uint32_t size) { | |
480 switch (tag) { | |
481 case SK_PICT_PATH_BUFFER_TAG: | |
482 if (size > 0) { | |
483 fPathHeap.reset(SkNEW_ARGS(SkPathHeap, (buffer))); | |
484 } | |
485 break; | |
486 default: | |
487 // The tag was invalid. | |
488 return false; | |
489 } | |
490 | |
491 return true; // success | |
492 } | |
493 | |
494 void SkPicture::flattenToBuffer(SkWriteBuffer& buffer) const { | |
495 int n; | |
496 | |
497 if ((n = SafeCount(fPathHeap.get())) > 0) { | |
498 WriteTagSize(buffer, SK_PICT_PATH_BUFFER_TAG, n); | |
499 fPathHeap->flatten(buffer); | |
500 } | |
501 } | |
502 | |
503 void SkPicture::flatten(SkWriteBuffer& buffer) const { | 432 void SkPicture::flatten(SkWriteBuffer& buffer) const { |
504 SkPicturePlayback* playback = fPlayback; | 433 SkPicturePlayback* playback = fPlayback; |
505 | 434 |
506 SkPictInfo info; | 435 SkPictInfo info; |
507 this->createHeader(&info); | 436 this->createHeader(&info); |
508 buffer.writeByteArray(&info, sizeof(info)); | 437 buffer.writeByteArray(&info, sizeof(info)); |
509 if (playback) { | 438 if (playback) { |
510 buffer.writeBool(true); | 439 buffer.writeBool(true); |
511 playback->flatten(buffer); | 440 playback->flatten(buffer); |
512 // delete playback if it is a local version (i.e. cons'd up just now) | 441 // delete playback if it is a local version (i.e. cons'd up just now) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
557 } while (SK_InvalidGenID == genID); | 486 } while (SK_InvalidGenID == genID); |
558 return genID; | 487 return genID; |
559 } | 488 } |
560 | 489 |
561 uint32_t SkPicture::uniqueID() const { | 490 uint32_t SkPicture::uniqueID() const { |
562 if (SK_InvalidGenID == fUniqueID) { | 491 if (SK_InvalidGenID == fUniqueID) { |
563 fUniqueID = next_picture_generation_id(); | 492 fUniqueID = next_picture_generation_id(); |
564 } | 493 } |
565 return fUniqueID; | 494 return fUniqueID; |
566 } | 495 } |
OLD | NEW |