From: mike@reedtribe.org Date: Sun, 10 Apr 2011 00:35:29 +0000 (+0000) Subject: add init() to SkTLazy to create a default instance X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~18705 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2c8fc5a7038cdfbb28a8364fd0057f3c21f90bfd;p=platform%2Fupstream%2FlibSkiaSharp.git add init() to SkTLazy to create a default instance use SkLazyPaint in internalDrawBitmap git-svn-id: http://skia.googlecode.com/svn/trunk@1093 2bbb7eff-a529-9590-31e7-b0007b416f81 --- diff --git a/include/core/SkTLazy.h b/include/core/SkTLazy.h index 94e6415..fecc975 100644 --- a/include/core/SkTLazy.h +++ b/include/core/SkTLazy.h @@ -48,6 +48,20 @@ public: } /** + * Return a pointer to a default-initialized instance of the class. If a + * previous instance had been initialzied (either from init() or set()) it + * will first be destroyed, so that a freshly initialized instance is + * always returned. + */ + T* init() { + if (fPtr) { + fPtr->~T(); + } + fPtr = new (fStorage) T; + return fPtr; + } + + /** * Copy src into this, and return a pointer to a copy of it. Note this * will always return the same pointer, so if it is called on a lazy that * has already been initialized, then this will copy over the previous diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 07c7dbc..16cfc4b 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -51,6 +51,8 @@ #define dec_canvas() #endif +typedef SkTLazy SkLazyPaint; + /////////////////////////////////////////////////////////////////////////////// // Helpers for computing fast bounds for quickReject tests @@ -305,14 +307,14 @@ public: bool next(SkDrawFilter::Type drawType); private: - SkTLazy fLazyPaint; - SkCanvas* fCanvas; - const SkPaint& fOrigPaint; - SkDrawLooper* fLooper; - SkDrawFilter* fFilter; - const SkPaint* fPaint; - int fSaveCount; - bool fDone; + SkLazyPaint fLazyPaint; + SkCanvas* fCanvas; + const SkPaint& fOrigPaint; + SkDrawLooper* fLooper; + SkDrawFilter* fFilter; + const SkPaint* fPaint; + int fSaveCount; + bool fDone; }; bool AutoDrawLooper::next(SkDrawFilter::Type drawType) { @@ -841,12 +843,11 @@ void SkCanvas::internalDrawBitmap(const SkBitmap& bitmap, const SkIRect* srcRect return; } + SkLazyPaint lazy; if (NULL == paint) { - SkPaint tmpPaint; - this->commonDrawBitmap(bitmap, srcRect, matrix, tmpPaint); - } else { - this->commonDrawBitmap(bitmap, srcRect, matrix, *paint); + paint = lazy.init(); } + this->commonDrawBitmap(bitmap, srcRect, matrix, *paint); } void SkCanvas::drawDevice(SkDevice* device, int x, int y, @@ -1380,8 +1381,8 @@ public: const SkPaint& paint() const { return *fPaint; } private: - const SkPaint* fPaint; - SkTLazy fLazy; + const SkPaint* fPaint; + SkLazyPaint fLazy; }; void SkCanvas::drawText(const void* text, size_t byteLength,