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

Unified Diff: src/core/SkDescriptor.h

Issue 1041953002: Switch to one single bitmap text blob cache allocation (Closed) Base URL: https://skia.googlesource.com/skia.git@bmptext2
Patch Set: tidy up SkAutoDescriptor a bit more Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: src/core/SkDescriptor.h
diff --git a/src/core/SkDescriptor.h b/src/core/SkDescriptor.h
index 22ec29316fd30094ed6ad36cff8150acde8808cd..874c69d7f9cdcebfc792077cb3ba60dd81a8d524 100644
--- a/src/core/SkDescriptor.h
+++ b/src/core/SkDescriptor.h
@@ -134,22 +134,38 @@ private:
class SkAutoDescriptor : SkNoncopyable {
public:
- SkAutoDescriptor(size_t size) {
- if (size <= sizeof(fStorage)) {
+ SkAutoDescriptor() : fDesc(NULL), fHeapAllocSize(0) {}
+ SkAutoDescriptor(size_t size) : fDesc(NULL), fHeapAllocSize(0) { this->reset(size); }
+
+ ~SkAutoDescriptor() { this->free(); }
+
+ void reset(size_t size) {
+ if (this->isHeapAlloc()) {
+ if (size > fHeapAllocSize) {
+ this->free();
+ this->alloc(size);
+ }
+ } else if (size <= sizeof(fStorage)) {
fDesc = (SkDescriptor*)(void*)fStorage;
} else {
- fDesc = SkDescriptor::Alloc(size);
+ SkASSERT(!fDesc);
+ this->alloc(size);
}
}
- ~SkAutoDescriptor() {
- if (fDesc != (SkDescriptor*)(void*)fStorage) {
+ SkDescriptor* getDesc() const { SkASSERT(fDesc); return fDesc; }
+private:
+ void alloc(size_t size) {
+ fDesc = SkDescriptor::Alloc(size);
+ fHeapAllocSize = size;
+ }
+ bool isHeapAlloc() const { return fDesc && fDesc != (SkDescriptor*)(void*)fStorage; }
+ void free() {
+ if (this->isHeapAlloc()) {
SkDescriptor::Free(fDesc);
}
}
- SkDescriptor* getDesc() const { return fDesc; }
-private:
enum {
kStorageSize = sizeof(SkDescriptor)
+ sizeof(SkDescriptor::Entry) + sizeof(SkScalerContext::Rec) // for rec
@@ -158,6 +174,7 @@ private:
};
SkDescriptor* fDesc;
uint32_t fStorage[(kStorageSize + 3) >> 2];
+ size_t fHeapAllocSize;
bsalomon 2015/04/01 15:41:45 Is this really worth the complexity? Seems much si
joshualitt 2015/04/01 16:54:23 If I'm going to be reusing the blobs, which I basi
};
#define SkAutoDescriptor(...) SK_REQUIRE_LOCAL_VAR(SkAutoDescriptor)
« no previous file with comments | « include/core/SkPaint.h ('k') | src/core/SkPaint.cpp » ('j') | src/gpu/GrBitmapTextContext.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698