OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 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 "GrGpu.h" | 10 #include "GrGpu.h" |
11 | 11 |
12 #include "GrCaps.h" | 12 #include "GrCaps.h" |
13 #include "GrContext.h" | 13 #include "GrContext.h" |
14 #include "GrGpuResourcePriv.h" | 14 #include "GrGpuResourcePriv.h" |
15 #include "GrIndexBuffer.h" | 15 #include "GrIndexBuffer.h" |
16 #include "GrPathRendering.h" | 16 #include "GrPathRendering.h" |
17 #include "GrPipeline.h" | 17 #include "GrPipeline.h" |
18 #include "GrResourceCache.h" | 18 #include "GrResourceCache.h" |
| 19 #include "GrResourceProvider.h" |
19 #include "GrRenderTargetPriv.h" | 20 #include "GrRenderTargetPriv.h" |
20 #include "GrStencilAttachment.h" | 21 #include "GrStencilAttachment.h" |
21 #include "GrSurfacePriv.h" | 22 #include "GrSurfacePriv.h" |
22 #include "GrVertexBuffer.h" | 23 #include "GrVertexBuffer.h" |
23 #include "GrVertices.h" | 24 #include "GrVertices.h" |
24 | 25 |
25 GrVertices& GrVertices::operator =(const GrVertices& di) { | 26 GrVertices& GrVertices::operator =(const GrVertices& di) { |
26 fPrimitiveType = di.fPrimitiveType; | 27 fPrimitiveType = di.fPrimitiveType; |
27 fStartVertex = di.fStartVertex; | 28 fStartVertex = di.fStartVertex; |
28 fStartIndex = di.fStartIndex; | 29 fStartIndex = di.fStartIndex; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 } | 128 } |
128 if (tex) { | 129 if (tex) { |
129 fStats.incTextureCreates(); | 130 fStats.incTextureCreates(); |
130 if (srcData) { | 131 if (srcData) { |
131 fStats.incTextureUploads(); | 132 fStats.incTextureUploads(); |
132 } | 133 } |
133 } | 134 } |
134 return tex; | 135 return tex; |
135 } | 136 } |
136 | 137 |
137 bool GrGpu::attachStencilAttachmentToRenderTarget(GrRenderTarget* rt) { | |
138 SkASSERT(nullptr == rt->renderTargetPriv().getStencilAttachment()); | |
139 GrUniqueKey sbKey; | |
140 | |
141 int width = rt->width(); | |
142 int height = rt->height(); | |
143 #if 0 | |
144 if (this->caps()->oversizedStencilSupport()) { | |
145 width = SkNextPow2(width); | |
146 height = SkNextPow2(height); | |
147 } | |
148 #endif | |
149 | |
150 GrStencilAttachment::ComputeSharedStencilAttachmentKey(width, height, | |
151 rt->numStencilSamples(), &sbKey); | |
152 SkAutoTUnref<GrStencilAttachment> sb(static_cast<GrStencilAttachment*>( | |
153 this->getContext()->getResourceCache()->findAndRefUniqueResource(sbKey))
); | |
154 if (sb) { | |
155 if (this->attachStencilAttachmentToRenderTarget(sb, rt)) { | |
156 rt->renderTargetPriv().didAttachStencilAttachment(sb); | |
157 return true; | |
158 } | |
159 return false; | |
160 } | |
161 if (this->createStencilAttachmentForRenderTarget(rt, width, height)) { | |
162 // Right now we're clearing the stencil buffer here after it is | |
163 // attached to an RT for the first time. When we start matching | |
164 // stencil buffers with smaller color targets this will no longer | |
165 // be correct because it won't be guaranteed to clear the entire | |
166 // sb. | |
167 // We used to clear down in the GL subclass using a special purpose | |
168 // FBO. But iOS doesn't allow a stencil-only FBO. It reports unsupported | |
169 // FBO status. | |
170 this->clearStencil(rt); | |
171 GrStencilAttachment* sb = rt->renderTargetPriv().getStencilAttachment(); | |
172 sb->resourcePriv().setUniqueKey(sbKey); | |
173 return true; | |
174 } else { | |
175 return false; | |
176 } | |
177 } | |
178 | |
179 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwn
ership ownership) { | 138 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwn
ership ownership) { |
180 this->handleDirtyContext(); | 139 this->handleDirtyContext(); |
181 GrTexture* tex = this->onWrapBackendTexture(desc, ownership); | 140 GrTexture* tex = this->onWrapBackendTexture(desc, ownership); |
182 if (nullptr == tex) { | 141 if (nullptr == tex) { |
183 return nullptr; | 142 return nullptr; |
184 } | 143 } |
185 // TODO: defer this and attach dynamically | 144 // TODO: defer this and attach dynamically |
186 GrRenderTarget* tgt = tex->asRenderTarget(); | 145 GrRenderTarget* tgt = tex->asRenderTarget(); |
187 if (tgt && !this->attachStencilAttachmentToRenderTarget(tgt)) { | 146 if (tgt && !fContext->resourceProvider()->attachStencilAttachment(tgt)) { |
188 tex->unref(); | 147 tex->unref(); |
189 return nullptr; | 148 return nullptr; |
190 } else { | 149 } else { |
191 return tex; | 150 return tex; |
192 } | 151 } |
193 } | 152 } |
194 | 153 |
195 GrRenderTarget* GrGpu::wrapBackendRenderTarget(const GrBackendRenderTargetDesc&
desc, | 154 GrRenderTarget* GrGpu::wrapBackendRenderTarget(const GrBackendRenderTargetDesc&
desc, |
196 GrWrapOwnership ownership) { | 155 GrWrapOwnership ownership) { |
197 this->handleDirtyContext(); | 156 this->handleDirtyContext(); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 this->xferBarrier(args.fPipeline->getRenderTarget(), barrierType); | 321 this->xferBarrier(args.fPipeline->getRenderTarget(), barrierType); |
363 } | 322 } |
364 | 323 |
365 GrVertices::Iterator iter; | 324 GrVertices::Iterator iter; |
366 const GrNonInstancedVertices* verts = iter.init(vertices); | 325 const GrNonInstancedVertices* verts = iter.init(vertices); |
367 do { | 326 do { |
368 this->onDraw(args, *verts); | 327 this->onDraw(args, *verts); |
369 fStats.incNumDraws(); | 328 fStats.incNumDraws(); |
370 } while ((verts = iter.next())); | 329 } while ((verts = iter.next())); |
371 } | 330 } |
OLD | NEW |