| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "GrContext.h" | 10 #include "GrContext.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext)
{ | 81 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext)
{ |
| 82 GrContext* context = SkNEW(GrContext); | 82 GrContext* context = SkNEW(GrContext); |
| 83 if (context->init(backend, backendContext)) { | 83 if (context->init(backend, backendContext)) { |
| 84 return context; | 84 return context; |
| 85 } else { | 85 } else { |
| 86 context->unref(); | 86 context->unref(); |
| 87 return NULL; | 87 return NULL; |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 | 90 |
| 91 namespace { | |
| 92 void* CreateThreadInstanceCount() { | |
| 93 return SkNEW_ARGS(int, (0)); | |
| 94 } | |
| 95 void DeleteThreadInstanceCount(void* v) { | |
| 96 delete reinterpret_cast<int*>(v); | |
| 97 } | |
| 98 #define THREAD_INSTANCE_COUNT \ | |
| 99 (*reinterpret_cast<int*>(SkTLS::Get(CreateThreadInstanceCount, DeleteThreadI
nstanceCount))) | |
| 100 } | |
| 101 | |
| 102 GrContext::GrContext() { | 91 GrContext::GrContext() { |
| 103 ++THREAD_INSTANCE_COUNT; | |
| 104 fDrawState = NULL; | 92 fDrawState = NULL; |
| 105 fGpu = NULL; | 93 fGpu = NULL; |
| 106 fClip = NULL; | 94 fClip = NULL; |
| 107 fPathRendererChain = NULL; | 95 fPathRendererChain = NULL; |
| 108 fSoftwarePathRenderer = NULL; | 96 fSoftwarePathRenderer = NULL; |
| 109 fTextureCache = NULL; | 97 fTextureCache = NULL; |
| 110 fFontCache = NULL; | 98 fFontCache = NULL; |
| 111 fDrawBuffer = NULL; | 99 fDrawBuffer = NULL; |
| 112 fDrawBufferVBAllocPool = NULL; | 100 fDrawBufferVBAllocPool = NULL; |
| 113 fDrawBufferIBAllocPool = NULL; | 101 fDrawBufferIBAllocPool = NULL; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 141 fAARectRenderer = SkNEW(GrAARectRenderer); | 129 fAARectRenderer = SkNEW(GrAARectRenderer); |
| 142 fOvalRenderer = SkNEW(GrOvalRenderer); | 130 fOvalRenderer = SkNEW(GrOvalRenderer); |
| 143 | 131 |
| 144 fDidTestPMConversions = false; | 132 fDidTestPMConversions = false; |
| 145 | 133 |
| 146 this->setupDrawBuffer(); | 134 this->setupDrawBuffer(); |
| 147 | 135 |
| 148 return true; | 136 return true; |
| 149 } | 137 } |
| 150 | 138 |
| 151 int GrContext::GetThreadInstanceCount() { | |
| 152 return THREAD_INSTANCE_COUNT; | |
| 153 } | |
| 154 | |
| 155 GrContext::~GrContext() { | 139 GrContext::~GrContext() { |
| 156 if (NULL == fGpu) { | 140 if (NULL == fGpu) { |
| 157 return; | 141 return; |
| 158 } | 142 } |
| 159 | 143 |
| 160 this->flush(); | 144 this->flush(); |
| 161 | 145 |
| 162 for (int i = 0; i < fCleanUpData.count(); ++i) { | 146 for (int i = 0; i < fCleanUpData.count(); ++i) { |
| 163 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); | 147 (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); |
| 164 } | 148 } |
| 165 | 149 |
| 166 // Since the gpu can hold scratch textures, give it a chance to let go | 150 // Since the gpu can hold scratch textures, give it a chance to let go |
| 167 // of them before freeing the texture cache | 151 // of them before freeing the texture cache |
| 168 fGpu->purgeResources(); | 152 fGpu->purgeResources(); |
| 169 | 153 |
| 170 delete fTextureCache; | 154 delete fTextureCache; |
| 171 fTextureCache = NULL; | 155 fTextureCache = NULL; |
| 172 delete fFontCache; | 156 delete fFontCache; |
| 173 delete fDrawBuffer; | 157 delete fDrawBuffer; |
| 174 delete fDrawBufferVBAllocPool; | 158 delete fDrawBufferVBAllocPool; |
| 175 delete fDrawBufferIBAllocPool; | 159 delete fDrawBufferIBAllocPool; |
| 176 | 160 |
| 177 fAARectRenderer->unref(); | 161 fAARectRenderer->unref(); |
| 178 fOvalRenderer->unref(); | 162 fOvalRenderer->unref(); |
| 179 | 163 |
| 180 fGpu->unref(); | 164 fGpu->unref(); |
| 181 SkSafeUnref(fPathRendererChain); | 165 SkSafeUnref(fPathRendererChain); |
| 182 SkSafeUnref(fSoftwarePathRenderer); | 166 SkSafeUnref(fSoftwarePathRenderer); |
| 183 fDrawState->unref(); | 167 fDrawState->unref(); |
| 184 | |
| 185 --THREAD_INSTANCE_COUNT; | |
| 186 } | 168 } |
| 187 | 169 |
| 188 void GrContext::contextLost() { | 170 void GrContext::contextLost() { |
| 189 this->contextDestroyed(); | 171 this->contextDestroyed(); |
| 190 this->setupDrawBuffer(); | 172 this->setupDrawBuffer(); |
| 191 } | 173 } |
| 192 | 174 |
| 193 void GrContext::contextDestroyed() { | 175 void GrContext::contextDestroyed() { |
| 194 // abandon first to so destructors | 176 // abandon first to so destructors |
| 195 // don't try to free the resources in the API. | 177 // don't try to free the resources in the API. |
| (...skipping 1614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1810 } | 1792 } |
| 1811 return path; | 1793 return path; |
| 1812 } | 1794 } |
| 1813 | 1795 |
| 1814 /////////////////////////////////////////////////////////////////////////////// | 1796 /////////////////////////////////////////////////////////////////////////////// |
| 1815 #if GR_CACHE_STATS | 1797 #if GR_CACHE_STATS |
| 1816 void GrContext::printCacheStats() const { | 1798 void GrContext::printCacheStats() const { |
| 1817 fTextureCache->printStats(); | 1799 fTextureCache->printStats(); |
| 1818 } | 1800 } |
| 1819 #endif | 1801 #endif |
| OLD | NEW |