+++ /dev/null
-/*
- Copyright 2010 Google Inc.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-
-#ifndef GrMemory_DEFINED
-#define GrMemory_DEFINED
-
-#include "GrNoncopyable.h"
-
-class GrAutoMalloc : GrNoncopyable {
-public:
- GrAutoMalloc() : fPtr(NULL), fAllocatedBytes(0){
- }
-
- GrAutoMalloc(size_t bytes) : fPtr(GrMalloc(bytes)), fAllocatedBytes(bytes) {}
- ~GrAutoMalloc() { GrFree(fPtr); }
-
- /**
- * Return the allocated memory, or NULL if it has already been freed or
- * detached.
- */
- void* get() const { return fPtr; }
-
- size_t size() const { return fAllocatedBytes; }
-
- /**
- * transfer ownership of the memory to the caller. It must be freed with
- * a call to GrFree()
- */
- void* detach() {
- void* ptr = fPtr;
- fPtr = NULL; // we no longer own the block
- fAllocatedBytes = 0;
- return ptr;
- }
-
- /**
- * Reallocates to a new size. May or may not call malloc. The contents
- * are not preserved. If growOnly is true it will never reduce the
- * allocated size.
- */
- void* realloc(size_t newSize, bool growOnly = false) {
- bool alloc;
- if (growOnly) {
- alloc = newSize > fAllocatedBytes;
- } else {
- alloc = newSize != fAllocatedBytes;
- }
- if (alloc) {
- GrFree(fPtr);
- fPtr = newSize ? GrMalloc(newSize) : NULL;
- fAllocatedBytes = newSize;
- }
- GrAssert(fAllocatedBytes >= newSize);
- GR_DEBUGCODE(memset(fPtr, 0xEF, fAllocatedBytes));
- return fPtr;
- }
-
- /**
- * free the block now. get() will now return NULL
- */
- void free() {
- GrFree(fPtr);
- fPtr = NULL;
- fAllocatedBytes = 0;
- }
-
-private:
- void* fPtr;
- size_t fAllocatedBytes;
-};
-
-/**
- * Variant of GrAutoMalloc with a compile-time specified byte size that is
- * pre-allocated in the class object, avoiding a call to to GrMalloc if
- * possible.
- */
-template <size_t SIZE> class GrAutoSMalloc : GrNoncopyable {
-public:
- GrAutoSMalloc() {
- fPtr = fStorage;
- fAllocatedBytes = SIZE;
- }
-
- explicit GrAutoSMalloc(size_t bytes) {
- if (bytes > SIZE) {
- fPtr = GrMalloc(bytes);
- fAllocatedBytes = bytes;
- } else {
- fPtr = fStorage;
- fAllocatedBytes = SIZE;
- }
- }
-
- ~GrAutoSMalloc() {
- if (fPtr != (void*)fStorage) {
- GrFree(fPtr);
- }
- }
-
- /**
- * Return the allocated memory, or NULL if it has already been freed or
- * detached.
- */
- void* get() const { return fPtr; }
-
- /**
- * Reallocates to a new size. May or may not call malloc. The contents
- * are not preserved. If growOnly is true it will never reduce the
- * allocated size.
- */
- void* realloc(size_t newSize, bool growOnly = false) {
- if (newSize <= SIZE) {
- if (NULL == fPtr) {
- fPtr = fStorage;
- fAllocatedBytes = SIZE;
- } else if (!growOnly && fPtr != (void*)fStorage) {
- GrFree(fPtr);
- fPtr = fStorage;
- fAllocatedBytes = SIZE;
- }
- } else if ((newSize > fAllocatedBytes) ||
- (!growOnly && newSize < (fAllocatedBytes >> 1))) {
- if (NULL != fPtr && fPtr != (void*)fStorage) {
- GrFree(fPtr);
- }
- fPtr = GrMalloc(newSize);
- fAllocatedBytes = newSize;
- }
- GrAssert(fAllocatedBytes >= newSize);
- GrAssert((fPtr == fStorage) == (fAllocatedBytes == SIZE));
- GR_DEBUGCODE(memset(fPtr, 0xEF, fAllocatedBytes));
- return fPtr;
- }
-
- /**
- * free the block now. get() will now return NULL
- */
- void free() {
- if (fPtr != (void*)fStorage) {
- GrFree(fPtr);
- }
- fAllocatedBytes = 0;
- fPtr = NULL;
- }
-
-private:
- void* fPtr;
- uint32_t fAllocatedBytes;
- uint32_t fStorage[GrALIGN4(SIZE) >> 2];
-};
-
-/**
- * Variant of GrAutoMalloc with a compile-time specified byte size that is
- * pre-allocated in the class object, avoiding a call to to GrMalloc if
- * possible.
- */
-template <int COUNT, typename T>
-class GrAutoSTMalloc : public GrAutoSMalloc<COUNT * sizeof(T)> {
-public:
- GrAutoSTMalloc(int count) : GrAutoSMalloc<COUNT * sizeof(T)>(count * sizeof(T)) {}
-
- operator T*() { return (T*)this->get(); }
-};
-
-
-#endif
-
#include "GrAtlas.h"
#include "GrGpu.h"
-#include "GrMemory.h"
#include "GrRectanizer.h"
#include "GrPlotMgr.h"
return false;
}
- GrAutoSMalloc<1024> storage;
+ SkAutoSMalloc<1024> storage;
int dstW = width + 2*BORDER;
int dstH = height + 2*BORDER;
if (BORDER) {
fFirstPreallocBuffer = (fFirstPreallocBuffer + fPreallocBuffersInUse) %
fPreallocBuffers.count();
}
- fCpuData.realloc(fGpu->supportsBufferLocking() ? 0 : fMinBlockSize);
+ fCpuData.alloc(fGpu->supportsBufferLocking() ? 0 : fMinBlockSize);
GrAssert(0 == fPreallocBuffersInUse);
VALIDATE();
}
GrAssert(buf->lockPtr() == fBufferPtr);
} else {
GrAssert(fCpuData.get() == fBufferPtr);
- GrAssert(fCpuData.size() == fBlocks.back().fBuffer->size());
}
} else {
GrAssert(fBlocks.empty() || !fBlocks.back().fBuffer->isLocked());
}
if (NULL == fBufferPtr) {
- fBufferPtr = fCpuData.realloc(size);
+ fBufferPtr = fCpuData.alloc(size);
}
VALIDATE(true);
GrAssert(NULL != buffer);
GrAssert(!buffer->isLocked());
GrAssert(fCpuData.get() == fBufferPtr);
- GrAssert(fCpuData.size() == buffer->size());
GrAssert(flushSize <= buffer->size());
bool updated = false;
#include "GrNoncopyable.h"
#include "GrTDArray.h"
#include "GrTArray.h"
-#include "GrMemory.h"
class GrGeometryBuffer;
class GrGpu;
GrTArray<BufferBlock> fBlocks;
int fPreallocBuffersInUse;
int fFirstPreallocBuffer;
- GrAutoMalloc fCpuData;
- void* fBufferPtr;
+ SkAutoMalloc fCpuData;
+ void* fBufferPtr;
};
class GrVertexBuffer;
#include "GrGpu.h"
#include "GrIndexBuffer.h"
#include "GrInOrderDrawBuffer.h"
-#include "GrMemory.h"
#include "GrPathRenderer.h"
#include "GrPathUtils.h"
#include "GrTextureCache.h"
rtDesc.fWidth = GrNextPow2(desc.fWidth);
rtDesc.fHeight = GrNextPow2(desc.fHeight);
int bpp = GrBytesPerPixel(desc.fFormat);
- GrAutoSMalloc<128*128*4> stretchedPixels(bpp *
+ SkAutoSMalloc<128*128*4> stretchedPixels(bpp *
rtDesc.fWidth *
rtDesc.fHeight);
stretchImage(stretchedPixels.get(), rtDesc.fWidth, rtDesc.fHeight,
#include "GrBinHashKey.h"
#include "GrGLConfig.h"
-#include "GrMemory.h"
#include "SkXfermode.h"
#include SK_USER_TRACE_INCLUDE_FILE
if (!compiled) {
GrGLint infoLen = GR_GL_INIT_ZERO;
GR_GL(GetShaderiv(shader, GR_GL_INFO_LOG_LENGTH, &infoLen));
- GrAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger
+ SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger
if (infoLen > 0) {
GR_GL(GetShaderInfoLog(shader, infoLen+1, NULL, (char*)log.get()));
for (int i = 0; i < stringCnt; ++i) {
if (!linked) {
GrGLint infoLen = GR_GL_INIT_ZERO;
GR_GL(GetProgramiv(progID, GR_GL_INFO_LOG_LENGTH, &infoLen));
- GrAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger
+ SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger
if (infoLen > 0) {
GR_GL(GetProgramInfoLog(progID,
infoLen+1,
#include "GrGLTexture.h"
#include "GrGpuGL.h"
-#include "GrMemory.h"
#define GPUGL static_cast<GrGpuGL*>(getGpu())
GrAssert(fUploadFormat != GR_GL_PALETTE8_RGBA8);
// in case we need a temporary, trimmed copy of the src pixels
- GrAutoSMalloc<128 * 128> trimStorage;
+ SkAutoSMalloc<128 * 128> trimStorage;
/*
* check if our srcData has extra bytes past each row. If so, we need
*/
#include "GrGpu.h"
-#include "GrMemory.h"
#include "GrTextStrike.h"
#include "GrTextureCache.h"
#include "GrClipIterator.h"
*/
#include "GrGpuGL.h"
-#include "GrMemory.h"
#include "GrTypes.h"
+#include "SkTemplates.h"
static const GrGLuint GR_MAX_GLUINT = ~0;
static const GrGLint GR_INVAL_GLINT = ~0;
GrGLint numFormats;
GR_GL_GetIntegerv(GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
- GrAutoSTMalloc<10, GrGLint> formats(numFormats);
+ SkAutoSTMalloc<10, GrGLint> formats(numFormats);
GR_GL_GetIntegerv(GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
for (int i = 0; i < numFormats; ++i) {
if (formats[i] == GR_GL_PALETTE8_RGBA8) {
glDesc.fUploadByteCount = GrBytesPerPixel(desc.fFormat);
// in case we need a temporary, trimmed copy of the src pixels
- GrAutoSMalloc<128 * 128> trimStorage;
+ SkAutoSMalloc<128 * 128> trimStorage;
/*
* check if our srcData has extra bytes past each row. If so, we need
maxTexels = GrMax(extraW * desc.fHeight, maxTexels);
maxTexels = GrMax(desc.fWidth * extraH, maxTexels);
- GrAutoSMalloc<128*128> texels(glDesc.fUploadByteCount * maxTexels);
+ SkAutoSMalloc<128*128> texels(glDesc.fUploadByteCount * maxTexels);
uint32_t rowSize = desc.fWidth * glDesc.fUploadByteCount;
if (extraH) {
// API presents top-to-bottom
{
size_t stride = width * GrBytesPerPixel(config);
- GrAutoMalloc rowStorage(stride);
+ SkAutoMalloc rowStorage(stride);
void* tmp = rowStorage.get();
const int halfY = height >> 1;
#include "GrGLProgram.h"
#include "GrGpuGLShaders.h"
#include "GrGpuVertex.h"
-#include "GrMemory.h"
#include "GrNoncopyable.h"
#include "GrStringBuilder.h"
#include "GrRandom.h"
*/
-#include "GrMemory.h"
-
#include <stdlib.h>
void* GrMalloc(size_t bytes) {
#include "GrPoint.h"
#include "GrDrawTarget.h"
#include "GrPathUtils.h"
-#include "GrMemory.h"
#include "GrTexture.h"
#include "SkString.h"
+#include "SkTemplates.h"
+
#include SK_USER_TRACE_INCLUDE_FILE
GrPathRenderer::GrPathRenderer()
GrPoint* vert = base;
GrPoint* subpathBase = base;
- GrAutoSTMalloc<8, uint16_t> subpathVertCount(subpathCnt);
+ SkAutoSTMalloc<8, uint16_t> subpathVertCount(subpathCnt);
// TODO: use primitve restart if available rather than multiple draws
GrPrimitiveType type;
#include "GrTesselatedPathRenderer.h"
-#include "GrMemory.h"
#include "GrPathUtils.h"
#include "GrPoint.h"
#include "GrTDArray.h"
+#include "SkTemplates.h"
+
#include <limits.h>
#include <sk_glu.h>
if (maxPts > USHRT_MAX) {
return;
}
- GrAutoSTMalloc<8, GrPoint> baseMem(maxPts);
- GrPoint* base = (GrPoint*) baseMem;
+ SkAutoSTMalloc<8, GrPoint> baseMem(maxPts);
+ GrPoint* base = baseMem;
GrPoint* vert = base;
GrPoint* subpathBase = base;
- GrAutoSTMalloc<8, uint16_t> subpathVertCount(subpathCnt);
+ SkAutoSTMalloc<8, uint16_t> subpathVertCount(subpathCnt);
GrPoint pts[4];
SkPath::Iter iter(path, false);
#include "GrAtlas.h"
#include "GrGpu.h"
-#include "GrMemory.h"
#include "GrRectanizer.h"
#include "GrTextStrike.h"
#include "GrTextStrike_impl.h"
int bytesPerPixel = GrMaskFormatBytesPerPixel(fMaskFormat);
size_t size = glyph->fBounds.area() * bytesPerPixel;
- GrAutoSMalloc<1024> storage(size);
+ SkAutoSMalloc<1024> storage(size);
if (!scaler->getPackedGlyphImage(glyph->fPackedID, glyph->width(),
glyph->height(),
glyph->width() * bytesPerPixel,
'../gpu/include/GrIPoint.h',
'../gpu/include/GrKey.h',
'../gpu/include/GrMatrix.h',
- '../gpu/include/GrMemory.h',
'../gpu/include/GrMesh.h',
'../gpu/include/GrNoncopyable.h',
'../gpu/include/GrPaint.h',
*/
template <typename T> class SkAutoTMalloc : SkNoncopyable {
public:
- SkAutoTMalloc(size_t count)
- {
+ SkAutoTMalloc(size_t count) {
fPtr = (T*)sk_malloc_flags(count * sizeof(T), SK_MALLOC_THROW | SK_MALLOC_TEMP);
}
- ~SkAutoTMalloc()
- {
+
+ ~SkAutoTMalloc() {
sk_free(fPtr);
}
+
+ // doesn't preserve contents
+ void realloc (size_t count) {
+ sk_free(fPtr);
+ fPtr = fPtr = (T*)sk_malloc_flags(count * sizeof(T), SK_MALLOC_THROW | SK_MALLOC_TEMP);
+ }
+
T* get() const { return fPtr; }
+ operator T*() {
+ return fPtr;
+ }
+
+ operator const T*() const {
+ return fPtr;
+ }
+
+ T& operator[](int index) {
+ return fPtr[index];
+ }
+
+ const T& operator[](int index) const {
+ return fPtr[index];
+ }
+
private:
T* fPtr;
};
template <size_t N, typename T> class SkAutoSTMalloc : SkNoncopyable {
public:
- SkAutoSTMalloc(size_t count)
- {
- if (count <= N)
+ SkAutoSTMalloc(size_t count) {
+ if (count <= N) {
fPtr = fTStorage;
- else
+ } else {
fPtr = (T*)sk_malloc_flags(count * sizeof(T), SK_MALLOC_THROW | SK_MALLOC_TEMP);
+ }
+ }
+
+ ~SkAutoSTMalloc() {
+ if (fPtr != fTStorage) {
+ sk_free(fPtr);
+ }
}
- ~SkAutoSTMalloc()
- {
- if (fPtr != fTStorage)
+
+ // doesn't preserve contents
+ void realloc (size_t count) {
+ if (fPtr != fTStorage) {
sk_free(fPtr);
+ }
+ if (count <= N) {
+ fPtr = fTStorage;
+ } else {
+ fPtr = (T*)sk_malloc_flags(count * sizeof(T), SK_MALLOC_THROW | SK_MALLOC_TEMP);
+ }
}
+
T* get() const { return fPtr; }
+ operator T*() {
+ return fPtr;
+ }
+
+ operator const T*() const {
+ return fPtr;
+ }
+
+ T& operator[](int index) {
+ return fPtr[index];
+ }
+
+ const T& operator[](int index) const {
+ return fPtr[index];
+ }
+
private:
T* fPtr;
union {