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

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

Issue 17449012: combine glyph and image bulk alloc, and adjust initial alloc size, to reduce total waste from 50% t… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « include/core/SkChunkAlloc.h ('k') | src/core/SkGlyphCache.h » ('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 2006 The Android Open Source Project 2 * Copyright 2006 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 "SkChunkAlloc.h" 8 #include "SkChunkAlloc.h"
9 9
10 // Don't malloc any chunks smaller than this 10 // Don't malloc any chunks smaller than this
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 SkChunkAlloc::SkChunkAlloc(size_t minSize) { 46 SkChunkAlloc::SkChunkAlloc(size_t minSize) {
47 if (minSize < MIN_CHUNKALLOC_BLOCK_SIZE) { 47 if (minSize < MIN_CHUNKALLOC_BLOCK_SIZE) {
48 minSize = MIN_CHUNKALLOC_BLOCK_SIZE; 48 minSize = MIN_CHUNKALLOC_BLOCK_SIZE;
49 } 49 }
50 50
51 fBlock = NULL; 51 fBlock = NULL;
52 fMinSize = minSize; 52 fMinSize = minSize;
53 fChunkSize = fMinSize; 53 fChunkSize = fMinSize;
54 fTotalCapacity = 0; 54 fTotalCapacity = 0;
55 fTotalUsed = 0;
55 fBlockCount = 0; 56 fBlockCount = 0;
56 } 57 }
57 58
58 SkChunkAlloc::~SkChunkAlloc() { 59 SkChunkAlloc::~SkChunkAlloc() {
59 this->reset(); 60 this->reset();
60 } 61 }
61 62
62 void SkChunkAlloc::reset() { 63 void SkChunkAlloc::reset() {
63 Block::FreeChain(fBlock); 64 Block::FreeChain(fBlock);
64 fBlock = NULL; 65 fBlock = NULL;
65 fChunkSize = fMinSize; // reset to our initial minSize 66 fChunkSize = fMinSize; // reset to our initial minSize
66 fTotalCapacity = 0; 67 fTotalCapacity = 0;
68 fTotalUsed = 0;
67 fBlockCount = 0; 69 fBlockCount = 0;
68 } 70 }
69 71
70 SkChunkAlloc::Block* SkChunkAlloc::newBlock(size_t bytes, AllocFailType ftype) { 72 SkChunkAlloc::Block* SkChunkAlloc::newBlock(size_t bytes, AllocFailType ftype) {
71 size_t size = bytes; 73 size_t size = bytes;
72 if (size < fChunkSize) { 74 if (size < fChunkSize) {
73 size = fChunkSize; 75 size = fChunkSize;
74 } 76 }
75 77
76 Block* block = (Block*)sk_malloc_flags(sizeof(Block) + size, 78 Block* block = (Block*)sk_malloc_flags(sizeof(Block) + size,
77 ftype == kThrow_AllocFailType ? SK_MALLOC_THROW : 0); 79 ftype == kThrow_AllocFailType ? SK_MALLOC_THROW : 0);
78 80
79 if (block) { 81 if (block) {
80 // block->fNext = fBlock; 82 // block->fNext = fBlock;
81 block->fFreeSize = size; 83 block->fFreeSize = size;
82 block->fFreePtr = block->startOfData(); 84 block->fFreePtr = block->startOfData();
83 85
84 fTotalCapacity += size; 86 fTotalCapacity += size;
85 fBlockCount += 1; 87 fBlockCount += 1;
86 88
87 fChunkSize = increase_next_size(fChunkSize); 89 fChunkSize = increase_next_size(fChunkSize);
88 } 90 }
89 return block; 91 return block;
90 } 92 }
91 93
92 void* SkChunkAlloc::alloc(size_t bytes, AllocFailType ftype) { 94 void* SkChunkAlloc::alloc(size_t bytes, AllocFailType ftype) {
95 fTotalUsed += bytes;
96
93 bytes = SkAlign4(bytes); 97 bytes = SkAlign4(bytes);
94 98
95 Block* block = fBlock; 99 Block* block = fBlock;
96 100
97 if (block == NULL || bytes > block->fFreeSize) { 101 if (block == NULL || bytes > block->fFreeSize) {
98 block = this->newBlock(bytes, ftype); 102 block = this->newBlock(bytes, ftype);
99 if (NULL == block) { 103 if (NULL == block) {
100 return NULL; 104 return NULL;
101 } 105 }
102 block->fNext = fBlock; 106 block->fNext = fBlock;
(...skipping 26 matching lines...) Expand all
129 bool SkChunkAlloc::contains(const void* addr) const { 133 bool SkChunkAlloc::contains(const void* addr) const {
130 const Block* block = fBlock; 134 const Block* block = fBlock;
131 while (block) { 135 while (block) {
132 if (block->contains(addr)) { 136 if (block->contains(addr)) {
133 return true; 137 return true;
134 } 138 }
135 block = block->fNext; 139 block = block->fNext;
136 } 140 }
137 return false; 141 return false;
138 } 142 }
OLDNEW
« no previous file with comments | « include/core/SkChunkAlloc.h ('k') | src/core/SkGlyphCache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698