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

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

Issue 2261573002: Fix initialization bug for fConservativeIsScaleTranslate (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkCanvas.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 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 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 623
624 void SkCanvas::resetForNextPicture(const SkIRect& bounds) { 624 void SkCanvas::resetForNextPicture(const SkIRect& bounds) {
625 this->restoreToCount(1); 625 this->restoreToCount(1);
626 fClipStack->reset(); 626 fClipStack->reset();
627 fMCRec->reset(bounds); 627 fMCRec->reset(bounds);
628 628
629 // We're peering through a lot of structs here. Only at this scope do we 629 // We're peering through a lot of structs here. Only at this scope do we
630 // know that the device is an SkBitmapDevice (really an SkNoPixelsBitmapDevi ce). 630 // know that the device is an SkBitmapDevice (really an SkNoPixelsBitmapDevi ce).
631 static_cast<SkBitmapDevice*>(fMCRec->fLayer->fDevice)->setNewSize(bounds.siz e()); 631 static_cast<SkBitmapDevice*>(fMCRec->fLayer->fDevice)->setNewSize(bounds.siz e());
632 fDeviceClipBounds = qr_clip_bounds(bounds); 632 fDeviceClipBounds = qr_clip_bounds(bounds);
633 fConservativeIsScaleTranslate = true; 633 fIsScaleTranslate = true;
634 } 634 }
635 635
636 SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) { 636 SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) {
637 if (device && device->forceConservativeRasterClip()) { 637 if (device && device->forceConservativeRasterClip()) {
638 flags = InitFlags(flags | kConservativeRasterClip_InitFlag); 638 flags = InitFlags(flags | kConservativeRasterClip_InitFlag);
639 } 639 }
640 // Since init() is only called once by our constructors, it is safe to perfo rm this 640 // Since init() is only called once by our constructors, it is safe to perfo rm this
641 // const-cast. 641 // const-cast.
642 *const_cast<bool*>(&fConservativeRasterClip) = SkToBool(flags & kConservativ eRasterClip_InitFlag); 642 *const_cast<bool*>(&fConservativeRasterClip) = SkToBool(flags & kConservativ eRasterClip_InitFlag);
643 643
644 fAllowSoftClip = true; 644 fAllowSoftClip = true;
645 fAllowSimplifyClip = false; 645 fAllowSimplifyClip = false;
646 fDeviceCMDirty = true; 646 fDeviceCMDirty = true;
647 fSaveCount = 1; 647 fSaveCount = 1;
648 fMetaData = nullptr; 648 fMetaData = nullptr;
649 #ifdef SK_EXPERIMENTAL_SHADOWING 649 #ifdef SK_EXPERIMENTAL_SHADOWING
650 fLights = nullptr; 650 fLights = nullptr;
651 #endif 651 #endif
652 652
653 fClipStack.reset(new SkClipStack); 653 fClipStack.reset(new SkClipStack);
654 654
655 fMCRec = (MCRec*)fMCStack.push_back(); 655 fMCRec = (MCRec*)fMCStack.push_back();
656 new (fMCRec) MCRec(fConservativeRasterClip); 656 new (fMCRec) MCRec(fConservativeRasterClip);
657 fIsScaleTranslate = true;
657 658
658 SkASSERT(sizeof(DeviceCM) <= sizeof(fDeviceCMStorage)); 659 SkASSERT(sizeof(DeviceCM) <= sizeof(fDeviceCMStorage));
659 fMCRec->fLayer = (DeviceCM*)fDeviceCMStorage; 660 fMCRec->fLayer = (DeviceCM*)fDeviceCMStorage;
660 new (fDeviceCMStorage) DeviceCM(nullptr, nullptr, nullptr, fConservativeRast erClip, 661 new (fDeviceCMStorage) DeviceCM(nullptr, nullptr, nullptr, fConservativeRast erClip,
661 fMCRec->fMatrix); 662 fMCRec->fMatrix);
662 663
663 fMCRec->fTopLayer = fMCRec->fLayer; 664 fMCRec->fTopLayer = fMCRec->fLayer;
664 665
665 fSurfaceBase = nullptr; 666 fSurfaceBase = nullptr;
666 667
667 if (device) { 668 if (device) {
668 // The root device and the canvas should always have the same pixel geom etry 669 // The root device and the canvas should always have the same pixel geom etry
669 SkASSERT(fProps.pixelGeometry() == device->surfaceProps().pixelGeometry( )); 670 SkASSERT(fProps.pixelGeometry() == device->surfaceProps().pixelGeometry( ));
670 fMCRec->fLayer->fDevice = SkRef(device); 671 fMCRec->fLayer->fDevice = SkRef(device);
671 fMCRec->fRasterClip.setRect(device->getGlobalBounds()); 672 fMCRec->fRasterClip.setRect(device->getGlobalBounds());
672 fDeviceClipBounds = qr_clip_bounds(device->getGlobalBounds()); 673 fDeviceClipBounds = qr_clip_bounds(device->getGlobalBounds());
673 fConservativeIsScaleTranslate = true;
674 } 674 }
675 675
676 return device; 676 return device;
677 } 677 }
678 678
679 SkCanvas::SkCanvas() 679 SkCanvas::SkCanvas()
680 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) 680 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
681 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) 681 , fProps(SkSurfaceProps::kLegacyFontHost_InitType)
682 , fConservativeRasterClip(false) 682 , fConservativeRasterClip(false)
683 { 683 {
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 delete layer; 1321 delete layer;
1322 } else { 1322 } else {
1323 // we're at the root 1323 // we're at the root
1324 SkASSERT(layer == (void*)fDeviceCMStorage); 1324 SkASSERT(layer == (void*)fDeviceCMStorage);
1325 layer->~DeviceCM(); 1325 layer->~DeviceCM();
1326 // no need to update fMCRec, 'cause we're killing the canvas 1326 // no need to update fMCRec, 'cause we're killing the canvas
1327 } 1327 }
1328 } 1328 }
1329 1329
1330 if (fMCRec) { 1330 if (fMCRec) {
1331 fConservativeIsScaleTranslate = fMCRec->fMatrix.isScaleTranslate(); 1331 fIsScaleTranslate = fMCRec->fMatrix.isScaleTranslate();
1332 fDeviceClipBounds = qr_clip_bounds(fMCRec->fRasterClip.getBounds()); 1332 fDeviceClipBounds = qr_clip_bounds(fMCRec->fRasterClip.getBounds());
1333 } 1333 }
1334 } 1334 }
1335 1335
1336 sk_sp<SkSurface> SkCanvas::makeSurface(const SkImageInfo& info, const SkSurfaceP rops* props) { 1336 sk_sp<SkSurface> SkCanvas::makeSurface(const SkImageInfo& info, const SkSurfaceP rops* props) {
1337 if (nullptr == props) { 1337 if (nullptr == props) {
1338 props = &fProps; 1338 props = &fProps;
1339 } 1339 }
1340 return this->onNewSurface(info, *props); 1340 return this->onNewSurface(info, *props);
1341 } 1341 }
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1479 } 1479 }
1480 1480
1481 void SkCanvas::concat(const SkMatrix& matrix) { 1481 void SkCanvas::concat(const SkMatrix& matrix) {
1482 if (matrix.isIdentity()) { 1482 if (matrix.isIdentity()) {
1483 return; 1483 return;
1484 } 1484 }
1485 1485
1486 this->checkForDeferredSave(); 1486 this->checkForDeferredSave();
1487 fDeviceCMDirty = true; 1487 fDeviceCMDirty = true;
1488 fMCRec->fMatrix.preConcat(matrix); 1488 fMCRec->fMatrix.preConcat(matrix);
1489 fConservativeIsScaleTranslate = fMCRec->fMatrix.isScaleTranslate(); 1489 fIsScaleTranslate = fMCRec->fMatrix.isScaleTranslate();
1490 this->didConcat(matrix); 1490 this->didConcat(matrix);
1491 } 1491 }
1492 1492
1493 void SkCanvas::internalSetMatrix(const SkMatrix& matrix) { 1493 void SkCanvas::internalSetMatrix(const SkMatrix& matrix) {
1494 fDeviceCMDirty = true; 1494 fDeviceCMDirty = true;
1495 fMCRec->fMatrix = matrix; 1495 fMCRec->fMatrix = matrix;
1496 } 1496 }
1497 1497
1498 void SkCanvas::setMatrix(const SkMatrix& matrix) { 1498 void SkCanvas::setMatrix(const SkMatrix& matrix) {
1499 this->checkForDeferredSave(); 1499 this->checkForDeferredSave();
1500 this->internalSetMatrix(matrix); 1500 this->internalSetMatrix(matrix);
1501 fConservativeIsScaleTranslate = matrix.isScaleTranslate(); 1501 fIsScaleTranslate = matrix.isScaleTranslate();
1502 this->didSetMatrix(matrix); 1502 this->didSetMatrix(matrix);
1503 } 1503 }
1504 1504
1505 void SkCanvas::resetMatrix() { 1505 void SkCanvas::resetMatrix() {
1506 this->setMatrix(SkMatrix::I()); 1506 this->setMatrix(SkMatrix::I());
1507 } 1507 }
1508 1508
1509 #ifdef SK_EXPERIMENTAL_SHADOWING 1509 #ifdef SK_EXPERIMENTAL_SHADOWING
1510 void SkCanvas::translateZ(SkScalar z) { 1510 void SkCanvas::translateZ(SkScalar z) {
1511 this->checkForDeferredSave(); 1511 this->checkForDeferredSave();
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1837 bool SkCanvas::quickReject(const SkRect& src) const { 1837 bool SkCanvas::quickReject(const SkRect& src) const {
1838 #ifdef SK_DEBUG 1838 #ifdef SK_DEBUG
1839 // Verify that fDeviceClipBounds are set properly. 1839 // Verify that fDeviceClipBounds are set properly.
1840 SkRect tmp = qr_clip_bounds(fMCRec->fRasterClip.getBounds()); 1840 SkRect tmp = qr_clip_bounds(fMCRec->fRasterClip.getBounds());
1841 if (fMCRec->fRasterClip.isEmpty()) { 1841 if (fMCRec->fRasterClip.isEmpty()) {
1842 SkASSERT(fDeviceClipBounds.isEmpty()); 1842 SkASSERT(fDeviceClipBounds.isEmpty());
1843 } else { 1843 } else {
1844 SkASSERT(tmp == fDeviceClipBounds); 1844 SkASSERT(tmp == fDeviceClipBounds);
1845 } 1845 }
1846 1846
1847 // Verify that fConservativeIsScaleTranslate is set properly. 1847 // Verify that fIsScaleTranslate is set properly.
1848 SkASSERT(!fConservativeIsScaleTranslate || fMCRec->fMatrix.isScaleTranslate( )); 1848 SkASSERT(fIsScaleTranslate == fMCRec->fMatrix.isScaleTranslate());
1849 #endif 1849 #endif
1850 1850
1851 if (!fConservativeIsScaleTranslate) { 1851 if (!fIsScaleTranslate) {
1852 return quick_reject_slow_path(src, fDeviceClipBounds, fMCRec->fMatrix); 1852 return quick_reject_slow_path(src, fDeviceClipBounds, fMCRec->fMatrix);
1853 } 1853 }
1854 1854
1855 // We inline the implementation of mapScaleTranslate() for the fast path. 1855 // We inline the implementation of mapScaleTranslate() for the fast path.
1856 float sx = fMCRec->fMatrix.getScaleX(); 1856 float sx = fMCRec->fMatrix.getScaleX();
1857 float sy = fMCRec->fMatrix.getScaleY(); 1857 float sy = fMCRec->fMatrix.getScaleY();
1858 float tx = fMCRec->fMatrix.getTranslateX(); 1858 float tx = fMCRec->fMatrix.getTranslateX();
1859 float ty = fMCRec->fMatrix.getTranslateY(); 1859 float ty = fMCRec->fMatrix.getTranslateY();
1860 Sk4f scale(sx, sy, sx, sy); 1860 Sk4f scale(sx, sy, sx, sy);
1861 Sk4f trans(tx, ty, tx, ty); 1861 Sk4f trans(tx, ty, tx, ty);
(...skipping 1501 matching lines...) Expand 10 before | Expand all | Expand 10 after
3363 3363
3364 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { 3364 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() {
3365 fCanvas->restoreToCount(fSaveCount); 3365 fCanvas->restoreToCount(fSaveCount);
3366 } 3366 }
3367 3367
3368 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API 3368 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API
3369 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) { 3369 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) {
3370 return this->makeSurface(info, props).release(); 3370 return this->makeSurface(info, props).release();
3371 } 3371 }
3372 #endif 3372 #endif
OLDNEW
« no previous file with comments | « include/core/SkCanvas.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698