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

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

Issue 2099343002: Address ASAN fuzzer complaint (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address ASAN fuzzer complaint Created 4 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
« no previous file with comments | « no previous file | no next file » | 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 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkPatchUtils.h" 9 #include "SkPatchUtils.h"
10 #include "SkPictureData.h" 10 #include "SkPictureData.h"
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 case DRAW_DRAWABLE: 260 case DRAW_DRAWABLE:
261 canvas->drawDrawable(fPictureData->getDrawable(reader)); 261 canvas->drawDrawable(fPictureData->getDrawable(reader));
262 break; 262 break;
263 case DRAW_DRAWABLE_MATRIX: { 263 case DRAW_DRAWABLE_MATRIX: {
264 SkMatrix matrix; 264 SkMatrix matrix;
265 reader->readMatrix(&matrix); 265 reader->readMatrix(&matrix);
266 SkDrawable* drawable = fPictureData->getDrawable(reader); 266 SkDrawable* drawable = fPictureData->getDrawable(reader);
267 canvas->drawDrawable(drawable, &matrix); 267 canvas->drawDrawable(drawable, &matrix);
268 } break; 268 } break;
269 case DRAW_DRRECT: { 269 case DRAW_DRRECT: {
270 const SkPaint& paint = *fPictureData->getPaint(reader); 270 const SkPaint* paint = fPictureData->getPaint(reader);
271 SkRRect outer, inner; 271 SkRRect outer, inner;
272 reader->readRRect(&outer); 272 reader->readRRect(&outer);
273 reader->readRRect(&inner); 273 reader->readRRect(&inner);
274 canvas->drawDRRect(outer, inner, paint); 274 if (paint) {
275 canvas->drawDRRect(outer, inner, *paint);
276 }
275 } break; 277 } break;
276 case BEGIN_COMMENT_GROUP: { 278 case BEGIN_COMMENT_GROUP: {
277 SkString tmp; 279 SkString tmp;
278 reader->readString(&tmp); 280 reader->readString(&tmp);
279 // deprecated (M44) 281 // deprecated (M44)
280 break; 282 break;
281 } 283 }
282 case COMMENT: { 284 case COMMENT: {
283 SkString tmp; 285 SkString tmp;
284 reader->readString(&tmp); 286 reader->readString(&tmp);
(...skipping 30 matching lines...) Expand all
315 reader->readRect(&dst); // required 317 reader->readRect(&dst); // required
316 // DRAW_IMAGE_RECT_STRICT assumes this constraint, and doesn't store it 318 // DRAW_IMAGE_RECT_STRICT assumes this constraint, and doesn't store it
317 SkCanvas::SrcRectConstraint constraint = SkCanvas::kStrict_SrcRectCo nstraint; 319 SkCanvas::SrcRectConstraint constraint = SkCanvas::kStrict_SrcRectCo nstraint;
318 if (DRAW_IMAGE_RECT == op) { 320 if (DRAW_IMAGE_RECT == op) {
319 // newer op-code stores the constraint explicitly 321 // newer op-code stores the constraint explicitly
320 constraint = (SkCanvas::SrcRectConstraint)reader->readInt(); 322 constraint = (SkCanvas::SrcRectConstraint)reader->readInt();
321 } 323 }
322 canvas->legacy_drawImageRect(image, src, dst, paint, constraint); 324 canvas->legacy_drawImageRect(image, src, dst, paint, constraint);
323 } break; 325 } break;
324 case DRAW_OVAL: { 326 case DRAW_OVAL: {
325 const SkPaint& paint = *fPictureData->getPaint(reader); 327 const SkPaint* paint = fPictureData->getPaint(reader);
326 SkRect rect; 328 SkRect rect;
327 reader->readRect(&rect); 329 reader->readRect(&rect);
328 canvas->drawOval(rect, paint); 330 if (paint) {
331 canvas->drawOval(rect, *paint);
332 }
329 } break; 333 } break;
330 case DRAW_PAINT: 334 case DRAW_PAINT: {
331 canvas->drawPaint(*fPictureData->getPaint(reader)); 335 const SkPaint* paint = fPictureData->getPaint(reader);
332 break; 336 if (paint) {
337 canvas->drawPaint(*paint);
338 }
339 } break;
333 case DRAW_PATCH: { 340 case DRAW_PATCH: {
334 const SkPaint& paint = *fPictureData->getPaint(reader); 341 const SkPaint* paint = fPictureData->getPaint(reader);
335 342
336 const SkPoint* cubics = (const SkPoint*)reader->skip(SkPatchUtils::k NumCtrlPts * 343 const SkPoint* cubics = (const SkPoint*)reader->skip(SkPatchUtils::k NumCtrlPts *
337 sizeof(SkPoint) ); 344 sizeof(SkPoint) );
338 uint32_t flag = reader->readInt(); 345 uint32_t flag = reader->readInt();
339 const SkColor* colors = nullptr; 346 const SkColor* colors = nullptr;
340 if (flag & DRAW_VERTICES_HAS_COLORS) { 347 if (flag & DRAW_VERTICES_HAS_COLORS) {
341 colors = (const SkColor*)reader->skip(SkPatchUtils::kNumCorners * sizeof(SkColor)); 348 colors = (const SkColor*)reader->skip(SkPatchUtils::kNumCorners * sizeof(SkColor));
342 } 349 }
343 const SkPoint* texCoords = nullptr; 350 const SkPoint* texCoords = nullptr;
344 if (flag & DRAW_VERTICES_HAS_TEXS) { 351 if (flag & DRAW_VERTICES_HAS_TEXS) {
345 texCoords = (const SkPoint*)reader->skip(SkPatchUtils::kNumCorne rs * 352 texCoords = (const SkPoint*)reader->skip(SkPatchUtils::kNumCorne rs *
346 sizeof(SkPoint)); 353 sizeof(SkPoint));
347 } 354 }
348 sk_sp<SkXfermode> xfer; 355 sk_sp<SkXfermode> xfer;
349 if (flag & DRAW_VERTICES_HAS_XFER) { 356 if (flag & DRAW_VERTICES_HAS_XFER) {
350 int mode = reader->readInt(); 357 int mode = reader->readInt();
351 if (mode < 0 || mode > SkXfermode::kLastMode) { 358 if (mode < 0 || mode > SkXfermode::kLastMode) {
352 mode = SkXfermode::kModulate_Mode; 359 mode = SkXfermode::kModulate_Mode;
353 } 360 }
354 xfer = SkXfermode::Make((SkXfermode::Mode)mode); 361 xfer = SkXfermode::Make((SkXfermode::Mode)mode);
355 } 362 }
356 canvas->drawPatch(cubics, colors, texCoords, std::move(xfer), paint) ; 363 if (paint) {
364 canvas->drawPatch(cubics, colors, texCoords, std::move(xfer), *p aint);
365 }
357 } break; 366 } break;
358 case DRAW_PATH: { 367 case DRAW_PATH: {
359 const SkPaint& paint = *fPictureData->getPaint(reader); 368 const SkPaint* paint = fPictureData->getPaint(reader);
360 canvas->drawPath(fPictureData->getPath(reader), paint); 369 if (paint) {
370 canvas->drawPath(fPictureData->getPath(reader), *paint);
371 }
361 } break; 372 } break;
362 case DRAW_PICTURE: 373 case DRAW_PICTURE:
363 canvas->drawPicture(fPictureData->getPicture(reader)); 374 canvas->drawPicture(fPictureData->getPicture(reader));
364 break; 375 break;
365 case DRAW_PICTURE_MATRIX_PAINT: { 376 case DRAW_PICTURE_MATRIX_PAINT: {
366 const SkPaint* paint = fPictureData->getPaint(reader); 377 const SkPaint* paint = fPictureData->getPaint(reader);
367 SkMatrix matrix; 378 SkMatrix matrix;
368 reader->readMatrix(&matrix); 379 reader->readMatrix(&matrix);
369 const SkPicture* pic = fPictureData->getPicture(reader); 380 const SkPicture* pic = fPictureData->getPicture(reader);
370 canvas->drawPicture(pic, &matrix, paint); 381 canvas->drawPicture(pic, &matrix, paint);
371 } break; 382 } break;
372 case DRAW_POINTS: { 383 case DRAW_POINTS: {
373 const SkPaint& paint = *fPictureData->getPaint(reader); 384 const SkPaint* paint = fPictureData->getPaint(reader);
374 SkCanvas::PointMode mode = (SkCanvas::PointMode)reader->readInt(); 385 SkCanvas::PointMode mode = (SkCanvas::PointMode)reader->readInt();
375 size_t count = reader->readInt(); 386 size_t count = reader->readInt();
376 const SkPoint* pts = (const SkPoint*)reader->skip(sizeof(SkPoint)* c ount); 387 const SkPoint* pts = (const SkPoint*)reader->skip(sizeof(SkPoint)* c ount);
377 canvas->drawPoints(mode, count, pts, paint); 388 if (paint) {
389 canvas->drawPoints(mode, count, pts, *paint);
390 }
378 } break; 391 } break;
379 case DRAW_POS_TEXT: { 392 case DRAW_POS_TEXT: {
380 const SkPaint& paint = *fPictureData->getPaint(reader); 393 const SkPaint* paint = fPictureData->getPaint(reader);
381 TextContainer text; 394 TextContainer text;
382 get_text(reader, &text); 395 get_text(reader, &text);
383 size_t points = reader->readInt(); 396 size_t points = reader->readInt();
384 const SkPoint* pos = (const SkPoint*)reader->skip(points * sizeof(Sk Point)); 397 const SkPoint* pos = (const SkPoint*)reader->skip(points * sizeof(Sk Point));
385 canvas->drawPosText(text.text(), text.length(), pos, paint); 398 if (paint) {
399 canvas->drawPosText(text.text(), text.length(), pos, *paint);
400 }
386 } break; 401 } break;
387 case DRAW_POS_TEXT_TOP_BOTTOM: { 402 case DRAW_POS_TEXT_TOP_BOTTOM: {
388 const SkPaint& paint = *fPictureData->getPaint(reader); 403 const SkPaint* paint = fPictureData->getPaint(reader);
389 TextContainer text; 404 TextContainer text;
390 get_text(reader, &text); 405 get_text(reader, &text);
391 size_t points = reader->readInt(); 406 size_t points = reader->readInt();
392 const SkPoint* pos = (const SkPoint*)reader->skip(points * sizeof(Sk Point)); 407 const SkPoint* pos = (const SkPoint*)reader->skip(points * sizeof(Sk Point));
393 const SkScalar top = reader->readScalar(); 408 const SkScalar top = reader->readScalar();
394 const SkScalar bottom = reader->readScalar(); 409 const SkScalar bottom = reader->readScalar();
395 if (!canvas->quickRejectY(top, bottom)) { 410 if (!canvas->quickRejectY(top, bottom) && paint) {
396 canvas->drawPosText(text.text(), text.length(), pos, paint); 411 canvas->drawPosText(text.text(), text.length(), pos, *paint);
397 } 412 }
398 } break; 413 } break;
399 case DRAW_POS_TEXT_H: { 414 case DRAW_POS_TEXT_H: {
400 const SkPaint& paint = *fPictureData->getPaint(reader); 415 const SkPaint* paint = fPictureData->getPaint(reader);
401 TextContainer text; 416 TextContainer text;
402 get_text(reader, &text); 417 get_text(reader, &text);
403 size_t xCount = reader->readInt(); 418 size_t xCount = reader->readInt();
404 const SkScalar constY = reader->readScalar(); 419 const SkScalar constY = reader->readScalar();
405 const SkScalar* xpos = (const SkScalar*)reader->skip(xCount * sizeof (SkScalar)); 420 const SkScalar* xpos = (const SkScalar*)reader->skip(xCount * sizeof (SkScalar));
406 canvas->drawPosTextH(text.text(), text.length(), xpos, constY, paint ); 421 if (paint) {
422 canvas->drawPosTextH(text.text(), text.length(), xpos, constY, * paint);
423 }
407 } break; 424 } break;
408 case DRAW_POS_TEXT_H_TOP_BOTTOM: { 425 case DRAW_POS_TEXT_H_TOP_BOTTOM: {
409 const SkPaint& paint = *fPictureData->getPaint(reader); 426 const SkPaint* paint = fPictureData->getPaint(reader);
410 TextContainer text; 427 TextContainer text;
411 get_text(reader, &text); 428 get_text(reader, &text);
412 size_t xCount = reader->readInt(); 429 size_t xCount = reader->readInt();
413 const SkScalar* xpos = (const SkScalar*)reader->skip((3 + xCount) * sizeof(SkScalar)); 430 const SkScalar* xpos = (const SkScalar*)reader->skip((3 + xCount) * sizeof(SkScalar));
414 const SkScalar top = *xpos++; 431 const SkScalar top = *xpos++;
415 const SkScalar bottom = *xpos++; 432 const SkScalar bottom = *xpos++;
416 const SkScalar constY = *xpos++; 433 const SkScalar constY = *xpos++;
417 if (!canvas->quickRejectY(top, bottom)) { 434 if (!canvas->quickRejectY(top, bottom) && paint) {
418 canvas->drawPosTextH(text.text(), text.length(), xpos, constY, p aint); 435 canvas->drawPosTextH(text.text(), text.length(), xpos, constY, * paint);
419 } 436 }
420 } break; 437 } break;
421 case DRAW_RECT: { 438 case DRAW_RECT: {
422 const SkPaint& paint = *fPictureData->getPaint(reader); 439 const SkPaint* paint = fPictureData->getPaint(reader);
423 SkRect rect; 440 SkRect rect;
424 reader->readRect(&rect); 441 reader->readRect(&rect);
425 canvas->drawRect(rect, paint); 442 if (paint) {
443 canvas->drawRect(rect, *paint);
444 }
426 } break; 445 } break;
427 case DRAW_RRECT: { 446 case DRAW_RRECT: {
428 const SkPaint& paint = *fPictureData->getPaint(reader); 447 const SkPaint* paint = fPictureData->getPaint(reader);
429 SkRRect rrect; 448 SkRRect rrect;
430 reader->readRRect(&rrect); 449 reader->readRRect(&rrect);
431 canvas->drawRRect(rrect, paint); 450 if (paint) {
451 canvas->drawRRect(rrect, *paint);
452 }
432 } break; 453 } break;
433 case DRAW_SPRITE: { 454 case DRAW_SPRITE: {
434 /* const SkPaint* paint = */ fPictureData->getPaint(reader); 455 /* const SkPaint* paint = */ fPictureData->getPaint(reader);
435 /* const SkBitmap bitmap = */ shallow_copy(fPictureData->getBitmap(r eader)); 456 /* const SkBitmap bitmap = */ shallow_copy(fPictureData->getBitmap(r eader));
436 /* int left = */ reader->readInt(); 457 /* int left = */ reader->readInt();
437 /* int top = */ reader->readInt(); 458 /* int top = */ reader->readInt();
438 // drawSprite removed dec-2015 459 // drawSprite removed dec-2015
439 } break; 460 } break;
440 case DRAW_TEXT: { 461 case DRAW_TEXT: {
441 const SkPaint& paint = *fPictureData->getPaint(reader); 462 const SkPaint* paint = fPictureData->getPaint(reader);
442 TextContainer text; 463 TextContainer text;
443 get_text(reader, &text); 464 get_text(reader, &text);
444 SkScalar x = reader->readScalar(); 465 SkScalar x = reader->readScalar();
445 SkScalar y = reader->readScalar(); 466 SkScalar y = reader->readScalar();
446 canvas->drawText(text.text(), text.length(), x, y, paint); 467 if (paint) {
468 canvas->drawText(text.text(), text.length(), x, y, *paint);
469 }
447 } break; 470 } break;
448 case DRAW_TEXT_BLOB: { 471 case DRAW_TEXT_BLOB: {
449 const SkPaint& paint = *fPictureData->getPaint(reader); 472 const SkPaint* paint = fPictureData->getPaint(reader);
450 const SkTextBlob* blob = fPictureData->getTextBlob(reader); 473 const SkTextBlob* blob = fPictureData->getTextBlob(reader);
451 SkScalar x = reader->readScalar(); 474 SkScalar x = reader->readScalar();
452 SkScalar y = reader->readScalar(); 475 SkScalar y = reader->readScalar();
453 canvas->drawTextBlob(blob, x, y, paint); 476 if (paint) {
477 canvas->drawTextBlob(blob, x, y, *paint);
478 }
454 } break; 479 } break;
455 case DRAW_TEXT_TOP_BOTTOM: { 480 case DRAW_TEXT_TOP_BOTTOM: {
456 const SkPaint& paint = *fPictureData->getPaint(reader); 481 const SkPaint* paint = fPictureData->getPaint(reader);
457 TextContainer text; 482 TextContainer text;
458 get_text(reader, &text); 483 get_text(reader, &text);
459 const SkScalar* ptr = (const SkScalar*)reader->skip(4 * sizeof(SkSca lar)); 484 const SkScalar* ptr = (const SkScalar*)reader->skip(4 * sizeof(SkSca lar));
460 // ptr[0] == x 485 // ptr[0] == x
461 // ptr[1] == y 486 // ptr[1] == y
462 // ptr[2] == top 487 // ptr[2] == top
463 // ptr[3] == bottom 488 // ptr[3] == bottom
464 if (!canvas->quickRejectY(ptr[2], ptr[3])) { 489 if (!canvas->quickRejectY(ptr[2], ptr[3]) && paint) {
465 canvas->drawText(text.text(), text.length(), ptr[0], ptr[1], pai nt); 490 canvas->drawText(text.text(), text.length(), ptr[0], ptr[1], *pa int);
466 } 491 }
467 } break; 492 } break;
468 case DRAW_TEXT_ON_PATH: { 493 case DRAW_TEXT_ON_PATH: {
469 const SkPaint& paint = *fPictureData->getPaint(reader); 494 const SkPaint* paint = fPictureData->getPaint(reader);
470 TextContainer text; 495 TextContainer text;
471 get_text(reader, &text); 496 get_text(reader, &text);
472 const SkPath& path = fPictureData->getPath(reader); 497 const SkPath& path = fPictureData->getPath(reader);
473 SkMatrix matrix; 498 SkMatrix matrix;
474 reader->readMatrix(&matrix); 499 reader->readMatrix(&matrix);
475 canvas->drawTextOnPath(text.text(), text.length(), path, &matrix, pa int); 500 if (paint) {
501 canvas->drawTextOnPath(text.text(), text.length(), path, &matrix , *paint);
502 }
476 } break; 503 } break;
477 case DRAW_VERTICES: { 504 case DRAW_VERTICES: {
478 sk_sp<SkXfermode> xfer; 505 sk_sp<SkXfermode> xfer;
479 const SkPaint& paint = *fPictureData->getPaint(reader); 506 const SkPaint* paint = fPictureData->getPaint(reader);
480 DrawVertexFlags flags = (DrawVertexFlags)reader->readInt(); 507 DrawVertexFlags flags = (DrawVertexFlags)reader->readInt();
481 SkCanvas::VertexMode vmode = (SkCanvas::VertexMode)reader->readInt() ; 508 SkCanvas::VertexMode vmode = (SkCanvas::VertexMode)reader->readInt() ;
482 int vCount = reader->readInt(); 509 int vCount = reader->readInt();
483 const SkPoint* verts = (const SkPoint*)reader->skip(vCount * sizeof( SkPoint)); 510 const SkPoint* verts = (const SkPoint*)reader->skip(vCount * sizeof( SkPoint));
484 const SkPoint* texs = nullptr; 511 const SkPoint* texs = nullptr;
485 const SkColor* colors = nullptr; 512 const SkColor* colors = nullptr;
486 const uint16_t* indices = nullptr; 513 const uint16_t* indices = nullptr;
487 int iCount = 0; 514 int iCount = 0;
488 if (flags & DRAW_VERTICES_HAS_TEXS) { 515 if (flags & DRAW_VERTICES_HAS_TEXS) {
489 texs = (const SkPoint*)reader->skip(vCount * sizeof(SkPoint)); 516 texs = (const SkPoint*)reader->skip(vCount * sizeof(SkPoint));
490 } 517 }
491 if (flags & DRAW_VERTICES_HAS_COLORS) { 518 if (flags & DRAW_VERTICES_HAS_COLORS) {
492 colors = (const SkColor*)reader->skip(vCount * sizeof(SkColor)); 519 colors = (const SkColor*)reader->skip(vCount * sizeof(SkColor));
493 } 520 }
494 if (flags & DRAW_VERTICES_HAS_INDICES) { 521 if (flags & DRAW_VERTICES_HAS_INDICES) {
495 iCount = reader->readInt(); 522 iCount = reader->readInt();
496 indices = (const uint16_t*)reader->skip(iCount * sizeof(uint16_t )); 523 indices = (const uint16_t*)reader->skip(iCount * sizeof(uint16_t ));
497 } 524 }
498 if (flags & DRAW_VERTICES_HAS_XFER) { 525 if (flags & DRAW_VERTICES_HAS_XFER) {
499 int mode = reader->readInt(); 526 int mode = reader->readInt();
500 if (mode < 0 || mode > SkXfermode::kLastMode) { 527 if (mode < 0 || mode > SkXfermode::kLastMode) {
501 mode = SkXfermode::kModulate_Mode; 528 mode = SkXfermode::kModulate_Mode;
502 } 529 }
503 xfer = SkXfermode::Make((SkXfermode::Mode)mode); 530 xfer = SkXfermode::Make((SkXfermode::Mode)mode);
504 } 531 }
505 canvas->drawVertices(vmode, vCount, verts, texs, colors, xfer, indic es, iCount, paint); 532 if (paint) {
533 canvas->drawVertices(vmode, vCount, verts, texs, colors,
534 xfer, indices, iCount, *paint);
535 }
506 } break; 536 } break;
507 case RESTORE: 537 case RESTORE:
508 canvas->restore(); 538 canvas->restore();
509 break; 539 break;
510 case ROTATE: 540 case ROTATE:
511 canvas->rotate(reader->readScalar()); 541 canvas->rotate(reader->readScalar());
512 break; 542 break;
513 case SAVE: 543 case SAVE:
514 // SKPs with version < 29 also store a SaveFlags param. 544 // SKPs with version < 29 also store a SaveFlags param.
515 if (size > 4) { 545 if (size > 4) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 } break; 599 } break;
570 case TRANSLATE: { 600 case TRANSLATE: {
571 SkScalar dx = reader->readScalar(); 601 SkScalar dx = reader->readScalar();
572 SkScalar dy = reader->readScalar(); 602 SkScalar dy = reader->readScalar();
573 canvas->translate(dx, dy); 603 canvas->translate(dx, dy);
574 } break; 604 } break;
575 default: 605 default:
576 SkASSERTF(false, "Unknown draw type: %d", op); 606 SkASSERTF(false, "Unknown draw type: %d", op);
577 } 607 }
578 } 608 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698