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

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

Issue 1316233002: Style Change: NULL->nullptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-27 (Thursday) 10:25:06 EDT Created 5 years, 3 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 | « src/core/SkCachedData.cpp ('k') | src/core/SkChunkAlloc.cpp » ('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 * Copyright 2008 The Android Open Source Project 2 * Copyright 2008 The Android Open Source Project
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 "SkBitmapDevice.h" 8 #include "SkBitmapDevice.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkCanvasPriv.h" 10 #include "SkCanvasPriv.h"
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 DeviceCM* fNext; 187 DeviceCM* fNext;
188 SkBaseDevice* fDevice; 188 SkBaseDevice* fDevice;
189 SkRasterClip fClip; 189 SkRasterClip fClip;
190 SkPaint* fPaint; // may be null (in the future) 190 SkPaint* fPaint; // may be null (in the future)
191 const SkMatrix* fMatrix; 191 const SkMatrix* fMatrix;
192 SkMatrix fMatrixStorage; 192 SkMatrix fMatrixStorage;
193 const bool fDeviceIsBitmapDevice; 193 const bool fDeviceIsBitmapDevice;
194 194
195 DeviceCM(SkBaseDevice* device, const SkPaint* paint, SkCanvas* canvas, 195 DeviceCM(SkBaseDevice* device, const SkPaint* paint, SkCanvas* canvas,
196 bool conservativeRasterClip, bool deviceIsBitmapDevice) 196 bool conservativeRasterClip, bool deviceIsBitmapDevice)
197 : fNext(NULL) 197 : fNext(nullptr)
198 , fClip(conservativeRasterClip) 198 , fClip(conservativeRasterClip)
199 , fDeviceIsBitmapDevice(deviceIsBitmapDevice) 199 , fDeviceIsBitmapDevice(deviceIsBitmapDevice)
200 { 200 {
201 if (NULL != device) { 201 if (nullptr != device) {
202 device->ref(); 202 device->ref();
203 device->onAttachToCanvas(canvas); 203 device->onAttachToCanvas(canvas);
204 } 204 }
205 fDevice = device; 205 fDevice = device;
206 fPaint = paint ? new SkPaint(*paint) : NULL; 206 fPaint = paint ? new SkPaint(*paint) : nullptr;
207 } 207 }
208 208
209 ~DeviceCM() { 209 ~DeviceCM() {
210 if (fDevice) { 210 if (fDevice) {
211 fDevice->onDetachFromCanvas(); 211 fDevice->onDetachFromCanvas();
212 fDevice->unref(); 212 fDevice->unref();
213 } 213 }
214 delete fPaint; 214 delete fPaint;
215 } 215 }
216 216
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 bitmap/device to draw into from this level. This value is NOT 277 bitmap/device to draw into from this level. This value is NOT
278 reference counted, since the real owner is either our fLayer field, 278 reference counted, since the real owner is either our fLayer field,
279 or a previous one in a lower level.) 279 or a previous one in a lower level.)
280 */ 280 */
281 DeviceCM* fTopLayer; 281 DeviceCM* fTopLayer;
282 SkRasterClip fRasterClip; 282 SkRasterClip fRasterClip;
283 SkMatrix fMatrix; 283 SkMatrix fMatrix;
284 int fDeferredSaveCount; 284 int fDeferredSaveCount;
285 285
286 MCRec(bool conservativeRasterClip) : fRasterClip(conservativeRasterClip) { 286 MCRec(bool conservativeRasterClip) : fRasterClip(conservativeRasterClip) {
287 fFilter = NULL; 287 fFilter = nullptr;
288 fLayer = NULL; 288 fLayer = nullptr;
289 fTopLayer = NULL; 289 fTopLayer = nullptr;
290 fMatrix.reset(); 290 fMatrix.reset();
291 fDeferredSaveCount = 0; 291 fDeferredSaveCount = 0;
292 292
293 // don't bother initializing fNext 293 // don't bother initializing fNext
294 inc_rec(); 294 inc_rec();
295 } 295 }
296 MCRec(const MCRec& prev) : fRasterClip(prev.fRasterClip), fMatrix(prev.fMatr ix) { 296 MCRec(const MCRec& prev) : fRasterClip(prev.fRasterClip), fMatrix(prev.fMatr ix) {
297 fFilter = SkSafeRef(prev.fFilter); 297 fFilter = SkSafeRef(prev.fFilter);
298 fLayer = NULL; 298 fLayer = nullptr;
299 fTopLayer = prev.fTopLayer; 299 fTopLayer = prev.fTopLayer;
300 fDeferredSaveCount = 0; 300 fDeferredSaveCount = 0;
301 301
302 // don't bother initializing fNext 302 // don't bother initializing fNext
303 inc_rec(); 303 inc_rec();
304 } 304 }
305 ~MCRec() { 305 ~MCRec() {
306 SkSafeUnref(fFilter); 306 SkSafeUnref(fFilter);
307 delete fLayer; 307 delete fLayer;
308 dec_rec(); 308 dec_rec();
(...skipping 30 matching lines...) Expand all
339 } 339 }
340 340
341 const DeviceCM* rec = fCurrLayer; 341 const DeviceCM* rec = fCurrLayer;
342 if (rec && rec->fDevice) { 342 if (rec && rec->fDevice) {
343 343
344 fMatrix = rec->fMatrix; 344 fMatrix = rec->fMatrix;
345 fClip = &((SkRasterClip*)&rec->fClip)->forceGetBW(); 345 fClip = &((SkRasterClip*)&rec->fClip)->forceGetBW();
346 fRC = &rec->fClip; 346 fRC = &rec->fClip;
347 fDevice = rec->fDevice; 347 fDevice = rec->fDevice;
348 if (!fDevice->accessPixels(&fDst)) { 348 if (!fDevice->accessPixels(&fDst)) {
349 fDst.reset(fDevice->imageInfo(), NULL, 0); 349 fDst.reset(fDevice->imageInfo(), nullptr, 0);
350 } 350 }
351 fPaint = rec->fPaint; 351 fPaint = rec->fPaint;
352 SkDEBUGCODE(this->validate();) 352 SkDEBUGCODE(this->validate();)
353 353
354 fCurrLayer = rec->fNext; 354 fCurrLayer = rec->fNext;
355 // fCurrLayer may be NULL now 355 // fCurrLayer may be nullptr now
356 356
357 return true; 357 return true;
358 } 358 }
359 return false; 359 return false;
360 } 360 }
361 361
362 SkBaseDevice* getDevice() const { return fDevice; } 362 SkBaseDevice* getDevice() const { return fDevice; }
363 int getX() const { return fDevice->getOrigin().x(); } 363 int getX() const { return fDevice->getOrigin().x(); }
364 int getY() const { return fDevice->getOrigin().y(); } 364 int getY() const { return fDevice->getOrigin().y(); }
365 const SkMatrix& getMatrix() const { return *fMatrix; } 365 const SkMatrix& getMatrix() const { return *fMatrix; }
(...skipping 10 matching lines...) Expand all
376 }; 376 };
377 377
378 ///////////////////////////////////////////////////////////////////////////// 378 /////////////////////////////////////////////////////////////////////////////
379 379
380 static SkPaint* set_if_needed(SkLazyPaint* lazy, const SkPaint& orig) { 380 static SkPaint* set_if_needed(SkLazyPaint* lazy, const SkPaint& orig) {
381 return lazy->isValid() ? lazy->get() : lazy->set(orig); 381 return lazy->isValid() ? lazy->get() : lazy->set(orig);
382 } 382 }
383 383
384 /** 384 /**
385 * If the paint has an imagefilter, but it can be simplified to just a colorfil ter, return that 385 * If the paint has an imagefilter, but it can be simplified to just a colorfil ter, return that
386 * colorfilter, else return NULL. 386 * colorfilter, else return nullptr.
387 */ 387 */
388 static SkColorFilter* image_to_color_filter(const SkPaint& paint) { 388 static SkColorFilter* image_to_color_filter(const SkPaint& paint) {
389 SkImageFilter* imgf = paint.getImageFilter(); 389 SkImageFilter* imgf = paint.getImageFilter();
390 if (!imgf) { 390 if (!imgf) {
391 return NULL; 391 return nullptr;
392 } 392 }
393 393
394 SkColorFilter* imgCF; 394 SkColorFilter* imgCF;
395 if (!imgf->asAColorFilter(&imgCF)) { 395 if (!imgf->asAColorFilter(&imgCF)) {
396 return NULL; 396 return nullptr;
397 } 397 }
398 398
399 SkColorFilter* paintCF = paint.getColorFilter(); 399 SkColorFilter* paintCF = paint.getColorFilter();
400 if (NULL == paintCF) { 400 if (nullptr == paintCF) {
401 // there is no existing paint colorfilter, so we can just return the ima gefilter's 401 // there is no existing paint colorfilter, so we can just return the ima gefilter's
402 return imgCF; 402 return imgCF;
403 } 403 }
404 404
405 // The paint has both a colorfilter(paintCF) and an imagefilter-which-is-a-c olorfilter(imgCF) 405 // The paint has both a colorfilter(paintCF) and an imagefilter-which-is-a-c olorfilter(imgCF)
406 // and we need to combine them into a single colorfilter. 406 // and we need to combine them into a single colorfilter.
407 SkAutoTUnref<SkColorFilter> autoImgCF(imgCF); 407 SkAutoTUnref<SkColorFilter> autoImgCF(imgCF);
408 return SkColorFilter::CreateComposeFilter(imgCF, paintCF); 408 return SkColorFilter::CreateComposeFilter(imgCF, paintCF);
409 } 409 }
410 410
411 class AutoDrawLooper { 411 class AutoDrawLooper {
412 public: 412 public:
413 AutoDrawLooper(SkCanvas* canvas, const SkSurfaceProps& props, const SkPaint& paint, 413 AutoDrawLooper(SkCanvas* canvas, const SkSurfaceProps& props, const SkPaint& paint,
414 bool skipLayerForImageFilter = false, 414 bool skipLayerForImageFilter = false,
415 const SkRect* bounds = NULL) : fOrigPaint(paint) { 415 const SkRect* bounds = nullptr) : fOrigPaint(paint) {
416 fCanvas = canvas; 416 fCanvas = canvas;
417 fFilter = canvas->getDrawFilter(); 417 fFilter = canvas->getDrawFilter();
418 fPaint = &fOrigPaint; 418 fPaint = &fOrigPaint;
419 fSaveCount = canvas->getSaveCount(); 419 fSaveCount = canvas->getSaveCount();
420 fTempLayerForImageFilter = false; 420 fTempLayerForImageFilter = false;
421 fDone = false; 421 fDone = false;
422 422
423 SkColorFilter* simplifiedCF = image_to_color_filter(fOrigPaint); 423 SkColorFilter* simplifiedCF = image_to_color_filter(fOrigPaint);
424 if (simplifiedCF) { 424 if (simplifiedCF) {
425 SkPaint* paint = set_if_needed(&fLazyPaintInit, fOrigPaint); 425 SkPaint* paint = set_if_needed(&fLazyPaintInit, fOrigPaint);
426 paint->setColorFilter(simplifiedCF)->unref(); 426 paint->setColorFilter(simplifiedCF)->unref();
427 paint->setImageFilter(NULL); 427 paint->setImageFilter(nullptr);
428 fPaint = paint; 428 fPaint = paint;
429 } 429 }
430 430
431 if (!skipLayerForImageFilter && fPaint->getImageFilter()) { 431 if (!skipLayerForImageFilter && fPaint->getImageFilter()) {
432 /** 432 /**
433 * We implement ImageFilters for a given draw by creating a layer, then applying the 433 * We implement ImageFilters for a given draw by creating a layer, then applying the
434 * imagefilter to the pixels of that layer (its backing surface/ima ge), and then 434 * imagefilter to the pixels of that layer (its backing surface/ima ge), and then
435 * we call restore() to xfer that layer to the main canvas. 435 * we call restore() to xfer that layer to the main canvas.
436 * 436 *
437 * 1. SaveLayer (with a paint containing the current imagefilter an d xfermode) 437 * 1. SaveLayer (with a paint containing the current imagefilter an d xfermode)
(...skipping 14 matching lines...) Expand all
452 fTempLayerForImageFilter = true; 452 fTempLayerForImageFilter = true;
453 // we remove the imagefilter/xfermode inside doNext() 453 // we remove the imagefilter/xfermode inside doNext()
454 } 454 }
455 455
456 if (SkDrawLooper* looper = paint.getLooper()) { 456 if (SkDrawLooper* looper = paint.getLooper()) {
457 void* buffer = fLooperContextAllocator.reserveT<SkDrawLooper::Contex t>( 457 void* buffer = fLooperContextAllocator.reserveT<SkDrawLooper::Contex t>(
458 looper->contextSize()); 458 looper->contextSize());
459 fLooperContext = looper->createContext(canvas, buffer); 459 fLooperContext = looper->createContext(canvas, buffer);
460 fIsSimple = false; 460 fIsSimple = false;
461 } else { 461 } else {
462 fLooperContext = NULL; 462 fLooperContext = nullptr;
463 // can we be marked as simple? 463 // can we be marked as simple?
464 fIsSimple = !fFilter && !fTempLayerForImageFilter; 464 fIsSimple = !fFilter && !fTempLayerForImageFilter;
465 } 465 }
466 466
467 uint32_t oldFlags = paint.getFlags(); 467 uint32_t oldFlags = paint.getFlags();
468 fNewPaintFlags = filter_paint_flags(props, oldFlags); 468 fNewPaintFlags = filter_paint_flags(props, oldFlags);
469 if (fIsSimple && (fNewPaintFlags != oldFlags)) { 469 if (fIsSimple && (fNewPaintFlags != oldFlags)) {
470 SkPaint* paint = set_if_needed(&fLazyPaintInit, fOrigPaint); 470 SkPaint* paint = set_if_needed(&fLazyPaintInit, fOrigPaint);
471 paint->setFlags(fNewPaintFlags); 471 paint->setFlags(fNewPaintFlags);
472 fPaint = paint; 472 fPaint = paint;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 bool fTempLayerForImageFilter; 509 bool fTempLayerForImageFilter;
510 bool fDone; 510 bool fDone;
511 bool fIsSimple; 511 bool fIsSimple;
512 SkDrawLooper::Context* fLooperContext; 512 SkDrawLooper::Context* fLooperContext;
513 SkSmallAllocator<1, 32> fLooperContextAllocator; 513 SkSmallAllocator<1, 32> fLooperContextAllocator;
514 514
515 bool doNext(SkDrawFilter::Type drawType); 515 bool doNext(SkDrawFilter::Type drawType);
516 }; 516 };
517 517
518 bool AutoDrawLooper::doNext(SkDrawFilter::Type drawType) { 518 bool AutoDrawLooper::doNext(SkDrawFilter::Type drawType) {
519 fPaint = NULL; 519 fPaint = nullptr;
520 SkASSERT(!fIsSimple); 520 SkASSERT(!fIsSimple);
521 SkASSERT(fLooperContext || fFilter || fTempLayerForImageFilter); 521 SkASSERT(fLooperContext || fFilter || fTempLayerForImageFilter);
522 522
523 SkPaint* paint = fLazyPaintPerLooper.set(fLazyPaintInit.isValid() ? 523 SkPaint* paint = fLazyPaintPerLooper.set(fLazyPaintInit.isValid() ?
524 *fLazyPaintInit.get() : fOrigPaint) ; 524 *fLazyPaintInit.get() : fOrigPaint) ;
525 paint->setFlags(fNewPaintFlags); 525 paint->setFlags(fNewPaintFlags);
526 526
527 if (fTempLayerForImageFilter) { 527 if (fTempLayerForImageFilter) {
528 paint->setImageFilter(NULL); 528 paint->setImageFilter(nullptr);
529 paint->setXfermode(NULL); 529 paint->setXfermode(nullptr);
530 } 530 }
531 531
532 if (fLooperContext && !fLooperContext->next(fCanvas, paint)) { 532 if (fLooperContext && !fLooperContext->next(fCanvas, paint)) {
533 fDone = true; 533 fDone = true;
534 return false; 534 return false;
535 } 535 }
536 if (fFilter) { 536 if (fFilter) {
537 if (!fFilter->filter(paint, drawType)) { 537 if (!fFilter->filter(paint, drawType)) {
538 fDone = true; 538 fDone = true;
539 return false; 539 return false;
540 } 540 }
541 if (NULL == fLooperContext) { 541 if (nullptr == fLooperContext) {
542 // no looper means we only draw once 542 // no looper means we only draw once
543 fDone = true; 543 fDone = true;
544 } 544 }
545 } 545 }
546 fPaint = paint; 546 fPaint = paint;
547 547
548 // if we only came in here for the imagefilter, mark us as done 548 // if we only came in here for the imagefilter, mark us as done
549 if (!fLooperContext && !fFilter) { 549 if (!fLooperContext && !fFilter) {
550 fDone = true; 550 fDone = true;
551 } 551 }
552 552
553 // call this after any possible paint modifiers 553 // call this after any possible paint modifiers
554 if (fPaint->nothingToDraw()) { 554 if (fPaint->nothingToDraw()) {
555 fPaint = NULL; 555 fPaint = nullptr;
556 return false; 556 return false;
557 } 557 }
558 return true; 558 return true;
559 } 559 }
560 560
561 ////////// macros to place around the internal draw calls ////////////////// 561 ////////// macros to place around the internal draw calls //////////////////
562 562
563 #define LOOPER_BEGIN_DRAWDEVICE(paint, type) \ 563 #define LOOPER_BEGIN_DRAWDEVICE(paint, type) \
564 this->predrawNotify(); \ 564 this->predrawNotify(); \
565 AutoDrawLooper looper(this, fProps, paint, true); \ 565 AutoDrawLooper looper(this, fProps, paint, true); \
(...skipping 29 matching lines...) Expand all
595 } 595 }
596 596
597 SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) { 597 SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) {
598 fConservativeRasterClip = SkToBool(flags & kConservativeRasterClip_InitFlag) ; 598 fConservativeRasterClip = SkToBool(flags & kConservativeRasterClip_InitFlag) ;
599 fCachedLocalClipBounds.setEmpty(); 599 fCachedLocalClipBounds.setEmpty();
600 fCachedLocalClipBoundsDirty = true; 600 fCachedLocalClipBoundsDirty = true;
601 fAllowSoftClip = true; 601 fAllowSoftClip = true;
602 fAllowSimplifyClip = false; 602 fAllowSimplifyClip = false;
603 fDeviceCMDirty = true; 603 fDeviceCMDirty = true;
604 fSaveCount = 1; 604 fSaveCount = 1;
605 fMetaData = NULL; 605 fMetaData = nullptr;
606 606
607 fClipStack.reset(new SkClipStack); 607 fClipStack.reset(new SkClipStack);
608 608
609 fMCRec = (MCRec*)fMCStack.push_back(); 609 fMCRec = (MCRec*)fMCStack.push_back();
610 new (fMCRec) MCRec(fConservativeRasterClip); 610 new (fMCRec) MCRec(fConservativeRasterClip);
611 611
612 SkASSERT(sizeof(DeviceCM) <= sizeof(fDeviceCMStorage)); 612 SkASSERT(sizeof(DeviceCM) <= sizeof(fDeviceCMStorage));
613 fMCRec->fLayer = (DeviceCM*)fDeviceCMStorage; 613 fMCRec->fLayer = (DeviceCM*)fDeviceCMStorage;
614 new (fDeviceCMStorage) DeviceCM(NULL, NULL, NULL, fConservativeRasterClip, f alse); 614 new (fDeviceCMStorage) DeviceCM(nullptr, nullptr, nullptr, fConservativeRast erClip, false);
615 615
616 fMCRec->fTopLayer = fMCRec->fLayer; 616 fMCRec->fTopLayer = fMCRec->fLayer;
617 617
618 fSurfaceBase = NULL; 618 fSurfaceBase = nullptr;
619 619
620 if (device) { 620 if (device) {
621 // The root device and the canvas should always have the same pixel geom etry 621 // The root device and the canvas should always have the same pixel geom etry
622 SkASSERT(fProps.pixelGeometry() == device->surfaceProps().pixelGeometry( )); 622 SkASSERT(fProps.pixelGeometry() == device->surfaceProps().pixelGeometry( ));
623 if (device->forceConservativeRasterClip()) { 623 if (device->forceConservativeRasterClip()) {
624 fConservativeRasterClip = true; 624 fConservativeRasterClip = true;
625 } 625 }
626 device->onAttachToCanvas(this); 626 device->onAttachToCanvas(this);
627 fMCRec->fLayer->fDevice = SkRef(device); 627 fMCRec->fLayer->fDevice = SkRef(device);
628 fMCRec->fRasterClip.setRect(device->getGlobalBounds()); 628 fMCRec->fRasterClip.setRect(device->getGlobalBounds());
629 } 629 }
630 return device; 630 return device;
631 } 631 }
632 632
633 SkCanvas::SkCanvas() 633 SkCanvas::SkCanvas()
634 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) 634 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
635 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) 635 , fProps(SkSurfaceProps::kLegacyFontHost_InitType)
636 { 636 {
637 inc_canvas(); 637 inc_canvas();
638 638
639 this->init(NULL, kDefault_InitFlags); 639 this->init(nullptr, kDefault_InitFlags);
640 } 640 }
641 641
642 static SkBitmap make_nopixels(int width, int height) { 642 static SkBitmap make_nopixels(int width, int height) {
643 SkBitmap bitmap; 643 SkBitmap bitmap;
644 bitmap.setInfo(SkImageInfo::MakeUnknown(width, height)); 644 bitmap.setInfo(SkImageInfo::MakeUnknown(width, height));
645 return bitmap; 645 return bitmap;
646 } 646 }
647 647
648 class SkNoPixelsBitmapDevice : public SkBitmapDevice { 648 class SkNoPixelsBitmapDevice : public SkBitmapDevice {
649 public: 649 public:
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 732
733 SkDrawFilter* SkCanvas::setDrawFilter(SkDrawFilter* filter) { 733 SkDrawFilter* SkCanvas::setDrawFilter(SkDrawFilter* filter) {
734 this->checkForDeferredSave(); 734 this->checkForDeferredSave();
735 SkRefCnt_SafeAssign(fMCRec->fFilter, filter); 735 SkRefCnt_SafeAssign(fMCRec->fFilter, filter);
736 return filter; 736 return filter;
737 } 737 }
738 738
739 SkMetaData& SkCanvas::getMetaData() { 739 SkMetaData& SkCanvas::getMetaData() {
740 // metadata users are rare, so we lazily allocate it. If that changes we 740 // metadata users are rare, so we lazily allocate it. If that changes we
741 // can decide to just make it a field in the device (rather than a ptr) 741 // can decide to just make it a field in the device (rather than a ptr)
742 if (NULL == fMetaData) { 742 if (nullptr == fMetaData) {
743 fMetaData = new SkMetaData; 743 fMetaData = new SkMetaData;
744 } 744 }
745 return *fMetaData; 745 return *fMetaData;
746 } 746 }
747 747
748 /////////////////////////////////////////////////////////////////////////////// 748 ///////////////////////////////////////////////////////////////////////////////
749 749
750 void SkCanvas::flush() { 750 void SkCanvas::flush() {
751 SkBaseDevice* device = this->getDevice(); 751 SkBaseDevice* device = this->getDevice();
752 if (device) { 752 if (device) {
(...skipping 29 matching lines...) Expand all
782 } 782 }
783 return fMCRec->fTopLayer->fDevice; 783 return fMCRec->fTopLayer->fDevice;
784 } 784 }
785 785
786 bool SkCanvas::readPixels(SkBitmap* bitmap, int x, int y) { 786 bool SkCanvas::readPixels(SkBitmap* bitmap, int x, int y) {
787 if (kUnknown_SkColorType == bitmap->colorType() || bitmap->getTexture()) { 787 if (kUnknown_SkColorType == bitmap->colorType() || bitmap->getTexture()) {
788 return false; 788 return false;
789 } 789 }
790 790
791 bool weAllocated = false; 791 bool weAllocated = false;
792 if (NULL == bitmap->pixelRef()) { 792 if (nullptr == bitmap->pixelRef()) {
793 if (!bitmap->tryAllocPixels()) { 793 if (!bitmap->tryAllocPixels()) {
794 return false; 794 return false;
795 } 795 }
796 weAllocated = true; 796 weAllocated = true;
797 } 797 }
798 798
799 SkAutoPixmapUnlock unlocker; 799 SkAutoPixmapUnlock unlocker;
800 if (bitmap->requestLock(&unlocker)) { 800 if (bitmap->requestLock(&unlocker)) {
801 const SkPixmap& pm = unlocker.pixmap(); 801 const SkPixmap& pm = unlocker.pixmap();
802 if (this->readPixels(pm.info(), pm.writable_addr(), pm.rowBytes(), x, y) ) { 802 if (this->readPixels(pm.info(), pm.writable_addr(), pm.rowBytes(), x, y) ) {
803 return true; 803 return true;
804 } 804 }
805 } 805 }
806 806
807 if (weAllocated) { 807 if (weAllocated) {
808 bitmap->setPixelRef(NULL); 808 bitmap->setPixelRef(nullptr);
809 } 809 }
810 return false; 810 return false;
811 } 811 }
812 812
813 bool SkCanvas::readPixels(const SkIRect& srcRect, SkBitmap* bitmap) { 813 bool SkCanvas::readPixels(const SkIRect& srcRect, SkBitmap* bitmap) {
814 SkIRect r = srcRect; 814 SkIRect r = srcRect;
815 const SkISize size = this->getBaseLayerSize(); 815 const SkISize size = this->getBaseLayerSize();
816 if (!r.intersect(0, 0, size.width(), size.height())) { 816 if (!r.intersect(0, 0, size.width(), size.height())) {
817 bitmap->reset(); 817 bitmap->reset();
818 return false; 818 return false;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 860
861 bool SkCanvas::writePixels(const SkImageInfo& origInfo, const void* pixels, size _t rowBytes, 861 bool SkCanvas::writePixels(const SkImageInfo& origInfo, const void* pixels, size _t rowBytes,
862 int x, int y) { 862 int x, int y) {
863 switch (origInfo.colorType()) { 863 switch (origInfo.colorType()) {
864 case kUnknown_SkColorType: 864 case kUnknown_SkColorType:
865 case kIndex_8_SkColorType: 865 case kIndex_8_SkColorType:
866 return false; 866 return false;
867 default: 867 default:
868 break; 868 break;
869 } 869 }
870 if (NULL == pixels || rowBytes < origInfo.minRowBytes()) { 870 if (nullptr == pixels || rowBytes < origInfo.minRowBytes()) {
871 return false; 871 return false;
872 } 872 }
873 873
874 const SkISize size = this->getBaseLayerSize(); 874 const SkISize size = this->getBaseLayerSize();
875 SkIRect target = SkIRect::MakeXYWH(x, y, origInfo.width(), origInfo.height() ); 875 SkIRect target = SkIRect::MakeXYWH(x, y, origInfo.width(), origInfo.height() );
876 if (!target.intersect(0, 0, size.width(), size.height())) { 876 if (!target.intersect(0, 0, size.width(), size.height())) {
877 return false; 877 return false;
878 } 878 }
879 879
880 SkBaseDevice* device = this->getDevice(); 880 SkBaseDevice* device = this->getDevice();
(...skipping 27 matching lines...) Expand all
908 } 908 }
909 909
910 ////////////////////////////////////////////////////////////////////////////// 910 //////////////////////////////////////////////////////////////////////////////
911 911
912 void SkCanvas::updateDeviceCMCache() { 912 void SkCanvas::updateDeviceCMCache() {
913 if (fDeviceCMDirty) { 913 if (fDeviceCMDirty) {
914 const SkMatrix& totalMatrix = this->getTotalMatrix(); 914 const SkMatrix& totalMatrix = this->getTotalMatrix();
915 const SkRasterClip& totalClip = fMCRec->fRasterClip; 915 const SkRasterClip& totalClip = fMCRec->fRasterClip;
916 DeviceCM* layer = fMCRec->fTopLayer; 916 DeviceCM* layer = fMCRec->fTopLayer;
917 917
918 if (NULL == layer->fNext) { // only one layer 918 if (nullptr == layer->fNext) { // only one layer
919 layer->updateMC(totalMatrix, totalClip, *fClipStack, NULL); 919 layer->updateMC(totalMatrix, totalClip, *fClipStack, nullptr);
920 } else { 920 } else {
921 SkRasterClip clip(totalClip); 921 SkRasterClip clip(totalClip);
922 do { 922 do {
923 layer->updateMC(totalMatrix, clip, *fClipStack, &clip); 923 layer->updateMC(totalMatrix, clip, *fClipStack, &clip);
924 } while ((layer = layer->fNext) != NULL); 924 } while ((layer = layer->fNext) != nullptr);
925 } 925 }
926 fDeviceCMDirty = false; 926 fDeviceCMDirty = false;
927 } 927 }
928 } 928 }
929 929
930 /////////////////////////////////////////////////////////////////////////////// 930 ///////////////////////////////////////////////////////////////////////////////
931 931
932 void SkCanvas::checkForDeferredSave() { 932 void SkCanvas::checkForDeferredSave() {
933 if (fMCRec->fDeferredSaveCount > 0) { 933 if (fMCRec->fDeferredSaveCount > 0) {
934 this->doSave(); 934 this->doSave();
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 } 1049 }
1050 1050
1051 if (intersection) { 1051 if (intersection) {
1052 *intersection = ir; 1052 *intersection = ir;
1053 } 1053 }
1054 return true; 1054 return true;
1055 } 1055 }
1056 1056
1057 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint) { 1057 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint) {
1058 if (gIgnoreSaveLayerBounds) { 1058 if (gIgnoreSaveLayerBounds) {
1059 bounds = NULL; 1059 bounds = nullptr;
1060 } 1060 }
1061 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, kARGB_ClipLa yer_SaveFlag); 1061 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, kARGB_ClipLa yer_SaveFlag);
1062 fSaveCount += 1; 1062 fSaveCount += 1;
1063 this->internalSaveLayer(bounds, paint, kARGB_ClipLayer_SaveFlag, strategy); 1063 this->internalSaveLayer(bounds, paint, kARGB_ClipLayer_SaveFlag, strategy);
1064 return this->getSaveCount() - 1; 1064 return this->getSaveCount() - 1;
1065 } 1065 }
1066 1066
1067 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags fl ags) { 1067 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags fl ags) {
1068 if (gIgnoreSaveLayerBounds) { 1068 if (gIgnoreSaveLayerBounds) {
1069 bounds = NULL; 1069 bounds = nullptr;
1070 } 1070 }
1071 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, flags); 1071 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, flags);
1072 fSaveCount += 1; 1072 fSaveCount += 1;
1073 this->internalSaveLayer(bounds, paint, flags, strategy); 1073 this->internalSaveLayer(bounds, paint, flags, strategy);
1074 return this->getSaveCount() - 1; 1074 return this->getSaveCount() - 1;
1075 } 1075 }
1076 1076
1077 void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav eFlags flags, 1077 void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav eFlags flags,
1078 SaveLayerStrategy strategy) { 1078 SaveLayerStrategy strategy) {
1079 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG 1079 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
1080 flags |= kClipToLayer_SaveFlag; 1080 flags |= kClipToLayer_SaveFlag;
1081 #endif 1081 #endif
1082 1082
1083 // do this before we create the layer. We don't call the public save() since 1083 // do this before we create the layer. We don't call the public save() since
1084 // that would invoke a possibly overridden virtual 1084 // that would invoke a possibly overridden virtual
1085 this->internalSave(); 1085 this->internalSave();
1086 1086
1087 fDeviceCMDirty = true; 1087 fDeviceCMDirty = true;
1088 1088
1089 SkIRect ir; 1089 SkIRect ir;
1090 if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter( ) : NULL)) { 1090 if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter( ) : nullptr)) {
1091 return; 1091 return;
1092 } 1092 }
1093 1093
1094 // FIXME: do willSaveLayer() overriders returning kNoLayer_SaveLayerStrategy really care about 1094 // FIXME: do willSaveLayer() overriders returning kNoLayer_SaveLayerStrategy really care about
1095 // the clipRectBounds() call above? 1095 // the clipRectBounds() call above?
1096 if (kNoLayer_SaveLayerStrategy == strategy) { 1096 if (kNoLayer_SaveLayerStrategy == strategy) {
1097 return; 1097 return;
1098 } 1098 }
1099 1099
1100 bool isOpaque = !SkToBool(flags & kHasAlphaLayer_SaveFlag); 1100 bool isOpaque = !SkToBool(flags & kHasAlphaLayer_SaveFlag);
1101 SkPixelGeometry geo = fProps.pixelGeometry(); 1101 SkPixelGeometry geo = fProps.pixelGeometry();
1102 if (paint) { 1102 if (paint) {
1103 // TODO: perhaps add a query to filters so we might preserve opaqueness. .. 1103 // TODO: perhaps add a query to filters so we might preserve opaqueness. ..
1104 if (paint->getImageFilter() || paint->getColorFilter()) { 1104 if (paint->getImageFilter() || paint->getColorFilter()) {
1105 isOpaque = false; 1105 isOpaque = false;
1106 geo = kUnknown_SkPixelGeometry; 1106 geo = kUnknown_SkPixelGeometry;
1107 } 1107 }
1108 } 1108 }
1109 SkImageInfo info = SkImageInfo::MakeN32(ir.width(), ir.height(), 1109 SkImageInfo info = SkImageInfo::MakeN32(ir.width(), ir.height(),
1110 isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); 1110 isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
1111 1111
1112 SkBaseDevice* device = this->getTopDevice(); 1112 SkBaseDevice* device = this->getTopDevice();
1113 if (NULL == device) { 1113 if (nullptr == device) {
1114 SkDebugf("Unable to find device for layer."); 1114 SkDebugf("Unable to find device for layer.");
1115 return; 1115 return;
1116 } 1116 }
1117 1117
1118 bool forceSpriteOnRestore = false; 1118 bool forceSpriteOnRestore = false;
1119 { 1119 {
1120 const SkBaseDevice::TileUsage usage = SkBaseDevice::kNever_TileUsage; 1120 const SkBaseDevice::TileUsage usage = SkBaseDevice::kNever_TileUsage;
1121 const SkBaseDevice::CreateInfo createInfo = SkBaseDevice::CreateInfo(inf o, usage, geo); 1121 const SkBaseDevice::CreateInfo createInfo = SkBaseDevice::CreateInfo(inf o, usage, geo);
1122 SkBaseDevice* newDev = device->onCreateDevice(createInfo, paint); 1122 SkBaseDevice* newDev = device->onCreateDevice(createInfo, paint);
1123 if (NULL == newDev) { 1123 if (nullptr == newDev) {
1124 // If onCreateDevice didn't succeed, try raster (e.g. PDF couldn't h andle the paint) 1124 // If onCreateDevice didn't succeed, try raster (e.g. PDF couldn't h andle the paint)
1125 const SkSurfaceProps surfaceProps(fProps.flags(), createInfo.fPixelG eometry); 1125 const SkSurfaceProps surfaceProps(fProps.flags(), createInfo.fPixelG eometry);
1126 newDev = SkBitmapDevice::Create(createInfo.fInfo, surfaceProps); 1126 newDev = SkBitmapDevice::Create(createInfo.fInfo, surfaceProps);
1127 if (NULL == newDev) { 1127 if (nullptr == newDev) {
1128 SkErrorInternals::SetError(kInternalError_SkError, 1128 SkErrorInternals::SetError(kInternalError_SkError,
1129 "Unable to create device for layer.") ; 1129 "Unable to create device for layer.") ;
1130 return; 1130 return;
1131 } 1131 }
1132 forceSpriteOnRestore = true; 1132 forceSpriteOnRestore = true;
1133 } 1133 }
1134 device = newDev; 1134 device = newDev;
1135 } 1135 }
1136 1136
1137 device->setOrigin(ir.fLeft, ir.fTop); 1137 device->setOrigin(ir.fLeft, ir.fTop);
1138 DeviceCM* layer = 1138 DeviceCM* layer =
1139 new DeviceCM(device, paint, this, fConservativeRasterClip, forceSpri teOnRestore); 1139 new DeviceCM(device, paint, this, fConservativeRasterClip, forceSpri teOnRestore);
1140 device->unref(); 1140 device->unref();
1141 1141
1142 layer->fNext = fMCRec->fTopLayer; 1142 layer->fNext = fMCRec->fTopLayer;
1143 fMCRec->fLayer = layer; 1143 fMCRec->fLayer = layer;
1144 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer 1144 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer
1145 } 1145 }
1146 1146
1147 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { 1147 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) {
1148 return this->saveLayerAlpha(bounds, alpha, kARGB_ClipLayer_SaveFlag); 1148 return this->saveLayerAlpha(bounds, alpha, kARGB_ClipLayer_SaveFlag);
1149 } 1149 }
1150 1150
1151 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha, 1151 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha,
1152 SaveFlags flags) { 1152 SaveFlags flags) {
1153 if (0xFF == alpha) { 1153 if (0xFF == alpha) {
1154 return this->saveLayer(bounds, NULL, flags); 1154 return this->saveLayer(bounds, nullptr, flags);
1155 } else { 1155 } else {
1156 SkPaint tmpPaint; 1156 SkPaint tmpPaint;
1157 tmpPaint.setAlpha(alpha); 1157 tmpPaint.setAlpha(alpha);
1158 return this->saveLayer(bounds, &tmpPaint, flags); 1158 return this->saveLayer(bounds, &tmpPaint, flags);
1159 } 1159 }
1160 } 1160 }
1161 1161
1162 void SkCanvas::internalRestore() { 1162 void SkCanvas::internalRestore() {
1163 SkASSERT(fMCStack.count() != 0); 1163 SkASSERT(fMCStack.count() != 0);
1164 1164
1165 fDeviceCMDirty = true; 1165 fDeviceCMDirty = true;
1166 fCachedLocalClipBoundsDirty = true; 1166 fCachedLocalClipBoundsDirty = true;
1167 1167
1168 fClipStack->restore(); 1168 fClipStack->restore();
1169 1169
1170 // reserve our layer (if any) 1170 // reserve our layer (if any)
1171 DeviceCM* layer = fMCRec->fLayer; // may be null 1171 DeviceCM* layer = fMCRec->fLayer; // may be null
1172 // now detach it from fMCRec so we can pop(). Gets freed after its drawn 1172 // now detach it from fMCRec so we can pop(). Gets freed after its drawn
1173 fMCRec->fLayer = NULL; 1173 fMCRec->fLayer = nullptr;
1174 1174
1175 // now do the normal restore() 1175 // now do the normal restore()
1176 fMCRec->~MCRec(); // balanced in save() 1176 fMCRec->~MCRec(); // balanced in save()
1177 fMCStack.pop_back(); 1177 fMCStack.pop_back();
1178 fMCRec = (MCRec*)fMCStack.back(); 1178 fMCRec = (MCRec*)fMCStack.back();
1179 1179
1180 /* Time to draw the layer's offscreen. We can't call the public drawSprite, 1180 /* Time to draw the layer's offscreen. We can't call the public drawSprite,
1181 since if we're being recorded, we don't want to record this (the 1181 since if we're being recorded, we don't want to record this (the
1182 recorder will have already recorded the restore). 1182 recorder will have already recorded the restore).
1183 */ 1183 */
1184 if (layer) { 1184 if (layer) {
1185 if (layer->fNext) { 1185 if (layer->fNext) {
1186 const SkIPoint& origin = layer->fDevice->getOrigin(); 1186 const SkIPoint& origin = layer->fDevice->getOrigin();
1187 this->internalDrawDevice(layer->fDevice, origin.x(), origin.y(), 1187 this->internalDrawDevice(layer->fDevice, origin.x(), origin.y(),
1188 layer->fPaint, layer->fDeviceIsBitmapDevice ); 1188 layer->fPaint, layer->fDeviceIsBitmapDevice );
1189 // reset this, since internalDrawDevice will have set it to true 1189 // reset this, since internalDrawDevice will have set it to true
1190 fDeviceCMDirty = true; 1190 fDeviceCMDirty = true;
1191 delete layer; 1191 delete layer;
1192 } else { 1192 } else {
1193 // we're at the root 1193 // we're at the root
1194 SkASSERT(layer == (void*)fDeviceCMStorage); 1194 SkASSERT(layer == (void*)fDeviceCMStorage);
1195 layer->~DeviceCM(); 1195 layer->~DeviceCM();
1196 } 1196 }
1197 } 1197 }
1198 } 1198 }
1199 1199
1200 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) { 1200 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) {
1201 if (NULL == props) { 1201 if (nullptr == props) {
1202 props = &fProps; 1202 props = &fProps;
1203 } 1203 }
1204 return this->onNewSurface(info, *props); 1204 return this->onNewSurface(info, *props);
1205 } 1205 }
1206 1206
1207 SkSurface* SkCanvas::onNewSurface(const SkImageInfo& info, const SkSurfaceProps& props) { 1207 SkSurface* SkCanvas::onNewSurface(const SkImageInfo& info, const SkSurfaceProps& props) {
1208 SkBaseDevice* dev = this->getDevice(); 1208 SkBaseDevice* dev = this->getDevice();
1209 return dev ? dev->newSurface(info, props) : NULL; 1209 return dev ? dev->newSurface(info, props) : nullptr;
1210 } 1210 }
1211 1211
1212 SkImageInfo SkCanvas::imageInfo() const { 1212 SkImageInfo SkCanvas::imageInfo() const {
1213 SkBaseDevice* dev = this->getDevice(); 1213 SkBaseDevice* dev = this->getDevice();
1214 if (dev) { 1214 if (dev) {
1215 return dev->imageInfo(); 1215 return dev->imageInfo();
1216 } else { 1216 } else {
1217 return SkImageInfo::MakeUnknown(0, 0); 1217 return SkImageInfo::MakeUnknown(0, 0);
1218 } 1218 }
1219 } 1219 }
1220 1220
1221 const void* SkCanvas::peekPixels(SkImageInfo* info, size_t* rowBytes) { 1221 const void* SkCanvas::peekPixels(SkImageInfo* info, size_t* rowBytes) {
1222 SkPixmap pmap; 1222 SkPixmap pmap;
1223 if (!this->onPeekPixels(&pmap)) { 1223 if (!this->onPeekPixels(&pmap)) {
1224 return NULL; 1224 return nullptr;
1225 } 1225 }
1226 if (info) { 1226 if (info) {
1227 *info = pmap.info(); 1227 *info = pmap.info();
1228 } 1228 }
1229 if (rowBytes) { 1229 if (rowBytes) {
1230 *rowBytes = pmap.rowBytes(); 1230 *rowBytes = pmap.rowBytes();
1231 } 1231 }
1232 return pmap.addr(); 1232 return pmap.addr();
1233 } 1233 }
1234 1234
1235 bool SkCanvas::onPeekPixels(SkPixmap* pmap) { 1235 bool SkCanvas::onPeekPixels(SkPixmap* pmap) {
1236 SkBaseDevice* dev = this->getDevice(); 1236 SkBaseDevice* dev = this->getDevice();
1237 return dev && dev->peekPixels(pmap); 1237 return dev && dev->peekPixels(pmap);
1238 } 1238 }
1239 1239
1240 void* SkCanvas::accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes, SkIPoi nt* origin) { 1240 void* SkCanvas::accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes, SkIPoi nt* origin) {
1241 SkPixmap pmap; 1241 SkPixmap pmap;
1242 if (!this->onAccessTopLayerPixels(&pmap)) { 1242 if (!this->onAccessTopLayerPixels(&pmap)) {
1243 return NULL; 1243 return nullptr;
1244 } 1244 }
1245 if (info) { 1245 if (info) {
1246 *info = pmap.info(); 1246 *info = pmap.info();
1247 } 1247 }
1248 if (rowBytes) { 1248 if (rowBytes) {
1249 *rowBytes = pmap.rowBytes(); 1249 *rowBytes = pmap.rowBytes();
1250 } 1250 }
1251 if (origin) { 1251 if (origin) {
1252 *origin = this->getTopDevice(false)->getOrigin(); 1252 *origin = this->getTopDevice(false)->getOrigin();
1253 } 1253 }
1254 return pmap.writable_addr(); 1254 return pmap.writable_addr();
1255 } 1255 }
1256 1256
1257 bool SkCanvas::onAccessTopLayerPixels(SkPixmap* pmap) { 1257 bool SkCanvas::onAccessTopLayerPixels(SkPixmap* pmap) {
1258 SkBaseDevice* dev = this->getTopDevice(); 1258 SkBaseDevice* dev = this->getTopDevice();
1259 return dev && dev->accessPixels(pmap); 1259 return dev && dev->accessPixels(pmap);
1260 } 1260 }
1261 1261
1262 SkAutoROCanvasPixels::SkAutoROCanvasPixels(SkCanvas* canvas) { 1262 SkAutoROCanvasPixels::SkAutoROCanvasPixels(SkCanvas* canvas) {
1263 fAddr = canvas->peekPixels(&fInfo, &fRowBytes); 1263 fAddr = canvas->peekPixels(&fInfo, &fRowBytes);
1264 if (NULL == fAddr) { 1264 if (nullptr == fAddr) {
1265 fInfo = canvas->imageInfo(); 1265 fInfo = canvas->imageInfo();
1266 if (kUnknown_SkColorType == fInfo.colorType() || !fBitmap.tryAllocPixels (fInfo)) { 1266 if (kUnknown_SkColorType == fInfo.colorType() || !fBitmap.tryAllocPixels (fInfo)) {
1267 return; // failure, fAddr is NULL 1267 return; // failure, fAddr is nullptr
1268 } 1268 }
1269 if (!canvas->readPixels(&fBitmap, 0, 0)) { 1269 if (!canvas->readPixels(&fBitmap, 0, 0)) {
1270 return; // failure, fAddr is NULL 1270 return; // failure, fAddr is nullptr
1271 } 1271 }
1272 fAddr = fBitmap.getPixels(); 1272 fAddr = fBitmap.getPixels();
1273 fRowBytes = fBitmap.rowBytes(); 1273 fRowBytes = fBitmap.rowBytes();
1274 } 1274 }
1275 SkASSERT(fAddr); // success 1275 SkASSERT(fAddr); // success
1276 } 1276 }
1277 1277
1278 bool SkAutoROCanvasPixels::asROBitmap(SkBitmap* bitmap) const { 1278 bool SkAutoROCanvasPixels::asROBitmap(SkBitmap* bitmap) const {
1279 if (fAddr) { 1279 if (fAddr) {
1280 return bitmap->installPixels(fInfo, const_cast<void*>(fAddr), fRowBytes) ; 1280 return bitmap->installPixels(fInfo, const_cast<void*>(fAddr), fRowBytes) ;
1281 } else { 1281 } else {
1282 bitmap->reset(); 1282 bitmap->reset();
1283 return false; 1283 return false;
1284 } 1284 }
1285 } 1285 }
1286 1286
1287 ///////////////////////////////////////////////////////////////////////////// 1287 /////////////////////////////////////////////////////////////////////////////
1288 void SkCanvas::internalDrawBitmap(const SkBitmap& bitmap, 1288 void SkCanvas::internalDrawBitmap(const SkBitmap& bitmap,
1289 const SkMatrix& matrix, const SkPaint* paint) { 1289 const SkMatrix& matrix, const SkPaint* paint) {
1290 if (bitmap.drawsNothing()) { 1290 if (bitmap.drawsNothing()) {
1291 return; 1291 return;
1292 } 1292 }
1293 1293
1294 SkLazyPaint lazy; 1294 SkLazyPaint lazy;
1295 if (NULL == paint) { 1295 if (nullptr == paint) {
1296 paint = lazy.init(); 1296 paint = lazy.init();
1297 } 1297 }
1298 1298
1299 SkDEBUGCODE(bitmap.validate();) 1299 SkDEBUGCODE(bitmap.validate();)
1300 1300
1301 SkRect storage; 1301 SkRect storage;
1302 const SkRect* bounds = NULL; 1302 const SkRect* bounds = nullptr;
1303 if (paint && paint->canComputeFastBounds()) { 1303 if (paint && paint->canComputeFastBounds()) {
1304 bitmap.getBounds(&storage); 1304 bitmap.getBounds(&storage);
1305 matrix.mapRect(&storage); 1305 matrix.mapRect(&storage);
1306 bounds = &paint->computeFastBounds(storage, &storage); 1306 bounds = &paint->computeFastBounds(storage, &storage);
1307 } 1307 }
1308 1308
1309 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, bounds) 1309 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, bounds)
1310 1310
1311 while (iter.next()) { 1311 while (iter.next()) {
1312 iter.fDevice->drawBitmap(iter, bitmap, matrix, looper.paint()); 1312 iter.fDevice->drawBitmap(iter, bitmap, matrix, looper.paint());
1313 } 1313 }
1314 1314
1315 LOOPER_END 1315 LOOPER_END
1316 } 1316 }
1317 1317
1318 void SkCanvas::internalDrawDevice(SkBaseDevice* srcDev, int x, int y, 1318 void SkCanvas::internalDrawDevice(SkBaseDevice* srcDev, int x, int y,
1319 const SkPaint* paint, bool deviceIsBitmapDevic e) { 1319 const SkPaint* paint, bool deviceIsBitmapDevic e) {
1320 SkPaint tmp; 1320 SkPaint tmp;
1321 if (NULL == paint) { 1321 if (nullptr == paint) {
1322 paint = &tmp; 1322 paint = &tmp;
1323 } 1323 }
1324 1324
1325 LOOPER_BEGIN_DRAWDEVICE(*paint, SkDrawFilter::kBitmap_Type) 1325 LOOPER_BEGIN_DRAWDEVICE(*paint, SkDrawFilter::kBitmap_Type)
1326 while (iter.next()) { 1326 while (iter.next()) {
1327 SkBaseDevice* dstDev = iter.fDevice; 1327 SkBaseDevice* dstDev = iter.fDevice;
1328 paint = &looper.paint(); 1328 paint = &looper.paint();
1329 SkImageFilter* filter = paint->getImageFilter(); 1329 SkImageFilter* filter = paint->getImageFilter();
1330 SkIPoint pos = { x - iter.getX(), y - iter.getY() }; 1330 SkIPoint pos = { x - iter.getX(), y - iter.getY() };
1331 if (filter && !dstDev->canHandleImageFilter(filter)) { 1331 if (filter && !dstDev->canHandleImageFilter(filter)) {
1332 SkImageFilter::Proxy proxy(dstDev); 1332 SkImageFilter::Proxy proxy(dstDev);
1333 SkBitmap dst; 1333 SkBitmap dst;
1334 SkIPoint offset = SkIPoint::Make(0, 0); 1334 SkIPoint offset = SkIPoint::Make(0, 0);
1335 const SkBitmap& src = srcDev->accessBitmap(false); 1335 const SkBitmap& src = srcDev->accessBitmap(false);
1336 SkMatrix matrix = *iter.fMatrix; 1336 SkMatrix matrix = *iter.fMatrix;
1337 matrix.postTranslate(SkIntToScalar(-pos.x()), SkIntToScalar(-pos.y() )); 1337 matrix.postTranslate(SkIntToScalar(-pos.x()), SkIntToScalar(-pos.y() ));
1338 SkIRect clipBounds = SkIRect::MakeWH(srcDev->width(), srcDev->height ()); 1338 SkIRect clipBounds = SkIRect::MakeWH(srcDev->width(), srcDev->height ());
1339 SkAutoTUnref<SkImageFilter::Cache> cache(dstDev->getImageFilterCache ()); 1339 SkAutoTUnref<SkImageFilter::Cache> cache(dstDev->getImageFilterCache ());
1340 SkImageFilter::Context ctx(matrix, clipBounds, cache.get()); 1340 SkImageFilter::Context ctx(matrix, clipBounds, cache.get());
1341 if (filter->filterImage(&proxy, src, ctx, &dst, &offset)) { 1341 if (filter->filterImage(&proxy, src, ctx, &dst, &offset)) {
1342 SkPaint tmpUnfiltered(*paint); 1342 SkPaint tmpUnfiltered(*paint);
1343 tmpUnfiltered.setImageFilter(NULL); 1343 tmpUnfiltered.setImageFilter(nullptr);
1344 dstDev->drawSprite(iter, dst, pos.x() + offset.x(), pos.y() + of fset.y(), 1344 dstDev->drawSprite(iter, dst, pos.x() + offset.x(), pos.y() + of fset.y(),
1345 tmpUnfiltered); 1345 tmpUnfiltered);
1346 } 1346 }
1347 } else if (deviceIsBitmapDevice) { 1347 } else if (deviceIsBitmapDevice) {
1348 const SkBitmap& src = static_cast<SkBitmapDevice*>(srcDev)->fBitmap; 1348 const SkBitmap& src = static_cast<SkBitmapDevice*>(srcDev)->fBitmap;
1349 dstDev->drawSprite(iter, src, pos.x(), pos.y(), *paint); 1349 dstDev->drawSprite(iter, src, pos.x(), pos.y(), *paint);
1350 } else { 1350 } else {
1351 dstDev->drawDevice(iter, srcDev, pos.x(), pos.y(), *paint); 1351 dstDev->drawDevice(iter, srcDev, pos.x(), pos.y(), *paint);
1352 } 1352 }
1353 } 1353 }
1354 LOOPER_END 1354 LOOPER_END
1355 } 1355 }
1356 1356
1357 void SkCanvas::onDrawSprite(const SkBitmap& bitmap, int x, int y, const SkPaint* paint) { 1357 void SkCanvas::onDrawSprite(const SkBitmap& bitmap, int x, int y, const SkPaint* paint) {
1358 if (gTreatSpriteAsBitmap) { 1358 if (gTreatSpriteAsBitmap) {
1359 this->save(); 1359 this->save();
1360 this->resetMatrix(); 1360 this->resetMatrix();
1361 this->drawBitmap(bitmap, SkIntToScalar(x), SkIntToScalar(y), paint); 1361 this->drawBitmap(bitmap, SkIntToScalar(x), SkIntToScalar(y), paint);
1362 this->restore(); 1362 this->restore();
1363 return; 1363 return;
1364 } 1364 }
1365 1365
1366 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawSprite()"); 1366 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawSprite()");
1367 if (bitmap.drawsNothing()) { 1367 if (bitmap.drawsNothing()) {
1368 return; 1368 return;
1369 } 1369 }
1370 SkDEBUGCODE(bitmap.validate();) 1370 SkDEBUGCODE(bitmap.validate();)
1371 1371
1372 SkPaint tmp; 1372 SkPaint tmp;
1373 if (NULL == paint) { 1373 if (nullptr == paint) {
1374 paint = &tmp; 1374 paint = &tmp;
1375 } 1375 }
1376 1376
1377 LOOPER_BEGIN_DRAWDEVICE(*paint, SkDrawFilter::kBitmap_Type) 1377 LOOPER_BEGIN_DRAWDEVICE(*paint, SkDrawFilter::kBitmap_Type)
1378 1378
1379 while (iter.next()) { 1379 while (iter.next()) {
1380 paint = &looper.paint(); 1380 paint = &looper.paint();
1381 SkImageFilter* filter = paint->getImageFilter(); 1381 SkImageFilter* filter = paint->getImageFilter();
1382 SkIPoint pos = { x - iter.getX(), y - iter.getY() }; 1382 SkIPoint pos = { x - iter.getX(), y - iter.getY() };
1383 if (filter && !iter.fDevice->canHandleImageFilter(filter)) { 1383 if (filter && !iter.fDevice->canHandleImageFilter(filter)) {
1384 SkImageFilter::Proxy proxy(iter.fDevice); 1384 SkImageFilter::Proxy proxy(iter.fDevice);
1385 SkBitmap dst; 1385 SkBitmap dst;
1386 SkIPoint offset = SkIPoint::Make(0, 0); 1386 SkIPoint offset = SkIPoint::Make(0, 0);
1387 SkMatrix matrix = *iter.fMatrix; 1387 SkMatrix matrix = *iter.fMatrix;
1388 matrix.postTranslate(SkIntToScalar(-pos.x()), SkIntToScalar(-pos.y() )); 1388 matrix.postTranslate(SkIntToScalar(-pos.x()), SkIntToScalar(-pos.y() ));
1389 const SkIRect clipBounds = bitmap.bounds(); 1389 const SkIRect clipBounds = bitmap.bounds();
1390 SkAutoTUnref<SkImageFilter::Cache> cache(iter.fDevice->getImageFilte rCache()); 1390 SkAutoTUnref<SkImageFilter::Cache> cache(iter.fDevice->getImageFilte rCache());
1391 SkImageFilter::Context ctx(matrix, clipBounds, cache.get()); 1391 SkImageFilter::Context ctx(matrix, clipBounds, cache.get());
1392 if (filter->filterImage(&proxy, bitmap, ctx, &dst, &offset)) { 1392 if (filter->filterImage(&proxy, bitmap, ctx, &dst, &offset)) {
1393 SkPaint tmpUnfiltered(*paint); 1393 SkPaint tmpUnfiltered(*paint);
1394 tmpUnfiltered.setImageFilter(NULL); 1394 tmpUnfiltered.setImageFilter(nullptr);
1395 iter.fDevice->drawSprite(iter, dst, pos.x() + offset.x(), pos.y( ) + offset.y(), 1395 iter.fDevice->drawSprite(iter, dst, pos.x() + offset.x(), pos.y( ) + offset.y(),
1396 tmpUnfiltered); 1396 tmpUnfiltered);
1397 } 1397 }
1398 } else { 1398 } else {
1399 iter.fDevice->drawSprite(iter, bitmap, pos.x(), pos.y(), *paint); 1399 iter.fDevice->drawSprite(iter, bitmap, pos.x(), pos.y(), *paint);
1400 } 1400 }
1401 } 1401 }
1402 LOOPER_END 1402 LOOPER_END
1403 } 1403 }
1404 1404
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1641 SkASSERT(this->isClipEmpty()); 1641 SkASSERT(this->isClipEmpty());
1642 return; 1642 return;
1643 } 1643 }
1644 1644
1645 SkIRect ir; 1645 SkIRect ir;
1646 ir.set(0, 0, device->width(), device->height()); 1646 ir.set(0, 0, device->width(), device->height());
1647 SkRasterClip tmpClip(ir, fConservativeRasterClip); 1647 SkRasterClip tmpClip(ir, fConservativeRasterClip);
1648 1648
1649 SkClipStack::B2TIter iter(*fClipStack); 1649 SkClipStack::B2TIter iter(*fClipStack);
1650 const SkClipStack::Element* element; 1650 const SkClipStack::Element* element;
1651 while ((element = iter.next()) != NULL) { 1651 while ((element = iter.next()) != nullptr) {
1652 switch (element->getType()) { 1652 switch (element->getType()) {
1653 case SkClipStack::Element::kRect_Type: 1653 case SkClipStack::Element::kRect_Type:
1654 element->getRect().round(&ir); 1654 element->getRect().round(&ir);
1655 tmpClip.op(ir, element->getOp()); 1655 tmpClip.op(ir, element->getOp());
1656 break; 1656 break;
1657 case SkClipStack::Element::kEmpty_Type: 1657 case SkClipStack::Element::kEmpty_Type:
1658 tmpClip.setEmpty(); 1658 tmpClip.setEmpty();
1659 break; 1659 break;
1660 default: { 1660 default: {
1661 SkPath path; 1661 SkPath path;
1662 element->asPath(&path); 1662 element->asPath(&path);
1663 rasterclip_path(&tmpClip, this, path, element->getOp(), element- >isAA()); 1663 rasterclip_path(&tmpClip, this, path, element->getOp(), element- >isAA());
1664 break; 1664 break;
1665 } 1665 }
1666 } 1666 }
1667 } 1667 }
1668 } 1668 }
1669 #endif 1669 #endif
1670 1670
1671 void SkCanvas::replayClips(ClipVisitor* visitor) const { 1671 void SkCanvas::replayClips(ClipVisitor* visitor) const {
1672 SkClipStack::B2TIter iter(*fClipStack); 1672 SkClipStack::B2TIter iter(*fClipStack);
1673 const SkClipStack::Element* element; 1673 const SkClipStack::Element* element;
1674 1674
1675 while ((element = iter.next()) != NULL) { 1675 while ((element = iter.next()) != nullptr) {
1676 element->replay(visitor); 1676 element->replay(visitor);
1677 } 1677 }
1678 } 1678 }
1679 1679
1680 /////////////////////////////////////////////////////////////////////////////// 1680 ///////////////////////////////////////////////////////////////////////////////
1681 1681
1682 bool SkCanvas::isClipEmpty() const { 1682 bool SkCanvas::isClipEmpty() const {
1683 return fMCRec->fRasterClip.isEmpty(); 1683 return fMCRec->fRasterClip.isEmpty();
1684 } 1684 }
1685 1685
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1763 const SkMatrix& SkCanvas::getTotalMatrix() const { 1763 const SkMatrix& SkCanvas::getTotalMatrix() const {
1764 return fMCRec->fMatrix; 1764 return fMCRec->fMatrix;
1765 } 1765 }
1766 1766
1767 const SkRegion& SkCanvas::internal_private_getTotalClip() const { 1767 const SkRegion& SkCanvas::internal_private_getTotalClip() const {
1768 return fMCRec->fRasterClip.forceGetBW(); 1768 return fMCRec->fRasterClip.forceGetBW();
1769 } 1769 }
1770 1770
1771 GrRenderTarget* SkCanvas::internal_private_accessTopLayerRenderTarget() { 1771 GrRenderTarget* SkCanvas::internal_private_accessTopLayerRenderTarget() {
1772 SkBaseDevice* dev = this->getTopDevice(); 1772 SkBaseDevice* dev = this->getTopDevice();
1773 return dev ? dev->accessRenderTarget() : NULL; 1773 return dev ? dev->accessRenderTarget() : nullptr;
1774 } 1774 }
1775 1775
1776 GrContext* SkCanvas::getGrContext() { 1776 GrContext* SkCanvas::getGrContext() {
1777 #if SK_SUPPORT_GPU 1777 #if SK_SUPPORT_GPU
1778 SkBaseDevice* device = this->getTopDevice(); 1778 SkBaseDevice* device = this->getTopDevice();
1779 if (device) { 1779 if (device) {
1780 GrRenderTarget* renderTarget = device->accessRenderTarget(); 1780 GrRenderTarget* renderTarget = device->accessRenderTarget();
1781 if (renderTarget) { 1781 if (renderTarget) {
1782 return renderTarget->getContext(); 1782 return renderTarget->getContext();
1783 } 1783 }
1784 } 1784 }
1785 #endif 1785 #endif
1786 1786
1787 return NULL; 1787 return nullptr;
1788 1788
1789 } 1789 }
1790 1790
1791 void SkCanvas::drawDRRect(const SkRRect& outer, const SkRRect& inner, 1791 void SkCanvas::drawDRRect(const SkRRect& outer, const SkRRect& inner,
1792 const SkPaint& paint) { 1792 const SkPaint& paint) {
1793 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawDRRect()"); 1793 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawDRRect()");
1794 if (outer.isEmpty()) { 1794 if (outer.isEmpty()) {
1795 return; 1795 return;
1796 } 1796 }
1797 if (inner.isEmpty()) { 1797 if (inner.isEmpty()) {
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1960 fSurfaceBase->aboutToDraw(SkSurface::kDiscard_ContentChangeMode); 1960 fSurfaceBase->aboutToDraw(SkSurface::kDiscard_ContentChangeMode);
1961 } 1961 }
1962 } 1962 }
1963 1963
1964 void SkCanvas::onDrawPaint(const SkPaint& paint) { 1964 void SkCanvas::onDrawPaint(const SkPaint& paint) {
1965 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawPaint()"); 1965 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawPaint()");
1966 this->internalDrawPaint(paint); 1966 this->internalDrawPaint(paint);
1967 } 1967 }
1968 1968
1969 void SkCanvas::internalDrawPaint(const SkPaint& paint) { 1969 void SkCanvas::internalDrawPaint(const SkPaint& paint) {
1970 LOOPER_BEGIN_CHECK_COMPLETE_OVERWRITE(paint, SkDrawFilter::kPaint_Type, NULL , false) 1970 LOOPER_BEGIN_CHECK_COMPLETE_OVERWRITE(paint, SkDrawFilter::kPaint_Type, null ptr, false)
1971 1971
1972 while (iter.next()) { 1972 while (iter.next()) {
1973 iter.fDevice->drawPaint(iter, looper.paint()); 1973 iter.fDevice->drawPaint(iter, looper.paint());
1974 } 1974 }
1975 1975
1976 LOOPER_END 1976 LOOPER_END
1977 } 1977 }
1978 1978
1979 void SkCanvas::onDrawPoints(PointMode mode, size_t count, const SkPoint pts[], 1979 void SkCanvas::onDrawPoints(PointMode mode, size_t count, const SkPoint pts[],
1980 const SkPaint& paint) { 1980 const SkPaint& paint) {
1981 TRACE_EVENT1("disabled-by-default-skia", "SkCanvas::drawPoints()", "count", static_cast<uint64_t>(count)); 1981 TRACE_EVENT1("disabled-by-default-skia", "SkCanvas::drawPoints()", "count", static_cast<uint64_t>(count));
1982 if ((long)count <= 0) { 1982 if ((long)count <= 0) {
1983 return; 1983 return;
1984 } 1984 }
1985 1985
1986 SkRect r, storage; 1986 SkRect r, storage;
1987 const SkRect* bounds = NULL; 1987 const SkRect* bounds = nullptr;
1988 if (paint.canComputeFastBounds()) { 1988 if (paint.canComputeFastBounds()) {
1989 // special-case 2 points (common for drawing a single line) 1989 // special-case 2 points (common for drawing a single line)
1990 if (2 == count) { 1990 if (2 == count) {
1991 r.set(pts[0], pts[1]); 1991 r.set(pts[0], pts[1]);
1992 } else { 1992 } else {
1993 r.set(pts, SkToInt(count)); 1993 r.set(pts, SkToInt(count));
1994 } 1994 }
1995 bounds = &paint.computeFastStrokeBounds(r, &storage); 1995 bounds = &paint.computeFastStrokeBounds(r, &storage);
1996 if (this->quickReject(*bounds)) { 1996 if (this->quickReject(*bounds)) {
1997 return; 1997 return;
1998 } 1998 }
1999 } 1999 }
2000 2000
2001 SkASSERT(pts != NULL); 2001 SkASSERT(pts != nullptr);
2002 2002
2003 LOOPER_BEGIN(paint, SkDrawFilter::kPoint_Type, bounds) 2003 LOOPER_BEGIN(paint, SkDrawFilter::kPoint_Type, bounds)
2004 2004
2005 while (iter.next()) { 2005 while (iter.next()) {
2006 iter.fDevice->drawPoints(iter, mode, count, pts, looper.paint()); 2006 iter.fDevice->drawPoints(iter, mode, count, pts, looper.paint());
2007 } 2007 }
2008 2008
2009 LOOPER_END 2009 LOOPER_END
2010 } 2010 }
2011 2011
2012 void SkCanvas::onDrawRect(const SkRect& r, const SkPaint& paint) { 2012 void SkCanvas::onDrawRect(const SkRect& r, const SkPaint& paint) {
2013 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawRect()"); 2013 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawRect()");
2014 SkRect storage; 2014 SkRect storage;
2015 const SkRect* bounds = NULL; 2015 const SkRect* bounds = nullptr;
2016 if (paint.canComputeFastBounds()) { 2016 if (paint.canComputeFastBounds()) {
2017 // Skia will draw an inverted rect, because it explicitly "sorts" it dow nstream. 2017 // Skia will draw an inverted rect, because it explicitly "sorts" it dow nstream.
2018 // To prevent accidental rejecting at this stage, we have to sort it bef ore we check. 2018 // To prevent accidental rejecting at this stage, we have to sort it bef ore we check.
2019 SkRect tmp(r); 2019 SkRect tmp(r);
2020 tmp.sort(); 2020 tmp.sort();
2021 2021
2022 bounds = &paint.computeFastBounds(tmp, &storage); 2022 bounds = &paint.computeFastBounds(tmp, &storage);
2023 if (this->quickReject(*bounds)) { 2023 if (this->quickReject(*bounds)) {
2024 return; 2024 return;
2025 } 2025 }
2026 } 2026 }
2027 2027
2028 LOOPER_BEGIN_CHECK_COMPLETE_OVERWRITE(paint, SkDrawFilter::kRect_Type, bound s, false) 2028 LOOPER_BEGIN_CHECK_COMPLETE_OVERWRITE(paint, SkDrawFilter::kRect_Type, bound s, false)
2029 2029
2030 while (iter.next()) { 2030 while (iter.next()) {
2031 iter.fDevice->drawRect(iter, r, looper.paint()); 2031 iter.fDevice->drawRect(iter, r, looper.paint());
2032 } 2032 }
2033 2033
2034 LOOPER_END 2034 LOOPER_END
2035 } 2035 }
2036 2036
2037 void SkCanvas::onDrawOval(const SkRect& oval, const SkPaint& paint) { 2037 void SkCanvas::onDrawOval(const SkRect& oval, const SkPaint& paint) {
2038 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawOval()"); 2038 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawOval()");
2039 SkRect storage; 2039 SkRect storage;
2040 const SkRect* bounds = NULL; 2040 const SkRect* bounds = nullptr;
2041 if (paint.canComputeFastBounds()) { 2041 if (paint.canComputeFastBounds()) {
2042 bounds = &paint.computeFastBounds(oval, &storage); 2042 bounds = &paint.computeFastBounds(oval, &storage);
2043 if (this->quickReject(*bounds)) { 2043 if (this->quickReject(*bounds)) {
2044 return; 2044 return;
2045 } 2045 }
2046 } 2046 }
2047 2047
2048 LOOPER_BEGIN(paint, SkDrawFilter::kOval_Type, bounds) 2048 LOOPER_BEGIN(paint, SkDrawFilter::kOval_Type, bounds)
2049 2049
2050 while (iter.next()) { 2050 while (iter.next()) {
2051 iter.fDevice->drawOval(iter, oval, looper.paint()); 2051 iter.fDevice->drawOval(iter, oval, looper.paint());
2052 } 2052 }
2053 2053
2054 LOOPER_END 2054 LOOPER_END
2055 } 2055 }
2056 2056
2057 void SkCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { 2057 void SkCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) {
2058 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawRRect()"); 2058 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawRRect()");
2059 SkRect storage; 2059 SkRect storage;
2060 const SkRect* bounds = NULL; 2060 const SkRect* bounds = nullptr;
2061 if (paint.canComputeFastBounds()) { 2061 if (paint.canComputeFastBounds()) {
2062 bounds = &paint.computeFastBounds(rrect.getBounds(), &storage); 2062 bounds = &paint.computeFastBounds(rrect.getBounds(), &storage);
2063 if (this->quickReject(*bounds)) { 2063 if (this->quickReject(*bounds)) {
2064 return; 2064 return;
2065 } 2065 }
2066 } 2066 }
2067 2067
2068 if (rrect.isRect()) { 2068 if (rrect.isRect()) {
2069 // call the non-virtual version 2069 // call the non-virtual version
2070 this->SkCanvas::drawRect(rrect.getBounds(), paint); 2070 this->SkCanvas::drawRect(rrect.getBounds(), paint);
2071 return; 2071 return;
2072 } else if (rrect.isOval()) { 2072 } else if (rrect.isOval()) {
2073 // call the non-virtual version 2073 // call the non-virtual version
2074 this->SkCanvas::drawOval(rrect.getBounds(), paint); 2074 this->SkCanvas::drawOval(rrect.getBounds(), paint);
2075 return; 2075 return;
2076 } 2076 }
2077 2077
2078 LOOPER_BEGIN(paint, SkDrawFilter::kRRect_Type, bounds) 2078 LOOPER_BEGIN(paint, SkDrawFilter::kRRect_Type, bounds)
2079 2079
2080 while (iter.next()) { 2080 while (iter.next()) {
2081 iter.fDevice->drawRRect(iter, rrect, looper.paint()); 2081 iter.fDevice->drawRRect(iter, rrect, looper.paint());
2082 } 2082 }
2083 2083
2084 LOOPER_END 2084 LOOPER_END
2085 } 2085 }
2086 2086
2087 void SkCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, 2087 void SkCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner,
2088 const SkPaint& paint) { 2088 const SkPaint& paint) {
2089 SkRect storage; 2089 SkRect storage;
2090 const SkRect* bounds = NULL; 2090 const SkRect* bounds = nullptr;
2091 if (paint.canComputeFastBounds()) { 2091 if (paint.canComputeFastBounds()) {
2092 bounds = &paint.computeFastBounds(outer.getBounds(), &storage); 2092 bounds = &paint.computeFastBounds(outer.getBounds(), &storage);
2093 if (this->quickReject(*bounds)) { 2093 if (this->quickReject(*bounds)) {
2094 return; 2094 return;
2095 } 2095 }
2096 } 2096 }
2097 2097
2098 LOOPER_BEGIN(paint, SkDrawFilter::kRRect_Type, bounds) 2098 LOOPER_BEGIN(paint, SkDrawFilter::kRRect_Type, bounds)
2099 2099
2100 while (iter.next()) { 2100 while (iter.next()) {
2101 iter.fDevice->drawDRRect(iter, outer, inner, looper.paint()); 2101 iter.fDevice->drawDRRect(iter, outer, inner, looper.paint());
2102 } 2102 }
2103 2103
2104 LOOPER_END 2104 LOOPER_END
2105 } 2105 }
2106 2106
2107 void SkCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) { 2107 void SkCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) {
2108 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawPath()"); 2108 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawPath()");
2109 if (!path.isFinite()) { 2109 if (!path.isFinite()) {
2110 return; 2110 return;
2111 } 2111 }
2112 2112
2113 SkRect storage; 2113 SkRect storage;
2114 const SkRect* bounds = NULL; 2114 const SkRect* bounds = nullptr;
2115 if (!path.isInverseFillType() && paint.canComputeFastBounds()) { 2115 if (!path.isInverseFillType() && paint.canComputeFastBounds()) {
2116 const SkRect& pathBounds = path.getBounds(); 2116 const SkRect& pathBounds = path.getBounds();
2117 bounds = &paint.computeFastBounds(pathBounds, &storage); 2117 bounds = &paint.computeFastBounds(pathBounds, &storage);
2118 if (this->quickReject(*bounds)) { 2118 if (this->quickReject(*bounds)) {
2119 return; 2119 return;
2120 } 2120 }
2121 } 2121 }
2122 2122
2123 const SkRect& r = path.getBounds(); 2123 const SkRect& r = path.getBounds();
2124 if (r.width() <= 0 && r.height() <= 0) { 2124 if (r.width() <= 0 && r.height() <= 0) {
2125 if (path.isInverseFillType()) { 2125 if (path.isInverseFillType()) {
2126 this->internalDrawPaint(paint); 2126 this->internalDrawPaint(paint);
2127 } 2127 }
2128 return; 2128 return;
2129 } 2129 }
2130 2130
2131 LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, bounds) 2131 LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, bounds)
2132 2132
2133 while (iter.next()) { 2133 while (iter.next()) {
2134 iter.fDevice->drawPath(iter, path, looper.paint()); 2134 iter.fDevice->drawPath(iter, path, looper.paint());
2135 } 2135 }
2136 2136
2137 LOOPER_END 2137 LOOPER_END
2138 } 2138 }
2139 2139
2140 void SkCanvas::onDrawImage(const SkImage* image, SkScalar x, SkScalar y, const S kPaint* paint) { 2140 void SkCanvas::onDrawImage(const SkImage* image, SkScalar x, SkScalar y, const S kPaint* paint) {
2141 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImage()"); 2141 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImage()");
2142 SkRect bounds = SkRect::MakeXYWH(x, y, 2142 SkRect bounds = SkRect::MakeXYWH(x, y,
2143 SkIntToScalar(image->width()), SkIntToScala r(image->height())); 2143 SkIntToScalar(image->width()), SkIntToScala r(image->height()));
2144 if (NULL == paint || paint->canComputeFastBounds()) { 2144 if (nullptr == paint || paint->canComputeFastBounds()) {
2145 if (paint) { 2145 if (paint) {
2146 paint->computeFastBounds(bounds, &bounds); 2146 paint->computeFastBounds(bounds, &bounds);
2147 } 2147 }
2148 if (this->quickReject(bounds)) { 2148 if (this->quickReject(bounds)) {
2149 return; 2149 return;
2150 } 2150 }
2151 } 2151 }
2152 2152
2153 SkLazyPaint lazy; 2153 SkLazyPaint lazy;
2154 if (NULL == paint) { 2154 if (nullptr == paint) {
2155 paint = lazy.init(); 2155 paint = lazy.init();
2156 } 2156 }
2157 2157
2158 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &bounds) 2158 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &bounds)
2159 2159
2160 while (iter.next()) { 2160 while (iter.next()) {
2161 iter.fDevice->drawImage(iter, image, x, y, looper.paint()); 2161 iter.fDevice->drawImage(iter, image, x, y, looper.paint());
2162 } 2162 }
2163 2163
2164 LOOPER_END 2164 LOOPER_END
2165 } 2165 }
2166 2166
2167 void SkCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const Sk Rect& dst, 2167 void SkCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const Sk Rect& dst,
2168 const SkPaint* paint, SrcRectConstraint constrain t) { 2168 const SkPaint* paint, SrcRectConstraint constrain t) {
2169 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageRect()"); 2169 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageRect()");
2170 SkRect storage; 2170 SkRect storage;
2171 const SkRect* bounds = &dst; 2171 const SkRect* bounds = &dst;
2172 if (NULL == paint || paint->canComputeFastBounds()) { 2172 if (nullptr == paint || paint->canComputeFastBounds()) {
2173 if (paint) { 2173 if (paint) {
2174 bounds = &paint->computeFastBounds(dst, &storage); 2174 bounds = &paint->computeFastBounds(dst, &storage);
2175 } 2175 }
2176 if (this->quickReject(*bounds)) { 2176 if (this->quickReject(*bounds)) {
2177 return; 2177 return;
2178 } 2178 }
2179 } 2179 }
2180 SkLazyPaint lazy; 2180 SkLazyPaint lazy;
2181 if (NULL == paint) { 2181 if (nullptr == paint) {
2182 paint = lazy.init(); 2182 paint = lazy.init();
2183 } 2183 }
2184 2184
2185 LOOPER_BEGIN_CHECK_COMPLETE_OVERWRITE(*paint, SkDrawFilter::kBitmap_Type, bo unds, 2185 LOOPER_BEGIN_CHECK_COMPLETE_OVERWRITE(*paint, SkDrawFilter::kBitmap_Type, bo unds,
2186 image->isOpaque()) 2186 image->isOpaque())
2187 2187
2188 while (iter.next()) { 2188 while (iter.next()) {
2189 iter.fDevice->drawImageRect(iter, image, src, dst, looper.paint(), const raint); 2189 iter.fDevice->drawImageRect(iter, image, src, dst, looper.paint(), const raint);
2190 } 2190 }
2191 2191
2192 LOOPER_END 2192 LOOPER_END
2193 } 2193 }
2194 2194
2195 void SkCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y, cons t SkPaint* paint) { 2195 void SkCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y, cons t SkPaint* paint) {
2196 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawBitmap()"); 2196 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawBitmap()");
2197 SkDEBUGCODE(bitmap.validate();) 2197 SkDEBUGCODE(bitmap.validate();)
2198 2198
2199 if (NULL == paint || paint->canComputeFastBounds()) { 2199 if (nullptr == paint || paint->canComputeFastBounds()) {
2200 SkRect bounds = { 2200 SkRect bounds = {
2201 x, y, 2201 x, y,
2202 x + SkIntToScalar(bitmap.width()), 2202 x + SkIntToScalar(bitmap.width()),
2203 y + SkIntToScalar(bitmap.height()) 2203 y + SkIntToScalar(bitmap.height())
2204 }; 2204 };
2205 if (paint) { 2205 if (paint) {
2206 (void)paint->computeFastBounds(bounds, &bounds); 2206 (void)paint->computeFastBounds(bounds, &bounds);
2207 } 2207 }
2208 if (this->quickReject(bounds)) { 2208 if (this->quickReject(bounds)) {
2209 return; 2209 return;
2210 } 2210 }
2211 } 2211 }
2212 2212
2213 SkMatrix matrix; 2213 SkMatrix matrix;
2214 matrix.setTranslate(x, y); 2214 matrix.setTranslate(x, y);
2215 this->internalDrawBitmap(bitmap, matrix, paint); 2215 this->internalDrawBitmap(bitmap, matrix, paint);
2216 } 2216 }
2217 2217
2218 // this one is non-virtual, so it can be called safely by other canvas apis 2218 // this one is non-virtual, so it can be called safely by other canvas apis
2219 void SkCanvas::internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, 2219 void SkCanvas::internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
2220 const SkRect& dst, const SkPaint* paint, 2220 const SkRect& dst, const SkPaint* paint,
2221 SrcRectConstraint constraint) { 2221 SrcRectConstraint constraint) {
2222 if (bitmap.drawsNothing() || dst.isEmpty()) { 2222 if (bitmap.drawsNothing() || dst.isEmpty()) {
2223 return; 2223 return;
2224 } 2224 }
2225 2225
2226 SkRect storage; 2226 SkRect storage;
2227 const SkRect* bounds = &dst; 2227 const SkRect* bounds = &dst;
2228 if (NULL == paint || paint->canComputeFastBounds()) { 2228 if (nullptr == paint || paint->canComputeFastBounds()) {
2229 if (paint) { 2229 if (paint) {
2230 bounds = &paint->computeFastBounds(dst, &storage); 2230 bounds = &paint->computeFastBounds(dst, &storage);
2231 } 2231 }
2232 if (this->quickReject(*bounds)) { 2232 if (this->quickReject(*bounds)) {
2233 return; 2233 return;
2234 } 2234 }
2235 } 2235 }
2236 2236
2237 SkLazyPaint lazy; 2237 SkLazyPaint lazy;
2238 if (NULL == paint) { 2238 if (nullptr == paint) {
2239 paint = lazy.init(); 2239 paint = lazy.init();
2240 } 2240 }
2241 2241
2242 LOOPER_BEGIN_CHECK_COMPLETE_OVERWRITE(*paint, SkDrawFilter::kBitmap_Type, bo unds, 2242 LOOPER_BEGIN_CHECK_COMPLETE_OVERWRITE(*paint, SkDrawFilter::kBitmap_Type, bo unds,
2243 bitmap.isOpaque()) 2243 bitmap.isOpaque())
2244 2244
2245 while (iter.next()) { 2245 while (iter.next()) {
2246 iter.fDevice->drawBitmapRect(iter, bitmap, src, dst, looper.paint(), con straint); 2246 iter.fDevice->drawBitmapRect(iter, bitmap, src, dst, looper.paint(), con straint);
2247 } 2247 }
2248 2248
2249 LOOPER_END 2249 LOOPER_END
2250 } 2250 }
2251 2251
2252 void SkCanvas::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst, 2252 void SkCanvas::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
2253 const SkPaint* paint, SrcRectConstraint constrai nt) { 2253 const SkPaint* paint, SrcRectConstraint constrai nt) {
2254 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawBitmapRectToRect()") ; 2254 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawBitmapRectToRect()") ;
2255 SkDEBUGCODE(bitmap.validate();) 2255 SkDEBUGCODE(bitmap.validate();)
2256 this->internalDrawBitmapRect(bitmap, src, dst, paint, constraint); 2256 this->internalDrawBitmapRect(bitmap, src, dst, paint, constraint);
2257 } 2257 }
2258 2258
2259 void SkCanvas::onDrawImageNine(const SkImage* image, const SkIRect& center, cons t SkRect& dst, 2259 void SkCanvas::onDrawImageNine(const SkImage* image, const SkIRect& center, cons t SkRect& dst,
2260 const SkPaint* paint) { 2260 const SkPaint* paint) {
2261 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageNine()"); 2261 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageNine()");
2262 2262
2263 SkRect storage; 2263 SkRect storage;
2264 const SkRect* bounds = &dst; 2264 const SkRect* bounds = &dst;
2265 if (NULL == paint || paint->canComputeFastBounds()) { 2265 if (nullptr == paint || paint->canComputeFastBounds()) {
2266 if (paint) { 2266 if (paint) {
2267 bounds = &paint->computeFastBounds(dst, &storage); 2267 bounds = &paint->computeFastBounds(dst, &storage);
2268 } 2268 }
2269 if (this->quickReject(*bounds)) { 2269 if (this->quickReject(*bounds)) {
2270 return; 2270 return;
2271 } 2271 }
2272 } 2272 }
2273 2273
2274 SkLazyPaint lazy; 2274 SkLazyPaint lazy;
2275 if (NULL == paint) { 2275 if (nullptr == paint) {
2276 paint = lazy.init(); 2276 paint = lazy.init();
2277 } 2277 }
2278 2278
2279 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, bounds) 2279 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, bounds)
2280 2280
2281 while (iter.next()) { 2281 while (iter.next()) {
2282 iter.fDevice->drawImageNine(iter, image, center, dst, looper.paint()); 2282 iter.fDevice->drawImageNine(iter, image, center, dst, looper.paint());
2283 } 2283 }
2284 2284
2285 LOOPER_END 2285 LOOPER_END
2286 } 2286 }
2287 2287
2288 void SkCanvas::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, c onst SkRect& dst, 2288 void SkCanvas::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, c onst SkRect& dst,
2289 const SkPaint* paint) { 2289 const SkPaint* paint) {
2290 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawBitmapNine()"); 2290 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawBitmapNine()");
2291 SkDEBUGCODE(bitmap.validate();) 2291 SkDEBUGCODE(bitmap.validate();)
2292 2292
2293 SkRect storage; 2293 SkRect storage;
2294 const SkRect* bounds = &dst; 2294 const SkRect* bounds = &dst;
2295 if (NULL == paint || paint->canComputeFastBounds()) { 2295 if (nullptr == paint || paint->canComputeFastBounds()) {
2296 if (paint) { 2296 if (paint) {
2297 bounds = &paint->computeFastBounds(dst, &storage); 2297 bounds = &paint->computeFastBounds(dst, &storage);
2298 } 2298 }
2299 if (this->quickReject(*bounds)) { 2299 if (this->quickReject(*bounds)) {
2300 return; 2300 return;
2301 } 2301 }
2302 } 2302 }
2303 2303
2304 SkLazyPaint lazy; 2304 SkLazyPaint lazy;
2305 if (NULL == paint) { 2305 if (nullptr == paint) {
2306 paint = lazy.init(); 2306 paint = lazy.init();
2307 } 2307 }
2308 2308
2309 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, bounds) 2309 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, bounds)
2310 2310
2311 while (iter.next()) { 2311 while (iter.next()) {
2312 iter.fDevice->drawBitmapNine(iter, bitmap, center, dst, looper.paint()); 2312 iter.fDevice->drawBitmapNine(iter, bitmap, center, dst, looper.paint());
2313 } 2313 }
2314 2314
2315 LOOPER_END 2315 LOOPER_END
(...skipping 26 matching lines...) Expand all
2342 } else { 2342 } else {
2343 SkPaint p(paint); 2343 SkPaint p(paint);
2344 p.setStrokeWidth(SkScalarMul(textSize, paint.getStrokeWidth())); 2344 p.setStrokeWidth(SkScalarMul(textSize, paint.getStrokeWidth()));
2345 draw.fDevice->drawRect(draw, r, p); 2345 draw.fDevice->drawRect(draw, r, p);
2346 } 2346 }
2347 } 2347 }
2348 2348
2349 void SkCanvas::DrawTextDecorations(const SkDraw& draw, const SkPaint& paint, 2349 void SkCanvas::DrawTextDecorations(const SkDraw& draw, const SkPaint& paint,
2350 const char text[], size_t byteLength, 2350 const char text[], size_t byteLength,
2351 SkScalar x, SkScalar y) { 2351 SkScalar x, SkScalar y) {
2352 SkASSERT(byteLength == 0 || text != NULL); 2352 SkASSERT(byteLength == 0 || text != nullptr);
2353 2353
2354 // nothing to draw 2354 // nothing to draw
2355 if (text == NULL || byteLength == 0 || 2355 if (text == nullptr || byteLength == 0 ||
2356 draw.fClip->isEmpty() || 2356 draw.fClip->isEmpty() ||
2357 (paint.getAlpha() == 0 && paint.getXfermode() == NULL)) { 2357 (paint.getAlpha() == 0 && paint.getXfermode() == nullptr)) {
2358 return; 2358 return;
2359 } 2359 }
2360 2360
2361 SkScalar width = 0; 2361 SkScalar width = 0;
2362 SkPoint start; 2362 SkPoint start;
2363 2363
2364 start.set(0, 0); // to avoid warning 2364 start.set(0, 0); // to avoid warning
2365 if (paint.getFlags() & (SkPaint::kUnderlineText_Flag | 2365 if (paint.getFlags() & (SkPaint::kUnderlineText_Flag |
2366 SkPaint::kStrikeThruText_Flag)) { 2366 SkPaint::kStrikeThruText_Flag)) {
2367 width = paint.measureText(text, byteLength); 2367 width = paint.measureText(text, byteLength);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2402 start.fY); 2402 start.fY);
2403 r.fTop = offset; 2403 r.fTop = offset;
2404 r.fBottom = offset + height; 2404 r.fBottom = offset + height;
2405 DrawRect(draw, paint, r, textSize); 2405 DrawRect(draw, paint, r, textSize);
2406 } 2406 }
2407 } 2407 }
2408 } 2408 }
2409 2409
2410 void SkCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkSca lar y, 2410 void SkCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkSca lar y,
2411 const SkPaint& paint) { 2411 const SkPaint& paint) {
2412 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL) 2412 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, nullptr)
2413 2413
2414 while (iter.next()) { 2414 while (iter.next()) {
2415 SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint()); 2415 SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint());
2416 iter.fDevice->drawText(iter, text, byteLength, x, y, dfp.paint()); 2416 iter.fDevice->drawText(iter, text, byteLength, x, y, dfp.paint());
2417 DrawTextDecorations(iter, dfp.paint(), 2417 DrawTextDecorations(iter, dfp.paint(),
2418 static_cast<const char*>(text), byteLength, x, y); 2418 static_cast<const char*>(text), byteLength, x, y);
2419 } 2419 }
2420 2420
2421 LOOPER_END 2421 LOOPER_END
2422 } 2422 }
2423 2423
2424 void SkCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[], 2424 void SkCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
2425 const SkPaint& paint) { 2425 const SkPaint& paint) {
2426 SkPoint textOffset = SkPoint::Make(0, 0); 2426 SkPoint textOffset = SkPoint::Make(0, 0);
2427 2427
2428 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL) 2428 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, nullptr)
2429 2429
2430 while (iter.next()) { 2430 while (iter.next()) {
2431 SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint()); 2431 SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint());
2432 iter.fDevice->drawPosText(iter, text, byteLength, &pos->fX, 2, textOffse t, 2432 iter.fDevice->drawPosText(iter, text, byteLength, &pos->fX, 2, textOffse t,
2433 dfp.paint()); 2433 dfp.paint());
2434 } 2434 }
2435 2435
2436 LOOPER_END 2436 LOOPER_END
2437 } 2437 }
2438 2438
2439 void SkCanvas::onDrawPosTextH(const void* text, size_t byteLength, const SkScala r xpos[], 2439 void SkCanvas::onDrawPosTextH(const void* text, size_t byteLength, const SkScala r xpos[],
2440 SkScalar constY, const SkPaint& paint) { 2440 SkScalar constY, const SkPaint& paint) {
2441 2441
2442 SkPoint textOffset = SkPoint::Make(0, constY); 2442 SkPoint textOffset = SkPoint::Make(0, constY);
2443 2443
2444 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL) 2444 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, nullptr)
2445 2445
2446 while (iter.next()) { 2446 while (iter.next()) {
2447 SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint()); 2447 SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint());
2448 iter.fDevice->drawPosText(iter, text, byteLength, xpos, 1, textOffset, 2448 iter.fDevice->drawPosText(iter, text, byteLength, xpos, 1, textOffset,
2449 dfp.paint()); 2449 dfp.paint());
2450 } 2450 }
2451 2451
2452 LOOPER_END 2452 LOOPER_END
2453 } 2453 }
2454 2454
2455 void SkCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const SkPat h& path, 2455 void SkCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const SkPat h& path,
2456 const SkMatrix* matrix, const SkPaint& paint) { 2456 const SkMatrix* matrix, const SkPaint& paint) {
2457 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL) 2457 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, nullptr)
2458 2458
2459 while (iter.next()) { 2459 while (iter.next()) {
2460 iter.fDevice->drawTextOnPath(iter, text, byteLength, path, 2460 iter.fDevice->drawTextOnPath(iter, text, byteLength, path,
2461 matrix, looper.paint()); 2461 matrix, looper.paint());
2462 } 2462 }
2463 2463
2464 LOOPER_END 2464 LOOPER_END
2465 } 2465 }
2466 2466
2467 void SkCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, 2467 void SkCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
2468 const SkPaint& paint) { 2468 const SkPaint& paint) {
2469 2469
2470 SkRect storage; 2470 SkRect storage;
2471 const SkRect* bounds = NULL; 2471 const SkRect* bounds = nullptr;
2472 if (paint.canComputeFastBounds()) { 2472 if (paint.canComputeFastBounds()) {
2473 storage = blob->bounds().makeOffset(x, y); 2473 storage = blob->bounds().makeOffset(x, y);
2474 bounds = &paint.computeFastBounds(storage, &storage); 2474 bounds = &paint.computeFastBounds(storage, &storage);
2475 2475
2476 if (this->quickReject(*bounds)) { 2476 if (this->quickReject(*bounds)) {
2477 return; 2477 return;
2478 } 2478 }
2479 } 2479 }
2480 2480
2481 // We cannot filter in the looper as we normally do, because the paint is 2481 // We cannot filter in the looper as we normally do, because the paint is
2482 // incomplete at this point (text-related attributes are embedded within blo b run paints). 2482 // incomplete at this point (text-related attributes are embedded within blo b run paints).
2483 SkDrawFilter* drawFilter = fMCRec->fFilter; 2483 SkDrawFilter* drawFilter = fMCRec->fFilter;
2484 fMCRec->fFilter = NULL; 2484 fMCRec->fFilter = nullptr;
2485 2485
2486 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, bounds) 2486 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, bounds)
2487 2487
2488 while (iter.next()) { 2488 while (iter.next()) {
2489 SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint()); 2489 SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint());
2490 iter.fDevice->drawTextBlob(iter, blob, x, y, dfp.paint(), drawFilter); 2490 iter.fDevice->drawTextBlob(iter, blob, x, y, dfp.paint(), drawFilter);
2491 } 2491 }
2492 2492
2493 LOOPER_END 2493 LOOPER_END
2494 2494
(...skipping 28 matching lines...) Expand all
2523 this->onDrawTextBlob(blob, x, y, paint); 2523 this->onDrawTextBlob(blob, x, y, paint);
2524 } 2524 }
2525 } 2525 }
2526 2526
2527 void SkCanvas::onDrawVertices(VertexMode vmode, int vertexCount, 2527 void SkCanvas::onDrawVertices(VertexMode vmode, int vertexCount,
2528 const SkPoint verts[], const SkPoint texs[], 2528 const SkPoint verts[], const SkPoint texs[],
2529 const SkColor colors[], SkXfermode* xmode, 2529 const SkColor colors[], SkXfermode* xmode,
2530 const uint16_t indices[], int indexCount, 2530 const uint16_t indices[], int indexCount,
2531 const SkPaint& paint) { 2531 const SkPaint& paint) {
2532 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawVertices()"); 2532 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawVertices()");
2533 LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, NULL) 2533 LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, nullptr)
2534 2534
2535 while (iter.next()) { 2535 while (iter.next()) {
2536 iter.fDevice->drawVertices(iter, vmode, vertexCount, verts, texs, 2536 iter.fDevice->drawVertices(iter, vmode, vertexCount, verts, texs,
2537 colors, xmode, indices, indexCount, 2537 colors, xmode, indices, indexCount,
2538 looper.paint()); 2538 looper.paint());
2539 } 2539 }
2540 2540
2541 LOOPER_END 2541 LOOPER_END
2542 } 2542 }
2543 2543
2544 void SkCanvas::drawPatch(const SkPoint cubics[12], const SkColor colors[4], 2544 void SkCanvas::drawPatch(const SkPoint cubics[12], const SkColor colors[4],
2545 const SkPoint texCoords[4], SkXfermode* xmode, const Sk Paint& paint) { 2545 const SkPoint texCoords[4], SkXfermode* xmode, const Sk Paint& paint) {
2546 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawPatch()"); 2546 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawPatch()");
2547 if (NULL == cubics) { 2547 if (nullptr == cubics) {
2548 return; 2548 return;
2549 } 2549 }
2550 2550
2551 // Since a patch is always within the convex hull of the control points, we discard it when its 2551 // Since a patch is always within the convex hull of the control points, we discard it when its
2552 // bounding rectangle is completely outside the current clip. 2552 // bounding rectangle is completely outside the current clip.
2553 SkRect bounds; 2553 SkRect bounds;
2554 bounds.set(cubics, SkPatchUtils::kNumCtrlPts); 2554 bounds.set(cubics, SkPatchUtils::kNumCtrlPts);
2555 if (this->quickReject(bounds)) { 2555 if (this->quickReject(bounds)) {
2556 return; 2556 return;
2557 } 2557 }
2558 2558
2559 this->onDrawPatch(cubics, colors, texCoords, xmode, paint); 2559 this->onDrawPatch(cubics, colors, texCoords, xmode, paint);
2560 } 2560 }
2561 2561
2562 void SkCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], 2562 void SkCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
2563 const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint) { 2563 const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint) {
2564 2564
2565 LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, NULL) 2565 LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, nullptr)
2566 2566
2567 while (iter.next()) { 2567 while (iter.next()) {
2568 iter.fDevice->drawPatch(iter, cubics, colors, texCoords, xmode, paint); 2568 iter.fDevice->drawPatch(iter, cubics, colors, texCoords, xmode, paint);
2569 } 2569 }
2570 2570
2571 LOOPER_END 2571 LOOPER_END
2572 } 2572 }
2573 2573
2574 void SkCanvas::drawDrawable(SkDrawable* dr, SkScalar x, SkScalar y) { 2574 void SkCanvas::drawDrawable(SkDrawable* dr, SkScalar x, SkScalar y) {
2575 if (dr) { 2575 if (dr) {
2576 if (x || y) { 2576 if (x || y) {
2577 SkMatrix matrix = SkMatrix::MakeTrans(x, y); 2577 SkMatrix matrix = SkMatrix::MakeTrans(x, y);
2578 this->onDrawDrawable(dr, &matrix); 2578 this->onDrawDrawable(dr, &matrix);
2579 } else { 2579 } else {
2580 this->onDrawDrawable(dr, NULL); 2580 this->onDrawDrawable(dr, nullptr);
2581 } 2581 }
2582 } 2582 }
2583 } 2583 }
2584 2584
2585 void SkCanvas::drawDrawable(SkDrawable* dr, const SkMatrix* matrix) { 2585 void SkCanvas::drawDrawable(SkDrawable* dr, const SkMatrix* matrix) {
2586 if (dr) { 2586 if (dr) {
2587 if (matrix && matrix->isIdentity()) { 2587 if (matrix && matrix->isIdentity()) {
2588 matrix = NULL; 2588 matrix = nullptr;
2589 } 2589 }
2590 this->onDrawDrawable(dr, matrix); 2590 this->onDrawDrawable(dr, matrix);
2591 } 2591 }
2592 } 2592 }
2593 2593
2594 void SkCanvas::onDrawDrawable(SkDrawable* dr, const SkMatrix* matrix) { 2594 void SkCanvas::onDrawDrawable(SkDrawable* dr, const SkMatrix* matrix) {
2595 SkRect bounds = dr->getBounds(); 2595 SkRect bounds = dr->getBounds();
2596 if (matrix) { 2596 if (matrix) {
2597 matrix->mapRect(&bounds); 2597 matrix->mapRect(&bounds);
2598 } 2598 }
2599 if (this->quickReject(bounds)) { 2599 if (this->quickReject(bounds)) {
2600 return; 2600 return;
2601 } 2601 }
2602 dr->draw(this, matrix); 2602 dr->draw(this, matrix);
2603 } 2603 }
2604 2604
2605 void SkCanvas::onDrawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], 2605 void SkCanvas::onDrawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[],
2606 const SkColor colors[], int count, SkXfermode::Mode m ode, 2606 const SkColor colors[], int count, SkXfermode::Mode m ode,
2607 const SkRect* cull, const SkPaint* paint) { 2607 const SkRect* cull, const SkPaint* paint) {
2608 if (cull && this->quickReject(*cull)) { 2608 if (cull && this->quickReject(*cull)) {
2609 return; 2609 return;
2610 } 2610 }
2611 2611
2612 SkPaint pnt; 2612 SkPaint pnt;
2613 if (paint) { 2613 if (paint) {
2614 pnt = *paint; 2614 pnt = *paint;
2615 } 2615 }
2616 2616
2617 LOOPER_BEGIN(pnt, SkDrawFilter::kPath_Type, NULL) 2617 LOOPER_BEGIN(pnt, SkDrawFilter::kPath_Type, nullptr)
2618 while (iter.next()) { 2618 while (iter.next()) {
2619 iter.fDevice->drawAtlas(iter, atlas, xform, tex, colors, count, mode, pn t); 2619 iter.fDevice->drawAtlas(iter, atlas, xform, tex, colors, count, mode, pn t);
2620 } 2620 }
2621 LOOPER_END 2621 LOOPER_END
2622 } 2622 }
2623 2623
2624 ////////////////////////////////////////////////////////////////////////////// 2624 //////////////////////////////////////////////////////////////////////////////
2625 // These methods are NOT virtual, and therefore must call back into virtual 2625 // These methods are NOT virtual, and therefore must call back into virtual
2626 // methods, rather than actually drawing themselves. 2626 // methods, rather than actually drawing themselves.
2627 ////////////////////////////////////////////////////////////////////////////// 2627 //////////////////////////////////////////////////////////////////////////////
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
2754 * 2754 *
2755 * For now we pick a conservatively small value, though measurement (and other heuristics like 2755 * For now we pick a conservatively small value, though measurement (and other heuristics like
2756 * the type of ops contained) may justify changing this value. 2756 * the type of ops contained) may justify changing this value.
2757 */ 2757 */
2758 #define kMaxPictureOpsToUnrollInsteadOfRef 1 2758 #define kMaxPictureOpsToUnrollInsteadOfRef 1
2759 2759
2760 void SkCanvas::drawPicture(const SkPicture* picture, const SkMatrix* matrix, con st SkPaint* paint) { 2760 void SkCanvas::drawPicture(const SkPicture* picture, const SkMatrix* matrix, con st SkPaint* paint) {
2761 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawPicture()"); 2761 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawPicture()");
2762 if (picture) { 2762 if (picture) {
2763 if (matrix && matrix->isIdentity()) { 2763 if (matrix && matrix->isIdentity()) {
2764 matrix = NULL; 2764 matrix = nullptr;
2765 } 2765 }
2766 if (picture->approximateOpCount() <= kMaxPictureOpsToUnrollInsteadOfRef) { 2766 if (picture->approximateOpCount() <= kMaxPictureOpsToUnrollInsteadOfRef) {
2767 SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect( )); 2767 SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect( ));
2768 picture->playback(this); 2768 picture->playback(this);
2769 } else { 2769 } else {
2770 this->onDrawPicture(picture, matrix, paint); 2770 this->onDrawPicture(picture, matrix, paint);
2771 } 2771 }
2772 } 2772 }
2773 } 2773 }
2774 2774
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2823 SkBaseDevice* SkCanvas::LayerIter::device() const { 2823 SkBaseDevice* SkCanvas::LayerIter::device() const {
2824 return fImpl->getDevice(); 2824 return fImpl->getDevice();
2825 } 2825 }
2826 2826
2827 const SkMatrix& SkCanvas::LayerIter::matrix() const { 2827 const SkMatrix& SkCanvas::LayerIter::matrix() const {
2828 return fImpl->getMatrix(); 2828 return fImpl->getMatrix();
2829 } 2829 }
2830 2830
2831 const SkPaint& SkCanvas::LayerIter::paint() const { 2831 const SkPaint& SkCanvas::LayerIter::paint() const {
2832 const SkPaint* paint = fImpl->getPaint(); 2832 const SkPaint* paint = fImpl->getPaint();
2833 if (NULL == paint) { 2833 if (nullptr == paint) {
2834 paint = &fDefaultPaint; 2834 paint = &fDefaultPaint;
2835 } 2835 }
2836 return *paint; 2836 return *paint;
2837 } 2837 }
2838 2838
2839 const SkRegion& SkCanvas::LayerIter::clip() const { return fImpl->getClip(); } 2839 const SkRegion& SkCanvas::LayerIter::clip() const { return fImpl->getClip(); }
2840 int SkCanvas::LayerIter::x() const { return fImpl->getX(); } 2840 int SkCanvas::LayerIter::x() const { return fImpl->getX(); }
2841 int SkCanvas::LayerIter::y() const { return fImpl->getY(); } 2841 int SkCanvas::LayerIter::y() const { return fImpl->getY(); }
2842 2842
2843 /////////////////////////////////////////////////////////////////////////////// 2843 ///////////////////////////////////////////////////////////////////////////////
(...skipping 18 matching lines...) Expand all
2862 break; 2862 break;
2863 default: 2863 default:
2864 return false; 2864 return false;
2865 } 2865 }
2866 2866
2867 return true; 2867 return true;
2868 } 2868 }
2869 2869
2870 SkCanvas* SkCanvas::NewRasterDirect(const SkImageInfo& info, void* pixels, size_ t rowBytes) { 2870 SkCanvas* SkCanvas::NewRasterDirect(const SkImageInfo& info, void* pixels, size_ t rowBytes) {
2871 if (!supported_for_raster_canvas(info)) { 2871 if (!supported_for_raster_canvas(info)) {
2872 return NULL; 2872 return nullptr;
2873 } 2873 }
2874 2874
2875 SkBitmap bitmap; 2875 SkBitmap bitmap;
2876 if (!bitmap.installPixels(info, pixels, rowBytes)) { 2876 if (!bitmap.installPixels(info, pixels, rowBytes)) {
2877 return NULL; 2877 return nullptr;
2878 } 2878 }
2879 return new SkCanvas(bitmap); 2879 return new SkCanvas(bitmap);
2880 } 2880 }
2881 2881
2882 /////////////////////////////////////////////////////////////////////////////// 2882 ///////////////////////////////////////////////////////////////////////////////
2883 2883
2884 SkAutoCanvasMatrixPaint::SkAutoCanvasMatrixPaint(SkCanvas* canvas, const SkMatri x* matrix, 2884 SkAutoCanvasMatrixPaint::SkAutoCanvasMatrixPaint(SkCanvas* canvas, const SkMatri x* matrix,
2885 const SkPaint* paint, const SkR ect& bounds) 2885 const SkPaint* paint, const SkR ect& bounds)
2886 : fCanvas(canvas) 2886 : fCanvas(canvas)
2887 , fSaveCount(canvas->getSaveCount()) 2887 , fSaveCount(canvas->getSaveCount())
2888 { 2888 {
2889 if (paint) { 2889 if (paint) {
2890 SkRect newBounds = bounds; 2890 SkRect newBounds = bounds;
2891 if (matrix) { 2891 if (matrix) {
2892 matrix->mapRect(&newBounds); 2892 matrix->mapRect(&newBounds);
2893 } 2893 }
2894 canvas->saveLayer(&newBounds, paint); 2894 canvas->saveLayer(&newBounds, paint);
2895 } else if (matrix) { 2895 } else if (matrix) {
2896 canvas->save(); 2896 canvas->save();
2897 } 2897 }
2898 2898
2899 if (matrix) { 2899 if (matrix) {
2900 canvas->concat(*matrix); 2900 canvas->concat(*matrix);
2901 } 2901 }
2902 } 2902 }
2903 2903
2904 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { 2904 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() {
2905 fCanvas->restoreToCount(fSaveCount); 2905 fCanvas->restoreToCount(fSaveCount);
2906 } 2906 }
OLDNEW
« no previous file with comments | « src/core/SkCachedData.cpp ('k') | src/core/SkChunkAlloc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698