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" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 } | 127 } |
128 if (tex) { | 128 if (tex) { |
129 fStats.incTextureCreates(); | 129 fStats.incTextureCreates(); |
130 if (srcData) { | 130 if (srcData) { |
131 fStats.incTextureUploads(); | 131 fStats.incTextureUploads(); |
132 } | 132 } |
133 } | 133 } |
134 return tex; | 134 return tex; |
135 } | 135 } |
136 | 136 |
137 bool GrGpu::attachStencilAttachmentToRenderTarget(GrRenderTarget* rt) { | 137 bool GrGpu::getStencilAttachment(const GrRenderTarget* rt, GrStencilAttachment**
stencil) { |
138 SkASSERT(nullptr == rt->renderTargetPriv().getStencilAttachment()); | 138 SkASSERT(nullptr == rt->renderTargetPriv().getStencilAttachment()); |
| 139 SkASSERT(nullptr == *stencil); |
139 GrUniqueKey sbKey; | 140 GrUniqueKey sbKey; |
140 | 141 |
141 int width = rt->width(); | 142 int width = rt->width(); |
142 int height = rt->height(); | 143 int height = rt->height(); |
143 #if 0 | 144 #if 0 |
144 if (this->caps()->oversizedStencilSupport()) { | 145 if (this->caps()->oversizedStencilSupport()) { |
145 width = SkNextPow2(width); | 146 width = SkNextPow2(width); |
146 height = SkNextPow2(height); | 147 height = SkNextPow2(height); |
147 } | 148 } |
148 #endif | 149 #endif |
149 | 150 |
150 GrStencilAttachment::ComputeSharedStencilAttachmentKey(width, height, | 151 GrStencilAttachment::ComputeSharedStencilAttachmentKey(width, height, |
151 rt->numStencilSamples(), &sbKey); | 152 rt->numStencilSamples(), &sbKey); |
152 SkAutoTUnref<GrStencilAttachment> sb(static_cast<GrStencilAttachment*>( | 153 *stencil = static_cast<GrStencilAttachment*>( |
153 this->getContext()->getResourceCache()->findAndRefUniqueResource(sbKey))
); | 154 this->getContext()->getResourceCache()->findAndRefUniqueResource(sbKey))
; |
154 if (sb) { | 155 if (*stencil) { |
155 if (this->attachStencilAttachmentToRenderTarget(sb, rt)) { | |
156 rt->renderTargetPriv().didAttachStencilAttachment(sb); | |
157 return true; | |
158 } | |
159 return false; | 156 return false; |
160 } | 157 } |
161 if (this->createStencilAttachmentForRenderTarget(rt, width, height)) { | 158 *stencil = this->createStencilAttachmentForRenderTarget(rt, width, height); |
162 // Right now we're clearing the stencil buffer here after it is | 159 if (*stencil) { |
163 // attached to an RT for the first time. When we start matching | 160 (*stencil)->resourcePriv().setUniqueKey(sbKey); |
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; | 161 return true; |
174 } else { | |
175 return false; | |
176 } | 162 } |
| 163 return false; |
177 } | 164 } |
178 | 165 |
179 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwn
ership ownership) { | 166 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwn
ership ownership) { |
180 this->handleDirtyContext(); | 167 this->handleDirtyContext(); |
181 GrTexture* tex = this->onWrapBackendTexture(desc, ownership); | 168 GrTexture* tex = this->onWrapBackendTexture(desc, ownership); |
182 if (nullptr == tex) { | 169 if (nullptr == tex) { |
183 return nullptr; | 170 return nullptr; |
184 } | 171 } |
185 // TODO: defer this and attach dynamically | 172 // TODO: defer this and attach dynamically |
186 GrRenderTarget* tgt = tex->asRenderTarget(); | 173 GrRenderTarget* tgt = tex->asRenderTarget(); |
187 if (tgt && !this->attachStencilAttachmentToRenderTarget(tgt)) { | 174 if (tgt && !tgt->renderTargetPriv().attachStencilAttachment()) { |
188 tex->unref(); | 175 tex->unref(); |
189 return nullptr; | 176 return nullptr; |
190 } else { | 177 } else { |
191 return tex; | 178 return tex; |
192 } | 179 } |
193 } | 180 } |
194 | 181 |
195 GrRenderTarget* GrGpu::wrapBackendRenderTarget(const GrBackendRenderTargetDesc&
desc, | 182 GrRenderTarget* GrGpu::wrapBackendRenderTarget(const GrBackendRenderTargetDesc&
desc, |
196 GrWrapOwnership ownership) { | 183 GrWrapOwnership ownership) { |
197 this->handleDirtyContext(); | 184 this->handleDirtyContext(); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 this->xferBarrier(args.fPipeline->getRenderTarget(), barrierType); | 349 this->xferBarrier(args.fPipeline->getRenderTarget(), barrierType); |
363 } | 350 } |
364 | 351 |
365 GrVertices::Iterator iter; | 352 GrVertices::Iterator iter; |
366 const GrNonInstancedVertices* verts = iter.init(vertices); | 353 const GrNonInstancedVertices* verts = iter.init(vertices); |
367 do { | 354 do { |
368 this->onDraw(args, *verts); | 355 this->onDraw(args, *verts); |
369 fStats.incNumDraws(); | 356 fStats.incNumDraws(); |
370 } while ((verts = iter.next())); | 357 } while ((verts = iter.next())); |
371 } | 358 } |
OLD | NEW |