| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 this->handleDirtyContext(); | 59 this->handleDirtyContext(); |
| 60 tex = this->onCreateCompressedTexture(desc, budgeted, srcData); | 60 tex = this->onCreateCompressedTexture(desc, budgeted, srcData); |
| 61 } else { | 61 } else { |
| 62 this->handleDirtyContext(); | 62 this->handleDirtyContext(); |
| 63 tex = this->onCreateTexture(desc, budgeted, srcData, rowBytes); | 63 tex = this->onCreateTexture(desc, budgeted, srcData, rowBytes); |
| 64 if (tex && | 64 if (tex && |
| 65 (kRenderTarget_GrSurfaceFlag & desc.fFlags) && | 65 (kRenderTarget_GrSurfaceFlag & desc.fFlags) && |
| 66 !(kNoStencil_GrSurfaceFlag & desc.fFlags)) { | 66 !(kNoStencil_GrSurfaceFlag & desc.fFlags)) { |
| 67 SkASSERT(tex->asRenderTarget()); | 67 SkASSERT(tex->asRenderTarget()); |
| 68 // TODO: defer this and attach dynamically | 68 // TODO: defer this and attach dynamically |
| 69 if (!this->attachStencilBufferToRenderTarget(tex->asRenderTarget(),
budgeted)) { | 69 if (!this->attachStencilBufferToRenderTarget(tex->asRenderTarget()))
{ |
| 70 tex->unref(); | 70 tex->unref(); |
| 71 return NULL; | 71 return NULL; |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 if (!this->caps()->reuseScratchTextures() && !isRT) { | 75 if (!this->caps()->reuseScratchTextures() && !isRT) { |
| 76 tex->resourcePriv().removeScratchKey(); | 76 tex->resourcePriv().removeScratchKey(); |
| 77 } | 77 } |
| 78 if (tex) { | 78 if (tex) { |
| 79 fStats.incTextureCreates(); | 79 fStats.incTextureCreates(); |
| 80 if (srcData) { | 80 if (srcData) { |
| 81 fStats.incTextureUploads(); | 81 fStats.incTextureUploads(); |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 return tex; | 84 return tex; |
| 85 } | 85 } |
| 86 | 86 |
| 87 bool GrGpu::attachStencilBufferToRenderTarget(GrRenderTarget* rt, bool budgeted)
{ | 87 bool GrGpu::attachStencilBufferToRenderTarget(GrRenderTarget* rt) { |
| 88 SkASSERT(NULL == rt->getStencilBuffer()); | 88 SkASSERT(NULL == rt->getStencilBuffer()); |
| 89 GrScratchKey sbKey; | 89 GrUniqueKey sbKey; |
| 90 GrStencilBuffer::ComputeKey(rt->width(), rt->height(), rt->numSamples(), &sb
Key); | 90 GrStencilBuffer::ComputeSharedStencilBufferKey(rt->width(), rt->height(), rt
->numSamples(), |
| 91 &sbKey); |
| 91 SkAutoTUnref<GrStencilBuffer> sb(static_cast<GrStencilBuffer*>( | 92 SkAutoTUnref<GrStencilBuffer> sb(static_cast<GrStencilBuffer*>( |
| 92 this->getContext()->getResourceCache()->findAndRefScratchResource(sbKey)
)); | 93 this->getContext()->getResourceCache()->findAndRefUniqueResource(sbKey))
); |
| 93 if (sb) { | 94 if (sb) { |
| 94 rt->setStencilBuffer(sb); | 95 rt->setStencilBuffer(sb); |
| 95 bool attached = this->attachStencilBufferToRenderTarget(sb, rt); | 96 bool attached = this->attachStencilBufferToRenderTarget(sb, rt); |
| 96 if (!attached) { | 97 if (!attached) { |
| 97 rt->setStencilBuffer(NULL); | 98 rt->setStencilBuffer(NULL); |
| 98 } | 99 } |
| 99 return attached; | 100 return attached; |
| 100 } | 101 } |
| 101 if (this->createStencilBufferForRenderTarget(rt, budgeted, rt->width(), rt->
height())) { | 102 if (this->createStencilBufferForRenderTarget(rt, rt->width(), rt->height()))
{ |
| 102 // Right now we're clearing the stencil buffer here after it is | 103 // Right now we're clearing the stencil buffer here after it is |
| 103 // attached to an RT for the first time. When we start matching | 104 // attached to an RT for the first time. When we start matching |
| 104 // stencil buffers with smaller color targets this will no longer | 105 // stencil buffers with smaller color targets this will no longer |
| 105 // be correct because it won't be guaranteed to clear the entire | 106 // be correct because it won't be guaranteed to clear the entire |
| 106 // sb. | 107 // sb. |
| 107 // We used to clear down in the GL subclass using a special purpose | 108 // We used to clear down in the GL subclass using a special purpose |
| 108 // FBO. But iOS doesn't allow a stencil-only FBO. It reports unsupported | 109 // FBO. But iOS doesn't allow a stencil-only FBO. It reports unsupported |
| 109 // FBO status. | 110 // FBO status. |
| 110 this->clearStencil(rt); | 111 this->clearStencil(rt); |
| 112 rt->getStencilBuffer()->resourcePriv().setUniqueKey(sbKey); |
| 111 return true; | 113 return true; |
| 112 } else { | 114 } else { |
| 113 return false; | 115 return false; |
| 114 } | 116 } |
| 115 } | 117 } |
| 116 | 118 |
| 117 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc) { | 119 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc) { |
| 118 this->handleDirtyContext(); | 120 this->handleDirtyContext(); |
| 119 GrTexture* tex = this->onWrapBackendTexture(desc); | 121 GrTexture* tex = this->onWrapBackendTexture(desc); |
| 120 if (NULL == tex) { | 122 if (NULL == tex) { |
| 121 return NULL; | 123 return NULL; |
| 122 } | 124 } |
| 123 // TODO: defer this and attach dynamically | 125 // TODO: defer this and attach dynamically |
| 124 GrRenderTarget* tgt = tex->asRenderTarget(); | 126 GrRenderTarget* tgt = tex->asRenderTarget(); |
| 125 if (tgt && | 127 if (tgt && !this->attachStencilBufferToRenderTarget(tgt)) { |
| 126 !this->attachStencilBufferToRenderTarget(tgt, true /*budgeted*/)) { | |
| 127 tex->unref(); | 128 tex->unref(); |
| 128 return NULL; | 129 return NULL; |
| 129 } else { | 130 } else { |
| 130 return tex; | 131 return tex; |
| 131 } | 132 } |
| 132 } | 133 } |
| 133 | 134 |
| 134 GrRenderTarget* GrGpu::wrapBackendRenderTarget(const GrBackendRenderTargetDesc&
desc) { | 135 GrRenderTarget* GrGpu::wrapBackendRenderTarget(const GrBackendRenderTargetDesc&
desc) { |
| 135 this->handleDirtyContext(); | 136 this->handleDirtyContext(); |
| 136 return this->onWrapBackendRenderTarget(desc); | 137 return this->onWrapBackendRenderTarget(desc); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 GrDrawTarget::PathIndexType indexType, | 314 GrDrawTarget::PathIndexType indexType, |
| 314 const float transformValues[], | 315 const float transformValues[], |
| 315 GrDrawTarget::PathTransformType transformType, | 316 GrDrawTarget::PathTransformType transformType, |
| 316 int count, | 317 int count, |
| 317 const GrStencilSettings& stencilSettings) { | 318 const GrStencilSettings& stencilSettings) { |
| 318 this->handleDirtyContext(); | 319 this->handleDirtyContext(); |
| 319 pathRange->willDrawPaths(indices, indexType, count); | 320 pathRange->willDrawPaths(indices, indexType, count); |
| 320 this->onDrawPaths(args, pathRange, indices, indexType, transformValues, | 321 this->onDrawPaths(args, pathRange, indices, indexType, transformValues, |
| 321 transformType, count, stencilSettings); | 322 transformType, count, stencilSettings); |
| 322 } | 323 } |
| OLD | NEW |