Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(425)

Side by Side Diff: src/gpu/GrGpu.cpp

Issue 938383004: Dynamically create stencil buffer when needed. (Closed) Base URL: https://skia.googlesource.com/skia.git@bigstencil
Patch Set: wrap Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "GrBufferAllocPool.h" 12 #include "GrBufferAllocPool.h"
13 #include "GrContext.h" 13 #include "GrContext.h"
14 #include "GrDrawTargetCaps.h" 14 #include "GrDrawTargetCaps.h"
15 #include "GrGpuResourcePriv.h" 15 #include "GrGpuResourcePriv.h"
16 #include "GrIndexBuffer.h" 16 #include "GrIndexBuffer.h"
17 #include "GrResourceCache.h" 17 #include "GrResourceCache.h"
18 #include "GrRenderTargetPriv.h"
18 #include "GrStencilBuffer.h" 19 #include "GrStencilBuffer.h"
19 #include "GrVertexBuffer.h" 20 #include "GrVertexBuffer.h"
20 21
21 //////////////////////////////////////////////////////////////////////////////// 22 ////////////////////////////////////////////////////////////////////////////////
22 23
23 GrGpu::GrGpu(GrContext* context) 24 GrGpu::GrGpu(GrContext* context)
24 : fResetTimestamp(kExpiredTimestamp+1) 25 : fResetTimestamp(kExpiredTimestamp+1)
25 , fResetBits(kAll_GrBackendState) 26 , fResetBits(kAll_GrBackendState)
26 , fQuadIndexBuffer(NULL) 27 , fQuadIndexBuffer(NULL)
27 , fContext(context) { 28 , fContext(context) {
(...skipping 26 matching lines...) Expand all
54 if (!this->caps()->npotTextureTileSupport() && 55 if (!this->caps()->npotTextureTileSupport() &&
55 (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) { 56 (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) {
56 return NULL; 57 return NULL;
57 } 58 }
58 59
59 this->handleDirtyContext(); 60 this->handleDirtyContext();
60 tex = this->onCreateCompressedTexture(desc, budgeted, srcData); 61 tex = this->onCreateCompressedTexture(desc, budgeted, srcData);
61 } else { 62 } else {
62 this->handleDirtyContext(); 63 this->handleDirtyContext();
63 tex = this->onCreateTexture(desc, budgeted, srcData, rowBytes); 64 tex = this->onCreateTexture(desc, budgeted, srcData, rowBytes);
64 if (tex &&
65 (kRenderTarget_GrSurfaceFlag & desc.fFlags) &&
66 !(kNoStencil_GrSurfaceFlag & desc.fFlags)) {
67 SkASSERT(tex->asRenderTarget());
68 // TODO: defer this and attach dynamically
69 if (!this->attachStencilBufferToRenderTarget(tex->asRenderTarget())) {
70 tex->unref();
71 return NULL;
72 }
73 }
74 } 65 }
75 if (!this->caps()->reuseScratchTextures() && !isRT) { 66 if (!this->caps()->reuseScratchTextures() && !isRT) {
76 tex->resourcePriv().removeScratchKey(); 67 tex->resourcePriv().removeScratchKey();
77 } 68 }
78 if (tex) { 69 if (tex) {
79 fStats.incTextureCreates(); 70 fStats.incTextureCreates();
80 if (srcData) { 71 if (srcData) {
81 fStats.incTextureUploads(); 72 fStats.incTextureUploads();
82 } 73 }
83 } 74 }
84 return tex; 75 return tex;
85 } 76 }
86 77
87 bool GrGpu::attachStencilBufferToRenderTarget(GrRenderTarget* rt) { 78 bool GrGpu::attachStencilBufferToRenderTarget(GrRenderTarget* rt) {
88 SkASSERT(NULL == rt->getStencilBuffer()); 79 SkASSERT(NULL == rt->renderTargetPriv().getStencilBuffer());
89 GrUniqueKey sbKey; 80 GrUniqueKey sbKey;
90 81
91 int width = rt->width(); 82 int width = rt->width();
92 int height = rt->height(); 83 int height = rt->height();
93 if (this->caps()->oversizedStencilSupport()) { 84 if (this->caps()->oversizedStencilSupport()) {
94 width = SkNextPow2(width); 85 width = SkNextPow2(width);
95 height = SkNextPow2(height); 86 height = SkNextPow2(height);
96 } 87 }
97 88
98 GrStencilBuffer::ComputeSharedStencilBufferKey(width, height, rt->numSamples (), &sbKey); 89 GrStencilBuffer::ComputeSharedStencilBufferKey(width, height, rt->numSamples (), &sbKey);
99 SkAutoTUnref<GrStencilBuffer> sb(static_cast<GrStencilBuffer*>( 90 SkAutoTUnref<GrStencilBuffer> sb(static_cast<GrStencilBuffer*>(
100 this->getContext()->getResourceCache()->findAndRefUniqueResource(sbKey)) ); 91 this->getContext()->getResourceCache()->findAndRefUniqueResource(sbKey)) );
101 if (sb) { 92 if (sb) {
102 rt->setStencilBuffer(sb); 93 if (this->attachStencilBufferToRenderTarget(sb, rt)) {
103 bool attached = this->attachStencilBufferToRenderTarget(sb, rt); 94 rt->renderTargetPriv().didAttachStencilBuffer(sb);
104 if (!attached) { 95 return true;
105 rt->setStencilBuffer(NULL);
106 } 96 }
107 return attached; 97 return false;
108 } 98 }
109 if (this->createStencilBufferForRenderTarget(rt, width, height)) { 99 if (this->createStencilBufferForRenderTarget(rt, width, height)) {
robertphillips 2015/02/20 20:00:58 This comment seems important.
bsalomon 2015/02/20 20:02:55 Yikes! Yes.
110 // Right now we're clearing the stencil buffer here after it is 100 // Right now we're clearing the stencil buffer here after it is
111 // attached to an RT for the first time. When we start matching 101 // attached to an RT for the first time. When we start matching
112 // stencil buffers with smaller color targets this will no longer 102 // stencil buffers with smaller color targets this will no longer
113 // be correct because it won't be guaranteed to clear the entire 103 // be correct because it won't be guaranteed to clear the entire
114 // sb. 104 // sb.
115 // We used to clear down in the GL subclass using a special purpose 105 // We used to clear down in the GL subclass using a special purpose
116 // FBO. But iOS doesn't allow a stencil-only FBO. It reports unsupported 106 // FBO. But iOS doesn't allow a stencil-only FBO. It reports unsupported
117 // FBO status. 107 // FBO status.
118 this->clearStencil(rt); 108 this->clearStencil(rt);
119 rt->getStencilBuffer()->resourcePriv().setUniqueKey(sbKey); 109 GrStencilBuffer* sb = rt->renderTargetPriv().getStencilBuffer();
110 sb->resourcePriv().setUniqueKey(sbKey);
120 return true; 111 return true;
121 } else { 112 } else {
122 return false; 113 return false;
123 } 114 }
124 } 115 }
125 116
126 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc) { 117 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc) {
127 this->handleDirtyContext(); 118 this->handleDirtyContext();
128 GrTexture* tex = this->onWrapBackendTexture(desc); 119 GrTexture* tex = this->onWrapBackendTexture(desc);
129 if (NULL == tex) { 120 if (NULL == tex) {
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 GrDrawTarget::PathIndexType indexType, 312 GrDrawTarget::PathIndexType indexType,
322 const float transformValues[], 313 const float transformValues[],
323 GrDrawTarget::PathTransformType transformType, 314 GrDrawTarget::PathTransformType transformType,
324 int count, 315 int count,
325 const GrStencilSettings& stencilSettings) { 316 const GrStencilSettings& stencilSettings) {
326 this->handleDirtyContext(); 317 this->handleDirtyContext();
327 pathRange->willDrawPaths(indices, indexType, count); 318 pathRange->willDrawPaths(indices, indexType, count);
328 this->onDrawPaths(args, pathRange, indices, indexType, transformValues, 319 this->onDrawPaths(args, pathRange, indices, indexType, transformValues,
329 transformType, count, stencilSettings); 320 transformType, count, stencilSettings);
330 } 321 }
OLDNEW
« no previous file with comments | « src/gpu/GrGpu.h ('k') | src/gpu/GrRenderTarget.cpp » ('j') | src/gpu/GrRenderTargetPriv.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698