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

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

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

Powered by Google App Engine
This is Rietveld 408576698