| 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 #include "GrContext.h" | 9 #include "GrContext.h" |
| 10 | 10 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) | 55 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) |
| 56 #define RETURN_IF_ABANDONED if (fDrawingMgr.abandoned()) { return; } | 56 #define RETURN_IF_ABANDONED if (fDrawingMgr.abandoned()) { return; } |
| 57 #define RETURN_FALSE_IF_ABANDONED if (fDrawingMgr.abandoned()) { return false; } | 57 #define RETURN_FALSE_IF_ABANDONED if (fDrawingMgr.abandoned()) { return false; } |
| 58 #define RETURN_NULL_IF_ABANDONED if (fDrawingMgr.abandoned()) { return nullptr;
} | 58 #define RETURN_NULL_IF_ABANDONED if (fDrawingMgr.abandoned()) { return nullptr;
} |
| 59 | 59 |
| 60 | 60 |
| 61 //////////////////////////////////////////////////////////////////////////////// | 61 //////////////////////////////////////////////////////////////////////////////// |
| 62 | 62 |
| 63 void GrContext::DrawingMgr::init(GrContext* context) { | 63 void GrContext::DrawingMgr::init(GrContext* context) { |
| 64 fContext = context; | 64 fContext = context; |
| 65 fDrawTarget = new GrDrawTarget(context->getGpu(), context->resourceProvider(
)); | |
| 66 } | 65 } |
| 67 | 66 |
| 68 void GrContext::DrawingMgr::cleanup() { | 67 void GrContext::DrawingMgr::cleanup() { |
| 69 SkSafeSetNull(fDrawTarget); | 68 for (int i = 0; i < fDrawTargets.count(); ++i) { |
| 69 fDrawTargets[i]->unref(); |
| 70 } |
| 71 |
| 72 fDrawTargets.reset(); |
| 73 |
| 70 delete fNVPRTextContext; | 74 delete fNVPRTextContext; |
| 71 fNVPRTextContext = nullptr; | 75 fNVPRTextContext = nullptr; |
| 76 |
| 72 for (int i = 0; i < kNumPixelGeometries; ++i) { | 77 for (int i = 0; i < kNumPixelGeometries; ++i) { |
| 73 delete fTextContexts[i][0]; | 78 delete fTextContexts[i][0]; |
| 74 fTextContexts[i][0] = nullptr; | 79 fTextContexts[i][0] = nullptr; |
| 75 delete fTextContexts[i][1]; | 80 delete fTextContexts[i][1]; |
| 76 fTextContexts[i][1] = nullptr; | 81 fTextContexts[i][1] = nullptr; |
| 77 } | 82 } |
| 78 } | 83 } |
| 79 | 84 |
| 80 GrContext::DrawingMgr::~DrawingMgr() { | 85 GrContext::DrawingMgr::~DrawingMgr() { |
| 81 this->cleanup(); | 86 this->cleanup(); |
| 82 } | 87 } |
| 83 | 88 |
| 84 void GrContext::DrawingMgr::abandon() { | 89 void GrContext::DrawingMgr::abandon() { |
| 90 fAbandoned = true; |
| 85 this->cleanup(); | 91 this->cleanup(); |
| 86 } | 92 } |
| 87 | 93 |
| 88 void GrContext::DrawingMgr::reset() { | 94 void GrContext::DrawingMgr::reset() { |
| 89 if (fDrawTarget) { | 95 for (int i = 0; i < fDrawTargets.count(); ++i) { |
| 90 fDrawTarget->reset(); | 96 fDrawTargets[i]->reset(); |
| 91 } | 97 } |
| 92 } | 98 } |
| 93 | 99 |
| 94 void GrContext::DrawingMgr::flush() { | 100 void GrContext::DrawingMgr::flush() { |
| 95 if (fDrawTarget) { | 101 for (int i = 0; i < fDrawTargets.count(); ++i) { |
| 96 fDrawTarget->flush(); | 102 fDrawTargets[i]->flush(); |
| 97 } | 103 } |
| 98 } | 104 } |
| 99 | 105 |
| 100 GrTextContext* GrContext::DrawingMgr::textContext(const SkSurfaceProps& props, | 106 GrTextContext* GrContext::DrawingMgr::textContext(const SkSurfaceProps& props, |
| 101 GrRenderTarget* rt) { | 107 GrRenderTarget* rt) { |
| 102 if (this->abandoned()) { | 108 if (this->abandoned()) { |
| 103 return nullptr; | 109 return nullptr; |
| 104 } | 110 } |
| 105 | 111 |
| 106 SkASSERT(props.pixelGeometry() < kNumPixelGeometries); | 112 SkASSERT(props.pixelGeometry() < kNumPixelGeometries); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 118 } | 124 } |
| 119 } | 125 } |
| 120 | 126 |
| 121 if (!fTextContexts[props.pixelGeometry()][useDIF]) { | 127 if (!fTextContexts[props.pixelGeometry()][useDIF]) { |
| 122 fTextContexts[props.pixelGeometry()][useDIF] = GrAtlasTextContext::Creat
e(fContext, props); | 128 fTextContexts[props.pixelGeometry()][useDIF] = GrAtlasTextContext::Creat
e(fContext, props); |
| 123 } | 129 } |
| 124 | 130 |
| 125 return fTextContexts[props.pixelGeometry()][useDIF]; | 131 return fTextContexts[props.pixelGeometry()][useDIF]; |
| 126 } | 132 } |
| 127 | 133 |
| 134 GrDrawTarget* GrContext::DrawingMgr::newDrawTarget(GrRenderTarget* rt) { |
| 135 SkASSERT(fContext); |
| 136 |
| 137 // When MDB is disabled we always just return the single drawTarget |
| 138 #ifndef ENABLE_MDB |
| 139 if (fDrawTargets.count()) { |
| 140 SkASSERT(fDrawTargets.count() == 1); |
| 141 // DrawingMgr gets the creation ref - this ref is for the caller |
| 142 return SkRef(fDrawTargets[0]); |
| 143 } |
| 144 #endif |
| 145 |
| 146 GrDrawTarget* dt = new GrDrawTarget(fContext->getGpu(), fContext->resourcePr
ovider()); |
| 147 |
| 148 *fDrawTargets.append() = dt; |
| 149 |
| 150 // DrawingMgr gets the creation ref - this ref is for the caller |
| 151 return SkRef(dt); |
| 152 } |
| 153 |
| 128 GrDrawContext* GrContext::DrawingMgr::drawContext(GrRenderTarget* rt, | 154 GrDrawContext* GrContext::DrawingMgr::drawContext(GrRenderTarget* rt, |
| 129 const SkSurfaceProps* surfaceP
rops) { | 155 const SkSurfaceProps* surfaceP
rops) { |
| 130 if (this->abandoned()) { | 156 if (this->abandoned()) { |
| 131 return nullptr; | 157 return nullptr; |
| 132 } | 158 } |
| 133 | 159 |
| 134 return new GrDrawContext(fContext, rt, fDrawTarget, surfaceProps); | 160 return new GrDrawContext(fContext, rt, surfaceProps); |
| 135 } | 161 } |
| 136 | 162 |
| 137 //////////////////////////////////////////////////////////////////////////////// | 163 //////////////////////////////////////////////////////////////////////////////// |
| 138 | 164 |
| 139 | 165 |
| 140 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext)
{ | 166 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext)
{ |
| 141 GrContextOptions defaultOptions; | 167 GrContextOptions defaultOptions; |
| 142 return Create(backend, backendContext, defaultOptions); | 168 return Create(backend, backendContext, defaultOptions); |
| 143 } | 169 } |
| 144 | 170 |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 | 785 |
| 760 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes)
{ | 786 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes)
{ |
| 761 fResourceCache->setLimits(maxTextures, maxTextureBytes); | 787 fResourceCache->setLimits(maxTextures, maxTextureBytes); |
| 762 } | 788 } |
| 763 | 789 |
| 764 ////////////////////////////////////////////////////////////////////////////// | 790 ////////////////////////////////////////////////////////////////////////////// |
| 765 | 791 |
| 766 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { | 792 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
| 767 fResourceCache->dumpMemoryStatistics(traceMemoryDump); | 793 fResourceCache->dumpMemoryStatistics(traceMemoryDump); |
| 768 } | 794 } |
| OLD | NEW |