remove GrAllocPool
BUG=skia: Review URL: https://codereview.chromium.org/742253002
This commit is contained in:
parent
42ddcd4906
commit
947556f658
@ -52,8 +52,6 @@
|
||||
'<(skia_src_path)/gpu/GrAARectRenderer.h',
|
||||
'<(skia_src_path)/gpu/GrAddPathRenderers_default.cpp',
|
||||
'<(skia_src_path)/gpu/GrAllocator.h',
|
||||
'<(skia_src_path)/gpu/GrAllocPool.h',
|
||||
'<(skia_src_path)/gpu/GrAllocPool.cpp',
|
||||
'<(skia_src_path)/gpu/GrAtlas.cpp',
|
||||
'<(skia_src_path)/gpu/GrAtlas.h',
|
||||
'<(skia_src_path)/gpu/GrBitmapTextContext.cpp',
|
||||
|
@ -9,7 +9,6 @@
|
||||
#ifndef GrAADistanceFieldPathRenderer_DEFINED
|
||||
#define GrAADistanceFieldPathRenderer_DEFINED
|
||||
|
||||
#include "GrAllocPool.h"
|
||||
#include "GrAtlas.h"
|
||||
#include "GrPathRenderer.h"
|
||||
#include "GrRect.h"
|
||||
|
@ -1,116 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "GrAllocPool.h"
|
||||
|
||||
#include "GrTypes.h"
|
||||
|
||||
#define GrAllocPool_MIN_BLOCK_SIZE ((size_t)128)
|
||||
|
||||
struct GrAllocPool::Block {
|
||||
Block* fNext;
|
||||
char* fPtr;
|
||||
size_t fBytesFree;
|
||||
size_t fBytesTotal;
|
||||
|
||||
static Block* Create(size_t size, Block* next) {
|
||||
SkASSERT(size >= GrAllocPool_MIN_BLOCK_SIZE);
|
||||
|
||||
Block* block = (Block*)sk_malloc_throw(sizeof(Block) + size);
|
||||
block->fNext = next;
|
||||
block->fPtr = (char*)block + sizeof(Block);
|
||||
block->fBytesFree = size;
|
||||
block->fBytesTotal = size;
|
||||
return block;
|
||||
}
|
||||
|
||||
bool canAlloc(size_t bytes) const {
|
||||
return bytes <= fBytesFree;
|
||||
}
|
||||
|
||||
void* alloc(size_t bytes) {
|
||||
SkASSERT(bytes <= fBytesFree);
|
||||
fBytesFree -= bytes;
|
||||
void* ptr = fPtr;
|
||||
fPtr += bytes;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
size_t release(size_t bytes) {
|
||||
SkASSERT(bytes > 0);
|
||||
size_t free = SkTMin(bytes, fBytesTotal - fBytesFree);
|
||||
fBytesFree += free;
|
||||
fPtr -= free;
|
||||
return bytes - free;
|
||||
}
|
||||
|
||||
bool empty() const { return fBytesTotal == fBytesFree; }
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GrAllocPool::GrAllocPool(size_t blockSize) {
|
||||
fBlock = NULL;
|
||||
fMinBlockSize = SkTMax(blockSize, GrAllocPool_MIN_BLOCK_SIZE);
|
||||
SkDEBUGCODE(fBlocksAllocated = 0;)
|
||||
}
|
||||
|
||||
GrAllocPool::~GrAllocPool() {
|
||||
this->reset();
|
||||
}
|
||||
|
||||
void GrAllocPool::reset() {
|
||||
this->validate();
|
||||
|
||||
Block* block = fBlock;
|
||||
while (block) {
|
||||
Block* next = block->fNext;
|
||||
sk_free(block);
|
||||
block = next;
|
||||
}
|
||||
fBlock = NULL;
|
||||
SkDEBUGCODE(fBlocksAllocated = 0;)
|
||||
}
|
||||
|
||||
void* GrAllocPool::alloc(size_t size) {
|
||||
this->validate();
|
||||
|
||||
if (!fBlock || !fBlock->canAlloc(size)) {
|
||||
size_t blockSize = SkTMax(fMinBlockSize, size);
|
||||
fBlock = Block::Create(blockSize, fBlock);
|
||||
SkDEBUGCODE(fBlocksAllocated += 1;)
|
||||
}
|
||||
return fBlock->alloc(size);
|
||||
}
|
||||
|
||||
void GrAllocPool::release(size_t bytes) {
|
||||
this->validate();
|
||||
|
||||
while (bytes && fBlock) {
|
||||
bytes = fBlock->release(bytes);
|
||||
if (fBlock->empty()) {
|
||||
Block* next = fBlock->fNext;
|
||||
sk_free(fBlock);
|
||||
fBlock = next;
|
||||
SkDEBUGCODE(fBlocksAllocated -= 1;)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
|
||||
void GrAllocPool::validate() const {
|
||||
Block* block = fBlock;
|
||||
int count = 0;
|
||||
while (block) {
|
||||
count += 1;
|
||||
block = block->fNext;
|
||||
}
|
||||
SkASSERT(fBlocksAllocated == count);
|
||||
}
|
||||
|
||||
#endif
|
@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef GrAllocPool_DEFINED
|
||||
#define GrAllocPool_DEFINED
|
||||
|
||||
#include "SkTypes.h"
|
||||
|
||||
class GrAllocPool : SkNoncopyable {
|
||||
public:
|
||||
GrAllocPool(size_t blockSize = 0);
|
||||
~GrAllocPool();
|
||||
|
||||
/**
|
||||
* Frees all blocks that have been allocated with alloc().
|
||||
*/
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* Returns a block of memory bytes size big. This address must not be
|
||||
* passed to realloc/free/delete or any other function that assumes the
|
||||
* address was allocated by malloc or new (because it hasn't).
|
||||
*/
|
||||
void* alloc(size_t bytes);
|
||||
|
||||
/**
|
||||
* Releases the most recently allocated bytes back to allocpool.
|
||||
*/
|
||||
void release(size_t bytes);
|
||||
|
||||
private:
|
||||
struct Block;
|
||||
|
||||
Block* fBlock;
|
||||
size_t fMinBlockSize;
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
int fBlocksAllocated;
|
||||
void validate() const;
|
||||
#else
|
||||
void validate() const {}
|
||||
#endif
|
||||
};
|
||||
|
||||
template <typename T> class GrTAllocPool {
|
||||
public:
|
||||
GrTAllocPool(int count) : fPool(count * sizeof(T)) {}
|
||||
|
||||
void reset() { fPool.reset(); }
|
||||
T* alloc() { return (T*)fPool.alloc(sizeof(T)); }
|
||||
|
||||
private:
|
||||
GrAllocPool fPool;
|
||||
};
|
||||
|
||||
#endif
|
@ -227,7 +227,7 @@ void GrFontCache::dump() const {
|
||||
atlas and a position within that texture.
|
||||
*/
|
||||
|
||||
GrTextStrike::GrTextStrike(GrFontCache* cache, const GrFontDescKey* key) : fPool(64) {
|
||||
GrTextStrike::GrTextStrike(GrFontCache* cache, const GrFontDescKey* key) {
|
||||
fFontScalerKey = key;
|
||||
fFontScalerKey->ref();
|
||||
|
||||
@ -267,7 +267,7 @@ GrGlyph* GrTextStrike::generateGlyph(GrGlyph::PackedID packed,
|
||||
}
|
||||
GrMaskFormat format = scaler->getPackedGlyphMaskFormat(packed);
|
||||
|
||||
GrGlyph* glyph = fPool.alloc();
|
||||
GrGlyph* glyph = (GrGlyph*)fPool.alloc(sizeof(GrGlyph), SK_MALLOC_THROW);
|
||||
glyph->init(packed, bounds, format);
|
||||
fCache.add(glyph);
|
||||
return glyph;
|
||||
|
@ -11,12 +11,12 @@
|
||||
#ifndef GrTextStrike_DEFINED
|
||||
#define GrTextStrike_DEFINED
|
||||
|
||||
#include "GrAllocPool.h"
|
||||
#include "GrFontScaler.h"
|
||||
#include "SkTDynamicHash.h"
|
||||
#include "GrGlyph.h"
|
||||
#include "GrDrawTarget.h"
|
||||
#include "GrAtlas.h"
|
||||
#include "GrDrawTarget.h"
|
||||
#include "GrFontScaler.h"
|
||||
#include "GrGlyph.h"
|
||||
#include "SkTDynamicHash.h"
|
||||
#include "SkVarAlloc.h"
|
||||
|
||||
class GrFontCache;
|
||||
class GrGpu;
|
||||
@ -62,7 +62,7 @@ public:
|
||||
private:
|
||||
SkTDynamicHash<GrGlyph, GrGlyph::PackedID> fCache;
|
||||
const GrFontDescKey* fFontScalerKey;
|
||||
GrTAllocPool<GrGlyph> fPool;
|
||||
SkVarAlloc fPool;
|
||||
|
||||
GrFontCache* fFontCache;
|
||||
bool fUseDistanceField;
|
||||
|
Loading…
Reference in New Issue
Block a user