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

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

Issue 2205273003: Add onDrawBitmapLattice(), avoid unnecessary bitmap->image copy (Closed) Base URL: https://skia.googlesource.com/skia.git@copypaste
Patch Set: Move bitmap virtual into SkBaseDevice Created 4 years, 4 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
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 "SkPictureRecord.h" 8 #include "SkPictureRecord.h"
9 #include "SkImage_Base.h" 9 #include "SkImage_Base.h"
10 #include "SkPatchUtils.h" 10 #include "SkPatchUtils.h"
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 // op + paint_index + image_index + x + y 503 // op + paint_index + image_index + x + y
504 size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar); 504 size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar);
505 size_t initialOffset = this->addDraw(DRAW_IMAGE, &size); 505 size_t initialOffset = this->addDraw(DRAW_IMAGE, &size);
506 this->addPaintPtr(paint); 506 this->addPaintPtr(paint);
507 this->addImage(image); 507 this->addImage(image);
508 this->addScalar(x); 508 this->addScalar(x);
509 this->addScalar(y); 509 this->addScalar(y);
510 this->validate(initialOffset, size); 510 this->validate(initialOffset, size);
511 } 511 }
512 512
513 void SkPictureRecord::onDrawImageLattice(const SkImage* image, const Lattice& la ttice,
514 const SkRect& dst, const SkPaint* paint ) {
515 // xCount + xDivs + yCount+ yDivs
516 size_t latticeSize = (1 + lattice.fXCount + 1 + lattice.fYCount) * kUInt32Si ze;
517
518 // op + paint index + image index + lattice + dst rect
519 size_t size = 3 * kUInt32Size + latticeSize + sizeof(dst);
520 size_t initialOffset = this->addDraw(DRAW_IMAGE_LATTICE, &size);
521 this->addPaintPtr(paint);
522 this->addImage(image);
523 this->addInt(lattice.fXCount);
524 fWriter.writePad(lattice.fXDivs, lattice.fXCount * kUInt32Size);
525 this->addInt(lattice.fYCount);
526 fWriter.writePad(lattice.fYDivs, lattice.fYCount * kUInt32Size);
527 this->addRect(dst);
528 this->validate(initialOffset, size);
529 }
530
531 void SkPictureRecord::onDrawImageRect(const SkImage* image, const SkRect* src, c onst SkRect& dst, 513 void SkPictureRecord::onDrawImageRect(const SkImage* image, const SkRect* src, c onst SkRect& dst,
532 const SkPaint* paint, SrcRectConstraint co nstraint) { 514 const SkPaint* paint, SrcRectConstraint co nstraint) {
533 // id + paint_index + image_index + bool_for_src + constraint 515 // id + paint_index + image_index + bool_for_src + constraint
534 size_t size = 5 * kUInt32Size; 516 size_t size = 5 * kUInt32Size;
535 if (src) { 517 if (src) {
536 size += sizeof(*src); // + rect 518 size += sizeof(*src); // + rect
537 } 519 }
538 size += sizeof(dst); // + rect 520 size += sizeof(dst); // + rect
539 521
540 size_t initialOffset = this->addDraw(DRAW_IMAGE_RECT, &size); 522 size_t initialOffset = this->addDraw(DRAW_IMAGE_RECT, &size);
(...skipping 23 matching lines...) Expand all
564 // op + paint index + bitmap id + center + dst rect 546 // op + paint index + bitmap id + center + dst rect
565 size_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst); 547 size_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst);
566 size_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size); 548 size_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size);
567 this->addPaintPtr(paint); 549 this->addPaintPtr(paint);
568 this->addBitmap(bitmap); 550 this->addBitmap(bitmap);
569 this->addIRect(center); 551 this->addIRect(center);
570 this->addRect(dst); 552 this->addRect(dst);
571 this->validate(initialOffset, size); 553 this->validate(initialOffset, size);
572 } 554 }
573 555
556 void SkPictureRecord::onDrawImageLattice(const SkImage* image, const Lattice& la ttice,
557 const SkRect& dst, const SkPaint* paint ) {
558 // xCount + xDivs + yCount+ yDivs
559 size_t latticeSize = (1 + lattice.fXCount + 1 + lattice.fYCount) * kUInt32Si ze;
560
561 // op + paint index + image index + lattice + dst rect
562 size_t size = 3 * kUInt32Size + latticeSize + sizeof(dst);
563 size_t initialOffset = this->addDraw(DRAW_IMAGE_LATTICE, &size);
564 this->addPaintPtr(paint);
565 this->addImage(image);
566 this->addInt(lattice.fXCount);
567 fWriter.writePad(lattice.fXDivs, lattice.fXCount * kUInt32Size);
568 this->addInt(lattice.fYCount);
569 fWriter.writePad(lattice.fYDivs, lattice.fYCount * kUInt32Size);
570 this->addRect(dst);
571 this->validate(initialOffset, size);
572 }
573
574 void SkPictureRecord::onDrawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice,
575 const SkRect& dst, const SkPaint* pain t) {
576 sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap);
577 this->onDrawImageLattice(image.get(), lattice, dst, paint);
578 }
579
574 void SkPictureRecord::onDrawText(const void* text, size_t byteLength, SkScalar x , SkScalar y, 580 void SkPictureRecord::onDrawText(const void* text, size_t byteLength, SkScalar x , SkScalar y,
575 const SkPaint& paint) { 581 const SkPaint& paint) {
576 // op + paint index + length + 'length' worth of chars + x + y 582 // op + paint index + length + 'length' worth of chars + x + y
577 size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 2 * sizeof(SkScalar); 583 size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 2 * sizeof(SkScalar);
578 584
579 DrawType op = DRAW_TEXT; 585 DrawType op = DRAW_TEXT;
580 size_t initialOffset = this->addDraw(op, &size); 586 size_t initialOffset = this->addDraw(op, &size);
581 this->addPaint(paint); 587 this->addPaint(paint);
582 this->addText(text, byteLength); 588 this->addText(text, byteLength);
583 this->addScalar(x); 589 this->addScalar(x);
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 1077
1072 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) { 1078 void SkPictureRecord::addTextBlob(const SkTextBlob *blob) {
1073 int index = fTextBlobRefs.count(); 1079 int index = fTextBlobRefs.count();
1074 *fTextBlobRefs.append() = blob; 1080 *fTextBlobRefs.append() = blob;
1075 blob->ref(); 1081 blob->ref();
1076 // follow the convention of recording a 1-based index 1082 // follow the convention of recording a 1-based index
1077 this->addInt(index + 1); 1083 this->addInt(index + 1);
1078 } 1084 }
1079 1085
1080 /////////////////////////////////////////////////////////////////////////////// 1086 ///////////////////////////////////////////////////////////////////////////////
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698