move GrMalloc, GrFree, Gr_bzero to their sk equivalents

BUG=
R=bsalomon@google.com

Review URL: https://codereview.chromium.org/23566022

git-svn-id: http://skia.googlecode.com/svn/trunk@11486 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2013-09-26 19:56:51 +00:00
parent baed71fbfe
commit 939ca7ce86
11 changed files with 20 additions and 31 deletions

View File

@ -79,7 +79,6 @@
'<(skia_src_path)/gpu/GrIndexBuffer.h', '<(skia_src_path)/gpu/GrIndexBuffer.h',
'<(skia_src_path)/gpu/GrInOrderDrawBuffer.cpp', '<(skia_src_path)/gpu/GrInOrderDrawBuffer.cpp',
'<(skia_src_path)/gpu/GrInOrderDrawBuffer.h', '<(skia_src_path)/gpu/GrInOrderDrawBuffer.h',
'<(skia_src_path)/gpu/GrMemory.cpp',
'<(skia_src_path)/gpu/GrMemoryPool.cpp', '<(skia_src_path)/gpu/GrMemoryPool.cpp',
'<(skia_src_path)/gpu/GrMemoryPool.h', '<(skia_src_path)/gpu/GrMemoryPool.h',
'<(skia_src_path)/gpu/GrOvalRenderer.cpp', '<(skia_src_path)/gpu/GrOvalRenderer.cpp',

View File

@ -125,16 +125,6 @@ static inline size_t GrSizeAlignDown(size_t x, uint32_t alignment) {
*/ */
#define GR_ARRAY_COUNT(array) SK_ARRAY_COUNT(array) #define GR_ARRAY_COUNT(array) SK_ARRAY_COUNT(array)
//!< allocate a block of memory, will never return NULL
extern void* GrMalloc(size_t bytes);
//!< free block allocated by GrMalloc. ptr may be NULL
extern void GrFree(void* ptr);
static inline void Gr_bzero(void* dst, size_t size) {
memset(dst, 0, size);
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
/** /**

View File

@ -20,7 +20,7 @@ struct GrAllocPool::Block {
static Block* Create(size_t size, Block* next) { static Block* Create(size_t size, Block* next) {
SkASSERT(size >= GrAllocPool_MIN_BLOCK_SIZE); SkASSERT(size >= GrAllocPool_MIN_BLOCK_SIZE);
Block* block = (Block*)GrMalloc(sizeof(Block) + size); Block* block = (Block*)sk_malloc_throw(sizeof(Block) + size);
block->fNext = next; block->fNext = next;
block->fPtr = (char*)block + sizeof(Block); block->fPtr = (char*)block + sizeof(Block);
block->fBytesFree = size; block->fBytesFree = size;
@ -69,7 +69,7 @@ void GrAllocPool::reset() {
Block* block = fBlock; Block* block = fBlock;
while (block) { while (block) {
Block* next = block->fNext; Block* next = block->fNext;
GrFree(block); sk_free(block);
block = next; block = next;
} }
fBlock = NULL; fBlock = NULL;
@ -94,7 +94,7 @@ void GrAllocPool::release(size_t bytes) {
bytes = fBlock->release(bytes); bytes = fBlock->release(bytes);
if (fBlock->empty()) { if (fBlock->empty()) {
Block* next = fBlock->fNext; Block* next = fBlock->fNext;
GrFree(fBlock); sk_free(fBlock);
fBlock = next; fBlock = next;
SkDEBUGCODE(fBlocksAllocated -= 1;) SkDEBUGCODE(fBlocksAllocated -= 1;)
} }

View File

@ -49,9 +49,9 @@ public:
// we always have at least one block // we always have at least one block
if (0 == indexInBlock) { if (0 == indexInBlock) {
if (0 != fCount) { if (0 != fCount) {
fBlocks.push_back() = GrMalloc(fBlockSize); fBlocks.push_back() = sk_malloc_throw(fBlockSize);
} else if (fOwnFirstBlock) { } else if (fOwnFirstBlock) {
fBlocks[0] = GrMalloc(fBlockSize); fBlocks[0] = sk_malloc_throw(fBlockSize);
} }
} }
void* ret = (char*)fBlocks[fCount/fItemsPerBlock] + void* ret = (char*)fBlocks[fCount/fItemsPerBlock] +
@ -67,10 +67,10 @@ public:
int blockCount = GrMax((unsigned)1, int blockCount = GrMax((unsigned)1,
GrUIDivRoundUp(fCount, fItemsPerBlock)); GrUIDivRoundUp(fCount, fItemsPerBlock));
for (int i = 1; i < blockCount; ++i) { for (int i = 1; i < blockCount; ++i) {
GrFree(fBlocks[i]); sk_free(fBlocks[i]);
} }
if (fOwnFirstBlock) { if (fOwnFirstBlock) {
GrFree(fBlocks[0]); sk_free(fBlocks[0]);
fBlocks[0] = NULL; fBlocks[0] = NULL;
} }
fBlocks.pop_back_n(blockCount-1); fBlocks.pop_back_n(blockCount-1);

View File

@ -125,7 +125,7 @@ bool GrAtlas::addSubImage(int width, int height, const void* image,
if (BORDER) { if (BORDER) {
const size_t dstRB = dstW * fBytesPerPixel; const size_t dstRB = dstW * fBytesPerPixel;
uint8_t* dst = (uint8_t*)storage.reset(dstH * dstRB); uint8_t* dst = (uint8_t*)storage.reset(dstH * dstRB);
Gr_bzero(dst, dstRB); // zero top row sk_bzero(dst, dstRB); // zero top row
dst += dstRB; dst += dstRB;
for (int y = 0; y < height; y++) { for (int y = 0; y < height; y++) {
dst = zerofill(dst, fBytesPerPixel); // zero left edge dst = zerofill(dst, fBytesPerPixel); // zero left edge
@ -134,7 +134,7 @@ bool GrAtlas::addSubImage(int width, int height, const void* image,
dst = zerofill(dst, fBytesPerPixel); // zero right edge dst = zerofill(dst, fBytesPerPixel); // zero right edge
image = (const void*)((const char*)image + width * fBytesPerPixel); image = (const void*)((const char*)image + width * fBytesPerPixel);
} }
Gr_bzero(dst, dstRB); // zero bottom row sk_bzero(dst, dstRB); // zero bottom row
image = storage.get(); image = storage.get();
} }
adjustForPlot(loc, fPlot); adjustForPlot(loc, fPlot);

View File

@ -276,14 +276,14 @@ const GrIndexBuffer* GrGpu::getQuadIndexBuffer() const {
fill_indices(indices, MAX_QUADS); fill_indices(indices, MAX_QUADS);
fQuadIndexBuffer->unlock(); fQuadIndexBuffer->unlock();
} else { } else {
indices = (uint16_t*)GrMalloc(SIZE); indices = (uint16_t*)sk_malloc_throw(SIZE);
fill_indices(indices, MAX_QUADS); fill_indices(indices, MAX_QUADS);
if (!fQuadIndexBuffer->updateData(indices, SIZE)) { if (!fQuadIndexBuffer->updateData(indices, SIZE)) {
fQuadIndexBuffer->unref(); fQuadIndexBuffer->unref();
fQuadIndexBuffer = NULL; fQuadIndexBuffer = NULL;
GrCrash("Can't get indices into buffer!"); GrCrash("Can't get indices into buffer!");
} }
GrFree(indices); sk_free(indices);
} }
} }
} }

View File

@ -104,7 +104,7 @@ void GrMemoryPool::release(void* p) {
GrMemoryPool::BlockHeader* GrMemoryPool::CreateBlock(size_t size) { GrMemoryPool::BlockHeader* GrMemoryPool::CreateBlock(size_t size) {
BlockHeader* block = BlockHeader* block =
reinterpret_cast<BlockHeader*>(GrMalloc(size + kHeaderSize)); reinterpret_cast<BlockHeader*>(sk_malloc_throw(size + kHeaderSize));
// we assume malloc gives us aligned memory // we assume malloc gives us aligned memory
SkASSERT(!(reinterpret_cast<intptr_t>(block) % kAlignment)); SkASSERT(!(reinterpret_cast<intptr_t>(block) % kAlignment));
block->fLiveCount = 0; block->fLiveCount = 0;
@ -115,7 +115,7 @@ GrMemoryPool::BlockHeader* GrMemoryPool::CreateBlock(size_t size) {
} }
void GrMemoryPool::DeleteBlock(BlockHeader* block) { void GrMemoryPool::DeleteBlock(BlockHeader* block) {
GrFree(block); sk_free(block);
} }
void GrMemoryPool::validate() { void GrMemoryPool::validate() {

View File

@ -32,7 +32,7 @@ public:
} }
void reset() { void reset() {
Gr_bzero(fBusy, fDim.fX * fDim.fY); sk_bzero(fBusy, fDim.fX * fDim.fY);
} }
bool newPlot(GrIPoint16* loc) { bool newPlot(GrIPoint16* loc) {

View File

@ -18,7 +18,7 @@ public:
GrRectanizerPow2(int w, int h) : GrRectanizer(w, h) { GrRectanizerPow2(int w, int h) : GrRectanizer(w, h) {
fNextStripY = 0; fNextStripY = 0;
fAreaSoFar = 0; fAreaSoFar = 0;
Gr_bzero(fRows, sizeof(fRows)); sk_bzero(fRows, sizeof(fRows));
} }
virtual ~GrRectanizerPow2() { virtual ~GrRectanizerPow2() {

View File

@ -18,7 +18,7 @@ public:
GrRectanizerFIFO(int w, int h) : GrRectanizer(w, h) { GrRectanizerFIFO(int w, int h) : GrRectanizer(w, h) {
fNextStripY = 0; fNextStripY = 0;
fAreaSoFar = 0; fAreaSoFar = 0;
Gr_bzero(fRows, sizeof(fRows)); sk_bzero(fRows, sizeof(fRows));
} }
virtual ~GrRectanizerFIFO() { virtual ~GrRectanizerFIFO() {

View File

@ -34,7 +34,7 @@ public:
*/ */
template <typename T, typename Key, size_t kHashBits> class GrTHashTable { template <typename T, typename Key, size_t kHashBits> class GrTHashTable {
public: public:
GrTHashTable() { Gr_bzero(fHash, sizeof(fHash)); } GrTHashTable() { sk_bzero(fHash, sizeof(fHash)); }
~GrTHashTable() {} ~GrTHashTable() {}
int count() const { return fSorted.count(); } int count() const { return fSorted.count(); }
@ -210,19 +210,19 @@ T* GrTHashTable<T, Key, kHashBits>::removeAt(int elemIndex, uint32_t hash) {
template <typename T, typename Key, size_t kHashBits> template <typename T, typename Key, size_t kHashBits>
void GrTHashTable<T, Key, kHashBits>::removeAll() { void GrTHashTable<T, Key, kHashBits>::removeAll() {
fSorted.reset(); fSorted.reset();
Gr_bzero(fHash, sizeof(fHash)); sk_bzero(fHash, sizeof(fHash));
} }
template <typename T, typename Key, size_t kHashBits> template <typename T, typename Key, size_t kHashBits>
void GrTHashTable<T, Key, kHashBits>::deleteAll() { void GrTHashTable<T, Key, kHashBits>::deleteAll() {
fSorted.deleteAll(); fSorted.deleteAll();
Gr_bzero(fHash, sizeof(fHash)); sk_bzero(fHash, sizeof(fHash));
} }
template <typename T, typename Key, size_t kHashBits> template <typename T, typename Key, size_t kHashBits>
void GrTHashTable<T, Key, kHashBits>::unrefAll() { void GrTHashTable<T, Key, kHashBits>::unrefAll() {
fSorted.unrefAll(); fSorted.unrefAll();
Gr_bzero(fHash, sizeof(fHash)); sk_bzero(fHash, sizeof(fHash));
} }
#ifdef SK_DEBUG #ifdef SK_DEBUG