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

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

Issue 1375153007: Dynamically allocate the GrDrawContexts (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix more bugs Created 5 years, 2 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
OLDNEW
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 10 matching lines...) Expand all
21 #include "GrGpu.h" 21 #include "GrGpu.h"
22 #include "GrIndexBuffer.h" 22 #include "GrIndexBuffer.h"
23 #include "GrLayerCache.h" 23 #include "GrLayerCache.h"
24 #include "GrOvalRenderer.h" 24 #include "GrOvalRenderer.h"
25 #include "GrPathRenderer.h" 25 #include "GrPathRenderer.h"
26 #include "GrPathUtils.h" 26 #include "GrPathUtils.h"
27 #include "GrRenderTargetPriv.h" 27 #include "GrRenderTargetPriv.h"
28 #include "GrResourceCache.h" 28 #include "GrResourceCache.h"
29 #include "GrResourceProvider.h" 29 #include "GrResourceProvider.h"
30 #include "GrSoftwarePathRenderer.h" 30 #include "GrSoftwarePathRenderer.h"
31 #include "GrStencilAndCoverTextContext.h"
31 #include "GrStrokeInfo.h" 32 #include "GrStrokeInfo.h"
32 #include "GrSurfacePriv.h" 33 #include "GrSurfacePriv.h"
33 #include "GrTextBlobCache.h" 34 #include "GrTextBlobCache.h"
34 #include "GrTexturePriv.h" 35 #include "GrTexturePriv.h"
35 #include "GrTracing.h" 36 #include "GrTracing.h"
36 #include "GrVertices.h" 37 #include "GrVertices.h"
37 #include "SkDashPathPriv.h" 38 #include "SkDashPathPriv.h"
38 #include "SkConfig8888.h" 39 #include "SkConfig8888.h"
39 #include "SkGr.h" 40 #include "SkGr.h"
40 #include "SkRRect.h" 41 #include "SkRRect.h"
41 #include "SkStrokeRec.h" 42 #include "SkStrokeRec.h"
42 #include "SkSurfacePriv.h" 43 #include "SkSurfacePriv.h"
43 #include "SkTLazy.h" 44 #include "SkTLazy.h"
44 #include "SkTLS.h" 45 #include "SkTLS.h"
45 #include "SkTraceEvent.h" 46 #include "SkTraceEvent.h"
46 47
48
47 #include "batches/GrBatch.h" 49 #include "batches/GrBatch.h"
48 50
49 #include "effects/GrConfigConversionEffect.h" 51 #include "effects/GrConfigConversionEffect.h"
50 #include "effects/GrDashingEffect.h" 52 #include "effects/GrDashingEffect.h"
51 #include "effects/GrSingleTextureEffect.h" 53 #include "effects/GrSingleTextureEffect.h"
52 54
53 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) 55 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this)
54 #define RETURN_IF_ABANDONED if (fDrawingMgr.abandoned()) { return; } 56 #define RETURN_IF_ABANDONED if (fDrawingMgr.abandoned()) { return; }
55 #define RETURN_FALSE_IF_ABANDONED if (fDrawingMgr.abandoned()) { return false; } 57 #define RETURN_FALSE_IF_ABANDONED if (fDrawingMgr.abandoned()) { return false; }
56 #define RETURN_NULL_IF_ABANDONED if (fDrawingMgr.abandoned()) { return nullptr; } 58 #define RETURN_NULL_IF_ABANDONED if (fDrawingMgr.abandoned()) { return nullptr; }
57 59
58 60
59 //////////////////////////////////////////////////////////////////////////////// 61 ////////////////////////////////////////////////////////////////////////////////
60 62
61 void GrContext::DrawingMgr::init(GrContext* context) { 63 void GrContext::DrawingMgr::init(GrContext* context) {
62 fContext = context; 64 fContext = context;
63 fDrawTarget = new GrDrawTarget(context->getGpu(), context->resourceProvider( )); 65 fDrawTarget = new GrDrawTarget(context->getGpu(), context->resourceProvider( ));
64 } 66 }
65 67
66 void GrContext::DrawingMgr::cleanup() { 68 void GrContext::DrawingMgr::cleanup() {
67 SkSafeSetNull(fDrawTarget); 69 SkSafeSetNull(fDrawTarget);
70 delete fNVPRTextContext;
71 fNVPRTextContext = nullptr;
68 for (int i = 0; i < kNumPixelGeometries; ++i) { 72 for (int i = 0; i < kNumPixelGeometries; ++i) {
69 SkSafeSetNull(fDrawContext[i][0]); 73 delete fTextContexts[i][0];
70 SkSafeSetNull(fDrawContext[i][1]); 74 fTextContexts[i][0] = nullptr;
75 delete fTextContexts[i][1];
76 fTextContexts[i][1] = nullptr;
71 } 77 }
72 } 78 }
73 79
74 GrContext::DrawingMgr::~DrawingMgr() { 80 GrContext::DrawingMgr::~DrawingMgr() {
75 this->cleanup(); 81 this->cleanup();
76 } 82 }
77 83
78 void GrContext::DrawingMgr::abandon() { 84 void GrContext::DrawingMgr::abandon() {
79 SkSafeSetNull(fDrawTarget); 85 this->cleanup();
80 for (int i = 0; i < kNumPixelGeometries; ++i) {
81 for (int j = 0; j < kNumDFTOptions; ++j) {
82 if (fDrawContext[i][j]) {
83 SkSafeSetNull(fDrawContext[i][j]->fDrawTarget);
84 SkSafeSetNull(fDrawContext[i][j]);
85 }
86 }
87 }
88 } 86 }
89 87
90 void GrContext::DrawingMgr::reset() { 88 void GrContext::DrawingMgr::reset() {
91 if (fDrawTarget) { 89 if (fDrawTarget) {
92 fDrawTarget->reset(); 90 fDrawTarget->reset();
93 } 91 }
94 } 92 }
95 93
96 void GrContext::DrawingMgr::flush() { 94 void GrContext::DrawingMgr::flush() {
97 if (fDrawTarget) { 95 if (fDrawTarget) {
98 fDrawTarget->flush(); 96 fDrawTarget->flush();
99 } 97 }
100 } 98 }
101 99
100 GrTextContext* GrContext::DrawingMgr::textContext(const SkSurfaceProps& props,
101 GrRenderTarget* rt) {
102 if (this->abandoned()) {
103 return nullptr;
104 }
105
106 SkASSERT(props.pixelGeometry() < kNumPixelGeometries);
107 bool useDIF = props.isUseDeviceIndependentFonts();
108
109 if (useDIF && fContext->caps()->shaderCaps()->pathRenderingSupport() &&
110 rt->isStencilBufferMultisampled()) {
111 GrStencilAttachment* sb = fContext->resourceProvider()->attachStencilAtt achment(rt);
112 if (sb) {
113 if (!fNVPRTextContext) {
114 fNVPRTextContext = GrStencilAndCoverTextContext::Create(fContext , props);
115 }
116
117 return fNVPRTextContext;
118 }
119 }
120
121 if (!fTextContexts[props.pixelGeometry()][useDIF]) {
122 fTextContexts[props.pixelGeometry()][useDIF] = GrAtlasTextContext::Creat e(fContext, props);
123 }
124
125 return fTextContexts[props.pixelGeometry()][useDIF];
126 }
127
102 GrDrawContext* GrContext::DrawingMgr::drawContext(const SkSurfaceProps* surfaceP rops) { 128 GrDrawContext* GrContext::DrawingMgr::drawContext(const SkSurfaceProps* surfaceP rops) {
103 if (this->abandoned()) { 129 if (this->abandoned()) {
104 return nullptr; 130 return nullptr;
105 } 131 }
106 132
107 const SkSurfaceProps props(SkSurfacePropsCopyOrDefault(surfaceProps)); 133 return new GrDrawContext(fContext, fDrawTarget, surfaceProps);
108
109 SkASSERT(props.pixelGeometry() < kNumPixelGeometries);
110 if (!fDrawContext[props.pixelGeometry()][props.isUseDeviceIndependentFonts() ]) {
111 fDrawContext[props.pixelGeometry()][props.isUseDeviceIndependentFonts()] =
112 new GrDrawContext(fContext, fDrawTarget, props);
113 }
114
115 // For now, everyone gets a faux creation ref
116 return SkRef(fDrawContext[props.pixelGeometry()][props.isUseDeviceIndependen tFonts()]);
117 } 134 }
118 135
119 //////////////////////////////////////////////////////////////////////////////// 136 ////////////////////////////////////////////////////////////////////////////////
120 137
121 138
122 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext) { 139 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext) {
123 GrContextOptions defaultOptions; 140 GrContextOptions defaultOptions;
124 return Create(backend, backendContext, defaultOptions); 141 return Create(backend, backendContext, defaultOptions);
125 } 142 }
126 143
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 766
750 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes) { 767 void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes) {
751 fResourceCache->setLimits(maxTextures, maxTextureBytes); 768 fResourceCache->setLimits(maxTextures, maxTextureBytes);
752 } 769 }
753 770
754 ////////////////////////////////////////////////////////////////////////////// 771 //////////////////////////////////////////////////////////////////////////////
755 772
756 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { 773 void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const {
757 fResourceCache->dumpMemoryStatistics(traceMemoryDump); 774 fResourceCache->dumpMemoryStatistics(traceMemoryDump);
758 } 775 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698