Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(968)

Side by Side Diff: src/gpu/GrContext.cpp

Issue 2312123003: Revert of Restructure flushing relationship between GrContext, GrDrawingManager, and GrResourceCache (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/gpu/GrContext.h ('k') | src/gpu/GrDrawContext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrContext.h" 8 #include "GrContext.h"
9 #include "GrContextPriv.h" 9 #include "GrContextPriv.h"
10 #include "GrContextOptions.h" 10 #include "GrContextOptions.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 } while (id == SK_InvalidGenID); 59 } while (id == SK_InvalidGenID);
60 return id; 60 return id;
61 } 61 }
62 62
63 GrContext::GrContext() : fUniqueID(next_id()) { 63 GrContext::GrContext() : fUniqueID(next_id()) {
64 fGpu = nullptr; 64 fGpu = nullptr;
65 fCaps = nullptr; 65 fCaps = nullptr;
66 fResourceCache = nullptr; 66 fResourceCache = nullptr;
67 fResourceProvider = nullptr; 67 fResourceProvider = nullptr;
68 fBatchFontCache = nullptr; 68 fBatchFontCache = nullptr;
69 fFlushToReduceCacheSize = false;
69 } 70 }
70 71
71 bool GrContext::init(GrBackend backend, GrBackendContext backendContext, 72 bool GrContext::init(GrBackend backend, GrBackendContext backendContext,
72 const GrContextOptions& options) { 73 const GrContextOptions& options) {
73 ASSERT_SINGLE_OWNER 74 ASSERT_SINGLE_OWNER
74 SkASSERT(!fGpu); 75 SkASSERT(!fGpu);
75 76
76 fGpu = GrGpu::Create(backend, backendContext, options, this); 77 fGpu = GrGpu::Create(backend, backendContext, options, this);
77 if (!fGpu) { 78 if (!fGpu) {
78 return false; 79 return false;
79 } 80 }
80 this->initCommon(options); 81 this->initCommon(options);
81 return true; 82 return true;
82 } 83 }
83 84
84 void GrContext::initCommon(const GrContextOptions& options) { 85 void GrContext::initCommon(const GrContextOptions& options) {
85 ASSERT_SINGLE_OWNER 86 ASSERT_SINGLE_OWNER
86 87
87 fCaps = SkRef(fGpu->caps()); 88 fCaps = SkRef(fGpu->caps());
88 fResourceCache = new GrResourceCache(fCaps); 89 fResourceCache = new GrResourceCache(fCaps);
90 fResourceCache->setOverBudgetCallback(OverBudgetCB, this);
89 fResourceProvider = new GrResourceProvider(fGpu, fResourceCache, &fSingleOwn er); 91 fResourceProvider = new GrResourceProvider(fGpu, fResourceCache, &fSingleOwn er);
90 92
91 fDidTestPMConversions = false; 93 fDidTestPMConversions = false;
92 94
93 GrDrawTarget::Options dtOptions; 95 GrDrawTarget::Options dtOptions;
94 dtOptions.fClipBatchToBounds = options.fClipBatchToBounds; 96 dtOptions.fClipBatchToBounds = options.fClipBatchToBounds;
95 dtOptions.fDrawBatchBounds = options.fDrawBatchBounds; 97 dtOptions.fDrawBatchBounds = options.fDrawBatchBounds;
96 dtOptions.fMaxBatchLookback = options.fMaxBatchLookback; 98 dtOptions.fMaxBatchLookback = options.fMaxBatchLookback;
97 dtOptions.fMaxBatchLookahead = options.fMaxBatchLookahead; 99 dtOptions.fMaxBatchLookahead = options.fMaxBatchLookahead;
98 fDrawingManager.reset(new GrDrawingManager(this, dtOptions, options.fImmedia teMode, 100 fDrawingManager.reset(new GrDrawingManager(this, dtOptions, &fSingleOwner));
99 &fSingleOwner));
100 101
101 // GrBatchFontCache will eventually replace GrFontCache 102 // GrBatchFontCache will eventually replace GrFontCache
102 fBatchFontCache = new GrBatchFontCache(this); 103 fBatchFontCache = new GrBatchFontCache(this);
103 104
104 fTextBlobCache.reset(new GrTextBlobCache(TextBlobCacheOverBudgetCB, this)); 105 fTextBlobCache.reset(new GrTextBlobCache(TextBlobCacheOverBudgetCB, this));
105 } 106 }
106 107
107 GrContext::~GrContext() { 108 GrContext::~GrContext() {
108 ASSERT_SINGLE_OWNER 109 ASSERT_SINGLE_OWNER
109 110
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 if (resourceCount) { 196 if (resourceCount) {
196 *resourceCount = fResourceCache->getBudgetedResourceCount(); 197 *resourceCount = fResourceCache->getBudgetedResourceCount();
197 } 198 }
198 if (resourceBytes) { 199 if (resourceBytes) {
199 *resourceBytes = fResourceCache->getBudgetedResourceBytes(); 200 *resourceBytes = fResourceCache->getBudgetedResourceBytes();
200 } 201 }
201 } 202 }
202 203
203 //////////////////////////////////////////////////////////////////////////////// 204 ////////////////////////////////////////////////////////////////////////////////
204 205
206 void GrContext::OverBudgetCB(void* data) {
207 SkASSERT(data);
208
209 GrContext* context = reinterpret_cast<GrContext*>(data);
210
211 // Flush the GrBufferedDrawTarget to possibly free up some textures
212 context->fFlushToReduceCacheSize = true;
213 }
214
205 void GrContext::TextBlobCacheOverBudgetCB(void* data) { 215 void GrContext::TextBlobCacheOverBudgetCB(void* data) {
206 SkASSERT(data); 216 SkASSERT(data);
207 // TextBlobs are drawn at the SkGpuDevice level, therefore they cannot rely on GrDrawContext 217
208 // to perform a necessary flush. The solution is to move drawText calls to below the GrContext 218 // Unlike the GrResourceCache, TextBlobs are drawn at the SkGpuDevice level, therefore they
209 // level, but this is not trivial because they call drawPath on SkGpuDevice. 219 // cannot use fFlushTorReduceCacheSize because it uses AutoCheckFlush. The solution is to move
220 // drawText calls to below the GrContext level, but this is not trivial beca use they call
221 // drawPath on SkGpuDevice
210 GrContext* context = reinterpret_cast<GrContext*>(data); 222 GrContext* context = reinterpret_cast<GrContext*>(data);
211 context->flush(); 223 context->flush();
212 } 224 }
213 225
214 //////////////////////////////////////////////////////////////////////////////// 226 ////////////////////////////////////////////////////////////////////////////////
215 227
216 void GrContext::flush() { 228 void GrContext::flush(int flagsBitfield) {
217 ASSERT_SINGLE_OWNER 229 ASSERT_SINGLE_OWNER
218 RETURN_IF_ABANDONED 230 RETURN_IF_ABANDONED
219 fDrawingManager->flush(); 231 bool flushed = false;
232 if (kDiscard_FlushBit & flagsBitfield) {
233 fDrawingManager->reset();
234 } else {
235 flushed = fDrawingManager->flush();
236 }
237 if (flushed) {
238 fResourceCache->notifyFlushOccurred();
239 }
240 fFlushToReduceCacheSize = false;
220 } 241 }
221 242
222 bool sw_convert_to_premul(GrPixelConfig srcConfig, int width, int height, size_t inRowBytes, 243 bool sw_convert_to_premul(GrPixelConfig srcConfig, int width, int height, size_t inRowBytes,
223 const void* inPixels, size_t outRowBytes, void* outPix els) { 244 const void* inPixels, size_t outRowBytes, void* outPix els) {
224 SkSrcPixelInfo srcPI; 245 SkSrcPixelInfo srcPI;
225 if (!GrPixelConfigToColorType(srcConfig, &srcPI.fColorType)) { 246 if (!GrPixelConfigToColorType(srcConfig, &srcPI.fColorType)) {
226 return false; 247 return false;
227 } 248 }
228 srcPI.fAlphaType = kUnpremul_SkAlphaType; 249 srcPI.fAlphaType = kUnpremul_SkAlphaType;
229 srcPI.fPixels = inPixels; 250 srcPI.fPixels = inPixels;
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 ASSERT_SINGLE_OWNER 857 ASSERT_SINGLE_OWNER
837 fResourceCache->setLimits(maxTextures, maxTextureBytes); 858 fResourceCache->setLimits(maxTextures, maxTextureBytes);
838 } 859 }
839 860
840 ////////////////////////////////////////////////////////////////////////////// 861 //////////////////////////////////////////////////////////////////////////////
841 862
842 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { 863 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const {
843 ASSERT_SINGLE_OWNER 864 ASSERT_SINGLE_OWNER
844 fResourceCache->dumpMemoryStatistics(traceMemoryDump); 865 fResourceCache->dumpMemoryStatistics(traceMemoryDump);
845 } 866 }
OLDNEW
« no previous file with comments | « include/gpu/GrContext.h ('k') | src/gpu/GrDrawContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698