aboutsummaryrefslogtreecommitdiffhomepage
path: root/gpu/src/GrGpu.cpp
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-03-30 21:26:44 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-03-30 21:26:44 +0000
commit8fe72477f204b1a45393e6a64caa84fd287b805b (patch)
treeee45cdc16a5e66a5a198920897d82db4284b97da /gpu/src/GrGpu.cpp
parenta7d948523dce6044fc02db90726e5f971a93628b (diff)
Add GrResource base class for ibs, texs, vbs, etc.
Add lostContext() to GrContext. Review URL: http://codereview.appspot.com/4328044/ git-svn-id: http://skia.googlecode.com/svn/trunk@1026 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gpu/src/GrGpu.cpp')
-rw-r--r--gpu/src/GrGpu.cpp99
1 files changed, 80 insertions, 19 deletions
diff --git a/gpu/src/GrGpu.cpp b/gpu/src/GrGpu.cpp
index 378b881637..31e4d99668 100644
--- a/gpu/src/GrGpu.cpp
+++ b/gpu/src/GrGpu.cpp
@@ -69,20 +69,22 @@ bool GrTexture::PixelConfigIsAlphaOnly(PixelConfig config) {
extern void gr_run_unittests();
-GrGpu::GrGpu() : f8bitPaletteSupport(false),
- fCurrPoolVertexBuffer(NULL),
- fCurrPoolStartVertex(0),
- fCurrPoolIndexBuffer(NULL),
- fCurrPoolStartIndex(0),
- fVertexPool(NULL),
- fIndexPool(NULL),
- fQuadIndexBuffer(NULL),
- fUnitSquareVertexBuffer(NULL),
- fDefaultPathRenderer(NULL),
- fClientPathRenderer(NULL),
- fContextIsDirty(true),
- fVertexPoolInUse(false),
- fIndexPoolInUse(false) {
+GrGpu::GrGpu()
+ : f8bitPaletteSupport(false)
+ , fCurrPoolVertexBuffer(NULL)
+ , fCurrPoolStartVertex(0)
+ , fCurrPoolIndexBuffer(NULL)
+ , fCurrPoolStartIndex(0)
+ , fVertexPool(NULL)
+ , fIndexPool(NULL)
+ , fQuadIndexBuffer(NULL)
+ , fUnitSquareVertexBuffer(NULL)
+ , fDefaultPathRenderer(NULL)
+ , fClientPathRenderer(NULL)
+ , fContextIsDirty(true)
+ , fVertexPoolInUse(false)
+ , fIndexPoolInUse(false)
+ , fResourceHead(NULL) {
#if GR_DEBUG
//gr_run_unittests();
#endif
@@ -90,17 +92,76 @@ GrGpu::GrGpu() : f8bitPaletteSupport(false),
}
GrGpu::~GrGpu() {
- GrSafeUnref(fQuadIndexBuffer);
- GrSafeUnref(fUnitSquareVertexBuffer);
+ releaseResources();
+}
+
+void GrGpu::abandonResources() {
+
+ while (NULL != fResourceHead) {
+ fResourceHead->abandon();
+ }
+
+ GrAssert(NULL == fQuadIndexBuffer || !fQuadIndexBuffer->isValid());
+ GrAssert(NULL == fUnitSquareVertexBuffer ||
+ !fUnitSquareVertexBuffer->isValid());
+ GrSafeSetNull(fQuadIndexBuffer);
+ GrSafeSetNull(fUnitSquareVertexBuffer);
delete fVertexPool;
+ fVertexPool = NULL;
delete fIndexPool;
- GrSafeUnref(fClientPathRenderer);
- GrSafeUnref(fDefaultPathRenderer);
+ fIndexPool = NULL;
}
-void GrGpu::resetContext() {
+void GrGpu::releaseResources() {
+
+ while (NULL != fResourceHead) {
+ fResourceHead->release();
+ }
+
+ GrAssert(NULL == fQuadIndexBuffer || !fQuadIndexBuffer->isValid());
+ GrAssert(NULL == fUnitSquareVertexBuffer ||
+ !fUnitSquareVertexBuffer->isValid());
+ GrSafeSetNull(fQuadIndexBuffer);
+ GrSafeSetNull(fUnitSquareVertexBuffer);
+ delete fVertexPool;
+ fVertexPool = NULL;
+ delete fIndexPool;
+ fIndexPool = NULL;
}
+void GrGpu::insertResource(GrResource* resource) {
+ GrAssert(NULL != resource);
+ GrAssert(this == resource->getGpu());
+ GrAssert(NULL == resource->fNext);
+ GrAssert(NULL == resource->fPrevious);
+
+ resource->fNext = fResourceHead;
+ if (NULL != fResourceHead) {
+ GrAssert(NULL == fResourceHead->fPrevious);
+ fResourceHead->fPrevious = resource;
+ }
+ fResourceHead = resource;
+}
+
+void GrGpu::removeResource(GrResource* resource) {
+ GrAssert(NULL != resource);
+ GrAssert(NULL != fResourceHead);
+
+ if (fResourceHead == resource) {
+ GrAssert(NULL == resource->fPrevious);
+ fResourceHead = resource->fNext;
+ } else {
+ GrAssert(NULL != fResourceHead);
+ resource->fPrevious->fNext = resource->fNext;
+ }
+ if (NULL != resource->fNext) {
+ resource->fNext->fPrevious = resource->fPrevious;
+ }
+ resource->fNext = NULL;
+ resource->fPrevious = NULL;
+}
+
+
void GrGpu::unimpl(const char msg[]) {
#if GR_DEBUG
GrPrintf("--- GrGpu unimplemented(\"%s\")\n", msg);