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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 | 76 |
77 ~AutoCheckFlush() { | 77 ~AutoCheckFlush() { |
78 if (fContext->fFlushToReduceCacheSize) { | 78 if (fContext->fFlushToReduceCacheSize) { |
79 fContext->flush(); | 79 fContext->flush(); |
80 } | 80 } |
81 } | 81 } |
82 | 82 |
83 private: | 83 private: |
84 GrContext* fContext; | 84 GrContext* fContext; |
85 }; | 85 }; |
86 | 86 |
robertphillips
2014/08/11 19:22:20
Can we just have this in the header?
krajcevski
2014/08/11 20:01:33
Done.
| |
87 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext) { | 87 GrContext::Options::Options() |
88 : fDrawPathToCompressedTexture(false) | |
89 { } | |
90 | |
91 GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext, | |
92 const Options* opts) { | |
88 GrContext* context = SkNEW(GrContext); | 93 GrContext* context = SkNEW(GrContext); |
89 if (context->init(backend, backendContext)) { | 94 |
95 Options defaultOpts; | |
96 if (NULL == opts) { | |
97 opts = &defaultOpts; | |
98 } | |
99 | |
100 if (context->init(backend, backendContext, *opts)) { | |
90 return context; | 101 return context; |
91 } else { | 102 } else { |
92 context->unref(); | 103 context->unref(); |
93 return NULL; | 104 return NULL; |
94 } | 105 } |
95 } | 106 } |
96 | 107 |
97 GrContext::GrContext() { | 108 GrContext::GrContext() { |
98 fDrawState = NULL; | 109 fDrawState = NULL; |
99 fGpu = NULL; | 110 fGpu = NULL; |
100 fClip = NULL; | 111 fClip = NULL; |
101 fPathRendererChain = NULL; | 112 fPathRendererChain = NULL; |
102 fSoftwarePathRenderer = NULL; | 113 fSoftwarePathRenderer = NULL; |
103 fResourceCache = NULL; | 114 fResourceCache = NULL; |
104 fFontCache = NULL; | 115 fFontCache = NULL; |
105 fDrawBuffer = NULL; | 116 fDrawBuffer = NULL; |
106 fDrawBufferVBAllocPool = NULL; | 117 fDrawBufferVBAllocPool = NULL; |
107 fDrawBufferIBAllocPool = NULL; | 118 fDrawBufferIBAllocPool = NULL; |
108 fFlushToReduceCacheSize = false; | 119 fFlushToReduceCacheSize = false; |
109 fAARectRenderer = NULL; | 120 fAARectRenderer = NULL; |
110 fOvalRenderer = NULL; | 121 fOvalRenderer = NULL; |
111 fViewMatrix.reset(); | 122 fViewMatrix.reset(); |
112 fMaxTextureSizeOverride = 1 << 20; | 123 fMaxTextureSizeOverride = 1 << 20; |
113 } | 124 } |
114 | 125 |
115 bool GrContext::init(GrBackend backend, GrBackendContext backendContext) { | 126 bool GrContext::init(GrBackend backend, GrBackendContext backendContext, const O ptions& opts) { |
116 SkASSERT(NULL == fGpu); | 127 SkASSERT(NULL == fGpu); |
117 | 128 |
118 fGpu = GrGpu::Create(backend, backendContext, this); | 129 fGpu = GrGpu::Create(backend, backendContext, this); |
119 if (NULL == fGpu) { | 130 if (NULL == fGpu) { |
120 return false; | 131 return false; |
121 } | 132 } |
122 | 133 |
123 fDrawState = SkNEW(GrDrawState); | 134 fDrawState = SkNEW(GrDrawState); |
124 fGpu->setDrawState(fDrawState); | 135 fGpu->setDrawState(fDrawState); |
125 | 136 |
126 fResourceCache = SkNEW_ARGS(GrResourceCache, (MAX_RESOURCE_CACHE_COUNT, | 137 fResourceCache = SkNEW_ARGS(GrResourceCache, (MAX_RESOURCE_CACHE_COUNT, |
127 MAX_RESOURCE_CACHE_BYTES)); | 138 MAX_RESOURCE_CACHE_BYTES)); |
128 fResourceCache->setOverbudgetCallback(OverbudgetCB, this); | 139 fResourceCache->setOverbudgetCallback(OverbudgetCB, this); |
129 | 140 |
130 fFontCache = SkNEW_ARGS(GrFontCache, (fGpu)); | 141 fFontCache = SkNEW_ARGS(GrFontCache, (fGpu)); |
131 | 142 |
132 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this))); | 143 fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this))); |
133 | 144 |
134 fLastDrawWasBuffered = kNo_BufferedDraw; | 145 fLastDrawWasBuffered = kNo_BufferedDraw; |
135 | 146 |
136 fAARectRenderer = SkNEW(GrAARectRenderer); | 147 fAARectRenderer = SkNEW(GrAARectRenderer); |
137 fOvalRenderer = SkNEW(GrOvalRenderer); | 148 fOvalRenderer = SkNEW(GrOvalRenderer); |
138 | 149 |
139 fDidTestPMConversions = false; | 150 fDidTestPMConversions = false; |
140 | 151 |
141 this->setupDrawBuffer(); | 152 this->setupDrawBuffer(); |
142 | 153 |
154 fSupportsDrawPathToCompressed = opts.fDrawPathToCompressedTexture; | |
155 | |
143 return true; | 156 return true; |
144 } | 157 } |
145 | 158 |
146 GrContext::~GrContext() { | 159 GrContext::~GrContext() { |
147 if (NULL == fGpu) { | 160 if (NULL == fGpu) { |
148 return; | 161 return; |
149 } | 162 } |
150 | 163 |
151 this->flush(); | 164 this->flush(); |
152 | 165 |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
600 } | 613 } |
601 | 614 |
602 int GrContext::getMaxRenderTargetSize() const { | 615 int GrContext::getMaxRenderTargetSize() const { |
603 return fGpu->caps()->maxRenderTargetSize(); | 616 return fGpu->caps()->maxRenderTargetSize(); |
604 } | 617 } |
605 | 618 |
606 int GrContext::getMaxSampleCount() const { | 619 int GrContext::getMaxSampleCount() const { |
607 return fGpu->caps()->maxSampleCount(); | 620 return fGpu->caps()->maxSampleCount(); |
608 } | 621 } |
609 | 622 |
623 bool GrContext::supportsDrawPathToCompressedTexture() const { | |
624 if (!(fGpu->caps()->compressedTexSubImageSupport())) { | |
625 return false; | |
626 } | |
627 | |
628 return fSupportsDrawPathToCompressed; | |
629 } | |
630 | |
610 /////////////////////////////////////////////////////////////////////////////// | 631 /////////////////////////////////////////////////////////////////////////////// |
611 | 632 |
612 GrTexture* GrContext::wrapBackendTexture(const GrBackendTextureDesc& desc) { | 633 GrTexture* GrContext::wrapBackendTexture(const GrBackendTextureDesc& desc) { |
613 return fGpu->wrapBackendTexture(desc); | 634 return fGpu->wrapBackendTexture(desc); |
614 } | 635 } |
615 | 636 |
616 GrRenderTarget* GrContext::wrapBackendRenderTarget(const GrBackendRenderTargetDe sc& desc) { | 637 GrRenderTarget* GrContext::wrapBackendRenderTarget(const GrBackendRenderTargetDe sc& desc) { |
617 return fGpu->wrapBackendRenderTarget(desc); | 638 return fGpu->wrapBackendRenderTarget(desc); |
618 } | 639 } |
619 | 640 |
(...skipping 1327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1947 fDrawBuffer->removeGpuTraceMarker(marker); | 1968 fDrawBuffer->removeGpuTraceMarker(marker); |
1948 } | 1969 } |
1949 } | 1970 } |
1950 | 1971 |
1951 /////////////////////////////////////////////////////////////////////////////// | 1972 /////////////////////////////////////////////////////////////////////////////// |
1952 #if GR_CACHE_STATS | 1973 #if GR_CACHE_STATS |
1953 void GrContext::printCacheStats() const { | 1974 void GrContext::printCacheStats() const { |
1954 fResourceCache->printStats(); | 1975 fResourceCache->printStats(); |
1955 } | 1976 } |
1956 #endif | 1977 #endif |
OLD | NEW |