OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "GrResourceProvider.h" | 8 #include "GrResourceProvider.h" |
9 | 9 |
10 #include "GrGpu.h" | 10 #include "GrGpu.h" |
11 #include "GrIndexBuffer.h" | 11 #include "GrIndexBuffer.h" |
12 #include "GrPathRendering.h" | 12 #include "GrPathRendering.h" |
| 13 #include "GrRenderTarget.h" |
| 14 #include "GrRenderTargetPriv.h" |
13 #include "GrResourceCache.h" | 15 #include "GrResourceCache.h" |
14 #include "GrResourceKey.h" | 16 #include "GrResourceKey.h" |
| 17 #include "GrStencilAttachment.h" |
15 #include "GrVertexBuffer.h" | 18 #include "GrVertexBuffer.h" |
16 | 19 |
17 GR_DECLARE_STATIC_UNIQUE_KEY(gQuadIndexBufferKey); | 20 GR_DECLARE_STATIC_UNIQUE_KEY(gQuadIndexBufferKey); |
18 | 21 |
19 GrResourceProvider::GrResourceProvider(GrGpu* gpu, GrResourceCache* cache) : INH
ERITED(gpu, cache) { | 22 GrResourceProvider::GrResourceProvider(GrGpu* gpu, GrResourceCache* cache) : INH
ERITED(gpu, cache) { |
20 GR_DEFINE_STATIC_UNIQUE_KEY(gQuadIndexBufferKey); | 23 GR_DEFINE_STATIC_UNIQUE_KEY(gQuadIndexBufferKey); |
21 fQuadIndexBufferKey = gQuadIndexBufferKey; | 24 fQuadIndexBufferKey = gQuadIndexBufferKey; |
22 } | 25 } |
23 | 26 |
24 const GrIndexBuffer* GrResourceProvider::createInstancedIndexBuffer(const uint16
_t* pattern, | 27 const GrIndexBuffer* GrResourceProvider::createInstancedIndexBuffer(const uint16
_t* pattern, |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 // We don't want to flush the context so we claim we're in the middle of flu
shing so as to | 159 // We don't want to flush the context so we claim we're in the middle of flu
shing so as to |
157 // guarantee we do not recieve a texture with pending IO | 160 // guarantee we do not recieve a texture with pending IO |
158 // TODO: Determine how to avoid having to do this. (http://skbug.com/4156) | 161 // TODO: Determine how to avoid having to do this. (http://skbug.com/4156) |
159 static const uint32_t kFlags = GrResourceProvider::kNoPendingIO_Flag; | 162 static const uint32_t kFlags = GrResourceProvider::kNoPendingIO_Flag; |
160 GrTexture* texture = this->createApproxTexture(desc, kFlags); | 163 GrTexture* texture = this->createApproxTexture(desc, kFlags); |
161 if (!texture) { | 164 if (!texture) { |
162 return nullptr; | 165 return nullptr; |
163 } | 166 } |
164 return new GrBatchAtlas(texture, numPlotsX, numPlotsY); | 167 return new GrBatchAtlas(texture, numPlotsX, numPlotsY); |
165 } | 168 } |
| 169 |
| 170 GrStencilAttachment* GrResourceProvider::attachStencilAttachment(GrRenderTarget*
rt) { |
| 171 SkASSERT(rt); |
| 172 if (rt->renderTargetPriv().getStencilAttachment()) { |
| 173 return rt->renderTargetPriv().getStencilAttachment(); |
| 174 } |
| 175 |
| 176 if (!rt->wasDestroyed() && rt->canAttemptStencilAttachment()) { |
| 177 GrUniqueKey sbKey; |
| 178 |
| 179 int width = rt->width(); |
| 180 int height = rt->height(); |
| 181 #if 0 |
| 182 if (this->caps()->oversizedStencilSupport()) { |
| 183 width = SkNextPow2(width); |
| 184 height = SkNextPow2(height); |
| 185 } |
| 186 #endif |
| 187 bool newStencil = false; |
| 188 GrStencilAttachment::ComputeSharedStencilAttachmentKey(width, height, |
| 189 rt->numStencilSam
ples(), &sbKey); |
| 190 GrStencilAttachment* stencil = static_cast<GrStencilAttachment*>( |
| 191 this->findAndRefResourceByUniqueKey(sbKey)); |
| 192 if (!stencil) { |
| 193 // Need to try and create a new stencil |
| 194 stencil = this->gpu()->createStencilAttachmentForRenderTarget(rt, wi
dth, height); |
| 195 if (stencil) { |
| 196 stencil->resourcePriv().setUniqueKey(sbKey); |
| 197 newStencil = true; |
| 198 } |
| 199 } |
| 200 if (rt->renderTargetPriv().attachStencilAttachment(stencil)) { |
| 201 if (newStencil) { |
| 202 // Right now we're clearing the stencil attachment here after it
is |
| 203 // attached to an RT for the first time. When we start matching |
| 204 // stencil buffers with smaller color targets this will no longe
r |
| 205 // be correct because it won't be guaranteed to clear the entire |
| 206 // sb. |
| 207 // We used to clear down in the GL subclass using a special purp
ose |
| 208 // FBO. But iOS doesn't allow a stencil-only FBO. It reports uns
upported |
| 209 // FBO status. |
| 210 this->gpu()->clearStencil(rt); |
| 211 } |
| 212 } |
| 213 } |
| 214 return rt->renderTargetPriv().getStencilAttachment(); |
| 215 } |
| 216 |
| 217 |
OLD | NEW |