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

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

Issue 153583007: Revert "Serialization of SkPictureImageFilter" (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 10 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 | « samplecode/SampleFilterFuzz.cpp ('k') | src/core/SkPicturePlayback.h » ('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 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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 if (fPlayback) { 258 if (fPlayback) {
259 fPlayback->draw(*surface, callback); 259 fPlayback->draw(*surface, callback);
260 } 260 }
261 } 261 }
262 262
263 /////////////////////////////////////////////////////////////////////////////// 263 ///////////////////////////////////////////////////////////////////////////////
264 264
265 #include "SkStream.h" 265 #include "SkStream.h"
266 266
267 static const char kMagic[] = { 's', 'k', 'i', 'a', 'p', 'i', 'c', 't' }; 267 static const char kMagic[] = { 's', 'k', 'i', 'a', 'p', 'i', 'c', 't' };
268 static const size_t kHeaderSize = sizeof(kMagic) + sizeof(SkPictInfo);
269 268
270 bool SkPicture::StreamIsSKP(SkStream* stream, SkPictInfo* pInfo) { 269 bool SkPicture::StreamIsSKP(SkStream* stream, SkPictInfo* pInfo) {
271 if (NULL == stream) { 270 if (NULL == stream) {
272 return false; 271 return false;
273 } 272 }
274 273
275 // Check magic bytes. 274 // Check magic bytes.
276 char magic[sizeof(kMagic)]; 275 char magic[sizeof(kMagic)];
277 if (!stream->read(magic, sizeof(kMagic)) || 276 stream->read(magic, sizeof(kMagic));
278 (0 != memcmp(magic, kMagic, sizeof(kMagic)))) { 277 if (0 != memcmp(magic, kMagic, sizeof(kMagic))) {
279 return false; 278 return false;
280 } 279 }
281 280
282 SkPictInfo info; 281 SkPictInfo info;
283 if (!stream->read(&info, sizeof(SkPictInfo))) { 282 if (!stream->read(&info, sizeof(SkPictInfo))) {
284 return false; 283 return false;
285 } 284 }
286 285
287 if (PICTURE_VERSION != info.fVersion) { 286 if (PICTURE_VERSION != info.fVersion) {
288 return false; 287 return false;
289 } 288 }
290 289
291 if (pInfo != NULL) { 290 if (pInfo != NULL) {
292 *pInfo = info; 291 *pInfo = info;
293 } 292 }
294 return true; 293 return true;
295 } 294 }
296 295
297 bool SkPicture::BufferIsSKP(SkReadBuffer& buffer, SkPictInfo* pInfo) {
298 // Check magic bytes.
299 char magic[sizeof(kMagic)];
300
301 if (!buffer.readByteArray(magic, sizeof(kMagic)) ||
302 (0 != memcmp(magic, kMagic, sizeof(kMagic)))) {
303 return false;
304 }
305
306 SkPictInfo info;
307 if (!buffer.readByteArray(&info, sizeof(SkPictInfo))) {
308 return false;
309 }
310
311 if (PICTURE_VERSION != info.fVersion) {
312 return false;
313 }
314
315 if (pInfo != NULL) {
316 *pInfo = info;
317 }
318 return true;
319 }
320
321 SkPicture::SkPicture(SkPicturePlayback* playback, int width, int height) 296 SkPicture::SkPicture(SkPicturePlayback* playback, int width, int height)
322 : fPlayback(playback) 297 : fPlayback(playback)
323 , fRecord(NULL) 298 , fRecord(NULL)
324 , fWidth(width) 299 , fWidth(width)
325 , fHeight(height) {} 300 , fHeight(height) {}
326 301
327 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro c) { 302 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro c) {
328 SkPictInfo info; 303 SkPictInfo info;
329 304
330 if (!StreamIsSKP(stream, &info)) { 305 if (!StreamIsSKP(stream, &info)) {
331 return NULL; 306 return NULL;
332 } 307 }
333 308
334 SkPicturePlayback* playback; 309 SkPicturePlayback* playback;
335 // Check to see if there is a playback to recreate. 310 // Check to see if there is a playback to recreate.
336 if (stream->readBool()) { 311 if (stream->readBool()) {
337 playback = SkPicturePlayback::CreateFromStream(stream, info, proc); 312 playback = SkPicturePlayback::CreateFromStream(stream, info, proc);
338 if (NULL == playback) { 313 if (NULL == playback) {
339 return NULL; 314 return NULL;
340 } 315 }
341 } else { 316 } else {
342 playback = NULL; 317 playback = NULL;
343 } 318 }
344 319
345 return SkNEW_ARGS(SkPicture, (playback, info.fWidth, info.fHeight)); 320 return SkNEW_ARGS(SkPicture, (playback, info.fWidth, info.fHeight));
346 } 321 }
347 322
348 SkPicture* SkPicture::CreateFromBuffer(SkReadBuffer& buffer) {
349 SkPictInfo info;
350
351 if (!BufferIsSKP(buffer, &info)) {
352 return NULL;
353 }
354
355 SkPicturePlayback* playback;
356 // Check to see if there is a playback to recreate.
357 if (buffer.readBool()) {
358 playback = SkPicturePlayback::CreateFromBuffer(buffer);
359 if (NULL == playback) {
360 return NULL;
361 }
362 } else {
363 playback = NULL;
364 }
365
366 return SkNEW_ARGS(SkPicture, (playback, info.fWidth, info.fHeight));
367 }
368
369 void SkPicture::createHeader(void* header) const {
370 // Copy magic bytes at the beginning of the header
371 SkASSERT(sizeof(kMagic) == 8);
372 memcpy(header, kMagic, sizeof(kMagic));
373
374 // Set piture info after magic bytes in the header
375 SkPictInfo* info = (SkPictInfo*)(((char*)header) + sizeof(kMagic));
376 info->fVersion = PICTURE_VERSION;
377 info->fWidth = fWidth;
378 info->fHeight = fHeight;
379 info->fFlags = SkPictInfo::kCrossProcess_Flag;
380 // TODO: remove this flag, since we're always float (now)
381 info->fFlags |= SkPictInfo::kScalarIsFloat_Flag;
382
383 if (8 == sizeof(void*)) {
384 info->fFlags |= SkPictInfo::kPtrIs64Bit_Flag;
385 }
386 }
387
388 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { 323 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const {
389 SkPicturePlayback* playback = fPlayback; 324 SkPicturePlayback* playback = fPlayback;
390 325
391 if (NULL == playback && fRecord) { 326 if (NULL == playback && fRecord) {
392 playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord)); 327 playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord));
393 } 328 }
394 329
395 char header[kHeaderSize]; 330 SkPictInfo info;
396 createHeader(&header); 331
397 stream->write(header, kHeaderSize); 332 info.fVersion = PICTURE_VERSION;
333 info.fWidth = fWidth;
334 info.fHeight = fHeight;
335 info.fFlags = SkPictInfo::kCrossProcess_Flag;
336 // TODO: remove this flag, since we're always float (now)
337 info.fFlags |= SkPictInfo::kScalarIsFloat_Flag;
338
339 if (8 == sizeof(void*)) {
340 info.fFlags |= SkPictInfo::kPtrIs64Bit_Flag;
341 }
342
343 // Write 8 magic bytes to ID this file format.
344 SkASSERT(sizeof(kMagic) == 8);
345 stream->write(kMagic, sizeof(kMagic));
346
347 stream->write(&info, sizeof(info));
398 if (playback) { 348 if (playback) {
399 stream->writeBool(true); 349 stream->writeBool(true);
400 playback->serialize(stream, encoder); 350 playback->serialize(stream, encoder);
401 // delete playback if it is a local version (i.e. cons'd up just now) 351 // delete playback if it is a local version (i.e. cons'd up just now)
402 if (playback != fPlayback) { 352 if (playback != fPlayback) {
403 SkDELETE(playback); 353 SkDELETE(playback);
404 } 354 }
405 } else { 355 } else {
406 stream->writeBool(false); 356 stream->writeBool(false);
407 } 357 }
408 } 358 }
409 359
410 void SkPicture::flatten(SkWriteBuffer& buffer) const {
411 SkPicturePlayback* playback = fPlayback;
412
413 if (NULL == playback && fRecord) {
414 playback = SkNEW_ARGS(SkPicturePlayback, (*fRecord));
415 }
416
417 char header[kHeaderSize];
418 createHeader(&header);
419 buffer.writeByteArray(header, kHeaderSize);
420 if (playback) {
421 buffer.writeBool(true);
422 playback->flatten(buffer);
423 // delete playback if it is a local version (i.e. cons'd up just now)
424 if (playback != fPlayback) {
425 SkDELETE(playback);
426 }
427 } else {
428 buffer.writeBool(false);
429 }
430 }
431
432 bool SkPicture::willPlayBackBitmaps() const { 360 bool SkPicture::willPlayBackBitmaps() const {
433 if (!fPlayback) return false; 361 if (!fPlayback) return false;
434 return fPlayback->containsBitmaps(); 362 return fPlayback->containsBitmaps();
435 } 363 }
436 364
437 #ifdef SK_BUILD_FOR_ANDROID 365 #ifdef SK_BUILD_FOR_ANDROID
438 void SkPicture::abortPlayback() { 366 void SkPicture::abortPlayback() {
439 if (NULL == fPlayback) { 367 if (NULL == fPlayback) {
440 return; 368 return;
441 } 369 }
442 fPlayback->abort(); 370 fPlayback->abort();
443 } 371 }
444 #endif 372 #endif
OLDNEW
« no previous file with comments | « samplecode/SampleFilterFuzz.cpp ('k') | src/core/SkPicturePlayback.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698