| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4; | 59 static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4; |
| 60 | 60 |
| 61 static const size_t DRAW_BUFFER_IBPOOL_BUFFER_SIZE = 1 << 11; | 61 static const size_t DRAW_BUFFER_IBPOOL_BUFFER_SIZE = 1 << 11; |
| 62 static const int DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS = 4; | 62 static const int DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS = 4; |
| 63 | 63 |
| 64 #define ASSERT_OWNED_RESOURCE(R) GrAssert(!(R) || (R)->getContext() == this) | 64 #define ASSERT_OWNED_RESOURCE(R) GrAssert(!(R) || (R)->getContext() == this) |
| 65 | 65 |
| 66 // Glorified typedef to avoid including GrDrawState.h in GrContext.h | 66 // Glorified typedef to avoid including GrDrawState.h in GrContext.h |
| 67 class GrContext::AutoRestoreEffects : public GrDrawState::AutoRestoreEffects {}; | 67 class GrContext::AutoRestoreEffects : public GrDrawState::AutoRestoreEffects {}; |
| 68 | 68 |
| 69 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext)
{ | 69 GrContext* GrContext::Create(GrBackend backend, |
| 70 GrBackendContext backendContext, |
| 71 bool* reuseScratchTextures) { |
| 70 GrContext* context = SkNEW(GrContext); | 72 GrContext* context = SkNEW(GrContext); |
| 71 if (context->init(backend, backendContext)) { | 73 if (context->init(backend, backendContext, reuseScratchTextures)) { |
| 72 return context; | 74 return context; |
| 73 } else { | 75 } else { |
| 74 context->unref(); | 76 context->unref(); |
| 75 return NULL; | 77 return NULL; |
| 76 } | 78 } |
| 77 } | 79 } |
| 78 | 80 |
| 79 namespace { | 81 namespace { |
| 80 void* CreateThreadInstanceCount() { | 82 void* CreateThreadInstanceCount() { |
| 81 return SkNEW_ARGS(int, (0)); | 83 return SkNEW_ARGS(int, (0)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 97 fTextureCache = NULL; | 99 fTextureCache = NULL; |
| 98 fFontCache = NULL; | 100 fFontCache = NULL; |
| 99 fDrawBuffer = NULL; | 101 fDrawBuffer = NULL; |
| 100 fDrawBufferVBAllocPool = NULL; | 102 fDrawBufferVBAllocPool = NULL; |
| 101 fDrawBufferIBAllocPool = NULL; | 103 fDrawBufferIBAllocPool = NULL; |
| 102 fAARectRenderer = NULL; | 104 fAARectRenderer = NULL; |
| 103 fOvalRenderer = NULL; | 105 fOvalRenderer = NULL; |
| 104 fViewMatrix.reset(); | 106 fViewMatrix.reset(); |
| 105 } | 107 } |
| 106 | 108 |
| 107 bool GrContext::init(GrBackend backend, GrBackendContext backendContext) { | 109 bool GrContext::init(GrBackend backend, |
| 110 GrBackendContext backendContext, |
| 111 bool* reuseScratchTextures) { |
| 108 GrAssert(NULL == fGpu); | 112 GrAssert(NULL == fGpu); |
| 109 | 113 |
| 110 fGpu = GrGpu::Create(backend, backendContext, this); | 114 fGpu = GrGpu::Create(backend, backendContext, this); |
| 111 if (NULL == fGpu) { | 115 if (NULL == fGpu) { |
| 112 return false; | 116 return false; |
| 113 } | 117 } |
| 114 | 118 |
| 115 fDrawState = SkNEW(GrDrawState); | 119 fDrawState = SkNEW(GrDrawState); |
| 116 fGpu->setDrawState(fDrawState); | 120 fGpu->setDrawState(fDrawState); |
| 117 | 121 |
| 122 if (NULL == reuseScratchTextures) { |
| 123 this->setReuseScratchTextures(fGpu->caps()->reuseScratchTextures()); |
| 124 } else { |
| 125 this->setReuseScratchTextures(*reuseScratchTextures); |
| 126 } |
| 118 | 127 |
| 119 fTextureCache = SkNEW_ARGS(GrResourceCache, | 128 fTextureCache = SkNEW_ARGS(GrResourceCache, |
| 120 (MAX_TEXTURE_CACHE_COUNT, | 129 (MAX_TEXTURE_CACHE_COUNT, |
| 121 MAX_TEXTURE_CACHE_BYTES)); | 130 MAX_TEXTURE_CACHE_BYTES)); |
| 122 fTextureCache->setOverbudgetCallback(OverbudgetCB, this); | 131 fTextureCache->setOverbudgetCallback(OverbudgetCB, this); |
| 123 | 132 |
| 124 fFontCache = SkNEW_ARGS(GrFontCache, (fGpu)); | 133 fFontCache = SkNEW_ARGS(GrFontCache, (fGpu)); |
| 125 | 134 |
| 126 fLastDrawWasBuffered = kNo_BufferedDraw; | 135 fLastDrawWasBuffered = kNo_BufferedDraw; |
| 127 | 136 |
| (...skipping 1552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1680 return NULL; | 1689 return NULL; |
| 1681 } | 1690 } |
| 1682 } | 1691 } |
| 1683 | 1692 |
| 1684 /////////////////////////////////////////////////////////////////////////////// | 1693 /////////////////////////////////////////////////////////////////////////////// |
| 1685 #if GR_CACHE_STATS | 1694 #if GR_CACHE_STATS |
| 1686 void GrContext::printCacheStats() const { | 1695 void GrContext::printCacheStats() const { |
| 1687 fTextureCache->printStats(); | 1696 fTextureCache->printStats(); |
| 1688 } | 1697 } |
| 1689 #endif | 1698 #endif |
| OLD | NEW |