Rename existing nonpreserving reallocs to reset, add reset to SkAutoMalloc, use reset in GrBufferAllocPool
Review URL: http://codereview.appspot.com/4951058/ git-svn-id: http://skia.googlecode.com/svn/trunk@2215 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
f8cead5e08
commit
7d4679a2e1
@ -95,7 +95,7 @@ bool GrAtlas::addSubImage(int width, int height, const void* image,
|
||||
if (BORDER) {
|
||||
const int bpp = GrMaskFormatBytesPerPixel(fMaskFormat);
|
||||
const size_t dstRB = dstW * bpp;
|
||||
uint8_t* dst = (uint8_t*)storage.realloc(dstH * dstRB);
|
||||
uint8_t* dst = (uint8_t*)storage.reset(dstH * dstRB);
|
||||
Gr_bzero(dst, dstRB); // zero top row
|
||||
dst += dstRB;
|
||||
for (int y = 0; y < height; y++) {
|
||||
|
@ -91,7 +91,7 @@ void GrBufferAllocPool::reset() {
|
||||
fFirstPreallocBuffer = (fFirstPreallocBuffer + fPreallocBuffersInUse) %
|
||||
fPreallocBuffers.count();
|
||||
}
|
||||
fCpuData.alloc(fGpu->supportsBufferLocking() ? 0 : fMinBlockSize);
|
||||
fCpuData.reset(fGpu->supportsBufferLocking() ? 0 : fMinBlockSize);
|
||||
GrAssert(0 == fPreallocBuffersInUse);
|
||||
VALIDATE();
|
||||
}
|
||||
@ -283,7 +283,7 @@ bool GrBufferAllocPool::createBlock(size_t requestSize) {
|
||||
}
|
||||
|
||||
if (NULL == fBufferPtr) {
|
||||
fBufferPtr = fCpuData.alloc(size);
|
||||
fBufferPtr = fCpuData.reset(size);
|
||||
}
|
||||
|
||||
VALIDATE(true);
|
||||
|
@ -193,7 +193,7 @@ bool GrDefaultPathRenderer::requiresStencilPass(const GrDrawTarget* target,
|
||||
}
|
||||
|
||||
void GrDefaultPathRenderer::pathWillClear() {
|
||||
fSubpathVertCount.realloc(0);
|
||||
fSubpathVertCount.reset(0);
|
||||
fTarget->resetVertexSource();
|
||||
if (fUseIndexedDraw) {
|
||||
fTarget->resetIndexSource();
|
||||
@ -278,7 +278,7 @@ bool GrDefaultPathRenderer::createGeom(GrScalar srcSpaceTol,
|
||||
idx = idxBase;
|
||||
}
|
||||
|
||||
fSubpathVertCount.realloc(fSubpathCount);
|
||||
fSubpathVertCount.reset(fSubpathCount);
|
||||
|
||||
GrPoint pts[4];
|
||||
|
||||
|
@ -151,7 +151,7 @@ void GrGLTexture::uploadTextureData(int x,
|
||||
if (flipY) {
|
||||
src += (height - 1) * rowBytes;
|
||||
}
|
||||
char* dst = (char*)tempStorage.realloc(trimSize);
|
||||
char* dst = (char*)tempStorage.reset(trimSize);
|
||||
for (int y = 0; y < height; y++) {
|
||||
memcpy(dst, src, trimRowBytes);
|
||||
if (flipY) {
|
||||
|
@ -788,7 +788,7 @@ void GrGpuGL::allocateAndUploadTexData(const GrGLTexture::Desc& desc,
|
||||
if (flipY) {
|
||||
src += (desc.fContentHeight - 1) * rowBytes;
|
||||
}
|
||||
char* dst = (char*)tempStorage.realloc(trimSize);
|
||||
char* dst = (char*)tempStorage.reset(trimSize);
|
||||
for (int y = 0; y < desc.fContentHeight; y++) {
|
||||
memcpy(dst, src, trimRowBytes);
|
||||
if (flipY) {
|
||||
|
@ -181,7 +181,7 @@ public:
|
||||
}
|
||||
|
||||
// doesn't preserve contents
|
||||
void realloc (size_t count) {
|
||||
void reset (size_t count) {
|
||||
sk_free(fPtr);
|
||||
fPtr = fPtr = (T*)sk_malloc_flags(count * sizeof(T), SK_MALLOC_THROW | SK_MALLOC_TEMP);
|
||||
}
|
||||
@ -225,7 +225,7 @@ public:
|
||||
}
|
||||
|
||||
// doesn't preserve contents
|
||||
void realloc (size_t count) {
|
||||
void reset(size_t count) {
|
||||
if (fPtr != fTStorage) {
|
||||
sk_free(fPtr);
|
||||
}
|
||||
|
@ -387,20 +387,57 @@ private:
|
||||
SkAutoFree& operator=(const SkAutoFree&);
|
||||
};
|
||||
|
||||
class SkAutoMalloc : public SkAutoFree {
|
||||
/**
|
||||
* Manage an allocated block of heap memory. This object is the sole manager of
|
||||
* the lifetime of the block, so the caller must not call sk_free() or delete
|
||||
* on the block.
|
||||
*/
|
||||
class SkAutoMalloc : public SkNoncopyable {
|
||||
public:
|
||||
explicit SkAutoMalloc(size_t size)
|
||||
: SkAutoFree(sk_malloc_flags(size, SK_MALLOC_THROW | SK_MALLOC_TEMP)) {}
|
||||
|
||||
SkAutoMalloc(size_t size, unsigned flags)
|
||||
: SkAutoFree(sk_malloc_flags(size, flags)) {}
|
||||
SkAutoMalloc() {}
|
||||
|
||||
void* alloc(size_t size,
|
||||
unsigned flags = (SK_MALLOC_THROW | SK_MALLOC_TEMP)) {
|
||||
sk_free(set(sk_malloc_flags(size, flags)));
|
||||
return get();
|
||||
explicit SkAutoMalloc(size_t size = 0,
|
||||
unsigned flags = SK_MALLOC_THROW | SK_MALLOC_TEMP) {
|
||||
fPtr = size ? sk_malloc_flags(size, flags) : NULL;
|
||||
fSize = size;
|
||||
}
|
||||
|
||||
~SkAutoMalloc() {
|
||||
sk_free(fPtr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reallocates the block to a new size. The ptr may or may not change.
|
||||
*/
|
||||
void* reset(size_t size,
|
||||
unsigned flags = (SK_MALLOC_THROW | SK_MALLOC_TEMP)) {
|
||||
if (size != fSize) {
|
||||
sk_free(fPtr);
|
||||
fPtr = size ? sk_malloc_flags(size, flags) : NULL;
|
||||
fSize = size;
|
||||
}
|
||||
return fPtr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases the block back to the heap
|
||||
*/
|
||||
void free() {
|
||||
this->reset(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the allocated block.
|
||||
*/
|
||||
void* get() { return fPtr; }
|
||||
const void* get() const { return fPtr; }
|
||||
|
||||
/**
|
||||
* Gets the size of the block in bytes
|
||||
*/
|
||||
size_t getSize() const { return fSize; }
|
||||
|
||||
private:
|
||||
void* fPtr;
|
||||
size_t fSize;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -413,7 +450,7 @@ template <size_t kSize> class SkAutoSMalloc : SkNoncopyable {
|
||||
public:
|
||||
/**
|
||||
* Creates initially empty storage. get() returns a ptr, but it is to
|
||||
* a zero-byte allocation. Must call realloc(size) to return an allocated
|
||||
* a zero-byte allocation. Must call reset(size) to return an allocated
|
||||
* block.
|
||||
*/
|
||||
SkAutoSMalloc() {
|
||||
@ -427,7 +464,7 @@ public:
|
||||
*/
|
||||
explicit SkAutoSMalloc(size_t size) {
|
||||
fPtr = fStorage;
|
||||
this->realloc(size);
|
||||
this->reset(size);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -454,7 +491,7 @@ public:
|
||||
* then the return block may be allocated locally, rather than from the
|
||||
* heap.
|
||||
*/
|
||||
void* realloc(size_t size) {
|
||||
void* reset(size_t size) {
|
||||
if (fPtr != (void*)fStorage) {
|
||||
sk_free(fPtr);
|
||||
}
|
||||
|
@ -1393,7 +1393,7 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
|
||||
SkAutoSTMalloc<128, GrColor> convertedColors(0);
|
||||
if (NULL != colors) {
|
||||
// need to convert byte order and from non-PM to PM
|
||||
convertedColors.realloc(vertexCount);
|
||||
convertedColors.reset(vertexCount);
|
||||
for (int i = 0; i < vertexCount; ++i) {
|
||||
convertedColors[i] = SkGr::SkColor2GrColor(colors[i]);
|
||||
}
|
||||
|
@ -547,7 +547,7 @@ void SkScalerContext_Mac::generateImage(const SkGlyph& glyph) {
|
||||
} else if (SkMask::kBW_Format == glyph.fMaskFormat) {
|
||||
rowBytes = SkAlign4(glyph.fWidth);
|
||||
size_t size = glyph.fHeight * rowBytes;
|
||||
image = storage.realloc(size);
|
||||
image = storage.reset(size);
|
||||
sk_bzero(image, size);
|
||||
doAA = false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user