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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 } else { | 64 } else { |
65 return origin; | 65 return origin; |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, bool budgeted, | 69 GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, bool budgeted, |
70 const void* srcData, size_t rowBytes) { | 70 const void* srcData, size_t rowBytes) { |
71 GrSurfaceDesc desc = origDesc; | 71 GrSurfaceDesc desc = origDesc; |
72 | 72 |
73 if (!this->caps()->isConfigTexturable(desc.fConfig)) { | 73 if (!this->caps()->isConfigTexturable(desc.fConfig)) { |
74 return NULL; | 74 return nullptr; |
75 } | 75 } |
76 | 76 |
77 bool isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); | 77 bool isRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); |
78 if (isRT && !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt
> 0)) { | 78 if (isRT && !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt
> 0)) { |
79 return NULL; | 79 return nullptr; |
80 } | 80 } |
81 | 81 |
82 // We currently do not support multisampled textures | 82 // We currently do not support multisampled textures |
83 if (!isRT && desc.fSampleCnt > 0) { | 83 if (!isRT && desc.fSampleCnt > 0) { |
84 return NULL; | 84 return nullptr; |
85 } | 85 } |
86 | 86 |
87 GrTexture *tex = NULL; | 87 GrTexture *tex = nullptr; |
88 | 88 |
89 if (isRT) { | 89 if (isRT) { |
90 int maxRTSize = this->caps()->maxRenderTargetSize(); | 90 int maxRTSize = this->caps()->maxRenderTargetSize(); |
91 if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) { | 91 if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) { |
92 return NULL; | 92 return nullptr; |
93 } | 93 } |
94 } else { | 94 } else { |
95 int maxSize = this->caps()->maxTextureSize(); | 95 int maxSize = this->caps()->maxTextureSize(); |
96 if (desc.fWidth > maxSize || desc.fHeight > maxSize) { | 96 if (desc.fWidth > maxSize || desc.fHeight > maxSize) { |
97 return NULL; | 97 return nullptr; |
98 } | 98 } |
99 } | 99 } |
100 | 100 |
101 GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_LifeC
ycle : | 101 GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_LifeC
ycle : |
102 GrGpuResource::kUncached_Lif
eCycle; | 102 GrGpuResource::kUncached_Lif
eCycle; |
103 | 103 |
104 desc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount()); | 104 desc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount()); |
105 // Attempt to catch un- or wrongly initialized sample counts; | 105 // Attempt to catch un- or wrongly initialized sample counts; |
106 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64); | 106 SkASSERT(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64); |
107 | 107 |
108 desc.fOrigin = resolve_origin(desc.fOrigin, isRT); | 108 desc.fOrigin = resolve_origin(desc.fOrigin, isRT); |
109 | 109 |
110 if (GrPixelConfigIsCompressed(desc.fConfig)) { | 110 if (GrPixelConfigIsCompressed(desc.fConfig)) { |
111 // We shouldn't be rendering into this | 111 // We shouldn't be rendering into this |
112 SkASSERT(!isRT); | 112 SkASSERT(!isRT); |
113 SkASSERT(0 == desc.fSampleCnt); | 113 SkASSERT(0 == desc.fSampleCnt); |
114 | 114 |
115 if (!this->caps()->npotTextureTileSupport() && | 115 if (!this->caps()->npotTextureTileSupport() && |
116 (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) { | 116 (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) { |
117 return NULL; | 117 return nullptr; |
118 } | 118 } |
119 | 119 |
120 this->handleDirtyContext(); | 120 this->handleDirtyContext(); |
121 tex = this->onCreateCompressedTexture(desc, lifeCycle, srcData); | 121 tex = this->onCreateCompressedTexture(desc, lifeCycle, srcData); |
122 } else { | 122 } else { |
123 this->handleDirtyContext(); | 123 this->handleDirtyContext(); |
124 tex = this->onCreateTexture(desc, lifeCycle, srcData, rowBytes); | 124 tex = this->onCreateTexture(desc, lifeCycle, srcData, rowBytes); |
125 } | 125 } |
126 if (!this->caps()->reuseScratchTextures() && !isRT) { | 126 if (!this->caps()->reuseScratchTextures() && !isRT) { |
127 tex->resourcePriv().removeScratchKey(); | 127 tex->resourcePriv().removeScratchKey(); |
128 } | 128 } |
129 if (tex) { | 129 if (tex) { |
130 fStats.incTextureCreates(); | 130 fStats.incTextureCreates(); |
131 if (srcData) { | 131 if (srcData) { |
132 fStats.incTextureUploads(); | 132 fStats.incTextureUploads(); |
133 } | 133 } |
134 } | 134 } |
135 return tex; | 135 return tex; |
136 } | 136 } |
137 | 137 |
138 bool GrGpu::attachStencilAttachmentToRenderTarget(GrRenderTarget* rt) { | 138 bool GrGpu::attachStencilAttachmentToRenderTarget(GrRenderTarget* rt) { |
139 SkASSERT(NULL == rt->renderTargetPriv().getStencilAttachment()); | 139 SkASSERT(nullptr == rt->renderTargetPriv().getStencilAttachment()); |
140 GrUniqueKey sbKey; | 140 GrUniqueKey sbKey; |
141 | 141 |
142 int width = rt->width(); | 142 int width = rt->width(); |
143 int height = rt->height(); | 143 int height = rt->height(); |
144 #if 0 | 144 #if 0 |
145 if (this->caps()->oversizedStencilSupport()) { | 145 if (this->caps()->oversizedStencilSupport()) { |
146 width = SkNextPow2(width); | 146 width = SkNextPow2(width); |
147 height = SkNextPow2(height); | 147 height = SkNextPow2(height); |
148 } | 148 } |
149 #endif | 149 #endif |
(...skipping 23 matching lines...) Expand all Loading... |
173 sb->resourcePriv().setUniqueKey(sbKey); | 173 sb->resourcePriv().setUniqueKey(sbKey); |
174 return true; | 174 return true; |
175 } else { | 175 } else { |
176 return false; | 176 return false; |
177 } | 177 } |
178 } | 178 } |
179 | 179 |
180 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwn
ership ownership) { | 180 GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwn
ership ownership) { |
181 this->handleDirtyContext(); | 181 this->handleDirtyContext(); |
182 GrTexture* tex = this->onWrapBackendTexture(desc, ownership); | 182 GrTexture* tex = this->onWrapBackendTexture(desc, ownership); |
183 if (NULL == tex) { | 183 if (nullptr == tex) { |
184 return NULL; | 184 return nullptr; |
185 } | 185 } |
186 // TODO: defer this and attach dynamically | 186 // TODO: defer this and attach dynamically |
187 GrRenderTarget* tgt = tex->asRenderTarget(); | 187 GrRenderTarget* tgt = tex->asRenderTarget(); |
188 if (tgt && !this->attachStencilAttachmentToRenderTarget(tgt)) { | 188 if (tgt && !this->attachStencilAttachmentToRenderTarget(tgt)) { |
189 tex->unref(); | 189 tex->unref(); |
190 return NULL; | 190 return nullptr; |
191 } else { | 191 } else { |
192 return tex; | 192 return tex; |
193 } | 193 } |
194 } | 194 } |
195 | 195 |
196 GrRenderTarget* GrGpu::wrapBackendRenderTarget(const GrBackendRenderTargetDesc&
desc, | 196 GrRenderTarget* GrGpu::wrapBackendRenderTarget(const GrBackendRenderTargetDesc&
desc, |
197 GrWrapOwnership ownership) { | 197 GrWrapOwnership ownership) { |
198 this->handleDirtyContext(); | 198 this->handleDirtyContext(); |
199 return this->onWrapBackendRenderTarget(desc, ownership); | 199 return this->onWrapBackendRenderTarget(desc, ownership); |
200 } | 200 } |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 if (GrXferBarrierType barrierType = args.fPipeline->xferBarrierType(*this->c
aps())) { | 394 if (GrXferBarrierType barrierType = args.fPipeline->xferBarrierType(*this->c
aps())) { |
395 this->xferBarrier(args.fPipeline->getRenderTarget(), barrierType); | 395 this->xferBarrier(args.fPipeline->getRenderTarget(), barrierType); |
396 } | 396 } |
397 | 397 |
398 GrVertices::Iterator iter; | 398 GrVertices::Iterator iter; |
399 const GrNonInstancedVertices* verts = iter.init(vertices); | 399 const GrNonInstancedVertices* verts = iter.init(vertices); |
400 do { | 400 do { |
401 this->onDraw(args, *verts); | 401 this->onDraw(args, *verts); |
402 } while ((verts = iter.next())); | 402 } while ((verts = iter.next())); |
403 } | 403 } |
OLD | NEW |