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 @@
}
/**
+ * 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<SkPaint> SkLazyPaint;
+
///////////////////////////////////////////////////////////////////////////////
// Helpers for computing fast bounds for quickReject tests
@@ -305,14 +307,14 @@
bool next(SkDrawFilter::Type drawType);
private:
- SkTLazy<SkPaint> 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 @@
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 @@
const SkPaint& paint() const { return *fPaint; }
private:
- const SkPaint* fPaint;
- SkTLazy<SkPaint> fLazy;
+ const SkPaint* fPaint;
+ SkLazyPaint fLazy;
};
void SkCanvas::drawText(const void* text, size_t byteLength,